diff --git a/Interpolation/include/CGAL/interpolation_functions.h b/Interpolation/include/CGAL/interpolation_functions.h index bdb62827b8e..be35f6fceb0 100644 --- a/Interpolation/include/CGAL/interpolation_functions.h +++ b/Interpolation/include/CGAL/interpolation_functions.h @@ -27,6 +27,8 @@ #include #include +#include + #include #include #include @@ -58,17 +60,21 @@ struct Data_access //the interpolation functions: template < class ForwardIterator, class ValueFunctor > -typename ValueFunctor::result_type::first_type +typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type linear_interpolation(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, ValueFunctor value_function) { CGAL_precondition(norm > 0); - typedef typename ValueFunctor::result_type::first_type Value_type; + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type result_type; + typedef typename result_type::first_type Value_type; Value_type result(0); - typename ValueFunctor::result_type val; + result_type val; for(; first!=beyond; ++first) { val = value_function(first->first); @@ -78,9 +84,12 @@ linear_interpolation(ForwardIterator first, ForwardIterator beyond, return result; } - template < class ForwardIterator, class ValueFunctor, class GradFunctor, class Traits, class Point > -std::pair< typename ValueFunctor::result_type::first_type, bool> +std::pair< + typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type, + bool> quadratic_interpolation(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, const Point& p, @@ -89,15 +98,20 @@ quadratic_interpolation(ForwardIterator first, ForwardIterator beyond, const Traits& traits) { CGAL_precondition(norm > 0); - typedef typename ValueFunctor::result_type::first_type Value_type; - typedef typename Traits::Point_d Bare_point; + + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + typedef typename boost::result_of::type gradient_functor_result_type; + typedef typename value_functor_result_type::first_type Value_type; + + typedef typename Traits::Point_d Bare_point; Interpolation::internal::Extract_bare_point cp(traits); const Bare_point& bp = cp(p); Value_type result(0); - typename ValueFunctor::result_type f; - typename GradFunctor::result_type grad; + value_functor_result_type f; + gradient_functor_result_type grad; for(; first!=beyond; ++first) { @@ -119,7 +133,11 @@ quadratic_interpolation(ForwardIterator first, ForwardIterator beyond, template < class ForwardIterator, class ValueFunctor, class GradFunctor, class Traits, class Point > -std::pair< typename ValueFunctor::result_type::first_type, bool > +std::pair< + typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type, + bool> sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, const Point& p, @@ -129,17 +147,21 @@ sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond, { CGAL_precondition(norm >0); - typedef typename ValueFunctor::result_type::first_type Value_type; - typedef typename Traits::FT Coord_type; - typedef typename Traits::Point_d Bare_point; + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + typedef typename boost::result_of::type gradient_functor_result_type; + typedef typename value_functor_result_type::first_type Value_type; + + typedef typename Traits::FT Coord_type; + typedef typename Traits::Point_d Bare_point; Interpolation::internal::Extract_bare_point cp(traits); const Bare_point& bp = cp(p); Coord_type term1(0), term2(term1), term3(term1), term4(term1); Value_type linear_int(0), gradient_int(0); - typename ValueFunctor::result_type f; - typename GradFunctor::result_type grad; + value_functor_result_type f; + gradient_functor_result_type grad; for(; first!=beyond; ++first) { @@ -193,7 +215,11 @@ sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond, // gradient_int += (coeff/inv_weight) * (vh->get_value()+ vh->get_gradient() * (p - vh->point())); template < class ForwardIterator, class ValueFunctor, class GradFunctor, class Traits, class Point > -std::pair< typename ValueFunctor::result_type::first_type, bool > +std::pair< + typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type, + bool> sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, const Point& p, @@ -203,17 +229,21 @@ sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond, { CGAL_precondition(norm > 0); - typedef typename ValueFunctor::result_type::first_type Value_type; - typedef typename Traits::FT Coord_type; - typedef typename Traits::Point_d Bare_point; + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + typedef typename boost::result_of::type gradient_functor_result_type; + typedef typename value_functor_result_type::first_type Value_type; + + typedef typename Traits::FT Coord_type; + typedef typename Traits::Point_d Bare_point; Interpolation::internal::Extract_bare_point cp(traits); const Bare_point& bp = cp(p); Coord_type term1(0), term2(term1), term3(term1), term4(term1); Value_type linear_int(0), gradient_int(0); - typename ValueFunctor::result_type f; - typename GradFunctor::result_type grad; + value_functor_result_type f; + gradient_functor_result_type grad; for(; first!=beyond; ++first) { @@ -257,7 +287,11 @@ sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond, template < class RandomAccessIterator, class ValueFunctor, class GradFunctor, class Traits, class Point_> -std::pair< typename ValueFunctor::result_type::first_type, bool> +std::pair< + typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type, + bool> farin_c1_interpolation(RandomAccessIterator first, RandomAccessIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, @@ -268,14 +302,16 @@ farin_c1_interpolation(RandomAccessIterator first, { CGAL_precondition(norm >0); - // 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; + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + typedef typename boost::result_of::type gradient_functor_result_type; + typedef typename value_functor_result_type::first_type Value_type; + + typedef typename Traits::FT Coord_type; Interpolation::internal::Extract_bare_point cp(traits); - typename ValueFunctor::result_type f; - typename GradFunctor::result_type grad; + value_functor_result_type f; + gradient_functor_result_type grad; int n = static_cast(beyond - first); if(n == 1) diff --git a/Interpolation/include/CGAL/sibson_gradient_fitting.h b/Interpolation/include/CGAL/sibson_gradient_fitting.h index 04830e4845c..6e441b7a33e 100644 --- a/Interpolation/include/CGAL/sibson_gradient_fitting.h +++ b/Interpolation/include/CGAL/sibson_gradient_fitting.h @@ -29,9 +29,11 @@ #include #include +#include #include -#include +#include +#include #include #include @@ -45,12 +47,17 @@ sibson_gradient_fitting(ForwardIterator first, ForwardIterator beyond, const typename std::iterator_traits::value_type::second_type& norm, const Point& p, - const typename ValueFunctor::result_type::first_type fn, + const typename boost::result_of< + ValueFunctor(typename std::iterator_traits::value_type::first_type)> + ::type::first_type fn, ValueFunctor value_function, const Traits& traits) { CGAL_precondition( first != beyond && norm != 0); + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + typedef typename Traits::Aff_transformation_d Aff_transformation; typedef typename Traits::FT Coord_type; typedef typename Traits::Point_d Bare_point; @@ -69,7 +76,7 @@ sibson_gradient_fitting(ForwardIterator first, typename Traits::Vector_d d = traits.construct_vector_d_object()(bp, bare_f); // compute the vector pn: - typename ValueFunctor::result_type f = value_function(first->first); + value_functor_result_type f = value_function(first->first); CGAL_assertion(f.second); // function value of first->first is valid pn = pn + traits.construct_scaled_vector_d_object()(d, scale * (f.first - fn)); @@ -91,7 +98,10 @@ sibson_gradient_fitting(ForwardIterator first, ValueFunctor value_function, const Traits& traits) { - typename ValueFunctor::result_type fn = value_function(p); + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + + value_functor_result_type fn = value_function(p); CGAL_assertion(fn.second); return sibson_gradient_fitting(first, beyond, norm, p, fn.first, value_function, traits); @@ -110,8 +120,11 @@ sibson_gradient_fitting_internal(ForwardIterator first, const Traits& traits, const typename Traits::Point_d& /*dummy*/) { + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + const typename Traits::Point_d& bare_p = traits.construct_point_d_object()(vh->point()); - typename ValueFunctor::result_type fn = value_function(bare_p); + value_functor_result_type fn = value_function(bare_p); CGAL_assertion(fn.second); return sibson_gradient_fitting(first, beyond, norm, bare_p, fn.first, value_function, traits); @@ -129,7 +142,10 @@ sibson_gradient_fitting_internal(ForwardIterator first, const Traits& traits, const typename Traits::Weighted_point_d& /*dummy*/) { - typename ValueFunctor::result_type fn = value_function(vh->point()); + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + + value_functor_result_type fn = value_function(vh->point()); CGAL_assertion(fn.second); return sibson_gradient_fitting(first, beyond, norm, vh->point(), fn.first, value_function, traits); @@ -147,15 +163,19 @@ sibson_gradient_fitting_internal(ForwardIterator first, const Traits& traits, VH /*dummy*/) { + typedef typename std::iterator_traits::value_type::first_type arg_type; + typedef typename boost::result_of::type value_functor_result_type; + const typename Traits::Point_d& bare_p = traits.construct_point_d_object()(vh->point()); - typename ValueFunctor::result_type fn = value_function(vh); + value_functor_result_type fn = value_function(vh); CGAL_assertion(fn.second); return sibson_gradient_fitting(first, beyond, norm, bare_p, fn.first, value_function, traits); } -template < class Tr, class OutputIterator, class OutputFunctor, +template < class ValueFunctorArgType, + class Tr, class OutputIterator, class OutputFunctor, class ValueFunctor, class CoordFunctor, class Traits > OutputIterator sibson_gradient_fitting_internal(const Tr& tr, @@ -170,7 +190,7 @@ sibson_gradient_fitting_internal(const Tr& tr, typedef typename Tr::Vertex_handle Vertex_handle; Coord_type norm; - std::vector > coords; + std::vector > coords; typename Tr::Finite_vertices_iterator vit = tr.finite_vertices_begin(); for(; vit != tr.finite_vertices_end(); ++vit) @@ -187,7 +207,7 @@ sibson_gradient_fitting_internal(const Tr& tr, Vertex_handle(vit), value_function, traits, - typename ValueFunctor::argument_type()))); + ValueFunctorArgType()))); coords.clear(); } @@ -196,7 +216,6 @@ sibson_gradient_fitting_internal(const Tr& tr, return out; } - // The following functions allow to fit the gradients for all points in // a triangulation except the convex hull points. // -> _nn2: natural_neighbor_coordinates_2 @@ -208,31 +227,56 @@ sibson_gradient_fitting_nn_2(const Dt& dt, OutputIterator out, OutputFunctor fct, ValueFunctor value_function, - const Traits& traits) + const Traits& traits, + // Some SFINAE to distinguish whether the argument type + // of the value functor is 'DT::Point' or 'DT::Vertex_handle' + typename boost::enable_if_c< + boost::is_constructible< + cpp11::function, + ValueFunctor + >::value>::type* = NULL) { typedef typename Traits::FT FT; - typedef typename ValueFunctor::argument_type VF_arg_type; + typedef typename Dt::Point VF_arg_type; typedef typename std::back_insert_iterator > > CoordInserter; + typedef Interpolation::internal::Extract_point_in_pair Coord_OutputFunctor; - // If the functor evaluates at points (and not vertices), then we must convert - // the output of the coordinates computations - a pair - - // to a pair - typedef typename boost::mpl::if_< - boost::is_same, - Interpolation::internal::Extract_point_in_pair, - CGAL::Identity > - >::type Coord_OutputFunctor; - - return sibson_gradient_fitting_internal(dt, out, fct, value_function, - natural_neighbor_coordinates_2_object(), - traits); + return sibson_gradient_fitting_internal(dt, out, fct, value_function, + natural_neighbor_coordinates_2_object(), + traits); } +template < class Dt, class OutputIterator, class OutputFunctor, class ValueFunctor, class Traits > +OutputIterator +sibson_gradient_fitting_nn_2(const Dt& dt, + OutputIterator out, + OutputFunctor fct, + ValueFunctor value_function, + const Traits& traits, + typename boost::enable_if_c< + boost::is_constructible< + cpp11::function, + ValueFunctor + >::value>::type* = NULL) +{ + typedef typename Traits::FT FT; + typedef typename Dt::Vertex_handle VF_arg_type; + typedef typename std::back_insert_iterator > > CoordInserter; + typedef CGAL::Identity > Coord_OutputFunctor; -// Same as above but without OutputFunctor. Default to extracting the point, for backward compatibility. + return sibson_gradient_fitting_internal(dt, out, fct, value_function, + natural_neighbor_coordinates_2_object(), + traits); +} + +// Same as above but without OutputFunctor. +// Defaults to extracting the point, for backward compatibility. template < class Dt, class OutputIterator, class ValueFunctor, class Traits > OutputIterator sibson_gradient_fitting_nn_2(const Dt& dt, @@ -246,6 +290,33 @@ sibson_gradient_fitting_nn_2(const Dt& dt, return sibson_gradient_fitting_nn_2(dt, out, OutputFunctor(), value_function, traits); } +template < class Rt, class OutputIterator, class OutputFunctor, class ValueFunctor, class Traits > +OutputIterator +sibson_gradient_fitting_rn_2(const Rt& rt, + OutputIterator out, + OutputFunctor fct, + ValueFunctor value_function, + const Traits& traits, + // Some SFINAE to distinguish whether the argument type + // of the value functor is 'Rt::Point' (weighted point) or 'Rt::Vertex_handle' + typename boost::enable_if_c< + boost::is_constructible< + cpp11::function, + ValueFunctor + >::value>::type* = NULL) +{ + typedef typename Traits::FT FT; + typedef typename Rt::Point VF_arg_type; + typedef typename std::back_insert_iterator > > CoordInserter; + typedef Interpolation::internal::Extract_point_in_pair Coord_OutputFunctor; + + return sibson_gradient_fitting_internal(rt, out, fct, value_function, + regular_neighbor_coordinates_2_object(), + traits); +} template < class Rt, class OutputIterator, class OutputFunctor, class ValueFunctor, class Traits > OutputIterator @@ -253,30 +324,26 @@ sibson_gradient_fitting_rn_2(const Rt& rt, OutputIterator out, OutputFunctor fct, ValueFunctor value_function, - const Traits& traits) + const Traits& traits, + typename boost::enable_if_c< + boost::is_constructible< + cpp11::function, + ValueFunctor + >::value>::type* = NULL) { typedef typename Traits::FT FT; - typedef typename ValueFunctor::argument_type VF_arg_type; + typedef typename Rt::Vertex_handle VF_arg_type; typedef typename std::back_insert_iterator > > CoordInserter; + typedef CGAL::Identity > Coord_OutputFunctor; - // If the functor evaluates at points (and not vertices), then we must convert - // the output of the coordinates computations - a pair - - // to a pair - typedef typename boost::mpl::if_< - boost::is_same, - Interpolation::internal::Extract_point_in_pair, - CGAL::Identity > - >::type Coord_OutputFunctor; - - return sibson_gradient_fitting_internal(rt, out, fct, value_function, - regular_neighbor_coordinates_2_object(), - traits); + return sibson_gradient_fitting_internal(rt, out, fct, value_function, + regular_neighbor_coordinates_2_object(), + traits); } - // Same as above but without OutputFunctor. Default to extracting the point, for backward compatibility. template < class Rt, class OutputIterator, class ValueFunctor, class Traits > OutputIterator