From fbe2a506d781fe6144bc91e1d60d2050aadbecde Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 11 Feb 2013 22:03:18 +0100 Subject: [PATCH] Continue on group/ungroup: nyf --- .../include/CGAL/Combinatorial_map.h | 323 +++------ .../CGAL/Combinatorial_map_operations.h | 432 ++++++------ .../internal/Combinatorial_map_functors.h | 645 ++++++++++++------ 3 files changed, 732 insertions(+), 668 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 16d800d60a8..9f2a64dabab 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -86,13 +86,7 @@ namespace CGAL { 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_functor; - - template - friend struct internal::Test_is_valid_attribute_functor; + friend struct internal::Degroup_one_attribute_of_dart_functor; template friend struct internal::Group_attribute_functor_of_dart_run; @@ -100,11 +94,16 @@ namespace CGAL { template friend struct internal::Group_attribute_functor_run; - template - friend struct internal::Group_one_attribute_functor; - template friend struct internal::Degroup_attribute_functor_run; + */ + + template + friend struct internal::Degroup_one_attribute_functor; + + template + friend struct internal::Test_is_valid_attribute_functor; + template friend struct internal::Update_dart_of_attribute_functor; @@ -1420,7 +1419,7 @@ namespace CGAL { CGAL_assertion( (is_sewable_1(adart1,adart2)) ); int m = get_new_mark(); - std::vector dartv; + std::deque dartv; for (CMap_dart_iterator_basic_of_cell it(*this,adart1,m); it.cont(); ++it) { @@ -1432,14 +1431,12 @@ namespace CGAL { CMap_dart_iterator_of_involution_inv I2(*this, adart2); while ( I1.cont() ) { - if ( is_marked(I1,m) ) - basic_link_beta_1(I1, I2); - else - basic_link_beta_0(I1, I2); + if ( is_marked(I1,m) ) basic_link_beta_1(I1, I2); + else basic_link_beta_0(I1, I2); ++I1; ++I2; } - for (typename std::vector::iterator + for (typename std::deque::iterator it=dartv.begin(); it!=dartv.end(); ++it) { unmark(*it,m); } CGAL_assertion( is_whole_map_unmarked(m) ); @@ -1521,8 +1518,8 @@ namespace CGAL { { Dart_handle od1=I1->other_extremity(); Dart_handle od2=I2->other_extremity(); - if (od1!=NULL && od2!=NULL) - group_all_attributes_except(od1, od2, 1); + /*if (od1!=NULL && od2!=NULL) TODO + group_all_attributes_except(od1, od2, 1);*/ ++I1; ++I2; } @@ -1567,7 +1564,7 @@ namespace CGAL { CMap_dart_iterator_of_involution_inv I2(*this, adart2); while ( I1.cont() ) { - group_all_attributes_except(I1,I2,1); + // TODO group_all_attributes_except(I1,I2,1); ++I1; ++I2; } @@ -1613,7 +1610,7 @@ namespace CGAL { while ( I1.cont() ) { - group_all_attributes_except(I1,I2,i); + // TODO group_all_attributes_except(I1,I2,i); ++I1; ++I2; } @@ -1783,8 +1780,8 @@ namespace CGAL { // TODO do the degroup after the loop (cf unsew_for_involution) Dart_handle od1=it->other_extremity(); Dart_handle od2=d2->other_extremity(); - if ( od1!=NULL && od2!=NULL ) - degroup_all_attributes_except(od1,od2,1); + /* TODO if ( od1!=NULL && od2!=NULL ) + degroup_all_attributes_except(od1,od2,1); */ ++it; } @@ -1828,7 +1825,7 @@ namespace CGAL { else { d2 = it->beta(0); unlink_beta_0(it); } // TODO do the degroup after the loop (cf unsew_for_involution) - degroup_all_attributes_except(it,d2,1); + // TODO degroup_all_attributes_except(it,d2,1); ++it; } } @@ -1869,7 +1866,7 @@ namespace CGAL { { internal::Couple_dart_and_dim c=todegroup.top(); todegroup.pop(); - degroup_all_attributes_except(c.d1,c.d2,c.dim); + // TODO degroup_all_attributes_except(c.d1,c.d2,c.dim); } } @@ -2057,6 +2054,7 @@ namespace CGAL { } } + public: /** Update the dart of the given i-cell attribute onto a non marked dart. * @param ah the attribute to update. * @param amark the mark. @@ -2097,91 +2095,6 @@ 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 - * of \em adart2 onto the i-cell of \em adart1. - * We use the functor On_merge and possibly remove the second - * cell-attribute if there is no more darts linked to it. - * @param adart1 the first dart. - * @param adart2 the second dart. - */ - template - void group_enabled_attribute( Dart_handle adart1, Dart_handle adart2) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "group_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=adart2->template attribute(); - - // If the two attributes are equal, nothing to do. - if ( a1 == a2 ) return; - - Dart_handle toSet = NULL; - - // If the attribute associated to adart1 is NULL, set it with - // the attribute associated to adart2 (necessarily != NULL) - if (a1 == NULL) - { toSet = adart1; a1 = a2; } - else - { - toSet = adart2; - if (a2 != NULL) - { - internal::Apply_cell_functor::run(*a1,*a2); - } - } - set_attribute(toSet, a1); - } - /** 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 @@ -2230,86 +2143,6 @@ namespace CGAL { 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. - */ - template - void group_attribute(Dart_handle adart1, Dart_handle adart2) - { - internal::Group_one_attribute_functor::type>::run(this,adart1,adart2); - } - - /** Group all the dart attributes of adart1 and adart2, except the - * adim-cell attribute. - * @param adart1 the first dart. - * @param adart1 the second dart. - * @param adim the dimension to not group (-1 to group all dimensions). - * note that 0-attr are always grouped if adart1-> other_extremity()!=NULL. - */ - void group_all_dart_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); - } - - /** Group all the cells attributes of adart1 and adart2, except the - * adim-cell attribute. - * @param adart1 the first dart. - * @param adart1 the second dart. - * @param adim the dimension to not group (-1 to group all dimensions). - * note that 0-attr are always grouped if adart1-> other_extremity()!=NULL. - */ - 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); - } - - template - bool degroup_attribute(Dart_handle adart1, Dart_handle adart2) - { - return internal::Degroup_one_attribute_functor::type>::run(this,adart1,adart2); - } - - /** Degroup all the cells attributes of adart1 and adart2, except the - * adim-cell attribute. - * @param adart1 the first dart. - * @param adart1 the second dart. - * @param adim the dimension to not degroup (-1 to degroup all). - */ - void degroup_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 all the cells attributes of adart1 and adart2. - * @param adart1 the first dart. - * @param adart1 the second dart. - */ - void degroup_all_attributes(Dart_handle adart1, Dart_handle adart2) - { degroup_all_attributes_except(adart1, adart2, -1); } - - /* template - bool degroup_attribute_of_dart(Dart_handle adart1, Dart_handle 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. * @param adart a dart. @@ -2393,52 +2226,6 @@ namespace CGAL { return res; } - public: - /** Set the i th attribute of the given dart. - * @param adart a dart. - * @param ah the attribute to set. - */ - template - void set_attribute_of_dart(Dart_handle adart, - typename Attribute_handle::type ah) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "set_attribute_of_dart but " - "i-attributes are disabled"); - CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); - 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); - } - - /** Set the i th attribute of all the darts of a given i-cell. - * @param adart a dart of the i-cell. - * @param ah the vertex to set. - */ - template - void set_attribute(Dart_handle adart, - typename Attribute_handle::type ah) - { - CGAL_static_assertion(i<=dimension); - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "set_attribute but i-attributes are disabled"); - CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); - for (CMap_dart_iterator_of_cell it(*this, adart); - it.cont(); ++it) - { - if ( it->template attribute()!=ah ) - { - decrease_attribute_ref_counting(it); - it->template set_attribute(ah); - } - } - ah->set_dart(adart); - } - #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES //************************************************************************** // Dart_of_orbit_basic_range @@ -3266,6 +3053,71 @@ namespace CGAL { { return one_dart_per_cell(); } //-------------------------------------------------------------------------- + /** Set the i th attribute of the given dart. + * @param adart a dart. + * @param ah the attribute to set. + */ + template + void set_attribute_of_dart(Dart_handle adart, + typename Attribute_handle::type ah) + { + CGAL_static_assertion(i<=dimension); + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "set_attribute_of_dart but " + "i-attributes are disabled"); + CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); + 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); + } + + public: + + /** Set the i-attribute of all the darts of a given range. + * @param adart a starting dart. + * @param ah an handle to the i-attribute to set. + */ + template + void set_attribute(Dart_handle adart, + typename Attribute_handle::type ah) + { + CGAL_static_assertion(i<=dimension); + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "set_attribute but i-attributes are disabled"); + CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); + for (typename Dart_of_cell_range::iterator it(*this, adart); + it.cont(); ++it) + { + if ( it->template attribute()!=ah ) + { + decrease_attribute_ref_counting(it); + it->template set_attribute(ah); + } + } + ah->set_dart(adart); + } + template + void set_attribute(Dart_handle adart, + typename Attribute_handle::type ah) + { + CGAL_static_assertion(i<=dimension); + CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, + "set_attribute but i-attributes are disabled"); + CGAL_assertion( adart!=NULL && adart!=null_dart_handle && ah!=NULL ); + for (typename Range::iterator it(*this, adart); it.cont(); ++it) + { + if ( it->template attribute()!=ah ) + { + decrease_attribute_ref_counting(it); + it->template set_attribute(ah); + } + } + ah->set_dart(adart); + } + /** Compute the dual of a Combinatorial_map. * @param amap the cmap in which we build the dual of this map. * @param adart a dart of the initial map, NULL by default. @@ -3331,7 +3183,6 @@ namespace CGAL { return res; } - public: /// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle. static Dart_handle null_dart_handle; diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index db807fc5a64..0112fd9991e 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -38,16 +38,16 @@ namespace CGAL { */ // TODO revoir toute la gestion des attributs // (utilisation correcte des link avec/sans la maj) - template < class Map > - typename Map::Dart_handle - insert_cell_0_in_cell_2(Map& amap, typename Map::Dart_handle adart) + template < class CMap > + typename CMap::Dart_handle + insert_cell_0_in_cell_2(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_assertion(adart != NULL && adart!=Map::null_dart_handle); + CGAL_assertion(adart != NULL && adart!=CMap::null_dart_handle); - typename Map::Dart_handle first = adart, prev = NULL, cur = NULL; - typename Map::Dart_handle n1 = NULL, n2 = NULL; + typename CMap::Dart_handle first = adart, prev = NULL, cur = NULL; + typename CMap::Dart_handle n1 = NULL, n2 = NULL; - typename Map::Dart_handle nn1 = NULL, nn2 = NULL; + typename CMap::Dart_handle nn1 = NULL, nn2 = NULL; // If the facet is open, we search the dart 0-free while (!first->is_free(0) && first->beta(0) != adart) @@ -55,17 +55,17 @@ namespace CGAL { // Stack of couple of dart and dimension for which // we must call on_split functor - std::stack > + std::stack > tosplit; // Mark used to mark darts already treated. int treated = amap.get_new_mark(); // Stack of marked darts - std::stack tounmark; + std::stack tounmark; // Now we run through the facet - for (CGAL::CMap_dart_iterator_basic_of_orbit it(amap,first); + for (CGAL::CMap_dart_iterator_basic_of_orbit it(amap,first); it.cont();) { cur = it; @@ -80,14 +80,14 @@ namespace CGAL { { // 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 + /* for (typename CMap::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)); } } @@ -112,7 +112,7 @@ namespace CGAL { if (n1 != NULL && prev != NULL) amap.template link_beta_for_involution<2>(prev, n1); - for (unsigned int dim=3; dim<=Map::dimension; ++dim) + for (unsigned int dim=3; dim<=CMap::dimension; ++dim) { if ( !adart->is_free(dim) ) { @@ -159,7 +159,7 @@ namespace CGAL { if (n2 != NULL) { amap.template link_beta_for_involution<2>(first->beta(0), n2); - for (unsigned int dim=3; dim<=Map::dimension; ++dim) + for (unsigned int dim=3; dim<=CMap::dimension; ++dim) { if ( !adart->is_free(dim) ) { @@ -181,9 +181,9 @@ namespace CGAL { while ( !tosplit.empty() ) { - internal::Couple_dart_and_dim c=tosplit.top(); + internal::Couple_dart_and_dim c=tosplit.top(); tosplit.pop(); - internal::Call_split_functor::run(c.d1, c.d2); + internal::Call_split_functor::run(c.d1, c.d2); } CGAL_expensive_postcondition( amap.is_valid() ); @@ -192,24 +192,24 @@ namespace CGAL { } /** Test if an i-cell can be removed. - * An i-cell can be removed if i==Map::dimension or i==Map::dimension-1, + * 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 < class Map, unsigned int i > - bool is_removable(const Map& amap, typename Map::Dart_const_handle adart) + 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<=Map::dimension); + CGAL_static_assertion(0<=i && i<=CMap::dimension); - if ( i==Map::dimension ) return true; - if ( i==Map::dimension-1 ) return true; + 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 (CMap_dart_const_iterator_of_cell it(amap, adart); + for (CMap_dart_const_iterator_of_cell it(amap, adart); res && it.cont(); ++it) { if (it->template beta()->template beta()!= @@ -225,39 +225,39 @@ namespace CGAL { * @param adart a dart of the i-cell to remove. * @return the number of deleted darts. */ - template + template struct Remove_cell_functor { - static size_t run(Map& amap, typename Map::Dart_handle adart) + static size_t run(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_static_assertion ( 1<=i && i(amap, adart)) ); + CGAL_static_assertion ( 1<=i && i(amap, adart)) ); size_t res = 0; - typename Map::Dart_handle d1, d2; - typename Map::Dart_handle dg1=NULL, dg2=NULL; + typename CMap::Dart_handle d1, d2; + typename CMap::Dart_handle dg1=NULL, dg2=NULL; int mark = amap.get_new_mark(); int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; + std::deque to_erase; const int iinv = CGAL_BETAINV(i); - /*int mark_for_incident_cells[Map::Helper::nb_attribs]; - std::deque > - incident_cells[Map::Helper::nb_attribs]; + /*int mark_for_incident_cells[CMap::Helper::nb_attribs]; + std::deque > + incident_cells[CMap::Helper::nb_attribs]; // Marks used to mark all the incident cells. - for (int j=0; j it(amap,adart,mark); + for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -269,35 +269,35 @@ namespace CGAL { // Second we store all the incident cells that can be split by // the operation. - typename std::deque::iterator it = + typename std::deque::iterator it = to_erase.begin(); /*for (; it != to_erase.end(); ++it) { d1 = (*it)->beta(iinv); - while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) + while ( d1!=CMap::null_dart_handle && amap.is_marked(d1, mark) ) { d1 = d1->beta(i+1)->beta(iinv); - if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; + if (d1 == (*it)->beta(iinv)) d1 = CMap::null_dart_handle; } d2 = (*it)->beta(i+1)->beta(i); - while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) ) + while ( d2!=CMap::null_dart_handle && amap.is_marked(d2, mark) ) { d2 = d2->beta(i+1)->beta(i); - if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle; + if ( d2==(*it)->beta(i+1)->beta(i) ) d2=CMap::null_dart_handle; } - if (d1 != Map::null_dart_handle) + if (d1 != CMap::null_dart_handle) { - if (d2 != Map::null_dart_handle) + if (d2 != CMap::null_dart_handle) { if ( dg1==NULL ) { dg1 = d1; dg2=d2; } - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, d1, mark, &mark_for_incident_cells[0], &incident_cells[0]); - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, d2, mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -305,19 +305,19 @@ namespace CGAL { { if ( !d1->is_free(i) ) { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, d1->beta(i), mark, &mark_for_incident_cells[0], &incident_cells[0]); } } } - else if (d2 != Map::null_dart_handle) + else if (d2 != CMap::null_dart_handle) { if ( !d2->is_free(iinv) ) { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, d2, mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -328,8 +328,8 @@ namespace CGAL { d1 = (*it)->beta(i); if ( !d1->is_free(iinv) ) { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, d1, mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -344,35 +344,36 @@ namespace CGAL { // We group the two (i+1)-cells incident if they exist. if ( dg1!=NULL ) - amap.template group_attribute(dg1, dg2); + internal::Group_attribute_functor_run:: + run(&amap, dg1, dg2); - std::deque modified_darts; - // std::deque modified_darts2; + std::deque modified_darts; + // std::deque modified_darts2; // For each dart of the i-cell, we modify i-links of neighbors. for ( it=to_erase.begin(); it != to_erase.end(); ++it) { - d1 = (*it)->beta(iinv); - while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) + d1=(*it)->beta(iinv); + while ( d1!=CMap::null_dart_handle && amap.is_marked(d1, mark) ) { - d1 = d1->beta(i+1)->beta(iinv); - if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; + d1=d1->beta(i+1)->beta(iinv); + if ( d1==(*it)->beta(iinv) ) d1=CMap::null_dart_handle; } if ( !amap.is_marked(d1, mark_modified_darts) ) { - d2 = (*it)->beta(i+1)->beta(i); - while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) ) + d2=(*it)->beta(i+1)->beta(i); + while ( d2!=CMap::null_dart_handle && amap.is_marked(d2, mark) ) { - d2 = d2->beta(i+1)->beta(i); - if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle; + d2=d2->beta(i+1)->beta(i); + if ( d2==(*it)->beta(i+1)->beta(i) ) d2=CMap::null_dart_handle; } if ( !amap.is_marked(d2, mark_modified_darts) ) { - if (d1 != Map::null_dart_handle) + if ( d1!=CMap::null_dart_handle ) { - if (d2 != Map::null_dart_handle && d1!=d2 ) + if ( d2!=CMap::null_dart_handle && d1!=d2 ) { //d1->basic_link_beta(d2, i); amap.template basic_link_beta(d1, d2); @@ -398,7 +399,7 @@ namespace CGAL { } } } - else if (d2 != Map::null_dart_handle) + else if ( d2!=CMap::null_dart_handle ) { if ( !d2->is_free(iinv) ) { @@ -425,9 +426,9 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. - Map::Helper::template Foreach_enabled_attributes - >:: - // >:: + CMap::Helper::template Foreach_enabled_attributes + >:: + // >:: run(&amap, &modified_darts, mark_modified_darts); //&modified_darts2); //&mark_for_incident_cells[0], &incident_cells[0]); @@ -441,11 +442,11 @@ namespace CGAL { if ( !amap.is_whole_map_unmarked(mark_modified_darts) ) { - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts.begin(); it!=modified_darts.end(); ++it ) amap.unmark(*it, mark_modified_darts); - /*for ( typename std::deque:: + /*for ( typename std::deque:: iterator it=modified_darts2.begin(); it!=modified_darts2.end(); ++it ) amap.unmark(*it, mark_modified_darts);*/ @@ -455,7 +456,7 @@ namespace CGAL { amap.free_mark(mark_modified_darts); // We free the marks. - /*for (int j=0; j - struct Remove_cell_functor + template + struct Remove_cell_functor { - static size_t run(Map& amap, typename Map::Dart_handle adart) + static size_t run(CMap& amap, typename CMap::Dart_handle adart) { CGAL_assertion( adart!=NULL ); int mark = amap.get_new_mark(); - std::deque to_erase; + std::deque to_erase; size_t res = 0; - std::deque modified_darts; + std::deque modified_darts; -/* int mark_for_incident_cells[Map::Helper::nb_attribs]; - std::deque > - incident_cells[Map::Helper::nb_attribs]; +/* int mark_for_incident_cells[CMap::Helper::nb_attribs]; + std::deque > + incident_cells[CMap::Helper::nb_attribs]; // Marks used to mark all the incident cells. - for (int j=0; j + for (CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it) { to_erase.push_back(it); @@ -508,17 +509,17 @@ namespace CGAL { ++res; } - typename std::deque::iterator + typename std::deque::iterator it = to_erase.begin(); // 2) We store all the incident cells that can be split by the operation, // and we update the dart of the cells incident to the remove volume. /* for ( ; it != to_erase.end(); ++it ) { - if ( !(*it)->is_free(Map::dimension) ) + if ( !(*it)->is_free(CMap::dimension) ) { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, *it, mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -529,19 +530,19 @@ namespace CGAL { // 3) We unlink all the darts of the volume for beta-d. for ( it = to_erase.begin(); it != to_erase.end(); ++it ) { - if ( !(*it)->is_free(Map::dimension) && - !amap.is_marked((*it)->beta(Map::dimension), mark) ) + if ( !(*it)->is_free(CMap::dimension) && + !amap.is_marked((*it)->beta(CMap::dimension), mark) ) { - modified_darts.push_back((*it)->beta(Map::dimension)); - //(*it)->beta(Map::dimension)->unlink_beta(Map::dimension); - amap.template unlink_beta_for_involution(*it, Map::dimension); + modified_darts.push_back((*it)->beta(CMap::dimension)); + //(*it)->beta(CMap::dimension)->unlink_beta(CMap::dimension); + amap.template unlink_beta_for_involution(*it); } } // 4) We test the split of all the incident cells for all the non // void attributes. - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, &modified_darts, -1); //, modified_darts2); //&mark_for_incident_cells[0], //&incident_cells[0]); @@ -554,7 +555,7 @@ namespace CGAL { amap.free_mark(mark); // We free the marks. -/* for (int j=0; j - struct Remove_cell_functor + template + struct Remove_cell_functor { - static size_t run(Map& amap, typename Map::Dart_handle adart) + static size_t run(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_assertion( (is_removable(amap,adart)) ); + CGAL_assertion( (is_removable(amap,adart)) ); size_t res = 0; - typename Map::Dart_handle d1, d2; - typename Map::Dart_handle dg1=NULL, dg2=NULL; + typename CMap::Dart_handle d1, d2; + typename CMap::Dart_handle dg1=NULL, dg2=NULL; int mark = amap.get_new_mark(); // int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; + std::deque to_erase; - std::deque modified_darts; + std::deque modified_darts; -/* int mark_for_incident_cells[Map::Helper::nb_attribs]; - std::deque > - incident_cells[Map::Helper::nb_attribs]; +/* int mark_for_incident_cells[CMap::Helper::nb_attribs]; + std::deque > + incident_cells[CMap::Helper::nb_attribs]; // Marks used to mark all the incident cells. - for (int j=0; j it(amap,adart,mark); + for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -617,7 +618,7 @@ namespace CGAL { // Second we store all the incident cells that can be split by // the operation. - typename std::deque::iterator it = + typename std::deque::iterator it = to_erase.begin(); /* for (; it != to_erase.end(); ++it) { @@ -626,15 +627,15 @@ namespace CGAL { if ( !(*it)->is_free(1) && (*it)->beta(0)!=(*it) ) { if ( dg1==NULL ) { dg1=(*it)->beta(0); dg2=(*it)->beta(1); } - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, *it, mark, &mark_for_incident_cells[0], &incident_cells[0]); } else { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, *it, mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -643,8 +644,8 @@ namespace CGAL { { if ( !(*it)->is_free(1) ) { - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, (*it)->beta(1), mark, &mark_for_incident_cells[0], &incident_cells[0]); } @@ -657,7 +658,8 @@ namespace CGAL { // We group the two edges incident if they exist. if ( dg1!=NULL ) - amap.template group_attribute<1>(dg1, dg2); + internal::Group_attribute_functor_run:: + run(&amap, dg1, dg2); // For each dart of the vertex, we modify 0 and 1-links of neighbors. for ( it=to_erase.begin(); it != to_erase.end(); ++it) @@ -676,7 +678,7 @@ namespace CGAL { modified_darts.push_back((*it)->beta(0)); } - for ( unsigned int j=2; j<=Map::dimension; ++j ) + for ( unsigned int j=2; j<=CMap::dimension; ++j ) { if ( !(*it)->is_free(j) ) { @@ -695,7 +697,7 @@ namespace CGAL { modified_darts.push_back((*it)->beta(1)); } - for ( unsigned int j=2; j<=Map::dimension; ++j ) + for ( unsigned int j=2; j<=CMap::dimension; ++j ) { if ( !(*it)->is_free(j) ) { @@ -709,9 +711,9 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. - Map::Helper::template Foreach_enabled_attributes - >:: - // >:: + CMap::Helper::template Foreach_enabled_attributes + >:: + // >:: run(&amap, &modified_darts, -1); //mark_modified_darts); //&mark_for_incident_cells[0], @@ -725,7 +727,7 @@ namespace CGAL { amap.free_mark(mark); // We free the marks. - /* for (int j=0; j - size_t remove_cell(Map& amap, typename Map::Dart_handle adart) - { return Remove_cell_functor::run(amap,adart); } + template < class CMap, unsigned int i > + size_t remove_cell(CMap& amap, typename CMap::Dart_handle adart) + { return Remove_cell_functor::run(amap,adart); } /** Test if an edge can be inserted onto a 2-cell between two given darts. * @param amap the used combinatorial map. @@ -755,14 +757,14 @@ namespace CGAL { * @param adart2 a second dart. * @return true iff an edge can be inserted between adart1 and adart2. */ - template < class Map > - bool is_insertable_cell_1_in_cell_2(const Map& amap, - typename Map::Dart_const_handle adart1, - typename Map::Dart_const_handle adart2) + template < class CMap > + bool is_insertable_cell_1_in_cell_2(const CMap& amap, + typename CMap::Dart_const_handle adart1, + typename CMap::Dart_const_handle adart2) { CGAL_assertion(adart1 != NULL && adart2 != NULL); if ( adart1==adart2 ) return false; - for ( CMap_dart_const_iterator_of_orbit it(amap,adart1); + for ( CMap_dart_const_iterator_of_orbit it(amap,adart1); it.cont(); ++it ) { if ( it==adart2 ) return true; @@ -776,11 +778,11 @@ namespace CGAL { * @param adart a dart of the i-cell. * @return true iff the i-cell can be contracted. */ - template < class Map, unsigned int i > - bool is_contractible(const Map& amap, typename Map::Dart_const_handle adart) + 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<=Map::dimension); + CGAL_static_assertion(0<=i && i<=CMap::dimension); if ( i==0 ) return false; if ( i==1 ) return true; @@ -788,7 +790,7 @@ namespace CGAL { // TODO ? Optimisation possible to not test all // the darts of the cell ? bool res = true; - for (CMap_dart_const_iterator_of_cell it(amap, adart); + for (CMap_dart_const_iterator_of_cell it(amap, adart); res && it.cont(); ++it) { if ( it->beta(i-2)->beta(i-1)!=it->beta(i-1)->beta_inv(i-2) ) @@ -803,28 +805,28 @@ namespace CGAL { * @param adart a dart of the i-cell to contract. * @return the number of deleted darts. */ - template + template struct Contract_cell_functor { - static size_t run(Map& amap, typename Map::Dart_handle adart) + static size_t run(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_static_assertion ( 2<=i && i<=Map::dimension ); - CGAL_assertion( (is_contractible(amap, adart)) ); + CGAL_static_assertion ( 2<=i && i<=CMap::dimension ); + CGAL_assertion( (is_contractible(amap, adart)) ); size_t res = 0; - typename Map::Dart_handle d1, d2; - typename Map::Dart_handle dg1=NULL, dg2=NULL; + typename CMap::Dart_handle d1, d2; + typename CMap::Dart_handle dg1=NULL, dg2=NULL; int mark = amap.get_new_mark(); int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; + std::deque to_erase; const int imuinv = CGAL_BETAINV(i-1); // First we store and mark all the darts of the i-cell to contract. - for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -836,40 +838,41 @@ namespace CGAL { // We group the two (i+1)-cells incident if they exist. if ( dg1!=NULL ) - amap.template group_attribute(dg1, dg2); + internal::Group_attribute_functor_run:: + run(&amap, dg1, dg2); // Second we update the dart of the cell attributes on non marked darts. - typename std::deque::iterator it = + typename std::deque::iterator it = to_erase.begin(); for (; it != to_erase.end(); ++it) amap.update_dart_of_all_attributes(*it, mark); - std::deque modified_darts; + std::deque modified_darts; // For each dart of the i-cell, we modify i-links of neighbors. for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { d1 = (*it)->beta(i); - while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) + while ( d1!=CMap::null_dart_handle && amap.is_marked(d1, mark) ) { d1 = d1->beta(imuinv)->beta(i); - if (d1 == (*it)->beta(i)) d1 = Map::null_dart_handle; + if (d1 == (*it)->beta(i)) d1 = CMap::null_dart_handle; } if ( !amap.is_marked(d1, mark_modified_darts) ) { d2 = (*it)->beta(i-1)->beta(i); - while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) ) + while ( d2!=CMap::null_dart_handle && amap.is_marked(d2, mark) ) { d2 = d2->beta(i-1)->beta(i); - if ( d2==(*it)->beta(i-1)->beta(i) ) d2=Map::null_dart_handle; + if ( d2==(*it)->beta(i-1)->beta(i) ) d2=CMap::null_dart_handle; } if ( !amap.is_marked(d2, mark_modified_darts) ) { - if (d1 != Map::null_dart_handle) + if (d1 != CMap::null_dart_handle) { - if (d2 != Map::null_dart_handle && d1!=d2 ) + if (d2 != CMap::null_dart_handle && d1!=d2 ) { amap.template basic_link_beta(d1, d2); amap.mark(d1, mark_modified_darts); @@ -888,7 +891,7 @@ namespace CGAL { } } } - else if (d2 != Map::null_dart_handle) + else if (d2 != CMap::null_dart_handle) { if ( !d2->is_free(i) ) { @@ -915,8 +918,8 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. - Map::Helper::template Foreach_enabled_attributes - >:: + CMap::Helper::template Foreach_enabled_attributes + >:: run(&amap, &modified_darts, mark_modified_darts); // We remove all the darts of the i-cell. @@ -928,7 +931,7 @@ namespace CGAL { if ( !amap.is_whole_map_unmarked(mark_modified_darts) ) { - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts.begin(); it!=modified_darts.end(); ++it ) amap.unmark(*it, mark_modified_darts); @@ -951,27 +954,27 @@ namespace CGAL { * @param adart a dart of the edge to contract. * @return the number of deleted darts. */ - template - struct Contract_cell_functor + template + struct Contract_cell_functor { - static size_t run(Map& amap, typename Map::Dart_handle adart) + static size_t run(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_assertion( (is_contractible(amap,adart)) ); + CGAL_assertion( (is_contractible(amap,adart)) ); size_t res = 0; - typename Map::Dart_handle d1, d2; - typename Map::Dart_handle dg1=NULL, dg2=NULL; + typename CMap::Dart_handle d1, d2; + typename CMap::Dart_handle dg1=NULL, dg2=NULL; int mark = amap.get_new_mark(); // int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; + std::deque to_erase; - std::deque modified_darts; + std::deque modified_darts; // First we store and mark all the darts of the 1-cell to contract. - for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -981,7 +984,7 @@ namespace CGAL { ++res; } - typename std::deque::iterator it = + typename std::deque::iterator it = to_erase.begin(); for (; it != to_erase.end(); ++it) @@ -989,7 +992,8 @@ namespace CGAL { // We group the two vertices incident if they exist. if ( dg1!=NULL ) - amap.template group_attribute<0>(dg1, dg2); + internal::Group_attribute_functor_run:: + run(&amap, dg1, dg2); // 4) For each dart of the cell, we modify link of neighbors. for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) @@ -1026,9 +1030,9 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. - Map::Helper::template Foreach_enabled_attributes - >:: - // >:: + CMap::Helper::template Foreach_enabled_attributes + >:: + // >:: run(&amap, &modified_darts, -1); //mark_modified_darts); //&mark_for_incident_cells[0], @@ -1053,9 +1057,9 @@ namespace CGAL { * @param adart a dart of the i-cell to remove. * @return the number of deleted darts. */ - template < class Map, unsigned int i > - size_t contract_cell(Map& amap, typename Map::Dart_handle adart) - { return Contract_cell_functor::run(amap,adart); } + template < class CMap, unsigned int i > + size_t contract_cell(CMap& amap, typename CMap::Dart_handle adart) + { return Contract_cell_functor::run(amap,adart); } /** Test if a 2-cell can be inserted onto a given 3-cell along * a path of edges. @@ -1064,32 +1068,32 @@ namespace CGAL { * @param alast iterator on the end of the path. * @return true iff a 2-cell can be inserted along the path. */ - template - bool is_insertable_cell_2_in_cell_3(const Map& amap, + template + bool is_insertable_cell_2_in_cell_3(const CMap& amap, InputIterator afirst, InputIterator alast) { - CGAL_static_assertion( Map::dimension>= 3 ); + CGAL_static_assertion( CMap::dimension>= 3 ); // The path must have at least one dart. if (afirst==alast) return false; - typename Map::Dart_const_handle prec = NULL; - typename Map::Dart_const_handle od = NULL; + typename CMap::Dart_const_handle prec = NULL; + typename CMap::Dart_const_handle od = NULL; for (InputIterator it(afirst); it!=alast; ++it) { // The path must contain only non empty darts. - if (*it == NULL || *it==Map::null_dart_handle) return false; + if (*it == NULL || *it==CMap::null_dart_handle) return false; // Two consecutive darts of the path must belong to two edges // incident to the same vertex of the same volume. if (prec != NULL) { od = prec->other_extremity(); - if ( od==Map::null_dart_handle ) return false; + if ( od==CMap::null_dart_handle ) return false; // of and *it must belong to the same vertex of the same volume - if ( !belong_to_same_cell(amap, od, *it) ) + if ( !belong_to_same_cell(amap, od, *it) ) return false; } prec = *it; @@ -1097,9 +1101,9 @@ namespace CGAL { // The path must be closed. od = prec->other_extremity(); - if ( od==Map::null_dart_handle ) return false; + if ( od==CMap::null_dart_handle ) return false; - if (!belong_to_same_cell(amap, od, *afirst)) + if (!belong_to_same_cell(amap, od, *afirst)) return false; return true; @@ -1110,25 +1114,25 @@ namespace CGAL { * @param adart a dart of the edge (!=NULL && !=null_dart_handle). * @return a dart of the new vertex. */ - template - typename Map::Dart_handle - insert_cell_0_in_cell_1(Map& amap, typename Map::Dart_handle adart) + template + typename CMap::Dart_handle + insert_cell_0_in_cell_1(CMap& amap, typename CMap::Dart_handle adart) { - CGAL_assertion(adart != NULL && adart!=Map::null_dart_handle); + CGAL_assertion(adart != NULL && adart!=CMap::null_dart_handle); - typename Map::Dart_handle d1, d2; + typename CMap::Dart_handle d1, d2; int mark = amap.get_new_mark(); - std::vector vect; + std::vector vect; { - for (typename Map::template Dart_of_cell_range<1>::iterator it= + for (typename CMap::template Dart_of_cell_range<1>::iterator it= amap.template darts_of_cell<1>(adart).begin(); it != amap.template darts_of_cell<1>(adart).end(); ++it) vect.push_back(it); } // 3) For each dart of the cell, we modify link of neighbors. - typename std::vector::iterator it = vect.begin(); + typename std::vector::iterator it = vect.begin(); for (; it != vect.end(); ++it) { d1 = amap.create_dart(); @@ -1136,7 +1140,7 @@ namespace CGAL { if (!(*it)->is_free(1)) { amap.template basic_link_beta<1>(d1, (*it)->beta(1)); } - for ( unsigned int dim = 2; dim<=Map::dimension; ++dim ) + for ( unsigned int dim = 2; dim<=CMap::dimension; ++dim ) { if (!(*it)->is_free(dim) && amap.is_marked((*it)->beta(dim), mark)) { @@ -1157,7 +1161,7 @@ namespace CGAL { amap.free_mark(mark); - amap.template degroup_attribute<1>(adart, adart->beta(1)); + // TODO amap.template degroup_attribute<1>(adart, adart->beta(1)); // CGAL_expensive_postcondition( amap.is_valid() ); @@ -1169,16 +1173,16 @@ namespace CGAL { * @param adart1 a first dart of the facet (!=NULL && !=null_dart_handle). * @return a dart of the new edge, not incident to the vertex of adart1. */ - template - typename Map::Dart_handle - insert_dangling_cell_1_in_cell_2(Map& amap, typename Map::Dart_handle adart1) + template + typename CMap::Dart_handle + insert_dangling_cell_1_in_cell_2(CMap& amap, typename CMap::Dart_handle adart1) { - CGAL_assertion(adart1!=NULL && adart1!=Map::null_dart_handle); + CGAL_assertion(adart1!=NULL && adart1!=CMap::null_dart_handle); int mark1 = amap.get_new_mark(); - std::vector to_unmark; + std::vector to_unmark; { - for ( CMap_dart_iterator_basic_of_cell it(amap,adart1,mark1); + for ( CMap_dart_iterator_basic_of_cell it(amap,adart1,mark1); it.cont(); ++it ) { to_unmark.push_back(it); @@ -1186,13 +1190,13 @@ namespace CGAL { } } - typename Map::Dart_handle d1 = NULL; - typename Map::Dart_handle d2 = NULL; + typename CMap::Dart_handle d1 = NULL; + typename CMap::Dart_handle d2 = NULL; unsigned int s1 = 0; int treated = amap.get_new_mark(); - CGAL::CMap_dart_iterator_of_involution it1(amap,adart1); + CGAL::CMap_dart_iterator_of_involution it1(amap,adart1); for ( ; it1.cont(); ++it1) { @@ -1221,7 +1225,7 @@ namespace CGAL { amap.template link_beta_for_involution<2>(d1, d2); - for ( unsigned int dim=3; dim<=Map::dimension; ++dim) + for ( unsigned int dim=3; dim<=CMap::dimension; ++dim) { if ( !it1->is_free(dim) && amap.is_marked(it1->beta(dim), treated) ) @@ -1246,7 +1250,7 @@ namespace CGAL { CGAL_assertion( amap.is_whole_map_unmarked(treated) ); amap.free_mark(treated); - typename std::vector::iterator it = + typename std::vector::iterator it = to_unmark.begin(); for (; it != to_unmark.end(); ++it) { amap.unmark(*it, mark1); } @@ -1348,7 +1352,7 @@ namespace CGAL { } // amap.template degroup_attribute<1>(adart1, adart1->beta(0)); - amap.template degroup_attribute<2>(d1, d2); + // TODO amap.template degroup_attribute<2>(d1, d2); amap.negate_mark(m1); amap.negate_mark(m2); @@ -1386,13 +1390,13 @@ namespace CGAL { * @param alast iterator on the end of the path. * @return a dart of the new 2-cell. */ - template - typename Map::Dart_handle - insert_cell_2_in_cell_3(Map& amap, InputIterator afirst, InputIterator alast) + template + typename CMap::Dart_handle + insert_cell_2_in_cell_3(CMap& amap, InputIterator afirst, InputIterator alast) { CGAL_assertion(is_insertable_cell_2_in_cell_3(amap,afirst,alast)); - typename Map::Dart_handle prec = NULL, d = NULL, dd = NULL, first = NULL; + typename CMap::Dart_handle prec = NULL, d = NULL, dd = NULL, first = NULL; bool withBeta3 = false; { @@ -1435,13 +1439,13 @@ namespace CGAL { } // Make copies of the new facet for dimension >=4 - for ( unsigned int dim=4; dim<=Map::dimension; ++dim ) + for ( unsigned int dim=4; dim<=CMap::dimension; ++dim ) { if ( !first->is_free(dim) ) { - typename Map::Dart_handle first2 = NULL; + typename CMap::Dart_handle first2 = NULL; prec = NULL; - for ( CMap_dart_iterator_of_orbit it(amap, first); + for ( CMap_dart_iterator_of_orbit it(amap, first); it.cont(); ++it ) { d = amap.create_dart(); @@ -1462,7 +1466,7 @@ namespace CGAL { } else first2 = prec; - for ( unsigned dim2=2; dim2<=Map::dimension; ++dim2 ) + for ( unsigned dim2=2; dim2<=CMap::dimension; ++dim2 ) { if ( dim2+1!=dim && dim2!=dim && dim2!=dim+1 ) { @@ -1487,9 +1491,9 @@ namespace CGAL { } // Degroup the attributes - if ( withBeta3 ) + /* TODO if ( withBeta3 ) amap.template degroup_attribute<3>( first, first->beta(3) ); - +*/ // CGAL_expensive_postcondition( amap.is_valid() ); return first; diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index 2b7e21b5c94..cd052f0518b 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -31,34 +31,139 @@ * compiling time. * * Group_attribute_functor_of_dart to group the -attributes of two - * given darts (except for adim). + * given darts (except for j-dim). Only the attributes of the two given + * darts are possibly modified. * 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. * + * Group_attribute_functor to group the -attributes of two + * given i-cells (except forj-adim). If one i-attribute is NULL, we set the + * darts of its i-cell to the second attribute. If both i-attributes are + * non NULL, we overide all the i-attribute of the second i-cell to the + * first i-attribute. * + * Call_split_functor to call the OnSplit functor on two given + * i-attributes. * + ** Call_merge_functor to call the OnMerge functor on two given + * i-attributes. */ -namespace CGAL { - namespace internal { +namespace CGAL +{ + namespace internal + { /** @file Combinatorial_map_functors.h * Definition of functors used for dD Combinatorial map. */ + // ************************************************************************** + // Functor which call Functor::operator() on the two given cell_attributes + template + struct Apply_cell_functor + { + static void run(Cell_attribute& acell1, Cell_attribute& acell2) + { + Functor() (acell1,acell2); + } + }; + //...except for Null_functor. + template + struct Apply_cell_functor + { + static void run(Cell_attribute&, Cell_attribute&) + {} + }; + + // Functor used to call the On_split functor between the two given darts. + template::type> + struct Call_split_functor + { + static void run(typename Map::Dart_handle adart1, + typename Map::Dart_handle adart2) + { + Apply_cell_functor + ::type, + typename Map::Helper::template Attribute_type::type::On_split>:: + run(*(adart1->template attribute()), + *(adart2->template attribute())); + } + static void + run(typename Map::Helper::template Attribute_handle::type a1, + typename Map::Helper::template Attribute_handle::type a2) + { + Apply_cell_functor + ::type, + typename Map::Helper::template Attribute_type::type::On_split>:: + run(*a1, *a2); + } + }; + + // Specialization for disabled attributes. + template + struct Call_split_functor + { + static void run(typename Map::Dart_handle, + typename Map::Dart_handle) + {} + }; + + // Functor used to call the On_merge functor between the two given darts. + template::type> + struct Call_merge_functor + { + static void run(typename Map::Dart_handle adart1, + typename Map::Dart_handle adart2) + { + Apply_cell_functor + ::type, + typename Map::Helper::template Attribute_type::type::On_merge>:: + run(*(adart1->template attribute()), + *(adart2->template attribute())); + } + static void + run(typename Map::Helper::template Attribute_handle::type a1, + typename Map::Helper::template Attribute_handle::type a2) + { + Apply_cell_functor + ::type, + typename Map::Helper::template Attribute_type::type::On_merge>:: + run(*a1, *a2); + } + }; + + // Specialization for disabled attributes. + template + struct Call_merge_functor + { + static void run(typename Map::Dart_handle, + typename Map::Dart_handle) + {} + }; + // ************************************************************************** /// Functor used for link_beta to update the i-attributes of /// adart2 on the attributes of this dart, except if i=j. /// Only attributes of dh1 or dh2 can be modified. template::type> + typename CMap::Helper::template Attribute_type::type> struct Group_attribute_functor_of_dart_run { /// Group the i-attribute of dh1 and dh2. - /// @return true if the two attributes are grouped, false otherwise. - static bool run(CMap* amap, + static void run(CMap* amap, typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh2) { @@ -69,29 +174,38 @@ namespace CGAL { "Group_attribute_functor_of_dart_run but " "i-attributes are disabled"); CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh1!=CMap::null_dart_handle ); - T a1=dh1->template attribute(); - T a2=dh2->template attribute(); + typename CMap::Helper::template Attribute_handle::type + a1=dh1->template attribute(); + typename CMap::Helper::template Attribute_handle::type + a2=dh2->template attribute(); // If the two attributes are equal, nothing to do. - if ( a1==a2 ) return false; + if ( a1==a2 ) return; if ( a1==NULL ) amap->template set_attribute_of_dart(dh1, a2); else amap->template set_attribute_of_dart(dh2, a1); - - return true; } }; template struct Group_attribute_functor_of_dart_run { - static bool run(CMap* amap, + static void run(CMap* amap, typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh2) { CGAL_static_assertion(j!=0 && j!=1); - bool res = false; - T a1=NULL, a2=NULL; + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh1!=CMap::null_dart_handle ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Group_attribute_functor_of_dart_run<0> but " + "0-attributes are disabled"); + typename CMap::Helper::template Attribute_handle<0>::type + a1=NULL, a2=NULL; // First extremity typename CMap::Dart_handle od = dh2->other_extremity(); @@ -103,7 +217,6 @@ namespace CGAL { if ( a1==NULL && a2!=NULL ) { amap->template set_attribute_of_dart<0>(dh1, a2); - res = true; } } @@ -117,60 +230,70 @@ namespace CGAL { if ( a1!=NULL ) { amap->template set_attribute_of_dart<0>(dh2, a1); - res = true; } } - return res; } }; template struct Group_attribute_functor_of_dart_run { - static bool run(CMap* amap, + static void run(CMap* amap, typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh2) { + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh1!=CMap::null_dart_handle ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Group_attribute_functor_of_dart_run<0> but " + "0-attributes are disabled"); typename CMap::Dart_handle od = dh2->other_extremity(); if ( od!=NULL ) { - T a1=dh1->template attribute<0>(); - T a2=od->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a1=dh1->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a2=od->template attribute<0>(); if ( a1==NULL && a2!=NULL ) { amap->template set_attribute_of_dart<0>(dh1, a2); - return true; } } - - return false; } }; template struct Group_attribute_functor_of_dart_run { - static bool run(CMap* amap, + static void run(CMap* amap, typename CMap::Dart_handle dh1, typename CMap::Dart_handle dh2) { + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh1!=CMap::null_dart_handle ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Group_attribute_functor_of_dart_run<0> but " + "0-attributes are disabled"); typename CMap::Dart_handle od = dh1->other_extremity(); if ( od!=NULL ) { - T a1=od->template attribute<0>(); - T a2=dh2->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a1=od->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a2=dh2->template attribute<0>(); if ( a1!=NULL ) { amap->template set_attribute_of_dart<0>(dh2, a1); - return true; } } - - return false; } }; template - struct Group_attribute_functor_of_dart_run + struct Group_attribute_functor_of_dart_run { static void run(CMap*, typename CMap::Dart_handle, @@ -196,16 +319,287 @@ namespace CGAL { struct Group_attribute_functor_of_dart { template - static bool run(CMap* amap, + static void run(CMap* amap, typename CMap::Dart_handle adart1, typename CMap::Dart_handle adart2) { - return Group_attribute_functor_of_dart_run:: - run(amap,adart1,adart2); + Group_attribute_functor_of_dart_run::run(amap,adart1,adart2); } }; // ************************************************************************** + // Functor used to group the two i-attributes of the two i-cells, except the + // attribute of j + template::type> + struct Group_attribute_functor_run + { + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) + { + CGAL_static_assertion( i<=CMap::dimension ); + CGAL_static_assertion( i!=j ); + CGAL_static_assertion_msg + ( CMap::Helper::template Dimension_index::value>=0, + "Group_attribute_functor_run but i-attributes are disabled" ); + CGAL_assertion( adart1!=NULL && adart2!=NULL ); + CGAL_assertion( adart1!=CMap::null_dart_handle && + adart2!=CMap::null_dart_handle ); + + typename CMap::Helper::template Attribute_handle::type + a1=adart1->template attribute(); + typename CMap::Helper::template Attribute_handle::type + a2=adart2->template attribute(); + + // If the two attributes are equal, nothing to do. + if ( a1 == a2 ) return; + + typename CMap::Dart_handle toSet = NULL; + + // If the attribute associated to adart1 is NULL, set it with + // the attribute associated to adart2 (necessarily != NULL) + if (a1 == NULL) + { toSet = adart1; a1 = a2; } + else + { + toSet = adart2; + if (a2 != NULL) + { + Call_merge_functor::run(a1, a2); + } + } + amap->template set_attribute(toSet, a1); + } + }; + template + struct Group_attribute_functor_run + { + static void run( CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2 ) + { + CGAL_static_assertion_msg + ( CMap::Helper::template Dimension_index<0>::value>=0, + "Group_attribute_functor_run<0> but 0-attributes are disabled" ); + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh2!=CMap::null_dart_handle ); + CGAL_static_assertion(j!=0 && j!=1); + + typename CMap::Helper::template Attribute_handle<0>::type + a1=NULL, a2=NULL; + typename CMap::Dart_handle toSet=NULL; + // First extremity + typename CMap::Dart_handle od=dh2->other_extremity(); + if ( od!=NULL ) + { + a1=dh1->template attribute<0>(); + a2=od->template attribute<0>(); + if ( a1!=a2 ) + { + if ( a1==NULL ) + { toSet=dh1; a1=a2; } + else + { + toSet=od; + if ( a2!=NULL ) + { // TODO REMOVE ? + Call_merge_functor::run(a1, a2); + } + } + // TODO set_attribute templated by a range + amap->template set_attribute<0>(toSet, a1); + } + } + // Second extremity + od = dh1->other_extremity(); + if ( od!=NULL ) + { + a1=od->template attribute<0>(); + a2=dh2->template attribute<0>(); + if ( a1!=a2 ) + { + if ( a1==NULL ) + { toSet=od; a1=a2; } + else + { + toSet=dh2; + if ( a2!=NULL ) + { // TODO REMOVE ? + Call_merge_functor::run(a1, a2); + } + } + // TODO set_attribute templated by a range + amap->template set_attribute<0>(toSet, a1); + } + } + } + }; + template + struct Group_attribute_functor_run + { + static void run( CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2 ) + { + CGAL_static_assertion_msg + ( CMap::Helper::template Dimension_index<0>::value>=0, + "Group_attribute_functor_run<0> but 0-attributes are disabled" ); + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh2!=CMap::null_dart_handle ); + + typename CMap::Dart_handle od=dh2->other_extremity(); + if ( od!=NULL ) + { + typename CMap::Dart_handle toSet=NULL; + typename CMap::Helper::template Attribute_handle<0>::type + a1=dh1->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a2=od->template attribute<0>(); + if ( a1!=a2 ) + { + if ( a1==NULL ) + { toSet=dh1; a1=a2; } + else + { + toSet=od; + if ( a2!=NULL ) + { // TODO REMOVE ? + Call_merge_functor::run(a1, a2); + } + } + // TODO set_attribute templated by a range + amap->template set_attribute<0>(toSet, a1); + } + } + } + }; + template + struct Group_attribute_functor_run + { + static void run( CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2 ) + { + CGAL_static_assertion_msg + ( CMap::Helper::template Dimension_index<0>::value>=0, + "Group_attribute_functor_run<0> but 0-attributes are disabled" ); + CGAL_assertion( dh1!=NULL && dh2!=NULL ); + CGAL_assertion( dh1!=CMap::null_dart_handle && + dh2!=CMap::null_dart_handle ); + + typename CMap::Dart_handle od = dh1->other_extremity(); + if ( od!=NULL ) + { + typename CMap::Dart_handle toSet=NULL; + typename CMap::Helper::template Attribute_handle<0>::type + a1=od->template attribute<0>(); + typename CMap::Helper::template Attribute_handle<0>::type + a2=dh2->template attribute<0>(); + if ( a1!=a2 ) + { + if ( a1==NULL ) + { toSet=od; a1=a2; } + else + { + toSet=dh2; + if ( a2!=NULL ) + { // TODO REMOVE ? + Call_merge_functor::run(a1, a2); + } + } + // TODO set_attribute templated by a range + amap->template set_attribute<0>(toSet, a1); + } + } + } + }; + template + struct Group_attribute_functor_run + { + static void run( CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle ) + {} + }; + + /// Functor used for sew to update the attributes of + /// adart2 on the attributes of this dart, except for j-attributes. + /// We define run to allows to use this functor with + /// Foreach_enabled_attributes. + /// If you know i at compiling time, use directly + /// Group_attribute_functor_run. + template + struct Group_attribute_functor + { + template + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) + { + Group_attribute_functor_run::run(amap,adart1,adart2); + } + }; + + // Functor used to degroup the two n-attributes of the two darts, except the + // attribute of adim + template + struct Degroup_attribute_functor_run + { + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2, int adim) + { + CGAL_assertion( adim==-1 || + (1<=adim && (unsigned int)adim<=CMap::dimension) ); + if (i!=adim ) + { + amap->template degroup_enabled_attribute + ::type> + (adart1, adart2); + } + } + }; + template + struct Degroup_attribute_functor_run + { + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2, int adim) + { + CGAL_assertion( adim==-1 || + (1<=adim && (unsigned int)adim<=CMap::dimension) ); + typename CMap::Dart_handle od = adart1->other_extremity(); + if ( od!=NULL ) + amap->template degroup_enabled_attribute + <0, typename CMap::Helper::template Attribute_type<0>::type > + (od, adart2); + + if ( adim!=1 ) + { + od = adart2->other_extremity(); + if ( od!=NULL ) + { + amap->template degroup_enabled_attribute + <0, typename CMap::Helper::template Attribute_type<0>::type> + (adart1, od); + } + } + } + }; + template + struct Degroup_attribute_functor + { + template + static void run(Map* amap,typename Map::Dart_handle adart1, + typename Map::Dart_handle adart2, int adim) + { + Degroup_attribute_functor_run::run(amap,adart1,adart2,adim); + } + }; //////////////////////////////////// @@ -219,30 +613,6 @@ namespace CGAL { int dim; }; - - // Functor used to group one attribute of two given darts - template - struct Group_one_attribute_functor - { - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2) - { - CGAL_assertion(amap!=NULL); - amap->template group_enabled_attribute(adart1,adart2); - } - }; - - // Specialization for i-attributes disabled. - template - struct Group_one_attribute_functor - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // Functor used to degroup one attribute of two given darts template struct Degroup_one_attribute_functor @@ -375,167 +745,6 @@ namespace CGAL { } }; - // Functor used to group the two n-attributes of the two darts, except the - // attribute of adim (adim==-1 || 1<=adim<=dimension) - template - struct Group_attribute_functor_run - { - static void run(Map* amap, - typename Map::Dart_handle adart1, - typename Map::Dart_handle adart2, int adim) - { - if ( i!=adim ) - { - amap->template group_enabled_attribute - ::type> - (adart1, adart2); - } - } - }; - - template - struct Group_attribute_functor_run - { - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2, int adim) - { - typename CMap::Dart_handle od = adart1->other_extremity(); - if ( od!=NULL ) - { - amap->template group_enabled_attribute - <0, typename CMap::Helper::template Attribute_type<0>::type> - (od, adart2); - } - - if ( adim!=1 ) - { - od = adart2->other_extremity(); - if ( od!=NULL ) - amap->template group_enabled_attribute - <0, typename CMap::Helper::template Attribute_type<0>::type> - (adart1, od); - } - } - }; - - template - struct Group_attribute_functor - { - template - static void run(Map* amap, - typename Map::Dart_handle adart1, - typename Map::Dart_handle adart2, int adim) - { - CGAL_assertion( adim==-1 || - (1<=adim && (unsigned int)adim<=Map::dimension) ); - Group_attribute_functor_run::run(amap,adart1,adart2,adim); - } - }; - - // Functor used to degroup the two n-attributes of the two darts, except the - // attribute of adim - template - struct Degroup_attribute_functor_run - { - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2, int adim) - { - CGAL_assertion( adim==-1 || - (1<=adim && (unsigned int)adim<=CMap::dimension) ); - if (i!=adim ) - { - amap->template degroup_enabled_attribute - ::type> - (adart1, adart2); - } - } - }; - template - struct Degroup_attribute_functor_run - { - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2, int adim) - { - CGAL_assertion( adim==-1 || - (1<=adim && (unsigned int)adim<=CMap::dimension) ); - typename CMap::Dart_handle od = adart1->other_extremity(); - if ( od!=NULL ) - amap->template degroup_enabled_attribute - <0, typename CMap::Helper::template Attribute_type<0>::type > - (od, adart2); - - if ( adim!=1 ) - { - od = adart2->other_extremity(); - if ( od!=NULL ) - { - amap->template degroup_enabled_attribute - <0, typename CMap::Helper::template Attribute_type<0>::type> - (adart1, od); - } - } - } - }; - template - struct Degroup_attribute_functor - { - template - static void run(Map* amap,typename Map::Dart_handle adart1, - typename Map::Dart_handle adart2, int adim) - { - Degroup_attribute_functor_run::run(amap,adart1,adart2,adim); - } - }; - - // Functor which call operator() on the cell_attribute... - template - struct Apply_cell_functor - { - static void run(Cell_attribute& acell1, Cell_attribute& acell2) - { - Functor() (acell1,acell2); - } - }; - //...except for Null_functor. - template - struct Apply_cell_functor - { - static void run(Cell_attribute&, Cell_attribute&) - {} - }; - - // Functor used to call the On_split functor between the two given darts. - template::type> - struct Call_split_functor - { - static void run(typename Map::Dart_handle adart1, - typename Map::Dart_handle adart2) - { - Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type::On_split>:: - run(*(adart1->template attribute()), - *(adart2->template attribute())); - } - }; - - // Specialization for disabled attributes. - template - struct Call_split_functor - { - static void run(typename Map::Dart_handle, - typename Map::Dart_handle) - {} - }; /// Functor for counting the memory occupation of attributes /// Be careful not reentrant !!! TODO a Foreach_enabled_attributes