Loading...
Searching...
No Matches
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
OpenMesh::VPropHandleT< double > vprop_double;
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
OpenMesh::EPropHandleT< float > eprop_float;
mesh.add_property( eprop_float ,"Edge property name");
// for each face an extra double value
OpenMesh::FPropHandleT< double > fprop_double;
mesh.add_property( fprop_double ,"Face property name");
// for the mesh an extra string
OpenMesh::MPropHandleT< string > mprop_string;
mesh.add_property( mprop_string , "Mesh property name ");
OpenMesh::VPropHandleT
Handle representing a vertex property.
Definition Property.hh:417
OpenMesh::EPropHandleT
Handle representing an edge property.
Definition Property.hh:447
OpenMesh::FPropHandleT
Handle representing a face property.
Definition Property.hh:462
OpenMesh::MPropHandleT
Handle representing a mesh property.
Definition Property.hh:477

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):
OpenMesh::FPropHandleT< double > fprop_double;
// 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.