Developer Documentation
Tutorial 03: Adding Properties

In OpenVolumeMesh it is possible to attach multiple properties to each of the entities. Due to the use of STL template programming, these properties can be of any data type. In this tutorial, we learn how to attach properties to the entities of a polyhedral mesh.

Read Section Generic Dynamic Properties for a detailed description of the property system.

The following example shows how to attach a floating-point property to the vertices of a mesh.

void someFunction() {
// Create mesh object
// Fill mesh with geometry
...
// Add property
myMesh.request_vertex_property<float>("Vertex Weights");
// non-persistent properties get deleted once the last user goes out of scope,
// we set it persistent so we can access it again later:
myMesh.set_persistent(floatProp);
// Now, iterate over all vertices and set property value to some number
float val = 0.0f;
for(const auto vh: myMesh.vertices()) {
// Set property value
floatProp[vh] = val;
// Increase value by 1.5
val += 1.5f;
}
// Call some other function
someOtherFunction(myMesh);
}
void someOtherFunction(OpenVolumeMesh::GeometricPolyhedralMeshV3d& _mesh) {
// Try to get property by its name
OpenVolumeMesh::VertexPropertyT<float> floatProp = _mesh.request_vertex_property<float>("Vertex Weights");
// Now floatProp is a valid property that contains
// the values we have inserted before
// Access a property value via floatProp[vertexHandle].
}

For all other entities, this works the same way. Use class OpenVolumeMesh::EdgePropertyT as edge property, OpenVolumeMesh::HalfFacePropertyT for half-face properties, and so on...

When saving a mesh to a file, only properties marked as persistent will be stored. Additionally, non-standard property types need to be registered with encoder/decoder implementations to be stored in files.

Todo:
Document using a mesh property