1 #ifndef INCLUDE_UNITTESTS_PROPERTY_HH
2 #define INCLUDE_UNITTESTS_PROPERTY_HH
4 #include <gtest/gtest.h>
5 #include <Unittests/unittests_common.hh>
12 virtual void SetUp() {
18 virtual void TearDown() {
40 Mesh::VertexHandle vhandle[4];
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));
48 std::vector<Mesh::VertexHandle> face_vhandles;
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);
55 face_vhandles.clear();
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);
70 EXPECT_EQ(4u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
71 EXPECT_EQ(2u, mesh_.n_faces() ) <<
"Wrong number of faces";
76 EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,
"doubleProp") );
78 mesh_.add_property(doubleHandle,
"doubleProp");
80 EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,
"doubleProp"));
86 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
87 mesh_.property(doubleHandle,v_it) = index;
92 Mesh::VertexIter v_it = mesh_.vertices_begin();
93 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 0.0 ) <<
"Invalid double value for vertex 0";
96 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 1.0 ) <<
"Invalid double value for vertex 1";
99 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 2.0 ) <<
"Invalid double value for vertex 2";
102 EXPECT_EQ( mesh_.property(doubleHandle,v_it) , 3.0 ) <<
"Invalid double value for vertex 3";
105 std::vector<double>::iterator it=mesh_.property(doubleHandle).data_vector().begin();
106 std::vector<double>::iterator end=mesh_.property(doubleHandle).data_vector().end();
108 EXPECT_EQ( *it , 0.0 ) <<
"Invalid double value for vertex 0";
111 EXPECT_EQ( *it , 1.0 ) <<
"Invalid double value for vertex 1";
114 EXPECT_EQ( *it , 2.0 ) <<
"Invalid double value for vertex 2";
117 EXPECT_EQ( *it , 3.0 ) <<
"Invalid double value for vertex 3";
120 EXPECT_EQ( it, end ) <<
"End iterator not mathing!";
131 Mesh::VertexHandle vhandle[4];
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));
139 std::vector<Mesh::VertexHandle> face_vhandles;
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);
146 face_vhandles.clear();
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);
161 EXPECT_EQ(4u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
162 EXPECT_EQ(2u, mesh_.n_faces() ) <<
"Wrong number of faces";
167 EXPECT_FALSE( mesh_.get_property_handle(boolHandle,
"boolProp") );
169 mesh_.add_property(boolHandle,
"boolProp");
171 EXPECT_TRUE(mesh_.get_property_handle(boolHandle,
"boolProp"));
176 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
177 mesh_.property(boolHandle,v_it) = current;
182 Mesh::VertexIter v_it = mesh_.vertices_begin();
183 EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) <<
"Invalid bool value for vertex 0";
186 EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) <<
"Invalid bool value for vertex 1";
189 EXPECT_TRUE( mesh_.property(boolHandle,v_it) ) <<
"Invalid bool value for vertex 2";
192 EXPECT_FALSE( mesh_.property(boolHandle,v_it) ) <<
"Invalid bool value for vertex 3";
195 std::vector<bool>::iterator it=mesh_.property(boolHandle).data_vector().begin();
196 std::vector<bool>::iterator end=mesh_.property(boolHandle).data_vector().end();
198 EXPECT_TRUE( *it ) <<
"Invalid bool value for vertex 0";
201 EXPECT_FALSE( *it ) <<
"Invalid bool value for vertex 1";
204 EXPECT_TRUE( *it ) <<
"Invalid bool value for vertex 2";
207 EXPECT_FALSE( *it ) <<
"Invalid bool value for vertex 3";
210 EXPECT_EQ( it, end ) <<
"End iterator not mathing!";
221 Mesh::VertexHandle vhandle[4];
223 vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
224 vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
225 vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
226 vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
229 std::vector<Mesh::VertexHandle> face_vhandles;
231 face_vhandles.push_back(vhandle[2]);
232 face_vhandles.push_back(vhandle[1]);
233 face_vhandles.push_back(vhandle[0]);
234 mesh_.add_face(face_vhandles);
236 face_vhandles.clear();
238 face_vhandles.push_back(vhandle[2]);
239 face_vhandles.push_back(vhandle[0]);
240 face_vhandles.push_back(vhandle[3]);
241 mesh_.add_face(face_vhandles);
251 EXPECT_EQ(4u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
252 EXPECT_EQ(2u, mesh_.n_faces() ) <<
"Wrong number of faces";
257 EXPECT_FALSE( mesh_.get_property_handle(intHandle,
"intProp") );
259 mesh_.add_property(intHandle,
"intProp");
261 EXPECT_TRUE(mesh_.get_property_handle(intHandle,
"intProp"));
264 for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
265 mesh_.property(intHandle,v_it) = v_it.handle().idx();
269 Mesh::VertexIter v_it = mesh_.vertices_begin();
270 EXPECT_EQ( 0, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 0";
273 EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 1";
276 EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 2";
279 EXPECT_EQ( 3, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 3";
282 v_it = mesh_.vertices_begin();
284 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 0";
285 EXPECT_EQ( 0, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 0";
286 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 0";
289 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 1";
290 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 1";
291 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 1";
294 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 2";
295 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 2";
296 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 2";
299 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 3";
300 EXPECT_EQ( 0, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 3";
301 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 3";
307 mesh_.copy_all_properties(vhandle[1], vhandle[0]);
310 v_it = mesh_.vertices_begin();
312 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 0 after copy";
313 EXPECT_EQ( 0, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 0 after copy";
314 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 0 after copy";
317 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 1 after copy";
318 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 1 after copy";
319 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 1 after copy";
322 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 2 after copy";
323 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 2 after copy";
324 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 2 after copy";
327 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 3 after copy";
328 EXPECT_EQ( 0, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 3 after copy";
329 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 3 after copy";
332 v_it = mesh_.vertices_begin();
333 EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 0 after copy"; ++v_it;
334 EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 1 after copy"; ++v_it;
335 EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 2 after copy"; ++v_it;
336 EXPECT_EQ( 3, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 3 after copy";
341 mesh_.copy_all_properties(vhandle[2], vhandle[3],
true);
344 v_it = mesh_.vertices_begin();
346 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 0 after copy";
347 EXPECT_EQ( 0, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 0 after copy";
348 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 0 after copy";
351 EXPECT_EQ( 0, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 1 after copy";
352 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 1 after copy";
353 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 1 after copy";
356 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 2 after copy";
357 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 2 after copy";
358 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 2 after copy";
361 EXPECT_EQ( 1, mesh_.point(v_it)[0] ) <<
"Invalid x position for vertex 3 after copy";
362 EXPECT_EQ( 1, mesh_.point(v_it)[1] ) <<
"Invalid y position for vertex 3 after copy";
363 EXPECT_EQ( 0, mesh_.point(v_it)[2] ) <<
"Invalid z position for vertex 3 after copy";
366 v_it = mesh_.vertices_begin();
367 EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 0 after copy"; ++v_it;
368 EXPECT_EQ( 1, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 1 after copy"; ++v_it;
369 EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 2 after copy"; ++v_it;
370 EXPECT_EQ( 2, mesh_.property(intHandle,v_it) ) <<
"Invalid int value for vertex 3 after copy";
384 mesh_.request_vertex_status();
385 mesh_.request_face_status();
386 mesh_.request_halfedge_status();
387 mesh_.request_edge_status();
390 Mesh::Point p1 = Mesh::Point(0, 0, 0);
391 Mesh::Point p2 = Mesh::Point(0, 1, 0);
392 Mesh::Point p3 = Mesh::Point(1, 1, 0);
393 Mesh::Point p4 = Mesh::Point(0, 0, 1);
396 Mesh::VertexHandle vh1 = mesh_.add_vertex(p1);
397 Mesh::VertexHandle vh2 = mesh_.add_vertex(p2);
398 Mesh::VertexHandle vh3 = mesh_.add_vertex(p3);
399 Mesh::VertexHandle vh4 = mesh_.add_vertex(p4);
402 Mesh::FaceHandle f1 = mesh_.add_face(vh1,vh3,vh2);
403 Mesh::FaceHandle f2 = mesh_.add_face(vh1,vh2,vh4);
404 Mesh::FaceHandle f3 = mesh_.add_face(vh2,vh3,vh4);
405 Mesh::FaceHandle f4 = mesh_.add_face(vh3,vh1,vh4);
408 mesh_.delete_face(f1);
409 mesh_.delete_face(f2);
410 mesh_.delete_face(f3);
411 mesh_.delete_face(f4);
413 for( Mesh::ConstHalfedgeIter he_it = mesh_.halfedges_begin(); he_it != mesh_.halfedges_end(); ++he_it)
415 EXPECT_TRUE( mesh_.status(mesh_.edge_handle(he_it.handle())).deleted() ) <<
"Edge not deleted";
416 EXPECT_TRUE( mesh_.status(he_it.handle()).deleted() ) <<
"Halfedge not deleted";
422 #endif // INCLUDE GUARD