diff --git a/Interpolation/examples/Interpolation/interpolation_vertex_with_info_2.cpp b/Interpolation/examples/Interpolation/interpolation_vertex_with_info_2.cpp index 387fa8f135f..bfbb4692618 100644 --- a/Interpolation/examples/Interpolation/interpolation_vertex_with_info_2.cpp +++ b/Interpolation/examples/Interpolation/interpolation_vertex_with_info_2.cpp @@ -39,7 +39,7 @@ typedef CGAL::Interpolation_traits_2 Traits; typedef std::vector< std::pair > Coordinate_vector; template -struct Function_value +struct Value_function { typedef V argument_type; typedef std::pair result_type; @@ -50,7 +50,7 @@ struct Function_value }; template -struct Function_gradient +struct Gradient_function : public std::iterator { @@ -61,13 +61,13 @@ struct Function_gradient return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR); } - const Function_gradient& operator=(const std::pair& p) const { + const Gradient_function& operator=(const std::pair& 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 Gradient_function& operator++(int) const { return *this; } + const Gradient_function& operator*() const { return *this; } }; int main() @@ -94,8 +94,8 @@ int main() Delaunay_triangulation T; - Function_value function_value; - Function_gradient function_gradient; + Value_function value_function; + Gradient_function gradient_function; //parameters for quadratic function: Coord_type alpha = Coord_type(1.0), @@ -154,7 +154,7 @@ int main() //linear interpolant: l_value = CGAL::linear_interpolation(coords.begin(), coords.end(), - norm, function_value); + norm, value_function); error = CGAL_NTS abs(l_value - exact_value); l_total += error; @@ -163,8 +163,8 @@ int main() //Farin interpolant: res = CGAL::farin_c1_interpolation(coords.begin(), coords.end(), norm,points[i], - function_value, - function_gradient, + value_function, + gradient_function, Traits()); @@ -183,8 +183,8 @@ int main() //quadratic interpolant: res = CGAL::quadratic_interpolation(coords.begin(), coords.end(), norm, points[i], - function_value, - function_gradient, + value_function, + gradient_function, Traits()); if(res.second) @@ -203,8 +203,8 @@ int main() res = CGAL::sibson_c1_interpolation_square(coords.begin(), coords.end(), norm, points[i], - function_value, - function_gradient, + value_function, + gradient_function, Traits()); //error statistics if(res.second) @@ -223,8 +223,8 @@ int main() res = CGAL::sibson_c1_interpolation(coords.begin(), coords.end(), norm, points[i], - function_value, - function_gradient, + value_function, + gradient_function, Traits()); //error statistics diff --git a/Interpolation/examples/Interpolation/linear_interpolation_2.cpp b/Interpolation/examples/Interpolation/linear_interpolation_2.cpp index d399e2b6c11..a8a78edba0d 100644 --- a/Interpolation/examples/Interpolation/linear_interpolation_2.cpp +++ b/Interpolation/examples/Interpolation/linear_interpolation_2.cpp @@ -18,14 +18,14 @@ int main() typedef std::map Coord_map; typedef CGAL::Data_access Value_access; - Coord_map function_values; + Coord_map value_function; 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)); + value_function.insert(std::make_pair(p, a + bx*x + by*y)); } } @@ -35,7 +35,7 @@ int main() 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)); + Value_access(value_function)); std::cout << "Tested interpolation on " << p << " interpolation: " << res << " exact: " << a + bx*p.x() + by*p.y() << std::endl; diff --git a/Interpolation/examples/Interpolation/sibson_interpolation_2.cpp b/Interpolation/examples/Interpolation/sibson_interpolation_2.cpp index 1499e977df4..9402cd4b60d 100644 --- a/Interpolation/examples/Interpolation/sibson_interpolation_2.cpp +++ b/Interpolation/examples/Interpolation/sibson_interpolation_2.cpp @@ -25,8 +25,8 @@ int main() { Delaunay_triangulation T; - Point_value_map function_values; - Point_vector_map function_gradients; + 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); @@ -34,32 +34,31 @@ int main() 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))); + 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(function_gradients, - function_gradients.begin()), - CGAL::Data_access(function_values), + sibson_gradient_fitting_nn_2(T, std::inserter(gradient_function, + gradient_function.begin()), + CGAL:: Data_access(value_function), Traits()); - for(Point_vector_map::iterator it = function_gradients.begin(); it != function_gradients.end(); ++it) + 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; + Coord_type norm = CGAL::natural_neighbor_coordinates_2(T, p, std::back_inserter(coords)).second; //Sibson interpolant: version without sqrt: std::pair res = CGAL::sibson_c1_interpolation_square(coords.begin(), - coords.end(),norm,p, - CGAL::Data_access(function_values), - CGAL::Data_access(function_gradients), + coords.end(), norm, p, + CGAL::Data_access(value_function), + CGAL::Data_access(gradient_function), Traits()); if(res.second) @@ -69,7 +68,7 @@ int main() << std::endl; else std::cout << "C^1 Interpolation not successful." << std::endl - << " not all function_gradients are provided." << std::endl + << " not all gradients are provided." << std::endl << " You may resort to linear interpolation." << std::endl; return EXIT_SUCCESS; diff --git a/Interpolation/examples/Interpolation/sibson_interpolation_vertex_with_info_2.cpp b/Interpolation/examples/Interpolation/sibson_interpolation_vertex_with_info_2.cpp index 4bfde90b3e7..c75f443476f 100644 --- a/Interpolation/examples/Interpolation/sibson_interpolation_vertex_with_info_2.cpp +++ b/Interpolation/examples/Interpolation/sibson_interpolation_vertex_with_info_2.cpp @@ -35,7 +35,7 @@ typedef CGAL::Delaunay_triangulation_2 Delaunay_triangulati typedef Delaunay_triangulation::Vertex_handle Vertex_handle; template -struct Function_value +struct Value_function { typedef V argument_type; typedef std::pair result_type; @@ -46,7 +46,7 @@ struct Function_value }; template -struct Function_gradient +struct Gradient_function : public std::iterator { typedef V argument_type; @@ -56,21 +56,21 @@ struct Function_gradient return std::make_pair(a->info().gradient, a->info().gradient != CGAL::NULL_VECTOR); } - const Function_gradient& operator=(const std::pair& p) const { + const Gradient_function& operator=(const std::pair& 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 Gradient_function& operator++(int) const { return *this; } + const Gradient_function& operator*() const { return *this; } }; int main() { Delaunay_triangulation dt; - Function_value function_value; - Function_gradient function_gradient; + Value_function value_function; + Gradient_function gradient_function; //parameters for spherical function: Coord_type a(0.25), bx(1.3), by(-0.7), c(0.2); @@ -84,9 +84,9 @@ int main() } sibson_gradient_fitting_nn_2(dt, - function_gradient, - function_value, + gradient_function, CGAL::Identity >(), + value_function, Traits()); //coordinate computation @@ -103,8 +103,8 @@ int main() coords.end(), norm, p, - function_value, - function_gradient, + value_function, + gradient_function, Traits()); if(res.second) diff --git a/Interpolation/include/CGAL/interpolation_functions.h b/Interpolation/include/CGAL/interpolation_functions.h index 32b4ac6e4b1..4d700b10df1 100644 --- a/Interpolation/include/CGAL/interpolation_functions.h +++ b/Interpolation/include/CGAL/interpolation_functions.h @@ -39,8 +39,8 @@ struct Data_access : public CGAL::unary_function > { - typedef typename Map::mapped_type Data_type; - typedef typename Map::key_type Key_type; + typedef typename Map::mapped_type Data_type; + typedef typename Map::key_type Key_type; Data_access(const Map& m): map(m){} @@ -57,21 +57,21 @@ struct Data_access }; //the interpolation functions: -template < class ForwardIterator, class Functor > -typename Functor::result_type::first_type +template < class ForwardIterator, class ValueFunctor > +typename ValueFunctor::result_type::first_type linear_interpolation(ForwardIterator first, ForwardIterator beyond, - const typename - std::iterator_traits::value_type:: - second_type& norm, - Functor function_value) + const typename std::iterator_traits::value_type::second_type& norm, + ValueFunctor value_function) { - CGAL_precondition(norm>0); - typedef typename Functor::result_type::first_type Value_type; + CGAL_precondition(norm > 0); + + typedef typename ValueFunctor::result_type::first_type Value_type; + Value_type result(0); - typename Functor::result_type val; + typename ValueFunctor::result_type val; for(; first !=beyond; ++first) { - val = function_value(first->first); + val = value_function(first->first); CGAL_assertion(val.second); result += (first->second/norm) * val.first; } @@ -79,30 +79,28 @@ linear_interpolation(ForwardIterator first, ForwardIterator beyond, } - template < class ForwardIterator, class Functor, class GradFunctor, - class Traits, class Point > -std::pair< typename Functor::result_type::first_type, bool> +template < class ForwardIterator, class ValueFunctor, class GradFunctor, + class Traits, class Point > +std::pair< typename ValueFunctor::result_type::first_type, bool> quadratic_interpolation(ForwardIterator first, ForwardIterator beyond, - const typename - std::iterator_traits:: - value_type::second_type& norm, + const typename std::iterator_traits::value_type::second_type& norm, const Point& p, - Functor function_value, - GradFunctor function_gradient, + ValueFunctor value_function, + GradFunctor gradient_function, const Traits& traits) { CGAL_precondition(norm > 0); - typedef typename Functor::result_type::first_type Value_type; + typedef typename ValueFunctor::result_type::first_type Value_type; Interpolation::internal::Extract_bare_point cp(traits); Value_type result(0); - typename Functor::result_type f; + typename ValueFunctor::result_type f; typename GradFunctor::result_type grad; for(; first !=beyond; ++first) { - f = function_value(first->first); - grad = function_gradient(first->first); + f = value_function(first->first); + grad = gradient_function(first->first); //test if value and gradient are correctly retrieved: CGAL_assertion(f.second); if(!grad.second) @@ -115,32 +113,31 @@ quadratic_interpolation(ForwardIterator first, ForwardIterator beyond, } - template < class ForwardIterator, class Functor, class GradFunctor, - class Traits, class Point > -std::pair< typename Functor::result_type::first_type, bool> +template < class ForwardIterator, class ValueFunctor, class GradFunctor, + class Traits, class Point > +std::pair< typename ValueFunctor::result_type::first_type, bool> sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond, - const typename - std::iterator_traits:: - value_type::second_type& norm, + const typename std::iterator_traits::value_type::second_type& norm, const Point& p, - Functor function_value, - GradFunctor function_gradient, + ValueFunctor value_function, + GradFunctor gradient_function, const Traits& traits) { CGAL_precondition(norm >0); - typedef typename Functor::result_type::first_type Value_type; - typedef typename Traits::FT Coord_type; + + typedef typename ValueFunctor::result_type::first_type Value_type; + typedef typename Traits::FT Coord_type; Interpolation::internal::Extract_bare_point cp(traits); Coord_type term1(0), term2(term1), term3(term1), term4(term1); Value_type linear_int(0), gradient_int(0); - typename Functor::result_type f; + typename ValueFunctor::result_type f; typename GradFunctor::result_type grad; for(; first !=beyond; ++first) { - f = function_value(first->first); - grad = function_gradient(first->first); + f = value_function(first->first); + grad = gradient_function(first->first); CGAL_assertion(f.second); if(!grad.second) return std::make_pair(Value_type(0), false); //the values are not correct @@ -187,32 +184,31 @@ sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond, // term3 += coeff*(squared_dist/inv_weight); // gradient_int += (coeff/inv_weight) * (vh->get_value()+ vh->get_gradient() * (p - vh->point())); -template < class ForwardIterator, class Functor, class GradFunctor, +template < class ForwardIterator, class ValueFunctor, class GradFunctor, class Traits, class Point > -std::pair< typename Functor::result_type::first_type, bool > +std::pair< typename ValueFunctor::result_type::first_type, bool > sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond, - const typename - std::iterator_traits:: - value_type::second_type& norm, + const typename std::iterator_traits::value_type::second_type& norm, const Point& p, - Functor function_value, - GradFunctor function_gradient, + ValueFunctor value_function, + GradFunctor gradient_function, const Traits& traits) { CGAL_precondition(norm > 0); - typedef typename Functor::result_type::first_type Value_type; - typedef typename Traits::FT Coord_type; + + typedef typename ValueFunctor::result_type::first_type Value_type; + typedef typename Traits::FT Coord_type; Interpolation::internal::Extract_bare_point cp(traits); Coord_type term1(0), term2(term1), term3(term1), term4(term1); Value_type linear_int(0), gradient_int(0); - typename Functor::result_type f; + typename ValueFunctor::result_type f; typename GradFunctor::result_type grad; for(; first!=beyond; ++first) { - f = function_value(first->first); - grad = function_gradient(first->first); + f = value_function(first->first); + grad = gradient_function(first->first); CGAL_assertion(f.second); if(!grad.second) @@ -249,33 +245,32 @@ sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond, } -template < class RandomAccessIterator, class Functor, class - GradFunctor, class Traits, class Point_> -std::pair< typename Functor::result_type::first_type, bool> +template < class RandomAccessIterator, class ValueFunctor, class GradFunctor, + class Traits, class Point_> +std::pair< typename ValueFunctor::result_type::first_type, bool> farin_c1_interpolation(RandomAccessIterator first, RandomAccessIterator beyond, - const typename - std::iterator_traits:: - value_type::second_type& norm, + const typename std::iterator_traits::value_type::second_type& norm, const Point_& /*p*/, - Functor function_value, GradFunctor - function_gradient, + ValueFunctor value_function, + GradFunctor gradient_function, const Traits& traits) { CGAL_precondition(norm >0); - //the function value is available for all points - //if a gradient value is not availble: function returns false - typedef typename Functor::result_type::first_type Value_type; - typedef typename Traits::FT Coord_type; + + // the function value is available for all points + // if a gradient value is not availble: function returns false + typedef typename ValueFunctor::result_type::first_type Value_type; + typedef typename Traits::FT Coord_type; Interpolation::internal::Extract_bare_point cp(traits); - typename Functor::result_type f; + typename ValueFunctor::result_type f; typename GradFunctor::result_type grad; int n = static_cast(beyond - first); if(n == 1) { - f = function_value(first->first); + f = value_function(first->first); CGAL_assertion(f.second); return std::make_pair(f.first, true); } @@ -296,7 +291,7 @@ farin_c1_interpolation(RandomAccessIterator first, Coord_type coord_i_square = CGAL_NTS square(it->second); // for later: the function value of it->first: - f = function_value(it->first); + f = value_function(it->first); CGAL_assertion(f.second); ordinates[i][i] = f.first; @@ -311,7 +306,7 @@ farin_c1_interpolation(RandomAccessIterator first, { it2 = first + j; - grad = function_gradient(it->first); + grad = gradient_function(it->first); if(!grad.second) return std::make_pair(Value_type(0), false); // the gradient is not known