tutorial_06.docu 3.13 KB
 Jan Möbius committed Feb 06, 2009 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 /** \page tutorial_06 Using mesh attributes and traits this example shows how to change the data type for positions, normals, colors, and texture, In the previous tutorial (\ref tutorial_05) we learned to use standard properties by calling the appropriate \c request method. Unlike the custom properties, where the user specifies the data type by passing the type to the handle (e.g. \c 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 -# changing data type for positions, normals, colors, and texture coordinates -# extend mesh entities Vertex, Face, Edge, and Halfedge (see tutorial '\ref tutorial_07') Let's start. Every custom traits should derive from the default traits \dontinclude 06-attributes/attributes.cc \skipline struct MyTraits As mentioned, we can change the basic data types for the basic types \c MyMesh::Point, \c MyMesh::Normal, \c MyMesh::Color, and \c 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 \c OpenMesh::Vec3f (defined in the \c OpenMesh::DefaultTraits) for positions and normals with \c OpenMesh::Vec3d \skipline Vec3d \skipline Vec3d (In general it's better to have the same scalar type for the point and normal vector, for instance \c 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 \c OpenMesh::DefaultTraits is merely empty. It solely defines the types for \c Point, \c Normal, \c TexCoord, and \c Color and one attribute, that we used implicitly all the time: \skipline HalfedgeAttributes The attribute \c 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: -# fast access to previous halfedge -# increase of memory consumption 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 \skipline HalfedgeAttributes Then we need 8 bytes less per edge, which can be quite a lot as one can derive from the Euler formula (\f$V-E+F=2 (1-g)\f$), that for a regular triangle meshes with genus \f$g=0\f$ the number of edges \f$E\f$ is approximately three times the number of vertices \f$V\f$: \f$E \approx 3 \cdot V\f$. The complete source looks like this: \include 06-attributes/attributes.cc */