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