int main() { Delaunay_triangulation T; Point_value_map value_function; Point_vector_map gradient_function; //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++) { K::Point_2 p(x,y); T.insert(p); value_function.insert(std::make_pair(p,a + bx* x+ by*y + c*(x*x+y*y))); } } sibson_gradient_fitting_nn_2(T, std::inserter(gradient_function, gradient_function.begin()), CGAL:: Data_access<Point_value_map>(value_function), Traits()); for(Point_vector_map::iterator it = gradient_function.begin(); it != gradient_function.end(); ++it) { std::cout << it->first << " " << it->second << std::endl; } // 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; //Sibson interpolant: version without sqrt: std::pair<Coord_type, bool> res = CGAL::sibson_c1_interpolation_square(coords.begin(), coords.end(), norm, p, CGAL::Data_access<Point_value_map>(value_function), CGAL::Data_access<Point_vector_map>(gradient_function), Traits()); 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()) << std::endl; else std::cout << "C^1 Interpolation not successful." << std::endl << " not all gradients are provided." << std::endl << " You may resort to linear interpolation." << std::endl; return EXIT_SUCCESS; }
/* Interpolation Potential */ Potential_interpolation_2d::Potential_interpolation_2d( const Coordinate_2d& coords, const vector<double>& values) { size_t n = coords.size(); for (size_t i = 0; i < n; ++i) { Point p(coords.x(i), coords.y(i)); _dt.insert(p); _value_map.insert(make_pair(p, values[i])); } sibson_gradient_fitting_nn_2( _dt, inserter(_grad_map, _grad_map.begin()), Data_access_value(_value_map), GradTraits()); }