From 5be11826cb26bad76991191919846224041a15df Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 30 Jan 2013 22:01:36 +0100 Subject: [PATCH] Onsplit: it seems ok now. --- .../CGAL/Combinatorial_map_operations.h | 182 ++++++++++----- Combinatorial_map/include/CGAL/Dart.h | 26 +-- .../internal/Combinatorial_map_functors.h | 213 ++++++++++-------- 3 files changed, 246 insertions(+), 175 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index a1820964817..cea15596104 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -221,11 +221,15 @@ namespace CGAL { CGAL_static_assertion ( 1<=i && i(amap, adart)) ); + size_t res = 0; + typename Map::Dart_handle d1, d2; + typename Map::Dart_handle dg1=NULL, dg2=NULL; + int mark = amap.get_new_mark(); int mark_modified_darts = amap.get_new_mark(); + std::deque to_erase; - typename Map::Dart_handle dg1=NULL, dg2=NULL; const int iinv = CGAL_BETAINV(i); @@ -241,7 +245,6 @@ namespace CGAL { }*/ // First we store and mark all the darts of the i-cell to remove. - size_t res = 0; for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); it.cont(); ++it ) { @@ -324,16 +327,15 @@ namespace CGAL { amap.update_dart_of_all_attributes(*it, mark); }*/ - //for (; it != to_erase.end(); ++it) - // amap.update_dart_of_all_attributes(*it, mark); + for (; it != to_erase.end(); ++it) + amap.update_dart_of_all_attributes(*it, mark); // We group the two (i+1)-cells incident if they exist. if ( dg1!=NULL ) amap.template group_attribute(dg1, dg2); - //amap.update_dart_of_all_attributes(adart, mark); - std::deque modified_darts; + // std::deque modified_darts2; // For each dart of the i-cell, we modify i-links of neighbors. for ( it=to_erase.begin(); it != to_erase.end(); ++it) @@ -367,10 +369,10 @@ namespace CGAL { modified_darts.push_back(d1); modified_darts.push_back(d2); /*if ( i==1 ) - { - d2->basic_link_beta(d1, 0); - // modified_darts2.push_back(d2); - }*/ + { + d2->basic_link_beta(d1, 0); + modified_darts.push_back(d2); + }*/ // modified_darts2.push_back(d1); } else @@ -412,9 +414,10 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. Map::Helper::template Foreach_enabled_attributes - >:: + >:: // >:: run(&amap, &modified_darts, mark_modified_darts); + //&modified_darts2); //&mark_for_incident_cells[0], &incident_cells[0]); // We remove all the darts of the i-cell. @@ -430,6 +433,10 @@ namespace CGAL { iterator it=modified_darts.begin(); it!=modified_darts.end(); ++it ) amap.unmark(*it, mark_modified_darts); + /*for ( typename std::deque:: + iterator it=modified_darts2.begin(); + it!=modified_darts2.end(); ++it ) + amap.unmark(*it, mark_modified_darts);*/ } CGAL_assertion ( amap.is_whole_map_unmarked(mark_modified_darts) ); @@ -462,11 +469,13 @@ namespace CGAL { { CGAL_assertion( adart!=NULL ); + int mark = amap.get_new_mark(); std::deque to_erase; - int mark = amap.get_new_mark(); size_t res = 0; - int mark_for_incident_cells[Map::Helper::nb_attribs]; + std::deque modified_darts; + +/* int mark_for_incident_cells[Map::Helper::nb_attribs]; std::deque > incident_cells[Map::Helper::nb_attribs]; @@ -476,6 +485,7 @@ namespace CGAL { mark_for_incident_cells[j] = amap.get_new_mark(); CGAL_assertion( mark_for_incident_cells[j]!=-1 ); } +*/ // 1) We mark all the darts of the d-cell. for (CMap_dart_iterator_basic_of_cell @@ -491,7 +501,7 @@ namespace CGAL { // 2) We store all the incident cells that can be split by the operation, // and we update the dart of the cells incident to the remove volume. - for ( ; it != to_erase.end(); ++it ) +/* for ( ; it != to_erase.end(); ++it ) { if ( !(*it)->is_free(Map::dimension) ) { @@ -501,23 +511,28 @@ namespace CGAL { &incident_cells[0]); } amap.update_dart_of_all_attributes(*it, mark); - } + }*/ + // 3) We unlink all the darts of the volume for beta-d. for ( it = to_erase.begin(); it != to_erase.end(); ++it ) { - if ( !(*it)->is_free(Map::dimension) ) + if ( !(*it)->is_free(Map::dimension) && + !amap.is_marked((*it)->beta(Map::dimension), mark) ) { - amap.unlink_beta_for_involution(*it,Map::dimension); + modified_darts.push_back((*it)->beta(Map::dimension)); + //(*it)->beta(Map::dimension)->unlink_beta(Map::dimension); + amap.template unlink_beta_for_involution(*it, Map::dimension); } } // 4) We test the split of all the incident cells for all the non // void attributes. Map::Helper::template Foreach_enabled_attributes - >:: - run(&amap, &mark_for_incident_cells[0], - &incident_cells[0]); + >:: + run(&amap, &modified_darts, -1); //, modified_darts2); + //&mark_for_incident_cells[0], + //&incident_cells[0]); // 5) We remove all the darts of the d-cell. for ( it = to_erase.begin(); it != to_erase.end(); ++it ) @@ -527,14 +542,15 @@ namespace CGAL { amap.free_mark(mark); // We free the marks. - for (int j=0; j to_erase; - int mark_for_incident_cells[Map::Helper::nb_attribs]; + std::deque modified_darts; + +/* int mark_for_incident_cells[Map::Helper::nb_attribs]; std::deque > incident_cells[Map::Helper::nb_attribs]; @@ -568,23 +590,24 @@ namespace CGAL { mark_for_incident_cells [j] = amap.get_new_mark(); CGAL_assertion( mark_for_incident_cells [j]!=-1 ); } +*/ // 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); it.cont(); ++it ) { to_erase.push_back(it); + if ( !it->is_free(0) && dg1==NULL ) + { dg1=it; dg2=it->beta(0); } amap.mark(it, mark); ++res; } - typename Map::Dart_handle dg1=NULL, dg2=NULL; - // 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) +/* for (; it != to_erase.end(); ++it) { if ( !(*it)->is_free(0) ) { @@ -615,12 +638,14 @@ namespace CGAL { } } } +*/ + + 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 ) amap.template group_attribute<1>(dg1, dg2); - //if (!adart->is_free(0)) - // amap.template group_attribute<1>(adart, adart->beta(0)); // For each dart of the vertex, we modify 0 and 1-links of neighbors. for ( it=to_erase.begin(); it != to_erase.end(); ++it) @@ -628,17 +653,26 @@ namespace CGAL { if ( !(*it)->is_free(0) ) { if ( !(*it)->is_free(1) && (*it)->beta(0)!=(*it) ) + { amap.template basic_link_beta<1>((*it)->beta(0), (*it)->beta(1)); + modified_darts.push_back((*it)->beta(0)); + modified_darts.push_back((*it)->beta(1)); + } else { (*it)->beta(0)->unlink_beta(1); + modified_darts.push_back((*it)->beta(0)); } for ( unsigned int j=2; j<=Map::dimension; ++j ) { if ( !(*it)->is_free(j) ) + { + // TODO push these darts in modified_darts ? + // not sure this is required amap.basic_link_beta((*it)->beta(0), (*it)->beta(j), j); //((*it)->beta(0))->basic_link_beta((*it)->beta(j),j); + } } } else @@ -646,12 +680,17 @@ namespace CGAL { if ( !(*it)->is_free(1) ) { (*it)->beta(1)->unlink_beta(0); + modified_darts.push_back((*it)->beta(1)); } for ( unsigned int j=2; j<=Map::dimension; ++j ) { if ( !(*it)->is_free(j) ) + { + // TODO push these darts in modified_darts ? + // not sure this is required amap.unlink_beta(*it, j); + } } } } @@ -659,9 +698,12 @@ namespace CGAL { // We test the split of all the incident cells for all the non // void attributes. Map::Helper::template Foreach_enabled_attributes - >:: - run(&amap, &mark_for_incident_cells[0], - &incident_cells[0]); + >:: + // >:: + run(&amap, + &modified_darts, -1); //mark_modified_darts); + //&mark_for_incident_cells[0], + //&incident_cells[0]); // We remove all the darts of the i-cell. for ( it=to_erase.begin(); it!=to_erase.end(); ++it ) @@ -671,14 +713,16 @@ namespace CGAL { amap.free_mark(mark); // We free the marks. - for (int j=0; j - Dart_pair; - std::stack todegroup; - - // 1) We group the two vertices if they exist. - typename Map::Dart_handle dh2 = adart->other_extremity(); - if (dh2!=NULL) - amap.template group_attribute<0>(adart, dh2); - typename Map::Dart_handle d1, d2; - int mark = amap.get_new_mark(); - std::vector to_erase; + typename Map::Dart_handle dg1=NULL, dg2=NULL; - // 2) We mark all the darts of the edge. + int mark = amap.get_new_mark(); +// int mark_modified_darts = amap.get_new_mark(); + + std::deque to_erase; + + std::deque modified_darts; + + // First we store and mark all the darts of the 1-cell to contract. + for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); + it.cont(); ++it ) { - for ( CMap_dart_iterator_basic_of_cell it(amap,adart,mark); - it.cont(); ++it ) - { - to_erase.push_back(it); - amap.mark(it,mark); - ++res; - } + to_erase.push_back(it); + if ( dg1==NULL && it->other_extremity()!=NULL ) + { dg1=it; dg2=it->other_extremity(); } + amap.mark(it, mark); + ++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 ) + amap.template group_attribute<0>(dg1, dg2); + // 3) We modify the darts of the cells incident to the edge // when they are marked to remove. - typename std::vector::iterator - it = to_erase.begin(); - for (; it != to_erase.end(); ++it) + for (it=to_erase.begin(); it!=to_erase.end(); ++it) { amap.update_dart_of_all_attributes(*it, mark); } // 4) For each dart of the cell, we modify link of neighbors. @@ -813,11 +861,17 @@ namespace CGAL { if ( !(*it)->is_free(0) ) { if ( !(*it)->is_free(1) && (*it)->beta(0)!=(*it) ) + { amap.template basic_link_beta<1>((*it)->beta(0), (*it)->beta(1)); + modified_darts.push_back((*it)->beta(0)); + modified_darts.push_back((*it)->beta(1)); + + } else { // TODO todegroup.push(Dart_pair((*it)->beta(0), *it)); (*it)->beta(0)->unlink_beta(1); + modified_darts.push_back((*it)->beta(0)); } } else @@ -826,17 +880,20 @@ namespace CGAL { { // TODO todegroup.push(Dart_pair((*it)->beta(1), *it)); (*it)->beta(1)->unlink_beta(0); + modified_darts.push_back((*it)->beta(1)); } } } - // 5) We degroup all the pairs - while ( !todegroup.empty() ) - { - Dart_pair p=todegroup.top(); - todegroup.pop(); - amap.degroup_all_attributes(p.first,p.second); - } + // We test the split of all the incident cells for all the non + // void attributes. + Map::Helper::template Foreach_enabled_attributes + >:: + // >:: + run(&amap, + &modified_darts, -1); //mark_modified_darts); + //&mark_for_incident_cells[0], + //&incident_cells[0]); // 6) We remove all the darts of the cell. for (it = to_erase.begin(); it != to_erase.end(); ++it) @@ -846,6 +903,7 @@ namespace CGAL { amap.free_mark(mark); CGAL_expensive_postcondition( amap.is_valid() ); + assert( amap.is_valid() ); // TO REMOVEE return res; } diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 68184d1e336..a8f99676167 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -80,10 +80,10 @@ namespace CGAL { typedef typename Refs::Dart_const_handle Dart_const_handle; typedef typename Refs::Helper Helper; /// Typedef for attributes - template + template struct Attribute_handle: public Refs::template Attribute_handle {}; - template + template struct Attribute_const_handle: public Refs::template Attribute_const_handle {}; @@ -139,7 +139,7 @@ namespace CGAL { Dart_const_handle beta_inv(unsigned int i) const { return beta(CGAL_BETAINV(i)); } - /** Return a dart belonging to the same edge and to the second vertex + /** Return a dart belonging to the same edge and to the second vertex * of the current edge (NULL if such a dart does not exist). * @return An handle to the opposite dart. */ @@ -155,7 +155,7 @@ namespace CGAL { if (!is_free(i)) return beta(i); return NULL; } - + /** Return a dart incident to the other extremity of the current edge, * but contrary to opposite, non necessary to the same edge * (NULL if such a dart does not exist). @@ -181,15 +181,15 @@ namespace CGAL { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "attribute called but i-attributes are disabled."); return CGAL::cpp11::get::value> - (mattribute_handles); + (mattribute_handles); } - template + template typename Attribute_const_handle::type attribute() const - { + { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "attribute called but i-attributes are disabled."); return CGAL::cpp11::get::value> - (mattribute_handles); + (mattribute_handles); } protected: @@ -260,11 +260,11 @@ namespace CGAL { /// @return a handle on the i th attribute template void set_attribute( typename Attribute_handle::type & ahandle ) - { + { CGAL_static_assertion_msg(Helper::template Dimension_index::value>=0, "set_attribute called but i-attributes are disabled."); CGAL::cpp11::get::value> - (mattribute_handles) = ahandle; + (mattribute_handles) = ahandle; if (ahandle!=NULL) ahandle->inc_nb_refs(); } @@ -274,16 +274,16 @@ namespace CGAL { { template static void run(Self* adart) - { + { // TODO BUG EN 1 SEULE LIGNE ? typename Attribute_handle::type h = NULL; adart->template set_attribute (h); } }; public: - void * for_compact_container() const + void * for_compact_container() const { return mbeta[0].for_compact_container(); } - void * & for_compact_container() + void * & for_compact_container() { return mbeta[0].for_compact_container(); } protected: diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index 19d1af4a5f8..7f90566bde6 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -625,24 +625,74 @@ namespace CGAL { } }; - template + template struct Test2_split_with_deque { + template + static void test_one_dart( Map* amap, + typename Map::Dart_handle adart, + std::set::type>& found_attributes, + int mark) + { + if ( adart->template attribute()!=NULL && + !amap->is_marked(adart, mark) ) + { + typename Map::Helper::template Attribute_handle::type + a1 = adart->template attribute(); + if ( !found_attributes.insert(a1).second ) + { // Here the attribute was already present in the set + typename Map::Helper::template Attribute_handle::type + a2 = amap->template create_attribute(*a1); + // std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; + + for ( CMap_dart_iterator_basic_of_cell + itj(*amap, adart, mark); + itj.cont(); ++itj ) + { + // std::cout<<&*itj<<", "; + amap->template set_attribute_of_dart(itj, a2); + amap->mark(itj, mark); + } + + Apply_cell_functor + ::type, + typename Map::Helper::template Attribute_type::type:: + On_split>::run(*a1, *a2); + } + else + { + // Here the attribute was not in the set as we are able + // to insert it. + a1->set_dart(adart); + // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; + + for ( CMap_dart_iterator_basic_of_cell + itj(*amap, adart, mark); + itj.cont(); ++itj ) + { + // std::cout<<&*itj<<", "; + CGAL_assertion( itj->template attribute()==a1 ); + amap->mark(itj, mark); + } + } + // std::cout< static void run( Map* amap, std::deque *modified_darts, - int mark_modified_darts ) + int mark_modified_darts + /*, + std::deque + *modified_darts2*/) { - if ( i==j || j==k ) return; + if ( i==j ) return; CGAL_assertion( amap!=NULL ); - typename Map::Helper::template Attribute_handle::type - a1 = NULL; - typename Map::Helper::template Attribute_handle::type - a2=NULL; - std::set::type> found_attributes; @@ -652,105 +702,36 @@ namespace CGAL { iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) { - if ( (*it)->template attribute()!=NULL && - !amap->is_marked(*it, mark) ) - { - a1 = (*it)->template attribute(); - if ( found_attributes.insert(a1).second ) - { // Here the attribute was not in the set as we are able - // to insert it. - a2 = amap->template create_attribute(*a1); - // std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, *it, mark); - itj.cont(); ++itj ) - { - ++nb; - // std::cout<<&*itj<<", "; - amap->template set_attribute_of_dart(itj, a2); - amap->mark(itj, mark); - } - - Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type:: - On_split>::run(*a1, *a2); - } - else - { // Here the attribute was already present in the set - a1->set_dart(*it); - // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, *it, mark); - itj.cont(); ++itj ) - { - ++nb; - // std::cout<<&*itj<<", "; - CGAL_assertion( itj->template attribute()==a1 ); - amap->mark(itj, mark); - } - } - // std::cout<(amap, *it, found_attributes, mark); if ( i!=1 && j==0 ) { typename Map::Dart_handle od = (*it)->other_extremity(); - if ( od!=NULL && od->template attribute()!=NULL && - !amap->is_marked(od, mark) ) - { - a1 = od->template attribute(); - if ( found_attributes.insert(a1).second ) - { // Here the attribute was not in the set as we are able - // to insert it. - a2 = amap->template create_attribute(*a1); - // std::cout<<"A2 "<<&*a2<<" "<<&**itj<<": "; - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, od, mark); - itj.cont(); ++itj ) - { - ++nb; - // std::cout<<&*itj<<", "; - amap->template set_attribute_of_dart(itj, a2); - amap->mark(itj, mark); - } - - Apply_cell_functor - ::type, - typename Map::Helper::template Attribute_type::type:: - On_split>::run(*a1, *a2); - } - else - { // Here the attribute was already present in the set - a1->set_dart(od); - // std::cout<<"A1 "<<&*a1<<" "<<&**itj<<": "; - - for ( CMap_dart_iterator_basic_of_cell - itj(*amap, od, mark); - itj.cont(); ++itj ) - { - ++nb; - // std::cout<<&*itj<<", "; - CGAL_assertion( itj->template attribute()==a1 ); - amap->mark(itj, mark); - } - } - // std::cout<(amap, od, found_attributes, mark); } } - /* std::cout<<"Size of set for dim "<:: + iterator it=modified_darts2->begin(); + it!=modified_darts2->end(); ++it ) + { + test_one_dart(amap, *it, found_attributes, mark); - std::cout<<"Size of deque for dim "<size()<number_of_marked_darts(mark)<other_extremity(); + if ( od!=NULL ) + test_one_dart(amap, od, found_attributes, mark); + } + } + }*/ + // std::cout<<"Size of set for dim "<size()<number_of_marked_darts(mark)<negate_mark(mark); @@ -759,7 +740,8 @@ namespace CGAL { iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) { - amap->unmark(*it, mark_modified_darts); + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); if ( !amap->is_marked(*it, mark) ) for ( CMap_dart_iterator_basic_of_cell @@ -782,6 +764,37 @@ namespace CGAL { } } + /* if ( i+1==j ) + { + for ( typename std::deque:: + iterator it=modified_darts2->begin(); + it!=modified_darts2->end(); ++it ) + { + if ( mark_modified_darts!=-1 ) + amap->unmark(*it, mark_modified_darts); + + if ( !amap->is_marked(*it, mark) ) + for ( CMap_dart_iterator_basic_of_cell + itj(*amap, *it, mark); + itj.cont(); ++itj ) + { + amap->mark(itj, mark); + } + + if ( i!=1 && j==0 ) + { + typename Map::Dart_handle od = (*it)->other_extremity(); + if ( od!=NULL && !amap->is_marked(od, mark) ) + for ( CMap_dart_iterator_basic_of_cell + itj(*amap, od, mark); + itj.cont(); ++itj ) + { + amap->mark(itj, mark); + } + } + } + }*/ + CGAL_assertion( amap->is_whole_map_marked(mark) ); amap->free_mark(mark); }