Search code examples
c++graphicsopenmesh

Remove a property by name in OpenMesh


In OpenMesh, once a named property is added to an element, it will be permanent in the sense that the property survives the scope of the property manager as explained here. My question is, how to remove such a property by its name?

So far I tried removing by the property manager and even this one fails:

auto face_props = OpenMesh::FProp<FaceProp>(mesh, "face_props");
mesh.remove_property(face_props);

with the error

error: no matching function for call to ‘OpenMesh::TriMesh_ArrayKernelT<>::remove_property(OpenMesh::PropertyManager<OpenMesh::FPropHandleT<FaceProp>, int>&)’

Is there a remove_property function where I could write remove_property("face_props") (or similar) to remove the property?

Edit: The following gives the same error:

mesh.remove_property( OpenMesh::getProperty<OpenMesh::FaceHandle, FaceProp>(mesh, "face_props") );

I suspect that mesh.remove_property() expects a property handle object, but getProperty() returns a property manager. I don't see how to get around this.

Edit2: I guess an alternative question would be: how to get a property handle to a property from a property manager?

Edit3: Looking at the source, it seems like PropertyManager has a member function deleteProperty() but a) is private and b) it only deletes the property if retain is not set which I assume would be set for named properties.


Solution

  • Apparently one can define a lower level property handle and then use get_property_handle which takes a handle as reference and updates it in place. This works:

        OpenMesh::FPropHandleT< FaceProp > fprop;
        mesh.get_property_handle(fprop, "face_props");
        mesh.remove_property( fprop );
    

    I wish this was better documented. Or that I was better in C++.