tutorial_03.docu 1.95 KB
Newer Older
Jan Möbius's avatar
Jan Möbius committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
/** \page tutorial_03 Using (custom) properties

This examples shows:
- How to add and remove custom properties,
- How to get and set the value of a custom property

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
Mike Kremer's avatar
Mike Kremer committed
18
\c property(..) via a handle and an entity handle
Jan Möbius's avatar
Jan Möbius committed
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
(e.g. VertexHandle). Whereas the standard properties are accessed via
special member functions, e.g. the vertex position is accessed with \c
point(..) and a vertex handle.

In this example we will store the \c 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 (\c MyMesh::Point) and register the handle at the mesh:

\dontinclude 03-properties/smooth.cc
\skipline vertex property stores
\until mesh.add

<br>The \c mesh allocates enough memory to hold as many elements of type
\c 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 \c v_it

\dontinclude 03-properties/smooth.cc
\skipline vv_it=
\until }
\until mesh.prop

<br>and finally set the new position for each vertex \c v_it

\dontinclude 03-properties/smooth.cc
\skipline mesh.set_point

<br>Below is the complete source code:

\include 03-properties/smooth.cc

*/