From 0558f60b09f3b11ac1e3bedfaf306c97bfcad55e Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 11 Feb 2013 13:49:39 +0100 Subject: [PATCH] Start some cleanup in group/degroup methods. --- .../include/CGAL/Combinatorial_map.h | 223 ++++++++---------- .../CGAL/Combinatorial_map_operations.h | 15 +- .../internal/Combinatorial_map_functors.h | 197 ++++++++++------ .../CGAL/internal/Combinatorial_map_utility.h | 49 ++++ 4 files changed, 282 insertions(+), 202 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index fe4c790c48f..b17d788a3d4 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -85,8 +85,8 @@ namespace CGAL { typename Map::Dart_handle insert_cell_0_in_cell_2(Map& amap, typename Map::Dart_handle adart); - template - friend struct internal::Degroup_one_attribute_of_dart_functor; + /*template + friend struct internal::Degroup_one_attribute_of_dart_functor;*/ template friend struct internal::Degroup_one_attribute_functor; @@ -94,7 +94,7 @@ namespace CGAL { template friend struct internal::Test_is_valid_attribute_functor; - template + template friend struct internal::Group_attribute_functor_of_dart_run; template @@ -2077,6 +2077,48 @@ namespace CGAL { >::run(this,ah,amark); } + /** Group the i-cell-attributes of the two given darts, if required. + * If the two i-cell-attributes of \em adart1 and \em adart2 are different, + * we set the i-cell-attribute of adart2 onto the attribute of adart1. + * @param adart1 the first dart. + * @param adart2 the second dart. + * @return true iff the two attributes are merged. + */ + template + bool group_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2) + { + } + + /** Degroup the i-cell attribute of the two given darts, if required. + * We create a new attribute and link dart2 onto this new attribute. + * The new attribute is initialized by copying the old one. + * @param adart1 the first dart. + * @param adart2 the second dart. + * @return true iff the attribute is split. + */ + template + bool degroup_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2) + { + CGAL_static_assertion(i<=dimension); + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "group_enabled_attribute_of_dart but " + "i-attributes are disabled"); + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=null_dart_handle && dh2!=null_dart_handle ); + + typename Attribute_handle::type a1=dh1->template attribute(); + typename Attribute_handle::type a2=dh2->template attribute(); + + // If the two attributes are different, nothing to do. + if ( a1==NULL || a1 != a2 ) return false; + + a2 = create_attribute(*a1); + + // We set the attribute of dh2 to a2. + set_attribute_of_dart(dh2, a2); + return true; + } + /** Group the i cell-attributes of two darts. * If the two i cell-attribute of \em adart1 and \em adart2 are different, * we set the i cell-attribute of each dart belonging to the i-cell orbit @@ -2120,7 +2162,55 @@ namespace CGAL { set_attribute(toSet, a1); } - /** Group all the attributes of adart1 and adart2. If both dart have a + /** Degroup the i-cell attribute of the two given darts, if required. + * If the two darts are incident to the same attribute and do not belong to + * the same i-cell, we create a new attibute and link each dart + * belonging to the i-cell of adart2 onto this new attribute. + * The new attribute is initialized by copying the old one then by using + * the functor On_split from the original attribute. + * @param adart1 the first dart. + * @param adart2 the second dart. + * @return true iff the attribute is split. + */ + template + bool degroup_enabled_attribute(Dart_handle adart1, Dart_handle adart2) + { + CGAL_static_assertion(i<=dimension); + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "degroup_enabled_attribute but " + "i-attributes are disabled"); + CGAL_assertion(adart1 != NULL && adart2 != NULL); + CGAL_assertion(adart1 != null_dart_handle && adart2 != null_dart_handle); + + typename Attribute_handle::type a1=adart1->template attribute(); + typename Attribute_handle::type a2=NULL; + + // If the two attributes are not equal, nothing to do. + if ( a1 != adart2->template attribute() || a1 == NULL) return false; + + // TODO improve this step: use basic iterator to iterate through cell(adart2) + // If the two darts belong to the same cell, nothing to do. + if ( belong_to_same_cell(*this, adart1, adart2) ) + return false; + + // Here we create a new attribute + a2 = create_attribute(*a1); + + // We call the on_split functor + internal::Apply_cell_functor::run(*a1,*a2); + + // We set the dart of the cell a1 onto adart1. + a1->set_dart(adart1); + + // and reuse the basic iterator here to unmark. + // And we set all the dart of the cell of adart2 to v1. + set_attribute(adart2, a2); + + return true; + } + + /** Group all the attributes of adart1 and adart2. If both dart have a * i-attribute, the attribute associated to adart1 is kept. * @param adart1 the first dart. * @param adart1 the second dart. @@ -2132,32 +2222,6 @@ namespace CGAL { typename Attribute_type::type>::run(this,adart1,adart2); } - /** Group the i cell-attributes of two darts. - * If the two i cell-attribute of \em adart1 and \em adart2 are different, - * we set the i cell-attribute of adart2 onto the attribute of adart1. - * @param adart1 the first dart. - * @param adart2 the second dart. - */ - template - void group_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "group_enabled_attribute_of_dart but " - "i-attributes are disabled"); - CGAL_assertion( dh1!=NULL && dh2!=NULL ); - CGAL_assertion( dh1!=null_dart_handle && dh2!=null_dart_handle ); - - typename Attribute_handle::type a1=dh1->template attribute(); - typename Attribute_handle::type a2=dh2->template attribute(); - - // If the two attributes are equal, nothing to do. - if ( a1 == a2 ) return; - - if ( a1==NULL ) set_attribute_of_dart(dh1, a2); - else set_attribute_of_dart(dh2, a1); - } - /** Group all the dart attributes of adart1 and adart2, except the * adim-cell attribute. * @param adart1 the first dart. @@ -2183,58 +2247,12 @@ namespace CGAL { */ void group_all_attributes_except(Dart_handle adart1, Dart_handle adart2, int adim) - { + { CGAL_assertion( adim==-1 || (1<=adim && (unsigned int)adim<=dimension) ); Helper::template Foreach_enabled_attributes >:: run(this,adart1,adart2,adim); } - - /** Degroup the i-cell attribute of the two given darts, if required. - * If the two darts are incident to the same attribute and do not belong to - * the same i-cell, we create a new attibute and link each dart - * belonging to the i-cell of adart2 onto this new attribute. - * The new attribute is initialized by copying the old one then by using - * the functor On_split from the original attribute. - * @param adart1 the first dart. - * @param adart2 the second dart. - * @return true iff the attribute is split. - */ - template - bool degroup_enabled_attribute(Dart_handle adart1, Dart_handle adart2) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "degroup_enabled_attribute but " - "i-attributes are disabled"); - CGAL_assertion(adart1 != NULL && adart2 != NULL); - CGAL_assertion(adart1 != null_dart_handle && adart2 != null_dart_handle); - - typename Attribute_handle::type a1=adart1->template attribute(); - typename Attribute_handle::type a2=NULL; - - // If the two attributes are not equal, nothing to do. - if ( a1 != adart2->template attribute() || a1 == NULL) return false; - - // If the two darts belong to the same cell, nothing to do. - if ( belong_to_same_cell(*this, adart1, adart2) ) - return false; - - // Here we create a new attribute - a2 = create_attribute(*a1); - - // We call the on_split functor - internal::Apply_cell_functor::run(*a1,*a2); - - // We set the dart of the cell a1 onto adart1. - a1->set_dart(adart1); - - // And we set all the dart of the cell of adart2 to v1. - set_attribute(adart2, a2); - - return true; - } template bool degroup_attribute(Dart_handle adart1, Dart_handle adart2) @@ -2265,51 +2283,12 @@ namespace CGAL { void degroup_all_attributes(Dart_handle adart1, Dart_handle adart2) { degroup_all_attributes_except(adart1, adart2, -1); } - /** Degroup the i-cell attribute of the two given darts, if required. - * We create a new attibute and link dart2 onto this new attribute. - * The new attribute is initialized by copying the old one then by using - * the functor On_split from the original attribute. - * @param adart1 the first dart. - * @param adart2 the second dart. - * @return true iff the attribute is split. - */ - template - bool degroup_enabled_attribute_of_dart( Dart_handle dh1, Dart_handle dh2) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "group_enabled_attribute_of_dart but " - "i-attributes are disabled"); - CGAL_assertion( dh1!=NULL && dh2!=NULL ); - CGAL_assertion( dh1!=null_dart_handle && dh2!=null_dart_handle ); - - typename Attribute_handle::type a1=dh1->template attribute(); - typename Attribute_handle::type a2=dh2->template attribute(); - - // If the two attributes are equal, nothing to do. - if ( a1==NULL || a1 != a2 ) return false; - - a2 = create_attribute(*a1); - - // We call the on_split functor - // internal::Apply_cell_functor::run(*a1,*a2); - - // We set the attribute of dh2 to a2. - for (typename Range::iterator it=Range(*this,dh2).begin(), - itend=Range(*this,dh2).end(); it!=itend; ++it) - { - set_attribute_of_dart(it, a2); - } - return true; - } - - template + /* template bool degroup_attribute_of_dart(Dart_handle adart1, Dart_handle adart2) { - return internal::Degroup_one_attribute_of_dart_functor::type, Range>::run(this,adart1,adart2); - } + return internal::Degroup_one_attribute_of_dart_functor:: + run(this,adart1,adart2); + }*/ /** Test the validity of a i-cell-attribute. * ie all the darts belonging to a i-cell are linked to the same attribute. @@ -2408,11 +2387,11 @@ namespace CGAL { "set_attribute_of_dart but " "i-attributes are disabled"); CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); - if ( adart->template attribute()==ah ) return; + CGAL_assertion( adart->template attribute()!=ah ); decrease_attribute_ref_counting(adart); - adart->template set_attribute(ah); + // TODO remove the set_dart ? ah->set_dart(adart); } diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index fdf44920f51..e7a178032e4 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -73,12 +73,20 @@ namespace CGAL { if ( cur!=first ) { - if ( amap.template degroup_attribute_of_dart<2, - typename Map::template Dart_of_involution_range<1> > - (first, cur) ) + if ( amap.template degroup_attribute_of_dart<2>(first, cur) ) + { + // TODO Functor takiing a range, an attrib_handle, and that set + // all the darts of the range to this handle + for (typename Map::template Dart_of_involution_range<1>::iterator + it=template darts_of_involution<1>(dh2).begin(), + itend=template darts_of_involution<1>(dh2).end(); it!=itend; + ++it) + { + } tosplit.push(internal::Couple_dart_and_dim (first,cur,2)); + } } if (!cur->is_free(0)) @@ -1134,6 +1142,7 @@ namespace CGAL { } amap.template basic_link_beta<1>(*it, d1); + // TODO remove this group, and use link_beta instead ? amap.group_all_dart_attributes_except(*it, d1, 1); amap.mark(*it, mark); diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index 7f90566bde6..75afd474674 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -26,13 +26,127 @@ #include #include +/* Definition of functors used to manage attributes (we need functors as + * attributes are stored in tuple, thus all the access must be done at + * compiling time. + * + * Group_attribute_functor_of_dart to group the -attributes of two + * given darts (except for adim). + * Group_attribute_functor_of_dart_run same than + * Group_attribute_functor_of_dart::run, with i template argument + * given in the struct to enable specialization. + * + * + * + */ + namespace CGAL { namespace internal { - /** @file Combinatorial_map_functors.h - * Definition of functors used for dD Combinatorial map. - */ + /** @file Combinatorial_map_functors.h + * Definition of functors used for dD Combinatorial map. + */ + // ************************************************************************** + /// Functor used for link_beta to update the attributes of + /// adart2 on the attributes of this dart. + template::type> + struct Group_attribute_functor_of_dart_run + { + static void run(CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2) + { + CGAL_static_assertion(i<=CMap::dimension); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index::value>=0, + "Group_attribute_functor_of_dart_run but " + "i-attributes are disabled"); + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh2!=CMap::null_dart_handle ); + + T a1=dh1->template attribute(); + T a2=dh2->template attribute(); + + // If the two attributes are equal, nothing to do. + if ( a1 == a2 ) return false; + + if ( a1==NULL ) amap->set_attribute_of_dart(dh1, a2); + else amap->set_attribute_of_dart(dh2, a1); + } + }; + template + struct Group_attribute_functor_of_dart_run + { + static void run(CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2, + int adim) + { + CGAL_assertion( adim==-1 || + (0<=adim && (unsigned int)adim<=CMap::dimension) ); + // todo ASSERT (1<=adim && ...) ??? + if ( adim!=0 ) + { + typename CMap::Dart_handle od = dh1->other_extremity(); + if ( od!=NULL ) + { + typename CMap::Helper::template Attribute_handle<0>::type + a1=od->template attribute<0>(); + if ( a1!=NULL && a1!=dh2->template attribute<0>() ) + amap->template set_attribute_of_dart<0>(dh2, a1); + } + } + + if ( adim!=1 ) + { + typename CMap::Dart_handle od = dh2->other_extremity(); + if ( od!=NULL && dh1->template attribute<0>()==NULL ) + { + typename CMap::Helper::template Attribute_handle<0>::type + a2=od->template attribute<0>(); + if ( a2!=NULL ) + amap->template set_attribute_of_dart<0>(dh1, a2); + } + } + } + }; + template + struct Group_attribute_functor_of_dart_run + { + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle, + int) + { + } + }; + + /// Functor used for link_beta to update the attributes of + /// adart2 on the attributes of this dart, except for adim-attributes. + /// We define run to allows to use this functor with + /// Foreach_enabled_attributes. + template + struct Group_attribute_functor_of_dart + { + template + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2, int adim) + { + CGAL_assertion( adim==-1 || + (0<=adim && (unsigned int)adim<=CMap::dimension) ); + Group_attribute_functor_of_dart_run:: + run(amap,adart1,adart2,adim); + } + }; + + // ************************************************************************** + + + //////////////////////////////////// template struct Couple_dart_and_dim { @@ -43,6 +157,7 @@ namespace CGAL { int dim; }; + // Functor used to group one attribute of two given darts template struct Group_one_attribute_functor @@ -90,7 +205,7 @@ namespace CGAL { { return false; } }; - // Functor used to degroup one attribute of one dart +/* // Functor used to degroup one attribute of one dart template struct Degroup_one_attribute_of_dart_functor { @@ -112,7 +227,7 @@ namespace CGAL { typename CMap::Dart_handle, typename CMap::Dart_handle) { return false; } - }; + };*/ /// Functor used to call decrease_attribute_ref_counting /// on each i-cell attribute enabled @@ -330,78 +445,6 @@ namespace CGAL { {} }; - /// Functor used for link_beta to update the attributes of - /// adart2 on the attributes of this dart, except for adimension-attributes. - template - struct Group_attribute_functor_of_dart_run - { - static void run(CMap* amap, - typename CMap::Dart_handle dh1, - typename CMap::Dart_handle dh2, - int adim) - { - CGAL_assertion( adim==-1 || - (0<=adim && (unsigned int)adim<=CMap::dimension) ); - if ( adim!=i ) - { - amap->template group_enabled_attribute_of_dart - ::type> - (dh1, dh2); - } - } - }; - template - struct Group_attribute_functor_of_dart_run - { - static void run(CMap* amap, - typename CMap::Dart_handle dh1, - typename CMap::Dart_handle dh2, - int adim) - { - CGAL_assertion( adim==-1 || - (0<=adim && (unsigned int)adim<=CMap::dimension) ); - // todo ASSERT (1<=adim && ...) ??? - if ( adim!=0 ) - { - typename CMap::Dart_handle od = dh1->other_extremity(); - if ( od!=NULL ) - { - typename CMap::Helper::template Attribute_handle<0>::type - a1=od->template attribute<0>(); - if ( a1!=NULL && a1!=dh2->template attribute<0>() ) - amap->template set_attribute_of_dart<0>(dh2, a1); - } - } - - if ( adim!=1 ) - { - typename CMap::Dart_handle od = dh2->other_extremity(); - if ( od!=NULL && dh1->template attribute<0>()==NULL ) - { - typename CMap::Helper::template Attribute_handle<0>::type - a2=od->template attribute<0>(); - if ( a2!=NULL ) - amap->template set_attribute_of_dart<0>(dh1, a2); - } - } - } - }; - - template - struct Group_attribute_functor_of_dart - { - template - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2, int adim) - { - CGAL_assertion( adim==-1 || - (0<=adim && (unsigned int)adim<=CMap::dimension) ); - Group_attribute_functor_of_dart_run:: - run(amap,adart1,adart2,adim); - } - }; - // Functor used to call the On_split functor between the two given darts. template + struct Conditionnal_run_except{ + template + static void run(const T& ... t){ + Functor:: template run(t...); + } + }; + + template + struct Conditionnal_run + { + template + static void run(T...){} + }; + + template + struct Conditionnal_run + { + template + static void run(T...){} + }; + //Same as Foreach_static excepted that Functor //is called for case k only if the k'th type in the tuple //is different from Void. Note that to the converse of Foreach_static @@ -279,6 +303,31 @@ namespace CGAL template static void run(const T& ... ){} }; + + //Same as Foreach_static_restricted excepted that Functor + //is called for case k only if the k'th type in the tuple + //is different from Void and k!=j. + template + struct Foreach_static_restricted_except; + + template + struct Foreach_static_restricted_except,n> + { + template + static void run(const T& ... t){ + Conditionnal_run_except::run(t...); + Foreach_static_restricted_except + ,n+1>::run(t...); + } + }; + + template + struct Foreach_static_restricted_except,n> + { + template + static void run(const T& ... ){} + }; #else // Definitions of structs are moved to another file. #include