Improved tests of natural/regular coordinates (2D)

backward compatible + new tests
This commit is contained in:
Mael Rouxel-Labbé 2018-01-12 16:45:11 +01:00
parent dbc48009bc
commit ee4134317e
4 changed files with 579 additions and 244 deletions

View File

@ -18,67 +18,278 @@
// //
// //
// Author(s) : Naceur MESKINI. // Author(s) : Naceur MESKINI.
// Mael Rouxel-Labbé
#include <CGAL/Interpolation/internal/helpers.h>
#include <CGAL/natural_neighbor_coordinates_2.h> #include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/algorithm.h> #include <CGAL/algorithm.h>
#include <CGAL/Random.h> #include <CGAL/Random.h>
#include <CGAL/barycenter.h> #include <CGAL/barycenter.h>
#include <iostream>
#include <cassert> #include <cassert>
#include <iostream>
#include <iterator>
#include <list>
#include <utility> #include <utility>
#include <vector>
template < class ForwardIterator > template < class ForwardIterator >
bool test_norm(ForwardIterator first, ForwardIterator beyond, bool test_norm(ForwardIterator first, ForwardIterator beyond,
typename std::iterator_traits<ForwardIterator>::value_type::second_type norm) typename std::iterator_traits<ForwardIterator>::value_type::second_type norm)
{ {
typename typename std::iterator_traits<ForwardIterator>::value_type::second_type sum(0);
std::iterator_traits<ForwardIterator>::value_type::second_type sum(0); for(; first!=beyond; first++)
for(; first !=beyond; first++)
sum += first->second; sum += first->second;
return norm == sum; return norm == sum;
} }
template < class ForwardIterator, class Point > template < class ForwardIterator, class Dt >
bool test_barycenter(ForwardIterator first, ForwardIterator beyond, bool test_barycenter(ForwardIterator first, ForwardIterator beyond,
typename std::iterator_traits<ForwardIterator>::value_type::second_type /*norm*/, const typename Dt::Point& p)
const Point& p)
{ {
return p == CGAL::barycenter(first, beyond); return p == CGAL::barycenter(first, beyond);
} }
template < class Dt >
template <class Tr> void _test_natural_neighbors_2_without_outputfunctor(const Dt& T)
void _test_natural_neighbors_2( const Tr & )
{ {
std::cout << "Testing backward compatibility..." << std::endl;
typedef typename Tr::Geom_traits Gt; typedef typename Dt::Geom_traits Gt;
typedef typename Gt::Point_2 Point_2;
typedef typename Gt::FT Coord_type;
typedef typename Gt::Point_2 Point_2; typedef std::vector<std::pair<Point_2, Coord_type> > Point_coordinate_vector;
typedef typename Gt::FT Coord_type; typedef typename Point_coordinate_vector::const_iterator PCV_cit;
typedef std::vector< std::pair<Point_2, Coord_type> > Point_coordinate_vector; typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Face_handle Face_handle;
typedef std::pair<Face_handle, int> Edge;
// TESTING a GRID POINT SET Point_coordinate_vector coords;
std::cout << "NN2: Testing grid points." << std::endl;
Tr T; // point on a vertex
Point_2 p = T.finite_vertices_begin()->point();
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> coordinate_result =
CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
Coord_type norm = coordinate_result.second;
assert(norm == Coord_type(1));
PCV_cit ci = coords.begin();
assert(ci->first == p);
assert(ci->second == Coord_type(1));
++ci;
assert(ci == coords.end());
coords.clear();
// On a point, but as a vertex handle
Vertex_handle vh = --(T.finite_vertices_end());
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, vh, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
bool is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
assert(norm == Coord_type(1));
ci = coords.begin();
while(ci != coords.end())
{
assert(ci->first != vh->point());
assert(ci->second != Coord_type(1));
++ci;
}
coords.clear();
// point on an edge
p = Point_2(0,0.5);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_barycenter<PCV_cit, Dt>(coords.begin(), coords.end(), p);
assert(is_equal);
coords.clear();
// with the conflict hole
std::list<Edge> hole_bd;
T.get_boundary_of_conflicts(p, std::back_inserter(hole_bd));
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords),
hole_bd.begin(), hole_bd.end());
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<PCV_cit, Dt>(coords.begin(), coords.end(), p);
assert(is_equal);
coords.clear();
// outside convex hull
p = Point_2(3,0.5);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(!coordinate_result.third);
// same, but with the face hint API
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords),
T.finite_faces_begin());
assert(!coordinate_result.third);
// on a convex hull edge:
coords.clear();
p = Point_2(2, 1);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<PCV_cit, Dt>(coords.begin(), coords.end(), p);
assert(is_equal);
}
template < class Dt >
void _test_natural_neighbors_2_with_outputfunctor(const Dt& T)
{
std::cout << "Testing with OutputFunctor..." << std::endl;
typedef typename Dt::Geom_traits Gt;
typedef typename Dt::Point Point;
typedef typename Gt::FT Coord_type;
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Face_handle Face_handle;
typedef std::pair<Face_handle, int> Edge;
typedef std::vector<std::pair<Vertex_handle, Coord_type> > Vertex_coordinate_vector;
typedef typename Vertex_coordinate_vector::const_iterator VCV_cit;
typedef CGAL::Identity<std::pair<Vertex_handle, Coord_type> > Identity_output_functor;
typedef std::vector<std::pair<Point, Coord_type> > Point_coordinate_vector;
typedef typename Point_coordinate_vector::const_iterator PCV_cit;
typedef CGAL::Interpolation::internal::Extract_point_in_pair<Dt, Coord_type> Point_output_functor;
Vertex_coordinate_vector vh_coords;
Identity_output_functor vh_fct;
Point_coordinate_vector pt_coords;
Point_output_functor pt_fct;
// point on a vertex
Point p = T.finite_vertices_begin()->point();
CGAL::Triple<std::back_insert_iterator<Vertex_coordinate_vector>, Coord_type, bool> vh_coordinate_result =
CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(vh_coords), vh_fct);
assert(vh_coordinate_result.third);
Coord_type norm = vh_coordinate_result.second;
assert(norm == Coord_type(1));
VCV_cit ci = vh_coords.begin();
assert(ci->first == Vertex_handle(T.finite_vertices_begin()));
assert(ci->second == Coord_type(1));
++ci;
assert(ci == vh_coords.end());
vh_coords.clear();
// On a point, but as a vertex handle
Vertex_handle vh = --(T.finite_vertices_end());
vh_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, vh, std::back_inserter(vh_coords), vh_fct);
assert(vh_coordinate_result.third);
norm = vh_coordinate_result.second;
assert(norm == Coord_type(1));
ci = vh_coords.begin();
while(ci != vh_coords.end())
{
assert(ci->first != vh);
assert(T.tds().is_vertex(vh));
assert(ci->second != Coord_type(1));
++ci;
}
vh_coords.clear();
// point on an edge
p = Point(0,0.5);
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> pt_coordinate_result =
CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
bool is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<PCV_cit, Dt>(pt_coords.begin(), pt_coords.end(), p);
assert(is_equal);
pt_coords.clear();
// with the conflict hole
std::list<Edge> hole_bd;
T.get_boundary_of_conflicts(p, std::back_inserter(hole_bd));
pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct,
hole_bd.begin(), hole_bd.end());
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<PCV_cit, Dt>(pt_coords.begin(), pt_coords.end(), p);
assert(is_equal);
pt_coords.clear();
// outside convex hull
p = Point(3,0.5);
pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct);
assert(!pt_coordinate_result.third);
pt_coords.clear();
// same, but with the face hint API
pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct,
T.finite_faces_begin());
assert(!pt_coordinate_result.third);
pt_coords.clear();
// on a convex hull edge:
p = Point(2, 1);
pt_coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<PCV_cit, Dt>(pt_coords.begin(), pt_coords.end(), p);
assert(is_equal);
}
template < class Dt >
void _test_natural_neighbors_2(const Dt&)
{
typedef typename Dt::Geom_traits Gt;
typedef typename Gt::Point_2 Point;
Dt T;
//Grid points: //Grid points:
Point_2 p1_2(-2, -2); Point p1_2(-2, -2);
Point_2 p2_2(-2, 2); Point p2_2(-2, 2);
Point_2 p3_2(2, -2); Point p3_2(2, -2);
Point_2 p4_2(2, 2); Point p4_2(2, 2);
Point_2 p1(-1, -1); Point p1(-1, -1);
Point_2 p2(-1, 1); Point p2(-1, 1);
Point_2 p3(1, -1); Point p3(1, -1);
Point_2 p4(1, 1); Point p4(1, 1);
Point_2 p12(-1, 0); Point p12(-1, 0);
Point_2 p23(0, 1); Point p23(0, 1);
Point_2 p34(1, 0); Point p34(1, 0);
Point_2 p41(0, -1); Point p41(0, -1);
T.insert(p1_2); T.insert(p1_2);
T.insert(p2_2); T.insert(p2_2);
@ -92,47 +303,10 @@ void _test_natural_neighbors_2( const Tr & )
T.insert(p23); T.insert(p23);
T.insert(p34); T.insert(p34);
T.insert(p41); T.insert(p41);
T.insert(Point_2(0,0)); T.insert(Point(0,0));
Point_coordinate_vector coords; _test_natural_neighbors_2_without_outputfunctor(T);
_test_natural_neighbors_2_with_outputfunctor(T);
// point on a vertex;
Point_2 p = Point_2(p34);
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> coordinate_result =
CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
Coord_type norm = coordinate_result.second;
assert(norm == Coord_type(1));
typename std::vector<std::pair<Point_2, Coord_type> >::const_iterator ci= coords.begin();
assert(ci->first == p);
assert(ci->second == Coord_type(1));
ci++;
assert(ci==coords.end());
coords.clear();
// point on an edge:
p = Point_2(0,0.5);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter(coords.begin(), coords.end(), norm, p));
coords.clear();
// outside convex hull:
p = Point_2(3,0.5);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(!coordinate_result.third);
// on a convex hull edge:
coords.clear();
p = Point_2(2, 1);
coordinate_result = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter( coords.begin(), coords.end(),norm, p));
std::cout << "done" << std::endl;
} }

