From 04d10f13e9c5cf6a05d21018adb2f796f46b0ff6 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 23 Mar 2017 13:33:37 -0400 Subject: [PATCH] Update graph traits and properties for lcc. --- .../graph/graph_traits_Linear_cell_complex.h | 79 +++++++++---------- .../graph/properties_Linear_cell_complex.h | 29 +++---- BGL/test/BGL/CMakeLists.txt | 4 +- .../BGL/graph_concept_Linear_cell_complex.cpp | 2 +- BGL/test/BGL/test_Prefix.h | 5 +- BGL/test/BGL/test_graph_traits.cpp | 2 + .../CMakeLists.txt | 9 +-- 7 files changed, 63 insertions(+), 67 deletions(-) diff --git a/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h b/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h index 352d8b7ee4e..dfaa867f342 100644 --- a/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h +++ b/BGL/include/CGAL/boost/graph/graph_traits_Linear_cell_complex.h @@ -71,19 +71,23 @@ template struct EdgeHandle : Dart_handle { EdgeHandle() : Dart_handle(NULL){} - EdgeHandle(Dart_handle& h): Dart_handle(h) - {} - EdgeHandle(const Dart_handle& h): Dart_handle(h) + EdgeHandle(Dart_handle h): Dart_handle(h) {} - Dart_handle first_halfedge() + Dart_handle first_halfedge() const { return *this; } - Dart_handle second_halfedge() - { return this->beta(2); } + Dart_handle second_halfedge() const + { + assert(*this!=NULL); + return (*this)->get_f(2); + } - bool operator==(const EdgeHandle& h) - { return (*this)==h || h->get_f(2)==*this; } + bool operator==(const EdgeHandle& h) const + { + return first_halfedge()==h.first_halfedge() || + first_halfedge()==h.second_halfedge(); + } }; template @@ -100,7 +104,7 @@ public: typedef typename std::iterator_traits::iterator_category iterator_category; typedef typename std::iterator_traits::difference_type difference_type; - typedef Dart_handle value_type; + typedef EdgeHandle value_type; typedef value_type reference; typedef value_type pointer; @@ -221,18 +225,12 @@ target(typename boost::graph_traits::edge_descriptor e, } CGAL_LCC_TEMPLATE_ARGS -std::pair::out_edge_iterator, - typename boost::graph_traits::out_edge_iterator> -out_edges(typename boost::graph_traits::vertex_descriptor u, +Iterator_range::out_edge_iterator> +out_edges(typename boost::graph_traits::vertex_descriptor v, const CGAL_LCC_TYPE& cm) { - typedef typename boost::graph_traits::out_edge_iterator - iter_type; - - // CGAL_LCC_TYPE& cmap = const_cast(cm); - - return std::make_pair(iter_type(u->dart(), cm), - iter_type(u->dart(), cm, 1)); + typedef typename boost::graph_traits::out_edge_iterator Iter; + return make_range(Iter(halfedge(v, cm), cm), Iter(halfedge(v, cm), cm, 1)); } CGAL_LCC_TEMPLATE_ARGS @@ -244,18 +242,12 @@ out_degree(typename boost::graph_traits::vertex_descriptor u, // Expression required by the boost::BidirectionalGraph concept. CGAL_LCC_TEMPLATE_ARGS -std::pair::in_edge_iterator, - typename boost::graph_traits::in_edge_iterator> +Iterator_range::in_edge_iterator> in_edges(typename boost::graph_traits::vertex_descriptor v, const CGAL_LCC_TYPE& cm) { - typedef typename boost::graph_traits::in_edge_iterator - iter_type; - - // CGAL_LCC_TYPE& cmap = const_cast(cm); - - return std::make_pair(iter_type(v->dart(), cm), - iter_type(v->dart(), cm, 1)); + typedef typename boost::graph_traits::in_edge_iterator Iter; + return make_range(Iter(halfedge(v, cm), cm), Iter(halfedge(v, cm), cm, 1)); } CGAL_LCC_TEMPLATE_ARGS @@ -290,13 +282,10 @@ CGAL_LCC_TEMPLATE_ARGS CGAL::Iterator_range::vertex_iterator> vertices(const CGAL_LCC_TYPE& cm) { - typedef typename boost::graph_traits::vertex_iterator - iter_type; - + typedef typename boost::graph_traits::vertex_iterator Iter; CGAL_LCC_TYPE& cmap = const_cast(cm); - - return CGAL::make_range(iter_type(cmap.template attributes<0>().begin()), - iter_type(cmap.template attributes<0>().end())); + return CGAL::make_range(Iter(cmap.template attributes<0>().begin()), + Iter(cmap.template attributes<0>().end())); } CGAL_LCC_TEMPLATE_ARGS @@ -310,15 +299,13 @@ num_vertices(const CGAL_LCC_TYPE& cm) // Expression required by the boost::EdgeListGraph concept. CGAL_LCC_TEMPLATE_ARGS -std::pair::edge_iterator, - typename boost::graph_traits::edge_iterator> +Iterator_range::edge_iterator> edges(const CGAL_LCC_TYPE& cm) { - typedef typename boost::graph_traits::edge_iterator iter_type; + typedef typename boost::graph_traits::edge_iterator Iter; CGAL_LCC_TYPE& cmap = const_cast(cm); - - return std::make_pair(iter_type(cmap.darts().begin()), - iter_type(cmap.darts().end())); + return CGAL::make_range(Iter(cmap.darts().begin()), + Iter(cmap.darts().end())); } CGAL_LCC_TEMPLATE_ARGS @@ -332,7 +319,7 @@ edge(typename boost::graph_traits::vertex_descriptor u, typename boost::graph_traits::vertex_descriptor v, const CGAL_LCC_TYPE& cm) { - std::pair::edge_descriptor, + std::pair::halfedge_descriptor, bool> res=halfedge(u,v,cm); return std::make_pair(EdgeHandle(res.first), res.second); @@ -425,7 +412,10 @@ CGAL_LCC_TEMPLATE_ARGS typename boost::graph_traits::halfedge_descriptor halfedge(typename boost::graph_traits::vertex_descriptor v, const CGAL_LCC_TYPE& cmap) -{ return const_cast(cmap).template beta<2>(v->dart()); } +{ + if (v->dart()==NULL) return NULL; + return const_cast(cmap).template beta<2>(v->dart()); +} CGAL_LCC_TEMPLATE_ARGS std::pair< @@ -553,7 +543,10 @@ void set_halfedge(typename boost::graph_traits::vertex_descriptor CGAL_LCC_TYPE& cm) { //cm.template set_dart_of_attribute<0>(v, h); - cm.template set_dart_of_attribute<0>(v, cm.template beta<2>(h)); + if (h!=NULL) + cm.template set_dart_of_attribute<0>(v, cm.template beta<2>(h)); + else + cm.template set_dart_of_attribute<0>(v, h); } CGAL_LCC_TEMPLATE_ARGS diff --git a/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h b/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h index 64eee0140bc..ddc9c24820a 100644 --- a/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h +++ b/BGL/include/CGAL/boost/graph/properties_Linear_cell_complex.h @@ -63,18 +63,17 @@ template class CMap_dart_index_map_external : public boost::put_get_helper > { - public: - typedef boost::read_write_property_map_tag category; typedef std::size_t value_type; typedef std::size_t& reference; typedef typename boost::graph_traits::edge_descriptor key_type; + typedef CGAL::Unique_hash_map Map; - CMap_dart_index_map_external() + CMap_dart_index_map_external(): map(new Map) {} - CMap_dart_index_map_external(CMap const& cm) + CMap_dart_index_map_external(CMap const& cm): map(new Map) { CMap &cmap = const_cast(cm); typedef typename CMap::Dart_range::iterator Iter; @@ -82,22 +81,22 @@ public: Iter e=cmap.template darts().end(); for(value_type i=0; b != e; ++b, ++i) { - map[b] = i; + (*map)[b] = i; } b=cmap.template darts().begin(); for(; b != e; ++b) { - value_type v1 = map[b]; - value_type v2 = map[cmap.template beta<2>(b)]; + value_type v1 = (*map)[b]; + value_type v2 = (*map)[cmap.template beta<2>(b)]; CGAL_assertion(v1==v2+1 || v2==v1+1); } } reference operator[](key_type const& e) const - { return const_cast&>(map)[e]; } + { return const_cast(*map)[e]; } private: - CGAL::Unique_hash_map map ; + boost::shared_ptr map; }; template @@ -109,11 +108,13 @@ public: typedef std::size_t value_type; typedef std::size_t& reference; typedef typename boost::graph_traits::vertex_descriptor key_type; + typedef CGAL::Unique_hash_map Map; - CMap_vertex_index() + + CMap_vertex_index(): map(new Map) {} - CMap_vertex_index(CMap const& cm) + CMap_vertex_index(CMap const& cm): map(new Map) { CMap &cmap = const_cast(cm); typedef typename CMap::template Attribute_range<0>::type::iterator Iter; @@ -121,15 +122,15 @@ public: Iter e=cmap.template attributes<0>().end(); for(value_type i=0; b != e; ++b, ++i) { - map[b] = i; + (*map)[b] = i; } } reference operator[](key_type const& e) const - { return const_cast&>(map)[e]; } + { return const_cast(*map)[e]; } private: - CGAL::Unique_hash_map map ; + boost::shared_ptr map; }; template diff --git a/BGL/test/BGL/CMakeLists.txt b/BGL/test/BGL/CMakeLists.txt index e29c015f501..e71acfba00a 100644 --- a/BGL/test/BGL/CMakeLists.txt +++ b/BGL/test/BGL/CMakeLists.txt @@ -77,6 +77,8 @@ create_single_source_cgal_program( "graph_concept_Surface_mesh.cpp" ) create_single_source_cgal_program( "graph_concept_Gwdwg_Surface_mesh.cpp" ) +create_single_source_cgal_program( "graph_concept_Linear_cell_complex.cpp" ) + create_single_source_cgal_program( "test_clear.cpp" ) create_single_source_cgal_program( "test_helpers.cpp" ) @@ -87,8 +89,6 @@ create_single_source_cgal_program( "test_Has_member_id.cpp" ) create_single_source_cgal_program( "test_cgal_bgl_named_params.cpp" ) -create_single_source_cgal_program( "graph_concept_Linear_cell_complex.cpp" ) - if(OpenMesh_FOUND) target_link_libraries( test_graph_geometry ${OPENMESH_LIBRARIES}) endif() diff --git a/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp b/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp index 341dcf95b3c..1e6fdfce147 100644 --- a/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp +++ b/BGL/test/BGL/graph_concept_Linear_cell_complex.cpp @@ -119,7 +119,7 @@ void runtime_check_halfedgegraph() assert(num_edges(p) == 8); assert(num_halfedges(p) == 16); - // WRONG ASSERT assert(num_faces(p) == 4); + assert(num_faces(p) == 4); } int diff --git a/BGL/test/BGL/test_Prefix.h b/BGL/test/BGL/test_Prefix.h index fcd4d248577..705a04316f2 100644 --- a/BGL/test/BGL/test_Prefix.h +++ b/BGL/test/BGL/test_Prefix.h @@ -177,6 +177,9 @@ std::vector omesh_data() { return t_data(); } #endif +std::vector lcc_data() +{ return t_data(); } + template struct Surface_fixture_1 { Surface_fixture_1() { @@ -319,7 +322,7 @@ struct Surface_fixture_3 { assert(z != boost::graph_traits::null_vertex()); f1 = CGAL::is_border(halfedge(u, m),m) ? face(opposite(halfedge(u, m), m), m) : face(halfedge(u, m), m); - f2 = CGAL::is_border(halfedge(u, m),m) ? face(opposite(halfedge(z, m), m), m) : face(halfedge(z, m), m); + f2 = CGAL::is_border(halfedge(z, m),m) ? face(opposite(halfedge(z, m), m), m) : face(halfedge(z, m), m); assert(f1 != boost::graph_traits::null_face()); assert(f2 != boost::graph_traits::null_face()); diff --git a/BGL/test/BGL/test_graph_traits.cpp b/BGL/test/BGL/test_graph_traits.cpp index a584b79bd75..96d45793d8e 100644 --- a/BGL/test/BGL/test_graph_traits.cpp +++ b/BGL/test/BGL/test_graph_traits.cpp @@ -283,6 +283,8 @@ main() { test(poly_data()); + test(lcc_data()); + #if defined(CGAL_USE_SURFACE_MESH) test(sm_data()); #endif diff --git a/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt b/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt index 1dcf38b79e4..f52375c837a 100644 --- a/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt +++ b/Surface_mesh_simplification/examples/Surface_mesh_simplification/CMakeLists.txt @@ -65,15 +65,12 @@ create_single_source_cgal_program( "edge_collapse_constrained_border_polyhedron. create_single_source_cgal_program( "edge_collapse_enriched_polyhedron.cpp" ) create_single_source_cgal_program( "edge_collapse_polyhedron.cpp" ) create_single_source_cgal_program( "edge_collapse_surface_mesh.cpp" ) +create_single_source_cgal_program( "edge_collapse_linear_cell_complex.cpp" ) create_single_source_cgal_program( "edge_collapse_constrained_border_surface_mesh.cpp" ) create_single_source_cgal_program( "edge_collapse_all_short_edges.cpp" ) -create_single_source_cgal_program( "edge_collapse_linear_cell_complex.cpp" ) - -create_single_source_cgal_program( "edge_collapse_linear_cell_complex.cpp" ) - if(OpenMesh_FOUND) -create_single_source_cgal_program( "edge_collapse_OpenMesh.cpp" ) + create_single_source_cgal_program( "edge_collapse_OpenMesh.cpp" ) -target_link_libraries( edge_collapse_OpenMesh ${OPENMESH_LIBRARIES} ) + target_link_libraries( edge_collapse_OpenMesh ${OPENMESH_LIBRARIES} ) endif()