From 6cc05e3920a0827076dd7f24e82be413e9c97a82 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 3 Jun 2013 18:50:35 +0200 Subject: [PATCH] wip copy --- .../include/CGAL/Combinatorial_map.h | 4 +- .../Combinatorial_map_copy_functors.h | 38 ++- .../Combinatorial_map_internal_functors.h | 4 +- .../include/CGAL/Linear_cell_complex.h | 119 ++----- .../Linear_cell_complex_copy_functors.h | 318 ++++++++++++++++-- 5 files changed, 341 insertions(+), 142 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 27beb6e8d21..11f6375762c 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -159,7 +159,7 @@ namespace CGAL { * @post *this is valid. */ template - void copy(const CMap2& amap, Converters& converters) + void copy(const CMap2& amap, const Converters& converters) { this->clear(); @@ -233,7 +233,7 @@ namespace CGAL { } template - void copy(const CMap2 & amap) + void copy(const CMap2& amap) { CGAL::cpp11::tuple<> converters; return copy< CMap2, CGAL::cpp11::tuple<> >(amap, converters); diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h index 49e89892dd1..761c2eb53a9 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -38,7 +38,8 @@ namespace internal // **************************************************************************** // Map1 is the existing map, to convert into map2. // Case where the two i-attributes are non void. -template< typename Map1, typename Map2, unsigned int i, typename Info1, typename Info2 > +template< typename Map1, typename Map2, unsigned int i, + typename Info1, typename Info2 > struct Default_converter_two_non_void_attributes_cmap { static typename Map2::template Attribute_handle::type @@ -88,10 +89,12 @@ template::type - run( Map2* cmap2, typename Map1::Dart_const_handle dh1, - const Converters& converters) + run( const Map1* cmap1, Map2* cmap2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2, const Converters& converters) { - return CGAL::Default_converter_cmap_attributes() (*cmap2, dh1); + return + CGAL::Default_converter_cmap_attributes() + (*cmap1, *cmap2, dh1, dh2); } }; @@ -99,10 +102,10 @@ template struct Convert_attribute_functor { static typename Map2::template Attribute_handle::type - run( Map2* cmap2, typename Map1::Dart_const_handle dh1, - const Converters& converters) + run( const Map1* cmap1, Map2* cmap2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2, const Converters& converters) { - return CGAL::cpp11::get(converters) (*cmap2, dh1); + return CGAL::cpp11::get(converters) (*cmap1, *cmap2, dh1, dh2); } }; @@ -122,7 +125,7 @@ struct Copy_attributes_functor { typename Map2::template Attribute_handle::type res=Convert_attribute_functor:: - run(cmap2,dh1,converters); + run(cmap1, cmap2, dh1, dh2, converters); if ( res!=NULL ) cmap2->template set_attribute(dh2, res); @@ -140,7 +143,8 @@ template< typename Map1, typename Map2, unsigned int i, struct Default_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (Map2& map2, typename Map1::Dart_const_handle dh1) const + (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const { return internal::Default_converter_two_non_void_attributes_cmap :: run(map2, dh1->template attribute()); } @@ -151,7 +155,8 @@ template< typename Map1, typename Map2, unsigned int i, struct Default_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) const + (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const { return NULL; } }; @@ -160,7 +165,8 @@ template< typename Map1, typename Map2, unsigned int i, struct Default_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) const + (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const { return NULL; } }; @@ -168,7 +174,8 @@ template< typename Map1, typename Map2, unsigned int i> struct Default_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) const + (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const { return NULL; } }; @@ -181,12 +188,13 @@ template< typename Map1, typename Map2, unsigned int i> struct Cast_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (Map2& map2, typename Map1::Dart_const_handle dh) const + (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const { - if ( dh->template attribute()!=NULL ) + if ( dh1->template attribute()!=NULL ) return map2.template create_attribute ((typename Map2::template Attribute_type::type::Info) - dh->template attribute()->info()); + dh1->template attribute()->info()); return map2.template create_attribute(); } 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 f71354795f7..171c558fb28 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -459,8 +459,8 @@ template struct Is_same_attribute_functor { - static bool const run(typename Map1::Dart_const_handle dh1, - typename Map2::Dart_const_handle dh2) + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle dh2) { if (dh1->template attribute()==NULL && dh2->template attribute()==NULL) diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index 17d90689327..42decf83618 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -25,6 +25,7 @@ #include #include #include +#include #include namespace CGAL { @@ -81,6 +82,8 @@ namespace CGAL { typedef typename Base::template Attribute_const_range<0>::type Vertex_attribute_const_range; + typedef typename Base::size_type size_type; + /// To use previous definition of create_dart methods. using Base::create_dart; @@ -92,114 +95,34 @@ namespace CGAL { * @param alcc the linear cell complex to copy. * @post *this is valid. */ - template - void copy(const Linear_cell_complex & alcc, - Converters& converters) + template + void copy(const LCC2& alcc, const Converters& converters) { - typedef Linear_cell_complex LCC2; + typedef typename CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute + ::type Converters2; - this->clear(); - - this->mnb_used_marks = amap.mnb_used_marks; - this->mmask_marks = amap.mmask_marks; - - for (size_type i = 0; i < NB_MARKS; ++i) - { - this->mfree_marks_stack[i] = amap.mfree_marks_stack[i]; - this->mindex_marks[i] = amap.mindex_marks[i]; - this->mnb_marked_darts[i] = amap.mnb_marked_darts[i]; - this->mnb_times_reserved_marks[i] = amap.mnb_times_reserved_marks[i]; - } - - // We must do this ony once, but problem because null_dart_handle - // is static ! - if (mnull_dart_container.empty()) - { - null_dart_handle = - mnull_dart_container.emplace(amap.null_dart_handle->mmarks); - - for (unsigned int i = 0; i <= dimension; ++i) - { - null_dart_handle->unlink_beta(i); - } - } - else - null_dart_handle->mmarks = amap.null_dart_handle->mmarks; - - // Create an mapping between darts of the two maps (originals->copies). - std::map dartmap; - - for (typename CMap2::Dart_const_range::const_iterator - it=amap.darts().begin(), itend=amap.darts().end(); - it!=itend; ++it) - { - dartmap[it]=mdarts.emplace(it->mmarks); - } - - unsigned int min_dim= - (dimension - ::iterator dartmap_iter, dartmap_iter_end=dartmap.end(); - for (dartmap_iter=dartmap.begin(); dartmap_iter!=dartmap_iter_end; - ++dartmap_iter) - { - for (unsigned int i=0; i<=min_dim; i++) - { - if (dartmap_iter->first->beta(i)!=CMap2::null_dart_handle && - (dartmap_iter->first)<(dartmap_iter->first->beta(i))) - { - basic_link_beta(dartmap_iter->second, - dartmap[dartmap_iter->first->beta(i)], i); - } - } - } - - /** Copy attributes */ - for (dartmap_iter=dartmap.begin(); dartmap_iter!=dartmap_iter_end; - ++dartmap_iter) - { - Helper::template Foreach_enabled_attributes - < internal::Copy_attributes_functor >:: - run(&amap, this, dartmap_iter->first, dartmap_iter->second, - converters); - // Ici tester si pas attribut alors le créer et associer le Point - if ( dartmap_iter->second->attribute<0>()==NULL ) - { - set_attribute<0>(dartmap_iter->second, create_attribute<0>()); - Set_point_if_exist::type, - typename LCC2::template Attribute_type<0>::type>:: - run( dartmap_iter->first->template attribute<0>(), - dartmap_iter->second->template attribute<0>() ); - } - } - - CGAL_assertion (is_valid () == 1); + Converters2 converters2=CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute + ::run(converters); + Base::template copy(alcc, converters2); } - template - void copy(const Linear_cell_complex & alcc) + template + void copy(const LCC2& alcc) { CGAL::cpp11::tuple<> converters; - return copy< dbis,Refsbis,Itemsbis,Allocbis,CGAL::cpp11::tuple<> > - (amap, converters); + return copy >(alcc, converters); } Linear_cell_complex(const Self & alcc) - { copy(alcc); } + { copy(alcc); } - template < class LCC > - Linear_cell_complex(const LCC & alcc) - { Base::copy(alcc);} + template < class LCC2 > + Linear_cell_complex(const LCC2& alcc) + { copy(alcc);} - template < class LCC, typename Converters > - Linear_cell_complex(const LCC & alcc, Converters& converters) - { Base::copy(alcc, converters);} + template < class LCC2, typename Converters > + Linear_cell_complex(const LCC2& alcc, Converters& converters) + { copy(alcc, converters);} /** Create a vertex attribute. * @return an handle on the new attribute. @@ -808,7 +731,7 @@ namespace CGAL { { return insert_point_in_cell(dh, barycenter(dh)); } /** Compute the dual of a Linear_cell_complex. - * @param amap the lcc in which we build the dual of this lcc. + * @param alcc the lcc in which we build the dual of this lcc. * @param adart a dart of the initial lcc, NULL by default. * @return adart of the dual lcc, the dual of adart if adart!=NULL, * any dart otherwise. diff --git a/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h b/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h index 1406aa3ffa8..2133d81aedd 100644 --- a/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h +++ b/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h @@ -30,6 +30,11 @@ */ namespace CGAL { +template< typename LCC1, typename LCC2> +struct Attribute_converter_lcc_vertex_attributes; + +template< typename Functor, typename LCC1, typename LCC2> +struct Modify_attribute_converter_lcc_vertex_attributes; // **************************************************************************** namespace internal { @@ -62,7 +67,8 @@ struct Set_point_if_possible }; template -struct Set_point_if_possible, Dimension_tag<2> > +struct Set_point_if_possible, Dimension_tag<2> > { static void run(const Point1& p1, Point2& p2) { @@ -72,7 +78,8 @@ struct Set_point_if_possible, Dimension_tag<2> }; template -struct Set_point_if_possible, Dimension_tag<3> > +struct Set_point_if_possible, Dimension_tag<3> > { static void run(const Point1& p1, Point2& p2) { @@ -111,68 +118,329 @@ struct Set_point_if_exist {} }; // **************************************************************************** -// Map1 is the existing map, to convert into map2. +#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES +template > +struct Modify_tuple_of_converter_for_vertex_attribute; + +// empty tuple and empty res: res is a tuple with only +// Point_converter_lcc_vertex_attributes +template +struct Modify_tuple_of_converter_for_vertex_attribute + , CGAL::cpp11::tuple<> > +{ + typedef CGAL::cpp11::tuple + > type; + + static type run(const CGAL::cpp11::tuple<>&) + { return type(); } +}; + +// empty tuple but non empty res: we already have modified vertex attribute +template < typename LCC1, typename LCC2, class ... Res > +struct Modify_tuple_of_converter_for_vertex_attribute + , CGAL::cpp11::tuple > +{ + typedef CGAL::cpp11::tuple type; + + static type run(const CGAL::cpp11::tuple<>&) + { CGAL_assertion(false); return type(); } +}; + +// empty res but non empty empty tuple, Firsttype is vertex attribute. +template < typename LCC1, typename LCC2, class Firsttype, class ... Tuple > +struct Modify_tuple_of_converter_for_vertex_attribute + , CGAL::cpp11::tuple<> > +{ + typedef typename Modify_tuple_of_converter_for_vertex_attribute + , + CGAL::cpp11::tuple + >:: + type type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +// non empty res, non empty tuple, we copy +template < typename LCC1, typename LCC2, class Firsttype, + class ... Tuple, class ... Res > +struct Modify_tuple_of_converter_for_vertex_attribute + , + CGAL::cpp11::tuple > +{ + typedef typename Modify_tuple_of_converter_for_vertex_attribute + , + CGAL::cpp11::tuple >::type type; + + static type run(const CGAL::cpp11::tuple<>&) + { CGAL_assertion(false); return type; } +}; +#else // CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES +template +struct Modify_tuple_of_converter_for_vertex_attribute; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + > type; + + static type run(const CGAL::cpp11::tuple<>&) + { return type(); } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + > type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3> + type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4> + type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4, + T5> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4, + T5,T6> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4, + T5,T6,T7> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4, + T5,T6,T7,T8> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; + +template +struct Modify_tuple_of_converter_for_vertex_attribute + > { + typedef CGAL::cpp11::tuple + ,T2,T3,T4, + T5,T6,T7,T8,T9> type; + + static type run(const CGAL::cpp11::tuple& t) + { + return type + (Modify_attribute_converter_lcc_vertex_attributes + (t.get_head()), + t.get_tail()); + } +}; +#endif +// **************************************************************************** +} // namespace internal +// LCC1 is the existing map, to convert into map2. +// **************************************************************************** +template< typename LCC1, typename LCC2> +struct Attribute_converter_lcc_vertex_attributes +{ + typename LCC2::Vertex_attribute_handle operator() + (const LCC1& map1, LCC2& map2, typename LCC1::Dart_const_handle dh1, + typename LCC2::Dart_handle dh2) const + { + map2.set_vertex_attribute(dh2, map2.create_vertex_attribute()); + internal::Set_point_if_exist:: + run( dh1->vertex_attribute(), dh2->vertex_attribute() ); + return dh2->vertex_attribute(); + } +}; +// **************************************************************************** +template< typename Functor, typename LCC1, typename LCC2> +struct Modify_attribute_converter_lcc_vertex_attributes +{ + Modify_attribute_converter_lcc_vertex_attributes(const Functor& f): myf(f) + {} + + typename LCC2::Vertex_attribute_handle operator() + (const LCC1& map1, LCC2& map2, typename LCC1::Dart_const_handle dh1, + typename LCC2::Dart_handle dh2) const + { + myf(map1, map2, dh1, dh2); + if ( dh2->vertex_attribute()==NULL ) + map2.set_vertex_attribute(dh2, map2.create_vertex_attribute()); + internal::Set_point_if_exist:: + run( dh1->vertex_attribute(), dh2->vertex_attribute() ); + return dh2->vertex_attribute(); + } + private: + Functor myf; +}; // Case where the two i-attributes are non void. -template< typename Map1, typename Map2, unsigned int i, +template< typename LCC1, typename LCC2, unsigned int i, typename Info1, typename Info2, typename Point2 > struct Default_converter_two_non_void_attributes_lcc { // Here Info1!=Info2 but Point2!=CGAL::Void (thus Linear_cell_complex) - static typename Map2::template Attribute_handle::type - run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) + static typename LCC2::template Attribute_handle::type + run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) { - typename Map2::template Attribute_handle::type + typename LCC2::template Attribute_handle::type res=map2.template create_attribute(); if ( ah!=NULL ) { // Copy the point of ah if it exists and have same dimension - Set_point_if_exist::type, - typename Map2::template Attribute_type::type>::run( *ah, *res ); + CGAL::internal::Set_point_if_exist::type, + typename LCC2::template Attribute_type::type>::run( *ah, *res ); } return res; } }; -template< typename Map1, typename Map2, unsigned int i, typename Info, typename Point2 > -struct Default_converter_two_non_void_attributes_lcc +template< typename LCC1, typename LCC2, unsigned int i, typename Info, typename Point2 > +struct Default_converter_two_non_void_attributes_lcc { // Here Info1==Info2 but Point2!=CGAL::Void (thus Linear_cell_complex) - static typename Map2::template Attribute_handle::type - run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) + static typename LCC2::template Attribute_handle::type + run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) { - typename Map2::template Attribute_handle::type + typename LCC2::template Attribute_handle::type res=map2.template create_attribute(); if ( ah!=NULL ) { res->info()=ah->info(); // Copy the point of ah if it exists and have same dimension - Set_point_if_exist::type, - typename Map2::template Attribute_type::type>::run( *ah, *res ); + CGAL::internal::Set_point_if_exist::type, + typename LCC2::template Attribute_type::type>::run( *ah, *res ); } return res; } }; -template< typename Map1, typename Map2, unsigned int i, typename Point2 > -struct Default_converter_two_non_void_attributes_lcc +template< typename LCC1, typename LCC2, unsigned int i, typename Point2 > +struct Default_converter_two_non_void_attributes_lcc { // Here Info1==Info2==void but Point2!=CGAL::Void (thus Linear_cell_complex) - static typename Map2::template Attribute_handle::type - run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) + static typename LCC2::template Attribute_handle::type + run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) { - typename Map2::template Attribute_handle::type res= + typename LCC2::template Attribute_handle::type res= map2.template create_attribute(); if ( ah!=NULL ) { // Copy the point of ah if it exists and have same dimension - Set_point_if_exist::type, - typename Map2::template Attribute_type::type>:: + CGAL::internal::Set_point_if_exist::type, + typename LCC2::template Attribute_type::type>:: run( *ah, *res ); } return res; } }; - // **************************************************************************** -} // namespace internal } // namespace CGAL #endif // CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H