OpenMesh: Doc/Tutorial/09-persistence/fill_props.hh Source File

| OpenMesh

fill_props.hh
1 #ifndef FILL_PROPS_HH
2 #define FILL_PROPS_HH
3
4 #include <OpenMesh/Core/Utils/Property.hh>
5 #include "int2roman.hh"
6
7
8 template <typename Mesh>
9 bool
10 fill_props( Mesh& _m, OpenMesh::VPropHandleT<float> _ph, bool _check=false)
11 {
12 static float a[9] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f };
13
14 for(typename Mesh::VertexIter it=_m.vertices_begin();
15 it != _m.vertices_end(); ++it)
16 {
17 const float v = a[it->idx()%9];
18 if ( _check && !(_m.property( _ph, *it ) == v) )
19 return false;
20 else
21 _m.property( _ph, *it ) = v;
22 }
23 return true;
24 }
25
26
27 template <typename Mesh>
28 bool
29 fill_props( Mesh& _m, OpenMesh::EPropHandleT<bool> _ph, bool _check=false )
30 {
31
32 for( typename Mesh::EdgeIter it=_m.edges_begin();
33 it != _m.edges_end(); ++it)
34 {
35 const size_t n = it->idx();
36 const bool v = ((n&(n-1))==0); // true for 0,1,2,4,8,..
37
38 if (_check && _m.property( _ph, *it ) != v)
39 {
40 std::cout << " eprop_bool: " << n << " -> "
41 << _m.property(_ph, *it ) << " != " << v << std::endl;
42 return false;
43 }
44 else
45 {
46 _m.property( _ph, *it ) = v;
47 std::cout << " eprop_bool: " << n << " -> " << v << std::endl;
48 }
49 }
50 return true;
51 }
52
53
54
55 template <typename Mesh>
56 bool
57 fill_props(Mesh& _m, OpenMesh::FPropHandleT<std::string> _ph, bool _check=false)
58 {
59
60 for( typename Mesh::FaceIter it=_m.faces_begin();
61 it != _m.faces_end(); ++it)
62 {
63 const int n = (it->idx()) + 1;
64 _m.property( _ph, *it ) = int2roman(n);
65 }
66 return true;
67 }
68
69
70 template <typename Mesh, typename T>
71 bool
72 fill_props( Mesh& _m, OpenMesh::HPropHandleT<T> _ph, bool _check=false)
73 {
74 T v;
75 static float a[9] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f };
76 static float b[9] = { 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f };
77 static float c[9] = { 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f };
78 static float d[9] = { 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f, 3.3f };
79 static double values[9] = { 0.1, 0.02, 0.003, 0.0004, 0.00005, 0.000006,
80 0.0000007, 0.00000008, 0.000000009 };
81
82 for( typename Mesh::HalfedgeIter it=_m.halfedges_begin();
83 it != _m.halfedges_end(); ++it)
84 {
85 const int n = it->idx();
86
87 v = it->idx()+1; // ival
88 v = values[n%9]; // dval
89 v = ((n&(n-1))==0); // bval
90 v.vec4fval[0] = a[n%9];
91 v.vec4fval[1] = b[n%9];
92 v.vec4fval[2] = c[n%9];
93 v.vec4fval[3] = d[n%9];
94
95 if ( _check && _m.property( _ph, *it ) != v )
96 return false;
97 else
98 _m.property( _ph, *it ) = v;
99 }
100 return true;
101 }
102
103 template <typename Mesh, typename T>
104 bool
105 fill_props( Mesh& _m, OpenMesh::MPropHandleT<T> _ph, bool _check=false)
106 {
107 for( typename Mesh::FaceIter it=_m.faces_begin(); it != _m.faces_end(); ++it)
108 {
109 const size_t idx = it->idx();
110 if ( _check && _m.property( _ph )[int2roman(idx+1)] != idx )
111 return false;
112 else
113 _m.property( _ph )[int2roman(idx+1)] = idx;
114 }
115 return true;
116 }
117
118
119 #endif
OpenMesh::FPropHandleT
Handle representing a face property.
Definition: Property.hh:529
OpenMesh::VPropHandleT< float >
OpenMesh::EPropHandleT
Handle representing an edge property.
Definition: Property.hh:515
OpenMesh::MPropHandleT
Handle representing a mesh property.
Definition: Property.hh:543
OpenMesh::HPropHandleT
Handle representing a halfedge property.
Definition: Property.hh:501