Merge pull request #3122 from MaelRL/T23-Fix_functor_return_type-GF

Triangulation_23: fix wrong return type in spatial_sort functor

# Conflicts:
#	Triangulation_3/test/Triangulation_3/test_regular_insert_range_with_info.cpp
This commit is contained in:
Laurent Rineau 2018-06-01 17:24:23 +02:00
commit c151778454
3 changed files with 203 additions and 160 deletions

View File

@ -443,7 +443,8 @@ private:
template<class Construct_bare_point, class Container> template<class Construct_bare_point, class Container>
struct Index_to_Bare_point struct Index_to_Bare_point
{ {
const Bare_point& operator()(const std::size_t& i) const typename boost::result_of<const Construct_bare_point(const Weighted_point&)>::type
operator()(const std::size_t& i) const
{ {
return cp(c[i]); return cp(c[i]);
} }

View File

@ -426,7 +426,8 @@ namespace CGAL {
template<class Construct_bare_point, class Container> template<class Construct_bare_point, class Container>
struct Index_to_Bare_point struct Index_to_Bare_point
{ {
const Bare_point& operator()(const std::size_t& i) const typename boost::result_of<const Construct_bare_point(const Weighted_point&)>::type
operator()(const std::size_t& i) const
{ {
return cp(c[i]); return cp(c[i]);
} }

View File

@ -1,85 +1,105 @@
#include "test_dependencies.h" #include "test_dependencies.h"
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h> #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_3.h> #include <CGAL/Regular_triangulation_3.h>
#include <CGAL/Triangulation_vertex_base_with_info_3.h> #include <CGAL/Triangulation_vertex_base_with_info_3.h>
#include <iostream>
#include <functional>
#include <utility>
#include <vector> #include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K; typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef K Traits;
typedef CGAL::Regular_triangulation_vertex_base_3<Traits> Vbb; template <typename K>
typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, Traits,Vbb> Vb; struct Tester
typedef CGAL::Triangulation_data_structure_3<Vb,CGAL::Regular_triangulation_cell_base_3<Traits> > Tds; {
typedef CGAL::Regular_triangulation_3<Traits, Tds> Regular; typedef K Traits;
typedef K::Weighted_point_3 Weighted_point; typedef CGAL::Regular_triangulation_vertex_base_3<Traits> Vbb;
typedef K::Point_3 Point; typedef CGAL::Triangulation_vertex_base_with_info_3<unsigned, Traits,Vbb> Vb;
typedef CGAL::Regular_triangulation_cell_base_3<Traits> Cb;
typedef CGAL::Triangulation_data_structure_3<Vb, Cb> Tds;
typedef CGAL::Regular_triangulation_3<Traits, Tds> RT;
typedef typename RT::Bare_point Bare_point;
typedef typename RT::Weighted_point Weighted_point;
#ifdef CGAL_LINKED_WITH_TBB #ifdef CGAL_LINKED_WITH_TBB
typedef CGAL::Spatial_lock_grid_3<CGAL::Tag_priority_blocking> Lock_ds; typedef CGAL::Spatial_lock_grid_3<CGAL::Tag_priority_blocking> Lock_ds;
typedef CGAL::Triangulation_data_structure_3<Vb, typedef CGAL::Triangulation_data_structure_3<Vb, Cb, CGAL::Parallel_tag> Tds_parallel;
CGAL::Regular_triangulation_cell_base_3<Traits>, CGAL::Parallel_tag> Tds_parallel; typedef CGAL::Regular_triangulation_3<Traits, Tds_parallel, Lock_ds> RT_parallel;
typedef CGAL::Regular_triangulation_3<Traits, Tds_parallel, Lock_ds> RT_parallel;
#endif #endif
template <bool is_const> template <bool is_const>
void test_iterator_on_pair(){ void test_iterator_on_pair() const
typedef std::vector< std::pair<Weighted_point,unsigned> > Container; {
typedef typename boost::mpl::if_< boost::mpl::bool_<is_const>,boost::add_const<Container>::type,Container >::type Cast_type; typedef std::vector<std::pair<Weighted_point, unsigned> > Container;
typedef typename boost::mpl::if_<boost::mpl::bool_<is_const>,
typename boost::add_const<Container>::type,
Container>::type Cast_type;
Container points; Container points;
points.push_back(std::make_pair(Weighted_point(Bare_point(0.160385, 0.599679, 0.374932), -0.118572), 0));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.17093, 0.82228, 0.51697), -0.0226131), 1));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.15773, 0.66293, 0.458541), -0.0753074), 2));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.388417, 0.685989, 0.401349), -0.0616195), 3));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.380061, 0.852124, 0.538984), -0.0145638), 4));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.0402467, 0.519724, 0.417205), -0.0698374), 5));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.0270472, 0.360373, 0.358776), -0.0109982), 6));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.257734, 0.383432, 0.301584), -0.0601458), 7));
points.push_back(std::make_pair(Weighted_point(Bare_point(0.142091, 0.643406, 0.61943), -0.251061), 8));
RT R(static_cast<Cast_type&>(points).begin(), static_cast<Cast_type&>(points).end());
assert(R.number_of_vertices() == 9);
points.push_back( std::make_pair( Weighted_point(Point(0,0,0),1),0 ) ); R.clear();
points.push_back( std::make_pair( Weighted_point(Point(1,0,0),2),1 ) ); R.insert(static_cast<Cast_type&>(points).begin(), static_cast<Cast_type&>(points).end());
points.push_back( std::make_pair( Weighted_point(Point(0,1,0),3),2 ) ); assert(R.number_of_vertices() == 9);
points.push_back( std::make_pair( Weighted_point(Point(0,0,1),4),3 ) );
points.push_back( std::make_pair( Weighted_point(Point(2,2,2),5),4 ) );
points.push_back( std::make_pair( Weighted_point(Point(-1,0,1),6),5 ) );
Regular R( static_cast<Cast_type&>(points).begin(),static_cast<Cast_type&>(points).end() );
assert( R.number_of_vertices() == 6 );
// check that the info was correctly set. // check that the info was correctly set.
Regular::Finite_vertices_iterator vit; typename RT::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit)
assert(points[vit->info()].first == vit->point()); assert(points[vit->info()].first == vit->point());
#ifdef CGAL_LINKED_WITH_TBB #ifdef CGAL_LINKED_WITH_TBB
{ {
// Construct the locking data-structure, using the bounding-box of the points // Construct the locking data-structure, using the bounding-box of the points
typename RT_parallel::Lock_data_structure locking_ds( typename RT_parallel::Lock_data_structure locking_ds(CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
// Contruct the triangulation in parallel
RT_parallel R(
static_cast<Cast_type&>(points).begin(),
static_cast<Cast_type&>(points).end(),
&locking_ds);
assert(R.number_of_vertices() == 6); // Contruct the triangulation in parallel
RT_parallel R(static_cast<Cast_type&>(points).begin(), static_cast<Cast_type&>(points).end(), &locking_ds);
assert(R.number_of_vertices() == 9);
R.clear();
R.insert(static_cast<Cast_type&>(points).begin(), static_cast<Cast_type&>(points).end(), &locking_ds);
assert(R.number_of_vertices() == 9);
// check that the info was correctly set. // check that the info was correctly set.
RT_parallel::Finite_vertices_iterator vit; typename RT_parallel::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) {
assert(points[vit->info()].first == vit->point()); assert(points[vit->info()].first == vit->point());
} }
}
#endif #endif
} }
void toto(int){} template <bool is_const>
void test_zip_iterator() const
{
typedef std::vector<Weighted_point> Container;
typedef typename boost::mpl::if_<boost::mpl::bool_<is_const>,
typename boost::add_const<Container>::type,
Container >::type Cast_type;
template <bool is_const>
void test_zip_iterator(){
typedef std::vector< Weighted_point > Container;
Container points; Container points;
typedef typename boost::mpl::if_< boost::mpl::bool_<is_const>,boost::add_const<Container>::type,Container >::type Cast_type; points.push_back(Weighted_point(Bare_point(0,0,0),1));
points.push_back(Weighted_point(Bare_point(1,0,0),2));
points.push_back( Weighted_point(Point(0,0,0),1) ); points.push_back(Weighted_point(Bare_point(0,1,0),3));
points.push_back( Weighted_point(Point(1,0,0),2) ); points.push_back(Weighted_point(Bare_point(0,0,1),4));
points.push_back( Weighted_point(Point(0,1,0),3) ); points.push_back(Weighted_point(Bare_point(2,2,2),5));
points.push_back( Weighted_point(Point(0,0,1),4) ); points.push_back(Weighted_point(Bare_point(-1,0,1),6));
points.push_back( Weighted_point(Point(2,2,2),5) );
points.push_back( Weighted_point(Point(-1,0,1),6) );
std::vector<unsigned> indices; std::vector<unsigned> indices;
indices.push_back(0); indices.push_back(0);
@ -89,96 +109,117 @@ void test_zip_iterator(){
indices.push_back(4); indices.push_back(4);
indices.push_back(5); indices.push_back(5);
Regular R( boost::make_zip_iterator(boost::make_tuple( static_cast<Cast_type&>(points).begin(),indices.begin() )), RT R(boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).begin(), indices.begin())),
boost::make_zip_iterator(boost::make_tuple( static_cast<Cast_type&>(points).end(),indices.end() ) ) ); boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).end(), indices.end())));
assert( R.number_of_vertices() == 6 ); assert(R.number_of_vertices() == 6);
// check that the info was correctly set. // check that the info was correctly set.
Regular::Finite_vertices_iterator vit; typename RT::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit)
assert( points[ vit->info() ] == vit->point() ); assert(points[ vit->info() ] == vit->point());
#ifdef CGAL_LINKED_WITH_TBB #ifdef CGAL_LINKED_WITH_TBB
{ {
// Construct the locking data-structure, using the bounding-box of the points // Construct the locking data-structure, using the bounding-box of the points
typename RT_parallel::Lock_data_structure locking_ds( typename RT_parallel::Lock_data_structure locking_ds(CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
// Contruct the triangulation in parallel // Contruct the triangulation in parallel
RT_parallel R( RT_parallel R(boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).begin(), indices.begin())),
boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).begin(), indices.begin())),
boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).end(), indices.end())), boost::make_zip_iterator(boost::make_tuple(static_cast<Cast_type&>(points).end(), indices.end())),
&locking_ds); &locking_ds);
assert(R.number_of_vertices() == 6);
// check that the info was correctly set.
typename RT_parallel::Finite_vertices_iterator vit;
for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) {
assert(points[vit->info()] == vit->point());
}
}
#endif
}
struct Auto_count
: public std::unary_function<const Weighted_point&,
std::pair<Weighted_point,
unsigned> >
{
mutable unsigned i;
Auto_count() : i(0){}
std::pair<Weighted_point,unsigned> operator()(const Weighted_point& p) const
{
return std::make_pair(p,i++);
}
};
template <bool is_const>
void test_transform_iterator() const
{
typedef std::vector< Weighted_point > Container;
typedef typename boost::mpl::if_<boost::mpl::bool_<is_const>,
typename boost::add_const<Container>::type,
Container >::type Cast_type;
Container points;
points.push_back(Weighted_point(Bare_point(0,0,0),1));
points.push_back(Weighted_point(Bare_point(1,0,0),2));
points.push_back(Weighted_point(Bare_point(0,1,0),3));
points.push_back(Weighted_point(Bare_point(0,0,1),4));
points.push_back(Weighted_point(Bare_point(2,2,2),5));
points.push_back(Weighted_point(Bare_point(-1,0,1),6));
RT R(boost::make_transform_iterator(static_cast<Cast_type&>(points).begin(), Auto_count()),
boost::make_transform_iterator(static_cast<Cast_type&>(points).end(), Auto_count()));
assert(R.number_of_vertices() == 6); assert(R.number_of_vertices() == 6);
// check that the info was correctly set. // check that the info was correctly set.
RT_parallel::Finite_vertices_iterator vit; typename RT::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit)
assert(points[vit->info()] == vit->point()); assert(points[ vit->info() ] == vit->point());
}
#endif
}
struct Auto_count : public CGAL::unary_function<const Weighted_point&,std::pair<Weighted_point,unsigned> >{
mutable unsigned i;
Auto_count() : i(0){}
std::pair<Weighted_point,unsigned> operator()(const Weighted_point& p) const {
return std::make_pair(p,i++);
}
};
template <bool is_const>
void test_transform_iterator(){
typedef std::vector< Weighted_point > Container;
Container points;
typedef typename boost::mpl::if_< boost::mpl::bool_<is_const>,boost::add_const<Container>::type,Container >::type Cast_type;
points.push_back( Weighted_point(Point(0,0,0),1) );
points.push_back( Weighted_point(Point(1,0,0),2) );
points.push_back( Weighted_point(Point(0,1,0),3) );
points.push_back( Weighted_point(Point(0,0,1),4) );
points.push_back( Weighted_point(Point(2,2,2),5) );
points.push_back( Weighted_point(Point(-1,0,1),6) );
Regular R( boost::make_transform_iterator(static_cast<Cast_type&>(points).begin(),Auto_count()),
boost::make_transform_iterator(static_cast<Cast_type&>(points).end(), Auto_count() ) );
assert( R.number_of_vertices() == 6 );
// check that the info was correctly set.
Regular::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit)
assert( points[ vit->info() ] == vit->point() );
#ifdef CGAL_LINKED_WITH_TBB #ifdef CGAL_LINKED_WITH_TBB
{ {
// Construct the locking data-structure, using the bounding-box of the points // Construct the locking data-structure, using the bounding-box of the points
typename RT_parallel::Lock_data_structure locking_ds( typename RT_parallel::Lock_data_structure locking_ds(CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
CGAL::Bbox_3(-1., 0., 0., 2, 2, 2), 50);
// Contruct the triangulation in parallel // Contruct the triangulation in parallel
RT_parallel R( RT_parallel R(boost::make_transform_iterator(static_cast<Cast_type&>(points).begin(), Auto_count()),
boost::make_transform_iterator(static_cast<Cast_type&>(points).begin(), Auto_count()),
boost::make_transform_iterator(static_cast<Cast_type&>(points).end(), Auto_count()), boost::make_transform_iterator(static_cast<Cast_type&>(points).end(), Auto_count()),
&locking_ds); &locking_ds);
assert(R.number_of_vertices() == 6); assert(R.number_of_vertices() == 6);
// check that the info was correctly set. // check that the info was correctly set.
RT_parallel::Finite_vertices_iterator vit; typename RT_parallel::Finite_vertices_iterator vit;
for (vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) for(vit = R.finite_vertices_begin(); vit != R.finite_vertices_end(); ++vit) {
assert(points[vit->info()] == vit->point()); assert(points[vit->info()] == vit->point());
} }
}
#endif #endif
} }
int main() void operator()() const
{ {
test_iterator_on_pair<false>(); test_iterator_on_pair<false>();
test_iterator_on_pair<true>(); test_iterator_on_pair<true>();
test_zip_iterator<false>(); test_zip_iterator<false>();
test_zip_iterator<true>(); test_zip_iterator<true>();
test_transform_iterator<false>(); test_transform_iterator<false>();
test_transform_iterator<true>(); test_transform_iterator<true>();
return 0; }
} };
int main()
{
typedef CGAL::Exact_predicates_inexact_constructions_kernel Epick;
typedef CGAL::Exact_predicates_exact_constructions_kernel Epeck;
std::cerr << "TESTING WITH Exact_predicates_inexact_constructions_kernel...\n";
Tester<Epick> test_epic;
test_epic();
std::cerr << "TESTING WITH Exact_predicates_exact_constructions_kernel...\n";
Tester<Epeck> test_epec;
test_epec();
return EXIT_SUCCESS;
}