OpenMesh Decimater 不减少顶点数

OpenMesh Decimater does not reduce vertex number

我正在尝试使用 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 方法正确终止并且 returns 56,000,这是应该折叠的顶点数。

但是,我可以从日志中看出网格上的顶点编号没有改变。 这怎么可能?

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

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