From 6f5e400039b2d41bacd009f0d284435501e1d4a6 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 May 2013 14:05:16 +0200 Subject: [PATCH 01/21] Add copy constructor, operator= and swap operations. (Copied from Combinatorial_map_copy-gdamiand, to start from a fresh copy of master) --- .../include/CGAL/Combinatorial_map.h | 321 ++++++++++++++++++ .../Combinatorial_map_internal_functors.h | 172 ++++++++++ 2 files changed, 493 insertions(+) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index a3a1cc76914..3d6fcfa701d 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -30,6 +30,7 @@ #include #include #include +#include #include #include #include @@ -60,6 +61,9 @@ namespace CGAL { friend struct CGAL::internal::Call_split_functor; public: + template < unsigned int A, class B, class I, class D > + friend class Combinatorial_map_base; + /// Types definition typedef Combinatorial_map_base Self; @@ -148,6 +152,138 @@ namespace CGAL { CGAL_assertion(number_of_darts()==0); } + /** Copy the given combinatorial map 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. + */ + template + void copy(const Combinatorial_map_base & amap) + { + typedef Combinatorial_map_base CMap2; + + 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) + { + Dart_handle dh2 = mdarts.emplace(it->mmarks); + dartmap.insert(std::pair + (it, dh2)); + } + + 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(this, &amap, dartmap_iter->second, dartmap_iter->first); + } + + CGAL_assertion (is_valid () == 1); + } + + // Copy constructor from a map having exactly the same type. + Combinatorial_map_base (const Self & amap) + { copy(amap); } + + // "Copy constructor" from a map having different type. + template + Combinatorial_map_base(const Combinatorial_map_base + & amap) + { copy(amap); } + + /** Affectation operation. Copies one map to the other. + * @param amap a combinatorial map. + * @return A copy of that combinatorial map. + */ + Self & operator= (const Self & amap) + { + if (this!=&amap) + { + Self tmp(amap); + this->swap(tmp); + } + return *this; + } + + /** Swap this combinatorial map with amap, a second combinatorial map. + * Note that the two maps have exactly the same type. + * @param amap a combinatorial map. + */ + void swap(Self & amap) + { + if (this!=&amap) + { + amap.mdarts.swap(mdarts); + + std::swap_ranges(mnb_times_reserved_marks, + mnb_times_reserved_marks+NB_MARKS, + amap.mnb_times_reserved_marks); + std::swap(mmask_marks,amap.mmask_marks); + std::swap(mnb_used_marks, amap.mnb_used_marks); + std::swap_ranges(mindex_marks,mindex_marks+NB_MARKS, + amap.mindex_marks); + std::swap_ranges(mfree_marks_stack, mfree_marks_stack+NB_MARKS, + amap.mfree_marks_stack); + std::swap_ranges(mused_marks_stack,mused_marks_stack+NB_MARKS, + amap.mused_marks_stack); + std::swap_ranges(mnb_marked_darts,mnb_marked_darts+NB_MARKS, + amap.mnb_marked_darts); + mattribute_containers.swap(amap.mattribute_containers); + } + } + /** Clear the combinatorial map. Remove all darts and all attributes. * Note that reserved marks are not free. */ @@ -3081,6 +3217,191 @@ namespace CGAL { return res; } + + /** Test if the connected component of cmap containing dart dh1 is + * isomorphic to the connected component of map2 containing dart dh2, + * starting from dh1 and dh2. + * @param dh1 initial dart for this map + * @param map2 the second combinatorial map + * @param dh2 initial dart for map2 + * @param testAttributes Boolean to test the equality of attributes (true) + * or not (false) + * @return true iff the cc of map is isomorphic to the cc of map2 starting + * from dh1 and dh2; by testing the equality of attributes if + * testAttributes is true + */ + template + bool are_cc_isomorphic(Dart_const_handle dh1, + const Combinatorial_map_base + & map2, + typename Combinatorial_map_base + ::Dart_const_handle dh2, + bool testAttributes=true) const + { + CGAL_assertion(dimension==map2.dimension); + CGAL_assertion(dh1!=NULL && dh2!=NULL); + + typedef Combinatorial_map_base Map2; + + bool match = true; + + // Two stacks used to run through the two maps. + std::deque< Dart_const_handle > toTreat1; + std::deque< typename Map2::Dart_const_handle > toTreat2; + + int m1 = get_new_mark(); + int m2 = map2.get_new_mark(); + + toTreat1.push(dh1); + toTreat2.push(dh2); + + Dart_const_handle current; + typename Map2::Dart_const_handle other; + + int i = 0; + CGAL::Unique_hash_map bijection; + + while (match && !toTreat1.empty()) + { + // Next dart + current = toTreat1.top(); + toTreat1.pop(); + other = toTreat2.top(); + toTreat2.pop(); + + if (!is_marked(current, m1)) + { + if (map2.is_marked(other, m2)) + match=false; + else + { + bijection[current] = other; + + mark(current, m1); + map2.mark(other, m2); + + if (testAttributes) + { + Helper::template Foreach_enabled_attributes + < internal::Test_is_same_attribute_functor >:: + run(current, other); + if ( !internal::Test_is_same_attribute_functor:: + value ) + match=false; + } + + // We test if the injection is valid with its neighboors. + // We go out as soon as it is not satisfied. + for (i = 0; match && i <= dimension; ++i) + { + if (current->is_free(i)) + { + if (!other->is_free(i)) + match = false; + } + else + { + if (other->is_free(i)) + match = false; + else + { + if (is_marked(current->beta (i), m1) != + map2.is_marked(other->beta(i), m2)) + match = false; + else + { + if (!is_marked (current->beta(i), m1)) + { + toTreat1.push(current->beta (i)); + toTreat2.push(other->beta (i)); + } + else + { + if (bijection[current->beta(i)] != + other->beta(i)) + match = false; + } + } + } + } + } + } + } + else + { + if (!map2.is_marked(other, m2)) + match = false; + } + } + + // Here we unmark all the marked darts. + while (!toTreat1.empty()) + toTreat1.pop(); + while (!toTreat2.empty()) + toTreat2.pop(); + + toTreat1.push(dh1); + toTreat2.push(dh2); + + while (!toTreat1.empty()) + { + current = toTreat1.top(); + toTreat1.pop(); + other = toTreat2.top(); + toTreat2.pop(); + + unmark(current, m1); + map2.unmark(other, m2); + + for (i = 0; match && i <= dimension; ++i) + { + if (!current->is_free(i) && is_marked(current->beta(i), m1)) + { + CGAL_assertion(!other->is_free(i) && + map2.is_marked(other->beta(i), m2)); + toTreat1.push(current->beta(i)); + toTreat2.push(other->beta(i)); + } + } + } + + free_mark(m1); + map2.free_mark(m2); + + return match; + } + + /** Test if this cmap is isomorphic to map2. + * @pre cmap is connected. + * @param map2 the second combinatorial map + * @param testAttributes Boolean to test the equality of attributes (true) + * or not (false) + * @return true iff this map is isomorphic to map2, testing the equality + * of attributes if testAttributes is true + */ + template + bool is_isomorphic_to(const Combinatorial_map_base + & map2, + bool testAttributes=true) + { + if ( dimension!=map2.dimension ) return false; + + Dart_const_handle d1=darts().begin(); + + for (typename Combinatorial_map_base:: + Dart_range::const_iterator it(map2.darts().begin()), + itend(map2.darts().end()); it!=itend; ++it) + { + if (are_cc_isomorphic(d1, map2, it, testAttributes)) + { + return true; + } + } + + return false; + } + /// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle. static Dart_handle null_dart_handle; 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..6ce75ec1662 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,178 @@ struct Set_i_attribute_of_dart_functor {} }; // **************************************************************************** +// Functor allowing to copy attributes whey info are convertible +// TODO replace these version by using is_constructible +// if no support for gcc11, use this simplified version ? (same type) +template +struct Affectation_if_same_type +{ + static void run(T1&, const T2&) + {} +}; + +template +struct Affectation_if_same_type +{ + static void run(T1&e1, const T1&e2) + { e1=e2; } +}; + +// Case of two non void type +template +struct Copy_attr_functor +{ + static void const run(Map1* cmap1, const Map2* cmap2, + typename Map1::Dart_handle dh1, + typename Map2::Dart_const_handle dh2) + { + CGAL_static_assertion(i<=Map2::dimension); + if (dh1->template attribute()==NULL && + dh2->template attribute()!=NULL) + { + cmap1->template + set_attribute(dh1, cmap1->template create_attribute()); + Affectation_if_same_type:: + run(dh1->template attribute()->info(), + dh2->template attribute()->info()); + } + } +}; + +// Case T1==void +template +struct Copy_attr_functor +{ + static void const run(Map1*, const Map2*, + typename Map1::Dart_handle, + typename Map2::Dart_const_handle) + {} +}; + +// Case T2==void +template +struct Copy_attr_functor +{ + static void const run(Map1*, const Map2*, + typename Map1::Dart_handle, + typename Map2::Dart_const_handle) + {} +}; + +// Case T1==T2==void +template +struct Copy_attr_functor +{ + static void const run(Map1*, const Map2*, + typename Map1::Dart_handle, + typename Map2::Dart_const_handle) + {} +}; + +/// Copy enabled attributes from one cmap to other +template +struct Copy_attributes_functor{ + template + static void run( Map1* cmap1, + const Map2* cmap2, + typename Map1::Dart_handle dh1, + typename Map2::Dart_const_handle dh2 ) + { + Copy_attr_functor::type, + typename Map2::Helper::template Attribute_type::type> + ::run(cmap1, cmap2, dh1, dh2); + } +}; +// **************************************************************************** +// Functor allowing to test if two info are the same or not +template +struct Is_same_info +{ + static bool run(const T1&, const T2&) + { return false; } +}; + +template +struct Is_same_info +{ + static bool run(const T1&e1, const T1&e2) + { return e1==e2; } +}; + +// Case of two non void type +template +struct Is_same_attribute_functor +{ + static bool const run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle dh2) + { + if (dh1->template attribute()==NULL && + dh2->template attribute()==NULL) + return true; + + if (dh1->template attribute()==NULL || + dh2->template attribute()==NULL) + return false; + + return + Is_same_info:: + run(dh1->template attribute()->info(), + dh2->template attribute()->info()); + } +}; + +// Case T1==void +template +struct Is_same_attribute_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle dh2) + { return dh2->template attribute()==NULL; } +}; + +// Case T2==void +template +struct Is_same_attribute_functor +{ + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle) + { return dh1->template attribute()==NULL; } +}; + +// Case T1==T2==void +template +struct Is_same_attribute_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return true; } +}; + +/// Test if the two darts are associated with the same attribute. +template +struct Test_is_same_attribute_functor +{ + template + static void run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle dh2 ) + { + if (value) + value = Is_same_attribute_functor + ::type, + typename Map2::Helper::template Attribute_type::type, + i>::run(dh1, dh2); + } + static bool value; +}; +template +bool Test_is_same_attribute_functor::value = true; +// **************************************************************************** // Beta functor, used to combine several beta. #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template From bac62f48fc32683ac359ce9dcfb5f0d827b99b56 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 May 2013 14:38:53 +0200 Subject: [PATCH 02/21] Add constructor in derived cmap and lcc classes --- Combinatorial_map/include/CGAL/Combinatorial_map.h | 10 ++++++++++ Linear_cell_complex/include/CGAL/Linear_cell_complex.h | 10 ++++++++++ 2 files changed, 20 insertions(+) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 3d6fcfa701d..a871a32440c 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -3470,6 +3470,16 @@ namespace CGAL { typedef typename Base::Dart_handle Dart_handle; typedef typename Base::Dart_const_handle Dart_const_handle; typedef typename Base::Alloc Alloc; + + Combinatorial_map() : Base() + {} + + template < class CMap > + Combinatorial_map(const CMap & amap) : Base(amap) + {} + + Combinatorial_map(const Self & amap) : Base(amap) + {} }; } // namespace CGAL diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index 4f9505206ee..5613414da8c 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -84,6 +84,16 @@ namespace CGAL { /// To use previous definition of create_dart methods. using Base::create_dart; + Linear_cell_complex() : Base() + {} + + template < class LCC > + Linear_cell_complex(const LCC & alcc) : Base(alcc) + {} + + Linear_cell_complex(const Self & alcc) : Base(alcc) + {} + /** Create a vertex attribute. * @return an handle on the new attribute. */ From 82136efdfa8f389aac9c321058941c9aff82e4b2 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 30 May 2013 16:26:27 +0200 Subject: [PATCH 03/21] Start tests for copy of cmap --- .../include/CGAL/Combinatorial_map.h | 80 ++++++++++--------- .../Combinatorial_map_test.cpp | 33 +++++--- 2 files changed, 64 insertions(+), 49 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index a871a32440c..4e4530a69b3 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -197,9 +197,7 @@ namespace CGAL { it=amap.darts().begin(), itend=amap.darts().end(); it!=itend; ++it) { - Dart_handle dh2 = mdarts.emplace(it->mmarks); - dartmap.insert(std::pair - (it, dh2)); + dartmap[it]=mdarts.emplace(it->mmarks); } unsigned int min_dim= @@ -3252,8 +3250,8 @@ namespace CGAL { int m1 = get_new_mark(); int m2 = map2.get_new_mark(); - toTreat1.push(dh1); - toTreat2.push(dh2); + toTreat1.push_back(dh1); + toTreat2.push_back(dh2); Dart_const_handle current; typename Map2::Dart_const_handle other; @@ -3265,10 +3263,10 @@ namespace CGAL { while (match && !toTreat1.empty()) { // Next dart - current = toTreat1.top(); - toTreat1.pop(); - other = toTreat2.top(); - toTreat2.pop(); + current = toTreat1.front(); + toTreat1.pop_front(); + other = toTreat2.front(); + toTreat2.pop_front(); if (!is_marked(current, m1)) { @@ -3295,37 +3293,49 @@ namespace CGAL { // We go out as soon as it is not satisfied. for (i = 0; match && i <= dimension; ++i) { - if (current->is_free(i)) + if ( i>Map2::dimension ) { - if (!other->is_free(i)) - match = false; + if (!current->is_free(i)) match=false; } else { - if (other->is_free(i)) - match = false; + if (current->is_free(i)) + { + if (!other->is_free(i)) + match = false; + } else { - if (is_marked(current->beta (i), m1) != - map2.is_marked(other->beta(i), m2)) + if (other->is_free(i)) match = false; else { - if (!is_marked (current->beta(i), m1)) - { - toTreat1.push(current->beta (i)); - toTreat2.push(other->beta (i)); - } + if (is_marked(current->beta (i), m1) != + map2.is_marked(other->beta(i), m2)) + match = false; else { - if (bijection[current->beta(i)] != - other->beta(i)) - match = false; + if (!is_marked (current->beta(i), m1)) + { + toTreat1.push_back(current->beta (i)); + toTreat2.push_back(other->beta (i)); + } + else + { + if (bijection[current->beta(i)] != + other->beta(i)) + match = false; + } } } } } } + // Now we test if the second map has more beta links than the first + for ( i=dimension+1; match && i<=Map2::dimension; ++i ) + { + if (!other->is_free(i)) match=false; + } } } else @@ -3336,20 +3346,18 @@ namespace CGAL { } // Here we unmark all the marked darts. - while (!toTreat1.empty()) - toTreat1.pop(); - while (!toTreat2.empty()) - toTreat2.pop(); + toTreat1.clear(); + toTreat2.clear(); - toTreat1.push(dh1); - toTreat2.push(dh2); + toTreat1.push_back(dh1); + toTreat2.push_back(dh2); while (!toTreat1.empty()) { - current = toTreat1.top(); - toTreat1.pop(); - other = toTreat2.top(); - toTreat2.pop(); + current = toTreat1.front(); + toTreat1.pop_front(); + other = toTreat2.front(); + toTreat2.pop_front(); unmark(current, m1); map2.unmark(other, m2); @@ -3360,8 +3368,8 @@ namespace CGAL { { CGAL_assertion(!other->is_free(i) && map2.is_marked(other->beta(i), m2)); - toTreat1.push(current->beta(i)); - toTreat2.push(other->beta(i)); + toTreat1.push_back(current->beta(i)); + toTreat2.push_back(other->beta(i)); } } } diff --git a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_test.cpp b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_test.cpp index 3fb9a15e14d..a53504ca479 100644 --- a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_test.cpp +++ b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_test.cpp @@ -3,6 +3,7 @@ #include "Combinatorial_map_2_test.h" #include "Combinatorial_map_3_test.h" +#include "Combinatorial_map_copy_test.h" struct f1 { @@ -63,9 +64,9 @@ struct Map_2_dart_max_items_3 typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f1, f2 > Int_attrib; typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f3, f4 > Double_attrib; - - typedef CGAL::cpp11::tuple Attributes; + + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -79,9 +80,9 @@ struct Map_3_dart_max_items_3 typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f5, f6 > Int_attrib; typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f7 > Double_attrib; - - typedef CGAL::cpp11::tuple Attributes; + + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -95,8 +96,8 @@ public: typedef CGAL::Dart< 3, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - - typedef CGAL::cpp11::tuple + + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -110,15 +111,13 @@ struct Map_dart_max_items_4 typedef CGAL::Cell_attribute< Refs, int > Int_attrib; typedef CGAL::Cell_attribute< Refs, double > Double_attrib; - - typedef CGAL::cpp11::tuple + + typedef CGAL::cpp11::tuple Attributes; }; }; - - int main() { typedef CGAL::Combinatorial_map<2, @@ -186,5 +185,13 @@ int main() return EXIT_FAILURE; } + // Copy tests + if ( !testCopy() ) + { + std::cout<<"ERROR during testCopy."< Date: Fri, 31 May 2013 14:43:56 +0200 Subject: [PATCH 04/21] End of copy constructor for cmaps. Add tests. --- .../include/CGAL/Cell_attribute.h | 92 ++-- .../include/CGAL/Combinatorial_map.h | 72 +-- .../Combinatorial_map_internal_functors.h | 168 +++++- .../Combinatorial_map_copy_test.cpp | 493 ++++++++++++++++++ .../Combinatorial_map_test.cpp | 86 ++- .../include/CGAL/Cell_attribute_with_point.h | 54 +- 6 files changed, 851 insertions(+), 114 deletions(-) create mode 100644 Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 153c4f643a1..093b0765286 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -60,26 +60,26 @@ namespace CGAL { /// Cell_attribute_without_info template class Cell_attribute_without_info; // Cell_attribute_without_info without dart support. template - class Cell_attribute_without_info { template < unsigned int d_, class Refs_, class Items_, class Alloc_ > friend class Combinatorial_map_base; - + template friend struct Dart; template < unsigned int d_, class Refs_, - class Items_, class Alloc_ > + class Items_, class Alloc_ > friend class Generalized_map_base; - + template friend struct GMap_dart; @@ -101,7 +101,7 @@ namespace CGAL { /// operator = /// We do nothing since we must not copy mrefcounting. - Cell_attribute_without_info& + Cell_attribute_without_info& operator=(const Cell_attribute_without_info& /*acell*/) { return *this; } @@ -145,9 +145,9 @@ namespace CGAL { unsigned int get_nb_refs() const { return (mrefcounting>>2); } // >>2 to ignore the 2 least significant bits - void * for_compact_container() const + void * for_compact_container() const { return vp; } - void * & for_compact_container() + void * & for_compact_container() { return vp; } private: @@ -165,7 +165,7 @@ namespace CGAL { * The refs class must provide the type of Combinatorial_map used. */ template - class Cell_attribute_without_info { template < unsigned int d_, class Refs_, @@ -176,7 +176,7 @@ namespace CGAL { friend struct Dart; template < unsigned int d_, class Refs_, - class Items_, class Alloc_ > + class Items_, class Alloc_ > friend class Generalized_map_base; template @@ -194,17 +194,17 @@ namespace CGAL { typedef typename Refs::Dart_handle Dart_handle; typedef typename Refs::Dart_const_handle Dart_const_handle; typedef typename Refs::Alloc Alloc; - + typedef OnMerge On_merge; typedef OnSplit On_split; /// operator = /// We must not copy mrefcounting. - Cell_attribute_without_info& + Cell_attribute_without_info& operator=(const Cell_attribute_without_info& acell) { mdart = acell.mdart; - return *this; + return *this; } /// Get the dart associated with the cell. @@ -241,7 +241,7 @@ namespace CGAL { void dec_nb_refs() { CGAL_assertion( mrefcounting>0 ); - --mrefcounting; + --mrefcounting; } public: @@ -251,39 +251,43 @@ namespace CGAL { void * for_compact_container() const { return mdart.for_compact_container(); } - void * & for_compact_container() + void * & for_compact_container() { return mdart.for_compact_container(); } private: /// The dart handle associated with the cell. Dart_handle mdart; - + /// Reference counting: the number of darts linked to this cell. unsigned int mrefcounting; }; - /// Cell associated with an attribute, with or without info depending + /// Cell associated with an attribute, with or without info depending /// if Info==void. - template class Cell_attribute; - + /// Specialization when Info==void. - template - class Cell_attribute : - public Cell_attribute_without_info : + public Cell_attribute_without_info { template < unsigned int d_, class Refs_, class Items_, class Alloc_ > friend class Combinatorial_map_base; - + template friend class Compact_container; + template + friend struct internal::Copy_attr_if_same_type; + public: typedef Tag_ Supports_cell_dart; typedef typename Refs::Dart_handle Dart_handle; @@ -291,8 +295,22 @@ namespace CGAL { typedef typename Refs::Alloc Alloc; typedef OnMerge On_merge; typedef OnSplit On_split; + typedef void Info; + + typedef CGAL::Void Point; + + protected: + /// Default contructor. + Cell_attribute() + {} + + /// Copy the info of an attribute in parameter, if same type. + /// Nothing to do as this attribute has no info. + template + void copy(const Attr2&) + {} }; - + /// Specialization when Info!=void. template friend class Combinatorial_map_base; - + template friend class Compact_container; + template + friend struct internal::Copy_attr_if_same_type; + public: + typedef Cell_attribute Self; + typedef Tag_ Supports_cell_dart; typedef typename Refs::Dart_handle Dart_handle; typedef typename Refs::Dart_const_handle Dart_const_handle; @@ -318,14 +342,24 @@ namespace CGAL { typedef OnSplit On_split; typedef Info_ Info; + typedef CGAL::Void Point; + protected: /// Default contructor. Cell_attribute() {} - /// Contructor with an attribute in parameter. - Cell_attribute(const Info_& ainfo) : Info_for_cell_attribute(ainfo) + /// Contructor with an info in parameter. + Cell_attribute(const Info_& ainfo) : + Info_for_cell_attribute(ainfo) {} + + /// Copy the info of an attribute in parameter, if same type. + template + void copy(const Attr2& aattr) + { + internal::Set_info_if_same_type::run(*this, aattr); + } }; } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 4e4530a69b3..99e67e81f55 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -63,7 +63,7 @@ namespace CGAL { public: template < unsigned int A, class B, class I, class D > friend class Combinatorial_map_base; - + /// Types definition typedef Combinatorial_map_base Self; @@ -174,14 +174,14 @@ namespace CGAL { 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); @@ -189,20 +189,20 @@ namespace CGAL { } 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; @@ -218,7 +218,7 @@ namespace CGAL { } } } - + /** Copy attributes */ for (dartmap_iter=dartmap.begin(); dartmap_iter!=dartmap_iter_end; ++dartmap_iter) @@ -227,20 +227,20 @@ namespace CGAL { < internal::Copy_attributes_functor >:: run(this, &amap, dartmap_iter->second, dartmap_iter->first); } - + CGAL_assertion (is_valid () == 1); } - + // Copy constructor from a map having exactly the same type. Combinatorial_map_base (const Self & amap) { copy(amap); } - + // "Copy constructor" from a map having different type. template Combinatorial_map_base(const Combinatorial_map_base & amap) { copy(amap); } - + /** Affectation operation. Copies one map to the other. * @param amap a combinatorial map. * @return A copy of that combinatorial map. @@ -264,7 +264,7 @@ namespace CGAL { if (this!=&amap) { amap.mdarts.swap(mdarts); - + std::swap_ranges(mnb_times_reserved_marks, mnb_times_reserved_marks+NB_MARKS, amap.mnb_times_reserved_marks); @@ -3236,11 +3236,11 @@ namespace CGAL { ::Dart_const_handle dh2, bool testAttributes=true) const { - CGAL_assertion(dimension==map2.dimension); + // CGAL_assertion(dimension==map2.dimension); CGAL_assertion(dh1!=NULL && dh2!=NULL); - + typedef Combinatorial_map_base Map2; - + bool match = true; // Two stacks used to run through the two maps. @@ -3281,10 +3281,18 @@ namespace CGAL { if (testAttributes) { + // We need to test in both direction because + // Foreach_enabled_attributes only test non void attributes + // of Self. Helper::template Foreach_enabled_attributes < internal::Test_is_same_attribute_functor >:: run(current, other); + Map2::Helper::template Foreach_enabled_attributes + < internal::Test_is_same_attribute_functor >:: + run(other, current); if ( !internal::Test_is_same_attribute_functor:: + value || + !internal::Test_is_same_attribute_functor:: value ) match=false; } @@ -3293,7 +3301,7 @@ namespace CGAL { // We go out as soon as it is not satisfied. for (i = 0; match && i <= dimension; ++i) { - if ( i>Map2::dimension ) + if ( i>map2.dimension ) { if (!current->is_free(i)) match=false; } @@ -3332,7 +3340,7 @@ namespace CGAL { } } // Now we test if the second map has more beta links than the first - for ( i=dimension+1; match && i<=Map2::dimension; ++i ) + for ( i=dimension+1; match && i<=map2.dimension; ++i ) { if (!other->is_free(i)) match=false; } @@ -3344,24 +3352,24 @@ namespace CGAL { match = false; } } - + // Here we unmark all the marked darts. toTreat1.clear(); toTreat2.clear(); - + toTreat1.push_back(dh1); toTreat2.push_back(dh2); - + while (!toTreat1.empty()) { current = toTreat1.front(); toTreat1.pop_front(); other = toTreat2.front(); toTreat2.pop_front(); - + unmark(current, m1); map2.unmark(other, m2); - + for (i = 0; match && i <= dimension; ++i) { if (!current->is_free(i) && is_marked(current->beta(i), m1)) @@ -3373,13 +3381,13 @@ namespace CGAL { } } } - + free_mark(m1); map2.free_mark(m2); - + return match; } - + /** Test if this cmap is isomorphic to map2. * @pre cmap is connected. * @param map2 the second combinatorial map @@ -3393,10 +3401,10 @@ namespace CGAL { & map2, bool testAttributes=true) { - if ( dimension!=map2.dimension ) return false; - + // if ( dimension!=map2.dimension ) return false; + Dart_const_handle d1=darts().begin(); - + for (typename Combinatorial_map_base:: Dart_range::const_iterator it(map2.darts().begin()), itend(map2.darts().end()); it!=itend; ++it) @@ -3406,10 +3414,10 @@ namespace CGAL { return true; } } - + return false; - } - + } + /// Void dart. A dart d is i-free if beta_i(d)=null_dart_handle. static Dart_handle null_dart_handle; 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 6ce75ec1662..93651b8f7f9 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -22,6 +22,9 @@ #include #include +#include +#include +#include #include /* Definition of functors used internally to manage attributes (we need @@ -413,27 +416,136 @@ struct Set_i_attribute_of_dart_functor {} }; // **************************************************************************** -// Functor allowing to copy attributes whey info are convertible -// TODO replace these version by using is_constructible -// if no support for gcc11, use this simplified version ? (same type) -template -struct Affectation_if_same_type +// Functor allowing to set the value of a point if point exist, have +// same dimension. For dim>3, if type of points are the same (because no converter). +template +struct Set_point_d_if_same { - static void run(T1&, const T2&) + static void run(Point1&, const Point2&) {} }; -template -struct Affectation_if_same_type +template +struct Set_point_d_if_same { - static void run(T1&e1, const T1&e2) - { e1=e2; } + static void run(Point1& p1, const Point1& p2) + { + p1 = p2; // Copy of Point_d having same type + } }; -// Case of two non void type -template -struct Copy_attr_functor +template::type, + typename T2=typename Ambient_dimension::type> +struct Set_point_if_possible +{ + static void run(Point1&, const Point2&) + {} +}; + +template +struct Set_point_if_possible, Dimension_tag<2> > +{ + static void run(Point1& p1, const Point2& p2) + { + p1 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>(p2); + } +}; + +template +struct Set_point_if_possible, Dimension_tag<3> > +{ + static void run(Point1& p1, const Point2& p2) + { + p1 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>(p2); + } +}; + +template +struct Set_point_if_possible +{ + static void run(Point1& p1, const Point2& p2) + { + if ( p1.dimension()==p2.dimension() ) + Set_point_d_if_same::run(p1, p2); + } +}; + +// Set_point_if_exist ensure that Attr2 has a point +template +struct Set_point_if_exist +{ + static void run(Point1& p1, const Attr2& a2) + { + Set_point_if_possible(p1, a2.point()); + } +}; + +template +struct Set_point_if_exist +{ + static void run(Point1&, const Attr2& ) + {} +}; + +// Functor allowing to set a value if two info are the same or not +// TODO replace these version by using is_constructible ? +// if no support for gcc11, use this simplified version ? (same type) +template +struct Set_info_if_same_type +{ + static void run(Attr1&, const Attr2&) + {} +}; + +template +struct Set_info_if_same_type +{ + static void run(Attr1&, const Attr2&) + {} +}; + +template +struct Set_info_if_same_type +{ + static void run(Attr1&, const Attr2&) + {} +}; + +template +struct Set_info_if_same_type +{ + static void run(Attr1&, const Attr2&) + {} +}; + +template +struct Set_info_if_same_type +{ + static void run(Attr1& a1, const Attr2& a2) + { a1.info()=a2.info(); } +}; + +// Functor allowing to copy attributes whey info are convertible +template +struct Copy_attr_if_same_type +{ + static void const run(Map1* cmap1, const Map2* cmap2, + typename Map1::Dart_handle dh1, + typename Map2::Dart_const_handle dh2) + {} +}; + +template +struct Copy_attr_if_same_type { static void const run(Map1* cmap1, const Map2* cmap2, typename Map1::Dart_handle dh1, @@ -445,16 +557,28 @@ struct Copy_attr_functor { cmap1->template set_attribute(dh1, cmap1->template create_attribute()); - Affectation_if_same_type:: - run(dh1->template attribute()->info(), - dh2->template attribute()->info()); + dh1->template attribute()->copy(*dh2->template attribute()); } } }; +// Case of two non void type +template +struct Copy_attr_functor +{ + static void const run(Map1* cmap1, const Map2* cmap2, + typename Map1::Dart_handle dh1, + typename Map2::Dart_const_handle dh2) + { + Copy_attr_if_same_type:: + run(cmap1, cmap2, dh1, dh2); + } +}; + // Case T1==void template -struct Copy_attr_functor +struct Copy_attr_functor { static void const run(Map1*, const Map2*, typename Map1::Dart_handle, @@ -464,7 +588,7 @@ struct Copy_attr_functor // Case T2==void template -struct Copy_attr_functor +struct Copy_attr_functor { static void const run(Map1*, const Map2*, typename Map1::Dart_handle, @@ -474,7 +598,7 @@ struct Copy_attr_functor // Case T1==T2==void template -struct Copy_attr_functor +struct Copy_attr_functor { static void const run(Map1*, const Map2*, typename Map1::Dart_handle, @@ -524,11 +648,11 @@ struct Is_same_attribute_functor if (dh1->template attribute()==NULL && dh2->template attribute()==NULL) return true; - + if (dh1->template attribute()==NULL || dh2->template attribute()==NULL) return false; - + return Is_same_info:: run(dh1->template attribute()->info(), diff --git a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp new file mode 100644 index 00000000000..347475e03ad --- /dev/null +++ b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp @@ -0,0 +1,493 @@ +#include +#include +#include +#include + +#include +#include + +using namespace std; + +struct f1 +{ + template + void operator() (Attr&, Attr&) + {} +}; +struct f2 +{ + template + void operator() (const Attr&, Attr&) + {} +}; +struct f3 +{ + template + void operator() (Attr&, const Attr&) + {} +}; +struct f4 +{ + template + void operator() (const Attr&, const Attr&) + {} +}; +struct f5 +{ + template + void operator() (const Attr&, const Attr&) + {} + template + void operator() (Attr&, const Attr&) + {} +}; +struct f6 +{ + template + void operator() (CMap*, Attr&, Attr&) + {} +}; +struct f7 +{ + template + void operator() (Attr&, const Attr&) + {} + template + void operator() (CMap*, Attr&, Attr&) + {} +}; + +struct Map_2_dart_items +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 2, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f1, f2 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f3, f4 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_2_dart_max_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 2, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f1, f2 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f3, f4 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_3_dart_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f5, f6 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f7 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_3_dart_max_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f5, f6 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f7 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +class Another_map_3_dart_items_3 +{ +public: + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_dart_items_4 +{ + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 4, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple + Attributes; + }; +}; + +struct Map_dart_max_items_4 +{ + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 4, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple + Attributes; + }; +}; + +// void, void, void +typedef CGAL::Combinatorial_map<2, CGAL::Combinatorial_map_min_items<2> > Map1; + +// double, void, double +typedef CGAL::Combinatorial_map<2, Map_2_dart_items > Map2; + +// int, int, double +typedef CGAL::Combinatorial_map<2, Map_2_dart_max_items_3> Map3; + +// void, void, void, void +typedef CGAL::Combinatorial_map<3, CGAL::Combinatorial_map_min_items<3> > Map4; + +// double, void, int, double +typedef CGAL::Combinatorial_map<3, Map_3_dart_items_3> Map5; + +// int, int, int, double +typedef CGAL::Combinatorial_map<3, Map_3_dart_max_items_3> Map6; + +// int, void, int, void +typedef CGAL::Combinatorial_map<3, Another_map_3_dart_items_3> Map7; + +// int, void, int, void, int +typedef CGAL::Combinatorial_map<4, Map_dart_items_4> Map8; + +// int, int, int, double, double +typedef CGAL::Combinatorial_map<4, Map_dart_max_items_4> Map9; + +/* +template +typename Map::Dart_handle getRandomDart(Map& map) +{ + int nb = rand()%map.number_of_darts(); + typename Map::Dart_range::iterator it=map.darts().begin(); + for ( int i=0; i::type> +struct CreateAttributes +{ + static void run(Map& map) + { + int nb=0; + for(typename Map::Dart_range::iterator it=map.darts().begin(), + itend=map.darts().end(); it!=itend; ++it) + { + if ( it->template attribute()==NULL ) + map.template set_attribute + (it, map.template create_attribute(++nb)); + } + } +}; + +template +struct CreateAttributes +{ + static void run(Map&) + { + } +}; + +template::type> +struct DisplayAttribs +{ + static void run(Map& amap) + { + std::cout<::type::iterator + it=amap.template attributes().begin(), + itend=amap.template attributes().end(); + it!=itend; ++it ) + { + std::cout<info()<<"; "; + } + std::cout< +struct DisplayAttribs +{ + static void run(Map&) + {} +}; + +template +void displayAllAttribs2D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); +} + +template +void create2Dmap(Map& map) +{ + for ( int i=0; i<15; ++i ) + CGAL::make_combinatorial_hexahedron(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} +template +void create3Dmap(Map& map) +{ + for ( int i=0; i<15; ++i ) + CGAL::make_combinatorial_hexahedron(map); + + for ( int i=0; i<20; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<3>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<3>(d1, d2) ) ++d2; + map.template sew<3>(d1,d2); + } + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} +template +void create4Dmap(Map& map) +{ + for ( int i=0; i<45; ++i ) + CGAL::make_combinatorial_hexahedron(map); + + for ( int i=0; i<40; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<3>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<3>(d1, d2) ) ++d2; + map.template sew<3>(d1,d2); + } + + for ( int i=0; i<20; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<4>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<4>(d1, d2) ) ++d2; + map.template sew<4>(d1,d2); + } + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} + +bool testCopy() +{ + Map1 map1; create2Dmap(map1); + Map2 map2; create2Dmap(map2); + Map3 map3; create2Dmap(map3); + + Map4 map4; create3Dmap(map4); + Map5 map5; create3Dmap(map5); + Map6 map6; create3Dmap(map6); + Map7 map7; create3Dmap(map7); + + Map8 map8; create3Dmap(map8); + Map9 map9; create3Dmap(map9); + + // First copy of same types + { + Map1 map1p(map1); + if ( !map1p.is_valid() || !map1.is_isomorphic_to(map1p) ) + { assert(false); return false; } + Map2 map2p(map2); + if ( !map2p.is_valid() || !map2.is_isomorphic_to(map2p) ) + { assert(false); return false; } + Map3 map3p(map3); + if ( !map3p.is_valid() || !map3.is_isomorphic_to(map3p) ) + { assert(false); return false; } + Map4 map4p(map4); + if ( !map4p.is_valid() || !map4.is_isomorphic_to(map4p) ) + { assert(false); return false; } + Map5 map5p(map5); + if ( !map5p.is_valid() || !map5.is_isomorphic_to(map5p) ) + { assert(false); return false; } + Map6 map6p(map6); + if ( !map6p.is_valid() || !map6.is_isomorphic_to(map6p) ) + { assert(false); return false; } + Map7 map7p(map7); + if ( !map7p.is_valid() || !map7.is_isomorphic_to(map7p) ) + { assert(false); return false; } + Map8 map8p(map8); + if ( !map8p.is_valid() || !map8.is_isomorphic_to(map8p) ) + { assert(false); return false; } + Map9 map9p(map9); + if ( !map9p.is_valid() || !map9.is_isomorphic_to(map9p) ) + { assert(false); return false; } + } + + // Second copy of same dimensions but different attributes + // Maps are still isomorphic but no same attributes + { + // 2D + Map2 map1p(map1); assert(map1p.is_valid()); + if ( !map1.is_isomorphic_to(map1p) ) { assert(false); return false; } + + Map3 map1t(map1); assert(map1t.is_valid()); + if ( !map1.is_isomorphic_to(map1t) ) { assert(false); return false; } + + if ( !map1p.is_isomorphic_to(map1t) ) { assert(false); return false; } + + Map1 map2p(map2); assert(map2p.is_valid()); + if ( map2.is_isomorphic_to(map2p) ) { assert(false); return false; } + if ( !map2.is_isomorphic_to(map2p, false) ) { assert(false); return false; } + + Map3 map2t(map2); assert(map2t.is_valid()); + if ( map2.is_isomorphic_to(map2t) ) { assert(false); return false; } + if ( !map2.is_isomorphic_to(map2t, false) ) { assert(false); return false; } + + if ( map2p.is_isomorphic_to(map2t) ) { assert(false); return false; } + if ( !map2p.is_isomorphic_to(map2t, false) ) { assert(false); return false; } + + Map1 map3p(map3); assert(map3p.is_valid()); + if ( map3.is_isomorphic_to(map3p) ) { assert(false); return false; } + if ( !map3.is_isomorphic_to(map3p, false) ) { assert(false); return false; } + + Map2 map3t(map3); assert(map3t.is_valid()); + if ( map3.is_isomorphic_to(map3t) ) { assert(false); return false; } + if ( !map3.is_isomorphic_to(map3t, false) ) { assert(false); return false; } + + if ( map3p.is_isomorphic_to(map3t) ) { assert(false); return false; } + if ( !map3p.is_isomorphic_to(map3t, false) ) { assert(false); return false; } + + assert( map1.is_isomorphic_to(map1p)==map1p.is_isomorphic_to(map1) ); + assert( map1.is_isomorphic_to(map1t)==map1t.is_isomorphic_to(map1) ); + assert( map2.is_isomorphic_to(map2p)==map2p.is_isomorphic_to(map2) ); + assert( map2.is_isomorphic_to(map2t)==map2t.is_isomorphic_to(map2) ); + assert( map3.is_isomorphic_to(map3p)==map3p.is_isomorphic_to(map3) ); + assert( map3.is_isomorphic_to(map3t)==map3t.is_isomorphic_to(map3) ); + + // 3D + Map4 map5a(map5); assert(map5a.is_valid()); + if ( map5.is_isomorphic_to(map5a) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5a, false) ) { assert(false); return false; } + + Map6 map5b(map5); assert(map5b.is_valid()); + if ( map5.is_isomorphic_to(map5b) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5b, false) ) { assert(false); return false; } + assert( map5b.number_of_attributes<0>()==0 && + map5b.number_of_attributes<1>()==0 && + map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && + map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); + + Map7 map5c(map5); assert(map5c.is_valid()); + if ( map5.is_isomorphic_to(map5c) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5c, false) ) { assert(false); return false; } + assert( map5c.number_of_attributes<0>()==0 && + map5c.number_of_attributes<2>()==map5.number_of_attributes<2>() ); + + assert( map5.is_isomorphic_to(map5a)==map5a.is_isomorphic_to(map5) ); + assert( map5.is_isomorphic_to(map5b)==map5b.is_isomorphic_to(map5) ); + assert( map5.is_isomorphic_to(map5c)==map5c.is_isomorphic_to(map5) ); + + // 4D + Map8 map9a(map9); assert(map9a.is_valid()); + if ( map9.is_isomorphic_to(map9a) ) { assert(false); return false; } + if ( !map9.is_isomorphic_to(map9a, false) ) { assert(false); return false; } + assert( map9a.number_of_attributes<0>()==map9.number_of_attributes<0>() && + map9a.number_of_attributes<2>()==map9.number_of_attributes<2>() && + map9a.number_of_attributes<4>()==0 ); + assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); + + Map9 map8a(map8); assert(map8a.is_valid()); + if ( map8.is_isomorphic_to(map8a) ) { assert(false); return false; } + if ( !map8.is_isomorphic_to(map8a, false) ) { assert(false); return false; } + assert( map8a.number_of_attributes<0>()==map8.number_of_attributes<0>() && + map8a.number_of_attributes<1>()==0 && + map8a.number_of_attributes<2>()==map8.number_of_attributes<2>() && + map8a.number_of_attributes<3>()==0 && + map8a.number_of_attributes<4>()==0 ); + assert( map8a.is_isomorphic_to(map8)==map8.is_isomorphic_to(map8a) ); + + } + + // Third copy of different dimensions and different attributes + { + Map5 map2a(map2); assert(map2a.is_valid()); + if ( map2a.is_isomorphic_to(map2) ) { assert(false); return false; } + if ( !map2a.is_isomorphic_to(map2, false) ) { assert(false); return false; } + assert( map2a.number_of_attributes<0>()==map2.number_of_attributes<0>() && + map2a.number_of_attributes<2>()==0 && + map2a.number_of_attributes<3>()==0 ); + assert( map2a.is_isomorphic_to(map2)==map2.is_isomorphic_to(map2a) ); + //map2.display_characteristics(std::cout)<()==map2.number_of_attributes<0>() && + map5a.number_of_attributes<2>()==0 ); + //map5.display_characteristics(std::cout)< + struct Dart_wrapper + { + typedef CGAL::Dart< 2, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f1, f2 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f3, f4 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + struct Map_2_dart_max_items_3 { /// Dart_wrapper defines the type of darts used. @@ -70,6 +84,22 @@ struct Map_2_dart_max_items_3 }; }; +struct Map_3_dart_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int, CGAL::Tag_true, f5, f6 > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double, CGAL::Tag_true, f7 > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + struct Map_3_dart_max_items_3 { /// Dart_wrapper defines the type of darts used. @@ -97,7 +127,22 @@ public: typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::cpp11::tuple + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_dart_items_4 +{ + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 4, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -118,80 +163,79 @@ struct Map_dart_max_items_4 }; }; +typedef CGAL::Combinatorial_map<2, CGAL::Combinatorial_map_min_items<2> > Map1; + +typedef CGAL::Combinatorial_map<2, Map_2_dart_items > Map2; + +typedef CGAL::Combinatorial_map<2, Map_2_dart_max_items_3> Map3; + +typedef CGAL::Combinatorial_map<3, CGAL::Combinatorial_map_min_items<3> > Map4; + +typedef CGAL::Combinatorial_map<3, Map_3_dart_items_3> Map5; + +typedef CGAL::Combinatorial_map<3, Map_3_dart_max_items_3> Map6; + +typedef CGAL::Combinatorial_map<3, Another_map_3_dart_items_3> Map7; + +typedef CGAL::Combinatorial_map<4, Map_dart_items_4> Map8; + +typedef CGAL::Combinatorial_map<4, Map_dart_max_items_4> Map9; + int main() { - typedef CGAL::Combinatorial_map<2, - CGAL::Combinatorial_map_min_items<2> > Map1; if ( !test2D() ) { std::cout<<"ERROR during test2D."< Map2; if ( !test2D() ) { std::cout<<"ERROR during test2D."< Map3; if ( !test2D() ) { std::cout<<"ERROR during test2D."< > Map4; if ( !test3D() ) { std::cout<<"ERROR during test3D."< Map5; if ( !test3D() ) { std::cout<<"ERROR during test3D."< Map6; if ( !test3D() ) { std::cout<<"ERROR during test3D."< Map7; if ( !test3D() ) { std::cout<<"ERROR during test3D."< Map8; if ( !test3D() ) { std::cout<<"ERROR during test3D."< Map9; if ( !test3D() ) { std::cout<<"ERROR during test3D."<() ) - { - std::cout<<"ERROR during testCopy."< + void copy(const Attr2& attr) + { + internal::Set_point_if_exist::run(point(), aattr); + } + protected: /// The point associated with the cell. Point mpoint; @@ -56,27 +63,36 @@ namespace CGAL { /// Attribute associated with a point and an info. template < class LCC, class Info_=void, class Tag=Tag_true, - class Functor_on_merge_=Null_functor, + class Functor_on_merge_=Null_functor, class Functor_on_split_=Null_functor > class Cell_attribute_with_point : - public Cell_attribute, public Point_for_cell { + template + friend struct internal::Copy_attr_if_same_type; + public: - typedef Cell_attribute Self; + + typedef Cell_attribute Base1; typedef Point_for_cell Base2; - + typedef typename LCC::Point Point; typedef typename LCC::Dart_handle Dart_handle; typedef typename LCC::Dart_const_handle Dart_const_handle; - + typedef Info_ Info; typedef Functor_on_merge_ Functor_on_merge; typedef Functor_on_split_ Functor_on_split; - + using Base1::info; + + protected: /// Default contructor. Cell_attribute_with_point() {} @@ -91,30 +107,41 @@ namespace CGAL { Base2(apoint) {} - using Base1::info; + /// Copy the point, and if same type info. + template + void copy(const Attr2& aattr) + { + Base1::copy(aattr); + Base2::copy(aattr); + } }; /// Attribute associated with a point and without info. template < class LCC, class Tag, - class Functor_on_merge_, + class Functor_on_merge_, class Functor_on_split_ > class Cell_attribute_with_point : public Cell_attribute, public Point_for_cell { + template + friend struct internal::Copy_attr_if_same_type; + public: - typedef Cell_attribute Base1; typedef Point_for_cell Base2; typedef typename LCC::Point Point; typedef typename LCC::Dart_handle Dart_handle; - typedef typename LCC::Dart_const_handle Dart_const_handle; + typedef typename LCC::Dart_const_handle Dart_const_handle; typedef Functor_on_merge_ Functor_on_merge; typedef Functor_on_split_ Functor_on_split; + protected: /// Default contructor. Cell_attribute_with_point() {} @@ -122,6 +149,13 @@ namespace CGAL { /// Contructor with a point in parameter. Cell_attribute_with_point(const Point& apoint) : Base2(apoint) {} + + /// Copy the point of an attribute in parameter. + template + void copy(const Attr2& attr) + { + Base2::copy(aattr); + } }; } // namespace CGAL From d3e2d15be79403e1247342b8b7a119983f43ba96 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 31 May 2013 15:02:25 +0200 Subject: [PATCH 05/21] Add tests to copy lcc --- .../Linear_cell_complex_copy_test.cpp | 458 ++++++++++++++++++ 1 file changed, 458 insertions(+) create mode 100644 Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp new file mode 100644 index 00000000000..b354a1417d0 --- /dev/null +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -0,0 +1,458 @@ +#include +#include +#include + +#include +#include + +using namespace std; + +struct Map_2_dart_items +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 2, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_2_dart_max_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 2, Refs > Dart; + + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_3_dart_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_3_dart_max_items_3 +{ + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +class Another_map_3_dart_items_3 +{ +public: + /// Dart_wrapper defines the type of darts used. + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 3, Refs > Dart; + + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + + typedef CGAL::cpp11::tuple Attributes; + }; +}; + +struct Map_dart_items_4 +{ + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 4, Refs > Dart; + + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple + Attributes; + }; +}; + +struct Map_dart_max_items_4 +{ + template < class Refs > + struct Dart_wrapper + { + typedef CGAL::Dart< 4, Refs > Dart; + + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; + + typedef CGAL::cpp11::tuple + Attributes; + }; +}; + +typedef CGAL::Linear_cell_complex_traits +<2, CGAL::Exact_predicates_inexact_constructions_kernel> Traits2_a; + +typedef CGAL::Linear_cell_complex_traits +<2, CGAL::Exact_predicates_exact_constructions_kernel> Traits2_b; + +typedef CGAL::Linear_cell_complex_traits +<3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits3_a; + +typedef CGAL::Linear_cell_complex_traits +<3, CGAL::Exact_predicates_exact_constructions_kernel> Traits3_b; + +typedef CGAL::Linear_cell_complex_traits +<4, CGAL::Exact_predicates_inexact_constructions_kernel> Traits4_a; + +// void, void, void +typedef CGAL::Linear_cell_complex<2,2, Traits2_a, CGAL::Linear_cell_complex_min_items<2> > Map1; + +// double, void, double +typedef CGAL::Linear_cell_complex<2,2, Traits2_a, Map_2_dart_items > Map2; + +// int, int, double +typedef CGAL::Linear_cell_complex<2,2, Traits2_b, Map_2_dart_max_items_3> Map3; + +// void, void, void, void +typedef CGAL::Linear_cell_complex<3,3, Traits3_a, CGAL::Combinatorial_map_min_items<3> > Map4; + +// double, void, int, double +typedef CGAL::Linear_cell_complex<3,3, Traits3_a, Map_3_dart_items_3> Map5; + +// int, int, int, double +typedef CGAL::Linear_cell_complex<3,3, Traits3_b, Map_3_dart_max_items_3> Map6; + +// int, void, int, void +typedef CGAL::Linear_cell_complex<3,4, Traits4_a, Another_map_3_dart_items_3> Map7; + +// int, void, int, void, int +typedef CGAL::Linear_cell_complex<4, Traits4_a, Map_dart_items_4> Map8; + +// int, int, int, double, double +typedef CGAL::Linear_cell_complex<4, Traits4_a, Map_dart_max_items_4> Map9; + +/* +template +typename Map::Dart_handle getRandomDart(Map& map) +{ + int nb = rand()%map.number_of_darts(); + typename Map::Dart_range::iterator it=map.darts().begin(); + for ( int i=0; i::type> +struct CreateAttributes +{ + static void run(Map& map) + { + int nb=0; + for(typename Map::Dart_range::iterator it=map.darts().begin(), + itend=map.darts().end(); it!=itend; ++it) + { + if ( it->template attribute()==NULL ) + map.template set_attribute + (it, map.template create_attribute(++nb)); + } + } +}; + +template +struct CreateAttributes +{ + static void run(Map&) + { + } +}; + +template::type> +struct DisplayAttribs +{ + static void run(Map& amap) + { + std::cout<::type::iterator + it=amap.template attributes().begin(), + itend=amap.template attributes().end(); + it!=itend; ++it ) + { + std::cout<info()<<"; "; + } + std::cout< +struct DisplayAttribs +{ + static void run(Map&) + {} +}; + +template +void displayAllAttribs2D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); +} + +template +void create2Dmap(Map& map) +{ + for ( int i=0; i<15; ++i ) + CGAL::make_combinatorial_hexahedron(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} +template +void create3Dmap(Map& map) +{ + for ( int i=0; i<15; ++i ) + CGAL::make_combinatorial_hexahedron(map); + + for ( int i=0; i<20; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<3>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<3>(d1, d2) ) ++d2; + map.template sew<3>(d1,d2); + } + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} +template +void create4Dmap(Map& map) +{ + for ( int i=0; i<45; ++i ) + CGAL::make_combinatorial_hexahedron(map); + + for ( int i=0; i<40; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<3>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<3>(d1, d2) ) ++d2; + map.template sew<3>(d1,d2); + } + + for ( int i=0; i<20; ++i ) + { + typename Map::Dart_handle d1=map.darts().begin(); + while ( !d1->template is_free<4>() ) ++d1; + typename Map::Dart_handle d2=map.darts().begin(); + while ( !map.template is_sewable<4>(d1, d2) ) ++d2; + map.template sew<4>(d1,d2); + } + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); + CreateAttributes::run(map); +} + +bool testCopy() +{ + Map1 map1; create2Dmap(map1); + Map2 map2; create2Dmap(map2); + Map3 map3; create2Dmap(map3); + + Map4 map4; create3Dmap(map4); + Map5 map5; create3Dmap(map5); + Map6 map6; create3Dmap(map6); + Map7 map7; create3Dmap(map7); + + Map8 map8; create3Dmap(map8); + Map9 map9; create3Dmap(map9); + + // First copy of same types + { + Map1 map1p(map1); + if ( !map1p.is_valid() || !map1.is_isomorphic_to(map1p) ) + { assert(false); return false; } + Map2 map2p(map2); + if ( !map2p.is_valid() || !map2.is_isomorphic_to(map2p) ) + { assert(false); return false; } + Map3 map3p(map3); + if ( !map3p.is_valid() || !map3.is_isomorphic_to(map3p) ) + { assert(false); return false; } + Map4 map4p(map4); + if ( !map4p.is_valid() || !map4.is_isomorphic_to(map4p) ) + { assert(false); return false; } + Map5 map5p(map5); + if ( !map5p.is_valid() || !map5.is_isomorphic_to(map5p) ) + { assert(false); return false; } + Map6 map6p(map6); + if ( !map6p.is_valid() || !map6.is_isomorphic_to(map6p) ) + { assert(false); return false; } + Map7 map7p(map7); + if ( !map7p.is_valid() || !map7.is_isomorphic_to(map7p) ) + { assert(false); return false; } + Map8 map8p(map8); + if ( !map8p.is_valid() || !map8.is_isomorphic_to(map8p) ) + { assert(false); return false; } + Map9 map9p(map9); + if ( !map9p.is_valid() || !map9.is_isomorphic_to(map9p) ) + { assert(false); return false; } + } + + // Second copy of same dimensions but different attributes + // Maps are still isomorphic but no same attributes + { + // 2D + Map2 map1p(map1); assert(map1p.is_valid()); + if ( !map1.is_isomorphic_to(map1p) ) { assert(false); return false; } + + Map3 map1t(map1); assert(map1t.is_valid()); + if ( !map1.is_isomorphic_to(map1t) ) { assert(false); return false; } + + if ( !map1p.is_isomorphic_to(map1t) ) { assert(false); return false; } + + Map1 map2p(map2); assert(map2p.is_valid()); + if ( map2.is_isomorphic_to(map2p) ) { assert(false); return false; } + if ( !map2.is_isomorphic_to(map2p, false) ) { assert(false); return false; } + + Map3 map2t(map2); assert(map2t.is_valid()); + if ( map2.is_isomorphic_to(map2t) ) { assert(false); return false; } + if ( !map2.is_isomorphic_to(map2t, false) ) { assert(false); return false; } + + if ( map2p.is_isomorphic_to(map2t) ) { assert(false); return false; } + if ( !map2p.is_isomorphic_to(map2t, false) ) { assert(false); return false; } + + Map1 map3p(map3); assert(map3p.is_valid()); + if ( map3.is_isomorphic_to(map3p) ) { assert(false); return false; } + if ( !map3.is_isomorphic_to(map3p, false) ) { assert(false); return false; } + + Map2 map3t(map3); assert(map3t.is_valid()); + if ( map3.is_isomorphic_to(map3t) ) { assert(false); return false; } + if ( !map3.is_isomorphic_to(map3t, false) ) { assert(false); return false; } + + if ( map3p.is_isomorphic_to(map3t) ) { assert(false); return false; } + if ( !map3p.is_isomorphic_to(map3t, false) ) { assert(false); return false; } + + assert( map1.is_isomorphic_to(map1p)==map1p.is_isomorphic_to(map1) ); + assert( map1.is_isomorphic_to(map1t)==map1t.is_isomorphic_to(map1) ); + assert( map2.is_isomorphic_to(map2p)==map2p.is_isomorphic_to(map2) ); + assert( map2.is_isomorphic_to(map2t)==map2t.is_isomorphic_to(map2) ); + assert( map3.is_isomorphic_to(map3p)==map3p.is_isomorphic_to(map3) ); + assert( map3.is_isomorphic_to(map3t)==map3t.is_isomorphic_to(map3) ); + + // 3D + Map4 map5a(map5); assert(map5a.is_valid()); + if ( map5.is_isomorphic_to(map5a) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5a, false) ) { assert(false); return false; } + + Map6 map5b(map5); assert(map5b.is_valid()); + if ( map5.is_isomorphic_to(map5b) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5b, false) ) { assert(false); return false; } + assert( map5b.number_of_attributes<0>()==0 && + map5b.number_of_attributes<1>()==0 && + map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && + map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); + + Map7 map5c(map5); assert(map5c.is_valid()); + if ( map5.is_isomorphic_to(map5c) ) { assert(false); return false; } + if ( !map5.is_isomorphic_to(map5c, false) ) { assert(false); return false; } + assert( map5c.number_of_attributes<0>()==0 && + map5c.number_of_attributes<2>()==map5.number_of_attributes<2>() ); + + assert( map5.is_isomorphic_to(map5a)==map5a.is_isomorphic_to(map5) ); + assert( map5.is_isomorphic_to(map5b)==map5b.is_isomorphic_to(map5) ); + assert( map5.is_isomorphic_to(map5c)==map5c.is_isomorphic_to(map5) ); + + // 4D + Map8 map9a(map9); assert(map9a.is_valid()); + if ( map9.is_isomorphic_to(map9a) ) { assert(false); return false; } + if ( !map9.is_isomorphic_to(map9a, false) ) { assert(false); return false; } + assert( map9a.number_of_attributes<0>()==map9.number_of_attributes<0>() && + map9a.number_of_attributes<2>()==map9.number_of_attributes<2>() && + map9a.number_of_attributes<4>()==0 ); + assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); + + Map9 map8a(map8); assert(map8a.is_valid()); + if ( map8.is_isomorphic_to(map8a) ) { assert(false); return false; } + if ( !map8.is_isomorphic_to(map8a, false) ) { assert(false); return false; } + assert( map8a.number_of_attributes<0>()==map8.number_of_attributes<0>() && + map8a.number_of_attributes<1>()==0 && + map8a.number_of_attributes<2>()==map8.number_of_attributes<2>() && + map8a.number_of_attributes<3>()==0 && + map8a.number_of_attributes<4>()==0 ); + assert( map8a.is_isomorphic_to(map8)==map8.is_isomorphic_to(map8a) ); + + } + + // Third copy of different dimensions and different attributes + { + Map5 map2a(map2); assert(map2a.is_valid()); + if ( map2a.is_isomorphic_to(map2) ) { assert(false); return false; } + if ( !map2a.is_isomorphic_to(map2, false) ) { assert(false); return false; } + assert( map2a.number_of_attributes<0>()==map2.number_of_attributes<0>() && + map2a.number_of_attributes<2>()==0 && + map2a.number_of_attributes<3>()==0 ); + assert( map2a.is_isomorphic_to(map2)==map2.is_isomorphic_to(map2a) ); + //map2.display_characteristics(std::cout)<()==map2.number_of_attributes<0>() && + map5a.number_of_attributes<2>()==0 ); + //map5.display_characteristics(std::cout)< Date: Fri, 31 May 2013 15:45:47 +0200 Subject: [PATCH 06/21] tests for lcc copy (nyf) --- .../include/CGAL/Cell_attribute_with_point.h | 4 +- .../Linear_cell_complex_copy_test.cpp | 146 +++++++++++++----- 2 files changed, 106 insertions(+), 44 deletions(-) diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index bdc7ac566b5..de66f44e50f 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -51,7 +51,7 @@ namespace CGAL { /// Copy the point of an attribute in parameter. template - void copy(const Attr2& attr) + void copy(const Attr2& aattr) { internal::Set_point_if_exist::run(point(), aattr); } @@ -152,7 +152,7 @@ namespace CGAL { /// Copy the point of an attribute in parameter. template - void copy(const Attr2& attr) + void copy(const Attr2& aattr) { Base2::copy(aattr); } diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index b354a1417d0..cba49e93411 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -1,6 +1,7 @@ #include #include #include +#include #include #include @@ -16,9 +17,10 @@ struct Map_2_dart_items typedef CGAL::Dart< 2, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib; + typedef CGAL::Cell_attribute< Refs, int > Double_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib_wp; - typedef CGAL::cpp11::tuple Attributes; + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -30,10 +32,11 @@ struct Map_2_dart_max_items_3 { typedef CGAL::Dart< 2, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib_wp; + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; typedef CGAL::Cell_attribute< Refs, double > Double_attrib; - typedef CGAL::cpp11::tuple Attributes; }; }; @@ -47,9 +50,10 @@ struct Map_3_dart_items_3 typedef CGAL::Dart< 3, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib; + typedef CGAL::Cell_attribute< Refs, int > Double_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib_wp; - typedef CGAL::cpp11::tuple Attributes; }; }; @@ -62,10 +66,11 @@ struct Map_3_dart_max_items_3 { typedef CGAL::Dart< 3, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib_wp; + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; typedef CGAL::Cell_attribute< Refs, double > Double_attrib; - typedef CGAL::cpp11::tuple Attributes; }; }; @@ -79,9 +84,10 @@ public: { typedef CGAL::Dart< 3, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib_wp; + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::cpp11::tuple Attributes; + typedef CGAL::cpp11::tuple Attributes; }; }; @@ -92,10 +98,11 @@ struct Map_dart_items_4 { typedef CGAL::Dart< 4, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib_wp; + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; typedef CGAL::Cell_attribute< Refs, double > Double_attrib; - typedef CGAL::cpp11::tuple Attributes; }; @@ -108,56 +115,50 @@ struct Map_dart_max_items_4 { typedef CGAL::Dart< 4, Refs > Dart; - typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib; + typedef CGAL::Cell_attribute_with_point< Refs, int > Int_attrib_wp; + typedef CGAL::Cell_attribute< Refs, int > Int_attrib; typedef CGAL::Cell_attribute< Refs, double > Double_attrib; - typedef CGAL::cpp11::tuple Attributes; }; }; -typedef CGAL::Linear_cell_complex_traits -<2, CGAL::Exact_predicates_inexact_constructions_kernel> Traits2_a; - -typedef CGAL::Linear_cell_complex_traits -<2, CGAL::Exact_predicates_exact_constructions_kernel> Traits2_b; - typedef CGAL::Linear_cell_complex_traits <3, CGAL::Exact_predicates_inexact_constructions_kernel> Traits3_a; typedef CGAL::Linear_cell_complex_traits <3, CGAL::Exact_predicates_exact_constructions_kernel> Traits3_b; -typedef CGAL::Linear_cell_complex_traits -<4, CGAL::Exact_predicates_inexact_constructions_kernel> Traits4_a; +typedef CGAL::Linear_cell_complex_traits<4> Traits4_a; -// void, void, void -typedef CGAL::Linear_cell_complex<2,2, Traits2_a, CGAL::Linear_cell_complex_min_items<2> > Map1; +// Point_3, void, void +typedef CGAL::Linear_cell_complex<2,3, Traits3_a, CGAL::Linear_cell_complex_min_items<2> > Map1; -// double, void, double -typedef CGAL::Linear_cell_complex<2,2, Traits2_a, Map_2_dart_items > Map2; +// Point_3+double, void, double +typedef CGAL::Linear_cell_complex<2,3, Traits3_a, Map_2_dart_items > Map2; -// int, int, double -typedef CGAL::Linear_cell_complex<2,2, Traits2_b, Map_2_dart_max_items_3> Map3; +// Point_3+int, int, double +typedef CGAL::Linear_cell_complex<2,3, Traits3_b, Map_2_dart_max_items_3> Map3; -// void, void, void, void -typedef CGAL::Linear_cell_complex<3,3, Traits3_a, CGAL::Combinatorial_map_min_items<3> > Map4; +// Point_3, void, void, void +typedef CGAL::Linear_cell_complex<3,3, Traits3_a, CGAL::Linear_cell_complex_min_items<3> > Map4; -// double, void, int, double +// Point_3+double, void, int, double typedef CGAL::Linear_cell_complex<3,3, Traits3_a, Map_3_dart_items_3> Map5; -// int, int, int, double +// Point_3+int, int, int, double typedef CGAL::Linear_cell_complex<3,3, Traits3_b, Map_3_dart_max_items_3> Map6; -// int, void, int, void +// Point_4+int, void, int, void typedef CGAL::Linear_cell_complex<3,4, Traits4_a, Another_map_3_dart_items_3> Map7; -// int, void, int, void, int -typedef CGAL::Linear_cell_complex<4, Traits4_a, Map_dart_items_4> Map8; +// Point_4+int, void, int, void, int +typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_items_4> Map8; -// int, int, int, double, double -typedef CGAL::Linear_cell_complex<4, Traits4_a, Map_dart_max_items_4> Map9; +// Point_4+int, int, int, double, double +typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_max_items_4> Map9; /* template @@ -188,12 +189,47 @@ struct CreateAttributes } }; +template +struct SetInfoIfNonVoid +{ + static void run(Attr&attr, int&nb) + { + if ( attr.info()==0 ) attr.info()=(++nb); + } +}; +template +struct SetInfoIfNonVoid +{ + static void run(Attr&attr, int&nb) + {} +}; + +template +struct CreateAttributes +{ + static void run(Map& map) + { + int nb=0; + for(typename Map::Dart_range::iterator it=map.darts().begin(), + itend=map.darts().end(); it!=itend; ++it) + { + SetInfoIfNonVoid::run(*it->template attribute<0>(), nb); + } + } +}; + template struct CreateAttributes { static void run(Map&) - { - } + {} +}; + +template +struct CreateAttributes +{ + static void run(Map&) + {} }; template::run(amap); DisplayAttribs::run(amap); DisplayAttribs::run(amap); + + std::cout<<"Points: "; + for ( typename Map::template Attribute_range<0>::type::iterator + it=amap.template attributes<0>().begin(), + itend=amap.template attributes<0>().end(); + it!=itend; ++it ) + { + std::cout<point()<<"; "; + } + std::cout< void create2Dmap(Map& map) { for ( int i=0; i<15; ++i ) - CGAL::make_combinatorial_hexahedron(map); + map.make_tetrahedron(typename Map::Point(i, 0, 0),typename Map::Point(i, 2, 0), + typename Map::Point(i+1, 0, 0),typename Map::Point(i+1, 1, 2)); CreateAttributes::run(map); CreateAttributes::run(map); CreateAttributes::run(map); @@ -242,7 +290,8 @@ template void create3Dmap(Map& map) { for ( int i=0; i<15; ++i ) - CGAL::make_combinatorial_hexahedron(map); + map.make_tetrahedron(typename Map::Point(i, 0, 0),typename Map::Point(i, 2, 0), + typename Map::Point(i+1, 0, 0),typename Map::Point(i+1, 1, 2)); for ( int i=0; i<20; ++i ) { @@ -257,11 +306,24 @@ void create3Dmap(Map& map) CreateAttributes::run(map); CreateAttributes::run(map); } + +template +typename LCC::Point apoint(typename LCC::FT x, typename LCC::FT y, + typename LCC::FT z, typename LCC::FT t) +{ + std::vector tab; + tab.push_back(x); tab.push_back(y); + tab.push_back(z); tab.push_back(t); + typename LCC::Point p(4,tab.begin(),tab.end()); + return p; +} + template void create4Dmap(Map& map) { for ( int i=0; i<45; ++i ) - CGAL::make_combinatorial_hexahedron(map); + map.make_tetrahedron(apoint(i, 0, 0, 0),apoint(i, 2, 0, 0), + apoint(i+1, 0, 0, 0),apoint(i+1, 1, 2, 0)); for ( int i=0; i<40; ++i ) { From 6fca9919239206f2c61b0023d09953b0a70208e6 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Sun, 2 Jun 2013 21:07:33 +0200 Subject: [PATCH 07/21] Copy constructor for cmap cont --- .../include/CGAL/Cell_attribute.h | 25 -- .../include/CGAL/Combinatorial_map.h | 47 +++- .../Combinatorial_map_copy_functors.h | 172 ++++++++++++ .../Combinatorial_map_internal_functors.h | 252 +++--------------- .../Combinatorial_map_copy_test.cpp | 4 +- .../include/CGAL/Cell_attribute_with_point.h | 40 +-- .../include/CGAL/Linear_cell_complex.h | 12 +- .../Linear_cell_complex_copy_functors.h | 178 +++++++++++++ .../Linear_cell_complex_copy_test.cpp | 8 +- 9 files changed, 443 insertions(+), 295 deletions(-) create mode 100644 Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h create mode 100644 Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index 093b0765286..c5cc9875eed 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -284,10 +284,6 @@ namespace CGAL { template friend class Compact_container; - template - friend struct internal::Copy_attr_if_same_type; - public: typedef Tag_ Supports_cell_dart; typedef typename Refs::Dart_handle Dart_handle; @@ -297,18 +293,10 @@ namespace CGAL { typedef OnSplit On_split; typedef void Info; - typedef CGAL::Void Point; - protected: /// Default contructor. Cell_attribute() {} - - /// Copy the info of an attribute in parameter, if same type. - /// Nothing to do as this attribute has no info. - template - void copy(const Attr2&) - {} }; @@ -327,10 +315,6 @@ namespace CGAL { template friend class Compact_container; - template - friend struct internal::Copy_attr_if_same_type; - public: typedef Cell_attribute Self; @@ -342,8 +326,6 @@ namespace CGAL { typedef OnSplit On_split; typedef Info_ Info; - typedef CGAL::Void Point; - protected: /// Default contructor. Cell_attribute() @@ -353,13 +335,6 @@ namespace CGAL { Cell_attribute(const Info_& ainfo) : Info_for_cell_attribute(ainfo) {} - - /// Copy the info of an attribute in parameter, if same type. - template - void copy(const Attr2& aattr) - { - internal::Set_info_if_same_type::run(*this, aattr); - } }; } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 99e67e81f55..402d258e263 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -24,6 +24,7 @@ #include #include #include +#include #include #include #include @@ -157,10 +158,12 @@ namespace CGAL { * @param amap the combinatorial map to copy. * @post *this is valid. */ - template - void copy(const Combinatorial_map_base & amap) + template + void copy(const Combinatorial_map_base & amap, + Converters& converters) { - typedef Combinatorial_map_base CMap2; + typedef Combinatorial_map_base CMap2; this->clear(); @@ -224,22 +227,34 @@ namespace CGAL { ++dartmap_iter) { Helper::template Foreach_enabled_attributes - < internal::Copy_attributes_functor >:: - run(this, &amap, dartmap_iter->second, dartmap_iter->first); + < internal::Copy_attributes_functor >:: + run(&amap, this, dartmap_iter->first, dartmap_iter->second, + converters); } CGAL_assertion (is_valid () == 1); } + template + void copy(const Combinatorial_map_base & amap) + { + CGAL::cpp11::tuple<> converters; + return copy< dbis,Refsbis,Itemsbis,Allocbis,CGAL::cpp11::tuple<> > + (amap, converters); + } + // Copy constructor from a map having exactly the same type. Combinatorial_map_base (const Self & amap) - { copy(amap); } + { copy(amap); } // "Copy constructor" from a map having different type. - template - Combinatorial_map_base(const Combinatorial_map_base - & amap) - { copy(amap); } + template + Combinatorial_map_base(const Combinatorial_map_base + & amap, + Converters& converters=CGAL::cpp11::tuple<>()) + { copy(amap, converters); } /** Affectation operation. Copies one map to the other. * @param amap a combinatorial map. @@ -3490,12 +3505,16 @@ namespace CGAL { Combinatorial_map() : Base() {} - template < class CMap > - Combinatorial_map(const CMap & amap) : Base(amap) - {} - Combinatorial_map(const Self & amap) : Base(amap) {} + + template < class CMap > + Combinatorial_map(const CMap & amap) + { Base::copy(amap); } + + template < class CMap, typename Converters > + Combinatorial_map(const CMap & amap, Converters& converters) + { Base::copy(amap, converters); } }; } // namespace CGAL diff --git a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h new file mode 100644 index 00000000000..ca329718af2 --- /dev/null +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -0,0 +1,172 @@ +// Copyright (c) 2010-2013 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H +#define CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H + +/* Definition of functors used internally to copy combinatorial maps attributes + * (we need functors as attributes are stored in tuple, thus all the access + * must be done at compiling time). + */ +namespace CGAL +{ +// **************************************************************************** +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 > +struct Default_converter_two_non_void_attributes_cmap +{ + static typename Map2::template Attribute_handle::type + run(Map2&, typename Map1::template Attribute_const_handle::type) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i> +struct Default_converter_two_non_void_attributes_cmap +{ + static typename Map2::template Attribute_handle::type + run(Map2&, typename Map1::template Attribute_const_handle::type) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i, typename Info1 > +struct Default_converter_two_non_void_attributes_cmap +{ + static typename Map2::template Attribute_handle::type + run(Map2&, typename Map1::template Attribute_const_handle::type) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i, typename Info2 > +struct Default_converter_two_non_void_attributes_cmap +{ + static typename Map2::template Attribute_handle::type + run(Map2&, typename Map1::template Attribute_const_handle::type) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i, typename Info > +struct Default_converter_two_non_void_attributes_cmap +{ + static typename Map2::template Attribute_handle::type + run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) + { + if ( ah!=NULL ) + return map2.template create_attribute(ah->info()); + + return map2.template create_attribute(); + } +}; + +// Map1 is the existing map, to convert into map2. +template< typename Map1, typename Map2, unsigned int i, + typename Attr1=typename Map1::template Attribute_type::type, + typename Attr2=typename Map2::template Attribute_type::type > +struct Default_converter_cmap_attr +{ + typename Map2::template Attribute_handle::type operator() + (Map2& map2, typename Map1::Dart_const_handle dh1) + { return Default_converter_two_non_void_attributes_cmap + :: + run(map2, dh1->template attribute()); } +}; + +template< typename Map1, typename Map2, unsigned int i, + typename Attr1> +struct Default_converter_cmap_attr +{ + typename Map2::template Attribute_handle::type operator() + (Map2&, typename Map1::Dart_const_handle) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i, + typename Attr2> +struct Default_converter_cmap_attr +{ + typename Map2::template Attribute_handle::type operator() + (Map2&, typename Map1::Dart_const_handle) + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i> +struct Default_converter_cmap_attr +{ + typename Map2::template Attribute_handle::type operator() + (Map2&, typename Map1::Dart_const_handle) + { return NULL; } +}; + +template=My_length::value)> +struct Convert_attribute_functor +{ + static typename Map2::template Attribute_handle::type + run( Map2* cmap2, typename Map1::Dart_const_handle dh1, + const Converters& converters) + { + return Default_converter_cmap_attr() (*cmap2, dh1); + } +}; + +template +struct Convert_attribute_functor +{ + static typename Map2::template Attribute_handle::type + run( Map2* cmap2, typename Map1::Dart_const_handle dh1, + const Converters& converters) + { + return CGAL::cpp11::get(converters) (*cmap2, dh1); + } +}; + + +/// Copy enabled attributes from one cmap to other +template +struct Copy_attributes_functor +{ + template + static void run( const Map1* cmap1, + Map2* cmap2, + typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2, + const Converters& converters) + { + typename Map2::template Attribute_handle::type res=NULL; + + /* if ( i>=My_length::value ) + res = Default_converter_cmap_attr() + (*cmap2, dh1->template attribute()); + else + res =CGAL::cpp11::get(converters) + (*cmap2, dh1->template attribute());*/ + res=Convert_attribute_functor::run(cmap2,dh1,converters); + + if ( res!=NULL ) + cmap2->template set_attribute(dh2, res); + } +}; +// **************************************************************************** +} // namespace internal +} // namespace CGAL + +#endif // CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H 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 93651b8f7f9..f71354795f7 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -22,9 +22,6 @@ #include #include -#include -#include -#include #include /* Definition of functors used internally to manage attributes (we need @@ -61,6 +58,9 @@ * * internal::Set_i_attribute_of_dart_functor to set the i-attribute * of a given dart. + * + * internal::Test_is_same_attribute_functor to test if two + * i-attributes of two darts are isomorphic. */ namespace CGAL @@ -416,225 +416,42 @@ struct Set_i_attribute_of_dart_functor {} }; // **************************************************************************** -// Functor allowing to set the value of a point if point exist, have -// same dimension. For dim>3, if type of points are the same (because no converter). -template -struct Set_point_d_if_same -{ - static void run(Point1&, const Point2&) - {} -}; - -template -struct Set_point_d_if_same -{ - static void run(Point1& p1, const Point1& p2) - { - p1 = p2; // Copy of Point_d having same type - } -}; - -template::type, - typename T2=typename Ambient_dimension::type> -struct Set_point_if_possible -{ - static void run(Point1&, const Point2&) - {} -}; - -template -struct Set_point_if_possible, Dimension_tag<2> > -{ - static void run(Point1& p1, const Point2& p2) - { - p1 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>(p2); - } -}; - -template -struct Set_point_if_possible, Dimension_tag<3> > -{ - static void run(Point1& p1, const Point2& p2) - { - p1 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>(p2); - } -}; - -template -struct Set_point_if_possible -{ - static void run(Point1& p1, const Point2& p2) - { - if ( p1.dimension()==p2.dimension() ) - Set_point_d_if_same::run(p1, p2); - } -}; - -// Set_point_if_exist ensure that Attr2 has a point -template -struct Set_point_if_exist -{ - static void run(Point1& p1, const Attr2& a2) - { - Set_point_if_possible(p1, a2.point()); - } -}; - -template -struct Set_point_if_exist -{ - static void run(Point1&, const Attr2& ) - {} -}; - -// Functor allowing to set a value if two info are the same or not -// TODO replace these version by using is_constructible ? -// if no support for gcc11, use this simplified version ? (same type) -template -struct Set_info_if_same_type -{ - static void run(Attr1&, const Attr2&) - {} -}; - -template -struct Set_info_if_same_type -{ - static void run(Attr1&, const Attr2&) - {} -}; - -template -struct Set_info_if_same_type -{ - static void run(Attr1&, const Attr2&) - {} -}; - -template -struct Set_info_if_same_type -{ - static void run(Attr1&, const Attr2&) - {} -}; - -template -struct Set_info_if_same_type -{ - static void run(Attr1& a1, const Attr2& a2) - { a1.info()=a2.info(); } -}; - -// Functor allowing to copy attributes whey info are convertible -template -struct Copy_attr_if_same_type -{ - static void const run(Map1* cmap1, const Map2* cmap2, - typename Map1::Dart_handle dh1, - typename Map2::Dart_const_handle dh2) - {} -}; - -template -struct Copy_attr_if_same_type -{ - static void const run(Map1* cmap1, const Map2* cmap2, - typename Map1::Dart_handle dh1, - typename Map2::Dart_const_handle dh2) - { - CGAL_static_assertion(i<=Map2::dimension); - if (dh1->template attribute()==NULL && - dh2->template attribute()!=NULL) - { - cmap1->template - set_attribute(dh1, cmap1->template create_attribute()); - dh1->template attribute()->copy(*dh2->template attribute()); - } - } -}; - -// Case of two non void type -template -struct Copy_attr_functor -{ - static void const run(Map1* cmap1, const Map2* cmap2, - typename Map1::Dart_handle dh1, - typename Map2::Dart_const_handle dh2) - { - Copy_attr_if_same_type:: - run(cmap1, cmap2, dh1, dh2); - } -}; - -// Case T1==void -template -struct Copy_attr_functor -{ - static void const run(Map1*, const Map2*, - typename Map1::Dart_handle, - typename Map2::Dart_const_handle) - {} -}; - -// Case T2==void -template -struct Copy_attr_functor -{ - static void const run(Map1*, const Map2*, - typename Map1::Dart_handle, - typename Map2::Dart_const_handle) - {} -}; - -// Case T1==T2==void -template -struct Copy_attr_functor -{ - static void const run(Map1*, const Map2*, - typename Map1::Dart_handle, - typename Map2::Dart_const_handle) - {} -}; - -/// Copy enabled attributes from one cmap to other -template -struct Copy_attributes_functor{ - template - static void run( Map1* cmap1, - const Map2* cmap2, - typename Map1::Dart_handle dh1, - typename Map2::Dart_const_handle dh2 ) - { - Copy_attr_functor::type, - typename Map2::Helper::template Attribute_type::type> - ::run(cmap1, cmap2, dh1, dh2); - } -}; -// **************************************************************************** // Functor allowing to test if two info are the same or not -template +template< typename Attr1, typename Attr2, + typename Info1=typename Attr1::Info, + typename Info2=typename Attr2::Info > struct Is_same_info { - static bool run(const T1&, const T2&) + static bool run(const Attr1&, const Attr2&) { return false; } }; -template -struct Is_same_info +template< typename Attr1, typename Attr2, typename Info1 > +struct Is_same_info { - static bool run(const T1&e1, const T1&e2) - { return e1==e2; } + static bool run(const Attr1&, const Attr2&) + { return false; } +}; + +template< typename Attr1, typename Attr2, typename Info2 > +struct Is_same_info +{ + static bool run(const Attr1&, const Attr2&) + { return false; } +}; + +template< typename Attr1, typename Attr2 > +struct Is_same_info +{ + static bool run(const Attr1&, const Attr2&) + { return true; } +}; + +template< typename Attr1, typename Attr2, typename Info > +struct Is_same_info +{ + static bool run(const Attr1&a1, const Attr2&a2) + { return a1.info()==a2.info(); } }; // Case of two non void type @@ -654,9 +471,8 @@ struct Is_same_attribute_functor return false; return - Is_same_info:: - run(dh1->template attribute()->info(), - dh2->template attribute()->info()); + Is_same_info::run(*(dh1->template attribute()), + *(dh2->template attribute())); } }; diff --git a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp index 347475e03ad..3bd89cdfba0 100644 --- a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp +++ b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp @@ -333,8 +333,8 @@ bool testCopy() Map6 map6; create3Dmap(map6); Map7 map7; create3Dmap(map7); - Map8 map8; create3Dmap(map8); - Map9 map9; create3Dmap(map9); + Map8 map8; create4Dmap(map8); + Map9 map9; create4Dmap(map9); // First copy of same types { diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index de66f44e50f..11a8b21af6d 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -49,13 +49,6 @@ namespace CGAL { const Point& point() const { return mpoint; } - /// Copy the point of an attribute in parameter. - template - void copy(const Attr2& aattr) - { - internal::Set_point_if_exist::run(point(), aattr); - } - protected: /// The point associated with the cell. Point mpoint; @@ -70,9 +63,12 @@ namespace CGAL { Functor_on_merge_, Functor_on_split_>, public Point_for_cell { - template - friend struct internal::Copy_attr_if_same_type; + template < unsigned int d_, class Refs_, + class Items_, class Alloc_ > + friend class Combinatorial_map_base; + + template + friend class Compact_container; public: typedef Cell_attribute_with_point - void copy(const Attr2& aattr) - { - Base1::copy(aattr); - Base2::copy(aattr); - } }; /// Attribute associated with a point and without info. @@ -125,9 +113,12 @@ namespace CGAL { public Cell_attribute, public Point_for_cell { - template - friend struct internal::Copy_attr_if_same_type; + template < unsigned int d_, class Refs_, + class Items_, class Alloc_ > + friend class Combinatorial_map_base; + + template + friend class Compact_container; public: typedef Cell_attribute - void copy(const Attr2& aattr) - { - Base2::copy(aattr); - } }; } // namespace CGAL diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index 5613414da8c..51f4378743c 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -87,13 +87,17 @@ namespace CGAL { Linear_cell_complex() : Base() {} - template < class LCC > - Linear_cell_complex(const LCC & alcc) : Base(alcc) - {} - Linear_cell_complex(const Self & alcc) : Base(alcc) {} + template < class LCC > + Linear_cell_complex(const LCC & alcc) + { Base::copy(alcc);} + + template < class LCC, typename Converters > + Linear_cell_complex(const LCC & alcc, Converters& converters) + { Base::copy(alcc, converters);} + /** Create a vertex attribute. * @return an handle on the new attribute. */ 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 new file mode 100644 index 00000000000..1406aa3ffa8 --- /dev/null +++ b/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h @@ -0,0 +1,178 @@ +// Copyright (c) 2010-2013 CNRS and LIRIS' Establishments (France). +// All rights reserved. +// +// This file is part of CGAL (www.cgal.org); you can redistribute it and/or +// modify it under the terms of the GNU Lesser General Public License as +// published by the Free Software Foundation; either version 3 of the License, +// or (at your option) any later version. +// +// Licensees holding a valid commercial license may use this file in +// accordance with the commercial license agreement provided with the software. +// +// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE +// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. +// +// $URL$ +// $Id$ +// +// Author(s) : Guillaume Damiand +// +#ifndef CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H +#define CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H 1 + +#include +#include +#include + +/* Definition of functors used internally to copy linear cell complex attributes + * (we need functors as attributes are stored in tuple, thus all the access + * must be done at compiling time). + */ +namespace CGAL +{ +// **************************************************************************** +namespace internal +{ +// **************************************************************************** +// Functor allowing to set the value of a point if point exist, have +// same dimension. For dim>3, if type of points are the same (because no converter). +template +struct Set_point_d_if_same +{ + static void run(const Point1&, Point2&) + {} +}; + +template +struct Set_point_d_if_same +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; // Copy of Point_d having same type + } +}; + +template::type, + typename T2=typename Ambient_dimension::type> +struct Set_point_if_possible +{ + static void run(const Point1&, Point2&) + {} +}; + +template +struct Set_point_if_possible, Dimension_tag<2> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>(p1); + } +}; + +template +struct Set_point_if_possible, Dimension_tag<3> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>()(p1); + } +}; + +template +struct Set_point_if_possible +{ + static void run(const Point1& p1, Point2& p2) + { + if ( p1.dimension()==p2.dimension() ) + Set_point_d_if_same::run(p1, p2); + } +}; + +// Set_point_if_exist if Attr1 has a point +template< typename Attr1, typename Attr2, + typename Point1=typename Attr1::Point, + typename Point2=typename Attr2::Point > +struct Set_point_if_exist +{ + static void run(const Attr1& a1, Attr2& a2) + { + Set_point_if_possible::run(a1.point(), a2.point()); + } +}; + +template +struct Set_point_if_exist +{ + static void run(const Attr1&, Attr2&) + {} +}; +// **************************************************************************** +// 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, + 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) + { + typename Map2::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 ); + } + return res; + } +}; + +template< typename Map1, typename Map2, 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) + { + typename Map2::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 ); + } + return res; + } +}; + +template< typename Map1, typename Map2, 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) + { + typename Map2::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 ); + } + return res; + } +}; + +// **************************************************************************** +} // namespace internal +} // namespace CGAL + +#endif // CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index cba49e93411..c21f1bf4d27 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -151,8 +151,8 @@ typedef CGAL::Linear_cell_complex<3,3, Traits3_a, Map_3_dart_items_3> Map5; // Point_3+int, int, int, double typedef CGAL::Linear_cell_complex<3,3, Traits3_b, Map_3_dart_max_items_3> Map6; -// Point_4+int, void, int, void -typedef CGAL::Linear_cell_complex<3,4, Traits4_a, Another_map_3_dart_items_3> Map7; +// Point_3+int, void, int, void +typedef CGAL::Linear_cell_complex<3,3, Traits3_b, Another_map_3_dart_items_3> Map7; // Point_4+int, void, int, void, int typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_items_4> Map8; @@ -360,8 +360,8 @@ bool testCopy() Map6 map6; create3Dmap(map6); Map7 map7; create3Dmap(map7); - Map8 map8; create3Dmap(map8); - Map9 map9; create3Dmap(map9); + Map8 map8; create4Dmap(map8); + Map9 map9; create4Dmap(map9); // First copy of same types { From 13a1bf5903b7a683308ae866500714869a6ebe8c Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 3 Jun 2013 09:10:44 +0200 Subject: [PATCH 08/21] cont... --- .../Combinatorial_map_copy_functors.h | 8 +- .../include/CGAL/Linear_cell_complex.h | 107 +++++++++++++++++- 2 files changed, 109 insertions(+), 6 deletions(-) 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 ca329718af2..8a9d6b9e6bf 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -70,10 +70,10 @@ struct Default_converter_two_non_void_attributes_cmap static typename Map2::template Attribute_handle::type run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) { - if ( ah!=NULL ) - return map2.template create_attribute(ah->info()); - - return map2.template create_attribute(); + typename Map2::template Attribute_handle::type + res = map2.template create_attribute(); + if ( ah!=NULL ) res->info() = ah->info(); + return res; } }; diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index 51f4378743c..17d90689327 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -87,8 +87,111 @@ namespace CGAL { Linear_cell_complex() : Base() {} - Linear_cell_complex(const Self & alcc) : Base(alcc) - {} + /** Copy the given linear cell complex into *this. + * Note that both LCC can have different dimensions and/or non void attributes. + * @param alcc the linear cell complex to copy. + * @post *this is valid. + */ + template + void copy(const Linear_cell_complex & alcc, + Converters& converters) + { + typedef Linear_cell_complex LCC2; + + 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); + } + + template + void copy(const Linear_cell_complex & alcc) + { + CGAL::cpp11::tuple<> converters; + return copy< dbis,Refsbis,Itemsbis,Allocbis,CGAL::cpp11::tuple<> > + (amap, converters); + } + + Linear_cell_complex(const Self & alcc) + { copy(alcc); } template < class LCC > Linear_cell_complex(const LCC & alcc) From 2fcd25ad139b963d3a228aa562d08fa552d7442b Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 3 Jun 2013 13:58:31 +0200 Subject: [PATCH 09/21] copy cont... --- .../include/CGAL/Combinatorial_map.h | 3 + .../Combinatorial_map_copy_functors.h | 20 ++--- .../Combinatorial_map_copy_test.cpp | 79 +++++++++++++++++-- 3 files changed, 84 insertions(+), 18 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 402d258e263..245ba84c0bb 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -3368,6 +3368,9 @@ namespace CGAL { } } + // Here we test if both queue are empty + if ( !toTreat1.empty() || !toTreat2.empty() ) match = false; + // Here we unmark all the marked darts. toTreat1.clear(); toTreat2.clear(); 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 ca329718af2..c4198110533 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -20,6 +20,8 @@ #ifndef CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H #define CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H +#include + /* Definition of functors used internally to copy combinatorial maps attributes * (we need functors as attributes are stored in tuple, thus all the access * must be done at compiling time). @@ -117,7 +119,7 @@ struct Default_converter_cmap_attr }; template=My_length::value)> + bool t=(i>=boost::tuples::length::value)> struct Convert_attribute_functor { static typename Map2::template Attribute_handle::type @@ -135,6 +137,7 @@ struct Convert_attribute_functor run( Map2* cmap2, typename Map1::Dart_const_handle dh1, const Converters& converters) { + return CGAL::cpp11::get(converters) (*cmap2, dh1); } }; @@ -151,18 +154,15 @@ struct Copy_attributes_functor typename Map2::Dart_handle dh2, const Converters& converters) { - typename Map2::template Attribute_handle::type res=NULL; - - /* if ( i>=My_length::value ) - res = Default_converter_cmap_attr() - (*cmap2, dh1->template attribute()); - else - res =CGAL::cpp11::get(converters) - (*cmap2, dh1->template attribute());*/ - res=Convert_attribute_functor::run(cmap2,dh1,converters); + if (dh2->template attribute()==NULL) + { + typename Map2::template Attribute_handle::type + res=Convert_attribute_functor:: + run(cmap2,dh1,converters); if ( res!=NULL ) cmap2->template set_attribute(dh2, res); + } } }; // **************************************************************************** diff --git a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp index 3bd89cdfba0..ddecd2bc640 100644 --- a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp +++ b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp @@ -162,7 +162,7 @@ struct Map_dart_max_items_4 typedef CGAL::Cell_attribute< Refs, double > Double_attrib; typedef CGAL::cpp11::tuple + Int_attrib, Int_attrib, Double_attrib> Attributes; }; }; @@ -191,9 +191,28 @@ typedef CGAL::Combinatorial_map<3, Another_map_3_dart_items_3> Map7; // int, void, int, void, int typedef CGAL::Combinatorial_map<4, Map_dart_items_4> Map8; -// int, int, int, double, double +// int, int, int, int, double typedef CGAL::Combinatorial_map<4, Map_dart_max_items_4> Map9; +// Convert a number type into another number type +// @pre Both info must be non void and number types +template< typename Map1, typename Map2, unsigned int i> +struct Number_type_converter_cmap_attr +{ + typename Map2::template Attribute_handle::type operator() + (Map2& map2, typename Map1::Dart_const_handle dh) //const + { + std::cout<<"Number type converter<"<\n"; + if ( dh->template attribute()!=NULL ) + return map2.template create_attribute + ((typename Map2::template Attribute_type::type::Info) + dh->template attribute()->info()); + + return map2.template create_attribute(); + } +}; + + /* template typename Map::Dart_handle getRandomDart(Map& map) @@ -461,17 +480,61 @@ bool testCopy() map2a.number_of_attributes<2>()==0 && map2a.number_of_attributes<3>()==0 ); assert( map2a.is_isomorphic_to(map2)==map2.is_isomorphic_to(map2a) ); - //map2.display_characteristics(std::cout)<()==map2.number_of_attributes<0>() && + if ( map5a.is_isomorphic_to(map5) ) { assert(false); return false; } + assert( map5a.number_of_attributes<0>()>=map5.number_of_attributes<0>() && map5a.number_of_attributes<2>()==0 ); - //map5.display_characteristics(std::cout)<()<<" " + <()<<" " + <()<<" " + <()<()==0 && + map9a.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9a.number_of_attributes<3>()==0 ); + assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); + + /*CGAL::cpp11::tuple*/ + typedef boost::tuple >/*, + CGAL::internal::Default_converter_cmap_attr, + CGAL::internal::Default_converter_cmap_attr, + Number_type_converter_cmap_attr >*/ MyConverters; + + + Number_type_converter_cmap_attr c0; + CGAL::internal::Default_converter_cmap_attr c1; + CGAL::internal::Default_converter_cmap_attr c2; + Number_type_converter_cmap_attr c3; + + c0(map5,map9.darts().begin()); + + MyConverters myconverters(c0); //, c1, c2, c3); + Map5 map9b(map9, myconverters); assert(map9a.is_valid()); + if ( map9b.is_isomorphic_to(map9) ) { assert(false); return false; } + + map9.display_characteristics(std::cout)<()<<" " + <()<<" " + <()<<" " + <()<<" " + <()<<" " + <()<()>=map9.number_of_attributes<0>() && + map9b.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9b.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); + assert( map9b.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9b) ); + } + //map5.display_characteristics(std::cout)< Date: Mon, 3 Jun 2013 15:37:43 +0200 Subject: [PATCH 10/21] cont tests for copy --- .../include/CGAL/Combinatorial_map.h | 45 ++++---- .../Combinatorial_map_copy_functors.h | 107 ++++++++++------- .../Combinatorial_map_copy_test.cpp | 108 ++++++++++-------- 3 files changed, 145 insertions(+), 115 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 245ba84c0bb..27beb6e8d21 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -158,13 +158,9 @@ namespace CGAL { * @param amap the combinatorial map to copy. * @post *this is valid. */ - template - void copy(const Combinatorial_map_base & amap, - Converters& converters) + template + void copy(const CMap2& amap, Converters& converters) { - typedef Combinatorial_map_base CMap2; - this->clear(); this->mnb_used_marks = amap.mnb_used_marks; @@ -227,34 +223,35 @@ namespace CGAL { ++dartmap_iter) { Helper::template Foreach_enabled_attributes - < internal::Copy_attributes_functor >:: - run(&amap, this, dartmap_iter->first, dartmap_iter->second, + < internal::Copy_attributes_functor >:: + run(&amap, static_cast(this), + dartmap_iter->first, dartmap_iter->second, converters); } CGAL_assertion (is_valid () == 1); } - template - void copy(const Combinatorial_map_base & amap) + template + void copy(const CMap2 & amap) { CGAL::cpp11::tuple<> converters; - return copy< dbis,Refsbis,Itemsbis,Allocbis,CGAL::cpp11::tuple<> > - (amap, converters); + return copy< CMap2, CGAL::cpp11::tuple<> >(amap, converters); } // Copy constructor from a map having exactly the same type. Combinatorial_map_base (const Self & amap) - { copy(amap); } + { copy(amap); } // "Copy constructor" from a map having different type. - template - Combinatorial_map_base(const Combinatorial_map_base - & amap, - Converters& converters=CGAL::cpp11::tuple<>()) - { copy(amap, converters); } + template + Combinatorial_map_base(const CMap2& amap) + { copy(amap); } + + // "Copy constructor" from a map having different type. + template + Combinatorial_map_base(const CMap2& amap, Converters& converters) + { copy(amap, converters); } /** Affectation operation. Copies one map to the other. * @param amap a combinatorial map. @@ -3508,16 +3505,16 @@ namespace CGAL { Combinatorial_map() : Base() {} - Combinatorial_map(const Self & amap) : Base(amap) - {} + Combinatorial_map(const Self & amap) + { Base::template copy(amap); } template < class CMap > Combinatorial_map(const CMap & amap) - { Base::copy(amap); } + { Base::template copy(amap); } template < class CMap, typename Converters > Combinatorial_map(const CMap & amap, Converters& converters) - { Base::copy(amap, converters); } + { Base::template copy(amap, converters); } }; } // namespace CGAL 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 c631a67b2ae..49e89892dd1 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -28,6 +28,10 @@ */ namespace CGAL { +template< typename Map1, typename Map2, unsigned int i, + typename Attr1=typename Map1::template Attribute_type::type, + typename Attr2=typename Map2::template Attribute_type::type > +struct Default_converter_cmap_attributes; // **************************************************************************** namespace internal { @@ -79,45 +83,6 @@ struct Default_converter_two_non_void_attributes_cmap } }; -// Map1 is the existing map, to convert into map2. -template< typename Map1, typename Map2, unsigned int i, - typename Attr1=typename Map1::template Attribute_type::type, - typename Attr2=typename Map2::template Attribute_type::type > -struct Default_converter_cmap_attr -{ - typename Map2::template Attribute_handle::type operator() - (Map2& map2, typename Map1::Dart_const_handle dh1) - { return Default_converter_two_non_void_attributes_cmap - :: - run(map2, dh1->template attribute()); } -}; - -template< typename Map1, typename Map2, unsigned int i, - typename Attr1> -struct Default_converter_cmap_attr -{ - typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i, - typename Attr2> -struct Default_converter_cmap_attr -{ - typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i> -struct Default_converter_cmap_attr -{ - typename Map2::template Attribute_handle::type operator() - (Map2&, typename Map1::Dart_const_handle) - { return NULL; } -}; - template=boost::tuples::length::value)> struct Convert_attribute_functor @@ -126,7 +91,7 @@ struct Convert_attribute_functor run( Map2* cmap2, typename Map1::Dart_const_handle dh1, const Converters& converters) { - return Default_converter_cmap_attr() (*cmap2, dh1); + return CGAL::Default_converter_cmap_attributes() (*cmap2, dh1); } }; @@ -137,7 +102,6 @@ struct Convert_attribute_functor run( Map2* cmap2, typename Map1::Dart_const_handle dh1, const Converters& converters) { - return CGAL::cpp11::get(converters) (*cmap2, dh1); } }; @@ -167,6 +131,67 @@ struct Copy_attributes_functor }; // **************************************************************************** } // namespace internal +// **************************************************************************** +// Map1 is the existing map, to convert into map2. +// Default converter copy only attributes if they have +// same info types. +template< typename Map1, typename Map2, unsigned int i, + typename Attr1,typename Attr2 > +struct Default_converter_cmap_attributes +{ + typename Map2::template Attribute_handle::type operator() + (Map2& map2, typename Map1::Dart_const_handle dh1) const + { return internal::Default_converter_two_non_void_attributes_cmap + :: + run(map2, dh1->template attribute()); } +}; + +template< typename Map1, typename Map2, unsigned int i, + typename Attr1> +struct Default_converter_cmap_attributes +{ + typename Map2::template Attribute_handle::type operator() + (Map2&, typename Map1::Dart_const_handle) const + { return NULL; } +}; + +template< typename Map1, typename Map2, unsigned int i, + typename Attr2> +struct Default_converter_cmap_attributes +{ + typename Map2::template Attribute_handle::type operator() + (Map2&, typename Map1::Dart_const_handle) const + { return NULL; } +}; + +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 + { return NULL; } +}; + +// Map1 is the existing map, to convert into map2. +// Cast converter copy always copy attributes, doing +// a cast. This works only if both types are convertible +// (and this is user responsability to use it only in +// this case). +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 + { + if ( dh->template attribute()!=NULL ) + return map2.template create_attribute + ((typename Map2::template Attribute_type::type::Info) + dh->template attribute()->info()); + + return map2.template create_attribute(); + } +}; +// **************************************************************************** } // namespace CGAL #endif // CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H diff --git a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp index ddecd2bc640..b50490b4c57 100644 --- a/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp +++ b/Combinatorial_map/test/Combinatorial_map/Combinatorial_map_copy_test.cpp @@ -194,25 +194,6 @@ typedef CGAL::Combinatorial_map<4, Map_dart_items_4> Map8; // int, int, int, int, double typedef CGAL::Combinatorial_map<4, Map_dart_max_items_4> Map9; -// Convert a number type into another number type -// @pre Both info must be non void and number types -template< typename Map1, typename Map2, unsigned int i> -struct Number_type_converter_cmap_attr -{ - typename Map2::template Attribute_handle::type operator() - (Map2& map2, typename Map1::Dart_const_handle dh) //const - { - std::cout<<"Number type converter<"<\n"; - if ( dh->template attribute()!=NULL ) - return map2.template create_attribute - ((typename Map2::template Attribute_type::type::Info) - dh->template attribute()->info()); - - return map2.template create_attribute(); - } -}; - - /* template typename Map::Dart_handle getRandomDart(Map& map) @@ -283,6 +264,27 @@ void displayAllAttribs2D(Map& amap, const char* c) DisplayAttribs::run(amap); } +template +void displayAllAttribs3D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); +} + +template +void displayAllAttribs4D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); +} + template void create2Dmap(Map& map) { @@ -488,55 +490,61 @@ bool testCopy() Map5 map9a(map9); assert(map9a.is_valid()); if ( map9a.is_isomorphic_to(map9) ) { assert(false); return false; } - - std::cout<()<<" " - <()<<" " - <()<<" " - <()<()==0 && map9a.number_of_attributes<2>()>=map9.number_of_attributes<2>() && map9a.number_of_attributes<3>()==0 ); assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); - /*CGAL::cpp11::tuple*/ - typedef boost::tuple >/*, - CGAL::internal::Default_converter_cmap_attr, - CGAL::internal::Default_converter_cmap_attr, - Number_type_converter_cmap_attr >*/ MyConverters; + CGAL::Cast_converter_cmap_attributes c0; + CGAL::Default_converter_cmap_attributes c1; + CGAL::Default_converter_cmap_attributes c2; + CGAL::Cast_converter_cmap_attributes c3; + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters + (c0, c1, c2, c3); - Number_type_converter_cmap_attr c0; - CGAL::internal::Default_converter_cmap_attr c1; - CGAL::internal::Default_converter_cmap_attr c2; - Number_type_converter_cmap_attr c3; - - c0(map5,map9.darts().begin()); - - MyConverters myconverters(c0); //, c1, c2, c3); Map5 map9b(map9, myconverters); assert(map9a.is_valid()); if ( map9b.is_isomorphic_to(map9) ) { assert(false); return false; } - - map9.display_characteristics(std::cout)<()<<" " - <()<<" " - <()<<" " - <()<<" " - <()<<" " - <()<()>=map9.number_of_attributes<0>() && map9b.number_of_attributes<2>()>=map9.number_of_attributes<2>() && map9b.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); assert( map9b.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9b) ); + CGAL::Cast_converter_cmap_attributes cb0; + CGAL::Default_converter_cmap_attributes cb1; + CGAL::Default_converter_cmap_attributes cb2; + CGAL::Cast_converter_cmap_attributes cb3; + + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters2 + (cb0, cb1, cb2, cb3); + + Map9 map5b(map5, myconverters2); assert(map5b.is_valid()); + if ( map5b.is_isomorphic_to(map5) ) { assert(false); return false; } + if ( !map5b.is_isomorphic_to(map5, false) ) { assert(false); return false; } + assert( map5b.number_of_attributes<0>()==map5.number_of_attributes<0>() && + map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && + map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); + assert( map5b.is_isomorphic_to(map5)==map5.is_isomorphic_to(map5b) ); } + /* displayAllAttribs4D(map9, "map9******************\n"); + displayAllAttribs3D(map9b, "map9b******************\n");*/ + + /* std::cout<()<<" " + <()<<" " + <()<<" " + <()<<" " + <()<<" " + <()< Date: Mon, 3 Jun 2013 18:50:35 +0200 Subject: [PATCH 11/21] 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 From 1cc9540daf2ef5764664f13b0204ed6dca88c130 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Mon, 3 Jun 2013 22:08:57 +0200 Subject: [PATCH 12/21] copy cont --- .../include/CGAL/Linear_cell_complex.h | 4 +- .../Linear_cell_complex_copy_functors.h | 108 ++++-------------- .../Linear_cell_complex_copy_test.cpp | 92 +++++++++++++-- 3 files changed, 107 insertions(+), 97 deletions(-) diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index 42decf83618..e1e42c5f29e 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -99,10 +99,10 @@ namespace CGAL { void copy(const LCC2& alcc, const Converters& converters) { typedef typename CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute - ::type Converters2; + ::type Converters2; Converters2 converters2=CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute - ::run(converters); + ::run(converters); Base::template copy(alcc, converters2); } 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 2133d81aedd..baa6aa0a859 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,9 +30,6 @@ */ 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; // **************************************************************************** @@ -117,6 +114,13 @@ struct Set_point_if_exist static void run(const Attr1&, Attr2&) {} }; + +template +struct Set_point_if_exist +{ + static void run(const Attr1&, Attr2&) + {} +}; // **************************************************************************** #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES template , CGAL::cpp11::tuple<> > { typedef CGAL::cpp11::tuple - > type; + , LCC1, LCC2> type; static type run(const CGAL::cpp11::tuple<>&) { return type(); } @@ -189,10 +194,16 @@ template struct Modify_tuple_of_converter_for_vertex_attribute > { typedef CGAL::cpp11::tuple - > type; + , LCC1, LCC2> > type; static type run(const CGAL::cpp11::tuple<>&) - { return type(); } + { + CGAL::Default_converter_cmap_attributes tmp; + return type(Modify_attribute_converter_lcc_vertex_attributes + , LCC1, LCC2> + (tmp)); + } }; template @@ -345,22 +356,6 @@ struct Modify_tuple_of_converter_for_vertex_attribute // **************************************************************************** } // 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 { @@ -371,75 +366,16 @@ struct Modify_attribute_converter_lcc_vertex_attributes (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()); + typename LCC2::Vertex_attribute_handle res = myf(map1, map2, dh1, dh2); + if ( res==NULL ) res = map2.create_vertex_attribute(); internal::Set_point_if_exist:: - run( dh1->vertex_attribute(), dh2->vertex_attribute() ); - return dh2->vertex_attribute(); + typename LCC2::Vertex_attribute>:: + run( *dh1->template attribute<0>(), *res ); + return res; } private: Functor myf; }; -// Case where the two i-attributes are non void. -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 LCC2::template Attribute_handle::type - run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) - { - 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 - CGAL::internal::Set_point_if_exist::type, - typename LCC2::template Attribute_type::type>::run( *ah, *res ); - } - return res; - } -}; - -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 LCC2::template Attribute_handle::type - run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) - { - 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 - CGAL::internal::Set_point_if_exist::type, - typename LCC2::template Attribute_type::type>::run( *ah, *res ); - } - return res; - } -}; - -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 LCC2::template Attribute_handle::type - run(LCC2& map2, typename LCC1::template Attribute_const_handle::type ah) - { - 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 - CGAL::internal::Set_point_if_exist::type, - typename LCC2::template Attribute_type::type>:: - run( *ah, *res ); - } - return res; - } -}; // **************************************************************************** } // namespace CGAL diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index c21f1bf4d27..8e27dee37c3 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -50,7 +50,7 @@ struct Map_3_dart_items_3 typedef CGAL::Dart< 3, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::Cell_attribute< Refs, int > Double_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib_wp; typedef CGAL::cpp11::tuple Double_attrib; typedef CGAL::cpp11::tuple + Int_attrib, Int_attrib, Double_attrib> Attributes; }; }; @@ -157,7 +157,7 @@ typedef CGAL::Linear_cell_complex<3,3, Traits3_b, Another_map_3_dart_items_3> Ma // Point_4+int, void, int, void, int typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_items_4> Map8; -// Point_4+int, int, int, double, double +// Point_4+int, int, int, int, double typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_max_items_4> Map9; /* @@ -256,6 +256,36 @@ struct DisplayAttribs {} }; +template +struct DisplayVertexAttrib +{ + static void run(Map& amap) + { + std::cout<<"0-attributes: "; + for ( typename Map::template Attribute_range<0>::type::iterator + it=amap.template attributes<0>().begin(), + itend=amap.template attributes<0>().end(); + it!=itend; ++it ) + { + std::cout<info()<<"; "; + } + std::cout< +struct DisplayVertexAttrib +{ + static void run(Map& amap) + {} +}; + +template +struct DisplayAttribs +{ + static void run(Map& amap) + { DisplayVertexAttrib::run(amap); } +}; + template void displayAllAttribs2D(Map& amap, const char* c) { @@ -264,6 +294,47 @@ void displayAllAttribs2D(Map& amap, const char* c) DisplayAttribs::run(amap); DisplayAttribs::run(amap); + std::cout<<"Points: "; + for ( typename Map::template Attribute_range<0>::type::iterator + it=amap.template attributes<0>().begin(), + itend=amap.template attributes<0>().end(); + it!=itend; ++it ) + { + std::cout<point()<<"; "; + } + std::cout< +void displayAllAttribs3D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + + std::cout<<"Points: "; + for ( typename Map::template Attribute_range<0>::type::iterator + it=amap.template attributes<0>().begin(), + itend=amap.template attributes<0>().end(); + it!=itend; ++it ) + { + std::cout<point()<<"; "; + } + std::cout< +void displayAllAttribs4D(Map& amap, const char* c) +{ + std::cout<::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + DisplayAttribs::run(amap); + std::cout<<"Points: "; for ( typename Map::template Attribute_range<0>::type::iterator it=amap.template attributes<0>().begin(), @@ -399,12 +470,15 @@ bool testCopy() { // 2D Map2 map1p(map1); assert(map1p.is_valid()); - if ( !map1.is_isomorphic_to(map1p) ) { assert(false); return false; } + if ( map1.is_isomorphic_to(map1p) ) { assert(false); return false; } + if ( !map1.is_isomorphic_to(map1p, false) ) { assert(false); return false; } Map3 map1t(map1); assert(map1t.is_valid()); - if ( !map1.is_isomorphic_to(map1t) ) { assert(false); return false; } + if ( map1.is_isomorphic_to(map1t) ) { assert(false); return false; } + if ( !map1.is_isomorphic_to(map1t, false) ) { assert(false); return false; } - if ( !map1p.is_isomorphic_to(map1t) ) { assert(false); return false; } + if ( map1p.is_isomorphic_to(map1t) ) { assert(false); return false; } + if ( !map1p.is_isomorphic_to(map1t, false) ) { assert(false); return false; } Map1 map2p(map2); assert(map2p.is_valid()); if ( map2.is_isomorphic_to(map2p) ) { assert(false); return false; } @@ -443,7 +517,7 @@ bool testCopy() Map6 map5b(map5); assert(map5b.is_valid()); if ( map5.is_isomorphic_to(map5b) ) { assert(false); return false; } if ( !map5.is_isomorphic_to(map5b, false) ) { assert(false); return false; } - assert( map5b.number_of_attributes<0>()==0 && + assert( map5b.number_of_attributes<0>()==map5.number_of_attributes<0>() && map5b.number_of_attributes<1>()==0 && map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); @@ -451,7 +525,7 @@ bool testCopy() Map7 map5c(map5); assert(map5c.is_valid()); if ( map5.is_isomorphic_to(map5c) ) { assert(false); return false; } if ( !map5.is_isomorphic_to(map5c, false) ) { assert(false); return false; } - assert( map5c.number_of_attributes<0>()==0 && + assert( map5c.number_of_attributes<0>()==map5.number_of_attributes<0>() && map5c.number_of_attributes<2>()==map5.number_of_attributes<2>() ); assert( map5.is_isomorphic_to(map5a)==map5a.is_isomorphic_to(map5) ); @@ -507,7 +581,7 @@ bool testCopy() int main() { - std::cout<<"Combinatorial map copy test (v1)."< Date: Tue, 4 Jun 2013 13:23:43 +0200 Subject: [PATCH 13/21] copy cont --- .../include/CGAL/Cell_attribute.h | 19 ++ .../Combinatorial_map_copy_functors.h | 9 +- .../Combinatorial_map_internal_functors.h | 178 +++++++++++++++++- .../include/CGAL/Cell_attribute_with_point.h | 16 ++ .../Linear_cell_complex_copy_functors.h | 126 +++++-------- .../Linear_cell_complex_copy_test.cpp | 62 +++++- 6 files changed, 304 insertions(+), 106 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index c5cc9875eed..da22eb1e72d 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -119,6 +119,12 @@ namespace CGAL { bool is_valid() const { return true; } + bool operator==(const Cell_attribute_without_info&) const + { return true; } + + bool operator!=(const Cell_attribute_without_info& other) const + { return !operator==(other); } + protected: /// Contructor without parameter. Cell_attribute_without_info(): mrefcounting(0) @@ -221,6 +227,12 @@ namespace CGAL { bool is_valid() const { return mdart!=NULL; } + bool operator==(const Cell_attribute_without_info&) const + { return true; } + + bool operator!=(const Cell_attribute_without_info& other) const + { return !operator==(other); } + protected: /// Contructor without parameter. Cell_attribute_without_info() : mdart(NULL), @@ -326,6 +338,13 @@ namespace CGAL { typedef OnSplit On_split; typedef Info_ Info; + bool operator==(const Self& other) const + { return this->info()==other.info(); } + + bool operator!=(const Self& other) const + { return !operator==(other); } + + protected: /// Default contructor. Cell_attribute() 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 761c2eb53a9..a5458b8b207 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -191,12 +191,11 @@ struct Cast_converter_cmap_attributes (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, typename Map2::Dart_handle dh2) const { + typename Map2::template Attribute_handle::type + res = map2.template create_attribute(); if ( dh1->template attribute()!=NULL ) - return map2.template create_attribute - ((typename Map2::template Attribute_type::type::Info) - dh1->template attribute()->info()); - - return map2.template create_attribute(); + res->info() = dh1->template attribute()->info(); + return res; } }; // **************************************************************************** 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 171c558fb28..3269b231ac5 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -22,6 +22,8 @@ #include #include +#include +#include #include /* Definition of functors used internally to manage attributes (we need @@ -457,7 +459,7 @@ struct Is_same_info // Case of two non void type template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle dh1, typename Map2::Dart_const_handle dh2) @@ -478,33 +480,177 @@ struct Is_same_attribute_functor // Case T1==void template -struct Is_same_attribute_functor + typename T2, int i> +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle, typename Map2::Dart_const_handle dh2) - { return dh2->template attribute()==NULL; } + { + return dh2->template attribute()==NULL || + Is_same_info:: + run(0, *(dh2->template attribute())); + } }; // Case T2==void template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle dh1, typename Map2::Dart_const_handle) - { return dh1->template attribute()==NULL; } + { + return dh1->template attribute()==NULL || + Is_same_info:: + run(*(dh1->template attribute()), 0); + } }; // Case T1==T2==void template -struct Is_same_attribute_functor +struct Is_same_attribute_info_functor { static bool run(typename Map1::Dart_const_handle, typename Map2::Dart_const_handle) { return true; } }; +// **************************************************************************** +// Functor allowing to test if two points are the same or not. +// Here we know both attributes have points. +template< typename Attr1, typename Attr2, + typename Point1=typename Attr1::Point, + typename Point2=typename Attr2::Point, + typename T1=typename Ambient_dimension::type > +struct Is_same_point +{ + static bool run(const Attr1&, const Attr2&) + { return false; } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point > +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_2() + (a1.point(),a2.point()); } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point > +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_3() + (a1.point(),a2.point()); } +}; + +template< typename Attr1, typename Attr2, typename Point> +struct Is_same_point +{ + static bool run(const Attr1& a1, const Attr2& a2) + { return typename Kernel_traits::Kernel::Equal_d() + (a1.point(),a2.point()); } +}; + +// Case of two non void type, with two points +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle dh2) + { + CGAL_static_assertion( Withpoint1==true && Withpoint2==true ); + if (dh1->template attribute()==NULL && + dh2->template attribute()==NULL) + return true; + + if (dh1->template attribute()==NULL || + dh2->template attribute()==NULL) + return false; + + return + Is_same_point::run(*(dh1->template attribute()), + *(dh2->template attribute())); + } +}; + +// Case of two non void type, first without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return false; } +}; + +// Case of two non void type, second without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return false; } +}; + +// Case of two non void type, both without point +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return true; } +}; + +// Case T1==void +/*template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle dh2) + { + return dh2->template attribute()==NULL || + Withpoint2==false; + } +}; + +// Case T2==void +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle dh1, + typename Map2::Dart_const_handle) + { + return dh1->template attribute()==NULL || + Withpoint1==false; + } +}; + +// Case T1==T2==void +template +struct Is_same_attribute_point_functor +{ + static bool run(typename Map1::Dart_const_handle, + typename Map2::Dart_const_handle) + { return true; } +};*/ + +struct twochar{ char dummy[2]; }; + +template +static char has_point(typename T::Point*){} + +template +static twochar has_point(...){} + /// Test if the two darts are associated with the same attribute. template struct Test_is_same_attribute_functor @@ -514,11 +660,23 @@ struct Test_is_same_attribute_functor typename Map2::Dart_const_handle dh2 ) { if (value) - value = Is_same_attribute_functor + { + value = Is_same_attribute_info_functor ::type, - typename Map2::Helper::template Attribute_type::type, + typename Map1::template Attribute_type::type, + typename Map2::template Attribute_type::type, i>::run(dh1, dh2); + } + if (value) + { + value = Is_same_attribute_point_functor + ::type, + typename Map2::template Attribute_type::type, + sizeof(has_point::type>(NULL))==sizeof(char), + sizeof(has_point::type>(NULL))==sizeof(char), + i>::run(dh1, dh2); + } } static bool value; }; diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index 11a8b21af6d..0c91de8f00b 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -88,6 +88,12 @@ namespace CGAL { using Base1::info; + bool operator==(const Self& other) const + { return Base1::operator==(other) && this->point()==other.point(); } + + bool operator!=(const Self& other) const + { return !operator==(other); } + protected: /// Default contructor. Cell_attribute_with_point() @@ -132,6 +138,16 @@ namespace CGAL { typedef Functor_on_merge_ Functor_on_merge; typedef Functor_on_split_ Functor_on_split; + bool operator==(const Cell_attribute_with_point& other) const + { return Base1::operator==(other) && this->point()==other.point(); } + + bool operator!=(const Cell_attribute_with_point& other) const + { return !operator==(other); } + + template + bool operator==(const Cellattr& other) const + { return false; } + protected: /// Default contructor. Cell_attribute_with_point() 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 baa6aa0a859..2ac33a76ceb 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 @@ -91,8 +91,7 @@ struct Set_point_if_possible::run(p1, p2); + Set_point_d_if_same::run(p1, p2); } }; @@ -123,15 +122,13 @@ struct Set_point_if_exist }; // **************************************************************************** #ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -template > +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 +// empty tuple template struct Modify_tuple_of_converter_for_vertex_attribute - , CGAL::cpp11::tuple<> > + > { typedef CGAL::cpp11::tuple -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. +// 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; + typedef typename CGAL::cpp11::tuple + , + Tuple...> type; static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + Tuple... >(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; @@ -200,9 +168,10 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple<>&) { CGAL::Default_converter_cmap_attributes tmp; - return type(Modify_attribute_converter_lcc_vertex_attributes - , LCC1, LCC2> - (tmp)); + return CGAL::cpp11::tuple + , LCC1, LCC2> > + (tmp); } }; @@ -214,10 +183,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple<> >(t.get_head(),t.get_tail()); } }; @@ -229,10 +197,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -245,10 +212,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -261,10 +227,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -278,10 +243,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -295,10 +259,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -312,10 +275,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -329,10 +291,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; @@ -346,10 +307,9 @@ struct Modify_tuple_of_converter_for_vertex_attribute static type run(const CGAL::cpp11::tuple& t) { - return type - (Modify_attribute_converter_lcc_vertex_attributes - (t.get_head()), - t.get_tail()); + return boost::tuples::cons + , + CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); } }; #endif diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index 8e27dee37c3..0c18c542a80 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -17,7 +17,7 @@ struct Map_2_dart_items typedef CGAL::Dart< 2, Refs > Dart; typedef CGAL::Cell_attribute< Refs, int > Int_attrib; - typedef CGAL::Cell_attribute< Refs, int > Double_attrib; + typedef CGAL::Cell_attribute< Refs, double > Double_attrib; typedef CGAL::Cell_attribute_with_point< Refs, double > Double_attrib_wp; typedef CGAL::cpp11::tuple Attributes; @@ -562,19 +562,65 @@ bool testCopy() map2a.number_of_attributes<2>()==0 && map2a.number_of_attributes<3>()==0 ); assert( map2a.is_isomorphic_to(map2)==map2.is_isomorphic_to(map2a) ); - //map2.display_characteristics(std::cout)<()==map2.number_of_attributes<0>() && map5a.number_of_attributes<2>()==0 ); - //map5.display_characteristics(std::cout)<()>=map9.number_of_attributes<0>() && + map9a.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9a.number_of_attributes<3>()==0 ); + assert( map9a.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9a) ); + + CGAL::Cast_converter_cmap_attributes c0; + CGAL::Default_converter_cmap_attributes c1; + CGAL::Default_converter_cmap_attributes c2; + CGAL::Cast_converter_cmap_attributes c3; + + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters + (c0, c1, c2, c3); + + Map5 map9b(map9, myconverters); assert(map9a.is_valid()); + if ( map9b.is_isomorphic_to(map9) ) { assert(false); return false; } + assert( map9b.number_of_attributes<0>()>=map9.number_of_attributes<0>() && + map9b.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9b.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); + assert( map9b.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9b) ); + + CGAL::Cast_converter_cmap_attributes cb0; + CGAL::Default_converter_cmap_attributes cb1; + CGAL::Default_converter_cmap_attributes cb2; + CGAL::Cast_converter_cmap_attributes cb3; + + CGAL::cpp11::tuple, + CGAL::Default_converter_cmap_attributes, + CGAL::Default_converter_cmap_attributes, + CGAL::Cast_converter_cmap_attributes > myconverters2 + (cb0, cb1, cb2, cb3); + + Map9 map5b(map5, myconverters2); assert(map5b.is_valid()); + if ( map5b.is_isomorphic_to(map5) ) { assert(false); return false; } + if ( !map5b.is_isomorphic_to(map5, false) ) { assert(false); return false; } + assert( map5b.number_of_attributes<0>()==map5.number_of_attributes<0>() && + map5b.number_of_attributes<2>()==map5.number_of_attributes<2>() && + map5b.number_of_attributes<3>()==map5.number_of_attributes<3>() ); + assert( map5b.is_isomorphic_to(map5)==map5.is_isomorphic_to(map5b) ); } - // displayAllAttribs2D(mapXX, "mapXX******************\n"); - // displayAllAttribs2D(mapYY, "mapYY******************\n"); + /*map2.display_characteristics(std::cout)< Date: Tue, 4 Jun 2013 18:27:13 +0200 Subject: [PATCH 14/21] Better solution for lcc copy --- .../include/CGAL/Cell_attribute.h | 10 +- .../Combinatorial_map_copy_functors.h | 111 +++++- .../Combinatorial_map_internal_functors.h | 37 -- .../Linear_cell_complex/CMakeLists.txt | 7 +- .../include/CGAL/Cell_attribute_with_point.h | 4 +- .../include/CGAL/Linear_cell_complex.h | 27 +- .../Linear_cell_complex_copy_functors.h | 342 ------------------ 7 files changed, 128 insertions(+), 410 deletions(-) delete mode 100644 Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h diff --git a/Combinatorial_map/include/CGAL/Cell_attribute.h b/Combinatorial_map/include/CGAL/Cell_attribute.h index da22eb1e72d..269b40cc72b 100644 --- a/Combinatorial_map/include/CGAL/Cell_attribute.h +++ b/Combinatorial_map/include/CGAL/Cell_attribute.h @@ -125,7 +125,7 @@ namespace CGAL { bool operator!=(const Cell_attribute_without_info& other) const { return !operator==(other); } - protected: + // protected: /// Contructor without parameter. Cell_attribute_without_info(): mrefcounting(0) {} @@ -135,6 +135,7 @@ namespace CGAL { mrefcounting(0) {} + protected: /// Increment the reference counting. void inc_nb_refs() { mrefcounting+=4; } // 4 because this is the 3rd bit (ie 1<<2) @@ -233,7 +234,7 @@ namespace CGAL { bool operator!=(const Cell_attribute_without_info& other) const { return !operator==(other); } - protected: + // protected: /// Contructor without parameter. Cell_attribute_without_info() : mdart(NULL), mrefcounting(0) @@ -245,6 +246,7 @@ namespace CGAL { mrefcounting(0) {} + protected: /// Increment the reference counting. void inc_nb_refs() { ++mrefcounting; } @@ -305,7 +307,7 @@ namespace CGAL { typedef OnSplit On_split; typedef void Info; - protected: + // protected: /// Default contructor. Cell_attribute() {} @@ -345,7 +347,7 @@ namespace CGAL { { return !operator==(other); } - protected: + // protected: /// Default contructor. Cell_attribute() {} 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 a5458b8b207..392bda12dbb 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -21,6 +21,10 @@ #define CGAL_COMBINATORIAL_MAP_COPY_FUNCTORS_H #include +#include +#include +#include +#include /* Definition of functors used internally to copy combinatorial maps attributes * (we need functors as attributes are stored in tuple, thus all the access @@ -108,8 +112,108 @@ struct Convert_attribute_functor return CGAL::cpp11::get(converters) (*cmap1, *cmap2, dh1, dh2); } }; +// **************************************************************************** +// Functor allowing to set the value of a point if point exist, have +// same dimension. For dim>3, if type of points are the same +// (because no converter). +template::type, + typename T2=typename Ambient_dimension::type> +struct Set_point_if_possible +{ + static void run(const Point1&, Point2&) + {} +}; +template +struct Set_point_if_possible, Dimension_tag<2> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>(p1); + } +}; +template +struct Set_point_if_possible, Dimension_tag<2> > +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; + +template +struct Set_point_if_possible, Dimension_tag<3> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>()(p1); + } +}; + +template +struct Set_point_if_possible, Dimension_tag<3> > +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; + +template +struct Set_point_if_possible +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; +// **************************************************************************** +// Set_point_if_exist if both attribute has a point +template< typename Map1, typename Map2, unsigned int i, + bool Withpoint1, bool Withpoint2 > +struct Set_point_if_exist +{ + static void run( const Map1* cmap1, + Map2* cmap2, + typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2 ) + {} +}; + +template< typename Map1, typename Map2, unsigned int i > +struct Set_point_if_exist +{ + static void run( const Map1* cmap1, + Map2* cmap2, + typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2 ) + { + if ( dh1->template attribute()==NULL ) return; + + typename Map2::template Attribute_handle::type + res = dh2->template attribute(); + if ( res==NULL ) + { + res = cmap2->template create_attribute(); + cmap2->template set_attribute(dh2, res); + } + Set_point_if_possible + ::type::Point, + typename Map2::template Attribute_type::type::Point>:: + run(dh1->template attribute()->point(), + res->point()); + } +}; +// **************************************************************************** /// Copy enabled attributes from one cmap to other template struct Copy_attributes_functor @@ -129,6 +233,11 @@ struct Copy_attributes_functor if ( res!=NULL ) cmap2->template set_attribute(dh2, res); + + Set_point_if_exist::type>(NULL))==sizeof(char), + sizeof(has_point::type>(NULL))==sizeof(char)>:: + run(cmap1, cmap2, dh1, dh2); } } }; @@ -178,7 +287,7 @@ struct Default_converter_cmap_attributes typename Map2::Dart_handle dh2) const { return NULL; } }; - +// **************************************************************************** // Map1 is the existing map, to convert into map2. // Cast converter copy always copy attributes, doing // a cast. This works only if both types are convertible 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 3269b231ac5..e134e711f00 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -605,43 +605,6 @@ struct Is_same_attribute_point_functor { return true; } }; -// Case T1==void -/*template -struct Is_same_attribute_point_functor -{ - static bool run(typename Map1::Dart_const_handle, - typename Map2::Dart_const_handle dh2) - { - return dh2->template attribute()==NULL || - Withpoint2==false; - } -}; - -// Case T2==void -template -struct Is_same_attribute_point_functor -{ - static bool run(typename Map1::Dart_const_handle dh1, - typename Map2::Dart_const_handle) - { - return dh1->template attribute()==NULL || - Withpoint1==false; - } -}; - -// Case T1==T2==void -template -struct Is_same_attribute_point_functor -{ - static bool run(typename Map1::Dart_const_handle, - typename Map2::Dart_const_handle) - { return true; } -};*/ struct twochar{ char dummy[2]; }; diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 1a50baaf72e..4a830ce184f 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -37,7 +37,7 @@ if ( CGAL_FOUND ) # If you want to visualize a linear cell complex, there are 2 viewers # based on qt and vtk. Just uncomment the corresponding line - # include("CMakeLCCViewerQt.inc") + include("CMakeLCCViewerQt.inc") # include("CMakeLCCViewerVtk.inc") add_executable(linear_cell_complex_3_triangulation @@ -54,6 +54,11 @@ if ( CGAL_FOUND ) target_link_libraries(voronoi_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${MAP_VIEWER_LIBRARIES}) + add_executable(linear_cell_complex_3_with_colored_vertices_2 + linear_cell_complex_3_with_colored_vertices_2.cpp ) + target_link_libraries(linear_cell_complex_3_with_colored_vertices_2 + ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${MAP_VIEWER_LIBRARIES}) + else() message(STATUS "This program requires the CGAL library, " diff --git a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h index 0c91de8f00b..5a32980ae72 100644 --- a/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h +++ b/Linear_cell_complex/include/CGAL/Cell_attribute_with_point.h @@ -94,7 +94,7 @@ namespace CGAL { bool operator!=(const Self& other) const { return !operator==(other); } - protected: + // protected: /// Default contructor. Cell_attribute_with_point() {} @@ -148,7 +148,7 @@ namespace CGAL { bool operator==(const Cellattr& other) const { return false; } - protected: + // protected: /// Default contructor. Cell_attribute_with_point() {} diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index e1e42c5f29e..fd5801abc13 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -25,7 +25,6 @@ #include #include #include -#include #include namespace CGAL { @@ -95,34 +94,16 @@ namespace CGAL { * @param alcc the linear cell complex to copy. * @post *this is valid. */ - template - void copy(const LCC2& alcc, const Converters& converters) - { - typedef typename CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute - ::type Converters2; - - Converters2 converters2=CGAL::internal::Modify_tuple_of_converter_for_vertex_attribute - ::run(converters); - Base::template copy(alcc, converters2); - } - - template - void copy(const LCC2& alcc) - { - CGAL::cpp11::tuple<> converters; - return copy >(alcc, converters); - } - - Linear_cell_complex(const Self & alcc) - { copy(alcc); } + Linear_cell_complex(const Self & alcc) + { Base::template copy(alcc); } template < class LCC2 > Linear_cell_complex(const LCC2& alcc) - { copy(alcc);} + { Base::template copy(alcc);} template < class LCC2, typename Converters > Linear_cell_complex(const LCC2& alcc, Converters& converters) - { copy(alcc, converters);} + { Base::template copy(alcc, converters);} /** Create a vertex attribute. * @return an handle on the new attribute. 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 deleted file mode 100644 index 2ac33a76ceb..00000000000 --- a/Linear_cell_complex/include/CGAL/internal/Linear_cell_complex_copy_functors.h +++ /dev/null @@ -1,342 +0,0 @@ -// Copyright (c) 2010-2013 CNRS and LIRIS' Establishments (France). -// All rights reserved. -// -// This file is part of CGAL (www.cgal.org); you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public License as -// published by the Free Software Foundation; either version 3 of the License, -// or (at your option) any later version. -// -// Licensees holding a valid commercial license may use this file in -// accordance with the commercial license agreement provided with the software. -// -// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE -// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. -// -// $URL$ -// $Id$ -// -// Author(s) : Guillaume Damiand -// -#ifndef CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H -#define CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H 1 - -#include -#include -#include - -/* Definition of functors used internally to copy linear cell complex attributes - * (we need functors as attributes are stored in tuple, thus all the access - * must be done at compiling time). - */ -namespace CGAL -{ -template< typename Functor, typename LCC1, typename LCC2> -struct Modify_attribute_converter_lcc_vertex_attributes; -// **************************************************************************** -namespace internal -{ -// **************************************************************************** -// Functor allowing to set the value of a point if point exist, have -// same dimension. For dim>3, if type of points are the same (because no converter). -template -struct Set_point_d_if_same -{ - static void run(const Point1&, Point2&) - {} -}; - -template -struct Set_point_d_if_same -{ - static void run(const Point1& p1, Point1& p2) - { - p2 = p1; // Copy of Point_d having same type - } -}; - -template::type, - typename T2=typename Ambient_dimension::type> -struct Set_point_if_possible -{ - static void run(const Point1&, Point2&) - {} -}; - -template -struct Set_point_if_possible, Dimension_tag<2> > -{ - static void run(const Point1& p1, Point2& p2) - { - p2 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>(p1); - } -}; - -template -struct Set_point_if_possible, Dimension_tag<3> > -{ - static void run(const Point1& p1, Point2& p2) - { - p2 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>()(p1); - } -}; - -template -struct Set_point_if_possible -{ - static void run(const Point1& p1, Point2& p2) - { - Set_point_d_if_same::run(p1, p2); - } -}; - -// Set_point_if_exist if Attr1 has a point -template< typename Attr1, typename Attr2, - typename Point1=typename Attr1::Point, - typename Point2=typename Attr2::Point > -struct Set_point_if_exist -{ - static void run(const Attr1& a1, Attr2& a2) - { - Set_point_if_possible::run(a1.point(), a2.point()); - } -}; - -template -struct Set_point_if_exist -{ - static void run(const Attr1&, Attr2&) - {} -}; - -template -struct Set_point_if_exist -{ - static void run(const Attr1&, Attr2&) - {} -}; -// **************************************************************************** -#ifndef CGAL_CFG_NO_CPP0X_VARIADIC_TEMPLATES -template -struct Modify_tuple_of_converter_for_vertex_attribute; - -// empty tuple -template -struct Modify_tuple_of_converter_for_vertex_attribute - > -{ - typedef CGAL::cpp11::tuple - , LCC1, LCC2> type; - - static type run(const CGAL::cpp11::tuple<>&) - { return type(); } -}; - -// 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 - > -{ - typedef typename CGAL::cpp11::tuple - , - Tuple...> type; - - static type run(const CGAL::cpp11::tuple& t) - { - return boost::tuples::cons - , - Tuple... >(t.get_head(),t.get_tail()); - } -}; -#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 - , LCC1, LCC2> > type; - - static type run(const CGAL::cpp11::tuple<>&) - { - CGAL::Default_converter_cmap_attributes tmp; - return CGAL::cpp11::tuple - , LCC1, LCC2> > - (tmp); - } -}; - -template -struct Modify_tuple_of_converter_for_vertex_attribute - > { - typedef CGAL::cpp11::tuple - > type; - - static type run(const CGAL::cpp11::tuple& t) - { - return boost::tuples::cons - , - CGAL::cpp11::tuple<> >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(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 boost::tuples::cons - , - CGAL::cpp11::tuple >(t.get_head(),t.get_tail()); - } -}; -#endif -// **************************************************************************** -} // namespace internal -// LCC1 is the existing map, to convert into map2. -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 - { - typename LCC2::Vertex_attribute_handle res = myf(map1, map2, dh1, dh2); - if ( res==NULL ) res = map2.create_vertex_attribute(); - internal::Set_point_if_exist:: - run( *dh1->template attribute<0>(), *res ); - return res; - } - private: - Functor myf; -}; -// **************************************************************************** -} // namespace CGAL - -#endif // CGAL_LINEAR_CELL_COMPLEX_COPY_FUNCTORS_H From a4e392b5523b860c95ff86c93c77d2abd317a230 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Wed, 5 Jun 2013 16:16:02 +0200 Subject: [PATCH 15/21] Copy of CMap: ok for code and test suite. --- .../include/CGAL/Combinatorial_map.h | 42 +- .../Combinatorial_map_copy_functors.h | 458 +++++++++++------- .../Combinatorial_map_internal_functors.h | 51 +- .../Linear_cell_complex/CMakeLists.txt | 9 +- .../include/CGAL/Linear_cell_complex.h | 8 +- .../Linear_cell_complex_copy_test.cpp | 94 +++- 6 files changed, 441 insertions(+), 221 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 11f6375762c..338df4714d0 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -158,8 +158,9 @@ namespace CGAL { * @param amap the combinatorial map to copy. * @post *this is valid. */ - template - void copy(const CMap2& amap, const Converters& converters) + template + void copy(const CMap2& amap, const Converters& converters, + const Pointconverter& pointconverter) { this->clear(); @@ -223,10 +224,11 @@ namespace CGAL { ++dartmap_iter) { Helper::template Foreach_enabled_attributes - < internal::Copy_attributes_functor >:: + < internal::Copy_attributes_functor >:: run(&amap, static_cast(this), dartmap_iter->first, dartmap_iter->second, - converters); + converters, pointconverter); } CGAL_assertion (is_valid () == 1); @@ -236,7 +238,19 @@ namespace CGAL { void copy(const CMap2& amap) { CGAL::cpp11::tuple<> converters; - return copy< CMap2, CGAL::cpp11::tuple<> >(amap, converters); + Default_converter_cmap_0attributes_with_point pointconverter; + return copy< CMap2, CGAL::cpp11::tuple<>, + Default_converter_cmap_0attributes_with_point > + (amap, converters, pointconverter); + } + + template + void copy(const CMap2& amap, const Converters& converters) + { + Default_converter_cmap_0attributes_with_point pointconverter; + return copy< CMap2, Converters, + Default_converter_cmap_0attributes_with_point > + (amap, converters, pointconverter); } // Copy constructor from a map having exactly the same type. @@ -253,6 +267,13 @@ namespace CGAL { Combinatorial_map_base(const CMap2& amap, Converters& converters) { copy(amap, converters); } + // "Copy constructor" from a map having different type. + template + Combinatorial_map_base(const CMap2& amap, Converters& converters, + const Pointconverter& pointconverter) + { copy + (amap, converters, pointconverter); } + /** Affectation operation. Copies one map to the other. * @param amap a combinatorial map. * @return A copy of that combinatorial map. @@ -3513,8 +3534,15 @@ namespace CGAL { { Base::template copy(amap); } template < class CMap, typename Converters > - Combinatorial_map(const CMap & amap, Converters& converters) - { Base::template copy(amap, converters); } + Combinatorial_map(const CMap & amap, const Converters& converters) + { Base::template copy + (amap, converters); } + + template < class CMap, typename Converters, typename Pointconverter > + Combinatorial_map(const CMap & amap, const Converters& converters, + const Pointconverter& pointconverter) + { Base::template copy + (amap, converters, pointconverter); } }; } // namespace CGAL 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 392bda12dbb..03dc2d9877d 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -32,65 +32,113 @@ */ namespace CGAL { -template< typename Map1, typename Map2, unsigned int i, - typename Attr1=typename Map1::template Attribute_type::type, - typename Attr2=typename Map2::template Attribute_type::type > +template< typename Map1, typename Map2, unsigned int i> struct Default_converter_cmap_attributes; +template< typename Map1, typename Map2> +struct Default_converter_cmap_0attributes_with_point; // **************************************************************************** namespace internal { // **************************************************************************** // Map1 is the existing map, to convert into map2. -// Case where the two i-attributes are non void. +// Functor called only when both i-attributes have non void info. +// General cases when both info are differents. 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 - run(Map2&, typename Map1::template Attribute_const_handle::type) - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i> -struct Default_converter_two_non_void_attributes_cmap -{ - static typename Map2::template Attribute_handle::type - run(Map2&, typename Map1::template Attribute_const_handle::type) - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i, typename Info1 > -struct Default_converter_two_non_void_attributes_cmap -{ - static typename Map2::template Attribute_handle::type - run(Map2&, typename Map1::template Attribute_const_handle::type) - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i, typename Info2 > -struct Default_converter_two_non_void_attributes_cmap + typename Info1=typename Map1::template + Attribute_type::type::Info, + typename Info2=typename Map2::template + Attribute_type::type::Info > +struct Create_attribute_if_same_info_cmap { static typename Map2::template Attribute_handle::type run(Map2&, typename Map1::template Attribute_const_handle::type) { return NULL; } }; +// Special case when both attributes have the same info. template< typename Map1, typename Map2, unsigned int i, typename Info > -struct Default_converter_two_non_void_attributes_cmap +struct Create_attribute_if_same_info_cmap { static typename Map2::template Attribute_handle::type run(Map2& map2, typename Map1::template Attribute_const_handle::type ah) { + CGAL_assertion( ah!=NULL ); typename Map2::template Attribute_handle::type - res = map2.template create_attribute(); - if ( ah!=NULL ) res->info() = ah->info(); + res = map2.template create_attribute(); + res->info() = ah->info(); return res; } }; +// **************************************************************************** +// Functor allowing to set the value of a point if point exist, have +// same dimension. For dim>3, if type of points are the same +// (because no converter). +template::type, + typename T2=typename Ambient_dimension::type> +struct Set_point_if_possible_cmap +{ + static void run(const Point1&, Point2&) + {} +}; -template +struct Set_point_if_possible_cmap, Dimension_tag<2> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>(p1); + } +}; + +template +struct Set_point_if_possible_cmap, Dimension_tag<2> > +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; + +template +struct Set_point_if_possible_cmap, Dimension_tag<3> > +{ + static void run(const Point1& p1, Point2& p2) + { + p2 = Cartesian_converter::Kernel, + typename Kernel_traits::Kernel>()(p1); + } +}; + +template +struct Set_point_if_possible_cmap, Dimension_tag<3> > +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; + +template +struct Set_point_if_possible_cmap +{ + static void run(const Point1& p1, Point1& p2) + { + p2 = p1; + } +}; +// **************************************************************************** +// Get the ith functor of the converters tuple if i=boost::tuples::length::value)> -struct Convert_attribute_functor +struct Get_convert_attribute_functor { static typename Map2::template Attribute_handle::type run( const Map1* cmap1, Map2* cmap2, typename Map1::Dart_const_handle dh1, @@ -102,8 +150,8 @@ struct Convert_attribute_functor } }; -template -struct Convert_attribute_functor +template +struct Get_convert_attribute_functor { static typename Map2::template Attribute_handle::type run( const Map1* cmap1, Map2* cmap2, typename Map1::Dart_const_handle dh1, @@ -113,109 +161,159 @@ struct Convert_attribute_functor } }; // **************************************************************************** -// Functor allowing to set the value of a point if point exist, have -// same dimension. For dim>3, if type of points are the same -// (because no converter). -template::type, - typename T2=typename Ambient_dimension::type> -struct Set_point_if_possible +// Call a given functor if both i-attribute have an non void info +template< typename Map1, typename Map2, unsigned int i, + typename Converters, + bool Withinfo1=CGAL::internal::Is_attribute_has_non_void_info + ::type>::value, + bool Withinfo2=CGAL::internal::Is_attribute_has_non_void_info + ::type>::value > +struct Call_functor_if_both_attributes_have_info { - static void run(const Point1&, Point2&) - {} + static typename Map2::template Attribute_handle::type + run( const Map1*, + Map2*, + typename Map1::Dart_const_handle, + typename Map2::Dart_handle, + const Converters&) + { return NULL; } }; -template -struct Set_point_if_possible, Dimension_tag<2> > +template< typename Map1, typename Map2, unsigned int i, typename Converters > +struct Call_functor_if_both_attributes_have_info { - static void run(const Point1& p1, Point2& p2) + static typename Map2::template Attribute_handle::type + run( const Map1* cmap1, + Map2* cmap2, + typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2, + const Converters& converters ) { - p2 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>(p1); - } -}; - -template -struct Set_point_if_possible, Dimension_tag<2> > -{ - static void run(const Point1& p1, Point1& p2) - { - p2 = p1; - } -}; - -template -struct Set_point_if_possible, Dimension_tag<3> > -{ - static void run(const Point1& p1, Point2& p2) - { - p2 = Cartesian_converter::Kernel, - typename Kernel_traits::Kernel>()(p1); - } -}; - -template -struct Set_point_if_possible, Dimension_tag<3> > -{ - static void run(const Point1& p1, Point1& p2) - { - p2 = p1; - } -}; - -template -struct Set_point_if_possible -{ - static void run(const Point1& p1, Point1& p2) - { - p2 = p1; + return Get_convert_attribute_functor:: + run(cmap1, cmap2, dh1, dh2, converters); } }; // **************************************************************************** -// Set_point_if_exist if both attribute has a point +// Call a given functor only if both 0-attribute have a point. +// general case i!=0 or one attribute without point. template< typename Map1, typename Map2, unsigned int i, - bool Withpoint1, bool Withpoint2 > -struct Set_point_if_exist + typename Pointconverter, + bool Withpoint1=CGAL::internal::Is_attribute_has_point + ::type>::value, + bool Withpoint2=CGAL::internal::Is_attribute_has_point + ::type>::value > +struct Call_functor_if_both_attributes_have_point { - static void run( const Map1* cmap1, - Map2* cmap2, - typename Map1::Dart_const_handle dh1, - typename Map2::Dart_handle dh2 ) - {} + static typename Map2::template Attribute_handle::type + run( const Map1*, + Map2*, + typename Map1::Dart_const_handle, + typename Map2::Dart_handle, + const Pointconverter&) + { return NULL; } }; - -template< typename Map1, typename Map2, unsigned int i > -struct Set_point_if_exist +// Specialisation with i==0 and both attributes have points. +template< typename Map1, typename Map2, typename Pointconverter > +struct Call_functor_if_both_attributes_have_point +{ + static typename Map2::template Attribute_handle<0>::type + run( const Map1* cmap1, + Map2* cmap2, + typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2, + const Pointconverter& pointconverter ) + { return pointconverter(*cmap1, *cmap2, dh1, dh2); } +}; +// **************************************************************************** +// Copy attribute when if both i-attributes are non void. +// (note Attr2 could not be Void as copy functor is called only for +// non void attributes) +// General case with both attributes non void. +template::type, + typename Attr2=typename Map2::template Attribute_type::type > +struct Copy_attribute_functor_if_nonvoid { static void run( const Map1* cmap1, Map2* cmap2, typename Map1::Dart_const_handle dh1, - typename Map2::Dart_handle dh2 ) + typename Map2::Dart_handle dh2, + const Converters& converters, + const Pointconverter& pointconverter) { + // If dh1 has no i-attribute, nothing to copy. if ( dh1->template attribute()==NULL ) return; + // If dh2 has already an i-attribute, it was already copied. + if ( dh2->template attribute()!=NULL ) return; + + // Otherwise we copy the info if both attribute have non void info. typename Map2::template Attribute_handle::type - res = dh2->template attribute(); - if ( res==NULL ) - { - res = cmap2->template create_attribute(); + res=Call_functor_if_both_attributes_have_info + :: + run(cmap1, cmap2, dh1, dh2, converters); + + if ( res!=NULL ) + cmap2->template set_attribute(dh2, res); + + // And the point if both attributes have points (and only for 0-attributes) + res=Call_functor_if_both_attributes_have_point + :: + run(cmap1, cmap2, dh1, dh2, pointconverter); + + if ( res!=NULL && dh2->template attribute()==NULL ) cmap2->template set_attribute(dh2, res); - } - Set_point_if_possible - ::type::Point, - typename Map2::template Attribute_type::type::Point>:: - run(dh1->template attribute()->point(), - res->point()); } }; +// Specialisation when attr1 is void, and attr2 is non void i==0. Nothing to +// copy, but if 0-attributes has point and i==0, we need to create +// vertex attributes. +template +struct Copy_attribute_functor_if_nonvoid +{ + static void run( const Map1*, + Map2* cmap2, + typename Map1::Dart_const_handle, + typename Map2::Dart_handle dh2, + const Converters&, + const Pointconverter&) + { + // If dh2 has already an 0-attribute, it was already created. + if ( dh2->template attribute<0>()!=NULL ) return; + + // Create the point if 0-attributes has Point. + if ( CGAL::internal::Is_attribute_has_point + ::type>::value ) + cmap2->template + set_attribute<0>(dh2, cmap2->template create_attribute<0>()); + } +}; +// Specialisation when attr1 is void, and attr2 is non void i!=0. +// Nothing to do. +template +struct Copy_attribute_functor_if_nonvoid +{ + static void run( const Map1*, + Map2*, + typename Map1::Dart_const_handle, + typename Map2::Dart_handle, + const Converters&, + const Pointconverter&) + {} +}; // **************************************************************************** -/// Copy enabled attributes from one cmap to other -template +/// Copy enabled attributes from one cmap to other. General case called +/// by copy function in Combinatorial_map on all the non void attributes +/// of Map2. Map1 is the existing map, to convert into map2. +template struct Copy_attributes_functor { template @@ -223,87 +321,89 @@ struct Copy_attributes_functor Map2* cmap2, typename Map1::Dart_const_handle dh1, typename Map2::Dart_handle dh2, - const Converters& converters) - { - if (dh2->template attribute()==NULL) - { - typename Map2::template Attribute_handle::type - res=Convert_attribute_functor:: - run(cmap1, cmap2, dh1, dh2, converters); - - if ( res!=NULL ) - cmap2->template set_attribute(dh2, res); - - Set_point_if_exist::type>(NULL))==sizeof(char), - sizeof(has_point::type>(NULL))==sizeof(char)>:: - run(cmap1, cmap2, dh1, dh2); - } - } + const Converters& converters, + const Pointconverter& pointconverter) + { Copy_attribute_functor_if_nonvoid + :: + run(cmap1, cmap2, dh1, dh2, converters, pointconverter); + } }; // **************************************************************************** } // namespace internal // **************************************************************************** +// "Converters" called during the copy of attributes, to copy Info. +// Users can replace them by their own converters. +// Info converter are called only if both i-attributes have non void info, +// if dh1 has an i-attribute and if dh2 does not already has an i-attribute. // Map1 is the existing map, to convert into map2. -// Default converter copy only attributes if they have -// same info types. -template< typename Map1, typename Map2, unsigned int i, - typename Attr1,typename Attr2 > +// **************************************************************************** +// Default converter copy only attributes if they have same info types. +template< typename Map1, typename Map2, unsigned int i> struct Default_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + (const 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()); } -}; - -template< typename Map1, typename Map2, unsigned int i, - typename Attr1> -struct Default_converter_cmap_attributes -{ - typename Map2::template Attribute_handle::type operator() - (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, - typename Map2::Dart_handle dh2) const - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i, - typename Attr2> -struct Default_converter_cmap_attributes -{ - typename Map2::template Attribute_handle::type operator() - (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, - typename Map2::Dart_handle dh2) const - { return NULL; } -}; - -template< typename Map1, typename Map2, unsigned int i> -struct Default_converter_cmap_attributes -{ - typename Map2::template Attribute_handle::type operator() - (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, - typename Map2::Dart_handle dh2) const - { return NULL; } + { + CGAL_assertion( dh1->template attribute()!=NULL ); + CGAL_assertion( dh2->template attribute()==NULL ); + return internal::Create_attribute_if_same_info_cmap + :: + run(map2, dh1->template attribute()); + } }; // **************************************************************************** -// Map1 is the existing map, to convert into map2. -// Cast converter copy always copy attributes, doing -// a cast. This works only if both types are convertible -// (and this is user responsability to use it only in -// this case). +// Cast converter always copy attributes, doing a cast. This can work only +// if both types are convertible and this is user responsability +// to use it only in this case. template< typename Map1, typename Map2, unsigned int i> struct Cast_converter_cmap_attributes { typename Map2::template Attribute_handle::type operator() - (const Map1& map1, Map2& map2, typename Map1::Dart_const_handle dh1, + (const Map1&, Map2& map2, typename Map1::Dart_const_handle dh1, typename Map2::Dart_handle dh2) const { + CGAL_assertion( dh1->template attribute()!=NULL ); + CGAL_assertion( dh2->template attribute()==NULL ); typename Map2::template Attribute_handle::type res = map2.template create_attribute(); - if ( dh1->template attribute()!=NULL ) - res->info() = dh1->template attribute()->info(); + res->info() = (typename Map2::template Attribute_type::type::Info) + dh1->template attribute()->info(); + return res; + } +}; +// **************************************************************************** +// "Converters" called during the copy of attributes, to copy Point (for +// attributes having such type defined). +// Users can replace them by their own converters. +// Point converter is called after Info converters; thus it is possible that +// attribute<0> was already created for dh2. +// Point converter is only called if both types of 0-attributes have +// Point type defined, and if dh1 has a 0-attribute. +// Map1 is the existing map, to convert into map2. +// **************************************************************************** +// Default converter for points. Point are copied only if they have same +// types, or in 2D/3D we use Cartesian_converter. +template< typename Map1, typename Map2> +struct Default_converter_cmap_0attributes_with_point +{ + typename Map2::template Attribute_handle<0>::type operator() + (const Map1&, Map2& map2, typename Map1::Dart_const_handle dh1, + typename Map2::Dart_handle dh2) const + { + CGAL_assertion( dh1->template attribute<0>()!=NULL ); + + typename Map2::template Attribute_handle<0>::type + res = dh2->template attribute<0>(); + if ( res==NULL ) + { + res = map2.template create_attribute<0>(); + } + internal::Set_point_if_possible_cmap + ::type::Point, + typename Map2::template Attribute_type<0>::type::Point>:: + run(dh1->template attribute<0>()->point(), + res->point()); return res; } }; 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 e134e711f00..9b6bcd27f85 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -63,6 +63,12 @@ * * internal::Test_is_same_attribute_functor to test if two * i-attributes of two darts are isomorphic. + * + * internal::Is_attribute_has_non_void_info to test if the attribute + * Attr is non Void and has an non void Info as inner type + * + * internal::Is_attribute_has_point to test if the attribute + * Attr is non Void and has a Point inner type */ namespace CGAL @@ -604,8 +610,7 @@ struct Is_same_attribute_point_functor typename Map2::Dart_const_handle) { return true; } }; - - +// **************************************************************************** struct twochar{ char dummy[2]; }; template @@ -614,6 +619,41 @@ static char has_point(typename T::Point*){} template static twochar has_point(...){} +template +struct Is_nonvoid_attribute_has_non_void_info +{ + static const bool value=true; +}; +template +struct Is_nonvoid_attribute_has_non_void_info +{ + static const bool value=false; +}; + +template +struct Is_attribute_has_non_void_info +{ + static const bool value=Is_nonvoid_attribute_has_non_void_info::value; +}; +template<> +struct Is_attribute_has_non_void_info +{ + static const bool value=false; +}; + + +template(NULL))==sizeof(char)> +struct Is_attribute_has_point +{ + static const bool value=true; +}; +template +struct Is_attribute_has_point +{ + static const bool value=false; +}; +// **************************************************************************** /// Test if the two darts are associated with the same attribute. template struct Test_is_same_attribute_functor @@ -636,9 +676,10 @@ struct Test_is_same_attribute_functor ::type, typename Map2::template Attribute_type::type, - sizeof(has_point::type>(NULL))==sizeof(char), - sizeof(has_point::type>(NULL))==sizeof(char), - i>::run(dh1, dh2); + Is_attribute_has_point::type>::value, + Is_attribute_has_point::type>::value, i>::run(dh1, dh2); } } static bool value; diff --git a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt index 4a830ce184f..ad133599d65 100644 --- a/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt +++ b/Linear_cell_complex/examples/Linear_cell_complex/CMakeLists.txt @@ -37,8 +37,8 @@ if ( CGAL_FOUND ) # If you want to visualize a linear cell complex, there are 2 viewers # based on qt and vtk. Just uncomment the corresponding line - include("CMakeLCCViewerQt.inc") - # include("CMakeLCCViewerVtk.inc") + # include("CMakeLCCViewerQt.inc") + # include("CMakeLCCViewerVtk.inc") add_executable(linear_cell_complex_3_triangulation linear_cell_complex_3_triangulation.cpp) @@ -54,11 +54,6 @@ if ( CGAL_FOUND ) target_link_libraries(voronoi_3 ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${MAP_VIEWER_LIBRARIES}) - add_executable(linear_cell_complex_3_with_colored_vertices_2 - linear_cell_complex_3_with_colored_vertices_2.cpp ) - target_link_libraries(linear_cell_complex_3_with_colored_vertices_2 - ${CGAL_LIBRARIES} ${CGAL_3RD_PARTY_LIBRARIES} ${MAP_VIEWER_LIBRARIES}) - else() message(STATUS "This program requires the CGAL library, " diff --git a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h index fd5801abc13..5790eff4b0a 100644 --- a/Linear_cell_complex/include/CGAL/Linear_cell_complex.h +++ b/Linear_cell_complex/include/CGAL/Linear_cell_complex.h @@ -94,7 +94,7 @@ namespace CGAL { * @param alcc the linear cell complex to copy. * @post *this is valid. */ - Linear_cell_complex(const Self & alcc) + Linear_cell_complex(const Self & alcc) { Base::template copy(alcc); } template < class LCC2 > @@ -105,6 +105,12 @@ namespace CGAL { Linear_cell_complex(const LCC2& alcc, Converters& converters) { Base::template copy(alcc, converters);} + template < class LCC2, typename Converters, typename Pointconverter > + Linear_cell_complex(const LCC2& alcc, Converters& converters, + const Pointconverter& pointconverter) + { Base::template copy + (alcc, converters, pointconverter);} + /** Create a vertex attribute. * @return an handle on the new attribute. */ diff --git a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp index 0c18c542a80..4f2bd5f405e 100644 --- a/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp +++ b/Linear_cell_complex/test/Linear_cell_complex/Linear_cell_complex_copy_test.cpp @@ -160,6 +160,28 @@ typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_items_4> Map8; // Point_4+int, int, int, int, double typedef CGAL::Linear_cell_complex<4,4, Traits4_a, Map_dart_max_items_4> Map9; +struct Converter_map9_points_into_map5_points +{ + Map5::Attribute_handle<0>::type operator() + (const Map9&, Map5& map2, Map9::Dart_const_handle dh1, + Map5::Dart_handle dh2) const + { + CGAL_assertion( dh1->attribute<0>()!=NULL ); + + Map5::Attribute_handle<0>::type + res = dh2->attribute<0>(); + if ( res==NULL ) + { + res = map2.create_attribute<0>(); + } + + const Map9::Point & p = dh1->attribute<0>()->point(); + res->point() = Map5::Point(p[0],p[1],p[2]); + return res; + } +}; + + /* template typename Map::Dart_handle getRandomDart(Map& map) @@ -172,6 +194,21 @@ typename Map::Dart_handle getRandomDart(Map& map) } */ +template +struct SetInfoIfNonVoid +{ + static void run(Attr&attr, int nb) + { + attr.info()=nb; + } +}; +template +struct SetInfoIfNonVoid +{ + static void run(Attr&, int) + {} +}; + template::type> struct CreateAttributes @@ -183,38 +220,26 @@ struct CreateAttributes itend=map.darts().end(); it!=itend; ++it) { if ( it->template attribute()==NULL ) + { map.template set_attribute - (it, map.template create_attribute(++nb)); + (it, map.template create_attribute()); + SetInfoIfNonVoid::run(*(it->template attribute()), ++nb); + } } } }; -template -struct SetInfoIfNonVoid -{ - static void run(Attr&attr, int&nb) - { - if ( attr.info()==0 ) attr.info()=(++nb); - } -}; -template -struct SetInfoIfNonVoid -{ - static void run(Attr&attr, int&nb) - {} -}; - template struct CreateAttributes { - static void run(Map& map) + static void run(Map& amap) { int nb=0; - for(typename Map::Dart_range::iterator it=map.darts().begin(), - itend=map.darts().end(); it!=itend; ++it) - { - SetInfoIfNonVoid::run(*it->template attribute<0>(), nb); - } + for ( typename Map::template Attribute_range<0>::type::iterator + it=amap.template attributes<0>().begin(), + itend=amap.template attributes<0>().end(); + it!=itend; ++it ) + SetInfoIfNonVoid::run(*it, ++nb); } }; @@ -232,6 +257,22 @@ struct CreateAttributes {} }; +template::type> +struct DisplayNumberOfAttribs +{ + static void run(Map& amap) + { + std::cout<()<<" "; + } +}; +template +struct DisplayNumberOfAttribs +{ + static void run(Map&) + {} +}; + template::type> struct DisplayAttribs @@ -593,6 +634,15 @@ bool testCopy() map9b.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); assert( map9b.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9b) ); + Converter_map9_points_into_map5_points mypointconverter; + + Map5 map9c(map9, myconverters, mypointconverter); assert(map9a.is_valid()); + if ( map9c.is_isomorphic_to(map9) ) { assert(false); return false; } + assert( map9c.number_of_attributes<0>()>=map9.number_of_attributes<0>() && + map9c.number_of_attributes<2>()>=map9.number_of_attributes<2>() && + map9c.number_of_attributes<3>()>=map9.number_of_attributes<3>() ); + assert( map9c.is_isomorphic_to(map9)==map9.is_isomorphic_to(map9c) ); + CGAL::Cast_converter_cmap_attributes cb0; CGAL::Default_converter_cmap_attributes cb1; CGAL::Default_converter_cmap_attributes cb2; From 23e8a540f7f23d1a166d10dd383c62e1c961efbf Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 6 Jun 2013 08:18:13 +0200 Subject: [PATCH 16/21] Small corrections after first results of testsuite --- Combinatorial_map/include/CGAL/Combinatorial_map.h | 2 +- .../include/CGAL/internal/Combinatorial_map_copy_functors.h | 2 +- .../CGAL/internal/Combinatorial_map_internal_functors.h | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/Combinatorial_map/include/CGAL/Combinatorial_map.h b/Combinatorial_map/include/CGAL/Combinatorial_map.h index 338df4714d0..41ff65f3845 100644 --- a/Combinatorial_map/include/CGAL/Combinatorial_map.h +++ b/Combinatorial_map/include/CGAL/Combinatorial_map.h @@ -3289,7 +3289,7 @@ namespace CGAL { Dart_const_handle current; typename Map2::Dart_const_handle other; - int i = 0; + unsigned int i = 0; CGAL::Unique_hash_map bijection; 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 03dc2d9877d..c93953f0e0c 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -137,7 +137,7 @@ struct Set_point_if_possible_cmap=boost::tuples::length::value)> + bool t=(i>=My_length::value)> struct Get_convert_attribute_functor { static typename Map2::template Attribute_handle::type 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 9b6bcd27f85..9457fb1e608 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -614,10 +614,10 @@ struct Is_same_attribute_point_functor struct twochar{ char dummy[2]; }; template -static char has_point(typename T::Point*){} +static char has_point(typename T::Point*); template -static twochar has_point(...){} +static twochar has_point(...); template struct Is_nonvoid_attribute_has_non_void_info From ff8b4686d9457b11e0134b1bb50362cbca9783b1 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Fri, 7 Jun 2013 08:46:25 +0200 Subject: [PATCH 17/21] Remove a warning --- .../include/CGAL/internal/Combinatorial_map_copy_functors.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) 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 c93953f0e0c..4cedb20d9aa 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -137,7 +137,7 @@ struct Set_point_if_possible_cmap=My_length::value)> + bool t=((int)i>=My_length::value)> struct Get_convert_attribute_functor { static typename Map2::template Attribute_handle::type From 67756fd5d34dd5e1bfa6aad64703f8ec5360470d Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Jun 2013 10:21:09 +0200 Subject: [PATCH 18/21] Add missing template keywords --- .../CGAL/internal/Combinatorial_map_copy_functors.h | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) 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 4cedb20d9aa..97555704599 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_copy_functors.h @@ -164,9 +164,11 @@ struct Get_convert_attribute_functor // Call a given functor if both i-attribute have an non void info template< typename Map1, typename Map2, unsigned int i, typename Converters, - bool Withinfo1=CGAL::internal::Is_attribute_has_non_void_info + bool Withinfo1=CGAL::internal::template + Is_attribute_has_non_void_info ::type>::value, - bool Withinfo2=CGAL::internal::Is_attribute_has_non_void_info + bool Withinfo2=CGAL::internal::template + Is_attribute_has_non_void_info ::type>::value > struct Call_functor_if_both_attributes_have_info { @@ -199,9 +201,9 @@ struct Call_functor_if_both_attributes_have_info::type>::value, - bool Withpoint2=CGAL::internal::Is_attribute_has_point + bool Withpoint2=CGAL::internal::template Is_attribute_has_point ::type>::value > struct Call_functor_if_both_attributes_have_point { @@ -287,7 +289,7 @@ struct Copy_attribute_functor_if_nonvoidtemplate attribute<0>()!=NULL ) return; // Create the point if 0-attributes has Point. - if ( CGAL::internal::Is_attribute_has_point + if ( CGAL::internal::template Is_attribute_has_point ::type>::value ) cmap2->template set_attribute<0>(dh2, cmap2->template create_attribute<0>()); From 50fd54b5f1a3dba38946c20a0642909494b3b0c4 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Jun 2013 14:53:04 +0200 Subject: [PATCH 19/21] Patch for compiler gcc4.3 (Sebastien is the best, even it is not fair because I don't have access to the compiler. But I will pay my beer ;) --- .../Combinatorial_map_internal_functors.h | 24 ++++--------------- 1 file changed, 5 insertions(+), 19 deletions(-) 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 9457fb1e608..6f4e5b923f9 100644 --- a/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h +++ b/Combinatorial_map/include/CGAL/internal/Combinatorial_map_internal_functors.h @@ -25,6 +25,7 @@ #include #include #include +#include /* Definition of functors used internally to manage attributes (we need * functors as attributes are stored in tuple, thus all the access must be @@ -611,13 +612,7 @@ struct Is_same_attribute_point_functor { return true; } }; // **************************************************************************** -struct twochar{ char dummy[2]; }; - -template -static char has_point(typename T::Point*); - -template -static twochar has_point(...); +BOOST_MPL_HAS_XXX_TRAIT_NAMED_DEF(Has_point,Point,false) template struct Is_nonvoid_attribute_has_non_void_info @@ -640,19 +635,10 @@ struct Is_attribute_has_non_void_info { static const bool value=false; }; - - -template(NULL))==sizeof(char)> -struct Is_attribute_has_point -{ - static const bool value=true; -}; +// **************************************************************************** template -struct Is_attribute_has_point -{ - static const bool value=false; -}; +struct Is_attribute_has_point +{ static const bool value=Has_point::value; }; // **************************************************************************** /// Test if the two darts are associated with the same attribute. template From d1395ba60912d393c519be6cc4683423f0249f78 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Jun 2013 17:58:31 +0200 Subject: [PATCH 20/21] Add doc for new constructor, operator= and swap method. --- .../Concepts/CombinatorialMap.h | 19 +++++++++++++++++++ 1 file changed, 19 insertions(+) diff --git a/Combinatorial_map/doc/Combinatorial_map/Concepts/CombinatorialMap.h b/Combinatorial_map/doc/Combinatorial_map/Concepts/CombinatorialMap.h index 6556b19bd8c..eb595c64e49 100644 --- a/Combinatorial_map/doc/Combinatorial_map/Concepts/CombinatorialMap.h +++ b/Combinatorial_map/doc/Combinatorial_map/Concepts/CombinatorialMap.h @@ -19,6 +19,13 @@ public: */ CombinatorialMap(); +/*! +Construct a new combinatorial map from another one. +The new combinatorial map is created by copying the darts and the non void attributes of cmap. CMap must be a model of `CombinatorialMap` concept, which can be defined with a different dimension and/or different attributes than `*this`. In this case, only permutations that are common to `cmap` and `*this`, and only non void i-attributes of `cmap` whose info type is the same to the info of non void i-attributes of `*this`, are copied. +*/ +template +CombinatorialMap cm(const CMap& cmap); + /// @} /// \name Types @@ -521,6 +528,18 @@ Deletes all the darts and all the attributes of the combinatorial map. */ void clear(); +/*! +Assignment operator. +All darts and attributes are duplicated, and the former combinatorial map is deleted. +*/ +CombinatorialMap& operator= (const CombinatorialMap& cmap); + +/*! +Swap the current combinatorial map with `cmap`. +There is no copy of darts and attributes thus this method runs in constant time. +*/ +void swap(CombinatorialMap& cmap); + /// @} /// \name Operations From 2198f959a7c00a3d3185cc7b44de5492212ac342 Mon Sep 17 00:00:00 2001 From: Guillaume Damiand Date: Thu, 13 Jun 2013 17:59:05 +0200 Subject: [PATCH 21/21] Add modif in changes.html --- Installation/changes.html | 2 ++ 1 file changed, 2 insertions(+) diff --git a/Installation/changes.html b/Installation/changes.html index e0554bdb8dd..9173a541b44 100755 --- a/Installation/changes.html +++ b/Installation/changes.html @@ -133,6 +133,8 @@ David A. Wheeler's 'SLOCCount', restricted to the include/CGAL/

Combinatorial Maps

  • Two bug fixes: do not use the 2 least significant bits for cell attribute without dart support; add share a mark in CMap_cell_iterator.
  • +
  • Add a constructor taking a given combinatorial map as argument, possibly with different dimension and/or different attributes. This allows to transform a combinatorial map.
  • +
  • Add operator= and swap method.

2D Apollonius graphs