move helper classes in a subdirectory/namespace/file

This commit is contained in:
Andreas Fabri 2017-12-19 17:44:08 +00:00 committed by Mael Rouxel-Labbé
parent abc19d9c9d
commit 2bc8e23653
5 changed files with 189 additions and 221 deletions

View File

@ -0,0 +1,160 @@
// Copyright (c) 2003,2017 INRIA Sophia-Antipolis (France).
// All rights reserved.
//
// This file is part of CGAL (www.cgal.org).
// You can redistribute it and/or modify it under the terms of the GNU
// General Public License as published by the Free Software Foundation,
// either version 3 of the License, or (at your option) any later version.
//
// Licensees holding a valid commercial license may use this file in
// accordance with the commercial license agreement provided with the software.
//
// This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
// WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
//
// $URL$
// $Id$
// SPDX-License-Identifier: GPL-3.0+
//
// Author(s) : Julia Floetotto
#ifndef CGAL_INTERPOLATION_INTERNAL_HELPERS_H
#define CGAL_INTERPOLATION_INTERNAL_HELPERS_H
#include <CGAL/license/Interpolation.h>
namespace CGAL {
namespace Interpolation {
namespace internal {
template < class InterpolationTraits>
struct V2P
{
typedef typename InterpolationTraits::Point_d Point;
typedef typename InterpolationTraits::Weighted_point_d Weighted_point;
V2P(const InterpolationTraits& 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;
}
Point operator()(const Weighted_point& wp) const
{
return traits.construct_point_d_object()(wp);
}
private:
InterpolationTraits traits;
};
template < typename Dt, typename T2>
struct Vertex2Point {
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Point Point;
typedef std::pair<Vertex_handle, T2> argument_type;
typedef std::pair<Point, T2> result_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;
const Map& map;
const Dt& dt;
Vertex2Vertex(const Map& map, const Dt& dt)
: map(map), dt(dt)
{}
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);
}
};
template <typename Tr, typename InterpolationTraits, typename FunctorArgType, typename T2>
struct Output_iterator_functor_selector
{
typedef CGAL::Identity<std::pair<FunctorArgType, T2> > type;
};
template <typename Tr, typename InterpolationTraits, typename T2>
struct Output_iterator_functor_selector<Tr, InterpolationTraits,
typename InterpolationTraits::Point_d, T2>
{
typedef Interpolation::internal::Vertex2Point<Tr, T2> type;
};
// 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
//
//projection of iterator over std::pair <Vertex_handle, T>
//to iterator over std::pair< Point, T>
template < class OutputIterator, class Fct = void>
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;
//creation:
Project_vertex_output_iterator(OutputIterator o, Fct fct)
: _base(o), fct(fct)
{}
OutputIterator base() {return _base;}
Project_vertex_output_iterator& operator++(){_base++; return *this;}
Project_vertex_output_iterator& operator++(int){_base++; 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);
return *this;
}
};
} // namespace internal
} // namespace Interpolation
} // namespace CGAL
#endif // CGAL_INTERPOLATION_INTERNAL_HELPERS_H

View File

