This commit is contained in:
Andreas Fabri 2019-05-20 18:23:08 +02:00
parent 12ffb4a844
commit 2d1c78fdd9
9 changed files with 266 additions and 30 deletions

View File

@ -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,

View File

@ -0,0 +1,49 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_2.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <boost/iterator/zip_iterator.hpp>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_2<unsigned, K> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
typedef CGAL::Triangulation_2<K, Tds> Triangulation;
typedef Triangulation::Point Point;
int main()
{
std::vector<unsigned> 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<Point> 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;
}

View File

@ -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

View File

@ -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<Point,Vertex::Info>`.
*/
template < class PointWithInfoInputIterator >
std::ptrdiff_t
insert(PointWithInfoInputIterator first, PointWithInfoInputIterator last);
/// @}
/*! \name

View File

@ -46,10 +46,8 @@
#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
#include <CGAL/Spatial_sort_traits_adapter_3.h>
#include <CGAL/internal/info_check.h>
#include <boost/tuple/tuple.hpp>
#include <boost/iterator/zip_iterator.hpp>
#include <boost/mpl/and.hpp>
#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 <class Info>
const Point& top_get_first(const std::pair<Point,Info>& pair) const { return pair.first; }
@ -426,7 +425,7 @@ private:
template <class Info>
const Info& top_get_second(const boost::tuple<Point,Info>& tuple) const { return boost::get<1>(tuple); }
*/
template <class Tuple_or_pair,class InputIterator>
std::ptrdiff_t insert_with_info(InputIterator first, InputIterator last)
{

View File

@ -421,6 +421,7 @@ public:
#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
private:
/*
//top stands for tuple-or-pair
template <class Info>
const Weighted_point& top_get_first(const std::pair<Weighted_point,Info>& pair) const { return pair.first; }
@ -433,7 +434,7 @@ private:
template <class Info>
const Info& top_get_second(const boost::tuple<Weighted_point,Info>& 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<class Construct_bare_point, class Container>

View File

@ -68,6 +68,11 @@
#include <boost/unordered_map.hpp>
#include <boost/utility/result_of.hpp>
#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
#include <CGAL/internal/info_check.h>
#include <boost/iterator/zip_iterator.hpp>
#endif
#ifndef CGAL_NO_STRUCTURAL_FILTERING
#include <CGAL/internal/Static_filters/tools.h>
#include <CGAL/Triangulation_structural_filtering_traits.h>
@ -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<InputIterator>::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<Point> 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<const Construct_point_3(const Point&)>::type Ret;
typedef CGAL::internal::boost_::function_property_map<Construct_point_3, Point, Ret> fpmap;
typedef CGAL::Spatial_sort_traits_adapter_3<Geom_traits, fpmap> Search_traits_3;
spatial_sort(points.begin(), points.end(),
Search_traits_3(
CGAL::internal::boost_::make_function_property_map<Point, Ret, Construct_point_3>(
geom_traits().construct_point_3_object()), geom_traits()));
Vertex_handle hint;
for(typename std::vector<Point>::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 <class Info>
const Point& top_get_first(const std::pair<Point,Info>& pair) const { return pair.first; }
template <class Info>
const Info& top_get_second(const std::pair<Point,Info>& pair) const { return pair.second; }
template <class Info>
const Point& top_get_first(const boost::tuple<Point,Info>& tuple) const { return boost::get<0>(tuple); }
template <class Info>
const Info& top_get_second(const boost::tuple<Point,Info>& tuple) const { return boost::get<1>(tuple); }
template <class Tuple_or_pair,class InputIterator>
std::ptrdiff_t insert_with_info(InputIterator first, InputIterator last)
{
size_type n = number_of_vertices();
std::vector<std::size_t> indices;
std::vector<Point> points;
std::vector<typename Triangulation_data_structure::Vertex::Info> 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<InputIterator>::value_type,
std::pair<Point, typename internal::Info_check<
typename Triangulation_data_structure::Vertex>::type>
> >::type* =NULL)
{
return insert_with_info< std::pair<Point,typename internal::Info_check<typename Triangulation_data_structure::Vertex>::type> >(first,last);
}
template <class InputIterator_1,class InputIterator_2>
std::ptrdiff_t
insert(boost::zip_iterator< boost::tuple<InputIterator_1,InputIterator_2> > first,
boost::zip_iterator< boost::tuple<InputIterator_1,InputIterator_2> > last,
typename boost::enable_if<
boost::mpl::and_<
boost::is_convertible< typename std::iterator_traits<InputIterator_1>::value_type, Point >,
boost::is_convertible< typename std::iterator_traits<InputIterator_2>::value_type, typename internal::Info_check<typename Triangulation_data_structure::Vertex>::type >
>
>::type* =NULL)
{
return insert_with_info< boost::tuple<Point, typename internal::Info_check<
typename Triangulation_data_structure::Vertex>::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) {

View File

@ -0,0 +1,52 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <CGAL/boost/iterator/transform_iterator.hpp>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, K> Vb;
typedef CGAL::Triangulation_cell_base_3<K> Cb;
typedef CGAL::Triangulation_data_structure_3<Vb, Cb> Tds;
typedef CGAL::Triangulation_3<K, Tds> Triangulation;
typedef Triangulation::Point Point;
//a functor that returns a std::pair<Point,unsigned>.
//the unsigned integer is incremented at each call to
//operator()
struct Auto_count : public CGAL::cpp98::unary_function<const Point&,std::pair<Point,unsigned> >{
mutable unsigned i;
Auto_count() : i(0){}
std::pair<Point,unsigned> operator()(const Point& p) const {
return std::make_pair(p,i++);
}
};
int main()
{
std::vector<Point> 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;
}

View File

@ -0,0 +1,50 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <boost/iterator/zip_iterator.hpp>
#include <iostream>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, K> Vb;
typedef CGAL::Triangulation_cell_base_3<K> Cb;
typedef CGAL::Triangulation_data_structure_3<Vb, Cb> Tds;
typedef CGAL::Triangulation_3<K, Tds> Triangulation;
typedef Triangulation::Point Point;
int main()
{
std::vector<unsigned> 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<Point> 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;
}