diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index 0112fd9991e..91aae074a4a 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -200,14 +200,13 @@ 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); + 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 ? + // 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); res && it.cont(); ++it) @@ -787,13 +786,13 @@ namespace CGAL { if ( i==0 ) return false; if ( i==1 ) return true; - // TODO ? Optimisation possible to not test all - // the darts of the cell ? + // 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); res && it.cont(); ++it) { - if ( it->beta(i-2)->beta(i-1)!=it->beta(i-1)->beta_inv(i-2) ) + if ( it->template beta()->template beta()!= + it->template beta()->template beta_inv() ) res = false; } return res; diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index cd052f0518b..8dd15816214 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -30,6 +30,12 @@ * attributes are stored in tuple, thus all the access must be done at * compiling time. * + * Call_split_functor to call the OnSplit functors on two given + * i-attributes. + * + * Call_merge_functor to call the OnMerge functors on two given + * i-attributes. + * * Group_attribute_functor_of_dart to group the -attributes of two * given darts (except for j-dim). Only the attributes of the two given * darts are possibly modified. @@ -43,11 +49,6 @@ * 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 @@ -77,82 +78,178 @@ namespace CGAL {} }; + // ************************************************************************** // 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) + static void run(typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) { Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type::On_split>:: + ::type, + typename CMap::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) + run(typename CMap::Helper::template Attribute_handle::type a1, + typename CMap::Helper::template Attribute_handle::type a2) { Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type::On_split>:: + ::type, + typename CMap::Helper:: + template Attribute_type::type::On_split>:: run(*a1, *a2); } }; // Specialization for disabled attributes. - template - struct Call_split_functor + template + struct Call_split_functor { - static void run(typename Map::Dart_handle, - typename Map::Dart_handle) + static void run(typename CMap::Dart_handle, + typename CMap::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) + static void run(typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) { Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type::On_merge>:: + ::type, + typename CMap::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) + run(typename CMap::Helper::template Attribute_handle::type a1, + typename CMap::Helper::template Attribute_handle::type a2) { Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type::On_merge>:: + ::type, + typename CMap::Helper::template Attribute_type::type::On_merge>:: run(*a1, *a2); } }; // Specialization for disabled attributes. - template - struct Call_merge_functor + template + struct Call_merge_functor { - static void run(typename Map::Dart_handle, - typename Map::Dart_handle) + static void run(typename CMap::Dart_handle, + typename CMap::Dart_handle) {} }; + // ************************************************************************** + /// Functor used to reserve one mark for each enabled attribute. + template + struct Reserve_mark_functor + { + template + static void run(const CMap* amap, std::vector* marks) + { (*marks)[i] = amap->get_new_mark(); } + }; + + // ************************************************************************** + /// Functor used to test if a cell is valid + template + struct Test_is_valid_attribute_functor + { + template + static void run(const CMap* amap, + typename CMap::Dart_const_handle adart, + std::vector* marks, bool *ares) + { + if (!amap->template is_valid_attribute(adart,(*marks)[i]) ) + { + (*ares)=false; + std::cerr << "CMap not valid: a "< + struct Count_cell_functor + { + template + static void run( const CMap* amap, + typename CMap::Dart_const_handle adart, + std::vector* amarks, + std::vector* ares ) + { + if ( (*amarks)[i]!=-1 && !amap->is_marked(adart, (*amarks)[i]) ) + { + ++ (*ares)[i]; + mark_cell(*amap, adart, (*amarks)[i]); + } + } + }; + + // ************************************************************************** + /// Functor for counting the memory occupation of attributes + /// Be careful not reentrant !!! TODO a Foreach_enabled_attributes + /// taking an instance of a functor as argument allowing to compute + /// and return values. + template + struct Count_bytes_one_attribute_functor + { + template + static void run( const CMap* amap ) + { + res += amap->template attributes().capacity()* + sizeof(typename CMap::template Attribute_type::type); + } + + static typename CMap::size_type res; + }; + template + typename CMap::size_type Count_bytes_one_attribute_functor::res = 0; + + template + struct Count_bytes_all_attributes_functor + { + static typename CMap::size_type run( const CMap& amap ) + { + Count_bytes_one_attribute_functor::res = 0; + CMap::Helper::template Foreach_enabled_attributes + >::run(&amap); + return Count_bytes_one_attribute_functor::res; + } + }; + + // ************************************************************************** + /// Functor used to call decrease_attribute_ref_counting + /// on each i-cell attribute enabled + template + struct Decrease_attribute_functor + { + template + static void run(CMap* amap, typename CMap::Dart_handle adart) + { amap->template + decrease_attribute_ref_counting(adart/*,Tag_true()*/); } + }; + // ************************************************************************** /// Functor used for link_beta to update the i-attributes of /// adart2 on the attributes of this dart, except if i=j. @@ -544,6 +641,7 @@ namespace CGAL } }; + // ************************************************************************** // Functor used to degroup the two n-attributes of the two darts, except the // attribute of adim template @@ -590,14 +688,14 @@ namespace CGAL } } }; - template + template struct Degroup_attribute_functor { template - static void run(Map* amap,typename Map::Dart_handle adart1, - typename Map::Dart_handle adart2, int adim) + static void run(CMap* amap,typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2, int adim) { - Degroup_attribute_functor_run::run(amap,adart1,adart2,adim); + Degroup_attribute_functor_run::run(amap,adart1,adart2,adim); } }; @@ -637,146 +735,34 @@ namespace CGAL { return false; } }; -/* // Functor used to degroup one attribute of one dart - template - struct Degroup_one_attribute_of_dart_functor - { - static bool run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2) - { - CGAL_assertion(amap!=NULL); - return amap->template degroup_enabled_attribute_of_dart - (adart1,adart2); - } - }; - - // Specialization for i-attributes disabled. - template - struct Degroup_one_attribute_of_dart_functor - { - static bool run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - { return false; } - };*/ - - /// Functor used to call decrease_attribute_ref_counting - /// on each i-cell attribute enabled - template - struct Decrease_attribute_functor - { - template - static void run(Map* amap, typename Map::Dart_handle adart) - { amap->template - decrease_attribute_ref_counting(adart/*,Tag_true()*/); } - }; - /// Functor used to call update_dart_of_attribute /// on each i-cell attribute enabled - template + template struct Update_dart_of_attribute_functor { template - static void run(Map* amap, typename Map::Dart_handle ah, int amark) + static void run(CMap* amap, typename CMap::Dart_handle ah, int amark) { amap->template update_dart_of_attribute(ah,amark); } }; - template::type> struct Update_dart_of_one_attribute_functor { - static void run(Map* amap, typename Map::Dart_handle ah, int amark) + static void run(CMap* amap, typename CMap::Dart_handle ah, int amark) { amap->template update_dart_of_attribute(ah,amark); } }; - template - struct Update_dart_of_one_attribute_functor + template + struct Update_dart_of_one_attribute_functor { - static void run(Map*, typename Map::Dart_handle, int) + static void run(CMap*, typename CMap::Dart_handle, int) {} }; - /// Functor used to reserve one mark for each enabled attribute. - template - struct Reserve_mark_functor - { - template - static void run(const Map* amap, std::vector* marks) - { (*marks)[i] = amap->get_new_mark(); } - }; - - /// Functor used to test if a cell is valid - template - struct Test_is_valid_attribute_functor - { - template - static void run(const Map* amap, - typename Map::Dart_const_handle adart, - std::vector* marks, bool *ares) - { - if (!amap->template is_valid_attribute(adart,(*marks)[i]) ) - { - (*ares)=false; - std::cerr << "Map not valid: a "< - struct Count_cell_functor - { - template - static void run( const Map* amap, - typename Map::Dart_const_handle adart, - std::vector* amarks, - std::vector* ares ) - { - if ( (*amarks)[i]!=-1 && !amap->is_marked(adart, (*amarks)[i]) ) - { - ++ (*ares)[i]; - mark_cell(*amap, adart, (*amarks)[i]); - } - } - }; - - - /// Functor for counting the memory occupation of attributes - /// Be careful not reentrant !!! TODO a Foreach_enabled_attributes - /// taking an instance of a functor as argument allowing to compute - /// and return values. - template - struct Count_bytes_one_attribute_functor - { - template - static void run( const Map* amap ) - { - res += amap->template attributes().capacity()* - sizeof(typename Map::template Attribute_type::type); - } - - static typename Map::size_type res; - }; - template - typename Map::size_type Count_bytes_one_attribute_functor::res = 0; - - template - struct Count_bytes_all_attributes_functor - { - static typename Map::size_type run( const Map& amap ) - { - Count_bytes_one_attribute_functor::res = 0; - Map::Helper::template Foreach_enabled_attributes - >::run(&amap); - return Count_bytes_one_attribute_functor::res; - } - }; - #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template struct Beta_functor; @@ -821,23 +807,23 @@ namespace CGAL }; #endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template + template struct Store_incident_cells { template - static void run( Map* amap, typename Map::Dart_handle adart, + static void run( CMap* amap, typename CMap::Dart_handle adart, int mark_for_icell, int* mark_for_incident_cells, - std::deque > + std::deque > *store ) { if ( i==j ) return; const int mark_for_jcells = mark_for_incident_cells - [Map::Helper::template Dimension_index::value]; + [CMap::Helper::template Dimension_index::value]; - std::deque >& jcells = - store[Map::Helper::template Dimension_index::value]; + std::deque >& jcells = + store[CMap::Helper::template Dimension_index::value]; CGAL_assertion( amap!=NULL ); CGAL_assertion( adart!=NULL ); @@ -847,8 +833,8 @@ namespace CGAL if ( !amap->is_marked(adart, mark_for_jcells) && adart->template attribute()!=NULL ) { - jcells.push_back(std::deque()); - for ( CMap_dart_iterator_basic_of_cell + jcells.push_back(std::deque()); + for ( CMap_dart_iterator_basic_of_cell itj(*amap, adart, mark_for_jcells); itj.cont(); ++itj ) { if ( !amap->is_marked(itj, mark_for_icell) ) @@ -862,13 +848,13 @@ namespace CGAL if ( i!=1 && j==0 ) { - typename Map::Dart_handle od = adart->other_extremity(); + typename CMap::Dart_handle od = adart->other_extremity(); if ( od!=NULL && !amap->is_marked(od, mark_for_jcells) && od->template attribute()!=NULL ) { - jcells.push_back(std::deque()); - for ( CMap_dart_iterator_basic_of_cell + jcells.push_back(std::deque()); + for ( CMap_dart_iterator_basic_of_cell itj(*amap, od, mark_for_jcells); itj.cont(); ++itj ) { if ( !amap->is_marked(itj, mark_for_icell) ) @@ -883,39 +869,39 @@ namespace CGAL } }; - template + template struct Test_split_with_deque { template - static void run( Map* amap, + static void run( CMap* amap, int* mark_for_incident_cells, - std::deque > + std::deque > *store ) { const int mark_for_jcells = mark_for_incident_cells - [Map::Helper::template Dimension_index::value]; + [CMap::Helper::template Dimension_index::value]; amap->negate_mark( mark_for_jcells ); if ( i==j ) return; - std::deque >& jcells = - store[Map::Helper::template Dimension_index::value]; + std::deque >& jcells = + store[CMap::Helper::template Dimension_index::value]; CGAL_assertion( amap!=NULL ); CGAL_assertion( amap->is_reserved(mark_for_jcells) ); int nbofjcell = 0; - typename Map::Helper::template Attribute_handle::type + typename CMap::Helper::template Attribute_handle::type a1 = NULL; - typename Map::Helper::template Attribute_handle::type + typename CMap::Helper::template Attribute_handle::type a2=NULL; int nb=0; - for ( typename std::deque >:: + for ( typename std::deque >:: iterator it=jcells.begin(); it!=jcells.end(); ++it ) { nbofjcell = 0; - for ( typename std::deque::iterator + for ( typename std::deque::iterator itj=it->begin(); itj!=it->end(); ++itj ) { if ( !amap->is_marked(*itj, mark_for_jcells) ) @@ -934,7 +920,7 @@ namespace CGAL // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; } - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj2(*amap, *itj, mark_for_jcells); itj2.cont(); ++itj2 ) { @@ -948,8 +934,8 @@ namespace CGAL if ( nbofjcell>1 ) Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type:: + ::type, + typename CMap::Helper::template Attribute_type::type:: On_split>::run(*a1, *a2); } } @@ -960,28 +946,28 @@ namespace CGAL } }; - template + template struct Test2_split_with_deque { template - static void test_one_dart( Map* amap, - typename Map::Dart_handle adart, - std::set::type>& found_attributes, int mark) { if ( adart->template attribute()!=NULL && !amap->is_marked(adart, mark) ) { - typename Map::Helper::template Attribute_handle::type + typename CMap::Helper::template Attribute_handle::type a1 = adart->template attribute(); if ( !found_attributes.insert(a1).second ) { // Here the attribute was already present in the set - typename Map::Helper::template Attribute_handle::type + typename CMap::Helper::template Attribute_handle::type a2 = amap->template create_attribute(*a1); // std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, adart, mark); itj.cont(); ++itj ) { @@ -991,8 +977,8 @@ namespace CGAL } Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type:: + ::type, + typename CMap::Helper::template Attribute_type::type:: On_split>::run(*a1, *a2); } else @@ -1002,7 +988,7 @@ namespace CGAL a1->set_dart(adart); // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, adart, mark); itj.cont(); ++itj ) { @@ -1016,24 +1002,24 @@ namespace CGAL } template - static void run( Map* amap, - std::deque + static void run( CMap* amap, + std::deque *modified_darts, int mark_modified_darts /*, - std::deque + std::deque *modified_darts2*/) { if ( i==j ) return; CGAL_assertion( amap!=NULL ); - std::set::type> found_attributes; int mark = amap->get_new_mark(); int nb=0; - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) { @@ -1041,7 +1027,7 @@ namespace CGAL if ( i!=1 && j==0 ) { - typename Map::Dart_handle od = (*it)->other_extremity(); + typename CMap::Dart_handle od = (*it)->other_extremity(); if ( od!=NULL ) test_one_dart(amap, od, found_attributes, mark); } @@ -1049,7 +1035,7 @@ namespace CGAL /* if ( i+1==j ) { - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts2->begin(); it!=modified_darts2->end(); ++it ) { @@ -1057,7 +1043,7 @@ namespace CGAL if ( i!=1 && j==0 ) { - typename Map::Dart_handle od = (*it)->other_extremity(); + typename CMap::Dart_handle od = (*it)->other_extremity(); if ( od!=NULL ) test_one_dart(amap, od, found_attributes, mark); } @@ -1071,7 +1057,7 @@ namespace CGAL // Now we unmark all the marked darts. amap->negate_mark(mark); - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) { @@ -1079,7 +1065,7 @@ namespace CGAL amap->unmark(*it, mark_modified_darts); if ( !amap->is_marked(*it, mark) ) - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, *it, mark); itj.cont(); ++itj ) { @@ -1088,9 +1074,9 @@ namespace CGAL if ( i!=1 && j==0 ) { - typename Map::Dart_handle od = (*it)->other_extremity(); + typename CMap::Dart_handle od = (*it)->other_extremity(); if ( od!=NULL && !amap->is_marked(od, mark) ) - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, od, mark); itj.cont(); ++itj ) { @@ -1101,7 +1087,7 @@ namespace CGAL /* if ( i+1==j ) { - for ( typename std::deque:: + for ( typename std::deque:: iterator it=modified_darts2->begin(); it!=modified_darts2->end(); ++it ) { @@ -1109,7 +1095,7 @@ namespace CGAL amap->unmark(*it, mark_modified_darts); if ( !amap->is_marked(*it, mark) ) - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, *it, mark); itj.cont(); ++itj ) { @@ -1118,9 +1104,9 @@ namespace CGAL if ( i!=1 && j==0 ) { - typename Map::Dart_handle od = (*it)->other_extremity(); + typename CMap::Dart_handle od = (*it)->other_extremity(); if ( od!=NULL && !amap->is_marked(od, mark) ) - for ( CMap_dart_iterator_basic_of_cell + for ( CMap_dart_iterator_basic_of_cell itj(*amap, od, mark); itj.cont(); ++itj ) {