OpenMesh Decimater不会减少顶点数

OpenMesh Decimater does not reduce vertex number

本文关键字:顶点 Decimater OpenMesh      更新时间:2023-10-16

我正在尝试使用OpenMesh抽取一个网格。我遵循了文档中所述的示例:

    cout << "Vertices: " << mesh->n_vertices() << endl;
    DecimaterT<Mesh>   decimater(*mesh);  // a decimater object, connected to a mesh
    ModQuadricT<Mesh>::Handle hModQuadric;      // use a quadric module
    decimater.add(hModQuadric); // register module at the decimater
    decimater.initialize();       // let the decimater initialize the mesh and the
                                  // modules
    decimater.decimate_to(15000);         // do decimation
    cout << "Vertices: " << decimater.mesh().n_vertices() << endl;

decimate_to方法正确地终止并返回56000,这是应该折叠的顶点数。

然而,我可以从日志中看出,网格上的顶点数没有改变。这怎么可能?

Decimation通过删除元素(顶点、面等)来更改网格的连接性。OpenMesh中网格元素的删除是通过暂时标记各个元素以进行删除来实现的(使用mesh.status(handle).deleted()属性)。只有当通过调用mesh.garbage_collection()明确请求时,才会实际删除已删除的元素。在垃圾回收之前,mesh.n_vertices()的计数中仍然包括标记为删除的顶点。

Decimator不会自动提示垃圾收集;在decimater.decimate_to(...)之后插入对mesh.garbage_collection()的调用应该可以解决您的问题。