From 29039d2fde6c911db5c794cf0573ecb7d0d60f38 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Tue, 29 Jan 2013 16:30:43 +0100 Subject: [PATCH] wip split... --- .../CGAL/Combinatorial_map_operations.h | 152 +++++++++++------- .../internal/Combinatorial_map_functors.h | 88 +++++++++- .../demo/Linear_cell_complex/CMakeLists.txt | 5 + .../Linear_cell_complex_pqq_subdivision.cpp | 2 +- 4 files changed, 186 insertions(+), 61 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h index 709ebbeaec0..a1820964817 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map_operations.h @@ -175,6 +175,8 @@ namespace CGAL { internal::Call_split_functor::run(c.d1, c.d2); } + CGAL_expensive_postcondition( amap.is_valid() ); + return n1; } @@ -221,11 +223,13 @@ namespace CGAL { typename Map::Dart_handle d1, d2; 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); -/* int mark_for_incident_cells[Map::Helper::nb_attribs]; + /*int mark_for_incident_cells[Map::Helper::nb_attribs]; std::deque > incident_cells[Map::Helper::nb_attribs]; @@ -242,17 +246,17 @@ namespace CGAL { it.cont(); ++it ) { to_erase.push_back(it); + if ( !it->is_free(i+1) && dg1==NULL ) + { dg1=it; dg2=it->beta(i+1); } 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) { d1 = (*it)->beta(iinv); while ( d1!=Map::null_dart_handle && amap.is_marked(d1, mark) ) @@ -320,10 +324,14 @@ namespace CGAL { 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. - // TODO GROUP BEFORE TO MODIFY -/* if ( dg1!=NULL ) - amap.template group_attribute(dg1, dg2);*/ + if ( dg1!=NULL ) + amap.template group_attribute(dg1, dg2); + + //amap.update_dart_of_all_attributes(adart, mark); std::deque modified_darts; @@ -337,47 +345,66 @@ namespace CGAL { if (d1 == (*it)->beta(iinv)) d1 = Map::null_dart_handle; } - d2 = (*it)->beta(i+1)->beta(i); - while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) ) + if ( !amap.is_marked(d1, mark_modified_darts) ) { - d2 = d2->beta(i+1)->beta(i); - if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle; - } + d2 = (*it)->beta(i+1)->beta(i); + while ( d2!=Map::null_dart_handle && amap.is_marked(d2, mark) ) + { + d2 = d2->beta(i+1)->beta(i); + if ( d2==(*it)->beta(i+1)->beta(i) ) d2=Map::null_dart_handle; + } - // TODO ? We can optimize by using map.basic_link_beta but we - // need to mark the second dart to not process another time... - if (d1 != Map::null_dart_handle) - { - if (d2 != Map::null_dart_handle) + if ( !amap.is_marked(d2, mark_modified_darts) ) { - d1->basic_link_beta(d2, i); - if ( i==1 ) d2->basic_link_beta(d1, 0); - modified_darts.push_back(d1); - } - else - { - if ( !d1->is_free(i) ) + if (d1 != Map::null_dart_handle) { - d1->unlink_beta(i); - modified_darts.push_back(d1); + if (d2 != Map::null_dart_handle) + { + //d1->basic_link_beta(d2, i); + amap.template basic_link_beta(d1, d2); + amap.mark(d1, mark_modified_darts); + amap.mark(d2, mark_modified_darts); + modified_darts.push_back(d1); + modified_darts.push_back(d2); + /*if ( i==1 ) + { + d2->basic_link_beta(d1, 0); + // modified_darts2.push_back(d2); + }*/ + // modified_darts2.push_back(d1); + } + else + { + if ( !d1->is_free(i) ) + { + d1->unlink_beta(i); + CGAL_assertion( !amap.is_marked(d1, mark_modified_darts) ); + amap.mark(d1, mark_modified_darts); + modified_darts.push_back(d1); + } + } + } + else if (d2 != Map::null_dart_handle) + { + if ( !d2->is_free(iinv) ) + { + d2->unlink_beta(iinv); + CGAL_assertion( !amap.is_marked(d2, mark_modified_darts) ); + amap.mark(d2, mark_modified_darts); + modified_darts.push_back(d2); + } + } + if ((*it)->is_free(i+1) && !(*it)->is_free(i)) + { + d1 = (*it)->beta(i); + if ( !d1->is_free(iinv) ) + { + d1->unlink_beta(iinv); + CGAL_assertion( !amap.is_marked(d1, mark_modified_darts) ); + amap.mark(d1, mark_modified_darts); + modified_darts.push_back(d1); + } } - } - } - else if (d2 != Map::null_dart_handle) - { - if ( !d2->is_free(iinv) ) - { - d2->unlink_beta(iinv); - modified_darts.push_back(d2); - } - } - if ((*it)->is_free(i+1) && !(*it)->is_free(i)) - { - d1 = (*it)->beta(i); - if ( !d1->is_free(iinv) ) - { - d1->unlink_beta(iinv); - modified_darts.push_back(d1); } } } @@ -385,10 +412,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_for_incident_cells[0], - //&incident_cells[0]); + >:: + // >:: + run(&amap, &modified_darts, 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 ) @@ -397,15 +424,27 @@ namespace CGAL { CGAL_assertion( amap.is_whole_map_unmarked(mark) ); amap.free_mark(mark); + if ( !amap.is_whole_map_unmarked(mark_modified_darts) ) + { + for ( typename std::deque:: + iterator it=modified_darts.begin(); + it!=modified_darts.end(); ++it ) + amap.unmark(*it, mark_modified_darts); + } + + CGAL_assertion ( amap.is_whole_map_unmarked(mark_modified_darts) ); + amap.free_mark(mark_modified_darts); + // We free the marks. -/* for (int j=0; j(adart, adart->beta(1)); + // CGAL_expensive_postcondition( amap.is_valid() ); + return adart->beta(1); } @@ -1014,7 +1055,8 @@ namespace CGAL { CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); amap.free_mark(mark1); - // CGAL_postcondition(amap.is_valid()); + // CGAL_expensive_postcondition( amap.is_valid() ); + return adart1->beta(0); } @@ -1135,7 +1177,8 @@ namespace CGAL { CGAL_assertion( amap.is_whole_map_unmarked(mark1) ); amap.free_mark(mark1); - // CGAL_postcondition(amap.is_valid()); + // CGAL_expensive_postcondition( amap.is_valid() ); + return adart1->beta(0); } @@ -1249,7 +1292,8 @@ namespace CGAL { if ( withBeta3 ) amap.template degroup_attribute<3>( first, first->beta(3) ); - // CGAL_postcondition(amap.is_valid()); + // CGAL_expensive_postcondition( amap.is_valid() ); + return first; } } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h index aa6642a2964..19d1af4a5f8 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_functors.h @@ -575,6 +575,7 @@ namespace CGAL { typename Map::Helper::template Attribute_handle::type a2=NULL; + int nb=0; for ( typename std::deque >:: iterator it=jcells.begin(); it!=jcells.end(); ++it ) { @@ -605,7 +606,7 @@ namespace CGAL { // std::cout<<&*itj2<<", "; if ( nbofjcell>1 ) amap->template set_attribute_of_dart(itj2, a2); - + ++nb; amap->mark(itj2, mark_for_jcells); } // std::cout< : "<number_of_marked_darts(mark_for_jcells)< + template struct Test2_split_with_deque { template static void run( Map* amap, std::deque - *modified_darts ) + *modified_darts, + int mark_modified_darts ) { - if ( i==j ) return; + if ( i==j || j==k ) return; CGAL_assertion( amap!=NULL ); - int nbofjcell = 0; typename Map::Helper::template Attribute_handle::type a1 = NULL; typename Map::Helper::template Attribute_handle::type @@ -643,7 +647,7 @@ namespace CGAL { Attribute_handle::type> found_attributes; int mark = amap->get_new_mark(); - + int nb=0; for ( typename std::deque:: iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) @@ -662,6 +666,7 @@ namespace CGAL { itj(*amap, *it, mark); itj.cont(); ++itj ) { + ++nb; // std::cout<<&*itj<<", "; amap->template set_attribute_of_dart(itj, a2); amap->mark(itj, mark); @@ -681,6 +686,7 @@ namespace CGAL { itj(*amap, *it, mark); itj.cont(); ++itj ) { + ++nb; // std::cout<<&*itj<<", "; CGAL_assertion( itj->template attribute()==a1 ); amap->mark(itj, mark); @@ -688,8 +694,64 @@ namespace CGAL { } // std::cout<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<size()<number_of_marked_darts(mark)<negate_mark(mark); @@ -697,6 +759,8 @@ namespace CGAL { iterator it=modified_darts->begin(); it!=modified_darts->end(); ++it ) { + amap->unmark(*it, mark_modified_darts); + if ( !amap->is_marked(*it, mark) ) for ( CMap_dart_iterator_basic_of_cell itj(*amap, *it, mark); @@ -704,6 +768,18 @@ namespace CGAL { { 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) ); diff --git a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt index cf37a67d286..bf8687135e5 100644 --- a/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/demo/Linear_cell_complex/CMakeLists.txt @@ -13,6 +13,11 @@ endif() # add_definitions("-DCGAL_CHECK_EXPENSIVE") +# For profilling with gprof +add_definitions("-pg") +SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -pg") + +################## find_package(CGAL COMPONENTS Qt4) include(${CGAL_USE_FILE}) 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 ed03726ac16..57e29847147 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 @@ -281,9 +281,9 @@ subdivide_lcc_pqq (LCC & m) { CGAL_assertion( (CGAL::is_removable(m,*dit)) ); CGAL::remove_cell(m, *dit); - CGAL_assertion( m.is_valid() ); } remove.resize(0); + CGAL_assertion( m.is_valid() ); } }