From 2bc8e236533fa662c547ad19dd5d5d7f63a1cb6c Mon Sep 17 00:00:00 2001 From: Andreas Fabri Date: Tue, 19 Dec 2017 17:44:08 +0000 Subject: [PATCH] move helper classes in a subdirectory/namespace/file --- .../CGAL/Interpolation/internal/helpers.h | 160 +++++++++++++++ .../include/CGAL/interpolation_functions.h | 44 +---- .../CGAL/natural_neighbor_coordinates_2.h | 186 ++---------------- .../CGAL/regular_neighbor_coordinates_2.h | 11 +- .../include/CGAL/sibson_gradient_fitting.h | 9 +- 5 files changed, 189 insertions(+), 221 deletions(-) create mode 100644 Interpolation/include/CGAL/Interpolation/internal/helpers.h diff --git a/Interpolation/include/CGAL/Interpolation/internal/helpers.h b/Interpolation/include/CGAL/Interpolation/internal/helpers.h new file mode 100644 index 00000000000..1dfd0125d5e --- /dev/null +++ b/Interpolation/include/CGAL/Interpolation/internal/helpers.h @@ -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 + + +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 + 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 argument_type; + typedef std::pair result_type; + + result_type operator()(const argument_type& vp) const + { + return std::make_pair(vp.first->point(), vp.second); + } + }; + + + template + 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; + + 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 + struct Output_iterator_functor_selector + { + typedef CGAL::Identity > type; + }; + + + template + struct Output_iterator_functor_selector + { + typedef Interpolation::internal::Vertex2Point 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 + //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 + // 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; + + //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 + 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 diff --git a/Interpolation/include/CGAL/interpolation_functions.h b/Interpolation/include/CGAL/interpolation_functions.h index 7c3bad04d73..44e15a4a58b 100644 --- a/Interpolation/include/CGAL/interpolation_functions.h +++ b/Interpolation/include/CGAL/interpolation_functions.h @@ -23,6 +23,7 @@ #include +#include #include #include @@ -31,41 +32,6 @@ #include 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 - 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 v2p(traits); + Interpolation::internal::V2P 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 v2p(traits); + Interpolation::internal::V2P 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 v2p(traits); + Interpolation::internal::V2P 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 v2p(traits); + Interpolation::internal::V2P v2p(traits); typename Functor::result_type f; typename GradFunctor::result_type grad; diff --git a/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h b/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h index 10601dc1b5b..5ee31e3c817 100644 --- a/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h +++ b/Interpolation/include/CGAL/natural_neighbor_coordinates_2.h @@ -22,7 +22,7 @@ #define CGAL_NATURAL_NEIGHBOR_COORDINATES_2_H #include - +#include #include #include #include @@ -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 argument_type; - typedef std::pair result_type; - - result_type operator()(const argument_type& vp) const - { - return std::make_pair(vp.first->point(), vp.second); - } - }; - - template - 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; - - 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 - struct Output_iterator_functor_selector - { - typedef CGAL::Identity > type; - }; - - template - struct Output_iterator_functor_selector - { - typedef internal::interpolation::Vertex2Point 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 -//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 - // 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; - - //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 - 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 @@ -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 op(out, fct); + Interpolation::internal::Project_vertex_output_iterator op(out, fct); - Triple, + Triple, 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(), start); + Interpolation::internal::Vertex2Point(), 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 op(out); + Interpolation::internal::Project_vertex_output_iterator op(out); - Triple, + Triple, 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 v2v(correspondence_map, dt); - Unary_compose_1 > cfct(fct,v2v); + Interpolation::internal::Vertex2Vertex v2v(correspondence_map, dt); + Unary_compose_1 > cfct(fct,v2v); return natural_neighbor_coordinates_2(t2, vh->point(), out, cfct); } + template 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()); + Interpolation::internal::Vertex2Point()); } -#if 0 -/**********************************************************/ -// AF added -// writes pair 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 -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 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 > 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 diff --git a/Interpolation/include/CGAL/regular_neighbor_coordinates_2.h b/Interpolation/include/CGAL/regular_neighbor_coordinates_2.h index 02e515d603f..ea04a3c43c4 100644 --- a/Interpolation/include/CGAL/regular_neighbor_coordinates_2.h +++ b/Interpolation/include/CGAL/regular_neighbor_coordinates_2.h @@ -25,8 +25,7 @@ #include -//for definition of class Project_vertex_output_iterator -#include +#include #include #include @@ -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 op(out); + Interpolation::internal::Project_vertex_output_iterator op(out); CGAL_precondition(rt.dimension() == 2); - Triple< Project_vertex_output_iterator, + Triple< Interpolation::internal::Project_vertex_output_iterator, 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 op(out); + Interpolation::internal::Project_vertex_output_iterator op(out); - Triple< Project_vertex_output_iterator, + Triple< Interpolation::internal::Project_vertex_output_iterator, typename Rt::Geom_traits::FT, bool > result = regular_neighbor_coordinates_vertex_2(rt, p, op , vor_vertices, hole_begin, hole_end, diff --git a/Interpolation/include/CGAL/sibson_gradient_fitting.h b/Interpolation/include/CGAL/sibson_gradient_fitting.h index 9e26dd75c95..7cbb99fd4d2 100644 --- a/Interpolation/include/CGAL/sibson_gradient_fitting.h +++ b/Interpolation/include/CGAL/sibson_gradient_fitting.h @@ -46,7 +46,7 @@ sibson_gradient_fitting(ForwardIterator first, Functor function_value, const Traits& traits) { - internal::interpolation::V2P v2p(traits); + Interpolation::internal::V2P 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::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::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(), traits); + Interpolation::internal::Vertex2Point(), traits); }