From d5f74fd542fe85e83c542f3ded0fe9727c956804 Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 25 Nov 2014 18:28:50 +0100 Subject: [PATCH] fix surface_mesh_test.cpp --- .../include/CGAL/Surface_mesh/Surface_mesh.h | 29 ++++++++---- Surface_mesh/test/Surface_mesh/SM_common.h | 14 +++--- .../test/Surface_mesh/surface_mesh_test.cpp | 47 +++++++++---------- 3 files changed, 49 insertions(+), 41 deletions(-) diff --git a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h index 6def04f7cef..a27d47e5251 100644 --- a/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h +++ b/Surface_mesh/include/CGAL/Surface_mesh/Surface_mesh.h @@ -1840,6 +1840,9 @@ public: bool is_border(Vertex_index v, bool check_all_incident_halfedges = true) const { Halfedge_index h(halfedge(v)); + if (h == null_halfedge()){ + return false; + } if(check_all_incident_halfedges){ Halfedge_around_target_circulator hatc(h,*this), done(hatc); do { @@ -1870,8 +1873,9 @@ public: /// associated to vertex `v` to a border halfedge and returns `true` if it exists. bool set_vertex_halfedge_to_border_halfedge(Vertex_index v) { - if(halfedge(v) == null_halfedge()) + if(halfedge(v) == null_halfedge()){ return false; + } Halfedge_around_target_circulator hatc(halfedge(v),*this), done(hatc); do { if(is_border(*hatc)){ @@ -2207,13 +2211,13 @@ operator=(const Surface_mesh

& rhs) fprops_ = rhs.fprops_; // property handles contain pointers, have to be reassigned - vconn_ = property_map("v:connectivity"); - hconn_ = property_map("h:connectivity"); - fconn_ = property_map("f:connectivity"); - vremoved_ = property_map("v:removed"); - eremoved_ = property_map("e:removed"); - fremoved_ = property_map("f:removed"); - vpoint_ = property_map("v:point"); + vconn_ = property_map("v:connectivity").first; + hconn_ = property_map("h:connectivity").first; + fconn_ = property_map("f:connectivity").first; + vremoved_ = property_map("v:removed").first; + eremoved_ = property_map("e:removed").first; + fremoved_ = property_map("f:removed").first; + vpoint_ = property_map("v:point").first; // how many elements are removed? removed_vertices_ = rhs.removed_vertices_; @@ -2487,6 +2491,7 @@ Surface_mesh

::add_face(const Range& r) for (i=0, ii=1; i:: degree(Vertex_index v) const { size_type count(0); - + if(halfedge(v) == null_halfedge()){ + return 0; + } Vertex_around_target_circulator vvit(halfedge(v), *this); Vertex_around_target_circulator vvend = vvit; if(vvit) do @@ -2599,7 +2606,9 @@ Surface_mesh

:: degree(Face_index f) const { size_type count(0); - + if(halfedge(f) == null_halfedge()){ + return 0; + } Vertex_around_face_circulator fvit(halfedge(f),*this); Vertex_around_face_circulator fvend = fvit; if(fvit) do { diff --git a/Surface_mesh/test/Surface_mesh/SM_common.h b/Surface_mesh/test/Surface_mesh/SM_common.h index a3edf41f2f0..3409a647caa 100644 --- a/Surface_mesh/test/Surface_mesh/SM_common.h +++ b/Surface_mesh/test/Surface_mesh/SM_common.h @@ -37,8 +37,8 @@ struct Surface_fixture { } Sm m; - Sm::Vertex_descriptor u, v, w, x, y; - Sm::Face_descriptor f1, f2, f3; + Sm::Vertex_index u, v, w, x, y; + Sm::Face_index f1, f2, f3; ~Surface_fixture() {} }; @@ -71,8 +71,8 @@ struct Surface_fixture_2 { } Sm m; - Sm::Vertex_descriptor u, v, w, x, y; - Sm::Face_descriptor f1, f2, f3, f4; + Sm::Vertex_index u, v, w, x, y; + Sm::Face_index f1, f2, f3, f4; ~Surface_fixture_2() {} }; @@ -96,7 +96,7 @@ struct Surface_fixture_3 { y = m.add_vertex(Point_3(2,0,0)); z = m.add_vertex(Point_3(2,1,0)); - std::vector vec; + std::vector vec; using namespace boost::assign; vec += u, v, w, x; f1 = m.add_face(vec); @@ -106,8 +106,8 @@ struct Surface_fixture_3 { } Sm m; - Sm::Vertex_descriptor u, v, w, x, y, z; - Sm::Face_descriptor f1, f2; + Sm::Vertex_index u, v, w, x, y, z; + Sm::Face_index f1, f2; ~Surface_fixture_3() {} }; diff --git a/Surface_mesh/test/Surface_mesh/surface_mesh_test.cpp b/Surface_mesh/test/Surface_mesh/surface_mesh_test.cpp index ba96cc5fe1d..7daf629e5ab 100644 --- a/Surface_mesh/test/Surface_mesh/surface_mesh_test.cpp +++ b/Surface_mesh/test/Surface_mesh/surface_mesh_test.cpp @@ -35,6 +35,10 @@ BOOST_AUTO_TEST_CASE( standard_iterators ) boost::tie(vb, ve) = f.m.vertices(); test_iterator(vb, ve, 5); + Sm::Halfedge_iterator hb, he; + boost::tie(hb, he) = f.m.halfedges(); + test_iterator(hb, he, 14); + Sm::Edge_iterator eb, ee; boost::tie(eb, ee) = f.m.edges(); test_iterator(eb, ee, 7); @@ -92,9 +96,9 @@ BOOST_AUTO_TEST_CASE( test_remove_edge ) // now remove a border edge to check if this works // this should not lower the number of faces - Sm::size_type old_removed_faces_size = f.m.num_removed_faces(); + Sm::size_type old_removed_faces_size = f.m.number_of_removed_faces(); f.m.remove_edge(Sm::Edge_index(wx)); - BOOST_CHECK_EQUAL(f.m.num_removed_faces(), old_removed_faces_size); + BOOST_CHECK_EQUAL(f.m.number_of_removed_faces(), old_removed_faces_size); } @@ -123,50 +127,45 @@ BOOST_AUTO_TEST_CASE( memory_reuse_test ) } // remove all faces - std::size_t old_face_size = f.m.num_faces() - f.m.num_removed_faces(); + std::size_t old_face_size = f.m.number_of_faces(); + std::size_t old_removed_face_size = f.m.number_of_removed_faces(); boost::range::for_each(f.m.faces(), boost::bind(&Sm::remove_face, boost::ref(f.m), _1)); - BOOST_CHECK_EQUAL(f.m.num_faces() - f.m.num_removed_faces(), 0); - BOOST_CHECK_EQUAL(f.m.num_faces(), old_face_size); + BOOST_CHECK_EQUAL(f.m.number_of_faces(), 0); + BOOST_CHECK_EQUAL(f.m.number_of_removed_faces(), old_face_size + old_removed_face_size); // remove all edges - std::size_t old_edge_size = f.m.num_edges() - f.m.num_removed_edges(); + std::size_t old_edge_size = f.m.number_of_edges(); + std::size_t old_removed_edge_size = f.m.number_of_removed_edges(); boost::range::for_each(f.m.edges(), boost::bind(static_cast(&Sm::remove_edge), boost::ref(f.m), _1)); - BOOST_CHECK_EQUAL(f.m.num_faces() - f.m.num_removed_faces(), 0); - BOOST_CHECK_EQUAL(f.m.num_edges(), old_edge_size); + BOOST_CHECK_EQUAL(f.m.number_of_faces() , 0); + BOOST_CHECK_EQUAL(f.m.number_of_removed_edges(), old_edge_size + old_removed_edge_size); int fc = 0; // add all again for(Faces::iterator it = faces.begin(); it != faces.end(); ++it) { - std::cout << "add face " << fc++ << std::endl; Sm::Face_index fd = f.m.add_face(*it); BOOST_CHECK(fd.is_valid()); - f.m.fix_border(f.m.halfedge(fd)); + f.m.set_vertex_halfedge_to_border_halfedge(f.m.halfedge(fd)); for(VecFace::iterator it2 = it->begin(); it2 != it->end(); ++it2) { - std::cout << std::boolalpha << "Added: " << *it2 << " border?" << f.m.is_border(*it2) << std::endl; Sm::Halfedge_index h = f.m.halfedge(*it2); - std::cout << h << h.is_valid() << std::endl; Sm::Face_index fa = f.m.face(h); - std::cout << fa << fa.is_valid() << std::endl; - std::cout << h << " " << fa << std::endl; - std::cout << std::boolalpha << "deleted" << f.m.is_removed(fa) << f.m.is_removed(h) << std::endl; } - - std::cout << "success" << std::endl; } - BOOST_CHECK_EQUAL(f.m.num_edges() - f.m.num_removed_edges(), old_edge_size); - BOOST_CHECK_EQUAL(f.m.num_edges() - f.m.num_removed_faces(), old_face_size); + BOOST_CHECK_EQUAL(f.m.number_of_edges() , old_edge_size); + BOOST_CHECK_EQUAL(f.m.number_of_faces() , old_face_size); // remove all vertices - std::size_t old_size = f.m.num_vertices() - f.m.num_removed_vertices(); + std::size_t old_size = f.m.number_of_vertices(); + std::size_t old_removed_size = f.m.number_of_removed_vertices(); boost::range::for_each(f.m.vertices(), boost::bind(&Sm::remove_vertex, boost::ref(f.m), _1)); - BOOST_CHECK_EQUAL(f.m.num_vertices() - f.m.num_removed_vertices(), 0); - BOOST_CHECK_EQUAL(f.m.num_vertices(), old_size); + BOOST_CHECK_EQUAL(f.m.number_of_vertices() , 0); + BOOST_CHECK_EQUAL(f.m.number_of_removed_vertices(), old_size + old_removed_size); for(unsigned int i = 0; i < old_size; ++i) { @@ -174,7 +173,7 @@ BOOST_AUTO_TEST_CASE( memory_reuse_test ) } // the size must remain the same - BOOST_CHECK_EQUAL(f.m.num_vertices() - f.m.num_removed_vertices(), old_size); + BOOST_CHECK_EQUAL(f.m.number_of_vertices(), old_size); } BOOST_AUTO_TEST_CASE( test_validate ) @@ -195,7 +194,7 @@ BOOST_AUTO_TEST_CASE(isolated_vertex_check) Sm::Vertex_index isolated = f.m.add_vertex(Point_3(10, 10, 10)); BOOST_CHECK(f.m.is_isolated(isolated)); BOOST_CHECK(!f.m.halfedge(isolated).is_valid()); - BOOST_CHECK(f.m.is_border(isolated)); + BOOST_CHECK(! f.m.is_border(isolated)); BOOST_CHECK(f.m.degree(isolated) == 0); }