Engauge Digitizer
2
Toggle main menu visibility
Loading...
Searching...
No Matches
Spline
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
14
enum
SplineTCheck
{
15
SPLINE_ENABLE_T_CHECK
,
16
SPLINE_DISABLE_T_CHECK
17
};
18
29
class
Spline
30
{
32
friend
class
TestSpline
;
33
34
public
:
38
Spline
(
const
std::vector<double> &t,
39
const
std::vector<SplinePair> &xy,
40
SplineTCheck
splineTCheck =
SPLINE_ENABLE_T_CHECK
);
41
42
virtual
~Spline
();
43
48
void
computeUntranslatedCoefficients
(
double
aTranslated,
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
60
SplinePair
findSplinePairForFunctionX
(
double
x,
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
77
private
:
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
SplineCoeff.h
SplinePair.h
SplineTCheck
SplineTCheck
Definition
Spline.h:14
SPLINE_ENABLE_T_CHECK
@ SPLINE_ENABLE_T_CHECK
Definition
Spline.h:15
SPLINE_DISABLE_T_CHECK
@ SPLINE_DISABLE_T_CHECK
Definition
Spline.h:16
SplinePair
Single X/Y pair for cubic spline interpolation initialization and calculations.
Definition
SplinePair.h:15
Spline::~Spline
virtual ~Spline()
Definition
Spline.cpp:28
Spline::TestSpline
friend class TestSpline
For unit testing.
Definition
Spline.h:32
Spline::p2
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
Spline::interpolateControlPoints
SplinePair interpolateControlPoints(double t) const
Return interpolated y for specified x, for testing.
Definition
Spline.cpp:246
Spline::findSplinePairForFunctionX
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
Spline::Spline
Spline(const std::vector< double > &t, const std::vector< SplinePair > &xy, SplineTCheck splineTCheck=SPLINE_ENABLE_T_CHECK)
Initialize spline with independent (t) and dependent (x and y) value vectors.
Definition
Spline.cpp:13
Spline::p1
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
Spline::computeUntranslatedCoefficients
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
Spline::interpolateCoeff
SplinePair interpolateCoeff(double t) const
Return interpolated y for specified x.
Definition
Spline.cpp:233
Generated on
for Engauge Digitizer by
1.17.0