make the insertion of a range of points with info working with hierarchy

This commit is contained in:
Sébastien Loriot 2013-08-05 15:03:46 +02:00
parent 8cd8461fa5
commit ded66799a6
2 changed files with 113 additions and 2 deletions

View File

@ -6,7 +6,8 @@
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, K> Vb; typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, K> Vb;
typedef CGAL::Triangulation_data_structure_3<Vb> Tds; typedef CGAL::Triangulation_data_structure_3<Vb> Tds;
typedef CGAL::Delaunay_triangulation_3<K, Tds> Delaunay; //Use the Fast_location tag. Default or Compact_location works too.
typedef CGAL::Delaunay_triangulation_3<K, Tds, CGAL::Fast_location> Delaunay;
typedef Delaunay::Point Point; typedef Delaunay::Point Point;
int main() int main()

View File

@ -30,6 +30,15 @@
#include <boost/random/geometric_distribution.hpp> #include <boost/random/geometric_distribution.hpp>
#include <boost/random/variate_generator.hpp> #include <boost/random/variate_generator.hpp>
#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
namespace CGAL { namespace CGAL {
// This class is deprecated, but must be kept for backward compatibility. // 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, Vertex_handle insert(const Point &p, Locate_type lt, Cell_handle loc,
int li, int lj); int li, int lj);
#ifndef CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
template < class InputIterator > 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<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(); size_type n = number_of_vertices();
@ -154,6 +177,93 @@ public:
return number_of_vertices() - n; return number_of_vertices() - n;
} }
#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; }
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::ptrdiff_t> indices;
std::vector<Point> points;
std::vector<typename Vertex::Info> 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<Geom_traits,Point*> 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<std::ptrdiff_t>::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<InputIterator>::value_type,
std::pair<Point,typename internal::Info_check<Vertex>::type>
> >::type* =NULL
)
{
return insert_with_info< std::pair<Point,typename internal::Info_check<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<Vertex>::type >
>
>::type* =NULL
)
{
return insert_with_info< boost::tuple<Point,typename internal::Info_check<Vertex>::type> >(first,last);
}
#endif //CGAL_TRIANGULATION_3_DONT_INSERT_RANGE_OF_POINTS_WITH_INFO
void remove(Vertex_handle v); void remove(Vertex_handle v);
template < typename InputIterator > template < typename InputIterator >