ProteoWizard
interpolate.hpp
Go to the documentation of this file.
1 //
2 // $Id: interpolate.hpp 5313 2013-12-17 18:06:54Z chambm $
3 //
4 //
5 // Original author: Witold Wolski <wewolski@gmail.com>
6 //
7 // Copyright : ETH Zurich
8 //
9 // Licensed under the Apache License, Version 2.0 (the "License");
10 // you may not use this file except in compliance with the License.
11 // You may obtain a copy of the License at
12 //
13 // http://www.apache.org/licenses/LICENSE-2.0
14 //
15 // Unless required by applicable law or agreed to in writing, software
16 // distributed under the License is distributed on an "AS IS" BASIS,
17 // WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 // See the License for the specific language governing permissions and
19 // limitations under the License.
20 //
21 
22 
23 #ifndef EQUISPACEINTERPOLATION_H
24 #define EQUISPACEINTERPOLATION_H
25 
26 #include <utility>
27 #include <limits>
28 #include <vector>
29 #include <assert.h>
30 
32 
33 
34 /// EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
35 /// Interpolation on a equidistantly spaced grid. The Values y are located at a grid [0,1,..., len(y)].
36 ///
37 /// For equidistantly spaced y at a grid [0,1,..., len(y)] the \f$ x_{i}\f$ and \f$x_{i+1}\f$ enclosing \f$x_{out}\f$
38 /// can be found efficiently by i = floor(xout). Furthermore for \f$ x_{i+1} - x_{i} = 1 \f$ the interpolation formulas are simple.
39 /// Therefore, w provided this specialized implementation of interpolation functions.
40 /// Each segment (bounded by two data points) can be interpolated independently.
41 /// The parameter mu defines where to estimate the value on the interpolated line, it is 0 at the first point and 1 and the second point.
42 /// For interpolated values between the two points mu ranges between 0 and 1. Values of mu outside this range result in extrapolation.
43 /// This convention is followed for all the subsequent methods below.
44 
45 
46 namespace ralab
47 {
48  namespace base
49  {
50  namespace base
51  {
52  /// affine interpolation on equidistantly spaced y. The y's are located at 0,1,2....,len(y).
53  /// For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.
54 
55  template <typename YInputIterator,
56  typename XInputIterator,
57  typename OutputIterator>
59  YInputIterator begY, //!< y values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
60  YInputIterator endY,
61  XInputIterator begX, //!< points to interpolate at
62  XInputIterator endX,
63  OutputIterator out, //!< interpolated values, same length as x.
64  int start_index = 0, //!< if y values are placed on a grid with start_index != 0
65  typename std::iterator_traits<OutputIterator>::value_type epsilon =
66  std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon()
67  )
68  {
69  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
71  utilities::interpolateLinearCosine(begY , endY , begX , endX , out , functor , start_index);
72  }// end interpolate cubic
73 
74 
75 
76  /// cosine interpolation on equidistantly spaced y. The y's are located at 0,1,2....,len(y).
77  /// For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.
78 
79  template <typename YInputIterator,
80  typename XInputIterator,
81  typename OutputIterator
82  >
84  YInputIterator begY, //!< y values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
85  YInputIterator endY,
86  XInputIterator begX, //!< points to interpolate at
87  XInputIterator endX,
88  OutputIterator out, //!< interpolated values, same length as x.
89  int start_index = 0 //!< if y values are placed on a grid with start_index != 0
90  )
91  {
92  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
94  utilities::interpolateLinearCosine(begY,endY ,begX,endX, out,functor, start_index);
95  }// end interpolate cubic
96 
97 
98 
99  /// cubic interpolation on equidistantly spaced y's. The y's are located at 0,1,2....,len(y).
100  /// For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.
101 
102  template <typename YInputIterator,
103  typename XInputIterator,
104  typename OutputIterator>
106  YInputIterator begY, //!< y values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
107  YInputIterator endY,
108  XInputIterator begX, //!< points to interpolate at
109  XInputIterator endX,
110  OutputIterator out, //!< interpolated values, same length as x.
111  int start_index = 0, //!< if y values are placed on a grid with start_index != 0
112  typename std::iterator_traits<OutputIterator>::value_type epsilon =
113  std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon()
114  )
115  {
116  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
118  utilities::interpolateCubicHermite(begY,endY ,begX,endX, out,functor, start_index);
119  }// end interpolate cubic
120 
121 
122  /// Hermite interpolation on equidistantly spaced y's. The y's are located at 0,1,2....,len(y).
123  /// For x's < 0 or x's > len(y) y[0] or y[len(y) -1 ] is used.
124 
125  template <
126  typename YInputIterator,
127  typename XInputIterator,
128  typename OutputIterator
129  >
131  YInputIterator begY, //!< y values equidistantly spaced. spacing is [0,1,2, .... ,len(y)]
132  YInputIterator endY,
133  XInputIterator begX, //!< points to interpolate at
134  XInputIterator endX,
135  OutputIterator out, //!< interpolated values, same length as x.
136  double tension = 0, //!< 1 is high, 0 normal, -1 is low
137  double bias = 0, //!< 0 is even, positive is towards first segment, negative towards the other
138  int start_index = 0, //!< if y values are placed on a grid with start_index != 0
139  typename std::iterator_traits<OutputIterator>::value_type epsilon =
140  std::numeric_limits<typename std::iterator_traits<OutputIterator>::value_type>::epsilon()
141  )
142  {
143  typedef typename std::iterator_traits<OutputIterator>::value_type TReal;
144  utilities::HermiteInterpolate<TReal> functor(tension, bias, epsilon);
145  utilities::interpolateCubicHermite( begY , endY , begX , endX , out , functor , start_index );
146  }// end interpolate cubic
147  }//base
148  }//namespace base
149 }//namespace ralab
150 
151 
152 #endif // EQUISPACEINTERPOLATION_H
void interpolate_cubic(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
cubic interpolation on equidistantly spaced y&#39;s.
CosineInterpolate Functor Linear interpolation results in discontinuities at each point...
void interpolate_cosine(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0)
cosine interpolation on equidistantly spaced y.
Definition: interpolate.hpp:83
const double epsilon
Definition: DiffTest.cpp:41
static void interpolateCubicHermite(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, TFunctor &functor, int start_index=0)
Cubic or Hermite interpolation worker.
EQUISPACEINTERPOL Interpolation on a equidistantly spaced grid.
Definition: base.hpp:39
static void interpolateLinearCosine(YInputIterator y_p, YInputIterator endY, XInputIterator x_p, XInputIterator endX, OutputIterator out_p, TFunctor &interpolator, int start_index=0)
Linear cubic interpolator worker.
void interpolate_linear(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
affine interpolation on equidistantly spaced y.
Definition: interpolate.hpp:58
void interpolate_Hermite(YInputIterator begY, YInputIterator endY, XInputIterator begX, XInputIterator endX, OutputIterator out, double tension=0, double bias=0, int start_index=0, typename std::iterator_traits< OutputIterator >::value_type epsilon=std::numeric_limits< typename std::iterator_traits< OutputIterator >::value_type >::epsilon())
Hermite interpolation on equidistantly spaced y&#39;s.