From ded66799a6fd2a8407c9f051a545d153224982f1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=C3=A9bastien=20Loriot?= Date: Mon, 5 Aug 2013 15:03:46 +0200 Subject: [PATCH] make the insertion of a range of points with info working with hierarchy --- .../info_insert_with_pair_iterator.cpp | 3 +- .../include/CGAL/Triangulation_hierarchy_3.h | 112 +++++++++++++++++- 2 files changed, 113 insertions(+), 2 deletions(-) diff --git a/Triangulation_3/examples/Triangulation_3/info_insert_with_pair_iterator.cpp b/Triangulation_3/examples/Triangulation_3/info_insert_with_pair_iterator.cpp index c4315da1ef0..e72cfefa1d4 100644 --- a/Triangulation_3/examples/Triangulation_3/info_insert_with_pair_iterator.cpp +++ b/Triangulation_3/examples/Triangulation_3/info_insert_with_pair_iterator.cpp @@ -6,7 +6,8 @@ typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Triangulation_vertex_base_with_info_3 Vb; typedef CGAL::Triangulation_data_structure_3 Tds; -typedef CGAL::Delaunay_triangulation_3 Delaunay; +//Use the Fast_location tag. Default or Compact_location works too. +typedef CGAL::Delaunay_triangulation_3 Delaunay; typedef Delaunay::Point Point; int main() diff --git a/Triangulation_3/include/CGAL/Triangulation_hierarchy_3.h b/Triangulation_3/include/CGAL/Triangulation_hierarchy_3.h index 66a822260b5..81ba0df3afe 100644 --- a/Triangulation_3/include/CGAL/Triangulation_hierarchy_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_hierarchy_3.h @@ -30,6 +30,15 @@ #include #include +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO +#include +#include + +#include +#include +#include +#endif //CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO + namespace CGAL { // This class is deprecated, but must be kept for backward compatibility. @@ -125,8 +134,22 @@ public: Vertex_handle insert(const Point &p, Locate_type lt, Cell_handle loc, int li, int lj); +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO template < class InputIterator > - std::ptrdiff_t insert(InputIterator first, InputIterator last) + std::ptrdiff_t + insert( InputIterator first, InputIterator last, + typename boost::enable_if< + boost::is_convertible< + typename std::iterator_traits::value_type, + Point + > + >::type* = NULL + ) +#else + template < class InputIterator > + std::ptrdiff_t + insert( InputIterator first, InputIterator last) +#endif //CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO { size_type n = number_of_vertices(); @@ -154,6 +177,93 @@ public: return number_of_vertices() - n; } +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO +private: + //top stands for tuple-or-pair + template + const Point& top_get_first(const std::pair& pair) const { return pair.first; } + template + const Info& top_get_second(const std::pair& pair) const { return pair.second; } + template + const Point& top_get_first(const boost::tuple& tuple) const { return boost::get<0>(tuple); } + template + const Info& top_get_second(const boost::tuple& tuple) const { return boost::get<1>(tuple); } + + template + std::ptrdiff_t insert_with_info(InputIterator first,InputIterator last) + { + size_type n = number_of_vertices(); + std::vector indices; + std::vector points; + std::vector infos; + std::ptrdiff_t index=0; + for (InputIterator it=first;it!=last;++it){ + Tuple_or_pair value=*it; + points.push_back( top_get_first(value) ); + infos.push_back ( top_get_second(value) ); + indices.push_back(index++); + } + + typedef Spatial_sort_traits_adapter_3 Search_traits; + + spatial_sort(indices.begin(),indices.end(),Search_traits(&(points[0]),geom_traits())); + + + // hints[i] is the vertex of the previously inserted point in level i. + // Thanks to spatial sort, they are better hints than what the hierarchy + // would give us. + Vertex_handle hints[maxlevel]; + for (typename std::vector::const_iterator + it = indices.begin(), end = indices.end(); + it != end; ++it) + { + int vertex_level = random_level(); + + Vertex_handle v = hints[0] = hierarchy[0]->insert (points[*it], hints[0]); + v->info()=infos[*it]; + Vertex_handle prev = v; + + for (int level = 1; level <= vertex_level; ++level) { + v = hints[level] = hierarchy[level]->insert (points[*it], hints[level]); + set_up_down(v, prev); + prev = v; + } + } + return number_of_vertices() - n; + } + +public: + + template < class InputIterator > + std::ptrdiff_t + insert( InputIterator first, + InputIterator last, + typename boost::enable_if< + boost::is_convertible< + typename std::iterator_traits::value_type, + std::pair::type> + > >::type* =NULL + ) + { + return insert_with_info< std::pair::type> >(first,last); + } + + template + std::ptrdiff_t + insert( boost::zip_iterator< boost::tuple > first, + boost::zip_iterator< boost::tuple > last, + typename boost::enable_if< + boost::mpl::and_< + boost::is_convertible< typename std::iterator_traits::value_type, Point >, + boost::is_convertible< typename std::iterator_traits::value_type, typename internal::Info_check::type > + > + >::type* =NULL + ) + { + return insert_with_info< boost::tuple::type> >(first,last); + } +#endif //CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO + void remove(Vertex_handle v); template < typename InputIterator >