Fixed trailing whitespace and (some of the) inconsistent indentation

No real changes.
This commit is contained in:
Mael Rouxel-Labbé 2018-01-10 15:51:05 +01:00
parent 118e5dc9c3
commit 67f99cc53d
17 changed files with 592 additions and 591 deletions

View File

@ -208,6 +208,5 @@ int main()
<< CGAL::to_double(ssquare_total)/n << " max "
<< CGAL::to_double(ssquare_max) << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -20,68 +20,54 @@ typedef K::FT Coord_type;
typedef K::Vector_2 Vector;
typedef K::Point_2 Point;
template <typename V, typename G>
struct Value_and_gradient {
Value_and_gradient()
: value(), gradient(CGAL::NULL_VECTOR)
{}
struct Value_and_gradient
{
Value_and_gradient() : value(), gradient(CGAL::NULL_VECTOR) {}
V value;
G gradient;
};
typedef CGAL::Triangulation_vertex_base_with_info_2<Value_and_gradient<Coord_type,Vector>, K> Vb;
typedef CGAL::Triangulation_vertex_base_with_info_2<
Value_and_gradient<Coord_type, Vector>, K> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Delaunay_triangulation;
typedef CGAL::Delaunay_triangulation_2<K, Tds> Delaunay_triangulation;
typedef Delaunay_triangulation::Vertex_handle Vertex_handle;
typedef CGAL::Interpolation_traits_2<K> Traits;
typedef std::vector< std::pair<Point, Coord_type> > Coordinate_vector;
template <typename V, typename T>
struct Function_value {
struct Function_value
{
typedef V argument_type;
typedef std::pair<T, bool> result_type;
result_type operator()(const argument_type& a)const
{
result_type operator()(const argument_type& a) const {
return result_type(a->info().value, true);
}
};
template <typename V, typename G>
struct Function_gradient
: public std::iterator<std::output_iterator_tag,void,void,void,void> {
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
typedef V argument_type;
typedef std::pair<G,bool> result_type;
typedef std::pair<G, bool> result_type;
result_type
operator()(const argument_type& a)const
{
return std::make_pair(a->info().gradient,a->info().gradient != CGAL::NULL_VECTOR) ;
result_type operator()(const argument_type& a) const {
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
}
const Function_gradient& operator=(const std::pair<V, G>& p) const
{
const Function_gradient& operator=(const std::pair<V, G>& p) const {
p.first->info().gradient = p.second;
return *this;
}
const Function_gradient& operator++(int) const
{
return *this;
}
const Function_gradient& operator*() const
{
return *this;
}
const Function_gradient& operator++(int) const { return *this; }
const Function_gradient& operator*() const { return *this; }
};
int main()
@ -103,13 +89,13 @@ int main()
// Create n+m-4 points within a disc of radius 2
double r_d = 3;
CGAL::Random rng(1513114263);
CGAL::Random_points_in_disc_2<Point> g(r_d,rng );
CGAL::Random_points_in_disc_2<Point> g(r_d, rng);
CGAL::cpp11::copy_n( g, n+m, std::back_inserter(points));
Delaunay_triangulation T;
Function_value<Vertex_handle,Coord_type> function_value;
Function_gradient<Vertex_handle,Vector> function_gradient;
Function_value<Vertex_handle, Coord_type> function_value;
Function_gradient<Vertex_handle, Vector> function_gradient;
//parameters for quadratic function:
Coord_type alpha = Coord_type(1.0),
@ -120,7 +106,8 @@ int main()
gamma3 = Coord_type(0.0),
gamma4 = Coord_type(0.3);
for(int j=0; j<n ; j++){
for(int j=0; j<n ; j++)
{
Vertex_handle vh = T.insert(points[j]);
//determine function value/gradient:
@ -129,8 +116,8 @@ int main()
Coord_type value = alpha + beta1*x + beta2*y + gamma1*(x*x) +
gamma4*(y*y) + (gamma2+ gamma3) *(x*y);
Vector gradient(beta1+ (gamma2+ gamma3)*y + Coord_type(2)*(gamma1*x),
beta2+ (gamma2+ gamma3)*x + Coord_type(2)*(gamma4*y));
Vector gradient(beta1+ (gamma2 + gamma3)*y + Coord_type(2)*(gamma1*x),
beta2+ (gamma2 + gamma3)*x + Coord_type(2)*(gamma4*y));
vh->info().value = value;
vh->info().gradient = gradient;
}
@ -146,7 +133,8 @@ int main()
int failure(0);
//interpolation + error statistics
for(int i=n;i<n+m;i++){
for(int i=n; i<n+m; i++)
{
Coord_type x(points[i].x());
Coord_type y(points[i].y());
@ -155,32 +143,23 @@ int main()
total_value += exact_value;
//Coordinate_vector:
std::vector< std::pair< Vertex_handle, Coord_type > > coords;
typedef CGAL::Identity<std::pair< Vertex_handle, Coord_type > > Identity;
Coord_type norm =
CGAL::natural_neighbor_coordinates_2(T,
std::vector< std::pair<Vertex_handle, Coord_type> > coords;
typedef CGAL::Identity<std::pair< Vertex_handle, Coord_type> > Identity;
Coord_type norm = CGAL::natural_neighbor_coordinates_2(T,
points[i],
std::back_inserter(coords),
Identity()).second;
assert(norm>0);
assert(norm > 0);
//linear interpolant:
l_value =
CGAL::linear_interpolation(coords.begin(), coords.end(),
norm,
function_value);
l_value = CGAL::linear_interpolation(coords.begin(), coords.end(),
norm, function_value);
error = CGAL_NTS abs(l_value - exact_value);
l_total += error;
if (error > l_max) l_max = error;
//Farin interpolant:
res = CGAL::farin_c1_interpolation(coords.begin(),
coords.end(), norm,points[i],
@ -189,25 +168,36 @@ int main()
Traits());
if(res.second){
if(res.second)
{
error = CGAL_NTS abs(res.first - exact_value);
f_total += error;
if (error > f_max) f_max = error;
} else ++failure;
if (error > f_max)
f_max = error;
}
else
{
++failure;
}
//quadratic interpolant:
res = CGAL::quadratic_interpolation(coords.begin(), coords.end(),
norm,points[i],
norm, points[i],
function_value,
function_gradient,
Traits());
if(res.second){
if(res.second)
{
error = CGAL_NTS abs(res.first - exact_value);
q_total += error;
if (error > q_max) q_max = error;
} else ++failure;
if (error > q_max)
q_max = error;
}
else
{
++failure;
}
//Sibson interpolant: version without sqrt:
res = CGAL::sibson_c1_interpolation_square(coords.begin(),
@ -217,11 +207,17 @@ int main()
function_gradient,
Traits());
//error statistics
if(res.second){
if(res.second)
{
error = CGAL_NTS abs(res.first - exact_value);
ssquare_total += error;
if (error > ssquare_max) ssquare_max = error;
} else ++failure;
if (error > ssquare_max)
ssquare_max = error;
}
else
{
++failure;
}
//with sqrt(the traditional):
res = CGAL::sibson_c1_interpolation(coords.begin(),
@ -232,15 +228,18 @@ int main()
Traits());
//error statistics
if(res.second){
if(res.second)
{
error = CGAL_NTS abs(res.first - exact_value);
s_total += error;
if (error > s_max) s_max = error;
} else ++failure;
if (error > s_max)
s_max = error;
}
else
{
++failure;
}
}
/************** end of Interpolation: dump statistics **************/
std::cout << "Result: -----------------------------------" << std::endl;
@ -270,7 +269,5 @@ int main()
<< CGAL::to_double(ssquare_total)/n << " max "
<< CGAL::to_double(ssquare_max) << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -14,34 +14,31 @@ typedef K::Point_2 Point;
int main()
{
Delaunay_triangulation T;
std::map<Point, Coord_type, K::Less_xy_2> function_values;
typedef CGAL::Data_access< std::map<Point, Coord_type, K::Less_xy_2 > >
Value_access;
typedef std::map<Point, Coord_type, K::Less_xy_2> Coord_map;
typedef CGAL::Data_access<Coord_map> Value_access;
Coord_map function_values;
Coord_type a(0.25), bx(1.3), by(-0.7);
for (int y=0 ; y<3 ; y++){
for (int x=0 ; x<3 ; x++){
K::Point_2 p(x,y);
T.insert(p);
function_values.insert(std::make_pair(p,a + bx* x+ by*y));
function_values.insert(std::make_pair(p, a + bx*x + by*y));
}
}
//coordinate computation
K::Point_2 p(1.3,0.34);
std::vector< std::pair< Point, Coord_type > > coords;
Coord_type norm =
CGAL::natural_neighbor_coordinates_2
(T, p,std::back_inserter(coords)).second;
K::Point_2 p(1.3, 0.34);
std::vector<std::pair<Point, Coord_type> > coords;
Coord_type res = CGAL::linear_interpolation(coords.begin(), coords.end(),
norm,
Coord_type norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second;
Coord_type res = CGAL::linear_interpolation(coords.begin(), coords.end(), norm,
Value_access(function_values));
std::cout << "Tested interpolation on " << p << " interpolation: "
<< res << " exact: " << a + bx* p.x()+ by* p.y()<< std::endl;
<< res << " exact: " << a + bx*p.x() + by*p.y() << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -1,36 +1,40 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_2.h>
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay_triangulation;
typedef std::vector< std::pair< K::Point_2, K::FT > > Point_coordinate_vector;
typedef std::vector< std::pair<K::Point_2, K::FT> > Point_coordinate_vector;
int main()
{
Delaunay_triangulation dt;
for (int y=0 ; y<3 ; y++)
for (int x=0 ; x<3 ; x++)
dt.insert(K::Point_2(x,y));
for (int y=0; y<3; y++)
for (int x=0; x<3; x++)
dt.insert(K::Point_2(x, y));
//coordinate computation
K::Point_2 p(1.2, 0.7);
Point_coordinate_vector coords;
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>,
K::FT, bool> result =
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, K::FT, bool> result =
CGAL::natural_neighbor_coordinates_2(dt, p, std::back_inserter(coords));
if(!result.third){
std::cout << "The coordinate computation was not successful."
<< std::endl;
std::cout << "The point (" <<p << ") lies outside the convex hull."
<< std::endl;
if(!result.third)
{
std::cout << "The coordinate computation was not successful." << std::endl;
std::cout << "The point (" << p << ") lies outside the convex hull." << std::endl;
}
K::FT norm = result.second;
std::cout << "Coordinate computation successful." << std::endl;
std::cout << "Normalization factor: " <<norm << std::endl;
std::cout << "done" << std::endl;
return 0;
std::cout << "Normalization factor: " << norm << std::endl;
return EXIT_SUCCESS;
}

View File

@ -1,7 +1,13 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Delaunay_triangulation_3.h>
#include <CGAL/natural_neighbor_coordinates_3.h>
#include <fstream>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
typedef double NT; //Number Type
@ -35,11 +41,11 @@ int main()
Point3 pp[3];
std::cout << "Consider the natural coordinates of P1, P2 and P3 with regard to the triangulation of data/points3 " << std::endl;
pp[0]=Point3(106.55,112.57,110.4); //inside data/points3 convex hull
pp[0] = Point3(106.55,112.57,110.4); //inside data/points3 convex hull
std::cout << "P1 is inside the convex hull" << std::endl;
pp[1]=Point3(250,100,140); //on data/points3 convex hull
pp[1] = Point3(250,100,140); //on data/points3 convex hull
std::cout << "P2 is on a vertex of the triangulation" << std::endl;
pp[2]=Point3(0,0,0); //outside data/points3 convex hull
pp[2] = Point3(0,0,0); //outside data/points3 convex hull
std::cout << "P2 is outside the convex hull" << std::endl;
for(int ii=0; ii<3; ++ii)
@ -48,7 +54,7 @@ int main()
std::vector< std::pair< Vertex_handle,NT> > coor_sibson;
NT norm_coeff_laplace, norm_coeff_sibson;
std::cout << "Point P"<< ii+1 << " : "<<pp[ii].x() << " "
std::cout << "Point P" << ii+1 << " : " << pp[ii].x() << " "
<< pp[ii].y() << " "
<< pp[ii].z() << std::endl;
@ -67,6 +73,7 @@ int main()
sibson_natural_neighbor_coordinates_3(triangulation,pp[ii],
std::back_inserter(coor_sibson),
norm_coeff_sibson);
std::cout << "Linear combination of natural neighbors with Sibson natural coordinates" << std::endl;
std::cout << " + correctness (ensured only with an exact number type)" << std::endl;
std::cout << is_correct_natural_neighborhood(triangulation,pp[ii],
@ -76,6 +83,5 @@ int main()
<< std::endl;
}
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -1,40 +1,42 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_2.h>
#include <CGAL/regular_neighbor_coordinates_2.h>
#include <iostream>
#include <iterator>
#include <vector>
#include <utility>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Regular_triangulation_2<K> Regular_triangulation;
typedef Regular_triangulation::Bare_point Bare_point;
typedef Regular_triangulation::Weighted_point Weighted_point;
typedef std::vector< std::pair< Weighted_point, K::FT > > Point_coordinate_vector;
typedef std::vector<std::pair<Weighted_point, K::FT> > Point_coordinate_vector;
int main()
{
Regular_triangulation rt;
for (int y=0 ; y<3 ; y++)
for (int x=0 ; x<3 ; x++)
for (int y=0; y<3; y++)
for (int x=0; x<3; x++)
rt.insert(Weighted_point(Bare_point(x,y), 0));
//coordinate computation
Weighted_point wp(Bare_point(1.2, 0.7),2);
Weighted_point wp(Bare_point(1.2, 0.7), 2);
Point_coordinate_vector coords;
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>,
K::FT, bool> result =
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, K::FT, bool> result =
CGAL::regular_neighbor_coordinates_2(rt, wp, std::back_inserter(coords));
if(!result.third){
std::cout << "The coordinate computation was not successful."
<< std::endl;
std::cout << "The point (" <<wp.point() << ") lies outside the convex hull."
<< std::endl;
std::cout << "The coordinate computation was not successful." << std::endl;
std::cout << "The point (" <<wp.point() << ") lies outside the convex hull." << std::endl;
}
K::FT norm = result.second;
std::cout << "Coordinate computation successful." << std::endl;
std::cout << "Normalization factor: " <<norm << std::endl;
std::cout << "Normalization factor: " << norm << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -6,6 +6,12 @@
#include <CGAL/sibson_gradient_fitting.h>
#include <CGAL/interpolation_functions.h>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Delaunay_triangulation_2<K> Delaunay_triangulation;
typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
@ -13,7 +19,7 @@ typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
typedef K::FT Coord_type;
typedef K::Point_2 Point;
typedef std::map<Point, Coord_type, K::Less_xy_2> Point_value_map ;
typedef std::map<Point, K::Vector_2 , K::Less_xy_2 > Point_vector_map;
typedef std::map<Point, K::Vector_2 , K::Less_xy_2> Point_vector_map;
int main()
{
@ -24,15 +30,15 @@ int main()
//parameters for spherical function:
Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2);
for (int y=0 ; y<4 ; y++){
for (int x=0 ; x<4 ; x++){
for (int y=0; y<4; y++) {
for (int x=0; x<4; x++) {
K::Point_2 p(x,y);
T.insert(p);
function_values.insert(std::make_pair(p,a + bx* x+ by*y + c*(x*x+y*y)));
}
}
sibson_gradient_fitting_nn_2(T,std::inserter(function_gradients,
sibson_gradient_fitting_nn_2(T, std::inserter(function_gradients,
function_gradients.begin()),
CGAL::Data_access<Point_value_map>(function_values),
Traits());
@ -41,8 +47,8 @@ int main()
{
std::cout << it->first << " " << it->second << std::endl;
}
//coordinate computation
K::Point_2 p(1.6,1.4);
// coordinate computation
K::Point_2 p(1.6, 1.4);
std::vector< std::pair< Point, Coord_type > > coords;
Coord_type norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter
(coords)).second;
@ -50,8 +56,7 @@ int main()
//Sibson interpolant: version without sqrt:
std::pair<Coord_type, bool> res =
CGAL::sibson_c1_interpolation_square(
coords.begin(),
CGAL::sibson_c1_interpolation_square(coords.begin(),
coords.end(),norm,p,
CGAL::Data_access<Point_value_map>(function_values),
CGAL::Data_access<Point_vector_map>(function_gradients),
@ -60,13 +65,12 @@ int main()
if(res.second)
std::cout << "Tested interpolation on " << p
<< " interpolation: " << res.first << " exact: "
<< a + bx * p.x()+ by * p.y()+ c*(p.x()*p.x()+p.y()*p.y())
<< a + bx*p.x() + by*p.y() + c*(p.x()*p.x()+p.y()*p.y())
<< std::endl;
else
std::cout << "C^1 Interpolation not successful." << std::endl
<< " not all function_gradients are provided." << std::endl
<< " You may resort to linear interpolation." << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -1,11 +1,18 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Regular_triangulation_2.h>
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/Interpolation_gradient_fitting_traits_2.h>
#include <CGAL/sibson_gradient_fitting.h>
#include <CGAL/interpolation_functions.h>
#include <CGAL/Regular_triangulation_2.h>
#include <iostream>
#include <iterator>
#include <map>
#include <utility>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Regular_triangulation_2<K> Regular_triangulation;
typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
@ -13,16 +20,15 @@ typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
typedef K::FT Coord_type;
typedef K::Weighted_point_2 Point;
struct Less {
bool operator()(const Point& p, const Point& q) const
{
struct Less
{
bool operator()(const Point& p, const Point& q) const {
return K::Less_xy_2()(p.point(), q.point());
}
};
typedef std::map<Point, Coord_type, Less> Point_value_map ;
typedef std::map<Point, K::Vector_2 , Less > Point_vector_map;
typedef std::map<Point, K::Vector_2 , Less> Point_vector_map;
int main()
{
@ -33,11 +39,11 @@ int main()
//parameters for spherical function:
Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2);
for (int y=0 ; y<4 ; y++){
for (int x=0 ; x<4 ; x++){
for (int y=0; y<4; y++) {
for (int x=0; x<4; x++) {
Point p(x,y);
T.insert(p);
function_values.insert(std::make_pair(p,a + bx* x+ by*y + c*(x*x+y*y)));
function_values.insert(std::make_pair(p, a + bx*x + by*y + c*(x*x+y*y)));
}
}
@ -46,22 +52,21 @@ int main()
CGAL::Data_access<Point_value_map>(function_values),
Traits());
for(Point_vector_map::iterator it = function_gradients.begin(); it != function_gradients.end(); ++it)
{
for(Point_vector_map::iterator it = function_gradients.begin();
it != function_gradients.end(); ++it) {
std::cout << it->first << " " << it->second << std::endl;
}
//coordinate computation
Point p(1.6,1.4);
std::vector< std::pair< Point, Coord_type > > coords;
Coord_type norm = CGAL::regular_neighbor_coordinates_2(T, p, std::back_inserter
(coords)).second;
//coordinate computation
Point p(1.6, 1.4);
std::vector<std::pair<Point, Coord_type> > coords;
Coord_type norm = CGAL::regular_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second;
//Sibson interpolant: version without sqrt:
std::pair<Coord_type, bool> res =
CGAL::sibson_c1_interpolation_square(
coords.begin(),
coords.end(),norm,p,
std::pair<Coord_type, bool> res = CGAL::sibson_c1_interpolation_square(coords.begin(),
coords.end(),
norm,
p,
CGAL::Data_access<Point_value_map>(function_values),
CGAL::Data_access<Point_vector_map>(function_gradients),
Traits());
@ -69,13 +74,12 @@ int main()
if(res.second)
std::cout << "Tested interpolation on " << p
<< " interpolation: " << res.first << " exact: "
<< a + bx * p.x()+ by * p.y()+ c*(p.x()*p.x()+p.y()*p.y())
<< a + bx*p.x() + by*p.y()+ c*(p.x()*p.x()+p.y()*p.y())
<< std::endl;
else
std::cout << "C^1 Interpolation not successful." << std::endl
<< " not all function_gradients are provided." << std::endl
<< " You may resort to linear interpolation." << std::endl;
std::cout << "done" << std::endl;
return 0;
}

View File

@ -1,12 +1,18 @@
#include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Regular_triangulation_2.h>
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/Interpolation_gradient_fitting_traits_2.h>
#include <CGAL/sibson_gradient_fitting.h>
#include <CGAL/interpolation_functions.h>
#include <CGAL/Triangulation_vertex_base_with_info_2.h>
#include <CGAL/Regular_triangulation_2.h>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
@ -15,81 +21,67 @@ typedef K::Weighted_point_2 Point;
typedef K::Vector_2 Vector;
template <typename V, typename G>
struct Value_and_gradient {
Value_and_gradient()
: value(), gradient(CGAL::NULL_VECTOR)
{}
struct Value_and_gradient
{
Value_and_gradient() : value(), gradient(CGAL::NULL_VECTOR) {}
V value;
G gradient;
};
typedef CGAL::Triangulation_vertex_base_with_info_2<Value_and_gradient<Coord_type,Vector>, K, CGAL::Regular_triangulation_vertex_base_2<K> > Vb;
typedef CGAL::Triangulation_vertex_base_with_info_2<
Value_and_gradient<Coord_type, Vector>, K,
CGAL::Regular_triangulation_vertex_base_2<K> > Vb;
typedef CGAL::Regular_triangulation_face_base_2<K> Fb;
typedef CGAL::Triangulation_data_structure_2<Vb,Fb> Tds;
typedef CGAL::Regular_triangulation_2<K,Tds> Regular_triangulation;
typedef CGAL::Triangulation_data_structure_2<Vb, Fb> Tds;
typedef CGAL::Regular_triangulation_2<K, Tds> Regular_triangulation;
typedef Regular_triangulation::Vertex_handle Vertex_handle;
template <typename V, typename T>
struct Function_value {
struct Function_value
{
typedef V argument_type;
typedef std::pair<T, bool> result_type;
result_type operator()(const argument_type& a)const
{
result_type operator()(const argument_type& a) const {
return result_type(a->info().value, true);
}
};
template <typename V, typename G>
struct Function_gradient
: public std::iterator<std::output_iterator_tag,void,void,void,void> {
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
typedef V argument_type;
typedef std::pair<G,bool> result_type;
typedef std::pair<G, bool> result_type;
result_type
operator()(const argument_type& a)const
{
return std::make_pair(a->info().gradient,a->info().gradient != CGAL::NULL_VECTOR) ;
result_type operator()(const argument_type& a) const {
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
}
const Function_gradient& operator=(const std::pair<V, G>& p) const
{
const Function_gradient& operator=(const std::pair<V, G>& p) const {
p.first->info().gradient = p.second;
return *this;
}
const Function_gradient& operator++(int) const
{
return *this;
}
const Function_gradient& operator*() const
{
return *this;
}
const Function_gradient& operator++(int) const { return *this; }
const Function_gradient& operator*() const { return *this; }
};
int main()
{
Regular_triangulation rt;
Function_value<Vertex_handle,Coord_type> function_value;
Function_gradient<Vertex_handle,Vector> function_gradient;
Function_value<Vertex_handle, Coord_type> function_value;
Function_gradient<Vertex_handle, Vector> function_gradient;
//parameters for spherical function:
Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2);
for (int y=0 ; y<4 ; y++){
for (int x=0 ; x<4 ; x++){
for (int y=0; y<4; y++) {
for (int x=0; x<4; x++) {
Point p(x,y);
Vertex_handle vh = rt.insert(p);
Coord_type value = a + bx* x+ by*y + c*(x*x+y*y);
Coord_type value = a + bx*x + by*y + c*(x*x+y*y);
vh->info().value = value;
}
}
@ -99,16 +91,16 @@ int main()
function_value,
CGAL::Identity<std::pair<Vertex_handle, Vector> >(),
Traits());
//coordinate computation
Point p(1.6,1.4);
std::vector< std::pair< Vertex_handle, Coord_type > > coords;
typedef CGAL::Identity<std::pair< Vertex_handle, Coord_type > > Identity;
std::vector<std::pair<Vertex_handle, Coord_type> > coords;
typedef CGAL::Identity<std::pair<Vertex_handle, Coord_type> > Identity;
Coord_type norm = CGAL::regular_neighbor_coordinates_2(rt,
p,
std::back_inserter(coords),
Identity()).second;
//Sibson interpolant: version without sqrt:
std::pair<Coord_type, bool> res = CGAL::sibson_c1_interpolation_square(coords.begin(),
coords.end(),
@ -128,6 +120,5 @@ int main()
<< " not all function_gradients are provided." << std::endl
<< " You may resort to linear interpolation." << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -7,6 +7,11 @@
#include <CGAL/sibson_gradient_fitting.h>
#include <CGAL/interpolation_functions.h>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>
typedef CGAL::Exact_predicates_inexact_constructions_kernel K;
typedef CGAL::Interpolation_gradient_fitting_traits_2<K> Traits;
@ -15,77 +20,62 @@ typedef K::Point_2 Point;
typedef K::Vector_2 Vector;
template <typename V, typename G>
struct Value_and_gradient {
Value_and_gradient()
: value(), gradient(CGAL::NULL_VECTOR)
{}
struct Value_and_gradient
{
Value_and_gradient() : value(), gradient(CGAL::NULL_VECTOR) {}
V value;
G gradient;
};
typedef CGAL::Triangulation_vertex_base_with_info_2<Value_and_gradient<Coord_type,Vector>, K> Vb;
typedef CGAL::Triangulation_vertex_base_with_info_2<
Value_and_gradient<Coord_type, Vector>, K> Vb;
typedef CGAL::Triangulation_data_structure_2<Vb> Tds;
typedef CGAL::Delaunay_triangulation_2<K,Tds> Delaunay_triangulation;
typedef Delaunay_triangulation::Vertex_handle Vertex_handle;
template <typename V, typename T>
struct Function_value {
struct Function_value
{
typedef V argument_type;
typedef std::pair<T, bool> result_type;
result_type operator()(const argument_type& a)const
{
result_type operator()(const argument_type& a) const {
return result_type(a->info().value, true);
}
};
template <typename V, typename G>
struct Function_gradient
: public std::iterator<std::output_iterator_tag,void,void,void,void> {
: public std::iterator<std::output_iterator_tag, void, void, void, void>
{
typedef V argument_type;
typedef std::pair<G,bool> result_type;
typedef std::pair<G, bool> result_type;
result_type
operator()(const argument_type& a)const
{
return std::make_pair(a->info().gradient,a->info().gradient != CGAL::NULL_VECTOR) ;
result_type operator()(const argument_type& a) const {
return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR);
}
const Function_gradient& operator=(const std::pair<V, G>& p) const
{
const Function_gradient& operator=(const std::pair<V, G>& p) const {
p.first->info().gradient = p.second;
return *this;
}
const Function_gradient& operator++(int) const
{
return *this;
}
const Function_gradient& operator*() const
{
return *this;
}
const Function_gradient& operator++(int) const { return *this; }
const Function_gradient& operator*() const { return *this; }
};
int main()
{
Delaunay_triangulation dt;
Function_value<Vertex_handle,Coord_type> function_value;
Function_gradient<Vertex_handle,Vector> function_gradient;
Function_value<Vertex_handle, Coord_type> function_value;
Function_gradient<Vertex_handle, Vector> function_gradient;
//parameters for spherical function:
Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2);
for (int y=0 ; y<4 ; y++){
for (int x=0 ; x<4 ; x++){
for (int y=0 ; y<4 ; y++) {
for (int x=0 ; x<4 ; x++) {
K::Point_2 p(x,y);
Vertex_handle vh = dt.insert(p);
Coord_type value = a + bx* x+ by*y + c*(x*x+y*y);
@ -100,15 +90,14 @@ int main()
Traits());
//coordinate computation
K::Point_2 p(1.6,1.4);
std::vector< std::pair< Vertex_handle, Coord_type > > coords;
typedef CGAL::Identity<std::pair< Vertex_handle, Coord_type > > Identity;
K::Point_2 p(1.6, 1.4);
std::vector<std::pair<Vertex_handle, Coord_type> > coords;
typedef CGAL::Identity<std::pair< Vertex_handle, Coord_type> > Identity;
Coord_type norm = CGAL::natural_neighbor_coordinates_2(dt,
p,
std::back_inserter(coords),
Identity()).second;
//Sibson interpolant: version without sqrt:
std::pair<Coord_type, bool> res = CGAL::sibson_c1_interpolation_square(coords.begin(),
coords.end(),
@ -121,13 +110,12 @@ int main()
if(res.second)
std::cout << "Tested interpolation on " << p
<< " interpolation: " << res.first << " exact: "
<< a + bx * p.x()+ by * p.y()+ c*(p.x()*p.x()+p.y()*p.y())
<< a + bx*p.x() + by*p.y() + c*(p.x()*p.x() + p.y()*p.y())
<< std::endl;
else
std::cout << "C^1 Interpolation not successful." << std::endl
<< " not all function_gradients are provided." << std::endl
<< " You may resort to linear interpolation." << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -20,7 +20,7 @@ typedef std::vector< std::pair< Point_3, K::FT > > Point_coordinate_ve
int main()
{
int n=100;
int n = 100;
std::vector< Point_3> points;
points.reserve(n);
@ -28,32 +28,32 @@ int main()
CGAL::Random_points_on_sphere_3<Point_3> g(1);
CGAL::cpp11::copy_n(g, n, std::back_inserter(points));
Point_3 p(1, 0,0);
Point_3 p(1, 0, 0);
Vector_3 normal(p - CGAL::ORIGIN);
std::cout << "Compute surface neighbor coordinates for " << p << std::endl;
Point_coordinate_vector coords;
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>,
K::FT, bool> result =
CGAL::Triple<std::back_insert_iterator<Point_coordinate_vector>, K::FT, bool> result =
CGAL::surface_neighbor_coordinates_3(points.begin(), points.end(),
p, normal,
std::back_inserter(coords),
K());
if(!result.third){
if(!result.third)
{
//Undersampling:
std::cout << "The coordinate computation was not successful." << std::endl;
return 0;
}
K::FT norm = result.second;
std::cout << "Testing the barycentric property " << std::endl;
Point_3 b(0, 0, 0);
for(std::vector< std::pair< Point_3, Coord_type > >::const_iterator
it = coords.begin(); it!=coords.end(); ++it)
b = b + (it->second/norm)* (it->first - CGAL::ORIGIN);
b = b + (it->second/norm) * (it->first - CGAL::ORIGIN);
std::cout << " weighted barycenter: " << b <<std::endl;
std::cout << " squared distance: " << CGAL::squared_distance(p,b) << std::endl;
std::cout << "done" << std::endl;
return 0;
return EXIT_SUCCESS;
}

View File

@ -1,4 +1,4 @@
// Copyright (c) 2003,2017 INRIA Sophia-Antipolis (France).
// Copyright (c) 2003, 2017 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
@ -23,14 +23,13 @@
#include <CGAL/license/Interpolation.h>
namespace CGAL {
namespace Interpolation {
namespace internal {
template < class InterpolationTraits>
struct V2P
{
template < class InterpolationTraits >
struct V2P
{
typedef typename InterpolationTraits::Point_d Point;
typedef typename InterpolationTraits::Weighted_point_d Weighted_point;
@ -54,13 +53,14 @@ namespace internal {
return traits.construct_point_d_object()(wp);
}
private:
private:
InterpolationTraits traits;
};
};
template < typename Dt, typename T2>
struct Vertex2Point {
template < typename Dt, typename T2 >
struct Vertex2Point
{
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Point Point;
@ -71,10 +71,12 @@ namespace internal {
{
return std::make_pair(vp.first->point(), vp.second);
}
};
};
template < typename Dt, typename T2>
struct Vertex2WPoint {
template < typename Dt, typename T2 >
struct Vertex2WPoint
{
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Weighted_point Point;
@ -85,15 +87,16 @@ namespace internal {
{
return std::make_pair(vp.first->point(), vp.second);
}
};
};
template <typename Dt, typename Map>
struct Vertex2Vertex {
template < typename Dt, typename Map >
struct Vertex2Vertex
{
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Geom_traits::FT FT;
typedef std::pair<Vertex_handle,FT> argument_type;
typedef std::pair<Vertex_handle,FT> result_type;
typedef std::pair<Vertex_handle, FT> argument_type;
typedef std::pair<Vertex_handle, FT> result_type;
const Map& map;
const Dt& dt;
@ -109,18 +112,19 @@ namespace internal {
CGAL_assertion(dt.tds().is_vertex(it->second));
return std::make_pair(it->second, vp.second);
}
};
};
// the struct "Project_vertex_output_iterator"
// is used in the (next two) functions
// as well as in regular_neighbor_coordinates_2 and
// in surface_neighbor_coordinates_3
//
//projection of iterator over std::pair <Vertex_handle, T>
//to iterator over std::pair< Point, T>
template < class OutputIterator, class Fct = void>
struct Project_vertex_output_iterator
{
// the struct "Project_vertex_output_iterator"
// is used in the (next two) functions
// as well as in regular_neighbor_coordinates_2 and
// in surface_neighbor_coordinates_3
//
//projection of iterator over std::pair <Vertex_handle, T>
//to iterator over std::pair< Point, T>
template < class OutputIterator, class Fct = void >
struct Project_vertex_output_iterator
{
// this class wraps the OutputIterator with value type
// std::pair<Vertex_handle,T>
// into an output iterator with value type std::pair<Point, T>
@ -143,13 +147,12 @@ namespace internal {
Project_vertex_output_iterator& operator*(){return *this;}
template<class Vertex_pair>
Project_vertex_output_iterator&
operator=(const Vertex_pair& vp){
Project_vertex_output_iterator& operator=(const Vertex_pair& vp)
{
*_base = fct(vp);
return *this;
}
};
};
} // namespace internal
} // namespace Interpolation

View File

@ -163,16 +163,16 @@ public:
Comparison_result operator()(const Point& p, const Point& q) const
{
if(normal.x()!=Coord_type(0))
if(normal.x() != Coord_type(0))
return (Comparison_result) CGAL_NTS
sign(Vector(normal.y(),-normal.x(),Coord_type(0))*(p-q));
if(normal.y()!= Coord_type(0))
sign(Vector(normal.y(), -normal.x(), Coord_type(0))*(p-q));
if(normal.y() != Coord_type(0))
return (Comparison_result) CGAL_NTS
sign(Vector(-normal.y(),normal.x(),Coord_type(0))*(p-q));
sign(Vector(-normal.y(), normal.x(), Coord_type(0))*(p-q));
CGAL_assertion(normal.z()!= Coord_type(0));
CGAL_assertion(normal.z() != Coord_type(0));
return (Comparison_result) CGAL_NTS
sign(Vector(-normal.z(),Coord_type(0),normal.x())*(p-q));
sign(Vector(-normal.z(), Coord_type(0), normal.x())*(p-q));
}
private:
@ -195,16 +195,16 @@ public:
Comparison_result operator()(const Point& p, const Point& q) const
{
if(normal.x()!=Coord_type(0))
if(normal.x() != Coord_type(0))
return (Comparison_result) CGAL_NTS
sign(Vector(normal.z(),Coord_type(0),-normal.x())*(p-q));
if(normal.y()!= Coord_type(0))
sign(Vector(normal.z(), Coord_type(0), -normal.x())*(p-q));
if(normal.y() != Coord_type(0))
return (Comparison_result) CGAL_NTS
sign(Vector(Coord_type(0),normal.z(),-normal.y())*(p-q));
sign(Vector(Coord_type(0), normal.z(), -normal.y())*(p-q));
CGAL_assertion(normal.z()!= Coord_type(0));
CGAL_assertion(normal.z() != Coord_type(0));
return (Comparison_result) CGAL_NTS
sign(Vector(Coord_type(0),-normal.z(),normal.y())*(p-q));
sign(Vector(Coord_type(0), -normal.z(), normal.y())*(p-q));
}
private:

View File

@ -22,19 +22,21 @@
#define CGAL_NATURAL_NEIGHBOR_COORDINATES_2_H
#include <CGAL/license/Interpolation.h>
#include <CGAL/Interpolation/internal/helpers.h>
#include <CGAL/Iterator_project.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/number_utils_classes.h>
#include <CGAL/utility.h>
#include <iterator>
#include <list>
#include <utility>
#include <vector>
namespace CGAL {
// The following natural_neighbor_coordinate_2 functions fix the
// traits class to be Dt::Geom_traits. The following signatures could
// be used if one wants to pass a traits class as argument:
@ -60,8 +62,8 @@ template < class Dt, class OutputIterator >
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool >
natural_neighbors_2(const Dt& dt,
const typename Dt::Geom_traits::Point_2& p,
OutputIterator out, typename Dt::Face_handle start
= typename Dt::Face_handle())
OutputIterator out,
typename Dt::Face_handle start = typename Dt::Face_handle())
{
typedef typename Dt::Geom_traits Traits;
typedef typename Traits::FT Coord_type;
@ -102,7 +104,7 @@ natural_neighbors_2(const Dt& dt,
*out++ = std::make_pair(v2,coef2);
} else {
coef1 = (p.y() - p2.y()) / (p1.y() - p2.y());
coef2 = 1-coef1;
coef2 = 1 - coef1;
*out++ = std::make_pair(v1,coef1);
*out++ = std::make_pair(v2,coef2);
}
@ -148,6 +150,7 @@ natural_neighbors_2(const Dt& dt,
Coord_type area_sum(0);
EdgeIterator hit = hole_end;
--hit;
//in the beginning: prev is the "last" vertex of the hole:
// later: prev is the last vertex processed (previously)
Vertex_handle prev = hit->first->vertex(dt.cw(hit->second));
@ -205,8 +208,7 @@ natural_neighbor_coordinates_2(const Dt& dt,
Interpolation::internal::Project_vertex_output_iterator<OutputIterator, Fct> op(out, fct);
Triple<Interpolation::internal::Project_vertex_output_iterator<OutputIterator,Fct>,
typename Dt::Geom_traits::FT, bool > result =
natural_neighbors_2(dt, p, op, start);
typename Dt::Geom_traits::FT, bool > result = natural_neighbors_2(dt, p, op, start);
return make_triple(result.first.base(), result.second, result.third);
}
@ -255,6 +257,7 @@ natural_neighbor_coordinates_2(const Dt& dt,
return make_triple(result.first.base(), result.second, result.third);
}
//OutputIterator has value type
// std::pair< Dt::Geom_traits::Point_2, Dt::Geom_traits::FT>
//function call if the conflict zone is known:
@ -270,6 +273,7 @@ natural_neighbor_coordinates_2(const Dt& dt,
Interpolation::internal::Vertex2Point<Dt, typename Dt::Geom_traits::FT>());
}
/**********************************************************/
//compute the coordinates for a vertex of the triangulation
// with respect to the other points in the triangulation
@ -340,7 +344,6 @@ public:
}
};
} //namespace CGAL
#endif // CGAL_NATURAL_NEIGHBOR_COORDINATES_2_H

View File

@ -108,23 +108,25 @@ laplace_natural_neighbor_coordinates_3(const Dt& dt,
std::set<Cell_handle> cells;
// To replace the forbidden access to the "in conflict" flag :
// std::find operations on this set
std::vector<Facet> bound_facets; bound_facets.reserve(32);
typename std::vector<Facet>::iterator bound_it;
std::vector<Facet> bound_facets;
bound_facets.reserve(32);
// Find the cells in conflict with Q
dt.find_conflicts(Q, c,
std::back_inserter(bound_facets),
std::inserter(cells,cells.begin()));
std::inserter(cells, cells.begin()));
std::map<Vertex_handle,Coord_type> coordinate;
typename std::map<Vertex_handle,Coord_type>::iterator coor_it;
typename std::vector<Facet>::iterator bound_it;
for (bound_it = bound_facets.begin(); bound_it != bound_facets.end(); ++bound_it)
{
//for each facet on the boundary
Facet f1 = *bound_it;
Cell_handle cc1 = f1.first;
if (dt.is_infinite(cc1))
return make_triple(nn_out,norm_coeff=Coord_type(1), false);//point outside the convex-hull
return make_triple(nn_out, norm_coeff=Coord_type(1), false);//point outside the convex-hull
CGAL_triangulation_assertion_code(Cell_handle cc2 = cc1->neighbor(f1.second);)
CGAL_triangulation_assertion(std::find(cells.begin(),cells.end(),cc1) != cells.end());//TODO : Delete

View File

@ -120,8 +120,7 @@ regular_neighbor_coordinates_vertex_2(const Rt& rt,
rt.get_boundary_of_conflicts_and_hidden_vertices(p,
std::back_inserter(hole),
std::back_inserter
(hidden_vertices),
std::back_inserter(hidden_vertices),
fh);
return regular_neighbor_coordinates_vertex_2(rt, p, out, vor_vertices,
hole.begin(),hole.end(),
@ -217,6 +216,7 @@ regular_neighbor_coordinates_vertex_2(const Rt& rt,
area += polygon_area_2(vor.begin(), vor.end(), rt.geom_traits());
vor[1] = vor[2];
}
//the second Voronoi vertex of the cell of p:
vor[2] =
rt.geom_traits().construct_weighted_circumcenter_2_object()
@ -239,8 +239,8 @@ regular_neighbor_coordinates_vertex_2(const Rt& rt,
// vor1: dual of first triangle
// vor2, vor 3: duals of two consecutive triangles
Face_circulator fc, fc_begin;
for(; hidden_vertices_begin != hidden_vertices_end;
++hidden_vertices_begin){
for(; hidden_vertices_begin != hidden_vertices_end; ++hidden_vertices_begin)
{
Coord_type area(0);
fc_begin = rt.incident_faces(*hidden_vertices_begin);
vor[0] = rt.dual(fc_begin);
@ -248,7 +248,8 @@ regular_neighbor_coordinates_vertex_2(const Rt& rt,
++fc;
vor[1] = rt.dual(fc);
++fc;
while(fc != fc_begin){
while(fc != fc_begin)
{
vor[2] = rt.dual(fc);
area += polygon_area_2(vor.begin(), vor.end(), rt.geom_traits());