View File

@ -42,105 +42,337 @@ bool test_norm(ForwardIterator first, ForwardIterator beyond,
return norm == sum; return norm == sum;
} }
template < class ForwardIterator, class Point > template < class Rt, class ForwardIterator >
bool test_barycenter(ForwardIterator first, ForwardIterator beyond, bool test_barycenter(ForwardIterator first, ForwardIterator beyond,
typename std::iterator_traits<ForwardIterator>::value_type::second_type norm, typename std::iterator_traits<ForwardIterator>::value_type::second_type norm,
const Point& p) const typename Rt::Weighted_point& p)
{ {
typedef typename CGAL::Kernel_traits<Point>::Kernel::Point_2 Bare_point; typedef typename Rt::Geom_traits Gt;
typedef typename Rt::Bare_point Bare_point;
typename Gt::Construct_point_2 cp = Gt().construct_point_2_object();
Bare_point b = CGAL::ORIGIN; Bare_point b = CGAL::ORIGIN;
for(; first != beyond; ++first) for(; first != beyond; ++first)
b = b + (first->second/norm) * (first->first.point() - CGAL::ORIGIN); b = b + (first->second / norm) * (cp(first->first) - CGAL::ORIGIN);
return p == b; return (cp(p) == b);
} }
template <class Point, class FT> template < class Rt >
struct Functor void _test_natural_neighbors_2_without_outputfunctor(Rt T) // intentional copy because T is modified
{ {
typedef Point argument_type; std::cout << "Testing backward compatibility..." << std::endl;
typedef std::pair<FT, bool> result_type;
result_type operator()(const Point&) { return std::make_pair(0., true); } typedef typename Rt::Bare_point Bare_point;
}; typedef typename Rt::Weighted_point Weighted_point;
typedef typename Rt::Geom_traits Gt;
typedef typename Gt::FT Coord_type;
typedef std::vector<std::pair<Weighted_point, Coord_type> > Point_coordinate_vector;
template <class Tr> typedef typename Rt::Vertex_handle Vertex_handle;
void test_gradient_fitting(const Tr& rt) typedef typename Rt::Face_handle Face_handle;
{ typedef std::pair<Face_handle, int> Edge;
typedef typename Tr::Geom_traits::Kernel K;
typedef typename Tr::Geom_traits::FT FT;
typedef typename Tr::Geom_traits::Vector_2 Vector_2;
typedef typename Tr::Geom_traits::Weighted_point_2 Point;
typedef typename std::back_insert_iterator<
std::vector<
std::pair<Point, Vector_2> > > OutputIterator;
std::vector<std::pair< Point, Vector_2 > > v;
OutputIterator out = std::back_inserter(v);
Functor<Point, FT> f;
CGAL::Interpolation_gradient_fitting_traits_2<K> traits;
sibson_gradient_fitting_rn_2(rt, out, f, traits);
}
template <class Tr>
void _test_regular_neighbors_2(const Tr &)
{
Tr T;
int n=20, m=200;
double r = 3;
double max_weight =1;
typedef typename Tr::Geom_traits Gt;
typedef typename Gt::Weighted_point_2 Weighted_point;
typedef typename Gt::Point_2 Bare_point;
typedef typename Gt::FT Coord_type;
typedef std::vector<std::pair<Weighted_point,Coord_type > > Point_coordinate_vector;
std::cout << "RN2: Testing random points." << std::endl;
//test random points in a square of length r:
std::vector<Bare_point> points;
points.reserve(n+m);
//put four bounding box points:
points.push_back(Bare_point(-r,-r));
points.push_back(Bare_point(r,-r));
points.push_back(Bare_point(-r,r));
points.push_back(Bare_point(r,r));
// Create n+m-4 points within a disc of radius 2
CGAL::Random_points_in_square_2<Bare_point> g(r);
CGAL::cpp11::copy_n(g, n+m, std::back_inserter(points));
CGAL::Random random;
for(int i=0; i<n ; i++)
T.insert(Weighted_point(points[i],random.get_double(-max_weight, max_weight)));
Point_coordinate_vector coords; Point_coordinate_vector coords;
for(int i=n; i<n+m; i++)
// test with 0 weight:
Weighted_point wp(Bare_point(0,0), 0.);
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> coordinate_result =
CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(coordinate_result.third);
Coord_type norm = coordinate_result.second;
assert(norm == Coord_type(1));
typename std::vector< std::pair<Weighted_point, Coord_type> >::const_iterator ci = coords.begin();
for(; ci!= coords.end(); ci++)
assert(ci->second == Coord_type(0.25));
bool is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, wp);
assert(is_equal);
coords.clear();
// test with hidden_vertices:
wp = Weighted_point(Bare_point(0,0), 4.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, wp);
assert(is_equal);
coords.clear();
// add the middle point of the grid
T.insert(Weighted_point(Bare_point(0,0), 0.));
// point on a vertex;
wp = Weighted_point(Bare_point(1,0), 0.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(norm == Coord_type(1));
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
ci = coords.begin();
assert(ci->first == wp);
assert(ci->second == Coord_type(1));
++ci;
assert(ci == coords.end());
coords.clear();
// point on the vertex but creating a hole:
wp = Weighted_point(Bare_point(1,0), 2.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, wp);
assert(is_equal);
coords.clear();
// point on an edge:
wp = Weighted_point(Bare_point(0,0.5), 3.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, wp);
assert(is_equal);
coords.clear();
// a vertex v in Reg(P\v->point()):
typename Rt::Vertex_iterator vit = T.finite_vertices_end();
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, --vit, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, vit->point());
assert(is_equal);
coords.clear();
ci = coords.begin();
while(ci != coords.end())
{ {
Weighted_point wp = Weighted_point(points[i], random.get_double(2*max_weight, 3*max_weight)); assert(ci->first != (--vit)->point());
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> coordinate_result = assert(ci->second != Coord_type(1));
CGAL::regular_neighbor_coordinates_2(T,wp,std::back_inserter(coords)); ++ci;
assert(coordinate_result.third);
Coord_type norm = coordinate_result.second;
assert(norm > 0);
assert(test_barycenter(coords.begin(), coords.end(), norm, points[i]));
coords.clear();
} }
coords.clear();
test_gradient_fitting(T); // with the conflict hole
std::list<Edge> hole_bd;
std::list<Vertex_handle> hidden_vertices;
T.get_boundary_of_conflicts_and_hidden_vertices(wp, std::back_inserter(hole_bd), std::back_inserter(hidden_vertices));
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords),
hole_bd.begin(), hole_bd.end(),
hidden_vertices.begin(), hidden_vertices.end());
assert(coordinate_result.third);
//TESTING a GRID POINT SET norm = coordinate_result.second;
std::cout << "RN2: Testing grid points." << std::endl; is_equal = test_norm(coords.begin(), coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(coords.begin(), coords.end(), norm, wp);
assert(is_equal);
coords.clear();
// outside convex hull:
wp = Weighted_point(Bare_point(3,0.5), 3.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(!coordinate_result.third);
// same but with the face hint API
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords),
T.finite_faces_begin());
assert(!coordinate_result.third);
// on a convex hull edge:
wp = Weighted_point(Bare_point(2,1), 3.);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(coords));
assert(!coordinate_result.third);
}
template < class Rt >
void _test_natural_neighbors_2_with_outputfunctor(Rt T) // intentional copy because T is modified
{
std::cout << "Testing with OutputFunctor..." << std::endl;
typedef typename Rt::Bare_point Bare_point;
typedef typename Rt::Weighted_point Weighted_point;
typedef typename Rt::Geom_traits Gt;
typedef typename Gt::FT Coord_type;
typedef typename Rt::Vertex_handle Vertex_handle;
typedef typename Rt::Face_handle Face_handle;
typedef std::pair<Face_handle, int> Edge;
typedef std::vector<std::pair<Vertex_handle, Coord_type> > Vertex_coordinate_vector;
typedef typename Vertex_coordinate_vector::const_iterator VCV_cit;
typedef CGAL::Identity<std::pair<Vertex_handle, Coord_type> > Identity_output_functor;
typedef std::vector<std::pair<Weighted_point, Coord_type> > Point_coordinate_vector;
typedef typename Point_coordinate_vector::const_iterator PCV_cit;
typedef CGAL::Interpolation::internal::Extract_point_in_pair<Rt, Coord_type> Point_output_functor;
Vertex_coordinate_vector vh_coords;
Identity_output_functor vh_fct;
Point_coordinate_vector pt_coords;
Point_output_functor pt_fct;
// test with 0 weight:
Weighted_point wp(Bare_point(0,0), 0.);
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> pt_coordinate_result =
CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
Coord_type norm = pt_coordinate_result.second;
assert(norm == Coord_type(1));
PCV_cit ci = pt_coords.begin();
for(; ci!= pt_coords.end(); ci++)
assert(ci->second == Coord_type(0.25));
bool is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, wp);
assert(is_equal);
pt_coords.clear();
// test with hidden_vertices:
wp = Weighted_point(Bare_point(0,0), 4.);
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, wp);
assert(is_equal);
pt_coords.clear();
// add the middle point of the grid
T.insert(Weighted_point(Bare_point(0,0), 0.));
// point on a vertex;
wp = Weighted_point(Bare_point(1,0), 0.);
CGAL::Triple<std::back_insert_iterator<Vertex_coordinate_vector>, Coord_type, bool> vh_coordinate_result =
CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(vh_coords), vh_fct);
assert(vh_coordinate_result.third);
norm = vh_coordinate_result.second;
assert(norm == Coord_type(1));
is_equal = test_norm(vh_coords.begin(), vh_coords.end(), norm);
assert(is_equal);
VCV_cit vh_ci = vh_coords.begin();
assert(vh_ci->first->point() == wp);
assert(vh_ci->second == Coord_type(1));
++vh_ci;
assert(vh_ci == vh_coords.end());
vh_coords.clear();
// point on the vertex but creating a hole:
wp = Weighted_point(Bare_point(1,0), 2.);
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, wp);
assert(is_equal);
pt_coords.clear();
// point on an edge:
wp = Weighted_point(Bare_point(0,0.5), 3.);
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, wp);
assert(is_equal);
pt_coords.clear();
// a vertex v in Reg(P\v->point()):
typename Rt::Vertex_iterator vit = T.finite_vertices_end();
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, --vit, std::back_inserter(pt_coords), pt_fct);
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, vit->point());
assert(is_equal);
pt_coords.clear();
ci = pt_coords.begin();
while(ci != pt_coords.end())
{
assert(ci->first != (--vit)->point());
assert(ci->second != Coord_type(1));
++ci;
}
pt_coords.clear();
// with the conflict hole
std::list<Edge> hole_bd;
std::list<Vertex_handle> hidden_vertices;
T.get_boundary_of_conflicts_and_hidden_vertices(wp, std::back_inserter(hole_bd), std::back_inserter(hidden_vertices));
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct,
hole_bd.begin(), hole_bd.end(),
hidden_vertices.begin(), hidden_vertices.end());
assert(pt_coordinate_result.third);
norm = pt_coordinate_result.second;
is_equal = test_norm(pt_coords.begin(), pt_coords.end(), norm);
assert(is_equal);
is_equal = test_barycenter<Rt>(pt_coords.begin(), pt_coords.end(), norm, wp);
assert(is_equal);
pt_coords.clear();
// outside convex hull:
wp = Weighted_point(Bare_point(3,0.5), 3.);
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(!pt_coordinate_result.third);
// same but with the face hint API
vh_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(vh_coords), vh_fct,
T.finite_faces_begin());
assert(!vh_coordinate_result.third);
// on a convex hull edge:
wp = Weighted_point(Bare_point(2,1), 3.);
pt_coordinate_result = CGAL::regular_neighbor_coordinates_2(T, wp, std::back_inserter(pt_coords), pt_fct);
assert(!pt_coordinate_result.third);
}
template <class Rt>
void _test_regular_neighbors_2(const Rt &)
{
typedef typename Rt::Bare_point Bare_point;
typedef typename Rt::Weighted_point Weighted_point;
Rt T;
Tr T2;
//Grid points: //Grid points:
Bare_point p1_2(-2, -2); Bare_point p1_2(-2, -2);
Bare_point p2_2(-2,2); Bare_point p2_2(-2,2);
@ -155,89 +387,19 @@ void _test_regular_neighbors_2(const Tr &)
Bare_point p34(1,0); Bare_point p34(1,0);
Bare_point p41(0,-1); Bare_point p41(0,-1);
T2.insert(Weighted_point(p1_2, 0)); T.insert(Weighted_point(p1_2, 0));
T2.insert(Weighted_point(p2_2, 0)); T.insert(Weighted_point(p2_2, 0));
T2.insert(Weighted_point(p3_2, 0)); T.insert(Weighted_point(p3_2, 0));
T2.insert(Weighted_point(p4_2, 0)); T.insert(Weighted_point(p4_2, 0));
T2.insert(Weighted_point(p1, 0)); T.insert(Weighted_point(p1, 0));
T2.insert(Weighted_point(p2, 0)); T.insert(Weighted_point(p2, 0));
T2.insert(Weighted_point(p3, 0)); T.insert(Weighted_point(p3, 0));
T2.insert(Weighted_point(p4, 0)); T.insert(Weighted_point(p4, 0));
T2.insert(Weighted_point(p12, 0)); T.insert(Weighted_point(p12, 0));
T2.insert(Weighted_point(p23, 0)); T.insert(Weighted_point(p23, 0));
T2.insert(Weighted_point(p34, 0)); T.insert(Weighted_point(p34, 0));
T2.insert(Weighted_point(p41, 0)); T.insert(Weighted_point(p41, 0));
//test with 0 weight: _test_natural_neighbors_2_without_outputfunctor(T);
Weighted_point wp(Bare_point(0,0), 0); _test_natural_neighbors_2_with_outputfunctor(T);
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, Coord_type, bool> coordinate_result =
CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(coordinate_result.third);
Coord_type norm = coordinate_result.second;
assert(norm == Coord_type(1));
typename std::vector< std::pair<Weighted_point, Coord_type> >::const_iterator ci = coords.begin();
for(; ci!= coords.end(); ci++)
assert(ci->second == Coord_type(0.25));
assert(test_barycenter(coords.begin(), coords.end(), norm, wp));
coords.clear();
//test with hidden_vertices:
wp = Weighted_point(Bare_point(0,0), 4);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter(coords.begin(), coords.end(), norm, wp));
coords.clear();
//add the middle point of the grid
T2.insert(Weighted_point(Bare_point(0,0), 0));
//point on a vertex;
wp = Weighted_point(p34, 0);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(norm == Coord_type(1));
ci = coords.begin();
assert(ci->first == wp);
assert(ci->second == Coord_type(1));
ci++;
assert(ci == coords.end());
coords.clear();
//point on the vertex but creating a hole:
wp = Weighted_point(p34, 2);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter(coords.begin(), coords.end(), norm, wp));
coords.clear();
//point on an edge:
wp = Weighted_point(Bare_point(0,0.5), 3);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter(coords.begin(), coords.end(), norm, wp));
coords.clear();
//a vertex v in Reg(P\v->point()):
typename Tr::Vertex_iterator vit = T2.finite_vertices_end();
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, --vit, std::back_inserter(coords));
assert(coordinate_result.third);
norm = coordinate_result.second;
assert(test_barycenter(coords.begin(), coords.end(), norm,vit->point()));
coords.clear();
//outside convex hull:
wp = Weighted_point(Bare_point(3,0.5), 3);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(!coordinate_result.third);
//on a convex hull edge:
wp = Weighted_point(Bare_point(2,1), 3);
coordinate_result = CGAL::regular_neighbor_coordinates_2(T2, wp, std::back_inserter(coords));
assert(!coordinate_result.third);
} }

