Generalized Interpolation helper functors and cleaned their names

This commit is contained in:
Mael Rouxel-Labbé 2018-01-11 10:52:44 +01:00
parent 67f99cc53d
commit d041642800
1 changed files with 58 additions and 71 deletions

View File

@ -23,46 +23,50 @@
#include <CGAL/license/Interpolation.h>
#include <utility>
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 <typename VH>
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 <typename VH>
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<Triangulation_::Vertex_handle, T2_>
// into a pair<Triangulation_::Point, T2_>
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<Vertex_handle, T2> argument_type;
typedef std::pair<Point, T2> 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<Map::key_type, T2>`
// into an object of type `pair<Map::mapped_type, T2>`, 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<Vertex_handle, T2> argument_type;
typedef std::pair<Point, T2> 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<Vertex_handle, FT> argument_type;
typedef std::pair<Vertex_handle, FT> result_type;
typedef std::pair<Map_key_type, T2> argument_type;
typedef std::pair<Map_mapped_type, T2> 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 <Vertex_handle, T>
//to iterator over std::pair< Point, T>
template < class OutputIterator, class Fct = void >
// It wraps the OutputIterator with value type `std::pair<Vertex_handle, T2>`
// into an output iterator with value type `OutputFunctor::result_type`.
//
// \pre OutputIterator has value type std::pair<Vertex_handle, T>
// \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<Vertex_handle,T>
// into an output iterator with value type std::pair<Point, T>
// Conditions: OutputIterator has value type std::pair<Vertex_handle, T>
// 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<class Vertex_pair>
Project_vertex_output_iterator& operator=(const Vertex_pair& vp)
{
*_base = fct(vp);
*out = fct(vp);
return *this;
}
};