diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 647f5c6258e..8a325e39e41 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -114,6 +114,11 @@ namespace CGAL { /// Set the dart associated with the cell. void set_dart(Dart_handle) {} + /// Test if the cell is valid. + /// For cell without dart, return always true. + bool is_valid() const + { return true; } + protected: /// Contructor without parameter. Cell_attribute_without_info(): mrefcounting(0) @@ -124,11 +129,6 @@ namespace CGAL { mrefcounting(0) {} - /// Test if the cell is valid. - /// For cell without dart, return always true. - bool is_valid() const - { return true; } - /// Increment the reference counting. void inc_nb_refs() { ++mrefcounting; } @@ -216,6 +216,11 @@ namespace CGAL { /// Set the dart associated with the cell. void set_dart(Dart_handle adart) { mdart = adart; } + /// Test if the cell is valid. + /// A cell is valid if its dart is not NULL. + bool is_valid() const + { return mdart!=NULL; } + protected: /// Contructor without parameter. Cell_attribute_without_info() : mdart(NULL), @@ -228,11 +233,6 @@ namespace CGAL { mrefcounting(0) {} - /// Test if the cell is valid. - /// A cell is valid if its dart is not NULL. - bool is_valid() const - { return mdart!=NULL; } - /// Increment the reference counting. void inc_nb_refs() { ++mrefcounting; } @@ -244,12 +244,12 @@ namespace CGAL { --mrefcounting; } + public: /// Get the reference counting. unsigned int get_nb_refs() const { return mrefcounting; } - public: - void * for_compact_container() const + void * for_compact_container() const { return mdart.for_compact_container(); } void * & for_compact_container() { return mdart.for_compact_container(); } diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 44dcfbfb81a..64f6f9b5037 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -22,13 +22,14 @@ #include #include +#include +#include #include #include #include #include #include #include -#include #include #include #include @@ -56,66 +57,6 @@ namespace CGAL { class Alloc_=CGAL_ALLOCATOR(int) > class Combinatorial_map_base { - /* - template - friend struct Remove_cell_functor; - - template - friend struct Contract_cell_functor; - - template - friend typename Map::Dart_handle - insert_cell_0_in_cell_1(Map& amap, typename Map::Dart_handle adart); - - template - friend typename CMap::Dart_handle - insert_cell_1_in_cell_2(CMap& amap, typename CMap::Dart_handle adart1); - - template - friend - typename CMap::Dart_handle - insert_cell_1_in_cell_2(CMap& amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2); - - template - friend - typename Map::Dart_handle - insert_cell_2_in_cell_3(Map& amap, InputIterator afirst, - InputIterator alast); - - template < class Map > - friend - 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::Group_attribute_functor_of_dart_run; - - template - friend struct internal::Group_attribute_functor_run; - - 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; - - template - friend struct internal::Decrease_attribute_functor; - - template - friend struct internal::Update_dart_of_one_attribute_functor; -*/ public: /// Types definition typedef Combinatorial_map_base Self; @@ -245,32 +186,35 @@ namespace CGAL { Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3) { return mdarts.emplace(mmask_marks, t1, t2, t3); } template < typename T1, typename T2, typename T3, typename T4 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4); } template < typename T1, typename T2, typename T3, typename T4, typename T5 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, - const T5 &t5) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4, const T5 &t5) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4, t5); } template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, - const T5 &t5, const T6 &t6) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4, const T5 &t5, const T6 &t6) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4, t5, t6); } template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, - const T5 &t5, const T6 &t6, const T7 &t7) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4, const T5 &t5, const T6 &t6, + const T7 &t7) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4, t5, t6, t7); } template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, - const T5 &t5, const T6 &t6, const T7 &t7, const T8 &t8) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4, const T5 &t5, const T6 &t6, + const T7 &t7, const T8 &t8) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4, t5, t6, t7, t8); } template < typename T1, typename T2, typename T3, typename T4, typename T5, typename T6, typename T7, typename T8, typename T9 > - Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, const T4 &t4, - const T5 &t5, const T6 &t6, const T7 &t7, const T8 &t8, - const T9 &t9) + Dart_handle create_dart(const T1 &t1, const T2 &t2, const T3 &t3, + const T4 &t4, const T5 &t5, const T6 &t6, + const T7 &t7, const T8 &t8, const T9 &t9) { return mdarts.emplace(mmask_marks, t1, t2, t3, t4, t5, t6, t7, t8, t9); } #endif @@ -321,50 +265,52 @@ namespace CGAL { /// @return the betas of ADart (beta are used in the same order than /// they are given as parameters) #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template + template Dart_handle beta(Dart_handle ADart, Betas... betas) const - { return internal::Beta_functor:: + { return CGAL::internal::Beta_functor:: run(ADart, betas...); } - template + template Dart_const_handle beta(Dart_const_handle ADart, Betas... betas) const - { return internal::Beta_functor:: + { return CGAL::internal::Beta_functor:: run(ADart, betas...); } - template + template Dart_handle beta(Dart_handle ADart) const - { return internal::Beta_functor_static:: + { return CGAL::internal::Beta_functor_static:: run(ADart); } - template + template Dart_const_handle beta(Dart_const_handle ADart) const - { return internal::Beta_functor_static:: + { return CGAL::internal::Beta_functor_static:: run(ADart); } #else Dart_handle beta(Dart_handle ADart, int B1) - { return internal::Beta_functor::run(ADart, B1); } + { return CGAL::internal::Beta_functor::run(ADart, B1); } Dart_handle beta(Dart_handle ADart, int B1, int B2) - { return internal::Beta_functor::run(ADart, B1, B2); } + { return CGAL::internal::Beta_functor::run(ADart, B1, B2); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3) - { return internal::Beta_functor::run(ADart, B1, B2, B3); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4, int B5) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4, - B5); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4, B5); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4, int B5, int B6) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4, B5, - B6); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4, B5, B6); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4, int B5, int B6, int B7) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4, B5, - B6, B7); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4, B5, B6, B7); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4, int B5, int B6, int B7, int B8) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4, B5, - B6, B7, B8); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4, B5, B6, B7, B8); } Dart_handle beta(Dart_handle ADart, int B1, int B2, int B3, int B4, int B5, int B6, int B7, int B8, int B9) - { return internal::Beta_functor::run(ADart, B1, B2, B3, B4, B5, - B6, B7, B8, B9); } + { return CGAL::internal::Beta_functor:: + run(ADart, B1, B2, B3, B4, B5, B6, B7, B8, B9); } #endif /** Count the number of used marks. @@ -567,20 +513,18 @@ namespace CGAL { { CGAL_assertion( is_reserved(amark) ); - if (is_whole_map_unmarked(amark)) return; - - if (is_whole_map_marked(amark)) + if ( is_whole_map_marked(amark) ) { negate_mark(amark); } - else + else if ( !is_whole_map_unmarked(amark) ) { - unmark_null_dart(amark); for ( typename Dart_range::const_iterator it(darts().begin()), itend(darts().end()); it!=itend; ++it) unmark(it, amark); } CGAL_assertion(is_whole_map_unmarked(amark)); + unmark_null_dart(amark); } /** Free a given mark, previously calling unmark_all_darts. @@ -642,6 +586,7 @@ namespace CGAL { * @param i the dimension to close * @return the number of new darts. * @pre 2<=i<=n (TODO case i==1) + * @TODO move into Combinatorial_map_operations ? */ unsigned int close(unsigned int i) { @@ -662,8 +607,8 @@ namespace CGAL { basic_link_beta_for_involution(it, d, i); // we copy all the non void attribute Helper::template Foreach_enabled_attributes_except - , - dimension+1>:: run(this,it,d); + , dimension+1>:: run(this,it,d); // we need to remove i-attrib, how to do that ? // Special cases for 0 and 1 @@ -907,7 +852,7 @@ namespace CGAL { /// Create a new attribute. /// @return a handle on the new attribute. #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template + template typename Attribute_handle::type create_attribute(const Args&... args) { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, @@ -1351,7 +1296,7 @@ namespace CGAL { if ( adart1==adart2 ) { - for ( CMap_dart_iterator_of_involution it(*this, adart1); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart1); it.cont(); ++it ) { basic_link_beta_1(it, it); @@ -1361,15 +1306,15 @@ namespace CGAL { { int m = get_new_mark(); std::deque dartv; - for ( CMap_dart_iterator_basic_of_cell it(*this,adart1,m); - it.cont(); ++it) + for ( CGAL::CMap_dart_iterator_basic_of_cell + it(*this, adart1, m); it.cont(); ++it ) { mark(it,m); dartv.push_back(it); } - CMap_dart_iterator_of_involution I1(*this, adart1); - CMap_dart_iterator_of_involution_inv I2(*this, adart2); + CGAL::CMap_dart_iterator_of_involution I1(*this, adart1); + CGAL::CMap_dart_iterator_of_involution_inv I2(*this, adart2); for ( ; I1.cont(); ++I1, ++I2 ) { if ( is_marked(I1,m) ) basic_link_beta_1(I1, I2); @@ -1408,8 +1353,8 @@ namespace CGAL { CGAL_assertion( 2<=i && i<=Self::dimension ); CGAL_assertion( (is_sewable(adart1,adart2)) ); - CMap_dart_iterator_of_involution I1(*this, adart1); - CMap_dart_iterator_of_involution_inv I2(*this, adart2); + CGAL::CMap_dart_iterator_of_involution I1(*this, adart1); + CGAL::CMap_dart_iterator_of_involution_inv I2(*this, adart2); for ( ; I1.cont(); ++I1, ++I2 ) { basic_link_beta_for_involution(I1, I2); @@ -1445,7 +1390,7 @@ namespace CGAL { if ( adart1==adart2 ) { - for ( CMap_dart_iterator_of_involution it(*this, adart1); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart1); it.cont(); ++it ) { basic_link_beta_1(it, it); @@ -1455,8 +1400,8 @@ namespace CGAL { int m = get_new_mark(); std::deque dartv; - for ( CMap_dart_iterator_basic_of_cell it(*this,adart1,m); - it.cont(); ++it) + for ( CGAL::CMap_dart_iterator_basic_of_cell + it(*this, adart1, m); it.cont(); ++it ) { mark(it,m); dartv.push_back(it); @@ -1465,9 +1410,9 @@ namespace CGAL { int mark = get_new_mark(); CGAL_assertion( mark!=-1 ); - CMap_dart_iterator_basic_of_involution + CGAL::CMap_dart_iterator_basic_of_involution I1(*this, adart1, mark); - CMap_dart_iterator_basic_of_involution_inv + CGAL::CMap_dart_iterator_basic_of_involution_inv I2(*this, adart2, mark); // This first loop do not modify the map, but only the attributes @@ -1476,18 +1421,12 @@ namespace CGAL { { if ( is_marked(I1,m) ) Helper::template Foreach_enabled_attributes_except - , 1>:: + , 1>:: run(this, I1, I2); else Helper::template Foreach_enabled_attributes_except - , 1>:: + , 1>:: run(this, I1, I2); - - /* TODO check AVANT Dart_handle od1=I1->other_extremity(); - Dart_handle od2=I2->other_extremity(); - if (od1!=NULL && od2!=NULL) - run(this,adart1,adart2); - group_all_attributes_except(od1, od2, 1);*/ } // Now we update the beta links. @@ -1523,8 +1462,8 @@ namespace CGAL { if ( adart1==adart2 ) { - for ( CMap_dart_iterator_of_involution it(*this, adart1); - it.cont(); ++it ) + for ( CGAL::CMap_dart_iterator_of_involution + it(*this, adart1); it.cont(); ++it ) { basic_link_beta_1(it, it); } @@ -1533,8 +1472,8 @@ namespace CGAL { int m = get_new_mark(); std::deque dartv; - for ( CMap_dart_iterator_basic_of_cell it(*this,adart1,m); - it.cont(); ++it ) + for ( CGAL::CMap_dart_iterator_basic_of_cell + it(*this, adart1, m); it.cont(); ++it ) { mark(it,m); dartv.push_back(it); @@ -1543,9 +1482,9 @@ namespace CGAL { int mark = get_new_mark(); CGAL_assertion( mark!=-1 ); - CMap_dart_iterator_basic_of_involution + CGAL::CMap_dart_iterator_basic_of_involution I1(*this, adart1, mark); - CMap_dart_iterator_basic_of_involution_inv + CGAL::CMap_dart_iterator_basic_of_involution_inv I2(*this, adart2, mark); // This first loop do not modify the map, but only the attributes @@ -1561,7 +1500,6 @@ namespace CGAL { Helper::template Foreach_enabled_attributes_except , 1>:: run(this, I1, I2); - // TODO check avant group_all_attributes_except(I1,I2,1); } // Now we update the beta links. @@ -1573,7 +1511,7 @@ namespace CGAL { } for ( typename std::deque::iterator it=dartv.begin(); - it!=dartv.end(); ++it ) + it!=dartv.end(); ++it ) { unmark(*it,m); } CGAL_assertion( is_whole_map_unmarked(m) ); free_mark(m); @@ -1598,12 +1536,12 @@ namespace CGAL { CGAL_assertion( 2<=i && i<=dimension ); CGAL_assertion( (is_sewable(adart1,adart2)) ); - int mark = get_new_mark(); + int mark=get_new_mark(); CGAL_assertion( mark!=-1 ); - CMap_dart_iterator_basic_of_involution + CGAL::CMap_dart_iterator_basic_of_involution I1(*this, adart1, mark); - CMap_dart_iterator_basic_of_involution_inv + CGAL::CMap_dart_iterator_basic_of_involution_inv I2(*this, adart2, mark); // This first loop do not modify the map, but only the attributes @@ -1611,9 +1549,8 @@ namespace CGAL { for ( ; I1.cont(); ++I1, ++I2 ) { Helper::template Foreach_enabled_attributes_except - , i>:: + , i>:: run(this, I1, I2); - // TODO avant group_all_attributes_except(I1,I2,i); } // Now we update the beta links. @@ -1671,14 +1608,14 @@ namespace CGAL { int m = get_new_mark(); std::deque dartv; - for ( CMap_dart_iterator_basic_of_cell it(*this,adart,m); - it.cont(); ++it) + for ( CGAL::CMap_dart_iterator_basic_of_cell it(*this, adart, m); + it.cont(); ++it ) { mark(*it,m); dartv.push_back(*it); } - for ( CMap_dart_iterator_of_involution it(*this, adart); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart); it.cont(); ++it ) { if ( is_marked(*it,m) ) unlink_beta_1(*it); @@ -1717,7 +1654,7 @@ namespace CGAL { CGAL_assertion( adart!=NULL && !adart->template is_free() ); CGAL_assertion( 2<=i && i<=Self::dimension ); - for ( CMap_dart_iterator_of_involution it(*this, adart); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart); it.cont(); ++it ) { unlink_beta(*it); } } @@ -1753,14 +1690,14 @@ namespace CGAL { std::deque modified_darts; std::deque modified_darts2; - for ( CMap_dart_iterator_basic_of_cell it(*this, adart, m); - it.cont(); ++it) + for ( CGAL::CMap_dart_iterator_basic_of_cell it(*this, adart, m); + it.cont(); ++it ) { mark(it, m); dartv.push_back(it); } - for ( CMap_dart_iterator_of_involution it(*this, adart); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart); it.cont(); ++it ) { if ( is_marked(it, m) ) @@ -1787,7 +1724,7 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. Helper::template Foreach_enabled_attributes_except - , 1>:: + , 1>:: run(this, modified_darts, modified_darts2); } @@ -1808,14 +1745,14 @@ namespace CGAL { std::deque modified_darts; std::deque modified_darts2; - for ( CMap_dart_iterator_basic_of_cell it(*this,adart,m); - it.cont(); ++it) + for ( CGAL::CMap_dart_iterator_basic_of_cell + it(*this, adart, m); it.cont(); ++it) { - mark(it,m); + mark(it, m); dartv.push_back(it); } - for ( CMap_dart_iterator_of_involution it(*this, adart); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart); it.cont(); ++it ) { if ( is_marked(it, m) ) @@ -1834,15 +1771,14 @@ namespace CGAL { for ( typename std::deque::iterator it=dartv.begin(); it!=dartv.end(); ++it) - { unmark(*it,m); } + { unmark(*it, m); } CGAL_assertion( is_whole_map_unmarked(m) ); free_mark(m); - // TODO pass the mark m to know which dart is modified by b0 of b1 // We test the split of all the incident cells for all the non // void attributes. Helper::template Foreach_enabled_attributes_except - , 1>:: + , 1>:: run(this, modified_darts, modified_darts2); } @@ -1862,7 +1798,7 @@ namespace CGAL { std::deque modified_darts; - for ( CMap_dart_iterator_of_involution it(*this, adart); + for ( CGAL::CMap_dart_iterator_of_involution it(*this, adart); it.cont(); ++it ) { modified_darts.push_back(it); @@ -1873,7 +1809,7 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. Helper::template Foreach_enabled_attributes_except - , i>:: + , i>:: run(this, modified_darts); } @@ -1940,8 +1876,8 @@ namespace CGAL { { if ( is_marked(it, amark) ) { - internal::Foreach_static - ,dimension+1>:: + CGAL::internal::Foreach_static + ,dimension+1>:: run(this, it, &marks, &res); } } @@ -1971,7 +1907,6 @@ namespace CGAL { } for ( unsigned int i=0; i - void update_dart_of_attribute(Dart_handle ah, int amark) - { - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "update_dart_of_attribute but " - "i-attributes are disabled"); - CGAL_assertion(ah!=NULL && ah!=null_dart_handle); - - if ( ah->template attribute()==NULL || - ah->template attribute()->dart()==NULL || - !is_marked(ah->template attribute()->dart(),amark) ) - return; - - for ( CMap_dart_iterator_of_cell it(*this, ah); it.cont(); ++it) - { - if (!is_marked(it,amark)) - { - ah->template attribute()->set_dart(it); - return; - } - } - ah->template attribute()->set_dart(NULL); - } - - /** Update the dart of all the cell-attributes incident to ah onto a non - * marked dart. This method is used before to remove a cell (which is - * marked), to put all the darts of the enabled cells onto surviving dart. - * @param ah the dart to update. - * @param amark the mark. - */ - void update_dart_of_all_attributes(Dart_handle ah, int amark) - { - Helper::template Foreach_enabled_attributes - >::run(this,ah,amark); - } - - /** 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. - * @param amark a mark used to mark darts of the i-cell. - * @return true iff all the darts of the i-cell link to the same attribute. - */ - template - bool is_valid_attribute(Dart_const_handle adart, - unsigned int amark) const - { - CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, - "is_valid_attribute but i-attributes" - " are disabled"); - if ( is_marked(adart, amark) ) return true; - bool valid = true; - bool found_dart = false; - - typename Attribute_const_handle::type - a=adart->template attribute(); - - unsigned int nb = 0; - for ( CMap_dart_const_iterator_basic_of_cell - it(*this,adart,amark); it.cont(); ++it) - { - if ( it->template attribute() != a ) - { - std::cout<<"ERROR: an attribute of the cell is different " - <<&*a<<" != "<<&*it->template attribute()<<" for dart " - <<&*it<dart() ) found_dart = true; - - mark(it, amark); - ++nb; - } - - if ( a!=NULL && a->get_nb_refs()!=nb ) - { - std::cout<<"ERROR: the number of reference of an attribute is not correct. " - <<"Count: "<get_nb_refs()<<" for dart " - <<&*adart<dart()!=NULL && !found_dart ) - { - std::cout<<"ERROR: the dart of an attribute does not belong to the cell " - <<&*a->dart()<<" != NULL "<<" for dart " - <<&*adart< - struct Dart_of_orbit_basic_range : public CMap_range - , - CMap_dart_const_iterator_basic_of_orbit > + struct Dart_of_orbit_basic_range : public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_orbit > { - typedef CMap_range - , - CMap_dart_const_iterator_basic_of_orbit > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_orbit > Base; Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, int amark=-1): Base(amap, adart, amark) @@ -2188,27 +2025,28 @@ namespace CGAL { //************************************************************************** // Dart_of_orbit_basic_const_range template - struct Dart_of_orbit_basic_const_range : public CMap_const_range - > + struct Dart_of_orbit_basic_const_range : public CGAL::CMap_const_range + > { - typedef CMap_const_range - > Base; + typedef CGAL::CMap_const_range + > + Base; - Dart_of_orbit_basic_const_range(const Self &amap, Dart_const_handle adart, - int amark=-1): + Dart_of_orbit_basic_const_range(const Self &amap, Dart_const_handle + adart, int amark=-1): Base(amap, adart, amark) {} }; //************************************************************************** // Dart_of_orbit_range template - struct Dart_of_orbit_range : public CMap_range - , - CMap_dart_const_iterator_of_orbit > + struct Dart_of_orbit_range : public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_orbit > { - typedef CMap_range - , - CMap_dart_const_iterator_of_orbit > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_orbit > Base; Dart_of_orbit_range(Self &amap, Dart_handle adart) : Base(amap,adart) {} @@ -2216,11 +2054,11 @@ namespace CGAL { //************************************************************************** // Dart_of_orbit_const_range template - struct Dart_of_orbit_const_range : public CMap_const_range - > + struct Dart_of_orbit_const_range : public CGAL::CMap_const_range + > { - typedef CMap_const_range - > Base; + typedef CGAL::CMap_const_range + > Base; Dart_of_orbit_const_range(const Self &amap, Dart_const_handle adart): Base(amap,adart) @@ -2252,16 +2090,20 @@ namespace CGAL { // Dart_of_orbit_basic_range template - struct Dart_of_orbit_basic_range: public CMap_range - , - CMap_dart_const_iterator_basic_of_orbit > + struct Dart_of_orbit_basic_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_orbit > { - typedef CMap_range - , - CMap_dart_const_iterator_basic_of_orbit, + CGAL::CMap_dart_const_iterator_basic_of_orbit > Base; - Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, int /*amark*/=-1): + Dart_of_orbit_basic_range(Self &amap, Dart_handle adart, + int /*amark*/=-1): Base(amap, adart) {} }; @@ -2271,14 +2113,15 @@ namespace CGAL { int B6=-1,int B7=-1,int B8=-1,int B9=-1> struct Dart_of_orbit_basic_const_range: public CMap_const_range > + CGAL::CMap_dart_const_iterator_basic_of_orbit > { typedef CMap_const_range - > Base; - Dart_of_orbit_basic_const_range(const Self &amap, Dart_const_handle adart, - int amark=-1): + Dart_of_orbit_basic_const_range(const Self &amap, + Dart_const_handle adart, int amark=-1): Base(amap, adart, amark) {} }; @@ -2286,13 +2129,15 @@ namespace CGAL { // Dart_of_orbit_range template - struct Dart_of_orbit_range: public CMap_range - , - CMap_dart_const_iterator_of_orbit > + struct Dart_of_orbit_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_orbit > { - typedef CMap_range - , - CMap_dart_const_iterator_of_orbit > + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_orbit > Base; Dart_of_orbit_range(Self &amap, Dart_handle adart): @@ -2304,10 +2149,11 @@ namespace CGAL { template struct Dart_of_orbit_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; Dart_of_orbit_const_range(const Self &amap, Dart_const_handle adart): @@ -2542,13 +2388,13 @@ namespace CGAL { //************************************************************************** // Dart_of_cell_basic_range template - struct Dart_of_cell_basic_range: public CMap_range - , - CMap_dart_const_iterator_basic_of_cell > + struct Dart_of_cell_basic_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_cell > { - typedef CMap_range - , - CMap_dart_const_iterator_basic_of_cell > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_cell > Base; Dart_of_cell_basic_range(Self &amap, Dart_handle adart, int amark=-1) : Base(amap, adart, amark) @@ -2558,10 +2404,10 @@ namespace CGAL { // Dart_of_cell_basic_const_range template struct Dart_of_cell_basic_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; + > Base; Dart_of_cell_basic_const_range(const Self &amap, Dart_const_handle adart, int amark=-1) : @@ -2571,13 +2417,13 @@ namespace CGAL { //************************************************************************** // Dart_of_cell_range template - struct Dart_of_cell_range: public CMap_range + struct Dart_of_cell_range: public CGAL::CMap_range , - CMap_dart_const_iterator_of_cell > + CGAL::CMap_dart_const_iterator_of_cell > { - typedef CMap_range + typedef CGAL::CMap_range , - CMap_dart_const_iterator_of_cell > Base; + CGAL::CMap_dart_const_iterator_of_cell > Base; Dart_of_cell_range(Self &amap, Dart_handle adart) : Base(amap, adart) @@ -2587,10 +2433,10 @@ namespace CGAL { // Dart_of_cell_const_range template struct Dart_of_cell_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; + > Base; Dart_of_cell_const_range(const Self &amap, Dart_const_handle adart) : Base(amap, adart) @@ -2637,13 +2483,13 @@ namespace CGAL { //************************************************************************** // Dart_of_involution_basic_range template - struct Dart_of_involution_basic_range: public CMap_range - , - CMap_dart_const_iterator_basic_of_involution > + struct Dart_of_involution_basic_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_involution > { - typedef CMap_range - , - CMap_dart_const_iterator_basic_of_involution > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_involution > Base; Dart_of_involution_basic_range(Self &amap, Dart_handle adart, int amark=-1): @@ -2654,10 +2500,11 @@ namespace CGAL { // Dart_of_involution_basic_const_range template struct Dart_of_involution_basic_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; + > + Base; Dart_of_involution_basic_const_range(const Self &amap, Dart_const_handle adart, @@ -2690,13 +2537,14 @@ namespace CGAL { //************************************************************************** // Dart_of_involution_inv_basic_range template - struct Dart_of_involution_inv_basic_range: public CMap_range - , - CMap_dart_const_iterator_basic_of_involution_inv > + struct Dart_of_involution_inv_basic_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_involution_inv > { - typedef CMap_range - , - CMap_dart_const_iterator_basic_of_involution_inv > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_basic_of_involution_inv > + Base; Dart_of_involution_inv_basic_range(Self &amap, Dart_handle adart, int amark=-1): @@ -2707,10 +2555,11 @@ namespace CGAL { // Dart_of_involution_inv_basic_const_range template struct Dart_of_involution_inv_basic_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > + > Base; Dart_of_involution_inv_basic_const_range(const Self &amap, @@ -2745,13 +2594,13 @@ namespace CGAL { //************************************************************************** // Dart_of_involution_range template - struct Dart_of_involution_range: public CMap_range - , - CMap_dart_const_iterator_of_involution > + struct Dart_of_involution_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_involution > { - typedef CMap_range - , - CMap_dart_const_iterator_of_involution > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_involution > Base; Dart_of_involution_range(Self &amap, Dart_handle adart) : Base(amap, adart) @@ -2761,12 +2610,13 @@ namespace CGAL { // Dart_of_involution_const_range template struct Dart_of_involution_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; + > Base; - Dart_of_involution_const_range(const Self &amap, Dart_const_handle adart): + Dart_of_involution_const_range(const Self &amap, + Dart_const_handle adart): Base(amap, adart) {} }; @@ -2793,13 +2643,13 @@ namespace CGAL { //************************************************************************** // Dart_of_involution_inv_range template - struct Dart_of_involution_inv_range: public CMap_range - , - CMap_dart_const_iterator_of_involution_inv > + struct Dart_of_involution_inv_range: public CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_involution_inv > { - typedef CMap_range - , - CMap_dart_const_iterator_of_involution_inv > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_dart_const_iterator_of_involution_inv > Base; Dart_of_involution_inv_range(Self &amap, Dart_handle adart) : Base(amap, adart) @@ -2809,10 +2659,11 @@ namespace CGAL { // Dart_of_involution_inv_const_range template struct Dart_of_involution_inv_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > Base; + > + Base; Dart_of_involution_inv_const_range(const Self &amap, Dart_const_handle adart): @@ -2843,8 +2694,8 @@ namespace CGAL { //************************************************************************** // Dart_basic_range struct Dart_basic_range { - typedef CMap_dart_iterator_basic_of_all iterator; - typedef CMap_dart_const_iterator_basic_of_all const_iterator; + typedef CGAL::CMap_dart_iterator_basic_of_all iterator; + typedef CGAL::CMap_dart_const_iterator_basic_of_all const_iterator; Dart_basic_range(Self &amap) : mmap(amap) {} iterator begin() { return iterator(mmap); } @@ -2861,7 +2712,7 @@ namespace CGAL { //************************************************************************** // Dart_basic_const_range struct Dart_basic_const_range { - typedef CMap_dart_const_iterator_basic_of_all const_iterator; + typedef CGAL::CMap_dart_const_iterator_basic_of_all const_iterator; Dart_basic_const_range(Self &amap) : mmap(amap) {} const_iterator begin() const { return const_iterator(mmap); } @@ -2882,13 +2733,14 @@ namespace CGAL { //************************************************************************** // One_dart_per_incident_cell_range template - struct One_dart_per_incident_cell_range: public CMap_range - , - CMap_one_dart_per_incident_cell_const_iterator > + struct One_dart_per_incident_cell_range: public CGAL::CMap_range + , + CGAL::CMap_one_dart_per_incident_cell_const_iterator > { - typedef CMap_range - , - CMap_one_dart_per_incident_cell_const_iterator > Base; + typedef CGAL::CMap_range + , + CGAL::CMap_one_dart_per_incident_cell_const_iterator > + Base; One_dart_per_incident_cell_range(Self &amap, Dart_handle adart): Base(amap, adart) @@ -2898,11 +2750,11 @@ namespace CGAL { // One_dart_per_incident_cell_const_range template struct One_dart_per_incident_cell_const_range: public CMap_const_range - > + > { typedef CMap_const_range - > - Base; + > Base; One_dart_per_incident_cell_const_range(const Self &amap, Dart_const_handle adart) : @@ -2913,8 +2765,9 @@ namespace CGAL { // One_dart_per_cell_range template struct One_dart_per_cell_range { - typedef CMap_one_dart_per_cell_iterator iterator; - typedef CMap_one_dart_per_cell_const_iterator const_iterator; + typedef CGAL::CMap_one_dart_per_cell_iterator iterator; + typedef CGAL::CMap_one_dart_per_cell_const_iterator + const_iterator; One_dart_per_cell_range(Self &amap) : mmap(amap), msize(0) {} iterator begin() { return iterator(mmap); } @@ -2938,7 +2791,8 @@ namespace CGAL { // One_dart_per_cell_const_range template struct One_dart_per_cell_const_range { - typedef CMap_one_dart_per_cell_const_iterator const_iterator; + typedef CGAL::CMap_one_dart_per_cell_const_iterator + const_iterator; One_dart_per_cell_const_range(const Self &amap) : mmap(amap), msize(0) {} const_iterator begin() const { return const_iterator(mmap); } @@ -3019,8 +2873,8 @@ namespace CGAL { amap.clear(); // We create a copy of all the dart of the map. - for ( typename Dart_range::iterator it=darts().begin(); it!=darts().end(); - ++it) + for ( typename Dart_range::iterator it=darts().begin(); + it!=darts().end(); ++it) { dual[it] = amap.create_dart(); if ( it==adart && res==NULL ) res = dual[it]; diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_basic_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_basic_operations.h index 47e1473ae22..268e504bc3e 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_basic_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_basic_operations.h @@ -22,8 +22,8 @@ #include -namespace CGAL { - +namespace CGAL +{ /** @file Combinatorial_map_basic_operations.h * Basic operations on a combinatorial map. */ @@ -41,7 +41,7 @@ namespace CGAL { { CGAL_static_assertion( (boost::is_same::value) ); - bool found = false; + bool found=false; for (Iterator it(amap, adart1); !found && it.cont(); ++it) { @@ -64,7 +64,7 @@ namespace CGAL { { CGAL_static_assertion( (boost::is_same::value) ); - bool res = true; + bool res=true; for ( Iterator it(amap, adart); res && it.cont(); ++it ) { @@ -86,7 +86,7 @@ namespace CGAL { int amark) { amap.negate_mark(amark); - bool res = is_whole_orbit_marked(amap, adart, amark); + bool res=CGAL::is_whole_orbit_marked(amap, adart, amark); amap.negate_mark(amark); return res; } @@ -108,7 +108,7 @@ namespace CGAL { CGAL_assertion( (is_whole_orbit_unmarked > (amap, adart, amark)) ); - typename Map::size_type res = 0; + typename Map::size_type res=0; for (Iterator it(amap, adart, amark); it.cont(); ++it) { @@ -132,7 +132,8 @@ namespace CGAL { int amark) { amap.negate_mark(amark); - typename Map::size_type res = mark_orbit(amap, adart, amark); + typename Map::size_type + res=CGAL::mark_orbit(amap, adart, amark); amap.negate_mark(amark); return res; } @@ -148,10 +149,9 @@ namespace CGAL { typename Map::Dart_const_handle adart1, typename Map::Dart_const_handle adart2) { - return belong_to_same_orbit::const_iterator> - (amap, adart1, adart2); + return CGAL::belong_to_same_orbit::const_iterator> + (amap, adart1, adart2); } template < class Map, unsigned int i> @@ -159,7 +159,7 @@ namespace CGAL { typename Map::Dart_const_handle adart1, typename Map::Dart_const_handle adart2) { - return belong_to_same_cell(amap,adart1,adart2); + return CGAL::belong_to_same_cell(amap,adart1,adart2); } @@ -174,10 +174,9 @@ namespace CGAL { typename Map::Dart_const_handle adart, unsigned int amark) { - return is_whole_orbit_marked::const_iterator> - (amap, adart, amark); + return CGAL::is_whole_orbit_marked::const_iterator> + (amap, adart, amark); } template < class Map, unsigned int i> @@ -185,7 +184,7 @@ namespace CGAL { typename Map::Dart_const_handle adart, unsigned int amark) { - return is_whole_cell_marked(amap,adart,amark); + return CGAL::is_whole_cell_marked(amap,adart,amark); } /** Test if all the darts of a given cell are unmarked. @@ -199,10 +198,9 @@ namespace CGAL { typename Map::Dart_const_handle adart, unsigned int amark) { - return is_whole_orbit_unmarked::iterator> - (amap, adart, amark); + return CGAL::is_whole_orbit_unmarked::iterator> + (amap, adart, amark); } template < class Map, unsigned int i> @@ -210,7 +208,8 @@ namespace CGAL { typename Map::Dart_const_handle adart, unsigned int amark) { - return is_whole_cell_unmarked(amap,adart,amark); + return CGAL::is_whole_cell_unmarked + (amap,adart,amark); } /** Mark a given cell with a given mark. @@ -224,16 +223,15 @@ namespace CGAL { typename Map::size_type mark_cell(const Map & amap, typename Map::Dart_const_handle adart, int amark) - { return mark_orbit::const_iterator> - (amap, adart, amark); } + { return CGAL::mark_orbit::const_iterator> + (amap, adart, amark); } template < class Map, unsigned int i> typename Map::size_type mark_cell(const Map & amap, typename Map::Dart_const_handle adart, int amark) - { return mark_cell(amap, adart, amark);} + { return CGAL::mark_cell(amap, adart, amark);} /** Unmark a given orbit with a given mark. * @param amap a combinatorial map. @@ -246,16 +244,15 @@ namespace CGAL { typename Map::size_type unmark_cell(const Map & amap, typename Map::Dart_handle adart, int amark) - { return unmark_orbit::const_iterator> - (amap, adart, amark);} + { return CGAL::unmark_orbit::const_iterator> + (amap, adart, amark);} template < class Map, unsigned int i > typename Map::size_type unmark_cell(const Map & amap, typename Map::Dart_handle adart, int amark) - { return unmark_cell(amap, adart, amark);} + { return CGAL::unmark_cell(amap, adart, amark); } /** Compute the degree of a given i-cell c. * The degree is the number of distinct i+1 cells incident to c. @@ -280,7 +277,7 @@ namespace CGAL { if (!amap.is_marked(*it, treated)) { ++nbIncident; - mark_cell(amap, *it, treated); + CGAL::mark_cell(amap, *it, treated); } amap.mark(*it,mark); } @@ -289,7 +286,7 @@ namespace CGAL { for (it.rewind(); it.cont(); ++it) { if (amap.is_marked(*it, treated)) - unmark_cell(amap, *it, treated); + CGAL::unmark_cell(amap, *it, treated); amap.mark(*it,mark); } @@ -327,7 +324,7 @@ namespace CGAL { if (!amap.is_marked(*it, treated)) { ++nbIncident; - mark_cell(amap, *it, treated); + CGAL::mark_cell(amap, *it, treated); } amap.mark(*it,mark); } @@ -336,7 +333,7 @@ namespace CGAL { for (it.rewind(); it.cont(); ++it) { if (amap.is_marked(*it, treated)) - unmark_cell(amap, *it, treated); + CGAL::unmark_cell(amap, *it, treated); amap.mark(*it,mark); } diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h index 055a11779cf..a1a97e693f4 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_functors.h @@ -21,8 +21,8 @@ #define CGAL_COMBINATORIAL_MAP_FUNCTORS_H #include -#include #include +#include #include /* Definition of functors used to manage attributes (we need functors as @@ -30,404 +30,114 @@ * compiling time). Some of these functors are used with * Foreach_enabled_attributes to iterate through all the non void attribs. * Functors allowing to group/ungroup attributes are defined in - * Combinatorial_map_group_functors.h (included at the end of this file) + * Combinatorial_map_group_functors.h. Some internal functors are defined + * in internal/Combinatorial_map_internal_functors.h. * - * Reserve_mark_functor to reserve one mark for each non void attribute. + * Reserve_mark_functor to reserve one mark, used with + * Foreach_enabled_attributes to reserve a mark for each non void attribute. + * + * Display_attribute_functor to display the address of the i-attribute + * of a given dart (can be used with Foreach_enabled_attributes) * * Set_i_attribute_functor to set the i-attribute of a given * i-cell. - * - * internal::Call_split_functor to call the OnSplit functors on two - * given i-attributes. - * - * internal::Call_merge_functor to call the OnMerge functors on two - * given i-attributes. - * - * internal::Test_is_valid_attribute_functor to test if a given i-cell is - * valid (all its darts are linked to the same attribute, no other dart is - * linked with this attribute). - * - * internal::Count_cell_functor to count the nuber of i-cells. - * - * internal::Count_bytes_one_attribute_functor to count the memory - * occupied by i-attributes. - * - * internal::Decrease_attribute_functor to decrease by one the ref - * counting of a given i-attribute. - * - * internal::Beta_functor to call several beta on the given dart. - * Indices are given as parameter of the run function. - * - * internal::Beta_functor_static to call several beta on the given - * dart. Indices are given as template arguments. - * - * internal::Set_i_attribute_of_dart_functor to set the i-attribute - * of a given dart. */ namespace CGAL { - /** @file Combinatorial_map_functors.h - * Definition of functors used for dD Combinatorial map. - */ - // ************************************************************************** - /// Functor used to reserve one mark for each enabled attribute. - template - struct Reserve_mark_functor +/** @file Combinatorial_map_functors.h + * Definition of functors used for dD Combinatorial map. + */ +// **************************************************************************** +/// Functor used to reserve one mark, used with Foreach_enabled_attributes +/// to reserve a 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 display the address of the i-cell attribute. Can be used +/// with Foreach_enabled_attributes. +template +struct Display_attribute_functor +{ + template + static void run(const CMap* amap, + typename CMap::Dart_const_handle adart) { - template - static void run(const CMap* amap, std::vector* marks) - { (*marks)[i] = amap->get_new_mark(); } - }; - // ************************************************************************** - /// Functor used to display the address of the i-cell attribute - template - struct Display_attribute_functor + if ( adart->template attribute()==NULL ) + std::cout<<"NULL"; + else + std::cout<<&*(adart->template attribute()); + } +}; +// **************************************************************************** +/// Functor used to test if a cell is valid +template +struct Test_is_valid_attribute_functor +{ + template + static bool run(const CMap* amap, + typename CMap::Dart_const_handle adart) { - template - static void run(const CMap* amap, - typename CMap::Dart_const_handle adart) + int mark=amap->get_new_mark(); + bool res = true; + CGAL::internal::Test_is_valid_attribute_functor:: + run(amap, adart, mark, &res); + + amap->negate_mark(mark); + if ( !amap->is_whole_map_marked(mark) ) { - if ( adart->template attribute()==NULL ) - std::cout<<"NULL"; - else - std::cout<<&*(adart->template attribute()); + for ( CGAL::CMap_dart_const_iterator_basic_of_cell + it(*amap, adart, mark); it.cont(); ++it ) + amap->unmark(it, mark); } - }; - // ************************************************************************** - namespace internal + CGAL_assertion ( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + + return res; + } +}; +// **************************************************************************** +/// Functor used to set the i-attribute of a given i-cell. +/// We can use any range as Range type, by default we use +/// Dart_of_cell_range +template, + typename T=typename CMap::template Attribute_type::type> +struct Set_i_attribute_functor +{ + static void run( CMap* amap, typename CMap::Dart_handle dh, + typename CMap::template Attribute_handle::type + ah ) { - // 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) + CGAL_static_assertion(i<=CMap::dimension); + CGAL_assertion( dh!=NULL && dh!=CMap::null_dart_handle && ah!=NULL ); + + for ( typename Range::iterator it(*amap, dh); it.cont(); ++it) { - 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 CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2) - { - Apply_cell_functor - ::type, - typename CMap::Helper:: - template Attribute_type::type::On_split>:: - run(*(adart1->template attribute()), - *(adart2->template attribute())); - } - static void - run(typename CMap::Helper::template Attribute_handle::type a1, - typename CMap::Helper::template Attribute_handle::type a2) - { - Apply_cell_functor - ::type, - typename CMap::Helper:: - template Attribute_type::type::On_split>:: - run(*a1, *a2); - } - }; - // Specialization for disabled attributes. - template - struct Call_split_functor - { - 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 CMap::Dart_handle adart1, - typename CMap::Dart_handle adart2) - { - Apply_cell_functor - ::type, - typename CMap::Helper::template Attribute_type::type::On_merge>:: - run(*(adart1->template attribute()), - *(adart2->template attribute())); - } - static void - run(typename CMap::Helper::template Attribute_handle::type a1, - typename CMap::Helper::template Attribute_handle::type a2) - { - Apply_cell_functor - ::type, - typename CMap::Helper::template Attribute_type::type::On_merge>:: - run(*a1, *a2); - } - }; - // Specialization for disabled attributes. - template - struct Call_merge_functor - { - static void run(typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // ************************************************************************** - /// 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]) ) + if ( it->template attribute()!=ah ) { - (*ares)=false; - std::cerr << "CMap not valid: a "<::run(amap, it); + it->template set_attribute(ah); } } - }; - // ************************************************************************** - /// Functor for counting i-cell - template - 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; - } - }; - // ************************************************************************** - /// Decrease the cell attribute reference counting of the given dart. - /// The attribute is removed if there is no more darts linked with it. - template::type> - struct Decrease_attribute_functor_run - { - static void run(CMap* amap, typename CMap::Dart_handle adart) - { - if ( adart->template attribute()!=NULL ) - { - adart->template attribute()->dec_nb_refs(); - if ( adart->template attribute()->get_nb_refs()==0 ) - amap->template erase_attribute(adart->template attribute()); - } - } - }; - /// Specialization for void attributes. - template - struct Decrease_attribute_functor_run - { - static void run(CMap*, typename CMap::Dart_handle) - {} - }; - // ************************************************************************** - /// 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) - { Decrease_attribute_functor_run::run(amap, adart); } - }; - // ************************************************************************** - /// Functor used to set the i-attribute of a given dart. - template::type> - struct Set_i_attribute_of_dart_functor - { - static void run( CMap* amap, typename CMap::Dart_handle dh, - typename CMap::Helper::template Attribute_handle::type - ah ) - { - CGAL_static_assertion(i<=CMap::dimension); - CGAL_assertion( dh!=NULL && dh!=CMap::null_dart_handle ); - - if ( dh->template attribute()==ah ) return; - - Decrease_attribute_functor_run::run(amap, dh); - dh->template set_attribute(ah); - } - }; - /// Specialization for void attributes. - template - struct Set_i_attribute_of_dart_functor - { - static void run( CMap*, typename CMap::Dart_handle, - typename CMap::Helper::template Attribute_handle::type) - {} - }; - // ************************************************************************** - // Beta functor, used to combine several beta. -#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template - struct Beta_functor; - template - struct Beta_functor - { - static Dart_handle run(Dart_handle ADart, int B, Betas... betas) - { return Beta_functor::run(ADart->beta(B), - betas...); } - }; - template - struct Beta_functor - { - static Dart_handle run(Dart_handle ADart, int B) - { - CGAL_assertion( ADart!=NULL ); - return ADart->beta(B); - } - }; - // ************************************************************************** - template - struct Beta_functor_static; - template - struct Beta_functor_static - { - static Dart_handle run(Dart_handle ADart) - { return Beta_functor_static:: - run(ADart->template beta()); } - }; - template - struct Beta_functor_static - { - static Dart_handle run(Dart_handle ADart) - { - CGAL_assertion( ADart!=NULL ); - return ADart->template beta(); - } - }; -#endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - // ************************************************************************** - /// Functor used to call update_dart_of_attribute - /// on each i-cell attribute enabled - // TODO REMOVE ? - template - struct Update_dart_of_attribute_functor - { - template - 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(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 - { - static void run(CMap*, typename CMap::Dart_handle, int) - {} - }; - // ************************************************************************** - } // namespace internal - // ************************************************************************** - /// Functor used to set the i-attribute of a given i-cell. - /// We can use any range as Range type, by default we use - /// Dart_of_cell_range - template, - typename T=typename CMap::Helper::template Attribute_type::type> - struct Set_i_attribute_functor - { - static void run( CMap* amap, typename CMap::Dart_handle dh, - typename CMap::Helper::template Attribute_handle::type - ah ) - { - CGAL_static_assertion(i<=CMap::dimension); - CGAL_assertion( dh!=NULL && dh!=CMap::null_dart_handle && ah!=NULL ); - - for ( typename Range::iterator it(*amap, dh); it.cont(); ++it) - { - if ( it->template attribute()!=ah ) - { - internal::Decrease_attribute_functor_run::run(amap, it); - it->template set_attribute(ah); - } - } - ah->set_dart(dh); - } - }; - /// Specialization for void attributes. - template - struct Set_i_attribute_functor - { - static void run( CMap*, typename CMap::Dart_handle, - typename CMap::Helper::template Attribute_handle::type) - {} - }; - // ************************************************************************** + ah->set_dart(dh); + } +}; +/// Specialization for void attributes. +template +struct Set_i_attribute_functor +{ + static void run( CMap*, typename CMap::Dart_handle, + typename CMap::template Attribute_handle::type) + {} +}; +// **************************************************************************** } // namespace CGAL -#include - #endif // CGAL_COMBINATORIAL_MAP_FUNCTORS_H // // EOF // diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h b/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h index 7e7554466c2..91fc444aa2a 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_insertions.h @@ -1,7 +1,27 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// #ifndef CGAL_COMBINATORIAL_MAP_INSERTIONS_H #define CGAL_COMBINATORIAL_MAP_INSERTIONS_H -namespace CGAL { +namespace CGAL +{ /** @file Combinatorial_map_insertions.h * Insertion operations on combinatorial map. */ @@ -54,10 +74,11 @@ insert_cell_0_in_cell_1( CMap& amap, typename CMap::Dart_handle adart, // We copy all the attributes except for dim=0 CMap::Helper::template Foreach_enabled_attributes_except - , 0>:: + , 0>:: run(&amap,*it,d1); // We initialise the 0-atttrib to ah - internal::Set_i_attribute_of_dart_functor::run(&amap, d1, ah); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(&amap, d1, ah); amap.mark(*it, mark); } @@ -73,10 +94,12 @@ insert_cell_0_in_cell_1( CMap& amap, typename CMap::Dart_handle adart, amap.free_mark(m); amap.free_mark(mark); - internal::Degroup_attribute_functor_run:: + CGAL::internal::Degroup_attribute_functor_run:: run(&amap, adart, adart->beta(1)); +#ifdef CGAL_CMAP_TEST_VALID_INSERTIONS CGAL_assertion( amap.is_valid() ); +#endif return adart->beta(1); } @@ -90,7 +113,7 @@ insert_cell_0_in_cell_1( CMap& amap, typename CMap::Dart_handle adart, template < class CMap > typename CMap::Dart_handle insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, - typename CMap::Helper::template + typename CMap::template Attribute_handle<0>::type ah=NULL ) { CGAL_assertion(adart != NULL && adart!=CMap::null_dart_handle); @@ -144,7 +167,8 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, if ( prev!=NULL ) amap.template basic_link_beta_for_involution<2>(prev, n1); - internal::Set_i_attribute_of_dart_functor::run(&amap, n1, ah); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(&amap, n1, ah); } for (unsigned int dim=3; dim<=CMap::dimension; ++dim) @@ -166,7 +190,7 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, nn2=amap.create_dart(); amap.link_beta_0(cur->beta(dim), nn2); amap.basic_link_beta_for_involution(n2, nn2, dim); - internal::Set_i_attribute_of_dart_functor:: + CGAL::internal::Set_i_attribute_of_dart_functor:: run(&amap, nn2, ah); } else nn2=NULL; @@ -218,14 +242,16 @@ insert_cell_0_in_cell_2( CMap& amap, typename CMap::Dart_handle adart, amap.unmark(*itd, treated); if ( *itd!=adart ) - internal::Degroup_attribute_functor_run:: + CGAL::internal::Degroup_attribute_functor_run:: run(&amap, adart, *itd); } CGAL_assertion(amap.is_whole_map_unmarked(treated)); amap.free_mark(treated); +#ifdef CGAL_CMAP_TEST_VALID_INSERTIONS CGAL_assertion( amap.is_valid() ); +#endif return n1; } @@ -238,7 +264,7 @@ template typename CMap::Dart_handle insert_dangling_cell_1_in_cell_2( CMap& amap, typename CMap::Dart_handle adart1, - typename CMap::Helper::template + typename CMap::template Attribute_handle<0>::type ah=NULL ) { CGAL_assertion(adart1!=NULL && adart1!=CMap::null_dart_handle); @@ -303,7 +329,8 @@ insert_dangling_cell_1_in_cell_2( CMap& amap, (it1->beta(dim)->beta_inv(s1)->beta(2), d2, dim); } } - internal::Set_i_attribute_of_dart_functor::run(&amap, d1, ah); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(&amap, d1, ah); amap.mark(it1, treated); } @@ -321,7 +348,9 @@ insert_dangling_cell_1_in_cell_2( CMap& amap, CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); amap.free_mark(mark1); +#ifdef CGAL_CMAP_TEST_VALID_INSERTIONS CGAL_assertion( amap.is_valid() ); +#endif return adart1->template beta<0>(); } @@ -339,7 +368,7 @@ bool is_insertable_cell_1_in_cell_2(const CMap& amap, { CGAL_assertion(adart1 != NULL && adart2 != NULL); if ( adart1==adart2 ) return false; - for ( CMap_dart_const_iterator_of_orbit it(amap,adart1); + for ( CGAL::CMap_dart_const_iterator_of_orbit it(amap,adart1); it.cont(); ++it ) { if ( it==adart2 ) return true; @@ -365,17 +394,15 @@ insert_cell_1_in_cell_2(CMap& amap, CGAL_assertion(is_insertable_cell_1_in_cell_2(amap, adart1, adart2)); int m1=amap.get_new_mark(); - CMap_dart_iterator_basic_of_involution - it1 = CMap_dart_iterator_basic_of_involution(amap, adart1, m1); + CGAL::CMap_dart_iterator_basic_of_involution it1(amap, adart1, m1); int m2=amap.get_new_mark(); - CMap_dart_iterator_basic_of_involution - it2 = CMap_dart_iterator_basic_of_involution(amap, adart2, m2); + CGAL::CMap_dart_iterator_basic_of_involution it2(amap, adart2, m2); int mark1=amap.get_new_mark(); std::deque to_unmark; { - for ( CMap_dart_iterator_basic_of_cell it(amap,adart1,mark1); + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart1,mark1); it.cont(); ++it ) { to_unmark.push_back(it); @@ -437,8 +464,7 @@ insert_cell_1_in_cell_2(CMap& amap, amap.mark(it1,treated); } - internal::Degroup_attribute_functor_run:: - run(&amap, d1, d2); + CGAL::internal::Degroup_attribute_functor_run::run(&amap, d1, d2); amap.negate_mark(m1); amap.negate_mark(m2); @@ -465,7 +491,9 @@ insert_cell_1_in_cell_2(CMap& amap, CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); amap.free_mark(mark1); +#ifdef CGAL_CMAP_TEST_VALID_INSERTIONS CGAL_assertion( amap.is_valid() ); +#endif return adart1->template beta<0>(); } @@ -502,7 +530,7 @@ bool is_insertable_cell_2_in_cell_3(const CMap& amap, 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 ( !CGAL::belong_to_same_cell(amap, od, *it) ) return false; } prec = *it; @@ -512,7 +540,7 @@ bool is_insertable_cell_2_in_cell_3(const CMap& amap, od = prec->other_extremity(); if ( od==CMap::null_dart_handle ) return false; - if (!belong_to_same_cell(amap, od, *afirst)) + if (!CGAL::belong_to_same_cell(amap, od, *afirst)) return false; return true; @@ -581,7 +609,7 @@ insert_cell_2_in_cell_3(CMap& amap, InputIterator afirst, InputIterator alast) { typename CMap::Dart_handle first2 = NULL; prec = NULL; - for ( CMap_dart_iterator_of_orbit it(amap, first); + for ( CMap_dart_iterator_basic_of_orbit it(amap, first); it.cont(); ++it ) { d = amap.create_dart(); @@ -643,11 +671,13 @@ insert_cell_2_in_cell_3(CMap& amap, InputIterator afirst, InputIterator alast) if ( withBeta3 ) { // Here we cannot use Degroup_attribute_functor_run as new darts do not // have their 3-attribute - internal::Degroup_attribute_functor_run:: + CGAL::internal::Degroup_attribute_functor_run:: run(&amap, first, first->template beta<3>()); } +#ifdef CGAL_CMAP_TEST_VALID_INSERTIONS CGAL_assertion( amap.is_valid() ); +#endif return first; } diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index 1622f3a9cd6..3187795b16d 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -25,8 +25,8 @@ #include #include -namespace CGAL { - +namespace CGAL +{ /** @file Combinatorial_map_operations.h * Some operations to modify a combinatorial map. */ @@ -48,8 +48,8 @@ namespace CGAL { // 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) + for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); + res && it.cont(); ++it ) { if (it->template beta()->template beta()!= it->template beta_inv()->template beta() ) @@ -85,7 +85,7 @@ namespace CGAL { const int iinv = CGAL_BETAINV(i); // First we store and mark all the darts of the i-cell to remove. - for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -97,29 +97,25 @@ namespace CGAL { // We group the two (i+1)-cells incident if they exist. if ( dg1!=NULL ) - internal::Group_attribute_functor_run:: + CGAL::internal::Group_attribute_functor_run:: run(&amap, dg1, dg2); - // Second we store all the incident cells that can be split by - // the operation. - typename std::deque::iterator it = - to_erase.begin(); - //TODO remove ? or be sure that this is required - for (; it != to_erase.end(); ++it) - amap.update_dart_of_all_attributes(*it, mark); - + // During the operation, we store in modified_darts the darts modified + // to test after the loop the non void attributes that are split. std::deque modified_darts; - std::deque modified_darts2; // If i==1, we modify beta1, thus in modified_darts we store all // the darts having beta0 modified, and in modified_darts2 all the - // darts having beta1 modified. Otherwise we store all the darts in - // modified_darts. + // darts having beta1 modified. For i>1 all the modified darts are + // stored in modified_darts. + std::deque modified_darts2; std::deque &first_modified_darts= (i==1?modified_darts2: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 ) + typename std::deque::iterator it = + to_erase.begin(); + for ( ; it!=to_erase.end(); ++it ) { d1=(*it)->template beta(); while ( d1!=CMap::null_dart_handle && amap.is_marked(d1, mark) ) @@ -199,21 +195,24 @@ namespace CGAL { // void attributes. if ( i==1 ) CMap::Helper::template Foreach_enabled_attributes_except - , i>:: + , i>:: run(&amap, modified_darts, modified_darts2, mark_modified_darts); else CMap::Helper::template Foreach_enabled_attributes_except - , i>:: + , i>:: run(&amap, modified_darts, mark_modified_darts); // We remove all the darts of the i-cell. - for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) + for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { amap.erase_dart(*it); } CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); + // If no attribute is enabled (or if only i-attributes are enabled), + // the darts are not unmark by Foreach_enabled_attributes_except. + // Thus we unmark them now. if ( !amap.is_whole_map_unmarked(mark_modified_darts) ) { for ( typename std::deque:: @@ -233,8 +232,9 @@ namespace CGAL { CGAL_assertion ( amap.is_whole_map_unmarked(mark_modified_darts) ); amap.free_mark(mark_modified_darts); - CGAL_expensive_postcondition( amap.is_valid() ); - assert( amap.is_valid() ); // TODO remove +#ifdef CGAL_CMAP_TEST_VALID_REMOVALS + CGAL_assertion( amap.is_valid() ); +#endif return res; } @@ -258,19 +258,18 @@ namespace CGAL { std::deque modified_darts; - // 1) We mark all the darts of the d-cell. - for (CMap_dart_iterator_basic_of_cell - it(amap,adart,mark); it.cont(); ++it) + // We mark all the darts of the d-cell. + for ( CGAL::CMap_dart_iterator_basic_of_cell + it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); amap.mark(it,mark); ++res; } + // We unlink all the darts of the volume for beta-d. typename std::deque::iterator it = to_erase.begin(); - - // 3) We unlink all the darts of the volume for beta-d. for ( it = to_erase.begin(); it != to_erase.end(); ++it ) { if ( !(*it)->template is_free() && @@ -281,21 +280,22 @@ namespace CGAL { } } - // 4) We test the split of all the incident cells for all the non + // We test the split of all the incident cells for all the non // void attributes. CMap::Helper::template Foreach_enabled_attributes_except - , + , CMap::dimension>::run(&amap, modified_darts); - // 5) We remove all the darts of the d-cell. + // We remove all the darts of the d-cell. for ( it = to_erase.begin(); it != to_erase.end(); ++it ) { amap.erase_dart(*it); } CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); - CGAL_expensive_postcondition( amap.is_valid() ); - assert( amap.is_valid() ); // TO REMOVE +#ifdef CGAL_CMAP_TEST_VALID_REMOVALS + CGAL_assertion( amap.is_valid() ); +#endif return res; } @@ -321,13 +321,9 @@ namespace CGAL { int mark = amap.get_new_mark(); // int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; - - std::deque modified_darts; - std::deque modified_darts2; - // First we store and mark all the darts of the 0-cell to remove. - for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + std::deque to_erase; + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -337,20 +333,21 @@ namespace CGAL { ++res; } - // Second we store all the incident cells that can be split by - // the operation. - typename std::deque::iterator it = - to_erase.begin(); - for (; it != to_erase.end(); ++it) - amap.update_dart_of_all_attributes(*it, mark); - // We group the two edges incident if they exist. if ( dg1!=NULL ) - internal::Group_attribute_functor_run:: + CGAL::internal::Group_attribute_functor_run:: run(&amap, dg1, dg2); + // During the operation, we store in modified_darts the darts modified + // by beta0 to test after the loop non void attributes that are split. + std::deque modified_darts; + // And we store in modified_darts2 all the darts having beta1 modified. + std::deque modified_darts2; + // For each dart of the vertex, we modify 0 and 1-links of neighbors. - for ( it=to_erase.begin(); it != to_erase.end(); ++it) + typename std::deque::iterator it = + to_erase.begin(); + for ( ; it != to_erase.end(); ++it) { if ( !(*it)->template is_free<0>() ) { @@ -373,8 +370,6 @@ namespace CGAL { { if ( !(*it)->is_free(j) ) { - // TODO push these darts in modified_darts ? - // not sure this is required amap.basic_link_beta((*it)->template beta<0>(), (*it)->beta(j), j); //((*it)->beta(0))->basic_link_beta((*it)->beta(j),j); @@ -392,11 +387,7 @@ namespace CGAL { for ( unsigned int j=2; j<=CMap::dimension; ++j ) { if ( !(*it)->is_free(j) ) - { - // TODO push these darts in modified_darts ? - // not sure this is required - amap.unlink_beta(*it, j); - } + { amap.unlink_beta(*it, j); } } } } @@ -404,19 +395,19 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. CMap::Helper::template Foreach_enabled_attributes_except - , 1>:: - run(&amap, - modified_darts, modified_darts2); + , 1>:: + run(&amap,modified_darts, modified_darts2); - // We remove all the darts of the i-cell. - for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) + // We remove all the darts of the 0-cell. + for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { amap.erase_dart(*it); } CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); - CGAL_expensive_postcondition( amap.is_valid() ); - assert( amap.is_valid() ); // TO REMOVEE +#ifdef CGAL_CMAP_TEST_VALID_REMOVALS + CGAL_assertion( amap.is_valid() ); +#endif return res; } @@ -429,7 +420,10 @@ namespace CGAL { */ template < class CMap, unsigned int i > size_t remove_cell(CMap& amap, typename CMap::Dart_handle adart) - { return Remove_cell_functor::run(amap,adart); } + { + return + CGAL::Remove_cell_functor::run(amap,adart); + } /** Test if an i-cell can be contracted. * An i-cell can be contracted if i==1 @@ -448,8 +442,8 @@ 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); - res && it.cont(); ++it) + for ( CGAL::CMap_dart_const_iterator_of_cell it(amap, adart); + res && it.cont(); ++it ) { if ( it->template beta()->template beta()!= it->template beta()->template beta_inv() ) @@ -480,12 +474,11 @@ namespace CGAL { int mark = amap.get_new_mark(); int mark_modified_darts = amap.get_new_mark(); - 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); + std::deque to_erase; + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -497,19 +490,17 @@ namespace CGAL { // We group the two (i+1)-cells incident if they exist. if ( dg1!=NULL ) - internal::Group_attribute_functor_run:: + CGAL::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 = - to_erase.begin(); - for (; it != to_erase.end(); ++it) - amap.update_dart_of_all_attributes(*it, mark); - + // During the operation, we store in modified_darts the darts modified + // to test after the loop the non void attributes that are split. 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 ) + typename std::deque::iterator it = + to_erase.begin(); + for ( ; it!=to_erase.end(); ++it ) { d1 = (*it)->template beta(); while ( d1!=CMap::null_dart_handle && amap.is_marked(d1, mark) ) @@ -580,16 +571,19 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. CMap::Helper::template Foreach_enabled_attributes_except - , i>:: + , i>:: run(&amap, modified_darts, mark_modified_darts); // We remove all the darts of the i-cell. - for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) + for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { amap.erase_dart(*it); } CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); + // If no attribute is enabled (or if only i-attributes are enabled), + // the darts are not unmark by Foreach_enabled_attributes_except. + // Thus we unmark them now. if ( !amap.is_whole_map_unmarked(mark_modified_darts) ) { for ( typename std::deque:: @@ -598,13 +592,12 @@ namespace CGAL { amap.unmark(*it, mark_modified_darts); } - // amap.display_darts(std::cout); - CGAL_assertion ( amap.is_whole_map_unmarked(mark_modified_darts) ); amap.free_mark(mark_modified_darts); - CGAL_expensive_postcondition( amap.is_valid() ); - assert( amap.is_valid() ); +#ifdef CGAL_CMAP_TEST_VALID_CONTRACTIONS + CGAL_assertion( amap.is_valid() ); +#endif return res; } @@ -630,13 +623,9 @@ namespace CGAL { int mark = amap.get_new_mark(); // int mark_modified_darts = amap.get_new_mark(); - std::deque to_erase; - - std::deque modified_darts; - std::deque modified_darts2; - // 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); + std::deque to_erase; + for ( CGAL::CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { to_erase.push_back(it); @@ -647,19 +636,21 @@ namespace CGAL { ++res; } - typename std::deque::iterator it = - to_erase.begin(); - - for (; it != to_erase.end(); ++it) - amap.update_dart_of_all_attributes(*it, mark); - // We group the two vertices incident if they exist. if ( dg1!=NULL ) - internal::Group_attribute_functor_run:: - run(&amap, dg1, dg2); + CGAL::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 ) + // During the operation, we store in modified_darts the darts modified + // by beta0 to test after the loop non void attributes that are split. + std::deque modified_darts; + // And we store in modified_darts2 all the darts having beta1 modified. + std::deque modified_darts2; + + // For each dart of the cell, we modify link of neighbors. + typename std::deque::iterator it = + to_erase.begin(); + for ( ; it!=to_erase.end(); ++it ) { if ( !(*it)->template is_free<0>() ) { @@ -676,7 +667,6 @@ namespace CGAL { } else { - // TODO todegroup.push(Dart_pair((*it)->beta(0), *it)); modified_darts2.push_back((*it)->template beta<0>()); (*it)->template beta<0>()->template unlink_beta<1>(); } @@ -685,28 +675,28 @@ namespace CGAL { { if ( !(*it)->template is_free<1>() ) { - // TODO todegroup.push(Dart_pair((*it)->beta(1), *it)); modified_darts.push_back((*it)->template beta<1>()); (*it)->template beta<1>()->template unlink_beta<0>(); } } } - // We test the split of all the incident cells for all the non - // void attributes. - CMap::Helper::template Foreach_enabled_attributes_except - , 1>:: - run(&amap, modified_darts, modified_darts2); - - // 6) We remove all the darts of the cell. - for (it = to_erase.begin(); it != to_erase.end(); ++it) + // We remove all the darts of the cell. + for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) { amap.erase_dart(*it); } CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); - CGAL_expensive_postcondition( amap.is_valid() ); - assert( amap.is_valid() ); // TO REMOVE + // We test the split of all the incident cells for all the non + // void attributes. + CMap::Helper::template Foreach_enabled_attributes_except + , 1>:: + run(&amap, modified_darts, modified_darts2); + +#ifdef CGAL_CMAP_TEST_VALID_CONTRACTIONS + CGAL_assertion( amap.is_valid() ); +#endif return res; } @@ -719,7 +709,7 @@ namespace CGAL { */ template < class CMap, unsigned int i > size_t contract_cell(CMap& amap, typename CMap::Dart_handle adart) - { return Contract_cell_functor::run(amap,adart); } + { return CGAL::Contract_cell_functor::run(amap,adart); } } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h index 66d56013ac8..661921652c1 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_group_functors.h @@ -21,6 +21,8 @@ #define CGAL_COMBINATORIAL_MAP_GROUP_FUNCTORS_H #include +#include +#include /* Definition of functors used to group/ungroup attributes (we need functors * as attributes are stored in tuple, thus all the access must be done at @@ -51,954 +53,967 @@ */ namespace CGAL { - namespace internal +namespace internal +{ +// ************************************************************************ +/// Functor used for link_beta to update the i-attributes of +/// dh2 on the attributes of dh1 dart, except if i=j. +/// (j is the dimension of the beta modified between dh1 and dh2, +/// so that after the modification we will have beta_j(dh1)==dh2) +/// Only attributes of dh1 or dh2 can be modified. If one dart as its +/// attribute equal to null, it takes the attributes of the second dart. +/// If both attributes are non null, dh2 takes the attribute of dh1. +template::type> +struct Group_attribute_functor_of_dart_run +{ + /// Group the i-attribute of dh1 and dh2. + static void run(CMap* amap, + typename CMap::Dart_handle dh1, + typename CMap::Dart_handle dh2) { - // ************************************************************************ - /// Functor used for link_beta to update the i-attributes of - /// dh2 on the attributes of dh1 dart, except if i=j. - /// (j is the dimension of the beta modified between dh1 and dh2, - /// so that after the modification we will have beta_j(dh1)==dh2) - /// Only attributes of dh1 or dh2 can be modified. If one dart as its - /// attribute equal to null, it takes the attributes of the second dart. - /// If both attributes are non null, dh2 takes the attribute of dh1. - template::type> - struct Group_attribute_functor_of_dart_run + CGAL_static_assertion( 1<=i && i<=CMap::dimension ); + CGAL_static_assertion( i!=j && (i!=1 || j!=0) ); + 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 && + dh1!=CMap::null_dart_handle ); + + typename CMap::template Attribute_handle::type + a1=dh1->template attribute(); + typename CMap::template Attribute_handle::type + a2=dh2->template attribute(); + + // If the two attributes are equal, nothing to do. + if ( a1==a2 ) return; + + if ( a1==NULL ) + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh1, a2); + else + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh2, a1); + } +}; +// Specialization for i=0 and 2<=j. We modify 0-attribute for beta_j j>=2. +template +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(j!=0 && j!=1); + 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::template Attribute_handle<0>::type + a1=NULL, a2=NULL; + + // First extremity + typename CMap::Dart_handle od = dh2->other_extremity(); + if ( od!=NULL ) { - /// Group the i-attribute of dh1 and dh2. - static void run(CMap* amap, - typename CMap::Dart_handle dh1, - typename CMap::Dart_handle dh2) + a1=dh1->template attribute<0>(); + a2=od->template attribute<0>(); + + if ( a1==NULL && a2!=NULL ) { - CGAL_static_assertion( 1<=i && i<=CMap::dimension ); - CGAL_static_assertion( i!=j && (i!=1 || j!=0) ); - 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 && - dh1!=CMap::null_dart_handle ); - - 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; - - if ( a1==NULL ) - Set_i_attribute_of_dart_functor::run(amap, dh1, a2); - else - Set_i_attribute_of_dart_functor::run(amap, dh2, a1); - } - }; - // Specialization for i=0 and 2<=j. We modify 0-attribute for beta_j j>=2. - template - 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(j!=0 && j!=1); - 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(); - if ( od!=NULL ) - { - a1=dh1->template attribute<0>(); - a2=od->template attribute<0>(); - - if ( a1==NULL && a2!=NULL ) - { - Set_i_attribute_of_dart_functor::run(amap, dh1, a2); - } - } - - // Second extremity - od = dh1->other_extremity(); - if ( od!=NULL ) - { - a1=od->template attribute<0>(); - if ( a1!=NULL ) - { - Set_i_attribute_of_dart_functor::run(amap, dh2, a1); - } - } - } - }; - // Specialization for i=0 and j=0. We modify 0-attribute for beta_0. - template - struct Group_attribute_functor_of_dart_run - { - 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 ) - { - 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 ) - { - Set_i_attribute_of_dart_functor::run(amap, dh1, a2); - } - } - } - }; - // Specialization for i=0 and j=1. We modify 0-attribute for beta_1. - template - struct Group_attribute_functor_of_dart_run - { - 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 ) - { - typename CMap::Helper::template Attribute_handle<0>::type - a1=od->template attribute<0>(); - - if ( a1!=NULL ) - { - Set_i_attribute_of_dart_functor::run(amap, dh2, a1); - } - } - } - }; - // Specialization for void attributes. - template - struct Group_attribute_functor_of_dart_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // Specialization for i=j. Do nothing as j is the dimension to not consider. - template - struct Group_attribute_functor_of_dart_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // Specialization for i=1 and j=0. Do nothing as edges attributes are not - // modify when we modify beta_0. - template - struct Group_attribute_functor_of_dart_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // ************************************************************************ - /// Functor used for link_beta to update the attributes of - /// adart2 on the attributes of this dart, except for j-attributes. - /// (j is the dimension of the beta modified between adart1 and adart2, - /// so that after the modification we will have beta_j(adart1)==adart2) - /// 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_of_dart_run. - template - struct Group_attribute_functor_of_dart - { - template - static void run(CMap* amap, - typename CMap::Dart_handle adart1, - typename CMap::Dart_handle 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 - // (j is the dimension of the beta modified between adart1 and adart2). - 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( 1<=i && 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); - } - } - Set_i_attribute_functor::run(amap, toSet, a1); - } - }; - // Specialization for i=0 and 2<=j. We update 0-attributes for beta_j j>=2. - // We need to update both extremities of the edge dh1. - 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 ) - { - Call_merge_functor::run(a1, a2); - } - } - Set_i_attribute_functor::run(amap, 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 ) - { - Call_merge_functor::run(a1, a2); - } - } - Set_i_attribute_functor::run(amap, toSet, a1); - } - } - } - }; - // Specialization for i=0 and j=0. We update 0-attributes for beta_0. - // We need to update the first extremity of the edge dh1. - 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 ) - { - Call_merge_functor::run(a1, a2); - } - } - Set_i_attribute_functor::run(amap, toSet, a1); - } - } - } - }; - // Specialization for i=0 and j=1. We update 0-attributes for beta_1. - // We need to update the second extremity of the edge dh1. - 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 ) - { - Call_merge_functor::run(a1, a2); - } - } - Set_i_attribute_functor::run(amap, toSet, a1); - } - } - } - }; - // Specialization for void attributes. - template - struct Group_attribute_functor_run - { - static void run( CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle ) - {} - }; - // Specialization for i=j. Do nothing as j is the dimension to not consider. - template - struct Group_attribute_functor_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // Specialization for i=1 and j=0. Do nothing as edges attributes are not - // modify when we modify beta_0. - 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. - /// (j is the dimension of the beta modified between adart1 and adart2, - /// so that after the modification we will have beta_j(adart1)==adart2) - /// 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 one i-attribute of one i-cell in two, except the - // attribute of j. - template::type> - struct Degroup_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, - "Degroup_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(); - - // If there is no first attribute, nothing to degroup. - if ( a1==NULL ) return; - - // If the second attribute is non null and equal to a1, nothing to do. - if ( a1!=adart2->template attribute() && - adart2->template attribute()!=NULL ) return; - - CGAL_assertion( (!belong_to_same_cell(*amap, adart1, adart2)) ); - - typename CMap::Helper::template Attribute_handle::type - a2 = amap->template create_attribute(*a1); - - Set_i_attribute_functor::run(amap, adart2, a2); - Call_split_functor::run(a1, a2); - } - }; - // Specialization for void attributes. - template - struct Degroup_attribute_functor_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // Specialization for i==j. - template - struct Degroup_attribute_functor_run - { - static void run(CMap*, - typename CMap::Dart_handle, - typename CMap::Dart_handle) - {} - }; - // ************************************************************************ - // Function used by Test_split_attribute_functor_run to process one dart. - // Test the split of the i-cell containing the given dart adart. - // When we process a dart, we search in the Unique_hash_map if its - // i-attribute was already found. If yes, it means that we already - // found an i-cell with this attribute, thus this attribute is split. - // We mark (with mark) all the darts of the i-cell containing adart to - // process them exactly once. - template - void test_split_attribute_functor_one_dart - ( CMap* amap, typename CMap::Dart_handle adart, - Unique_hash_map::type, - unsigned int> & found_attributes, int mark ) - { - CGAL_assertion( amap!=NULL ); - CGAL_assertion( adart!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index::value>=0, - "Test_split_attribute_functor_one_dart but " - "i-attributes are disabled"); - - typedef typename CMap::Dart_handle Dart_handle; - typedef typename CMap::Helper::template Attribute_handle::type - Attribute_handle_i; - - // If the current dart has no attribute, or if it is aldready marked, - // nothing to do. - if ( adart->template attribute()==NULL || - amap->is_marked(adart, mark) ) - return; - - Attribute_handle_i a1 = adart->template attribute(); - if ( found_attributes.is_defined(a1) ) - { // Here the attribute was already present in the hash_map - Attribute_handle_i a2 = amap->template create_attribute(*a1); - a2->set_dart(adart); - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, adart, mark); itj.cont(); ++itj ) - { - Set_i_attribute_of_dart_functor::run(amap, itj, a2); - amap->mark(itj, mark); - } - Call_split_functor::run(a1, a2); - } - else - { - // Here the attribute was not in the hash_map. - found_attributes[a1]=1; - a1->set_dart(adart); - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, adart, mark); itj.cont(); ++itj ) - { - CGAL_assertion( itj->template attribute()==a1 ); - amap->mark(itj, mark); - } + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh1, a2); } } - // ************************************************************************ - /// Functor used for unsew to test if i-attributes are split after an - /// operation, except for j-attributes. - /// (j is the dimension of the beta modified for darts in modified_darts, - /// if j==0 modified_darts2 are the darts modified for beta_1). - template::type> - struct Test_split_attribute_functor_run + + // Second extremity + od = dh1->other_extremity(); + if ( od!=NULL ) { - // modified_darts is the set of modified darts for beta_j - static void run( CMap* amap, - const std::deque - &modified_darts, - int mark_modified_darts=-1) + a1=od->template attribute<0>(); + if ( a1!=NULL ) { - CGAL_static_assertion( 1<=i && i<=CMap::dimension ); - CGAL_assertion( i!=j ); - CGAL_assertion( amap!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index::value>=0, - "Test_split_attribute_functor_run but " - "i-attributes are disabled"); - - typedef typename CMap::Helper::template Attribute_handle::type - Attribute_handle_i; - - Unique_hash_map found_attributes; - - int mark = amap->get_new_mark(); // to mark incident cells. - typename std::deque::const_iterator - it=modified_darts.begin(); - for ( ; it!=modified_darts.end(); ++it ) - { - test_split_attribute_functor_one_dart - (amap, *it, found_attributes, mark); - } - - // Now we unmark all the marked darts. - amap->negate_mark(mark); - for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it, mark_modified_darts); - - if ( !amap->is_marked(*it, mark) ) - mark_cell(*amap, *it, mark); - } - - CGAL_assertion( amap->is_whole_map_marked(mark) ); - amap->free_mark(mark); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh2, a1); } - static void run( CMap* amap, - const std::deque - &modified_darts, - const std::deque - &modified_darts2, - int mark_modified_darts=-1) + } + } +}; +// Specialization for i=0 and j=0. We modify 0-attribute for beta_0. +template +struct Group_attribute_functor_of_dart_run +{ + 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 ) + { + typename CMap::template Attribute_handle<0>::type + a1=dh1->template attribute<0>(); + typename CMap::template Attribute_handle<0>::type + a2=od->template attribute<0>(); + + if ( a1==NULL && a2!=NULL ) { - CGAL_static_assertion( 1<=i && i<=CMap::dimension ); - CGAL_assertion( i!=j ); - CGAL_assertion( amap!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index::value>=0, - "Test_split_attribute_functor_run but " - "i-attributes are disabled"); - - typedef typename CMap::Helper::template Attribute_handle::type - Attribute_handle_i; - - Unique_hash_map found_attributes; - - int mark = amap->get_new_mark(); // to mark incident cells. - typename std::deque::const_iterator - it=modified_darts.begin(); - for ( ; it!=modified_darts.end(); ++it ) - { - test_split_attribute_functor_one_dart - (amap, *it, found_attributes, mark); - } - typename std::deque::const_iterator - it2=modified_darts2.begin(); - for ( ; it2!=modified_darts2.end(); ++it2 ) - { - test_split_attribute_functor_one_dart - (amap, *it2, found_attributes, mark); - } - - // Now we unmark all the marked darts. - amap->negate_mark(mark); - for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it, mark_modified_darts); - - if ( !amap->is_marked(*it, mark) ) - mark_cell(*amap, *it, mark); - } - for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it2, mark_modified_darts); - - if ( !amap->is_marked(*it2, mark) ) - mark_cell(*amap, *it2, mark); - } - - CGAL_assertion( amap->is_whole_map_marked(mark) ); - amap->free_mark(mark); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh1, a2); } - }; - // Specialization for i=0 and 2<=j. - template - struct Test_split_attribute_functor_run + } + } +}; +// Specialization for i=0 and j=1. We modify 0-attribute for beta_1. +template +struct Group_attribute_functor_of_dart_run +{ + 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 ) { - static void run( CMap* amap, - const std::deque - &modified_darts, - int mark_modified_darts=-1) + typename CMap::template Attribute_handle<0>::type + a1=od->template attribute<0>(); + + if ( a1!=NULL ) { - CGAL_assertion( j!=0 && j!=1 ); - CGAL_assertion( amap!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index<0>::value>=0, - "Test_split_attribute_functor_run<0> but " - "0-attributes are disabled"); - - typedef typename CMap::Helper::template Attribute_handle<0>::type - Attribute_handle_0; - - Unique_hash_map found_attributes; - typename CMap::Dart_handle od=NULL; - - int mark = amap->get_new_mark(); // to mark incident cells. - typename std::deque::const_iterator - it=modified_darts.begin(); - for ( ; it!=modified_darts.end(); ++it ) - { - test_split_attribute_functor_one_dart - (amap, *it, found_attributes, mark); - - od=(*it)->other_extremity(); - if ( od!=NULL ) - test_split_attribute_functor_one_dart - (amap, od, found_attributes, mark); - } - - // Now we unmark all the marked darts. - amap->negate_mark(mark); - for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it, mark_modified_darts); - - if ( !amap->is_marked(*it, mark) ) - mark_cell(*amap, *it, mark); - - od=(*it)->other_extremity(); - if ( od!=NULL && !amap->is_marked(od, mark) ) - mark_cell(*amap, od, mark); - } - - CGAL_assertion( amap->is_whole_map_marked(mark) ); - amap->free_mark(mark); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, dh2, a1); } - static void run( CMap* amap, - const std::deque - &modified_darts, - const std::deque - &modified_darts2, - int mark_modified_darts=-1) + } + } +}; +// Specialization for void attributes. +template +struct Group_attribute_functor_of_dart_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// Specialization for i=j. Do nothing as j is the dimension to not consider. +template +struct Group_attribute_functor_of_dart_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// Specialization for i=1 and j=0. Do nothing as edges attributes are not +// modify when we modify beta_0. +template +struct Group_attribute_functor_of_dart_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// ************************************************************************ +/// Functor used for link_beta to update the attributes of +/// adart2 on the attributes of this dart, except for j-attributes. +/// (j is the dimension of the beta modified between adart1 and adart2, +/// so that after the modification we will have beta_j(adart1)==adart2) +/// 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_of_dart_run. +template +struct Group_attribute_functor_of_dart +{ + template + static void run(CMap* amap, + typename CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) + { + CGAL::internal::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 +// (j is the dimension of the beta modified between adart1 and adart2). +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( 1<=i && 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::template Attribute_handle::type + a1=adart1->template attribute(); + typename CMap::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) { - CGAL_assertion( j!=0 && j!=1 ); - CGAL_assertion( amap!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index<0>::value>=0, - "Test_split_attribute_functor_run<0> but " - "0-attributes are disabled"); - - typedef typename CMap::Helper::template Attribute_handle<0>::type - Attribute_handle_0; - - Unique_hash_map found_attributes; - typename CMap::Dart_handle od=NULL; - - int mark = amap->get_new_mark(); // to mark incident cells. - typename std::deque::const_iterator - it=modified_darts.begin(); - for ( ; it!=modified_darts.end(); ++it ) - { - test_split_attribute_functor_one_dart - (amap, *it, found_attributes, mark); - - od=(*it)->other_extremity(); - if ( od!=NULL ) - test_split_attribute_functor_one_dart - (amap, od, found_attributes, mark); - } - typename std::deque::const_iterator - it2=modified_darts2.begin(); - for ( ; it2!=modified_darts2.end(); ++it2 ) - { - test_split_attribute_functor_one_dart - (amap, *it2, found_attributes, mark); - - od=(*it2)->other_extremity(); - if ( od!=NULL ) - test_split_attribute_functor_one_dart - (amap, od, found_attributes, mark); - } - - // Now we unmark all the marked darts. - amap->negate_mark(mark); - for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it, mark_modified_darts); - - if ( !amap->is_marked(*it, mark) ) - mark_cell(*amap, *it, mark); - - od=(*it)->other_extremity(); - if ( od!=NULL && !amap->is_marked(od, mark) ) - mark_cell(*amap, od, mark); - } - for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it2, mark_modified_darts); - - if ( !amap->is_marked(*it2, mark) ) - mark_cell(*amap, *it2, mark); - - od=(*it2)->other_extremity(); - if ( od!=NULL && !amap->is_marked(od, mark) ) - mark_cell(*amap, od, mark); - } - - CGAL_assertion( amap->is_whole_map_marked(mark) ); - amap->free_mark(mark); + CGAL::internal::Call_merge_functor::run(a1, a2); } - }; - // Specialization for i=0 and j=0. - // For j==0 or j==1, we use only the version with two list of darts, - // modified_darts are darts modified for beta0, and - // modified_darts2 are darts modified for beta1. - template - struct Test_split_attribute_functor_run + } + CGAL::Set_i_attribute_functor::run(amap, toSet, a1); + } +}; +// Specialization for i=0 and 2<=j. We update 0-attributes for beta_j j>=2. +// We need to update both extremities of the edge dh1. +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::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 ) { - static void run( CMap*, const std::deque&, - int =-1) - { CGAL_assertion(false); } - static void run( CMap* amap, - const std::deque - &modified_darts, - const std::deque - &modified_darts2, - int mark_modified_darts=-1) + a1=dh1->template attribute<0>(); + a2=od->template attribute<0>(); + if ( a1!=a2 ) { - CGAL_assertion( amap!=NULL ); - CGAL_static_assertion_msg(CMap::Helper::template - Dimension_index<0>::value>=0, - "Test_split_attribute_functor_run<0> but " - "0-attributes are disabled"); - - typedef typename CMap::Helper::template Attribute_handle<0>::type - Attribute_handle_0; - - Unique_hash_map found_attributes; - typename CMap::Dart_handle od=NULL; - - int mark = amap->get_new_mark(); // to mark incident cells. - typename std::deque::const_iterator - it=modified_darts.begin(); - for ( ; it!=modified_darts.end(); ++it ) + if ( a1==NULL ) + { toSet=dh1; a1=a2; } + else { - test_split_attribute_functor_one_dart - (amap, *it, found_attributes, mark); + toSet=od; + if ( a2!=NULL ) + { + CGAL::internal::Call_merge_functor::run(a1, a2); + } } - typename std::deque::const_iterator - it2=modified_darts2.begin(); - for ( ; it2!=modified_darts2.end(); ++it2 ) - { - od=(*it2)->other_extremity(); - if ( od!=NULL ) - test_split_attribute_functor_one_dart - (amap, od, found_attributes, mark); - } - - // Now we unmark all the marked darts. - amap->negate_mark(mark); - for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it, mark_modified_darts); - - if ( !amap->is_marked(*it, mark) ) - mark_cell(*amap, *it, mark); - } - for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) - { - if ( mark_modified_darts!=-1 ) - amap->unmark(*it2, mark_modified_darts); - - od=(*it2)->other_extremity(); - if ( od!=NULL && !amap->is_marked(od, mark) ) - mark_cell(*amap, od, mark); - } - - CGAL_assertion( amap->is_whole_map_marked(mark) ); - amap->free_mark(mark); + CGAL::Set_i_attribute_functor::run(amap, toSet, a1); } - }; - // Specialization for i=0 and j=1. - // Equivalent to i=0 and j=0. - template - struct Test_split_attribute_functor_run + } + // Second extremity + od = dh1->other_extremity(); + if ( od!=NULL ) { - static void run( CMap*, const std::deque&, - int =-1) - { CGAL_assertion(false); } - static void run( CMap* amap, const std::deque& - modified_darts, - const std::deque& - modified_darts2, int mark_modified_darts=-1) - { Test_split_attribute_functor_run:: - run(amap, modified_darts, modified_darts2, mark_modified_darts); } - }; - // Specialization for void attributes. - template - struct Test_split_attribute_functor_run - { - static void run( CMap*, const std::deque&, - int=-1) - {} - static void run( CMap*, const std::deque&, - const std::deque&, int=-1) - {} - }; - // Specialization for i=j. - template - struct Test_split_attribute_functor_run - { - static void run( CMap*, const std::deque&, - int=-1) - {} - static void run( CMap*, const std::deque&, - const std::deque&, int=-1) - {} - }; - // Specialization for i=1 and j=0 (edge attributes are not modified - // when we modify beta_0). - template - struct Test_split_attribute_functor_run - { - static void run( CMap*, const std::deque&, - int=-1) - {} - static void run( CMap*, const std::deque&, - const std::deque&, int=-1) - {} - }; - // ************************************************************************ - /// Functor used for unsew to test if i-attributes are split after an - /// operation, except for j-attributes. - /// We define run to allows to use this functor with - /// Foreach_enabled_attributes. - template - struct Test_split_attribute_functor - { - // Test the split of i-attributes, for all modified darts given in - // modified_darts, and marked with mark_modified_darts. - // For each split attribute, create a new i-attribute, associate - // it with the new i-cell and call onsplit functors. - template - static void run( CMap* amap, - const std::deque - &modified_darts, - int mark_modified_darts=-1) + a1=od->template attribute<0>(); + a2=dh2->template attribute<0>(); + if ( a1!=a2 ) { - Test_split_attribute_functor_run::run(amap, modified_darts, - mark_modified_darts); + if ( a1==NULL ) + { toSet=od; a1=a2; } + else + { + toSet=dh2; + if ( a2!=NULL ) + { + CGAL::internal::Call_merge_functor::run(a1, a2); + } + } + CGAL::Set_i_attribute_functor::run(amap, toSet, a1); } - template - static void run( CMap* amap, - const std::deque - &modified_darts, - const std::deque - &modified_darts2, - int mark_modified_darts=-1) + } + } +}; +// Specialization for i=0 and j=0. We update 0-attributes for beta_0. +// We need to update the first extremity of the edge dh1. +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::template Attribute_handle<0>::type + a1=dh1->template attribute<0>(); + typename CMap::template Attribute_handle<0>::type + a2=od->template attribute<0>(); + if ( a1!=a2 ) { - Test_split_attribute_functor_run::run(amap, modified_darts, - modified_darts2, - mark_modified_darts); + if ( a1==NULL ) + { toSet=dh1; a1=a2; } + else + { + toSet=od; + if ( a2!=NULL ) + { + CGAL::internal::Call_merge_functor::run(a1, a2); + } + } + CGAL::Set_i_attribute_functor::run(amap, toSet, a1); } - }; - // ************************************************************************ - } // namespace internal + } + } +}; +// Specialization for i=0 and j=1. We update 0-attributes for beta_1. +// We need to update the second extremity of the edge dh1. +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::template Attribute_handle<0>::type + a1=od->template attribute<0>(); + typename CMap::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 ) + { + CGAL::internal::Call_merge_functor::run(a1, a2); + } + } + CGAL::Set_i_attribute_functor::run(amap, toSet, a1); + } + } + } +}; +// Specialization for void attributes. +template +struct Group_attribute_functor_run +{ + static void run( CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle ) + {} +}; +// Specialization for i=j. Do nothing as j is the dimension to not consider. +template +struct Group_attribute_functor_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// Specialization for i=1 and j=0. Do nothing as edges attributes are not +// modify when we modify beta_0. +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. +/// (j is the dimension of the beta modified between adart1 and adart2, +/// so that after the modification we will have beta_j(adart1)==adart2) +/// 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) + { CGAL::internal::Group_attribute_functor_run:: + run(amap,adart1,adart2); } +}; +// ************************************************************************ +// Functor used to degroup one i-attribute of one i-cell in two, except the +// attribute of j. +template::type> +struct Degroup_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, + "Degroup_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::template Attribute_handle::type + a1=adart1->template attribute(); + + // If there is no first attribute, nothing to degroup. + if ( a1==NULL ) return; + + // If the second attribute is non null and already different from a1, + // nothing to do. + if ( a1!=adart2->template attribute() && + adart2->template attribute()!=NULL ) return; + + CGAL_assertion( (!CGAL::belong_to_same_cell + (*amap, adart1, adart2)) ); + + // As we split, we set the dart of the first attribute to adart1 for which + // we are sure it belongs to the first i-cell. + a1->set_dart(adart1); + + typename CMap::template Attribute_handle::type + a2 = amap->template create_attribute(*a1); + + CGAL::Set_i_attribute_functor::run(amap, adart2, a2); + CGAL::internal::Call_split_functor::run(a1, a2); + } +}; +// Specialization for void attributes. +template +struct Degroup_attribute_functor_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// Specialization for i==j. +template +struct Degroup_attribute_functor_run +{ + static void run(CMap*, + typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// ************************************************************************ +// Function used by Test_split_attribute_functor_run to process one dart. +// Test the split of the i-cell containing the given dart adart. +// When we process a dart, we search in the Unique_hash_map if its +// i-attribute was already found. If yes, it means that we already +// found an i-cell with this attribute, thus this attribute is split. +// We mark (with mark) all the darts of the i-cell containing adart to +// process them exactly once. +template +void test_split_attribute_functor_one_dart +( CMap* amap, typename CMap::Dart_handle adart, + CGAL::Unique_hash_map::type, + unsigned int> & found_attributes, int mark ) +{ + CGAL_assertion( amap!=NULL ); + CGAL_assertion( adart!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index::value>=0, + "Test_split_attribute_functor_one_dart but " + "i-attributes are disabled"); + + typedef typename CMap::Dart_handle Dart_handle; + typedef typename CMap::template Attribute_handle::type + Attribute_handle_i; + + // If the current dart has no attribute, or if it is aldready marked, + // nothing to do. + if ( adart->template attribute()==NULL || + amap->is_marked(adart, mark) ) + return; + + Attribute_handle_i a1 = adart->template attribute(); + if ( found_attributes.is_defined(a1) ) + { // Here the attribute was already present in the hash_map + Attribute_handle_i a2 = amap->template create_attribute(*a1); + + for ( CGAL::CMap_dart_iterator_basic_of_cell + itj(*amap, adart, mark); itj.cont(); ++itj ) + { + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, itj, a2); + amap->mark(itj, mark); + } + CGAL::internal::Call_split_functor::run(a1, a2); + } + else + { + // Here the attribute was not in the hash_map. + found_attributes[a1]=1; + a1->set_dart(adart); + + for ( CGAL::CMap_dart_iterator_basic_of_cell + itj(*amap, adart, mark); itj.cont(); ++itj ) + { + CGAL_assertion( itj->template attribute()==a1 ); + amap->mark(itj, mark); + } + } +} +// ************************************************************************ +/// Functor used for unsew to test if i-attributes are split after an +/// operation, except for j-attributes. +/// (j is the dimension of the beta modified for darts in modified_darts, +/// if j==0 modified_darts2 are the darts modified for beta_1). +template::type> +struct Test_split_attribute_functor_run +{ + // modified_darts is the set of modified darts for beta_j + static void run( CMap* amap, + const std::deque + &modified_darts, + int mark_modified_darts=-1) + { + CGAL_static_assertion( 1<=i && i<=CMap::dimension ); + CGAL_assertion( i!=j ); + CGAL_assertion( amap!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index::value>=0, + "Test_split_attribute_functor_run but " + "i-attributes are disabled"); + + typedef typename CMap::template Attribute_handle::type + Attribute_handle_i; + + CGAL::Unique_hash_map + found_attributes; + + int mark = amap->get_new_mark(); // to mark incident cells. + typename std::deque::const_iterator + it=modified_darts.begin(); + for ( ; it!=modified_darts.end(); ++it ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it, found_attributes, mark); + } + + // Now we unmark all the marked darts. + amap->negate_mark(mark); + for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + CGAL::mark_cell(*amap, *it, mark); + } + + CGAL_assertion( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + } + static void run( CMap* amap, + const std::deque + &modified_darts, + const std::deque + &modified_darts2, + int mark_modified_darts=-1) + { + CGAL_static_assertion( 1<=i && i<=CMap::dimension ); + CGAL_assertion( i!=j ); + CGAL_assertion( amap!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index::value>=0, + "Test_split_attribute_functor_run but " + "i-attributes are disabled"); + + typedef typename CMap::template Attribute_handle::type + Attribute_handle_i; + + CGAL::Unique_hash_map found_attributes; + + int mark = amap->get_new_mark(); // to mark incident cells. + typename std::deque::const_iterator + it=modified_darts.begin(); + for ( ; it!=modified_darts.end(); ++it ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it, found_attributes, mark); + } + typename std::deque::const_iterator + it2=modified_darts2.begin(); + for ( ; it2!=modified_darts2.end(); ++it2 ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it2, found_attributes, mark); + } + + // Now we unmark all the marked darts. + amap->negate_mark(mark); + for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + CGAL::mark_cell(*amap, *it, mark); + } + for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it2, mark_modified_darts); + + if ( !amap->is_marked(*it2, mark) ) + CGAL::mark_cell(*amap, *it2, mark); + } + + CGAL_assertion( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + } +}; +// Specialization for i=0 and 2<=j. +template +struct Test_split_attribute_functor_run +{ + static void run( CMap* amap, + const std::deque + &modified_darts, + int mark_modified_darts=-1) + { + CGAL_assertion( j!=0 && j!=1 ); + CGAL_assertion( amap!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Test_split_attribute_functor_run<0> but " + "0-attributes are disabled"); + + typedef typename CMap::template Attribute_handle<0>::type + Attribute_handle_0; + + CGAL::Unique_hash_map + found_attributes; + typename CMap::Dart_handle od=NULL; + + int mark = amap->get_new_mark(); // to mark incident cells. + typename std::deque::const_iterator + it=modified_darts.begin(); + for ( ; it!=modified_darts.end(); ++it ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it, found_attributes, mark); + + od=(*it)->other_extremity(); + if ( od!=NULL ) + CGAL::internal::test_split_attribute_functor_one_dart + (amap, od, found_attributes, mark); + } + + // Now we unmark all the marked darts. + amap->negate_mark(mark); + for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + CGAL::mark_cell(*amap, *it, mark); + + od=(*it)->other_extremity(); + if ( od!=NULL && !amap->is_marked(od, mark) ) + CGAL::mark_cell(*amap, od, mark); + } + + CGAL_assertion( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + } + static void run( CMap* amap, + const std::deque + &modified_darts, + const std::deque + &modified_darts2, + int mark_modified_darts=-1) + { + CGAL_assertion( j!=0 && j!=1 ); + CGAL_assertion( amap!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Test_split_attribute_functor_run<0> but " + "0-attributes are disabled"); + + typedef typename CMap::template Attribute_handle<0>::type + Attribute_handle_0; + + CGAL::Unique_hash_map + found_attributes; + typename CMap::Dart_handle od=NULL; + + int mark = amap->get_new_mark(); // to mark incident cells. + typename std::deque::const_iterator + it=modified_darts.begin(); + for ( ; it!=modified_darts.end(); ++it ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it, found_attributes, mark); + + od=(*it)->other_extremity(); + if ( od!=NULL ) + CGAL::internal::test_split_attribute_functor_one_dart + (amap, od, found_attributes, mark); + } + typename std::deque::const_iterator + it2=modified_darts2.begin(); + for ( ; it2!=modified_darts2.end(); ++it2 ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it2, found_attributes, mark); + + od=(*it2)->other_extremity(); + if ( od!=NULL ) + CGAL::internal::test_split_attribute_functor_one_dart + (amap, od, found_attributes, mark); + } + + // Now we unmark all the marked darts. + amap->negate_mark(mark); + for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + CGAL::mark_cell(*amap, *it, mark); + + od=(*it)->other_extremity(); + if ( od!=NULL && !amap->is_marked(od, mark) ) + CGAL::mark_cell(*amap, od, mark); + } + for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it2, mark_modified_darts); + + if ( !amap->is_marked(*it2, mark) ) + CGAL::mark_cell(*amap, *it2, mark); + + od=(*it2)->other_extremity(); + if ( od!=NULL && !amap->is_marked(od, mark) ) + CGAL::mark_cell(*amap, od, mark); + } + + CGAL_assertion( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + } +}; +// Specialization for i=0 and j=0. +// For j==0 or j==1, we use only the version with two list of darts, +// modified_darts are darts modified for beta0, and +// modified_darts2 are darts modified for beta1. +template +struct Test_split_attribute_functor_run +{ + static void run( CMap*, const std::deque&, + int =-1) + { CGAL_assertion(false); } + static void run( CMap* amap, + const std::deque + &modified_darts, + const std::deque + &modified_darts2, + int mark_modified_darts=-1) + { + CGAL_assertion( amap!=NULL ); + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index<0>::value>=0, + "Test_split_attribute_functor_run<0> but " + "0-attributes are disabled"); + + typedef typename CMap::template Attribute_handle<0>::type + Attribute_handle_0; + + CGAL::Unique_hash_map + found_attributes; + typename CMap::Dart_handle od=NULL; + + int mark = amap->get_new_mark(); // to mark incident cells. + typename std::deque::const_iterator + it=modified_darts.begin(); + for ( ; it!=modified_darts.end(); ++it ) + { + CGAL::internal::test_split_attribute_functor_one_dart + (amap, *it, found_attributes, mark); + } + typename std::deque::const_iterator + it2=modified_darts2.begin(); + for ( ; it2!=modified_darts2.end(); ++it2 ) + { + od=(*it2)->other_extremity(); + if ( od!=NULL ) + CGAL::internal::test_split_attribute_functor_one_dart + (amap, od, found_attributes, mark); + } + + // Now we unmark all the marked darts. + amap->negate_mark(mark); + for ( it=modified_darts.begin(); it!=modified_darts.end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + CGAL::mark_cell(*amap, *it, mark); + } + for ( it2=modified_darts2.begin(); it2!=modified_darts2.end(); ++it2 ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it2, mark_modified_darts); + + od=(*it2)->other_extremity(); + if ( od!=NULL && !amap->is_marked(od, mark) ) + CGAL::mark_cell(*amap, od, mark); + } + + CGAL_assertion( amap->is_whole_map_marked(mark) ); + amap->free_mark(mark); + } +}; +// Specialization for i=0 and j=1. +// Equivalent to i=0 and j=0. +template +struct Test_split_attribute_functor_run +{ + static void run( CMap*, const std::deque&, + int =-1) + { CGAL_assertion(false); } + static void run( CMap* amap, const std::deque& + modified_darts, + const std::deque& + modified_darts2, int mark_modified_darts=-1) + { CGAL::internal::Test_split_attribute_functor_run:: + run(amap, modified_darts, modified_darts2, mark_modified_darts); } +}; +// Specialization for void attributes. +template +struct Test_split_attribute_functor_run +{ + static void run( CMap*, const std::deque&, + int=-1) + {} + static void run( CMap*, const std::deque&, + const std::deque&, int=-1) + {} +}; +// Specialization for i=j. +template +struct Test_split_attribute_functor_run +{ + static void run( CMap*, const std::deque&, + int=-1) + {} + static void run( CMap*, const std::deque&, + const std::deque&, int=-1) + {} +}; +// Specialization for i=1 and j=0 (edge attributes are not modified +// when we modify beta_0). +template +struct Test_split_attribute_functor_run +{ + static void run( CMap*, const std::deque&, + int=-1) + {} + static void run( CMap*, const std::deque&, + const std::deque&, int=-1) + {} +}; +// ************************************************************************ +/// Functor used for unsew to test if i-attributes are split after an +/// operation, except for j-attributes. +/// We define run to allows to use this functor with +/// Foreach_enabled_attributes. +template +struct Test_split_attribute_functor +{ + // Test the split of i-attributes, for all modified darts given in + // modified_darts, and marked with mark_modified_darts. + // For each split attribute, create a new i-attribute, associate + // it with the new i-cell and call onsplit functors. + template + static void run( CMap* amap, + const std::deque + &modified_darts, + int mark_modified_darts=-1) + { + CGAL::internal::Test_split_attribute_functor_run:: + run(amap, modified_darts, mark_modified_darts); + } + template + static void run( CMap* amap, + const std::deque + &modified_darts, + const std::deque + &modified_darts2, + int mark_modified_darts=-1) + { + CGAL::internal::Test_split_attribute_functor_run:: + run(amap, modified_darts, modified_darts2, mark_modified_darts); + } +}; +// ************************************************************************ +} // namespace internal } // namespace CGAL #endif // CGAL_COMBINATORIAL_MAP_GROUP_FUNCTORS_H diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h new file mode 100644 index 00000000000..c5c2f86f8d1 --- /dev/null +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -0,0 +1,390 @@ +// Copyright (c) 2010-2011 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_COMBINATORIAL_MAP_INTERNAL_FUNCTORS_H +#define CGAL_COMBINATORIAL_MAP_INTERNAL_FUNCTORS_H + +#include +#include +#include + +/* Definition of functors used internally to manage attributes (we need + * functors as attributes are stored in tuple, thus all the access must be + * done at compiling time). Some of these functors are used with + * Foreach_enabled_attributes to iterate through all the non void attribs. + * Functors allowing to group/ungroup attributes are defined in + * internal/Combinatorial_map_group_functors.h. Public functions are defined + * in Combinatorial_map_functors.h. + * + * internal::Call_split_functor to call the OnSplit functors on two + * given i-attributes. + * + * internal::Call_merge_functor to call the OnMerge functors on two + * given i-attributes. + * + * internal::Test_is_valid_attribute_functor to test if a given i-cell is + * valid (all its darts are linked to the same attribute, no other dart is + * linked with this attribute). + * + * internal::Count_cell_functor to count the nuber of i-cells. + * + * internal::Count_bytes_one_attribute_functor to count the memory + * occupied by i-attributes. + * + * internal::Decrease_attribute_functor to decrease by one the ref + * counting of a given i-attribute. + * + * internal::Beta_functor to call several beta on the given dart. + * Indices are given as parameter of the run function. + * + * internal::Beta_functor_static to call several beta on the given + * dart. Indices are given as template arguments. + * + * internal::Set_i_attribute_of_dart_functor to set the i-attribute + * of a given dart. + */ + +namespace CGAL +{ +// **************************************************************************** +namespace internal +{ +// 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 CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) + { + CGAL::internal::Apply_cell_functor + ::type, + typename CMap::template Attribute_type::type::On_split>:: + run(*(adart1->template attribute()), + *(adart2->template attribute())); + } + static void + run(typename CMap::template Attribute_handle::type a1, + typename CMap::template Attribute_handle::type a2) + { + CGAL::internal::Apply_cell_functor + ::type, + typename CMap::template Attribute_type::type::On_split>:: + run(*a1, *a2); + } +}; +// Specialization for disabled attributes. +template +struct Call_split_functor +{ + 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 CMap::Dart_handle adart1, + typename CMap::Dart_handle adart2) + { + CGAL::internal::Apply_cell_functor + ::type, + typename CMap::template Attribute_type::type::On_merge>:: + run(*(adart1->template attribute()), + *(adart2->template attribute())); + } + static void + run(typename CMap::template Attribute_handle::type a1, + typename CMap::template Attribute_handle::type a2) + { + CGAL::internal::Apply_cell_functor + ::type, + typename CMap::template Attribute_type::type::On_merge>:: + run(*a1, *a2); + } +}; +// Specialization for disabled attributes. +template +struct Call_merge_functor +{ + static void run(typename CMap::Dart_handle, + typename CMap::Dart_handle) + {} +}; +// **************************************************************************** +/// Functor used to test if a cell is valid +template +struct Test_is_valid_attribute_functor +{ + /** 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. + * @param amark a mark used to mark darts of the i-cell. + * @return true iff all the darts of the i-cell link to the same attribute. + */ + template + static void run(const CMap* amap, + typename CMap::Dart_const_handle adart, + std::vector* marks, bool *ares) + { + CGAL_static_assertion_msg(CMap::Helper::template + Dimension_index::value>=0, + "Test_is_valid_attribute_functor but " + " i-attributes are disabled"); + + int amark = (*marks)[i]; + if ( amap->is_marked(adart, amark) ) return; // dart already test. + + bool valid = true; + bool found_dart = false; + + typename CMap::template Attribute_const_handle::type + a=adart->template attribute(); + + unsigned int nb = 0; + for ( CGAL::CMap_dart_const_iterator_basic_of_cell + it(*amap, adart, amark); it.cont(); ++it ) + { + if ( it->template attribute() != a ) + { + std::cout<<"ERROR: an attribute of the "<template attribute() + <<" for dart "<<&*it<dart() ) found_dart=true; + + amap->mark(it, amark); + ++nb; + } + + if ( a!=NULL ) + { + if ( a->get_nb_refs()!=nb ) + { + std::cout<<"ERROR: the number of reference of an "<get_nb_refs()<<" for dart " + <<&*adart<is_valid() ) + { + std::cout<<"ERROR: the dart associated with an "<dart()!=NULL && !found_dart ) + { + std::cout<<"ERROR: the non NULL dart of an "<dart()= " + <<&*a->dart()<<" for dart "<<&*adart< +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]; + CGAL::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 ) + { + CGAL::internal::Count_bytes_one_attribute_functor::res = 0; + CMap::Helper::template Foreach_enabled_attributes + >::run(&amap); + return CGAL::internal::Count_bytes_one_attribute_functor::res; + } +}; +// **************************************************************************** +/// Decrease the cell attribute reference counting of the given dart. +/// The attribute is removed if there is no more darts linked with it. +template::type> +struct Decrease_attribute_functor_run +{ + static void run(CMap* amap, typename CMap::Dart_handle adart) + { + if ( adart->template attribute()!=NULL ) + { + adart->template attribute()->dec_nb_refs(); + if ( adart->template attribute()->get_nb_refs()==0 ) + amap->template erase_attribute(adart->template attribute()); + } + } +}; +/// Specialization for void attributes. +template +struct Decrease_attribute_functor_run +{ + static void run(CMap*, typename CMap::Dart_handle) + {} +}; +// **************************************************************************** +/// 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) + { CGAL::internal::Decrease_attribute_functor_run::run(amap, adart); } +}; +// **************************************************************************** +/// Functor used to set the i-attribute of a given dart. +template::type> +struct Set_i_attribute_of_dart_functor +{ + static void run( CMap* amap, typename CMap::Dart_handle dh, + typename CMap::template Attribute_handle::type ah ) + { + CGAL_static_assertion(i<=CMap::dimension); + CGAL_assertion( dh!=NULL && dh!=CMap::null_dart_handle ); + + if ( dh->template attribute()==ah ) return; + + CGAL::internal::Decrease_attribute_functor_run::run(amap, dh); + dh->template set_attribute(ah); + if ( ah!=NULL ) ah->set_dart(dh); + } +}; +/// Specialization for void attributes. +template +struct Set_i_attribute_of_dart_functor +{ + static void run( CMap*, typename CMap::Dart_handle, + typename CMap::template Attribute_handle::type) + {} +}; +// **************************************************************************** +// Beta functor, used to combine several beta. +#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES +template +struct Beta_functor; +template +struct Beta_functor +{ + static Dart_handle run(Dart_handle ADart, int B, Betas... betas) + { return Beta_functor::run(ADart->beta(B), + betas...); } +}; +template +struct Beta_functor +{ + static Dart_handle run(Dart_handle ADart, int B) + { + CGAL_assertion( ADart!=NULL ); + return ADart->beta(B); + } +}; +// **************************************************************************** +template +struct Beta_functor_static; +template +struct Beta_functor_static +{ + static Dart_handle run(Dart_handle ADart) + { return Beta_functor_static:: + run(ADart->template beta()); } +}; +template +struct Beta_functor_static +{ + static Dart_handle run(Dart_handle ADart) + { + CGAL_assertion( ADart!=NULL ); + return ADart->template beta(); + } +}; +#endif //CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES +// **************************************************************************** +} // namespace internal +} // namespace CGAL + +#endif // CGAL_COMBINATORIAL_MAP_INTERNAL_FUNCTORS_H diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_sewable.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_sewable.h index 5bdcc58e236..c0d08e300a4 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_sewable.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_sewable.h @@ -49,8 +49,8 @@ struct Is_sewable_functor // TODO use a map (of hashtable) to build the isomorphism and to test // it during the while loop - CMap_dart_const_iterator_of_involution I1(*amap, adart1); - CMap_dart_const_iterator_of_involution_inv I2(*amap, adart2); + CGAL::CMap_dart_const_iterator_of_involution I1(*amap, adart1); + CGAL::CMap_dart_const_iterator_of_involution_inv I2(*amap, adart2); bool res = true; while (res && I1.cont() && I2.cont()) { @@ -102,8 +102,8 @@ struct Is_sewable_functor // TODO use a map (of hashtable) to build the isomorphism and to test // it during the while loop - CMap_dart_const_iterator_of_involution I1(*amap, adart1); - CMap_dart_const_iterator_of_involution_inv I2(*amap, adart2); + CGAL::CMap_dart_const_iterator_of_involution I1(*amap, adart1); + CGAL::CMap_dart_const_iterator_of_involution_inv I2(*amap, adart2); bool res = true; while (res && I1.cont() && I2.cont()) { @@ -324,8 +324,8 @@ struct Is_sewable_functor !adart2->template is_free<3>() ) return false; - CMap_dart_const_iterator_basic_of_orbit I1(*amap, adart1); - CMap_dart_const_iterator_basic_of_orbit I2(*amap, adart2); + CGAL::CMap_dart_const_iterator_basic_of_orbit I1(*amap, adart1); + CGAL::CMap_dart_const_iterator_basic_of_orbit I2(*amap, adart2); bool res=true; while (res && I1.cont() && I2.cont()) { diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index bf8687135e5..528bc704e9b 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -11,11 +11,20 @@ else() cmake_policy(VERSION 2.6) endif() +## To add expensive tests # add_definitions("-DCGAL_CHECK_EXPENSIVE") -# For profilling with gprof -add_definitions("-pg") -SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") +## For profilling with gprof +# add_definitions("-pg") +# SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") + +## To add an is_valid test after each operation (only in debug mode) +add_definitions("-DCGAL_CMAP_TEST_VALID_REMOVALS") +add_definitions("-DCGAL_CMAP_TEST_VALID_CONTRACTIONS") +#add_definitions("-DCGAL_CMAP_TEST_VALID_INSERTIONS") + +# Option allowing to profile each operation of the demo (cout times on stdout). +add_definitions(-DCGAL_PROFILE_LCC_DEMO) ################## find_package(CGAL COMPONENTS Qt4) @@ -42,9 +51,6 @@ include(${QT_USE_FILE}) include_directories(${QGLVIEWER_INCLUDE_DIR}) include_directories(BEFORE . ../../include/) -# Option allowing to profile each operation of the demo. -add_definitions(-DCGAL_PROFILE_LCC_DEMO) - # ui file, created wih Qt Designer qt4_wrap_ui(uis MainWindow.ui CreateMesh.ui CreateMenger.ui) diff --git a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_pqq_subdivision.cpp b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_pqq_subdivision.cpp index 57e29847147..c4bfe7991f3 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_pqq_subdivision.cpp +++ b/Linear_cell_complex/demo/Linear_cell_complex/Linear_cell_complex_pqq_subdivision.cpp @@ -18,6 +18,7 @@ // Author(s) : Guillaume Damiand // Jérémy Girerd-Rey // + #include "typedefs.h" // Smooth a vertex depending on the vertices of its incidents facets. @@ -283,8 +284,7 @@ subdivide_lcc_pqq (LCC & m) CGAL::remove_cell(m, *dit); } remove.resize(0); - CGAL_assertion( m.is_valid() ); - + // CGAL_assertion( m.is_valid() ); } } diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index bf04d007268..6970ce1397e 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -70,16 +70,15 @@ namespace CGAL { typedef typename Base::Dart_range Dart_range; - typedef typename Helper::template Attribute_type<0>::type - Vertex_attribute; - typedef typename Helper::template Attribute_handle<0>::type + typedef typename Base::template Attribute_type<0>::type Vertex_attribute; + typedef typename Base::template Attribute_handle<0>::type Vertex_attribute_handle; - typedef typename Helper::template Attribute_const_handle<0>::type + typedef typename Base::template Attribute_const_handle<0>::type Vertex_attribute_const_handle; - typedef typename Helper::template Attribute_range<0>::type + typedef typename Base::template Attribute_range<0>::type Vertex_attribute_range; - typedef typename Helper::template Attribute_const_range<0>::type + typedef typename Base::template Attribute_const_range<0>::type Vertex_attribute_const_range; /// To use previous definition of create_dart methods. @@ -89,7 +88,7 @@ namespace CGAL { * @return an handle on the new attribute. */ #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES - template + template Vertex_attribute_handle create_vertex_attribute(const Args&... args) { return Base::template create_attribute<0>(args...); } #else @@ -184,7 +183,7 @@ namespace CGAL { void set_vertex_attribute_of_dart(Dart_handle adart, Vertex_attribute_handle ah) { - return internal::Set_i_attribute_of_dart_functor:: + return CGAL::internal::Set_i_attribute_of_dart_functor:: run(this, adart,ah); } @@ -194,7 +193,7 @@ namespace CGAL { */ void set_vertex_attribute(Dart_handle adart, Vertex_attribute_handle ah) - { return Set_i_attribute_functor::run(this, adart,ah); } + { return CGAL::Set_i_attribute_functor::run(this, adart,ah); } /// @return the Vertex_attribute_range for all vertex_attributes. Vertex_attribute_range& vertex_attributes() @@ -614,8 +613,8 @@ namespace CGAL { unsigned int nb = 1; // TODO: test if we can optimize by using ? - CMap_one_dart_per_incident_cell_const_iterator it(*this, - adart); + CGAL::CMap_one_dart_per_incident_cell_const_iterator + it(*this, adart); for ( ++it; it.cont(); ++it) { vec = typename Traits::Construct_sum_of_vectors() @@ -675,7 +674,8 @@ namespace CGAL { * @param p the coordinates of the new vertex. * @return a dart of the new edge, incident to the new vertex. */ - Dart_handle insert_dangling_cell_1_in_cell_2(Dart_handle dh, const Point& p) + Dart_handle insert_dangling_cell_1_in_cell_2(Dart_handle dh, + const Point& p) { return CGAL::insert_dangling_cell_1_in_cell_2 (*this, dh, create_vertex_attribute(p));