1 #include <gtest/gtest.h>
2 #include <Unittests/unittests_common.hh>
13 virtual void SetUp() {
17 virtual void TearDown() {
35 TEST_F(OpenMeshIterators, VertexIter) {
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);
69 Mesh::VertexIter v_it = mesh_.vertices_begin();
70 Mesh::VertexIter v_end = mesh_.vertices_end();
72 EXPECT_EQ(0, v_it->idx()) <<
"Index wrong for vertex iterator vertices_begin()";
74 EXPECT_EQ(1, v_it->idx()) <<
"Index wrong in vertex iterator";
76 EXPECT_EQ(2, v_it->idx()) <<
"Index wrong in vertex iterator";
78 EXPECT_EQ(3, v_it->idx()) <<
"Index wrong in vertex iterator";
80 EXPECT_EQ(4, v_it->idx()) <<
"Index wrong in vertex iterator";
83 EXPECT_EQ(4, v_end->idx()) <<
"Index wrong in vertex iterator for vertices_end()";
93 TEST_F(OpenMeshIterators, VertexIterStartPosition) {
106 std::vector<Mesh::VertexHandle> face_vhandles;
108 face_vhandles.push_back(vhandle[2]);
109 face_vhandles.push_back(vhandle[1]);
110 face_vhandles.push_back(vhandle[0]);
111 mesh_.add_face(face_vhandles);
113 face_vhandles.clear();
115 face_vhandles.push_back(vhandle[2]);
116 face_vhandles.push_back(vhandle[0]);
117 face_vhandles.push_back(vhandle[3]);
118 mesh_.add_face(face_vhandles);
127 Mesh::VertexIter v_it = Mesh::VertexIter(mesh_,mesh_.vertex_handle(2));
128 Mesh::VertexIter v_end = mesh_.vertices_end();
130 EXPECT_EQ(2, v_it->idx()) <<
"Index wrong in vertex iterator";
132 EXPECT_EQ(3, v_it->idx()) <<
"Index wrong in vertex iterator";
134 EXPECT_EQ(4, v_it->idx()) <<
"Index wrong in vertex iterator";
137 EXPECT_EQ(4, v_end->idx()) <<
"Index wrong in vertex iterator for vertices_end()";
146 TEST_F(OpenMeshIterators, VertexIterContinueAfterEnd) {
159 std::vector<Mesh::VertexHandle> face_vhandles;
161 face_vhandles.push_back(vhandle[2]);
162 face_vhandles.push_back(vhandle[1]);
163 face_vhandles.push_back(vhandle[0]);
164 mesh_.add_face(face_vhandles);
166 face_vhandles.clear();
168 face_vhandles.push_back(vhandle[2]);
169 face_vhandles.push_back(vhandle[0]);
170 face_vhandles.push_back(vhandle[3]);
171 mesh_.add_face(face_vhandles);
184 EXPECT_FALSE( mesh_.get_property_handle(intHandle,
"intProp") );
185 mesh_.add_property(intHandle,
"intProp");
189 for (Mesh::VertexIter v_it = mesh_.vertices_begin(); v_it != mesh_.vertices_end() ; ++ v_it) {
190 mesh_.property(intHandle,*v_it) = i;
195 EXPECT_TRUE(mesh_.get_property_handle(intHandle,
"intProp"));
198 Mesh::VertexIter old_end = mesh_.vertices_end();
201 for (
unsigned int j = 0 ; j < 4 ; ++j ) {
203 mesh_.property(intHandle,vh) = i;
210 for ( Mesh::VertexIter
test = old_end ;
test != mesh_.vertices_end() ; ++
test ) {
211 EXPECT_EQ( mesh_.property(intHandle,*
test) , i);
220 TEST_F(OpenMeshIterators, EdgeIter) {
233 std::vector<Mesh::VertexHandle> face_vhandles;
235 face_vhandles.push_back(vhandle[2]);
236 face_vhandles.push_back(vhandle[1]);
237 face_vhandles.push_back(vhandle[0]);
238 mesh_.add_face(face_vhandles);
240 face_vhandles.clear();
242 face_vhandles.push_back(vhandle[2]);
243 face_vhandles.push_back(vhandle[0]);
244 face_vhandles.push_back(vhandle[3]);
245 mesh_.add_face(face_vhandles);
255 Mesh::EdgeIter e_it = mesh_.edges_begin();
256 Mesh::EdgeIter e_end = mesh_.edges_end();
258 EXPECT_EQ(0, e_it->idx()) <<
"Wrong start index in edge iterator";
259 EXPECT_EQ(5, e_end->idx()) <<
"Wrong end index in edge iterator";
261 EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"1: Wrong to vertex handle of halfedge 0";
262 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"1: Wrong from vertex handle of halfedge 0";
263 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"1: Wrong to vertex handle of halfedge 1";
264 EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"1: Wrong from vertex handle of halfedge 1";
267 EXPECT_EQ(1, e_it->idx()) <<
"Wrong index in edge iterator";
269 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"2: Wrong to vertex handle of halfedge 0";
270 EXPECT_EQ(1, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"2: Wrong from vertex handle of halfedge 0";
271 EXPECT_EQ(1, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"2: Wrong to vertex handle of halfedge 1";
272 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"2: Wrong from vertex handle of halfedge 1";
276 EXPECT_EQ(2, e_it->idx()) <<
"Wrong index in edge iterator";
278 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"3: Wrong to vertex handle of halfedge 0";
279 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"3: Wrong from vertex handle of halfedge 0";
280 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"3: Wrong to vertex handle of halfedge 1";
281 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"3: Wrong from vertex handle of halfedge 1";
285 EXPECT_EQ(3, e_it->idx()) <<
"Wrong index in edge iterator";
287 EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"4: Wrong to vertex handle of halfedge 0";
288 EXPECT_EQ(0, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"4: Wrong from vertex handle of halfedge 0";
289 EXPECT_EQ(0, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"4: Wrong to vertex handle of halfedge 1";
290 EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"4: Wrong from vertex handle of halfedge 1";
294 EXPECT_EQ(4, e_it->idx()) <<
"Wrong index in edge iterator";
296 EXPECT_EQ(2, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"5: Wrong to vertex handle of halfedge 0";
297 EXPECT_EQ(3, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,0)).idx() ) <<
"5: Wrong from vertex handle of halfedge 0";
298 EXPECT_EQ(3, mesh_.to_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"5: Wrong to vertex handle of halfedge 1";
299 EXPECT_EQ(2, mesh_.from_vertex_handle(mesh_.halfedge_handle(*e_it,1)).idx() ) <<
"5: Wrong from vertex handle of halfedge 1";
306 TEST_F(OpenMeshIterators, HalfedgeIterSkipping) {
322 std::vector<Mesh::VertexHandle> face_vhandles;
324 face_vhandles.clear();
325 face_vhandles.push_back(vhandle[0]);
326 face_vhandles.push_back(vhandle[1]);
327 face_vhandles.push_back(vhandle[3]);
328 mesh_.add_face(face_vhandles);
330 face_vhandles.clear();
331 face_vhandles.push_back(vhandle[1]);
332 face_vhandles.push_back(vhandle[2]);
333 face_vhandles.push_back(vhandle[3]);
334 mesh_.add_face(face_vhandles);
338 face_vhandles.clear();
339 face_vhandles.push_back(vhandle[7]);
340 face_vhandles.push_back(vhandle[6]);
341 face_vhandles.push_back(vhandle[5]);
342 mesh_.add_face(face_vhandles);
344 face_vhandles.clear();
345 face_vhandles.push_back(vhandle[7]);
346 face_vhandles.push_back(vhandle[5]);
347 face_vhandles.push_back(vhandle[4]);
348 mesh_.add_face(face_vhandles);
352 face_vhandles.clear();
353 face_vhandles.push_back(vhandle[1]);
354 face_vhandles.push_back(vhandle[0]);
355 face_vhandles.push_back(vhandle[4]);
356 mesh_.add_face(face_vhandles);
358 face_vhandles.clear();
359 face_vhandles.push_back(vhandle[1]);
360 face_vhandles.push_back(vhandle[4]);
361 face_vhandles.push_back(vhandle[5]);
362 mesh_.add_face(face_vhandles);
366 face_vhandles.clear();
367 face_vhandles.push_back(vhandle[2]);
368 face_vhandles.push_back(vhandle[1]);
369 face_vhandles.push_back(vhandle[5]);
370 mesh_.add_face(face_vhandles);
372 face_vhandles.clear();
373 face_vhandles.push_back(vhandle[2]);
374 face_vhandles.push_back(vhandle[5]);
375 face_vhandles.push_back(vhandle[6]);
376 mesh_.add_face(face_vhandles);
381 face_vhandles.clear();
382 face_vhandles.push_back(vhandle[3]);
383 face_vhandles.push_back(vhandle[2]);
384 face_vhandles.push_back(vhandle[6]);
385 mesh_.add_face(face_vhandles);
387 face_vhandles.clear();
388 face_vhandles.push_back(vhandle[3]);
389 face_vhandles.push_back(vhandle[6]);
390 face_vhandles.push_back(vhandle[7]);
391 mesh_.add_face(face_vhandles);
395 face_vhandles.clear();
396 face_vhandles.push_back(vhandle[0]);
397 face_vhandles.push_back(vhandle[3]);
398 face_vhandles.push_back(vhandle[7]);
399 mesh_.add_face(face_vhandles);
401 face_vhandles.clear();
402 face_vhandles.push_back(vhandle[0]);
403 face_vhandles.push_back(vhandle[7]);
404 face_vhandles.push_back(vhandle[4]);
405 mesh_.add_face(face_vhandles);
423 EXPECT_EQ(18u, mesh_.n_edges() ) <<
"Wrong number of Edges";
424 EXPECT_EQ(36u, mesh_.n_halfedges() ) <<
"Wrong number of HalfEdges";
425 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
426 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces";
428 mesh_.request_face_status();
429 mesh_.request_vertex_status();
430 mesh_.request_halfedge_status();
433 Mesh::EdgeHandle eh = mesh_.edge_handle(2);
436 mesh_.delete_edge(eh);
439 EXPECT_EQ(18u, mesh_.n_edges() ) <<
"Wrong number of Edges after delete";
440 EXPECT_EQ(36u, mesh_.n_halfedges() ) <<
"Wrong number of HalfEdges after delete";
441 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices after delete";
442 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces after delete";
444 Mesh::HalfedgeIter he_it = mesh_.halfedges_sbegin();
445 Mesh::HalfedgeIter he_end = mesh_.halfedges_end();
447 EXPECT_EQ(0, he_it->idx()) <<
"Wrong start index in halfedge iterator";
448 EXPECT_EQ(36, he_end->idx()) <<
"Wrong end index in halfedge iterator";
457 unsigned int count = 0;
459 while (he_it != he_end) {
460 if ( he_it->idx() == 4 )
463 if ( he_it->idx() == 5 )
470 EXPECT_EQ(34u,count) <<
"Skipping iterator count error";
471 EXPECT_TRUE( ok_4 ) <<
"Skipping iterator hit deleted halfedge 4";
472 EXPECT_TRUE( ok_5 ) <<
"Skipping iterator hit deleted halfedge 5";
477 he_it = mesh_.halfedges_begin();
483 while (he_it != he_end) {
484 if ( he_it->idx() == 4 )
487 if ( he_it->idx() == 5 )
495 EXPECT_EQ(36u,count) <<
"Non-skipping iterator count error";
496 EXPECT_TRUE( ok_4 ) <<
"Non-skipping iterator missed deleted halfedge 4";
497 EXPECT_TRUE( ok_5 ) <<
"Non-skipping iterator missed deleted halfedge 5";
502 TEST_F(OpenMeshIterators, HalfedgeIterSkippingLowLevel) {
518 std::vector<Mesh::VertexHandle> face_vhandles;
520 face_vhandles.clear();
521 face_vhandles.push_back(vhandle[0]);
522 face_vhandles.push_back(vhandle[1]);
523 face_vhandles.push_back(vhandle[3]);
524 mesh_.add_face(face_vhandles);
526 face_vhandles.clear();
527 face_vhandles.push_back(vhandle[1]);
528 face_vhandles.push_back(vhandle[2]);
529 face_vhandles.push_back(vhandle[3]);
530 mesh_.add_face(face_vhandles);
534 face_vhandles.clear();
535 face_vhandles.push_back(vhandle[7]);
536 face_vhandles.push_back(vhandle[6]);
537 face_vhandles.push_back(vhandle[5]);
538 mesh_.add_face(face_vhandles);
540 face_vhandles.clear();
541 face_vhandles.push_back(vhandle[7]);
542 face_vhandles.push_back(vhandle[5]);
543 face_vhandles.push_back(vhandle[4]);
544 mesh_.add_face(face_vhandles);
548 face_vhandles.clear();
549 face_vhandles.push_back(vhandle[1]);
550 face_vhandles.push_back(vhandle[0]);
551 face_vhandles.push_back(vhandle[4]);
552 mesh_.add_face(face_vhandles);
554 face_vhandles.clear();
555 face_vhandles.push_back(vhandle[1]);
556 face_vhandles.push_back(vhandle[4]);
557 face_vhandles.push_back(vhandle[5]);
558 mesh_.add_face(face_vhandles);
562 face_vhandles.clear();
563 face_vhandles.push_back(vhandle[2]);
564 face_vhandles.push_back(vhandle[1]);
565 face_vhandles.push_back(vhandle[5]);
566 mesh_.add_face(face_vhandles);
568 face_vhandles.clear();
569 face_vhandles.push_back(vhandle[2]);
570 face_vhandles.push_back(vhandle[5]);
571 face_vhandles.push_back(vhandle[6]);
572 mesh_.add_face(face_vhandles);
577 face_vhandles.clear();
578 face_vhandles.push_back(vhandle[3]);
579 face_vhandles.push_back(vhandle[2]);
580 face_vhandles.push_back(vhandle[6]);
581 mesh_.add_face(face_vhandles);
583 face_vhandles.clear();
584 face_vhandles.push_back(vhandle[3]);
585 face_vhandles.push_back(vhandle[6]);
586 face_vhandles.push_back(vhandle[7]);
587 mesh_.add_face(face_vhandles);
591 face_vhandles.clear();
592 face_vhandles.push_back(vhandle[0]);
593 face_vhandles.push_back(vhandle[3]);
594 face_vhandles.push_back(vhandle[7]);
595 mesh_.add_face(face_vhandles);
597 face_vhandles.clear();
598 face_vhandles.push_back(vhandle[0]);
599 face_vhandles.push_back(vhandle[7]);
600 face_vhandles.push_back(vhandle[4]);
601 mesh_.add_face(face_vhandles);
619 EXPECT_EQ(18u, mesh_.n_edges() ) <<
"Wrong number of Edges";
620 EXPECT_EQ(36u, mesh_.n_halfedges() ) <<
"Wrong number of HalfEdges";
621 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices";
622 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces";
624 mesh_.request_face_status();
625 mesh_.request_vertex_status();
626 mesh_.request_halfedge_status();
629 Mesh::EdgeHandle eh = mesh_.edge_handle(2);
632 EXPECT_EQ(18u, mesh_.n_edges() ) <<
"Wrong number of Edges after delete";
633 EXPECT_EQ(36u, mesh_.n_halfedges() ) <<
"Wrong number of HalfEdges after delete";
634 EXPECT_EQ(8u, mesh_.n_vertices() ) <<
"Wrong number of vertices after delete";
635 EXPECT_EQ(12u, mesh_.n_faces() ) <<
"Wrong number of faces after delete";
637 Mesh::HalfedgeIter he_it = mesh_.halfedges_sbegin();
638 Mesh::HalfedgeIter he_end = mesh_.halfedges_end();
640 EXPECT_EQ(0, he_it->idx()) <<
"Wrong start index in halfedge iterator";
641 EXPECT_EQ(36, he_end->idx()) <<
"Wrong end index in halfedge iterator";
651 he_it = mesh_.halfedges_sbegin();
652 he_end = mesh_.halfedges_end();
654 unsigned int count = 0;
655 bool found_36 =
false;
656 bool found_37 =
false;
658 while (he_it != he_end) {
659 if ( he_it->idx() == 36 )
662 if ( he_it->idx() == 37 )
669 EXPECT_EQ(38u,count) <<
"Skipping iterator count error";
670 EXPECT_TRUE( found_36 ) <<
"Skipping iterator missed halfedge 36";
671 EXPECT_TRUE( found_37 ) <<
"Skipping iterator missed halfedge 37";
679 mesh_.delete_edge(eh);
681 he_it = mesh_.halfedges_sbegin();
682 he_end = mesh_.halfedges_end();
685 bool found_4 =
false;
686 bool found_5 =
false;
690 while (he_it != he_end) {
692 if ( he_it->idx() == 4 )
695 if ( he_it->idx() == 5 )
698 if ( he_it->idx() == 36 )
701 if ( he_it->idx() == 37 )
708 EXPECT_EQ(36u,count) <<
"Deleted valid: Skipping iterator count error";
709 EXPECT_FALSE( found_4 ) <<
"Deleted valid: Skipping iterator hit deleted halfedge 4";
710 EXPECT_FALSE( found_5 ) <<
"Deleted valid: Skipping iterator hit deleted halfedge 5";
711 EXPECT_TRUE( found_36 ) <<
"Deleted valid: Skipping iterator missed halfedge 36";
712 EXPECT_TRUE( found_37 ) <<
"Deleted valid: Skipping iterator missed halfedge 37";
720 mesh_.delete_edge(eh_test);
722 he_it = mesh_.halfedges_sbegin();
723 he_end = mesh_.halfedges_end();
731 while (he_it != he_end) {
733 if ( he_it->idx() == 4 )
736 if ( he_it->idx() == 5 )
739 if ( he_it->idx() == 36 )
742 if ( he_it->idx() == 37 )
749 EXPECT_EQ(34u,count) <<
"Deleted invalid: Skipping iterator count error";
750 EXPECT_FALSE( found_4 ) <<
"Deleted invalid: Skipping iterator hit deleted halfedge 4";
751 EXPECT_FALSE( found_5 ) <<
"Deleted invalid: Skipping iterator hit deleted halfedge 5";
752 EXPECT_FALSE( found_36 ) <<
"Deleted invalid: Skipping iterator hit deleted halfedge 36";
753 EXPECT_FALSE( found_37 ) <<
"Deleted invalid: Skipping iterator hit deleted halfedge 37";
760 TEST_F(OpenMeshIterators, FaceIterEmptyMeshOneDeletedFace) {
765 mesh_.request_vertex_status();
766 mesh_.request_edge_status();
767 mesh_.request_face_status();
777 std::vector<Mesh::VertexHandle> face_vhandles;
779 face_vhandles.push_back(vhandle[2]);
780 face_vhandles.push_back(vhandle[1]);
781 face_vhandles.push_back(vhandle[0]);
782 Mesh::FaceHandle fh = mesh_.add_face(face_vhandles);
785 bool const is_delete_isolated_vertex =
false;
786 mesh_.delete_face(fh, is_delete_isolated_vertex);
795 Mesh::FaceIter f_it = mesh_.faces_begin();
796 Mesh::FaceIter f_end = mesh_.faces_end();
798 EXPECT_EQ(0, f_it->idx()) <<
"Wrong start index in FaceIterator";
800 EXPECT_EQ(1, f_end->idx()) <<
"Wrong end index in FaceIterator";
803 EXPECT_EQ(1, f_it->idx()) <<
"Wrong end index in FaceIterator after one step";
804 EXPECT_TRUE(f_it == f_end ) <<
"Iterator not at end for FaceIterator after one step";
806 Mesh::ConstFaceIter cf_it = mesh_.faces_begin();
807 Mesh::ConstFaceIter cf_end = mesh_.faces_end();
809 EXPECT_EQ(0, cf_it->idx()) <<
"Wrong start index in ConstFaceIterator";
811 EXPECT_EQ(1, cf_end->idx()) <<
"Wrong end index in ConstFaceIterator";
814 EXPECT_EQ(1, cf_it->idx()) <<
"Wrong end index in ConstFaceIterator after one step";
815 EXPECT_TRUE(cf_it == cf_end ) <<
"Iterator not at end for ConstFaceIterator after one step";
819 f_it = mesh_.faces_sbegin();
820 f_end = mesh_.faces_end();
822 EXPECT_EQ(1, f_it->idx()) <<
"Wrong start index in FaceIterator with skipping";
824 EXPECT_EQ(1, f_end->idx()) <<
"Wrong end index in FaceIterator with skipping";
826 EXPECT_TRUE(f_it == f_end ) <<
"Iterator not at end for FaceIterator with skipping";
829 cf_it = mesh_.faces_sbegin();
830 cf_end = mesh_.faces_end();
832 EXPECT_EQ(1, cf_it->idx()) <<
"Wrong start index in ConstFaceIterator with skipping";
834 EXPECT_EQ(1, cf_end->idx()) <<
"Wrong end index in ConstFaceIterator with skipping";
836 EXPECT_TRUE(cf_it == cf_end ) <<
"Iterator not at end for ConstFaceIterator with skipping";
839 mesh_.release_vertex_status();
840 mesh_.release_edge_status();
841 mesh_.release_face_status();
Kernel::Point Point
Coordinate type.
VertexHandle add_vertex(const Point &_p)
Alias for new_vertex(const Point&).
Handle for a vertex entity.
Kernel::VertexHandle VertexHandle
Handle for referencing the corresponding item.