Developer Documentation

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 for( typename Mesh::EdgeIter it=_m.edges_begin();
32 it != _m.edges_end(); ++it)
33 {
34 const size_t n = it->idx();
35 const bool v = ((n&(n-1))==0); // true for 0,1,2,4,8,..
36
37 if (_check && _m.property( _ph, it ) != v)
38 {
39 std::cout << " eprop_bool: " << n << " -> "
40 << _m.property(_ph, it ) << " != " << v << std::endl;
41 return false;
42 }
43 else
44 {
45 _m.property( _ph, it ) = v;
46 std::cout << " eprop_bool: " << n << " -> " << v << std::endl;
47 }
48 }
49 return true;
50 }
51
52
53
54 template <typename Mesh>
55 bool
56 fill_props(Mesh& _m, OpenMesh::FPropHandleT<std::string> _ph, bool _check=false)
57 {
58 for( typename Mesh::FaceIter it=_m.faces_begin();
59 it != _m.faces_end(); ++it)
60 {
61 const int n = it->idx();
62 _m.property( _ph, it ) = int2roman(++n);
63 }
64 return true;
65 }
66
67
68 template <typename Mesh, typename T>
69 bool
70 fill_props( Mesh& _m, OpenMesh::HPropHandleT<T> _ph, bool _check=false)
71 {
72 static float a[9] = { 1.1f, 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f };
73 static float b[9] = { 2.2f, 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f };
74 static float c[9] = { 3.3f, 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f };
75 static float d[9] = { 4.4f, 5.5f, 6.6f, 7.7f, 8.8f, 9.9f, 1.1f, 2.2f, 3.3f };
76 // static double values[9] = { 0.1, 0.02, 0.003, 0.0004, 0.00005, 0.000006,
77 // 0.0000007, 0.00000008, 0.000000009 };
78
79 for( typename Mesh::HalfedgeIter it=_m.halfedges_begin();
80 it != _m.halfedges_end(); ++it)
81 {
82 const int n = it->idx();
83
84 // v = it->idx()+1; // ival
85 // v = values[n%9]; // dval
86 T v = ((n&(n-1))==0); // bval
87 v.vec4fval[0] = a[n%9];
88 v.vec4fval[1] = b[n%9];
89 v.vec4fval[2] = c[n%9];
90 v.vec4fval[3] = d[n%9];
91
92 if ( _check && _m.property( _ph, it ) != v )
93 return false;
94 else
95 _m.property( _ph, it ) = v;
96 }
97 return true;
98 }
99
100 template <typename Mesh, typename T>
101 bool
102 fill_props( Mesh& _m, OpenMesh::MPropHandleT<T> _ph, bool _check=false)
103 {
104 for( typename Mesh::FaceIter it=_m.faces_begin(); it != _m.faces_end(); ++it)
105 {
106 const size_t idx = it->idx();
107 if ( _check && _m.property( _ph )[int2roman(idx+1)] != idx )
108 return false;
109 else
110 _m.property( _ph )[int2roman(idx+1)] = idx;
111 }
112 return true;
113 }
114
115
116 #endif
OpenMesh::MPropHandleT
Definition: Property.hh:544
OpenMesh::VPropHandleT< float >
OpenMesh::HPropHandleT
Definition: Property.hh:499
OpenMesh::EPropHandleT
Definition: Property.hh:514
OpenMesh::TriMesh_ArrayKernelT
Definition: PolyMesh_ArrayKernelT.hh:73
OpenMesh::FPropHandleT
Definition: Property.hh:529