Search code examples
c++openmesh

OpenMesh Decimater does not reduce vertex number


I am trying to decimate a mesh using OpenMesh. I followed the very example that is stated in the doc:

    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 method correctly terminates and returns 56,000, which is the number of vertices that should have collapsed.

However, I can tell by the log that the vertex number on the mesh did not change. How is this possible?


Solution

  • Decimation changes the connectivity of the mesh by removing elements (vertices, faces, etc.). Removal of mesh elements in OpenMesh is implemented by tentatively marking the respective elements for deletion (using the mesh.status(handle).deleted() property). The actual removal of deleted elements happens only when explicitly requested, by calling mesh.garbage_collection(). Before garbage collection, mesh.n_vertices() still includes vertices that are marked for deletion in its count.

    The Decimator does not automatically prompt a garbage collection; it is left for the user to do so. Inserting a call to mesh.garbage_collection() after decimater.decimate_to(...) should solve your problem.