This examples shows:
In the last example we computed the barycenter of each vertex' neighborhood and stored it in an array. It would be more convenient and less error-prone if we could store this data in the mesh and let OpenMesh manage the data. It would be even more helpful if we could attach such properties dynamically to the mesh.
OpenMesh provides dynamic properties, which can be attached to each mesh entity (vertex, face, edge, halfedge, and the mesh itself). We distinguish between custom and standard properties. A custom property is any user-defined property and is accessed via the member function
property(..) via a handle and an entity handle (e.g. VertexHandle). Whereas the standard properties are accessed via special member functions, e.g. the vertex position is accessed with
point(..) and a vertex handle.
In this example we will store the
cog-value (see previous example) in an additional vertex property instead of keeping it in a separate array. To do so we define first a so-called property handle with the desired type (
MyMesh::Point) and register the handle at the mesh:
mesh allocates enough memory to hold as many elements of type
MyMesh::Point as number of vertices exist, and of course the mesh synchronizes all insert and delete operations on the vertices with the vertex properties.
Once the wanted property is registered we can use the property to calculate the barycenter of the neighborhood of each vertex
and finally set the new position for each vertex
Below is the complete source code: