OpenMesh
Using custom properties (old style)

This small code example shows how to attach and access additional properties on a mesh.

Note that this is an old style of using properties. Nowadays you should use the OpenMesh::PropertyManager instead.

When you want to add an additional properties you have to attach it to a primitive of the mesh. You can attach to verticies, halfedges, edges, faces or to the mesh itself. Use the add_property function:

// for each vertex an extra double value
mesh.add_property( vprop_double ,"Vertex property name");
// for each halfedge an extra int value
OpenMesh::HEPropHandleT< int > heprop_int;
mesh.add_property( heprop_int ,"Halfedge property name");
// for each edge an extra float value
mesh.add_property( eprop_float ,"Edge property name");
// for each face an extra double value
mesh.add_property( fprop_double ,"Face property name");
// for the mesh an extra string
mesh.add_property( mprop_string , "Mesh property name ");

Accessing to the property is available via the property function. This function gets the property handle (created above) and a handle (e.g. to a vertex or a face):

// Write something to a face property:
mesh->property( <FaceProperty> , <FaceHandle> ) = <new value>;
// E.g.
for (f_it=mesh->faces_begin(); f_it!=mesh->faces_end() ; ++f_it) {
mesh->property( fprop_double , *f_it ) = 0.0;
}

As you can attach properties to the mesh, you might want to add a property in one function and access it in another, where the handle is not yet available. You can retrieve the required handle in the following way (Note that the handles are accessed by their name and type):

// Specify handle type (Double face handle in this case):
// Try to get handle with the given name.
if ( !mesh_.get_property_handle(fprop_double,"Face property name") ) {
std::cerr << "Unable to retrieve property! " << std::endl;
return
}
// If we reach this point, we have a valid handle.

The properties can be removed by calling remove_property:

// Remove the property
mesh->remove_property(fprop_double);

A useful function to see all properties on the mesh is:

// Print all available properties
mesh->property_stats();

A useful class for handling properties and their lifetime is the OpenMesh::PropertyManager.


Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .