From 8c610eb299c5dbb941d5cdd678f83e16dc713adb Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Fri, 3 May 2013 17:46:23 +0200 Subject: [PATCH 1/4] Changes for reversing the orientation of a combinatorial map Signed-off-by: Ken Arroyo Ohori --- .../include/CGAL/Combinatorial_map.h | 19 +++ Combinatorial_map/include/CGAL/Dart.h | 16 +++ .../Combinatorial_map_internal_functors.h | 131 ++++++++++++++++++ 3 files changed, 166 insertions(+) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index a3a1cc76914..dce8f539cdd 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -2003,6 +2003,25 @@ namespace CGAL { if ( update_attributes ) unsew(adart); else topo_unsew(adart); } + + /** Reverse the orientation (swap beta 0 & 1 links) of the entire map. + * A valid map after this operation remains valid. + * @param none + * @return none + */ + void inside_out() + { + internal::Flip_map_functor::run(this); + } + + /** Reverse the orientation (swap beta 0 & 1 links) of the cells connected to the given dart. + * @param adart handle to a dart + * @return none + */ + void connected_inside_out (Dart_handle adart) + { + internal::Flip_connected_components_functor::run(this, adart); + } /** Count the marked cells (at least one marked dart). * @param amark the mark to consider. diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 0af7239ea26..bf565eda2af 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -72,6 +72,12 @@ namespace CGAL { template friend struct internal::link_beta_functor; + + template + friend struct internal::Flip_map_functor; + + template + friend struct internal::Flip_connected_components_functor; public: typedef Dart Self; @@ -272,6 +278,16 @@ namespace CGAL { Helper::template Foreach_enabled_attributes:: run(this); } + + /** Copy constructor: + * @param adart a dart. + */ + Dart(const std::bitset& /*amarks*/, const Dart& adart) : mmarks(adart.mmarks), + mattribute_handles(adart.mattribute_handles) + { + for (unsigned int i = 0; i <= dimension; ++i) + mbeta[i] = adart.mbeta[i]; + } /** Return the mark value of a given mark number. * @param amark the mark number. diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index bc4a38dd3d4..bd4f11423d9 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -413,6 +413,137 @@ struct Set_i_attribute_of_dart_functor {} }; // **************************************************************************** +/// Functor to reverse the orientation of a combinatorial map +template ::type> +struct Flip_map_functor +{ + static void run(CMap *amap) + { + int mark = amap->get_new_mark(); + CGAL_precondition(amap->is_whole_map_unmarked(mark)); + CGAL_precondition(amap->is_valid()); + for (typename CMap::Dart_range::iterator current_dart = amap->darts().begin(), + last_dart = amap->darts().end(); current_dart != last_dart; ++current_dart) { + if (amap->is_marked(current_dart, mark)) continue; + typename CMap::Dart_handle first_dart_in_cell = current_dart; + typename CMap::Dart_handle current_dart_in_cell = first_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type attribute_for_first_dart = current_dart_in_cell->template attribute<0>(); + do { + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type next_attribute = next_dart_in_cell->template attribute<0>(); + amap->template set_attribute_of_dart<0>(current_dart_in_cell, next_attribute); // One line error??? + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + current_dart_in_cell = current_dart_in_cell->beta(0); + } while (current_dart_in_cell != first_dart_in_cell); + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + amap->template set_attribute_of_dart<0>(current_dart_in_cell, attribute_for_first_dart); + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + } amap->negate_mark(mark); + CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + CGAL_postcondition(amap->is_valid()); + amap->free_mark(mark); + } +}; +template +struct Flip_map_functor +{ + static void run(CMap *amap) + { + int mark = amap->get_new_mark(); + CGAL_precondition(amap->is_whole_map_unmarked(mark)); + CGAL_precondition(amap->is_valid()); + for (typename CMap::Dart_range::iterator current_dart = amap->darts().begin(), + last_dart = amap->darts().end(); current_dart != last_dart; ++current_dart) { + if (amap->is_marked(current_dart, mark)) continue; + for (typename CMap::template Dart_of_cell_range<2>::iterator current_dart_in_cell = amap->template darts_of_cell<2>(current_dart).begin(), + last_dart_in_cell = amap->template darts_of_cell<2>(current_dart).end(); current_dart_in_cell != last_dart_in_cell; ++current_dart_in_cell) { + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + } + } amap->negate_mark(mark); + CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + CGAL_postcondition(amap->is_valid()); + amap->free_mark(mark); + } +}; +// **************************************************************************** +/// Functor to reverse the orientation of a set of connected components in a given map +template ::type> +struct Flip_connected_components_functor +{ + static void run(CMap *amap, typename CMap::Dart_handle adart) + { + //unsigned int flipped_darts = 0, flipped_2cells = 0; + int mark = amap->get_new_mark(); + CGAL_precondition(amap->is_whole_map_unmarked(mark)); + for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), + last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + if (amap->is_marked(current_dart, mark)) continue; + //++flipped_2cells; + typename CMap::Dart_handle first_dart_in_cell = current_dart; + typename CMap::Dart_handle current_dart_in_cell = first_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type attribute_for_first_dart = current_dart_in_cell->template attribute<0>(); + do { + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type next_attribute = next_dart_in_cell->template attribute<0>(); + CGAL::internal::Set_i_attribute_of_dart_functor::run(amap, current_dart_in_cell, next_attribute); + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + current_dart_in_cell = current_dart_in_cell->beta(0); + //++flipped_darts; + } while (current_dart_in_cell != first_dart_in_cell); + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + CGAL::internal::Set_i_attribute_of_dart_functor::run(amap, current_dart_in_cell, attribute_for_first_dart); + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + //++flipped_darts; + } for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), + last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + amap->unmark(current_dart, mark); + } CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + amap->free_mark(mark); + //std::cout << "Flip_connected_components_functor::run(): Flipped " << flipped_2cells << " 2-cells, " << flipped_darts << " darts." << std::endl; + } +}; +template +struct Flip_connected_components_functor +{ + static void run(CMap *amap, typename CMap::Dart_handle adart) + { + int mark = amap->get_new_mark(); + CGAL_precondition(amap->is_whole_map_unmarked(mark)); + for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), + last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + if (amap->is_marked(current_dart, mark)) continue; + for (typename CMap::template Dart_of_cell_range<2>::iterator current_dart_in_cell = amap->template darts_of_cell<2>(current_dart).begin(), + last_dart_in_cell = amap->template darts_of_cell<2>(current_dart).end(); current_dart_in_cell != last_dart_in_cell; ++current_dart_in_cell) { + amap->mark(current_dart_in_cell, mark); + typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); + current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); + } + } for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), + last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + amap->unmark(current_dart, mark); + } CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + amap->free_mark(mark); + } +}; +// **************************************************************************** // Beta functor, used to combine several beta. #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template From d53f347e2def65a75c7786777b16e03d6423d7c3 Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Mon, 6 May 2013 13:48:18 +0200 Subject: [PATCH 2/4] New name and description for reversing the orientation of part of a combinatorial map Signed-off-by: Ken Arroyo Ohori --- Combinatorial_map/include/CGAL/Combinatorial_map.h | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index dce8f539cdd..6d12ac81c49 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -2014,11 +2014,13 @@ namespace CGAL { internal::Flip_map_functor::run(this); } - /** Reverse the orientation (swap beta 0 & 1 links) of the cells connected to the given dart. + /** Reverse the orientation (swap beta 0 & 1 links) of the connected + * component containing the given dart. + * A valid map after this operation remains valid. * @param adart handle to a dart * @return none */ - void connected_inside_out (Dart_handle adart) + void inside_out_connected_component (Dart_handle adart) { internal::Flip_connected_components_functor::run(this, adart); } From 0ac3e691202708ce3cc31fcc7b1409ee834803ad Mon Sep 17 00:00:00 2001 From: Ken Arroyo Ohori Date: Tue, 7 May 2013 11:20:38 +0200 Subject: [PATCH 3/4] Changed names of methods and functors Signed-off-by: Ken Arroyo Ohori --- Combinatorial_map/include/CGAL/Combinatorial_map.h | 8 ++++---- Combinatorial_map/include/CGAL/Dart.h | 4 ++-- .../internal/Combinatorial_map_internal_functors.h | 13 ++++--------- 3 files changed, 10 insertions(+), 15 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 6d12ac81c49..107f898454c 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -2009,9 +2009,9 @@ namespace CGAL { * @param none * @return none */ - void inside_out() + void reverse_orientation() { - internal::Flip_map_functor::run(this); + internal::Reverse_orientation_of_map_functor::run(this); } /** Reverse the orientation (swap beta 0 & 1 links) of the connected @@ -2020,9 +2020,9 @@ namespace CGAL { * @param adart handle to a dart * @return none */ - void inside_out_connected_component (Dart_handle adart) + void reverse_orientation_connected_component (Dart_handle adart) { - internal::Flip_connected_components_functor::run(this, adart); + internal::Reverse_orientation_of_conected_component_functor::run(this, adart); } /** Count the marked cells (at least one marked dart). diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index bf565eda2af..44e91d47ac9 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -74,10 +74,10 @@ namespace CGAL { friend struct internal::link_beta_functor; template - friend struct internal::Flip_map_functor; + friend struct internal::Reverse_orientation_of_map_functor; template - friend struct internal::Flip_connected_components_functor; + friend struct internal::Reverse_orientation_of_conected_component_functor; public: typedef Dart Self; diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index bd4f11423d9..e7aad76151c 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -415,7 +415,7 @@ struct Set_i_attribute_of_dart_functor // **************************************************************************** /// Functor to reverse the orientation of a combinatorial map template ::type> -struct Flip_map_functor +struct Reverse_orientation_of_map_functor { static void run(CMap *amap) { @@ -451,7 +451,7 @@ struct Flip_map_functor } }; template -struct Flip_map_functor +struct Reverse_orientation_of_map_functor { static void run(CMap *amap) { @@ -478,17 +478,15 @@ struct Flip_map_functor // **************************************************************************** /// Functor to reverse the orientation of a set of connected components in a given map template ::type> -struct Flip_connected_components_functor +struct Reverse_orientation_of_conected_component_functor { static void run(CMap *amap, typename CMap::Dart_handle adart) { - //unsigned int flipped_darts = 0, flipped_2cells = 0; int mark = amap->get_new_mark(); CGAL_precondition(amap->is_whole_map_unmarked(mark)); for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { if (amap->is_marked(current_dart, mark)) continue; - //++flipped_2cells; typename CMap::Dart_handle first_dart_in_cell = current_dart; typename CMap::Dart_handle current_dart_in_cell = first_dart_in_cell->beta(1); typename CMap::Helper::template Attribute_handle<0>::type attribute_for_first_dart = current_dart_in_cell->template attribute<0>(); @@ -501,7 +499,6 @@ struct Flip_connected_components_functor current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); current_dart_in_cell = current_dart_in_cell->beta(0); - //++flipped_darts; } while (current_dart_in_cell != first_dart_in_cell); amap->mark(current_dart_in_cell, mark); typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); @@ -509,17 +506,15 @@ struct Flip_connected_components_functor CGAL::internal::Set_i_attribute_of_dart_functor::run(amap, current_dart_in_cell, attribute_for_first_dart); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); - //++flipped_darts; } for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { amap->unmark(current_dart, mark); } CGAL_postcondition(amap->is_whole_map_unmarked(mark)); amap->free_mark(mark); - //std::cout << "Flip_connected_components_functor::run(): Flipped " << flipped_2cells << " 2-cells, " << flipped_darts << " darts." << std::endl; } }; template -struct Flip_connected_components_functor +struct Reverse_orientation_of_conected_component_functor { static void run(CMap *amap, typename CMap::Dart_handle adart) { From 7f7788bd8401800d804d3f8b1316620e0ed57b49 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Jun 2013 11:14:03 +0200 Subject: [PATCH 4/4] Small corrections on reverse orientations; reformating; start to add tests --- .../include/CGAL/Cell_attribute.h | 12 ++ .../include/CGAL/Combinatorial_map.h | 2 +- Combinatorial_map/include/CGAL/Dart.h | 2 +- .../Combinatorial_map_internal_functors.h | 164 ++++++++++++------ .../Linear_cell_complex_4_test.h | 6 + 5 files changed, 133 insertions(+), 53 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 153c4f643a1..c6caad68a24 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -89,6 +89,12 @@ namespace CGAL { template friend struct internal::Decrease_attribute_functor_run; + template + friend struct internal::Reverse_orientation_of_map_functor; + + template + friend struct internal::Reverse_orientation_of_connected_component_functor; + public: typedef Tag_false Supports_cell_dart; @@ -188,6 +194,12 @@ namespace CGAL { template friend struct internal::Decrease_attribute_functor_run; + template + friend struct internal::Reverse_orientation_of_map_functor; + + template + friend struct internal::Reverse_orientation_of_connected_component_functor; + public: typedef Tag_true Supports_cell_dart; diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 107f898454c..cd309cd5d98 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -2022,7 +2022,7 @@ namespace CGAL { */ void reverse_orientation_connected_component (Dart_handle adart) { - internal::Reverse_orientation_of_conected_component_functor::run(this, adart); + internal::Reverse_orientation_of_connected_component_functor::run(this, adart); } /** Count the marked cells (at least one marked dart). diff --git a/Combinatorial_map/include/CGAL/Dart.h b/Combinatorial_map/include/CGAL/Dart.h index 44e91d47ac9..8269c222f78 100644 --- a/Combinatorial_map/include/CGAL/Dart.h +++ b/Combinatorial_map/include/CGAL/Dart.h @@ -77,7 +77,7 @@ namespace CGAL { friend struct internal::Reverse_orientation_of_map_functor; template - friend struct internal::Reverse_orientation_of_conected_component_functor; + friend struct internal::Reverse_orientation_of_connected_component_functor; public: typedef Dart Self; diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h index e7aad76151c..cf1411956f6 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -414,7 +414,8 @@ struct Set_i_attribute_of_dart_functor }; // **************************************************************************** /// Functor to reverse the orientation of a combinatorial map -template ::type> +template ::type> struct Reverse_orientation_of_map_functor { static void run(CMap *amap) @@ -422,29 +423,45 @@ struct Reverse_orientation_of_map_functor int mark = amap->get_new_mark(); CGAL_precondition(amap->is_whole_map_unmarked(mark)); CGAL_precondition(amap->is_valid()); - for (typename CMap::Dart_range::iterator current_dart = amap->darts().begin(), - last_dart = amap->darts().end(); current_dart != last_dart; ++current_dart) { + for (typename CMap::Dart_range::iterator current_dart=amap->darts().begin(), + last_dart = amap->darts().end(); current_dart!=last_dart; + ++current_dart) + { if (amap->is_marked(current_dart, mark)) continue; - typename CMap::Dart_handle first_dart_in_cell = current_dart; - typename CMap::Dart_handle current_dart_in_cell = first_dart_in_cell->beta(1); - typename CMap::Helper::template Attribute_handle<0>::type attribute_for_first_dart = current_dart_in_cell->template attribute<0>(); + typename CMap::Dart_handle first_dart_in_cell= current_dart; + typename CMap::Dart_handle current_dart_in_cell= + first_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type + attribute_for_first_dart=current_dart_in_cell->template attribute<0>(); + attribute_for_first_dart->inc_nb_refs(); do { amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); - typename CMap::Helper::template Attribute_handle<0>::type next_attribute = next_dart_in_cell->template attribute<0>(); - amap->template set_attribute_of_dart<0>(current_dart_in_cell, next_attribute); // One line error??? + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type + next_attribute=next_dart_in_cell->template attribute<0>(); + // One line error??? + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, current_dart_in_cell, next_attribute); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); current_dart_in_cell = current_dart_in_cell->beta(0); - } while (current_dart_in_cell != first_dart_in_cell); + } + while (current_dart_in_cell != first_dart_in_cell); amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); - amap->template set_attribute_of_dart<0>(current_dart_in_cell, attribute_for_first_dart); + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, current_dart_in_cell, attribute_for_first_dart); + attribute_for_first_dart->dec_nb_refs(); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); - } amap->negate_mark(mark); + } + amap->negate_mark(mark); CGAL_postcondition(amap->is_whole_map_unmarked(mark)); CGAL_postcondition(amap->is_valid()); amap->free_mark(mark); @@ -458,83 +475,128 @@ struct Reverse_orientation_of_map_functor int mark = amap->get_new_mark(); CGAL_precondition(amap->is_whole_map_unmarked(mark)); CGAL_precondition(amap->is_valid()); - for (typename CMap::Dart_range::iterator current_dart = amap->darts().begin(), - last_dart = amap->darts().end(); current_dart != last_dart; ++current_dart) { + for (typename CMap::Dart_range::iterator current_dart=amap->darts().begin(), + last_dart = amap->darts().end(); current_dart!=last_dart; + ++current_dart) + { if (amap->is_marked(current_dart, mark)) continue; - for (typename CMap::template Dart_of_cell_range<2>::iterator current_dart_in_cell = amap->template darts_of_cell<2>(current_dart).begin(), - last_dart_in_cell = amap->template darts_of_cell<2>(current_dart).end(); current_dart_in_cell != last_dart_in_cell; ++current_dart_in_cell) { + for (typename CMap::template Dart_of_cell_range<2>::iterator + current_dart_in_cell=amap->template darts_of_cell<2>(current_dart). + begin(), last_dart_in_cell=amap->template darts_of_cell<2> + (current_dart).end(); current_dart_in_cell!=last_dart_in_cell; + ++current_dart_in_cell) + { amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); } - } amap->negate_mark(mark); + } + amap->negate_mark(mark); CGAL_postcondition(amap->is_whole_map_unmarked(mark)); CGAL_postcondition(amap->is_valid()); amap->free_mark(mark); } }; // **************************************************************************** -/// Functor to reverse the orientation of a set of connected components in a given map -template ::type> -struct Reverse_orientation_of_conected_component_functor +/// Functor to reverse the orientation of a connected component in a given map +template ::type> +struct Reverse_orientation_of_connected_component_functor { static void run(CMap *amap, typename CMap::Dart_handle adart) { int mark = amap->get_new_mark(); CGAL_precondition(amap->is_whole_map_unmarked(mark)); - for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), - last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + for (typename CMap::template Dart_of_cell_range::iterator + current_dart=amap->template darts_of_cell(adart). + begin(), last_dart=amap->template darts_of_cell + (adart).end(); current_dart!=last_dart; ++current_dart) + { if (amap->is_marked(current_dart, mark)) continue; - typename CMap::Dart_handle first_dart_in_cell = current_dart; - typename CMap::Dart_handle current_dart_in_cell = first_dart_in_cell->beta(1); - typename CMap::Helper::template Attribute_handle<0>::type attribute_for_first_dart = current_dart_in_cell->template attribute<0>(); + typename CMap::Dart_handle first_dart_in_cell=current_dart; + typename CMap::Dart_handle current_dart_in_cell= + first_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type + attribute_for_first_dart=current_dart_in_cell->template attribute<0>(); + attribute_for_first_dart->inc_nb_refs(); do { amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); - typename CMap::Helper::template Attribute_handle<0>::type next_attribute = next_dart_in_cell->template attribute<0>(); - CGAL::internal::Set_i_attribute_of_dart_functor::run(amap, current_dart_in_cell, next_attribute); + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); + typename CMap::Helper::template Attribute_handle<0>::type + next_attribute=next_dart_in_cell->template attribute<0>(); + + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, current_dart_in_cell, next_attribute); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); current_dart_in_cell = current_dart_in_cell->beta(0); - } while (current_dart_in_cell != first_dart_in_cell); + } + while (current_dart_in_cell != first_dart_in_cell); amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); - CGAL::internal::Set_i_attribute_of_dart_functor::run(amap, current_dart_in_cell, attribute_for_first_dart); + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); + CGAL::internal::Set_i_attribute_of_dart_functor:: + run(amap, current_dart_in_cell, attribute_for_first_dart); + attribute_for_first_dart->dec_nb_refs(); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); - } for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), - last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + } + for (typename CMap::template Dart_of_cell_range::iterator + current_dart=amap->template darts_of_cell(adart). + begin(), last_dart=amap->template darts_of_cell + (adart).end(); current_dart!=last_dart; ++current_dart) + { amap->unmark(current_dart, mark); - } CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + } + CGAL_postcondition(amap->is_whole_map_unmarked(mark)); amap->free_mark(mark); } }; template -struct Reverse_orientation_of_conected_component_functor +struct Reverse_orientation_of_connected_component_functor { static void run(CMap *amap, typename CMap::Dart_handle adart) { int mark = amap->get_new_mark(); CGAL_precondition(amap->is_whole_map_unmarked(mark)); - for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), - last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + for (typename CMap::template Dart_of_cell_range::iterator + current_dart=amap->template darts_of_cell(adart). + begin(), last_dart=amap->template darts_of_cell + (adart).end(); current_dart!=last_dart; ++current_dart) + { if (amap->is_marked(current_dart, mark)) continue; - for (typename CMap::template Dart_of_cell_range<2>::iterator current_dart_in_cell = amap->template darts_of_cell<2>(current_dart).begin(), - last_dart_in_cell = amap->template darts_of_cell<2>(current_dart).end(); current_dart_in_cell != last_dart_in_cell; ++current_dart_in_cell) { + for (typename CMap::template Dart_of_cell_range<2>::iterator + current_dart_in_cell=amap->template darts_of_cell<2>(current_dart). + begin(), last_dart_in_cell=amap->template darts_of_cell<2> + (current_dart).end(); current_dart_in_cell!=last_dart_in_cell; + ++current_dart_in_cell) + { amap->mark(current_dart_in_cell, mark); - typename CMap::Dart_handle previous_dart_in_cell = current_dart_in_cell->beta(0); - typename CMap::Dart_handle next_dart_in_cell = current_dart_in_cell->beta(1); + typename CMap::Dart_handle previous_dart_in_cell= + current_dart_in_cell->beta(0); + typename CMap::Dart_handle next_dart_in_cell= + current_dart_in_cell->beta(1); current_dart_in_cell->basic_link_beta(previous_dart_in_cell, 1); current_dart_in_cell->basic_link_beta(next_dart_in_cell, 0); } - } for (typename CMap::template Dart_of_cell_range::iterator current_dart = amap->template darts_of_cell(adart).begin(), - last_dart = amap->template darts_of_cell(adart).end(); current_dart != last_dart; ++current_dart) { + } + for (typename CMap::template Dart_of_cell_range::iterator + current_dart=amap->template darts_of_cell(adart). + begin(), last_dart=amap->template darts_of_cell + (adart).end(); current_dart!=last_dart; ++current_dart) + { amap->unmark(current_dart, mark); - } CGAL_postcondition(amap->is_whole_map_unmarked(mark)); + } + CGAL_postcondition(amap->is_whole_map_unmarked(mark)); amap->free_mark(mark); } }; diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_4_test.h b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_4_test.h index d19dee3bc22..a21e31ea478 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_4_test.h +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_4_test.h @@ -284,6 +284,12 @@ bool test_LCC_4() return false; } + lcc.reverse_orientation(); + lcc.reverse_orientation(); + + lcc.reverse_orientation_connected_component(dh1); + lcc.reverse_orientation_connected_component(dh1); + /* import_from_polyhedron(lcc,ap); lcc.clear();