Comments (4)
Hello,
The function pointGridSampling
in python returns an object of VertBitSet
type. You can use count()
method of it to find the number of samples.
If you want the result as numpy array, then you can export all points (before sampling) and sample mask:
from meshlib import mrmesh
from meshlib import mrmeshnumpy
# Start from numpy arrays
u, v = np.mgrid[0 : 2 * np.pi : 100j, 0 : np.pi : 100j]
x = np.cos(u) * np.sin(v)
y = np.sin(u) * np.sin(v)
z = np.cos(v)
# Prepare for MeshLib PointCloud
verts = np.stack((x.flatten(), y.flatten(), z.flatten()), axis=-1).reshape(-1, 3)
# Create MeshLib PointCloud from np ndarray
pc = mrmeshnumpy.pointCloudFromPoints(verts)
assert(pc.validPoints.count() == 10000)
# Sample points
samples = mrmesh.pointGridSampling(pc, 0.1)
assert(samples.count() == 1524)
# Convert all points (before downsampling) in numpy array
pts = mrmeshnumpy.toNumpyArray(pc.points)
# Convert sample mask in numpy array of True/False
mrmeshnumpy.getNumpyBitSet(samples)
from meshlib.
Thank you for your suggestion, which has solved my problem. By the way, I want to know if there is a method to downsample the point cloud to a fixed number. for example, after sampling, the number of points in the point cloud is 5000.
from meshlib.
I am trying to use a loop to downsample the point cloud to 5000 points. Here is my code:
def prepare(mesh):
verts = mesh.points
pc = mn.pointCloudFromPoints(verts)
while True:
samples = mm.pointGridSampling(pc, 0.99)
# Convert all points (before downsampling) in numpy array
pts = mn.toNumpyArray(pc.points)
# Convert sample mask in numpy array of True/False
samples_mask = mn.getNumpyBitSet(samples)
result = pts[np.where(samples_mask)[0]]
print(len(result))
tmp = len(result)
if tmp <= 5000:
break
pc = mn.pointCloudFromPoints(result)
But it only dropped to around 10000 and no longer undergoes downsampling. How to solve the problem?
from meshlib.
The second parameter in pointGridSampling
is voxel size (or 3d box size), and the function leaves only one sample per voxel. If you run the function several times, then the voxels are the same and they already contain one point each, so the function does nothing. The only exception is the second run, which still removes some points because the bounding box of the whole point cloud changes after the first invocation, so the distribution of voxels changes as well.
In short, one has to increase voxelSize
to get smaller number of output samples.
As to receiving exactly specified number of samples, we have such option for meshes (see decimation), but not for point clouds yet.
from meshlib.
Related Issues (20)
- Are there any examples of emscripten for reference? HOT 1
- WSL Ubuntu 22 build issue: Target "MRCuda" requires the language dialect "CUDA20" HOT 1
- Issue with `vectorEdges` in Python (Windows) HOT 4
- Expose computePerFaceNormals results to numpy HOT 2
- SegmentByGraphCut not Modifying faceBitSet HOT 3
- Correct Method for Projecting Face Labels of a Mesh with MeshToDistanceVolume HOT 2
- EditableProject Template for External Plugins HOT 5
- Boolean mapping HOT 4
- Add overload to find closest intersections for computeSkyViewFactor HOT 5
- Anisotropic offsetting HOT 5
- Reproduce Fill Hole & Smooth in python HOT 1
- mrmeshpy.decimateMesh question HOT 3
- Installation via package manager using pip-24.0 & python 3.12.1 not successfull HOT 12
- type object 'meshlib.mrmeshpy.LaplacianEdgeWeightsParam' has no attribute 'CotanWithAreaEqWeight' HOT 1
- Meshlib WASM Web Execution HOT 2
- VectorFloatByVert to numpy HOT 1
- Show notification unshadowed if running progress dialog
- Compilation Error in MRPch Project with Eigen3 HOT 4
- Chinese support problem HOT 1
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from meshlib.