From a211e558ee47d082fbe3f65cf7173e3410c7165d Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 20 Dec 2018 08:51:04 +0100 Subject: [PATCH] Copy methods are now able to keep mappings from copy to origin, and from origin to copy. --- .../include/CGAL/Combinatorial_map.h | 58 +++++++++++++------ .../include/CGAL/Generalized_map.h | 54 +++++++++++------ .../CGAL/Surface_mesh_curve_topology.h | 8 +-- 3 files changed, 79 insertions(+), 41 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 09301452deb..ff1456c25c7 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -208,7 +208,7 @@ namespace CGAL { CGAL_assertion(number_of_darts()==0); } - /** Copy the given combinatorial map into *this. + /** Copy the given combinatorial map 'amap' into *this. * Note that both CMap can have different dimensions and/or non void attributes. * @param amap the combinatorial map to copy. * @post *this is valid. @@ -223,7 +223,10 @@ namespace CGAL { const PointConverter& pointconverter, boost::unordered_map :: - Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { typedef Combinatorial_map_base CMap2; this->clear(); @@ -248,26 +251,31 @@ namespace CGAL { // (here we cannot use CGAL::Unique_hash_map because it does not provide // iterators... boost::unordered_map - local_dartmap; - if (dart_mapping==NULL) - { dart_mapping=&local_dartmap; } - + local_dartmap; + if (origin_to_copy==NULL) // Used local_dartmap if user does not provides its own unordered_map + { origin_to_copy=&local_dartmap; } + + Dart_handle new_dart; for (typename CMap2::Dart_const_range::const_iterator it=amap.darts().begin(), itend=amap.darts().end(); it!=itend; ++it) { - (*dart_mapping)[it]=mdarts.emplace(); - init_dart((*dart_mapping)[it], amap.get_marks(it)); + new_dart=mdarts.emplace(); + init_dart(new_dart, amap.get_marks(it)); + + (*origin_to_copy)[it]=new_dart; + if (copy_to_origin!=NULL) { (*copy_to_origin)[new_dart]=it; } + internal::Copy_dart_info_functor::run (static_cast(amap), static_cast(*this), - it, (*dart_mapping)[it], dartinfoconverter); + it, new_dart, dartinfoconverter); } unsigned int min_dim=(dimension - ::iterator dartmap_iter, dartmap_iter_end=dart_mapping->end(); - for (dartmap_iter=dart_mapping->begin(); dartmap_iter!=dartmap_iter_end; + ::iterator dartmap_iter, dartmap_iter_end=origin_to_copy->end(); + for (dartmap_iter=origin_to_copy->begin(); dartmap_iter!=dartmap_iter_end; ++dartmap_iter) { for (unsigned int i=0; i<=min_dim; i++) @@ -276,13 +284,13 @@ namespace CGAL { (dartmap_iter->first)<(amap.beta(dartmap_iter->first,i))) { basic_link_beta(dartmap_iter->second, - (*dart_mapping)[amap.beta(dartmap_iter->first,i)], i); + (*origin_to_copy)[amap.beta(dartmap_iter->first,i)], i); } } } /** Copy attributes */ - for (dartmap_iter=dart_mapping->begin(); dartmap_iter!=dartmap_iter_end; + for (dartmap_iter=origin_to_copy->begin(); dartmap_iter!=dartmap_iter_end; ++dartmap_iter) { Helper::template Foreach_enabled_attributes @@ -301,13 +309,17 @@ namespace CGAL { void copy(const Combinatorial_map_base& amap, boost::unordered_map ::Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Storage2>::Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { CGAL::cpp11::tuple<> converters; Default_converter_dart_info dartinfoconverter; Default_converter_cmap_0attributes_with_point pointconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } template ::Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Storage2>::Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { Default_converter_cmap_0attributes_with_point pointconverter; Default_converter_dart_info dartinfoconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } template ::Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Storage2>::Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { Default_converter_cmap_0attributes_with_point pointconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } // Copy constructor from a map having exactly the same type. diff --git a/Generalized_map/include/CGAL/Generalized_map.h b/Generalized_map/include/CGAL/Generalized_map.h index dfabfa6cec1..d8cf8361a4e 100644 --- a/Generalized_map/include/CGAL/Generalized_map.h +++ b/Generalized_map/include/CGAL/Generalized_map.h @@ -200,7 +200,10 @@ namespace CGAL { const PointConverter& pointconverter, boost::unordered_map :: - Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { typedef Generalized_map_base GMap2; this->clear(); @@ -224,25 +227,30 @@ namespace CGAL { // iterators... boost::unordered_map local_dartmap; - if (dart_mapping==NULL) - { dart_mapping=&local_dartmap; } + if (origin_to_copy==NULL) // Used local_dartmap if user does not provides its own unordered_map + { origin_to_copy=&local_dartmap; } + Dart_handle new_dart; for (typename GMap2::Dart_const_range::const_iterator it=amap.darts().begin(), itend=amap.darts().end(); it!=itend; ++it) { - (*dart_mapping)[it]=mdarts.emplace(); - init_dart((*dart_mapping)[it], amap.get_marks(it)); + new_dart=mdarts.emplace(); + init_dart(new_dart, amap.get_marks(it)); + + (*origin_to_copy)[it]=new_dart; + if (copy_to_origin!=NULL) { (*copy_to_origin)[new_dart]=it; } + internal::Copy_dart_info_functor:: run(static_cast(amap), static_cast(*this), - it, (*dart_mapping)[it], dartinfoconverter); + it, new_dart, dartinfoconverter); } unsigned int min_dim=(dimension - ::iterator dartmap_iter, dartmap_iter_end=dart_mapping->end(); - for (dartmap_iter=dart_mapping->begin(); dartmap_iter!=dartmap_iter_end; + ::iterator dartmap_iter, dartmap_iter_end=origin_to_copy->end(); + for (dartmap_iter=origin_to_copy->begin(); dartmap_iter!=dartmap_iter_end; ++dartmap_iter) { for (unsigned int i=0; i<=min_dim; i++) @@ -251,13 +259,13 @@ namespace CGAL { (dartmap_iter->first)<(amap.alpha(dartmap_iter->first,i))) { basic_link_alpha(dartmap_iter->second, - (*dart_mapping)[amap.alpha(dartmap_iter->first,i)], i); + (*origin_to_copy)[amap.alpha(dartmap_iter->first,i)], i); } } } /** Copy attributes */ - for (dartmap_iter=dart_mapping->begin(); dartmap_iter!=dartmap_iter_end; + for (dartmap_iter=origin_to_copy->begin(); dartmap_iter!=dartmap_iter_end; ++dartmap_iter) { Helper::template Foreach_enabled_attributes @@ -268,7 +276,7 @@ namespace CGAL { converters, pointconverter); } - CGAL_assertion (is_valid () == 1); + CGAL_assertion(is_valid()); } template & amap, boost::unordered_map :: - Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { CGAL::cpp11::tuple<> converters; Default_converter_dart_info dartinfoconverter; Default_converter_cmap_0attributes_with_point pointconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } template :: - Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { Default_converter_cmap_0attributes_with_point pointconverter; Default_converter_dart_info dartinfoconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } template :: - Dart_const_handle, Dart_handle>* dart_mapping=NULL) + Dart_const_handle, Dart_handle>* origin_to_copy=NULL, + boost::unordered_map + ::Dart_const_handle>* copy_to_origin=NULL) { Default_converter_cmap_0attributes_with_point pointconverter; - copy(amap, converters, dartinfoconverter, pointconverter, dart_mapping); + copy(amap, converters, dartinfoconverter, pointconverter, + origin_to_copy, copy_to_origin); } // Copy constructor from a map having exactly the same type. diff --git a/Surface_mesh_topology/include/CGAL/Surface_mesh_curve_topology.h b/Surface_mesh_topology/include/CGAL/Surface_mesh_curve_topology.h index 49d242687dd..0cb8b877495 100644 --- a/Surface_mesh_topology/include/CGAL/Surface_mesh_curve_topology.h +++ b/Surface_mesh_topology/include/CGAL/Surface_mesh_curve_topology.h @@ -100,14 +100,12 @@ namespace CGAL { boost::unordered_map origin_to_copy; - // We copy the original map, while keeping a mapping between darts. - m_map.copy(m_original_map, &origin_to_copy); - // The mapping between darts of the copy into darts of the original map. boost::unordered_map copy_to_origin; - for (auto it=origin_to_copy.begin(); it!=origin_to_copy.end(); ++it) - { copy_to_origin[it->second]=it->first; } + + // We copy the original map, while keeping mappings between darts. + m_map.copy(m_original_map, &origin_to_copy, ©_to_origin); if (display_time) {