Engauge Digitizer 2
Loading...
Searching...
No Matches
Spline.h
Go to the documentation of this file.
1/******************************************************************************************************
2 * (C) 2014 markummitchell@github.com. This file is part of Engauge Digitizer, which is released *
3 * under GNU General Public License version 2 (GPLv2) or (at your option) any later version. See file *
4 * LICENSE or go to gnu.org/licenses for details. Distribution requires prior written permission. *
5 ******************************************************************************************************/
6
7#ifndef SPLINE_H
8#define SPLINE_H
9
10#include "SplineCoeff.h"
11#include "SplinePair.h"
12#include <vector>
13
18
29class Spline
30{
32 friend class TestSpline;
33
34 public:
38 Spline(const std::vector<double> &t,
39 const std::vector<SplinePair> &xy,
41
42 virtual ~Spline();
43
49 double bTranslated,
50 double cTranslated,
51 double dTranslated,
52 double tI,
53 double &aUntranslated,
54 double &bUntranslated,
55 double &cUntranslated,
56 double &dUntranslated) const;
57
61 int numIterations) const;
62
65 SplinePair interpolateCoeff (double t) const;
66
69 SplinePair interpolateControlPoints (double t) const;
70
72 SplinePair p1 (unsigned int i) const;
73
75 SplinePair p2 (unsigned int i) const;
76
77private:
78 Spline();
79
80 // Although coefficient interpolation works for successive t values not 1.0 apart, the control point interpolation
81 // does not so we check the increments. Note that the starting value is arbitrary. Removing this restriction will
82 // mean upgrading the code to allow arbitrary t increments
83 void checkTIncrements (const std::vector<double> &t) const;
84
85 void computeCoefficientsForIntervals (const std::vector<double> &t,
86 const std::vector<SplinePair> &xy);
87 void computeControlPointsForIntervals ();
88
89 // Coefficients a,b,c,d
90 std::vector<SplineCoeff> m_elements;
91
92 // Input times
93 std::vector<double> m_t;
94
95 // Input points
96 std::vector<SplinePair> m_xy;
97
98 // Control points for each interval
99 std::vector<SplinePair> m_p1;
100 std::vector<SplinePair> m_p2;
101};
102
103#endif // SPLINE_H
const int INNER_RADIUS_MIN
SplineTCheck
Definition Spline.h:14
@ SPLINE_ENABLE_T_CHECK
Definition Spline.h:15
@ SPLINE_DISABLE_T_CHECK
Definition Spline.h:16
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition SplinePair.h:14
Cubic interpolation given independent and dependent value vectors.
Definition Spline.h:30
virtual ~Spline()
Definition Spline.cpp:28
SplinePair p2(unsigned int i) const
Bezier p2 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
Definition Spline.cpp:276
SplinePair interpolateControlPoints(double t) const
Return interpolated y for specified x, for testing.
Definition Spline.cpp:246
SplinePair findSplinePairForFunctionX(double x, int numIterations) const
Use bisection algorithm to iteratively find the SplinePair interpolated to best match the specified x...
Definition Spline.cpp:172
SplinePair p1(unsigned int i) const
Bezier p1 control point for specified interval. P0 is m_xy[i] and P3 is m_xy[i+1].
Definition Spline.cpp:269
void computeUntranslatedCoefficients(double aTranslated, double bTranslated, double cTranslated, double dTranslated, double tI, double &aUntranslated, double &bUntranslated, double &cUntranslated, double &dUntranslated) const
From coefficients in xy=d*(t-ti)^3+c*(t-ti)^2+b*(t-ti)+a we compute and return the coefficients in xy...
Definition Spline.cpp:145
SplinePair interpolateCoeff(double t) const
Return interpolated y for specified x.
Definition Spline.cpp:233
Unit test of spline library.
Definition TestSpline.h:13