How to use PyMeshLab to reduce vertex number to a certain number #318
Unanswered
jmespadero
asked this question in
Show and tell
Replies: 0 comments
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
This script was created as side result of this question in stackOverflow about how to decimate a mesh (reduce the number of vertex and faces) to a target number of vertex choosed by the user.
The question can be summarized as: "I know I can use simplification_quadric_edge_collapse_decimation filter to reduce the face number which means the vertex number will be reduced accordingly. But the problem is that I have to use the method several times in order to get the vertex number exactly down to 10000."
The decimation algorithm in meshlab/pymeshlab is based on Michael Garland's QSlim algorithm, which is based on Edge Collapse operations to perform the decimation using smalls step and a smart way to keep track of the amount of error introduced by current and previous steps.
As you can see in the image below, the Edge Collapse operator reduces in two the number of triangles in your mesh (one, if the edge is in the boundary) and reduce the number of vertices by one (two, if collapsing an edge of a isolated triangle make it to go banished) .
This means that it is possible to estimate how many edge collapses we need to apply to reduce the number of vertex, but... we can't feed that number to the algorithm, only the desired number of faces of the mesh. Both values are correllated but the exact number of steps depends of the presence of boundaries, and this depends on the geometry of the mesh.
So the idea is to implement a "soft landing" algorithm that reduce the number of faces in batches whose size depends of the excess of vertex (the current number of vertex minux the desired number of vertex), decreasing the size of the batch until the vertex count converges into the target.
This is the result applied to the Pythagore model courtesy of Geoffrey Marchal...
Please, note that:
numFaces = numFaces - int(1.5*(ms.current_mesh().vertex_number() - TARGET))
, but this increases the chances of ending under 9999 vertex and execution time won't be affected much.Beta Was this translation helpful? Give feedback.
All reactions