OpenMesh

- Main Page
- Related Pages
- Modules
- Namespaces
- Classes
- Files

- File List
- File Members

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