| 1 | //
|
---|
| 2 | // C++ Interface: CubicSplineInterpolator1D
|
---|
| 3 | //
|
---|
| 4 | // Description:
|
---|
| 5 | //
|
---|
| 6 | //
|
---|
| 7 | // Author: Takeshi Nakazato <takeshi.nakazato@nao.ac.jp>, (C) 2012
|
---|
| 8 | //
|
---|
| 9 | // Copyright: See COPYING file that comes with this distribution
|
---|
| 10 | //
|
---|
| 11 | //
|
---|
| 12 | #ifndef ASAP_CUBIC_SPLINE_INTERPOLATOR_1D_H
|
---|
| 13 | #define ASAP_CUBIC_SPLINE_INTERPOLATOR_1D_H
|
---|
| 14 |
|
---|
| 15 | #include "Interpolator1D.h"
|
---|
| 16 |
|
---|
| 17 | namespace asap {
|
---|
| 18 |
|
---|
| 19 | /**
|
---|
| 20 | * Implementation of (natural) cubic spline interpolation.
|
---|
| 21 | * @author TakeshiNakazato
|
---|
| 22 | */
|
---|
| 23 | template <class T, class U>
|
---|
| 24 | class CubicSplineInterpolator1D : public Interpolator1D<T, U> {
|
---|
| 25 | public:
|
---|
| 26 | // Default constructor.
|
---|
| 27 | CubicSplineInterpolator1D();
|
---|
| 28 |
|
---|
| 29 | // Destructor.
|
---|
| 30 | virtual ~CubicSplineInterpolator1D();
|
---|
| 31 |
|
---|
| 32 | // Override Interpolator1D::setData.
|
---|
| 33 | // @see Interpolator1D::setData
|
---|
| 34 | void setData(T *x, U *y, unsigned int n);
|
---|
| 35 |
|
---|
| 36 | // Override Interpolate1D::setX.
|
---|
| 37 | // @see Interpolate1D::setX()
|
---|
| 38 | void setX(T *x, unsigned int n);
|
---|
| 39 |
|
---|
| 40 | // Override Interpolator1D::setY.
|
---|
| 41 | // @see Interpolator1D::setY()
|
---|
| 42 | void setY(U *y, unsigned int n);
|
---|
| 43 |
|
---|
| 44 | // Perform interpolation.
|
---|
| 45 | // @param[in] x horizontal location where the value is evaluated
|
---|
| 46 | // by interpolation.
|
---|
| 47 | // @return interpolated value at x.
|
---|
| 48 | U interpolate(T x);
|
---|
| 49 | private:
|
---|
| 50 | // Determine second derivatives of each point based on
|
---|
| 51 | // natural cubic spline condition (second derivative at each
|
---|
| 52 | // end is zero).
|
---|
| 53 | void evaly2();
|
---|
| 54 |
|
---|
| 55 | // Do interpolation using second derivatives determined by evaly2().
|
---|
| 56 | // @param[in] x horizontal location where the value is evaluated
|
---|
| 57 | // by interpolation.
|
---|
| 58 | // @param[in] i location index for x.
|
---|
| 59 | // @return interpolated value at x.
|
---|
| 60 | U dospline(T x, unsigned int i);
|
---|
| 61 |
|
---|
| 62 | // Array to store second derivatives on the data points.
|
---|
| 63 | U *y2_;
|
---|
| 64 |
|
---|
| 65 | // number of data points for second derivatives
|
---|
| 66 | unsigned int ny2_;
|
---|
| 67 |
|
---|
| 68 | // Boolean parameter whether buffered values are effective or not.
|
---|
| 69 | bool reusable_;
|
---|
| 70 | };
|
---|
| 71 |
|
---|
| 72 | }
|
---|
| 73 |
|
---|
| 74 | #include "CubicSplineInterpolator1D.tcc"
|
---|
| 75 |
|
---|
| 76 | #endif
|
---|