diff --git a/Interpolation/include/CGAL/Interpolation/internal/helpers.h b/Interpolation/include/CGAL/Interpolation/internal/helpers.h index 4bfc0094045..5ebaeb7483d 100644 --- a/Interpolation/include/CGAL/Interpolation/internal/helpers.h +++ b/Interpolation/include/CGAL/Interpolation/internal/helpers.h @@ -23,46 +23,50 @@ #include +#include + namespace CGAL { + namespace Interpolation { + namespace internal { -template < class InterpolationTraits > -struct V2P +// Extracts the bare point from a weighted point or a vertex handle (and identity +// if the argument is a bare point) +template < typename InterpolationTraits_ > +struct Extract_bare_point { - typedef typename InterpolationTraits::Point_d Point; - typedef typename InterpolationTraits::Weighted_point_d Weighted_point; + typedef InterpolationTraits_ Traits; + typedef typename Traits::Point_d Point; + typedef typename Traits::Weighted_point_d Weighted_point; - V2P(const InterpolationTraits& traits) - : traits(traits) - {} + Extract_bare_point(const Traits& traits) : traits(traits) {} - template - const Point& operator()(const VH& vh) const - { - return traits.construct_point_d_object()(vh->point()); - } + const Point& operator()(const Point& p) const { return p; } - const Point& operator()(const Point& p) const - { - return p; - } - - Point operator()(const Weighted_point& wp) const - { + Point operator()(const Weighted_point& wp) const { return traits.construct_point_d_object()(wp); } + template + const Point& operator()(const VH& vh) const { + return traits.construct_point_d_object()(vh->point()); + } + private: - InterpolationTraits traits; + Traits traits; }; -template < typename Dt, typename T2 > -struct Vertex2Point +// Converts a pair +// into a pair +template < typename Triangulation_, typename T2_ > +struct Extract_point_in_pair { - typedef typename Dt::Vertex_handle Vertex_handle; - typedef typename Dt::Point Point; + typedef Triangulation_ Tr; + typedef T2_ T2; + typedef typename Tr::Vertex_handle Vertex_handle; + typedef typename Tr::Point Point; typedef std::pair argument_type; typedef std::pair result_type; @@ -74,82 +78,65 @@ struct Vertex2Point }; -template < typename Dt, typename T2 > -struct Vertex2WPoint +// Given a map `m` of type `Map`, transforms an object of type `pair` +// into an object of type `pair`, using the `m`. +// +template < typename Map_, typename T2_ > +struct Pair_mapper { - typedef typename Dt::Vertex_handle Vertex_handle; - typedef typename Dt::Weighted_point Point; + typedef Map_ Map; + typedef T2_ T2; - typedef std::pair argument_type; - typedef std::pair result_type; + typedef typename Map::key_type Map_key_type; + typedef typename Map::mapped_type Map_mapped_type; - result_type operator()(const argument_type& vp) const - { - return std::make_pair(vp.first->point(), vp.second); - } -}; - - -template < typename Dt, typename Map > -struct Vertex2Vertex -{ - typedef typename Dt::Vertex_handle Vertex_handle; - typedef typename Dt::Geom_traits::FT FT; - typedef std::pair argument_type; - typedef std::pair result_type; + typedef std::pair argument_type; + typedef std::pair result_type; const Map& map; - const Dt& dt; - Vertex2Vertex(const Map& map, const Dt& dt) - : map(map), dt(dt) - {} + Pair_mapper(const Map& map) : map(map) {} result_type operator()(const argument_type& vp) const { typename Map::const_iterator it = map.find(vp.first); CGAL_assertion(it != map.end()); - 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 +// The struct "Project_vertex_output_iterator" is used in natural_neighbor_coordinates_2, +// as well as in regular_neighbor_coordinates_2, and in surface_neighbor_coordinates_3. // -//projection of iterator over std::pair -//to iterator over std::pair< Point, T> -template < class OutputIterator, class Fct = void > +// It wraps the OutputIterator with value type `std::pair` +// into an output iterator with value type `OutputFunctor::result_type`. +// +// \pre OutputIterator has value type std::pair +// \pre Vertex_handle has a function ->point() with return type const Point& +// \pre OutputIterator::value_type == OutputFunctor::argument_type +template < class OutputIterator, class OutputFunctor > struct Project_vertex_output_iterator { - // this class wraps the OutputIterator with value type - // std::pair - // into an output iterator with value type std::pair - // Conditions: OutputIterator has value type std::pair - // and Vertex_handle has a function ->point() - // with return type const Point& - - OutputIterator _base; - Fct fct; + OutputIterator out; + OutputFunctor fct; //creation: - Project_vertex_output_iterator(OutputIterator o, Fct fct) - : _base(o), fct(fct) + Project_vertex_output_iterator(OutputIterator o, OutputFunctor f) + : out(o), fct(f) {} - OutputIterator base() {return _base;} + OutputIterator base() {return out;} - Project_vertex_output_iterator& operator++(){_base++; return *this;} - Project_vertex_output_iterator& operator++(int){_base++; return *this;} + Project_vertex_output_iterator& operator++(){out++; return *this;} + Project_vertex_output_iterator& operator++(int){out++; return *this;} Project_vertex_output_iterator& operator*(){return *this;} template Project_vertex_output_iterator& operator=(const Vertex_pair& vp) { - *_base = fct(vp); + *out = fct(vp); return *this; } };