2

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?

Lake
  • 4,072
  • 26
  • 36

1 Answers1

4

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.

jsb
  • 938
  • 6
  • 15
  • You made my day. Thanks. Do you have any pointer to where it states this behavior on the official docs?^^ – Lake Jul 21 '16 at 10:03
  • 1
    @Lake There's a general explanation on [deleting geometry elements](http://www.openmesh.org/media/Documentations/OpenMesh-6.2-Documentation/a00060.html). Unfortunately, the fact that `decimate_to` does not trigger a garbage collection seems to be only documented by a source code comment in the implementation in `DecimaterT.cpp`. – jsb Jul 21 '16 at 11:03
  • 1
    @Lake As of OpenMesh 6.3, the documentation has been updated accordingly. – jsb Oct 06 '16 at 11:48