@ -23,6 +23,7 @@
#include <CGAL/license/Interpolation.h>
#include <CGAL/Interpolation/internal/helpers.h>
#include <CGAL/double.h>
#include <CGAL/use.h>
@ -31,41 +32,6 @@
#include <vector>
namespace CGAL {
namespace internal {
namespace interpolation {
template < class InterpolationTraits>
struct V2P
{
typedef typename InterpolationTraits::Point_d Point;
typedef typename InterpolationTraits::Weighted_point_d Weighted_point;
V2P(const InterpolationTraits& 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;
}
Point operator()(const Weighted_point& wp) const
{
return traits.construct_point_d_object()(wp);
}
private:
InterpolationTraits traits;
};
} // end namespace interpolation
} // end namespace internal
//Functor class for accessing the function values/gradients
template< class Map >
@ -123,7 +89,7 @@ quadratic_interpolation(ForwardIterator first, ForwardIterator beyond,
const Traits& traits)
{
CGAL_precondition(norm >0);
internal::interpolation::V2P<Traits> v2p(traits);
Interpolation::internal::V2P<Traits> v2p(traits);
typedef typename Functor::result_type::first_type Value_type;
Value_type result(0);
typename Functor::result_type f;
@ -156,7 +122,7 @@ sibson_c1_interpolation(ForwardIterator first, ForwardIterator beyond,
const Traits& traits)
{
CGAL_precondition(norm >0);
internal::interpolation::V2P<Traits> v2p(traits);
Interpolation::internal::V2P<Traits> v2p(traits);
typedef typename Functor::result_type::first_type Value_type;
typedef typename Traits::FT Coord_type;
@ -229,7 +195,7 @@ sibson_c1_interpolation_square(ForwardIterator first, ForwardIterator beyond,
const Traits& traits)
{
CGAL_precondition(norm >0);
internal::interpolation::V2P<Traits> v2p(traits);
Interpolation::internal::V2P<Traits> v2p(traits);
typedef typename Functor::result_type::first_type Value_type;
typedef typename Traits::FT Coord_type;
@ -294,7 +260,7 @@ farin_c1_interpolation(RandomAccessIterator first,
typedef typename Functor::result_type::first_type Value_type;
typedef typename Traits::FT Coord_type;
internal::interpolation::V2P<Traits> v2p(traits);
Interpolation::internal::V2P<Traits> v2p(traits);
typename Functor::result_type f;
typename GradFunctor::result_type grad;

View File

@ -22,7 +22,7 @@
#define CGAL_NATURAL_NEIGHBOR_COORDINATES_2_H
#include <CGAL/license/Interpolation.h>
#include <CGAL/Interpolation/internal/helpers.h>
#include <CGAL/Iterator_project.h>
#include <CGAL/Polygon_2.h>
#include <CGAL/number_utils_classes.h>
@ -33,100 +33,6 @@
namespace CGAL {
namespace internal{
namespace interpolation{
template < typename Dt, typename T2>
struct Vertex2Point {
typedef typename Dt::Vertex_handle Vertex_handle;
typedef typename Dt::Point Point;
typedef std::pair<Vertex_handle, T2> argument_type;
typedef std::pair<Point, T2> result_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;
const Map& map;
const Dt& dt;
Vertex2Vertex(const Map& map, const Dt& dt)
: map(map), dt(dt)
{}
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);
}
};
template <typename Tr, typename InterpolationTraits, typename FunctorArgType, typename T2>
struct Output_iterator_functor_selector
{
typedef CGAL::Identity<std::pair<FunctorArgType, T2> > type;
};
template <typename Tr, typename InterpolationTraits, typename T2>
struct Output_iterator_functor_selector<Tr, InterpolationTraits,
typename InterpolationTraits::Point_d, T2>
{
typedef internal::interpolation::Vertex2Point<Tr, T2> type;
};
// 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
//
//projection of iterator over std::pair <Vertex_handle, T>
//to iterator over std::pair< Point, T>
template < class OutputIterator, class Fct = void>
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;
//creation:
Project_vertex_output_iterator(OutputIterator o, Fct fct)
: _base(o), fct(fct)
{}
OutputIterator base() {return _base;}
Project_vertex_output_iterator& operator++(){_base++; return *this;}
Project_vertex_output_iterator& operator++(int){_base++; 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);
return *this;
}
};
} } // end of namespace internal::interpolation
// The following natural_neighbor_coordinate_2 functions fix the
@ -216,6 +122,7 @@ natural_neighbors_2(const Dt& dt,
return natural_neighbors_2(dt, p, out, hole.begin(), hole.end());
}
//function call if the conflict zone is known:
// OutputIterator has value type
// std::pair<Dt::Vertex_handle, Dt::Geom_traits::FT>
@ -283,11 +190,6 @@ natural_neighbors_2(const Dt& dt,
return make_triple(out, area_sum, true);
}
template < class Dt, class OutputIterator, class Fct >
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool >
@ -301,9 +203,9 @@ natural_neighbor_coordinates_2(const Dt& dt,
{
CGAL_precondition(dt.dimension() == 2);
internal::interpolation::Project_vertex_output_iterator<OutputIterator, Fct> op(out, fct);
Interpolation::internal::Project_vertex_output_iterator<OutputIterator, Fct> op(out, fct);
Triple<internal::interpolation::Project_vertex_output_iterator<OutputIterator,Fct>,
Triple<Interpolation::internal::Project_vertex_output_iterator<OutputIterator,Fct>,
typename Dt::Geom_traits::FT, bool > result =
natural_neighbors_2(dt, p, op, start);
@ -311,7 +213,6 @@ natural_neighbor_coordinates_2(const Dt& dt,
}
/////////////////////////////////////////////////////////////
//the cast from vertex to point:
// the following functions return an Output_iterator over
@ -329,12 +230,10 @@ natural_neighbor_coordinates_2(const Dt& dt,
{
return natural_neighbor_coordinates_2(dt, p, out,
internal::interpolation::Vertex2Point<Dt, typename Dt::Geom_traits::FT>(), start);
Interpolation::internal::Vertex2Point<Dt, typename Dt::Geom_traits::FT>(), start);
}
//OutputIterator has value type
// std::pair< Dt::Geom_traits::Point_2, Dt::Geom_traits::FT>
//function call if the conflict zone is known:
@ -347,15 +246,16 @@ natural_neighbor_coordinates_2(const Dt& dt,
{
CGAL_precondition(dt.dimension() == 2);
internal::interpolation::Project_vertex_output_iterator<OutputIterator> op(out);
Interpolation::internal::Project_vertex_output_iterator<OutputIterator> op(out);
Triple<internal::interpolation::Project_vertex_output_iterator<OutputIterator>,
Triple<Interpolation::internal::Project_vertex_output_iterator<OutputIterator>,
typename Dt::Geom_traits::FT, bool > result =
natural_neighbors_2(dt, p, op, hole_begin,hole_end);
return make_triple(result.first.base(), result.second, result.third);
}
/**********************************************************/
//compute the coordinates for a vertex of the triangulation
// with respect to the other points in the triangulation
@ -389,11 +289,12 @@ natural_neighbor_coordinates_2(const Dt& dt,
}
while(++vc!=done);
internal::interpolation::Vertex2Vertex<Dt,V2V> v2v(correspondence_map, dt);
Unary_compose_1<Fct,internal::interpolation::Vertex2Vertex<Dt,V2V> > cfct(fct,v2v);
Interpolation::internal::Vertex2Vertex<Dt,V2V> v2v(correspondence_map, dt);
Unary_compose_1<Fct,Interpolation::internal::Vertex2Vertex<Dt,V2V> > cfct(fct,v2v);
return natural_neighbor_coordinates_2(t2, vh->point(), out, cfct);
}
template <class Dt, class OutputIterator>
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool >
natural_neighbor_coordinates_2(const Dt& dt,
@ -401,60 +302,15 @@ natural_neighbor_coordinates_2(const Dt& dt,
OutputIterator out)
{
return natural_neighbor_coordinates_2(dt, vh, out,
internal::interpolation::Vertex2Point<Dt, typename Dt::Geom_traits::FT>());
Interpolation::internal::Vertex2Point<Dt, typename Dt::Geom_traits::FT>());
}
#if 0
/**********************************************************/
// AF added
// writes pair<Vertex_handle,Vector> into out
//
//compute the coordinates for a vertex of the triangulation
// with respect to the other points in the triangulation
//OutputIterator has value type
// std::pair< Dt::Geom_traits::Point_2, Dt::Geom_traits::FT>
template <class Dt, class OutputIterator>
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool >
natural_neighbors_2(const Dt& dt,
typename Dt::Vertex_handle vh,
OutputIterator out)
{
typedef typename Dt::Geom_traits::FT FT;
typedef typename Dt::Vertex_handle Vertex_handle;
std::map<Vertex_handle, Vertex_handle> vv_map;
//this functions creates a small triangulation of the
// incident vertices of this vertex and computes the
// natural neighbor coordinates of ch->point() wrt. it.
typedef typename Dt::Vertex_circulator Vertex_circulator;
CGAL_precondition(dt.dimension() == 2);
Dt t2;
Vertex_circulator vc = dt.incident_vertices(vh), done(vc);
do{
CGAL_assertion(!dt.is_infinite(vc));
Vertex_handle vh = t2.insert(vc->point());
vv_map[vh] = vc;
}
while(++vc!=done);
std::vector<std::pair<Vertex_handle, FT> > res;
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool > result =
natural_neighbors_2(t2, vh->point(), std::back_inserter(res));
for(std::size_t i =0; i < res.size(); ++i){
*out++ = std::make_pair(vv_map[res[i].first], res[i].second);
}
result.first = out;
return result;
}
#endif
//class providing a function object:
//OutputIterator has value type
// std::pair< Dt::Geom_traits::Point_2, Dt::Geom_traits::FT>
#if 1
template < class Dt, class OutputIterator, class Fct >
template < class Dt, class OutputIterator, class Fct >
class natural_neighbor_coordinates_2_object
{
public:
@ -468,21 +324,7 @@ public:
}
};
#else
template < class Dt, class OutputIterator >
class natural_neighbor_coordinates_2_object
{
public:
Triple< OutputIterator, typename Dt::Geom_traits::FT, bool >
operator()(const Dt& dt,
typename Dt::Vertex_handle vh,
OutputIterator out) const
{
return natural_neighbor_coordinates_2(dt, vh, out);
}
};
#endif
} //namespace CGAL
#endif // CGAL_NATURAL_NEIGHBOR_COORDINATES_2_H

View File

@ -25,8 +25,7 @@
#include <CGAL/iterator.h>
//for definition of class Project_vertex_output_iterator
#include <CGAL/natural_neighbor_coordinates_2.h>
#include <CGAL/Interpolation/internal/helpers.h>
#include <list>
#include <utility>
@ -305,11 +304,11 @@ regular_neighbor_coordinates_2(const Rt& rt,
//out: the result of the coordinate computation
//vor_vertices: the vertices of the power cell (to avoid
// recomputation)
Project_vertex_output_iterator<OutputIterator> op(out);
Interpolation::internal::Project_vertex_output_iterator<OutputIterator> op(out);
CGAL_precondition(rt.dimension() == 2);
Triple< Project_vertex_output_iterator<OutputIterator>,
Triple< Interpolation::internal::Project_vertex_output_iterator<OutputIterator>,
typename Rt::Geom_traits::FT, bool > result =
regular_neighbor_coordinates_vertex_2(rt, p, op, vor_vertices, start);
@ -352,9 +351,9 @@ regular_neighbor_coordinates_2(const Rt& rt,
//out: the result of the coordinate computation
//vor_vertices: the vertices of the power cell of p
//(to avoid recomputation)
Project_vertex_output_iterator<OutputIterator> op(out);
Interpolation::internal::Project_vertex_output_iterator<OutputIterator> op(out);
Triple< Project_vertex_output_iterator<OutputIterator>,
Triple< Interpolation::internal::Project_vertex_output_iterator<OutputIterator>,
typename Rt::Geom_traits::FT, bool > result =
regular_neighbor_coordinates_vertex_2(rt, p, op , vor_vertices,
hole_begin, hole_end,

View File

@ -46,7 +46,7 @@ sibson_gradient_fitting(ForwardIterator first,
Functor function_value,
const Traits& traits)
{
internal::interpolation::V2P<Traits> v2p(traits);
Interpolation::internal::V2P<Traits> v2p(traits);
CGAL_precondition( first!=beyond && norm!=0);
typedef typename Traits::Aff_transformation_d Aff_transformation;
typedef typename Traits::FT Coord_type;
@ -107,6 +107,7 @@ sibson_gradient_fitting(const Triangul& tr,
traits);
}
template < class Triangul, class ForwardIterator, class Functor, class Traits, class VH>
typename Traits::Vector_d
sibson_gradient_fitting(const Triangul& tr,
@ -149,7 +150,7 @@ sibson_gradient_fitting_internal(const Triangul& tr,
std::vector< std::pair< typename Functor::argument_type, Coord_type> > coords;
Coord_type norm;
typedef typename internal::interpolation::Output_iterator_functor_selector<Triangul, Traits,
typedef typename Interpolation::internal::Output_iterator_functor_selector<Triangul, Traits,
typename Functor::argument_type,
Coord_type>::type Coord_OIF;
@ -196,7 +197,7 @@ sibson_gradient_fitting_nn_2(const Dt& dt,
std::pair< typename Functor::argument_type,
typename Traits::FT > > > CoordInserter;
typedef typename internal::interpolation::Output_iterator_functor_selector<Dt, Traits,
typedef typename Interpolation::internal::Output_iterator_functor_selector<Dt, Traits,
typename Functor::argument_type,
typename Traits::FT>::type Coord_OIF;
@ -217,7 +218,7 @@ sibson_gradient_fitting_nn_2(const Dt& dt,
const Traits& traits)
{
return sibson_gradient_fitting_nn_2(dt, out, function_value,
internal::interpolation::Vertex2Point<Dt, typename Traits::Vector_d>(), traits);
Interpolation::internal::Vertex2Point<Dt, typename Traits::Vector_d>(), traits);
}