OpenMesh
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
unittests_property.hh
1 #ifndef INCLUDE_UNITTESTS_DECIMATER_HH
2 #define INCLUDE_UNITTESTS_DECIMATER_HH
3 
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
6 #include <iostream>
8 
9  protected:
10 
11  // This function is called before each test is run
12  virtual void SetUp() {
13 
14  // Do some initial stuff with the member data here...
15  }
16 
17  // This function is called after all tests are through
18  virtual void TearDown() {
19 
20  // Do some final stuff with the member data here...
21  }
22 
23  // Member already defined in OpenMeshBase
24  //Mesh mesh_;
25 };
26 
27 /*
28  * ====================================================================
29  * Define tests below
30  * ====================================================================
31  */
32 
33 /* Creates a double property and checks if it works
34  */
35 TEST_F(OpenMeshProperties, VertexPropertyCheckDouble) {
36 
37  mesh_.clear();
38 
39  // Add some vertices
40  Mesh::VertexHandle vhandle[4];
41 
42  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
43  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
44  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
45  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
46 
47  // Add two faces
48  std::vector<Mesh::VertexHandle> face_vhandles;
49 
50  face_vhandles.push_back(vhandle[2]);
51  face_vhandles.push_back(vhandle[1]);
52  face_vhandles.push_back(vhandle[0]);
53  mesh_.add_face(face_vhandles);
54 
55  face_vhandles.clear();
56 
57  face_vhandles.push_back(vhandle[2]);
58  face_vhandles.push_back(vhandle[0]);
59  face_vhandles.push_back(vhandle[3]);
60  mesh_.add_face(face_vhandles);
61 
62  // Test setup:
63  // 1 === 2
64  // | / |
65  // | / |
66  // | / |
67  // 0 === 3
68 
69  // Check setup
70  EXPECT_EQ(4, mesh_.n_vertices() ) << "Wrong number of vertices";
71  EXPECT_EQ(2, mesh_.n_faces() ) << "Wrong number of faces";
72 
73  // Add a double vertex property
74  OpenMesh::VPropHandleT<double> doubleHandle;
75 
76  EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") );
77 
78  mesh_.add_property(doubleHandle,"doubleProp");
79 
80  EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
81 
82 
83  // Fill property
84  double index = 0.0;
85 
86  for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
87  mesh_.property(doubleHandle,v_it) = index;
88  index += 1.0;
89  }
90 
91  // Check if it is ok.
92  Mesh::VertexIter v_it = mesh_.vertices_begin();
93  EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 0.0 ) << "Invalid double value for vertex 0";
94  ++v_it;
95 
96  EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 1.0 ) << "Invalid double value for vertex 1";
97  ++v_it;
98 
99  EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 2.0 ) << "Invalid double value for vertex 2";
100  ++v_it;
101 
102  EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 3.0 ) << "Invalid double value for vertex 3";
103 
104  // Try to get the stl iterators:
105  std::vector<double>::iterator it=mesh_.property(doubleHandle).data_vector().begin();
106  std::vector<double>::iterator end=mesh_.property(doubleHandle).data_vector().end();
107 
108  EXPECT_EQ( *it , 0.0 ) << "Invalid double value for vertex 0";
109  ++it;
110 
111  EXPECT_EQ( *it , 1.0 ) << "Invalid double value for vertex 1";
112  ++it;
113 
114  EXPECT_EQ( *it , 2.0 ) << "Invalid double value for vertex 2";
115  ++it;
116 
117  EXPECT_EQ( *it , 3.0 ) << "Invalid double value for vertex 3";
118  ++it;
119 
120  EXPECT_EQ( it, end ) << "End iterator not mathing!";
121 
122 }
123 
124 /* Creates a bool property and checks if it works
125  */
126 TEST_F(OpenMeshProperties, VertexPropertyCheckBool) {
127 
128  mesh_.clear();
129 
130  // Add some vertices
131  Mesh::VertexHandle vhandle[4];
132 
133  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
134  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
135  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
136  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
137 
138  // Add two faces
139  std::vector<Mesh::VertexHandle> face_vhandles;
140 
141  face_vhandles.push_back(vhandle[2]);
142  face_vhandles.push_back(vhandle[1]);
143  face_vhandles.push_back(vhandle[0]);
144  mesh_.add_face(face_vhandles);
145 
146  face_vhandles.clear();
147 
148  face_vhandles.push_back(vhandle[2]);
149  face_vhandles.push_back(vhandle[0]);
150  face_vhandles.push_back(vhandle[3]);
151  mesh_.add_face(face_vhandles);
152 
153  // Test setup:
154  // 1 === 2
155  // | / |
156  // | / |
157  // | / |
158  // 0 === 3
159 
160  // Check setup
161  EXPECT_EQ(4, mesh_.n_vertices() ) << "Wrong number of vertices";
162  EXPECT_EQ(2, mesh_.n_faces() ) << "Wrong number of faces";
163 
164  // Add a double vertex property
165  OpenMesh::VPropHandleT<bool> boolHandle;
166 
167  EXPECT_FALSE( mesh_.get_property_handle(boolHandle,"boolProp") );
168 
169  mesh_.add_property(boolHandle,"boolProp");
170 
171  EXPECT_TRUE(mesh_.get_property_handle(boolHandle,"boolProp"));
172 
173  // Fill property
174  bool current = true;
175 
176  for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
177  mesh_.property(boolHandle,v_it) = current;
178  current = !current;
179  }
180 
181  // Check if it is ok.
182  Mesh::VertexIter v_it = mesh_.vertices_begin();
183  EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 0";
184  ++v_it;
185 
186  EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 1";
187  ++v_it;
188 
189  EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 2";
190  ++v_it;
191 
192  EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) << "Invalid bool value for vertex 3";
193 
194  // Try to get the stl iterators:
195  std::vector<bool>::iterator it=mesh_.property(boolHandle).data_vector().begin();
196  std::vector<bool>::iterator end=mesh_.property(boolHandle).data_vector().end();
197 
198  EXPECT_TRUE( *it ) << "Invalid bool value for vertex 0";
199  ++it;
200 
201  EXPECT_FALSE( *it ) << "Invalid bool value for vertex 1";
202  ++it;
203 
204  EXPECT_TRUE( *it ) << "Invalid bool value for vertex 2";
205  ++it;
206 
207  EXPECT_FALSE( *it ) << "Invalid bool value for vertex 3";
208  ++it;
209 
210  EXPECT_EQ( it, end ) << "End iterator not mathing!";
211 
212 }
213 
214 #endif // INCLUDE GUARD

acg pic Project OpenMesh, ©  Computer Graphics Group, RWTH Aachen. Documentation generated using doxygen .