The QwtSpline class is used for cubical spline interpolation. Two types of splines, natural and periodic, are supported.
#include <qwt_spline.h> QPolygonF interpolate(const QPolygonF& points, int numValues) { QwtSpline spline; if ( !spline.setPoints(points) ) return points; QPolygonF interpolatedPoints(numValues); const double delta = (points[numPoints - 1].x() - points[0].x()) / (points.size() - 1); for(i = 0; i < points.size(); i++) / interpolate { const double x = points[0].x() + i * delta; interpolatedPoints[i].setX(x); interpolatedPoints[i].setY(spline.value(x)); } return interpolatedPoints; }
Definition at line 77 of file qwt_spline.h.
Public Types | |
enum | SplineType { Natural, Periodic } |
Public Member Functions | |
QwtSpline () | |
QwtSpline (const QwtSpline &) | |
~QwtSpline () | |
QwtSpline & | operator= (const QwtSpline &) |
void | setSplineType (SplineType) |
SplineType | splineType () const |
bool | setPoints (const QPolygonF &points) |
QPolygonF | points () const |
void | reset () |
bool | isValid () const |
double | value (double x) const |
Protected Member Functions | |
bool | buildNaturalSpline (const QPolygonF &) |
bool | buildPeriodicSpline (const QPolygonF &) |
Protected Attributes | |
PrivateData * | d_data |
QwtSpline::QwtSpline | ( | ) |
QwtSpline::~QwtSpline | ( | ) |
bool QwtSpline::setPoints | ( | const QPolygonF & | points | ) |
Determine the function table index corresponding to a value x Calculate the spline coefficients.
Depending on the value of periodic, this function will determine the coefficients for a natural or a periodic spline and store them internally.
x | ||
y | points | |
size | number of points | |
periodic | if true, calculate periodic spline |
x[0] < x[1] < .... < x[n-1]
. If this is not the case, the function will return false Definition at line 126 of file qwt_spline.cpp.
QPolygonF QwtSpline::points | ( | ) | const |
Return points passed by setPoints
Definition at line 164 of file qwt_spline.cpp.
void QwtSpline::reset | ( | ) |
Free allocated memory and set size to 0.
Definition at line 172 of file qwt_spline.cpp.
References d_data.
bool QwtSpline::isValid | ( | ) | const |
double QwtSpline::value | ( | double | x | ) | const |
Calculate the interpolated function value corresponding to a given argument x.
Definition at line 190 of file qwt_spline.cpp.
References d_data.
bool QwtSpline::buildNaturalSpline | ( | const QPolygonF & | points | ) | [protected] |
Determines the coefficients for a natural spline.
Definition at line 209 of file qwt_spline.cpp.
bool QwtSpline::buildPeriodicSpline | ( | const QPolygonF & | points | ) | [protected] |
Determines the coefficients for a periodic spline.
Definition at line 292 of file qwt_spline.cpp.