From 481908df1fd0d94bca69f9a747e628ea4062c6a5 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 14 Feb 2013 17:21:36 +0100 Subject: [PATCH] * Re-add set_attribute method in CMap class (was removed by error). * Make functors Is_removable_functor and Is_contractible_functor to avoid a warning. --- .../map_3_with_colored_facets.cpp | 44 +++---- .../include/CGAL/Combinatorial_map.h | 14 +++ .../CGAL/Combinatorial_map_insertions.h | 15 ++- .../CGAL/Combinatorial_map_operations.h | 112 ++++++++++++------ 4 files changed, 119 insertions(+), 66 deletions(-) diff --git a/Combinatorial_map/examples/Combinatorial_map/map_3_with_colored_facets.cpp b/Combinatorial_map/examples/Combinatorial_map/map_3_with_colored_facets.cpp index f15f998fe1c..654dc872aa7 100644 --- a/Combinatorial_map/examples/Combinatorial_map/map_3_with_colored_facets.cpp +++ b/Combinatorial_map/examples/Combinatorial_map/map_3_with_colored_facets.cpp @@ -47,48 +47,48 @@ int main() Dart_handle dh2 = make_combinatorial_hexahedron(cm); // 1) Create all 2-attributes and associated them to darts. - for (CMap_3::Dart_range::iterator - it=cm.darts().begin(), itend=cm.darts().end(); - it!=itend; ++it) - { - if ( it->attribute<2>()==NULL ) - cm.set_attribute<2>(it, cm.create_attribute<2>()); - } + for (CMap_3::Dart_range::iterator + it=cm.darts().begin(), itend=cm.darts().end(); + it!=itend; ++it) + { + if ( it->attribute<2>()==NULL ) + cm.set_attribute<2>(it, cm.create_attribute<2>()); + } // 2) Set the color of all facets of the first hexahedron to 7. for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator - it=cm.one_dart_per_incident_cell<2,3>(dh1).begin(), - itend=cm.one_dart_per_incident_cell<2,3>(dh1).end(); it!=itend; ++it) - { it->attribute<2>()->info()=7; } + it=cm.one_dart_per_incident_cell<2,3>(dh1).begin(), + itend=cm.one_dart_per_incident_cell<2,3>(dh1).end(); it!=itend; ++it) + { it->attribute<2>()->info()=7; } // 3) Set the color of all facets of the second hexahedron to 13. for (CMap_3::One_dart_per_incident_cell_range<2, 3>::iterator it= - cm.one_dart_per_incident_cell<2,3>(dh2).begin(), - itend=cm.one_dart_per_incident_cell<2,3>(dh2).end(); it!=itend; ++it) - { it->attribute<2>()->info()=13; } + cm.one_dart_per_incident_cell<2,3>(dh2).begin(), + itend=cm.one_dart_per_incident_cell<2,3>(dh2).end(); it!=itend; ++it) + { it->attribute<2>()->info()=13; } // 4) 3-Sew the two hexahedra along one facet. cm.sew<3>(dh1, dh2); // 5) Display all the values of 2-attributes. for (CMap_3::Attribute_range<2>::type::iterator - it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end(); + it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end(); it!=itend; ++it) - { - std::cout<info()<<"; "; - } + { + std::cout<info()<<"; "; + } std::cout<::type::iterator - it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end(); + for (CMap_3::Attribute_range<2>::type::iterator + it=cm.attributes<2>().begin(), itend=cm.attributes<2>().end(); it!=itend; ++it) - { - std::cout<info()<<"; "; - } + { + std::cout<info()<<"; "; + } std::cout< but i-attributes are disabled"); + Set_i_attribute_functor::run(this, adart, ah); + } + /// @return a Attributes_range (range through all the /// attributes of the map). template diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h b/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h index 91fc444aa2a..5f4cbcbce97 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h @@ -126,10 +126,6 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, while ( !first->template is_free<0>() && first->template beta<0>()!=adart ) first = first->template beta<0>(); - // Stack of couple of dart and dimension for which - // we must call on_split functor - std::deque modified_darts; - // Mark used to mark darts already treated. int treated = amap.get_new_mark(); @@ -203,7 +199,6 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, (nn1, prev->beta(dim)); amap.mark(cur->beta(dim), treated); - tounmark.push_back(cur->beta(dim)); } else { @@ -240,7 +235,11 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, itd=tounmark.begin(); itd!=tounmark.end(); ++itd ) { amap.unmark(*itd, treated); - + for (unsigned int dim=3; dim<=CMap::dimension; ++dim) + { + if ( !(*itd)->is_free(dim) ) + amap.unmark((*itd)->beta(dim), treated); + } if ( *itd!=adart ) CGAL::internal::Degroup_attribute_functor_run:: run(&amap, adart, *itd); @@ -300,9 +299,9 @@ insert_dangling_cell_1_in_cell_2( CMap& amap, if ( !it1->is_free(s1) ) { if ( s1==0 ) - amap.template link_beta_1(it1->template beta<0>(), d2); + amap.link_beta_1(it1->template beta<0>(), d2); else - amap.template link_beta_0(it1->template beta<1>(), d2); + amap.link_beta_0(it1->template beta<1>(), d2); } if (s1==0) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index 3187795b16d..14176ed7929 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -31,6 +31,43 @@ namespace CGAL * Some operations to modify a combinatorial map. */ + /** Test if an i-cell can be removed. + * An i-cell can be removed if i==CMap::dimension or i==CMap::dimension-1, + * or if there are at most two (i+1)-cell incident to it. + * @param adart a dart of the i-cell. + * @return true iff the i-cell can be removed. + */ + template + struct Is_removable_functor + { + static bool run(const CMap& amap, typename CMap::Dart_const_handle adart) + { + // TODO? Optimisation for dim-2, and to not test all the darts of the cell? + bool res = true; + for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); + res && it.cont(); ++it ) + { + if (it->template beta()->template beta()!= + it->template beta_inv()->template beta() ) + res = false; + } + return res; + } + }; + // Specialization for i=CMap::dimension + template + struct Is_removable_functor + { + static bool run(const CMap&, typename CMap::Dart_const_handle) + { return true; } + }; + // Specialization for i=CMap::dimension-1 + template + struct Is_removable_functor + { + static bool run(const CMap&, typename CMap::Dart_const_handle) + { return true; } + }; /** Test if an i-cell can be removed. * An i-cell can be removed if i==CMap::dimension or i==CMap::dimension-1, * or if there are at most two (i+1)-cell incident to it. @@ -39,24 +76,7 @@ namespace CGAL */ template < class CMap, unsigned int i > bool is_removable(const CMap& amap, typename CMap::Dart_const_handle adart) - { - CGAL_assertion( adart!=NULL ); - CGAL_static_assertion( 0<=i && i<=CMap::dimension ); - - if ( i==CMap::dimension ) return true; - if ( i==CMap::dimension-1 ) return true; - - // TODO? Optimisation for dim-2, and to not test all the darts of the cell? - bool res = true; - for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); - res && it.cont(); ++it ) - { - if (it->template beta()->template beta()!= - it->template beta_inv()->template beta() ) - res = false; - } - return res; - } + { return CGAL::Is_removable_functor::run(amap,adart); } /** Remove an i-cell, 0::run(amap,adart); } + /** Test if an i-cell can be contracted. + * An i-cell can be contracted if i==1 + * or if there are at most two (i-1)-cell incident to it. + * @param adart a dart of the i-cell. + * @return true iff the i-cell can be contracted. + */ + template + struct Is_contractible_functor + { + static bool run(const CMap& amap, typename CMap::Dart_const_handle adart) + { + // TODO ? Optimisation possible to not test all the darts of the cell ? + bool res = true; + for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); + res && it.cont(); ++it ) + { + if ( it->template beta()->template beta()!= + it->template beta()->template beta_inv() ) + res = false; + } + return res; + } + }; + // Specialization for i=0 + template + struct Is_contractible_functor + { + static bool run(const CMap&, typename CMap::Dart_const_handle) + { return false; } + }; + // Specialization for i=1 + template + struct Is_contractible_functor + { + static bool run(const CMap&, typename CMap::Dart_const_handle) + { return true; } + }; /** Test if an i-cell can be contracted. * An i-cell can be contracted if i==1 * or if there are at most two (i-1)-cell incident to it. @@ -433,24 +490,7 @@ namespace CGAL */ template < class CMap, unsigned int i > bool is_contractible(const CMap& amap, typename CMap::Dart_const_handle adart) - { - CGAL_assertion(adart != NULL); - CGAL_static_assertion(0<=i && i<=CMap::dimension); - - if ( i==0 ) return false; - if ( i==1 ) return true; - - // TODO ? Optimisation possible to not test all the darts of the cell ? - bool res = true; - for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); - res && it.cont(); ++it ) - { - if ( it->template beta()->template beta()!= - it->template beta()->template beta_inv() ) - res = false; - } - return res; - } + { return CGAL::Is_contractible_functor::run(amap,adart); } /** Contract an i-cell, 1