View File

@ -30,8 +30,8 @@ typedef CGAL::Delaunay_triangulation_2<K> Dt;
int main() int main()
{ {
std::cout << "Testing NN_neighbors_2 " << std::endl; std::cout << "Testing NN_neighbors_2 " << std::endl;
std::cout << " with Exact_predicates_inexact_constructions_kernel: " << std::endl ; std::cout << " using Exact_predicates_inexact_constructions_kernel: " << std::endl;
_test_natural_neighbors_2( Dt() ); _test_natural_neighbors_2( Dt() );
return 0; return EXIT_SUCCESS;
} }

View File

@ -16,25 +16,24 @@
// //
// Author(s) : Julia Floetotto // Author(s) : Julia Floetotto
#include <CGAL/basic.h> #include <CGAL/_test_regular_neighbors_2.cpp>
#include <CGAL/double.h>
#include <CGAL/Exact_predicates_exact_constructions_kernel.h> #include <CGAL/Exact_predicates_exact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_2.h>
#include <CGAL/_test_regular_neighbors_2.cpp> #include <CGAL/basic.h>
#include <CGAL/double.h>
#include <CGAL/Regular_triangulation_2.h>
#include <iostream> #include <iostream>
typedef CGAL::Exact_predicates_exact_constructions_kernel K; typedef CGAL::Exact_predicates_exact_constructions_kernel K;
typedef CGAL::Regular_triangulation_2<K> Rt1; typedef CGAL::Regular_triangulation_2<K> Rt1;
int main() int main()
{ {
std::cout << "Testing NN_neighbors_2 " << std::endl; std::cout << "Testing NN_neighbors_2 " << std::endl;
std::cout << " with Exact_predicates_exact_constructions_kernel: " << std::endl ; std::cout << " using Exact_predicates_exact_constructions_kernel: " << std::endl;
_test_regular_neighbors_2( Rt1() ); _test_regular_neighbors_2( Rt1() );
return 0; return EXIT_SUCCESS;
} }