Reputation: 23
I'm using Meshlab software to decimate 3D meshes. This works fine, however when I want to decimate a 3D mesh with colors on vertices, I don't know which algorithm to use since no one is presented managing colors (MC Edge collapse, Clustering Decimation, Quadric Edge Collapse Decimation). Any advice for decimating 3D mesh with colors? Also, I will be interested if you know some code doing that. Thanks
Upvotes: 0
Views: 559
Reputation: 1337
Another example similar to Huang's one could be:
from vedo import Sphere
# a test mesh
s = Sphere().lw(1)
# points as numpy array
pts = s.points()
# associate a scalar to each mesh vertex
# and set its color by a standard colormap
s.cmap("rainbow", pts[:,0]).print()
s.decimate(method='pro')
s.smooth() #optionally smooth the mesh
s.show(axes=1)
Upvotes: 0
Reputation: 36
I have the experience about this.
First, train a KNN model for origin mesh
Second, downsample origin mesh to mesh2
Third, use KNN model to predict the mesh2 label
from sklearn.neighbors import KNeighborsClassifier
import vedo
import numpy as np
mesh = vedo.load(your_3Dobject_path)
neigh = KNeighborsClassifier(n_neighbors=3)
neigh.fit(mesh.cellCenters(), np.ravel(mesh.getCellArray('Label')))
#downsample to 1000
target_num = 1000
ratio = target_num/mesh.NCells() # calculate ratio
mesh2 = mesh.clone()
mesh2.decimate(fraction=ratio)
fine_labels = neigh.predict(mesh2.cellCenters())
fine_labels = fine_labels.reshape(-1, 1)
mesh2.addCellArray(fine_labels, 'Label')
Upvotes: 1
Reputation: 21
You can compute vertex attributes like color when doing edge collapsing.
Upvotes: 0