this example shows how to change the data type for positions, normals, colors, and texture,
In the previous tutorial (Using standard properties) we learned to use standard properties by calling the appropriate
request method. Unlike the custom properties, where the user specifies the data type by passing the type to the handle (e.g.
MyMesh::FPropHandleT< int>), the data types of the standard properties are defined by so-called mesh traits. With traits we can customize and extend the mesh data structure. We can do this by changing two important features
Let's start. Every custom traits should derive from the default traits
As mentioned, we can change the basic data types for the basic types
MyMesh::TexCoord. We can use the provided vector class or we use a different one from another library. Here we simply replace the default type
OpenMesh::Vec3f (defined in the
OpenMesh::DefaultTraits) for positions and normals with
(In general it's better to have the same scalar type for the point and normal vector, for instance
double in this case. Otherwise we have to cast quite a lot depending on the implementation of the vector class.)
Be aware that these settings overwrite the ones of the parent traits class! As we usually derive from the DefaultTraits let's have a close look.
Actually the struct
OpenMesh::DefaultTraits is merely empty. It solely defines the types for
Color and one attribute, that we used implicitly all the time:
PrevHalfedge is different, as it does not control a property. Yet it has a great impact on the resulting mesh type, as it adds additional information to the halfedge structure. The impact is twofold:
Using this feature depends highly on our needs. One situation where the previous halfedges are quite handy, is the mesh member function add_face(). The execution time for the member function drops dramatically, when the information about the previous halfedge is available. Usually we want to have this information. But if not, because we must save memory, we can easily remove it with
Then we need 8 bytes less per edge, which can be quite a lot as one can derive from the Euler formula ( ), that for a regular triangle meshes with genus the number of edges is approximately three times the number of vertices : .
The complete source looks like this: