Developer Documentation
unittests_property.cc
1 
2 #include <gtest/gtest.h>
3 #include <Unittests/unittests_common.hh>
4 
5 namespace {
6 
7 class OpenMeshProperties : public OpenMeshBase {
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(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
71  EXPECT_EQ(2u, 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(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
162  EXPECT_EQ(2u, 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 /* Creates an int property and checks if it the copy operation works
215  */
216 TEST_F(OpenMeshProperties, VertexPropertyCopypropertiesInt) {
217 
218  mesh_.clear();
219 
220  // Add some vertices
221  Mesh::VertexHandle vhandle[4];
222 
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));
227 
228  // Add two faces
229  std::vector<Mesh::VertexHandle> face_vhandles;
230 
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);
235 
236  face_vhandles.clear();
237 
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);
242 
243  // Test setup:
244  // 1 === 2
245  // | / |
246  // | / |
247  // | / |
248  // 0 === 3
249 
250  // Check setup
251  EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
252  EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces";
253 
254  // Add a double vertex property
255  OpenMesh::VPropHandleT<int> intHandle;
256 
257  EXPECT_FALSE( mesh_.get_property_handle(intHandle,"intProp") );
258 
259  mesh_.add_property(intHandle,"intProp");
260 
261  EXPECT_TRUE(mesh_.get_property_handle(intHandle,"intProp"));
262 
263  // Fill property
264  for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
265  mesh_.property(intHandle,*v_it) = v_it->idx();
266  }
267 
268  // Check if property it is ok.
269  Mesh::VertexIter v_it = mesh_.vertices_begin();
270  EXPECT_EQ( 0, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0";
271  ++v_it;
272 
273  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1";
274  ++v_it;
275 
276  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2";
277  ++v_it;
278 
279  EXPECT_EQ( 3, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3";
280 
281  // Check vertex positions
282  v_it = mesh_.vertices_begin();
283 
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";
287  ++v_it;
288 
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";
292  ++v_it;
293 
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";
297  ++v_it;
298 
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";
302 
303  //===========================================================
304  // Copy from vertex 1 to 0, with skipping build in properties
305  //===========================================================
306  mesh_.copy_all_properties(vhandle[1], vhandle[0]);
307 
308  // Check vertex positions
309  v_it = mesh_.vertices_begin();
310 
311  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 0 after copy";
312  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 0 after copy";
313  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 0 after copy";
314  ++v_it;
315 
316  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 1 after copy";
317  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 1 after copy";
318  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 1 after copy";
319  ++v_it;
320 
321  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 2 after copy";
322  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 2 after copy";
323  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 2 after copy";
324  ++v_it;
325 
326  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 3 after copy";
327  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 3 after copy";
328  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 3 after copy";
329 
330  v_it = mesh_.vertices_begin();
331  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it;
332  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it;
333  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it;
334  EXPECT_EQ( 3, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3 after copy";
335 
336  //===========================================================
337  // Copy from vertex 2 to 3, including build in properties
338  //===========================================================
339  mesh_.copy_all_properties(vhandle[2], vhandle[3], true);
340 
341  // Check vertex positions
342  v_it = mesh_.vertices_begin();
343 
344  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 0 after copy";
345  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 0 after copy";
346  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 0 after copy";
347  ++v_it;
348 
349  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 1 after copy";
350  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 1 after copy";
351  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 1 after copy";
352  ++v_it;
353 
354  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 2 after copy";
355  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 2 after copy";
356  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 2 after copy";
357  ++v_it;
358 
359  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 3 after copy";
360  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 3 after copy";
361  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 3 after copy";
362 
363  v_it = mesh_.vertices_begin();
364  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it;
365  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it;
366  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it;
367  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3 after copy";
368 
369 
370 }
371 
372 /*
373  * Checking for deleted flags of halfedge and edge handles
374  *
375  * Checks if after deleting a face, all halfedges and edges are arked as deleted as well
376 */
377 TEST_F(OpenMeshProperties, CheckStatusPropertiesHalfedgeEdgeAllDeleted) {
378 
379  mesh_.clear();
380 
381  mesh_.request_vertex_status();
382  mesh_.request_face_status();
383  mesh_.request_halfedge_status();
384  mesh_.request_edge_status();
385 
386  // Define positions
387  Mesh::Point p1 = Mesh::Point(0, 0, 0);
388  Mesh::Point p2 = Mesh::Point(0, 1, 0);
389  Mesh::Point p3 = Mesh::Point(1, 1, 0);
390  Mesh::Point p4 = Mesh::Point(0, 0, 1);
391 
392  // Add some vertices
393  Mesh::VertexHandle vh1 = mesh_.add_vertex(p1);
394  Mesh::VertexHandle vh2 = mesh_.add_vertex(p2);
395  Mesh::VertexHandle vh3 = mesh_.add_vertex(p3);
396  Mesh::VertexHandle vh4 = mesh_.add_vertex(p4);
397 
398  // Add some faces
399  Mesh::FaceHandle f1 = mesh_.add_face(vh1,vh3,vh2);
400  Mesh::FaceHandle f2 = mesh_.add_face(vh1,vh2,vh4);
401  Mesh::FaceHandle f3 = mesh_.add_face(vh2,vh3,vh4);
402  Mesh::FaceHandle f4 = mesh_.add_face(vh3,vh1,vh4);
403 
404  // delete all faces
405  mesh_.delete_face(f1);
406  mesh_.delete_face(f2);
407  mesh_.delete_face(f3);
408  mesh_.delete_face(f4);
409 
410  for( Mesh::ConstHalfedgeIter he_it = mesh_.halfedges_begin(); he_it != mesh_.halfedges_end(); ++he_it)
411  {
412  EXPECT_TRUE( mesh_.status(mesh_.edge_handle(*he_it)).deleted() ) << "Edge not deleted";
413  EXPECT_TRUE( mesh_.status(*he_it).deleted() ) << "Halfedge not deleted";
414  }
415 
416 }
417 
418 /*
419  * Copy properties from one mesh to another
420  *
421 */
422 TEST_F(OpenMeshProperties, CopyAllPropertiesVertexAfterRemoveOfProperty) {
423 
424  mesh_.clear();
425 
426  // Add some vertices
427  Mesh::VertexHandle vhandle[4];
428 
429  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
430  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
431  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
432  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
433 
434  // Add two faces
435  std::vector<Mesh::VertexHandle> face_vhandles;
436 
437  face_vhandles.push_back(vhandle[2]);
438  face_vhandles.push_back(vhandle[1]);
439  face_vhandles.push_back(vhandle[0]);
440  mesh_.add_face(face_vhandles);
441 
442  face_vhandles.clear();
443 
444  face_vhandles.push_back(vhandle[2]);
445  face_vhandles.push_back(vhandle[0]);
446  face_vhandles.push_back(vhandle[3]);
447  mesh_.add_face(face_vhandles);
448 
449  // Test setup:
450  // 1 === 2
451  // | / |
452  // | / |
453  // | / |
454  // 0 === 3
455 
456  // Check setup
457  EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
458  EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces";
459 
460  // Add a double vertex property
461  OpenMesh::VPropHandleT<double> doubleHandle;
462 
463  EXPECT_FALSE( mesh_.get_property_handle(doubleHandle,"doubleProp") );
464 
465  mesh_.add_property(doubleHandle,"doubleProp");
466 
467  EXPECT_TRUE(mesh_.get_property_handle(doubleHandle,"doubleProp"));
468 
469  // Add a double vertex property
470  OpenMesh::VPropHandleT<int> intHandle;
471 
472  EXPECT_FALSE( mesh_.get_property_handle(intHandle,"intProp") );
473 
474  mesh_.add_property(intHandle,"intProp");
475 
476  EXPECT_TRUE(mesh_.get_property_handle(intHandle,"intProp"));
477 
478  // Now remove the double property again.
479  mesh_.remove_property(doubleHandle);
480 
481  // Fill int property
482  for ( Mesh::VertexIter v_it = mesh_.vertices_begin() ; v_it != mesh_.vertices_end(); ++v_it ) {
483  mesh_.property(intHandle,*v_it) = v_it->idx();
484  }
485 
486  // Check if property it is ok.
487  Mesh::VertexIter v_it = mesh_.vertices_begin();
488  EXPECT_EQ( 0, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0";
489  ++v_it;
490 
491  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1";
492  ++v_it;
493 
494  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2";
495  ++v_it;
496 
497  EXPECT_EQ( 3, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3";
498 
499  // Check vertex positions
500  v_it = mesh_.vertices_begin();
501 
502  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 0";
503  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 0";
504  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 0";
505  ++v_it;
506 
507  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 1";
508  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 1";
509  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 1";
510  ++v_it;
511 
512  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 2";
513  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 2";
514  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 2";
515  ++v_it;
516 
517  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 3";
518  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 3";
519  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 3";
520 
521  //===========================================================
522  // Copy from vertex 1 to 0, with skipping build in properties
523  //===========================================================
524  mesh_.copy_all_properties(vhandle[1], vhandle[0]);
525 
526  // Check vertex positions
527  v_it = mesh_.vertices_begin();
528 
529  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 0 after copy";
530  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 0 after copy";
531  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 0 after copy";
532  ++v_it;
533 
534  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 1 after copy";
535  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 1 after copy";
536  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 1 after copy";
537  ++v_it;
538 
539  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 2 after copy";
540  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 2 after copy";
541  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 2 after copy";
542  ++v_it;
543 
544  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 3 after copy";
545  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 3 after copy";
546  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 3 after copy";
547 
548  v_it = mesh_.vertices_begin();
549  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it;
550  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it;
551  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it;
552  EXPECT_EQ( 3, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3 after copy";
553 
554  //===========================================================
555  // Copy from vertex 2 to 3, including build in properties
556  //===========================================================
557  mesh_.copy_all_properties(vhandle[2], vhandle[3], true);
558 
559  // Check vertex positions
560  v_it = mesh_.vertices_begin();
561 
562  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 0 after copy";
563  EXPECT_EQ( 0, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 0 after copy";
564  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 0 after copy";
565  ++v_it;
566 
567  EXPECT_EQ( 0, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 1 after copy";
568  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 1 after copy";
569  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 1 after copy";
570  ++v_it;
571 
572  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 2 after copy";
573  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 2 after copy";
574  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 2 after copy";
575  ++v_it;
576 
577  EXPECT_EQ( 1, mesh_.point(*v_it)[0] ) << "Invalid x position for vertex 3 after copy";
578  EXPECT_EQ( 1, mesh_.point(*v_it)[1] ) << "Invalid y position for vertex 3 after copy";
579  EXPECT_EQ( 0, mesh_.point(*v_it)[2] ) << "Invalid z position for vertex 3 after copy";
580 
581  v_it = mesh_.vertices_begin();
582  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 0 after copy"; ++v_it;
583  EXPECT_EQ( 1, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 1 after copy"; ++v_it;
584  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 2 after copy"; ++v_it;
585  EXPECT_EQ( 2, mesh_.property(intHandle,*v_it) ) << "Invalid int value for vertex 3 after copy";
586 
587 
588 
589 }
590 
591 /* Creates a double and int properties and check if we can iterate across them
592  */
593 TEST_F(OpenMeshProperties, PropertyIterators ) {
594 
595  mesh_.clear();
596 
597  // Add some vertices
598  Mesh::VertexHandle vhandle[4];
599 
600  vhandle[0] = mesh_.add_vertex(Mesh::Point(0, 0, 0));
601  vhandle[1] = mesh_.add_vertex(Mesh::Point(0, 1, 0));
602  vhandle[2] = mesh_.add_vertex(Mesh::Point(1, 1, 0));
603  vhandle[3] = mesh_.add_vertex(Mesh::Point(1, 0, 0));
604 
605  // Add two faces
606  std::vector<Mesh::VertexHandle> face_vhandles;
607 
608  face_vhandles.push_back(vhandle[2]);
609  face_vhandles.push_back(vhandle[1]);
610  face_vhandles.push_back(vhandle[0]);
611  mesh_.add_face(face_vhandles);
612 
613  face_vhandles.clear();
614 
615  face_vhandles.push_back(vhandle[2]);
616  face_vhandles.push_back(vhandle[0]);
617  face_vhandles.push_back(vhandle[3]);
618  mesh_.add_face(face_vhandles);
619 
620  // Test setup:
621  // 1 === 2
622  // | / |
623  // | / |
624  // | / |
625  // 0 === 3
626 
627  // Check setup
628  EXPECT_EQ(4u, mesh_.n_vertices() ) << "Wrong number of vertices";
629  EXPECT_EQ(2u, mesh_.n_faces() ) << "Wrong number of faces";
630 
631 
632  // Add vertex properties
633  OpenMesh::VPropHandleT<double> doubleHandleV;
635 
636  EXPECT_FALSE( mesh_.get_property_handle(doubleHandleV,"doublePropV") );
637  EXPECT_FALSE( mesh_.get_property_handle(intHandleV,"intPropV") );
638 
639  mesh_.add_property(doubleHandleV,"doublePropV");
640  mesh_.add_property(intHandleV,"intPropV");
641 
642  EXPECT_TRUE(mesh_.get_property_handle(doubleHandleV,"doublePropV"));
643  EXPECT_TRUE(mesh_.get_property_handle(intHandleV,"intPropV"));
644 
645  // Add a double Edge properties
646  OpenMesh::EPropHandleT<double> doubleHandleE;
648 
649  EXPECT_FALSE( mesh_.get_property_handle(doubleHandleE,"doublePropE") );
650  EXPECT_FALSE( mesh_.get_property_handle(intHandleE,"intPropE") );
651 
652  mesh_.add_property(doubleHandleE,"doublePropE");
653  mesh_.add_property(intHandleE,"intPropE");
654 
655  EXPECT_TRUE(mesh_.get_property_handle(doubleHandleE,"doublePropE"));
656  EXPECT_TRUE(mesh_.get_property_handle(intHandleE,"intPropE"));
657 
658 
659  // Add Face properties
660  OpenMesh::FPropHandleT<double> doubleHandleF;
662 
663  EXPECT_FALSE( mesh_.get_property_handle(doubleHandleF,"doublePropF") );
664  EXPECT_FALSE( mesh_.get_property_handle(intHandleF,"intPropF") );
665 
666  mesh_.add_property(doubleHandleF,"doublePropF");
667  mesh_.add_property(intHandleF,"intPropF");
668 
669  EXPECT_TRUE(mesh_.get_property_handle(doubleHandleF,"doublePropF"));
670  EXPECT_TRUE(mesh_.get_property_handle(intHandleF,"intPropF"));
671 
672 
673 
674 
675  unsigned int vertex_props = 0;
676  for (Mesh::prop_iterator vprop_it = mesh_.vprops_begin() ; vprop_it != mesh_.vprops_end(); ++vprop_it) {
677  switch (vertex_props) {
678  case 0:
679  EXPECT_EQ ("v:points",(*vprop_it)->name()) << "Wrong Vertex property name";
680  break;
681  case 1:
682  EXPECT_EQ ("<vprop>",(*vprop_it)->name()) << "Wrong Vertex property name";
683  break;
684  case 2:
685  EXPECT_EQ ("doublePropV",(*vprop_it)->name()) << "Wrong Vertex property name";
686  break;
687  case 3:
688  EXPECT_EQ ("intPropV",(*vprop_it)->name()) << "Wrong Vertex property name";
689  break;
690  default:
691  EXPECT_EQ (4u , vertex_props);
692  break;
693  }
694  ++vertex_props;
695  }
696 
697  EXPECT_EQ (4u,vertex_props) << "Wrong number of vertex properties";
698 
699 
700 
701  unsigned int edge_props = 0;
702  for (Mesh::prop_iterator eprop_it = mesh_.eprops_begin() ; eprop_it != mesh_.eprops_end(); ++eprop_it) {
703  switch (edge_props) {
704  case 0:
705  EXPECT_EQ ("<eprop>",(*eprop_it)->name()) << "Wrong Edge property name";
706  break;
707  case 1:
708  EXPECT_EQ ("doublePropE",(*eprop_it)->name()) << "Wrong Edge property name";
709  break;
710  case 2:
711  EXPECT_EQ ("intPropE",(*eprop_it)->name()) << "Wrong Edge property name";
712  break;
713  default:
714  EXPECT_EQ (4u , edge_props);
715  break;
716  }
717  ++edge_props;
718  }
719 
720  EXPECT_EQ (3u,edge_props) << "Wrong number of edge properties";
721 
722 
723 
724  unsigned int face_props = 0;
725  for (Mesh::prop_iterator prop_it = mesh_.fprops_begin() ; prop_it != mesh_.fprops_end(); ++prop_it) {
726  switch (face_props) {
727  case 0:
728  EXPECT_EQ ("<fprop>",(*prop_it)->name()) << "Wrong Face property name";
729  break;
730  case 1:
731  EXPECT_EQ ("doublePropF",(*prop_it)->name()) << "Wrong Face property name";
732  break;
733  case 2:
734  EXPECT_EQ ("intPropF",(*prop_it)->name()) << "Wrong Face property name";
735  break;
736  default:
737  EXPECT_EQ (4u , face_props);
738  break;
739  }
740  ++face_props;
741  }
742 
743  EXPECT_EQ (3u,face_props) << "Wrong number of face properties";
744 
745 
746 }
747 
748 
749 
750 }
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.
Definition: PolyMeshT.hh:139
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Definition: PolyMeshT.hh:236
Kernel::Point Point
Coordinate type.
Definition: PolyMeshT.hh:115