我有一批三角形网格,每个都有不同的顶点和面。我想将所有网格的顶点数减少到相同的数字,10000。
我知道我可以使用simplification_quadric_edge_collapse_decimation来减少面数,这意味着顶点数将相应减少。但问题是我必须多次使用该方法才能将顶点数精确到 10000。
因此,我想知道是否有另一种方法可以直接将顶点数减少到10000?
Meshlab,据我所知,任何其他能够简化的库都使用面数作为参数来指导简化过程。
好消息是这两个值都与网格的欧拉特性有关,它粗略地说顶点数是没有孔的表面的面数的一半。将您的网格减少到 20000 个面将生成大约 10000 个顶点的网格,但您也可以轻松地低于 9999。由于您具有使用 python 编程的优势,因此您可以设计一个过程来慢慢收敛到所需的顶点数。
这个想法是将您的网格简化为略高于 20000 的面数,然后慢慢细化您的解决方案,直到您获得正好 10000 个顶点。我建议您使用当前步骤(vertex_number - 10000)上多余的顶点来减少每个步骤中的面数。
import pymeshlab as ml
ms = ml.MeshSet()
ms.load_new_mesh('input.ply')
m = ms.current_mesh()
print('input mesh has', m.vertex_number(), 'vertex and', m.face_number(), 'faces')
#Target number of vertex
TARGET=10000
#Estimate number of faces to have 100+10000 vertex using Euler
numFaces = 100 + 2*TARGET
#Simplify the mesh. Only first simplification will be agressive
while (ms.current_mesh().vertex_number() > TARGET):
ms.apply_filter('simplification_quadric_edge_collapse_decimation', targetfacenum=numFaces, preservenormal=True)
print("Decimated to", numFaces, "faces mesh has", ms.current_mesh().vertex_number(), "vertex")
#Refine our estimation to slowly converge to TARGET vertex number
numFaces = numFaces - (ms.current_mesh().vertex_number() - TARGET)
m = ms.current_mesh()
print('output mesh has', m.vertex_number(), 'vertex and', m.face_number(), 'faces')
ms.save_current_mesh('output.ply')
请注意:
numFaces = numFaces - int(1.5*(ms.current_mesh().vertex_number() - 10000))
,但这会增加在 9999 顶点以下结束的机会,并且执行时间不会受到太大影响。