From 2d1c78fdd9074191e6c6fef4f6914161db91c42e Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Mon, 20 May 2019 18:23:08 +0200 Subject: [PATCH] Unify T3 --- .../Triangulation_2/CGAL/Triangulation_2.h | 2 +- ...test_triangulation_with_zip_iterator_2.cpp | 49 ++++++++ .../CGAL/Delaunay_triangulation_3.h | 1 - .../Triangulation_3/CGAL/Triangulation_3.h | 23 +++- .../include/CGAL/Delaunay_triangulation_3.h | 5 +- .../include/CGAL/Regular_triangulation_3.h | 3 +- .../include/CGAL/Triangulation_3.h | 111 ++++++++++++++---- ..._Triangulation_with_transform_iterator.cpp | 52 ++++++++ .../test_Triangulation_with_zip_iterator.cpp | 50 ++++++++ 9 files changed, 266 insertions(+), 30 deletions(-) create mode 100644 Triangulation_2/test/Triangulation_2/test_triangulation_with_zip_iterator_2.cpp create mode 100644 Triangulation_3/test/Triangulation_3/test_Triangulation_with_transform_iterator.cpp create mode 100644 Triangulation_3/test/Triangulation_3/test_Triangulation_with_zip_iterator.cpp diff --git a/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h b/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h index 12f708ca4ed..cea51b10905 100644 --- a/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h +++ b/Triangulation_2/doc/Triangulation_2/CGAL/Triangulation_2.h @@ -701,7 +701,7 @@ insert(InputIterator first, InputIterator last); /*! -inserts the points in the iterator range `[first,last)`. Returns the number of inserted points. +inserts the points in the iterator range `[first,last)` in the given order. Returns the number of inserted points. Given a pair `(p,i)`, the vertex `v` storing `p` also stores `i`, that is `v.point() == p` and `v.info() == i`. If several pairs have the same point, diff --git a/Triangulation_2/test/Triangulation_2/test_triangulation_with_zip_iterator_2.cpp b/Triangulation_2/test/Triangulation_2/test_triangulation_with_zip_iterator_2.cpp new file mode 100644 index 00000000000..f96a9b388c8 --- /dev/null +++ b/Triangulation_2/test/Triangulation_2/test_triangulation_with_zip_iterator_2.cpp @@ -0,0 +1,49 @@ +#include +#include +#include +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Triangulation_vertex_base_with_info_2 Vb; +typedef CGAL::Triangulation_data_structure_2 Tds; +typedef CGAL::Triangulation_2 Triangulation; +typedef Triangulation::Point Point; + +int main() +{ + + std::vector indices; + indices.push_back(0); + indices.push_back(1); + indices.push_back(2); + indices.push_back(3); + indices.push_back(4); + indices.push_back(5); + + std::vector points; + points.push_back(Point(0,0)); + points.push_back(Point(1,0)); + points.push_back(Point(0,1)); + points.push_back(Point(1,47)); + points.push_back(Point(2,2)); + points.push_back(Point(-1,0)); + + + + Triangulation T( boost::make_zip_iterator(boost::make_tuple( points.begin(),indices.begin() )), + boost::make_zip_iterator(boost::make_tuple( points.end(),indices.end() ) ) ); + + CGAL_assertion( T.number_of_vertices() == 6 ); + + + // check that the info was correctly set. + Triangulation::Finite_vertices_iterator vit; + for (vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit) + if( points[ vit->info() ] != vit->point() ){ + std::cerr << "Error different info" << std::endl; + exit(EXIT_FAILURE); + } + + return 0; +} diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/Delaunay_triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/Delaunay_triangulation_3.h index 670c2054ae1..ac4b39c6085 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/Delaunay_triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/Delaunay_triangulation_3.h @@ -209,7 +209,6 @@ std::ptrdiff_t insert(PointInputIterator first, PointInputIterator last); /*! - Inserts the points in the iterator range `[first,last)`. Returns the number of inserted points. Note that this function is not guaranteed to insert the points diff --git a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h index 3bd0dfbe653..3fa3a362201 100644 --- a/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h +++ b/Triangulation_3/doc/Triangulation_3/CGAL/Triangulation_3.h @@ -908,13 +908,30 @@ Cell_handle loc, int li, int lj); Inserts the points in the range `[first,last)`. Returns the number of inserted points. Note that this function is not guaranteed to insert the points following the order of `InputIterator`. -\tparam InputIterator must be an input iterator with value type `Point`. +\tparam PointInputIterator must be an input iterator with value type `Point`. */ -template < class InputIterator > +template < class PointInputIterator > std::ptrdiff_t -insert(InputIterator first, InputIterator last); +insert(PointInputIterator first, PointInputIterator last); +/*! +Inserts the points in the iterator range `[first,last)`. +Returns the number of inserted points. +Inserts the points following the order of `PointWithInfoInputIterator`. + +Given a pair `(p,i)`, the vertex `v` storing `p` also stores `i`, that is +`v.point() == p` and `v.info() == i`. If several pairs have the same point, +only one vertex is created, and one of the objects of type `Vertex::Info` will be stored in the vertex. +\pre `Vertex` must be model of the concept `TriangulationVertexBaseWithInfo_3`. + +\tparam PointWithInfoInputIterator must be an input iterator with the value type `std::pair`. + +*/ +template < class PointWithInfoInputIterator > +std::ptrdiff_t +insert(PointWithInfoInputIterator first, PointWithInfoInputIterator last); + /// @} /*! \name diff --git a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h index f88764b8197..387ae3377b9 100644 --- a/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Delaunay_triangulation_3.h @@ -46,10 +46,8 @@ #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 @@ -414,6 +412,7 @@ public: #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; } @@ -426,7 +425,7 @@ private: 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) { diff --git a/Triangulation_3/include/CGAL/Regular_triangulation_3.h b/Triangulation_3/include/CGAL/Regular_triangulation_3.h index bb88f2fe3dc..41bf968b395 100644 --- a/Triangulation_3/include/CGAL/Regular_triangulation_3.h +++ b/Triangulation_3/include/CGAL/Regular_triangulation_3.h @@ -421,6 +421,7 @@ public: #ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO private: + /* //top stands for tuple-or-pair template const Weighted_point& top_get_first(const std::pair& pair) const { return pair.first; } @@ -433,7 +434,7 @@ private: template const Info& top_get_second(const boost::tuple& tuple) const { return boost::get<1>(tuple); } - + */ // Functor to go from an index of a container of Weighted_point to // the corresponding Bare_point template diff --git a/Triangulation_3/include/CGAL/Triangulation_3.h b/Triangulation_3/include/CGAL/Triangulation_3.h index 71c1b37b443..891becdcabf 100644 --- a/Triangulation_3/include/CGAL/Triangulation_3.h +++ b/Triangulation_3/include/CGAL/Triangulation_3.h @@ -68,6 +68,11 @@ #include #include +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO +#include +#include +#endif + #ifndef CGAL_NO_STRUCTURAL_FILTERING #include #include @@ -1115,37 +1120,101 @@ public: Hidden_points_visitor& hider, bool *could_lock_zone = NULL); + +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO + template < class InputIterator > + 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(); - std::vector points (first, last); - - // The function insert(first, last) is overwritten in Regular_triangulation_3.h, - // so we know that, here, `Point` is not a type of Weighted point. - // Nevertheless, to make it more generic (that is, allowing the user to pass - // a `Point` type that is not GT::Point_3), we still use the spatial sort - // adapter traits and Construct_point_3 here. - typedef typename Geom_traits::Construct_point_3 Construct_point_3; - typedef typename boost::result_of::type Ret; - typedef CGAL::internal::boost_::function_property_map fpmap; - typedef CGAL::Spatial_sort_traits_adapter_3 Search_traits_3; - - spatial_sort(points.begin(), points.end(), - Search_traits_3( - CGAL::internal::boost_::make_function_property_map( - geom_traits().construct_point_3_object()), geom_traits())); - Vertex_handle hint; - for(typename std::vector::const_iterator p = points.begin(), - end = points.end(); - p != end; ++p) - hint = insert(*p, hint); + for(; first != last; ++first) + hint = insert(*first, hint); return number_of_vertices() - n; } +#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO +protected: + //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; + 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)); + } + + Vertex_handle hint; + for(std::size_t i=0; i < points.size(); ++i) + { + hint = insert(points[i], hint); + if(hint != Vertex_handle()) + hint->info() = infos[i]; + } + + 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 + + + Vertex_handle insert_in_cell(const Point& p, Cell_handle c); Vertex_handle insert_in_facet(const Point& p, Cell_handle c, int i); Vertex_handle insert_in_facet(const Point& p, const Facet& f) { diff --git a/Triangulation_3/test/Triangulation_3/test_Triangulation_with_transform_iterator.cpp b/Triangulation_3/test/Triangulation_3/test_Triangulation_with_transform_iterator.cpp new file mode 100644 index 00000000000..62ea5f34fd4 --- /dev/null +++ b/Triangulation_3/test/Triangulation_3/test_Triangulation_with_transform_iterator.cpp @@ -0,0 +1,52 @@ +#include + +#include +#include +#include + +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Triangulation_vertex_base_with_info_3 Vb; +typedef CGAL::Triangulation_cell_base_3 Cb; +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Triangulation_3 Triangulation; +typedef Triangulation::Point Point; + +//a functor that returns a std::pair. +//the unsigned integer is incremented at each call to +//operator() +struct Auto_count : public CGAL::cpp98::unary_function >{ + mutable unsigned i; + Auto_count() : i(0){} + std::pair operator()(const Point& p) const { + return std::make_pair(p,i++); + } +}; + +int main() +{ + std::vector points; + points.push_back(Point(0,0,0)); + points.push_back(Point(1,0,0)); + points.push_back(Point(0,1,0)); + points.push_back(Point(0,0,1)); + points.push_back(Point(2,2,2)); + points.push_back(Point(-1,0,1)); + + Triangulation T( boost::make_transform_iterator(points.begin(),Auto_count()), + boost::make_transform_iterator(points.end(), Auto_count() ) ); + + CGAL_assertion( T.number_of_vertices() == 6 ); + + // check that the info was correctly set. + Triangulation::Finite_vertices_iterator vit; + for (vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit) + if( points[ vit->info() ] != vit->point() ){ + std::cerr << "Error different info" << std::endl; + exit(EXIT_FAILURE); + } + std::cout << "OK" << std::endl; + + return 0; +} diff --git a/Triangulation_3/test/Triangulation_3/test_Triangulation_with_zip_iterator.cpp b/Triangulation_3/test/Triangulation_3/test_Triangulation_with_zip_iterator.cpp new file mode 100644 index 00000000000..06479948507 --- /dev/null +++ b/Triangulation_3/test/Triangulation_3/test_Triangulation_with_zip_iterator.cpp @@ -0,0 +1,50 @@ +#include + +#include +#include + +#include + +#include +#include + +typedef CGAL::Exact_predicates_inexact_constructions_kernel K; +typedef CGAL::Triangulation_vertex_base_with_info_3 Vb; +typedef CGAL::Triangulation_cell_base_3 Cb; +typedef CGAL::Triangulation_data_structure_3 Tds; +typedef CGAL::Triangulation_3 Triangulation; +typedef Triangulation::Point Point; + +int main() +{ + std::vector indices; + indices.push_back(0); + indices.push_back(1); + indices.push_back(2); + indices.push_back(3); + indices.push_back(4); + indices.push_back(5); + + std::vector points; + points.push_back(Point(0,0,0)); + points.push_back(Point(1,0,0)); + points.push_back(Point(0,1,0)); + points.push_back(Point(0,0,1)); + points.push_back(Point(2,2,2)); + points.push_back(Point(-1,0,1)); + + Triangulation T(boost::make_zip_iterator(boost::make_tuple( points.begin(),indices.begin() )), + boost::make_zip_iterator(boost::make_tuple( points.end(),indices.end() ) ) ); + + CGAL_assertion( T.number_of_vertices() == 6 ); + + // check that the info was correctly set. + Triangulation::Finite_vertices_iterator vit; + for (vit = T.finite_vertices_begin(); vit != T.finite_vertices_end(); ++vit) + if( points[ vit->info() ] != vit->point() ){ + std::cerr << "Error different info" << std::endl; + exit(EXIT_FAILURE); + } + + return 0; +}