24 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 34 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 42 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 50 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 58 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 66 inline double operator()(
const QPointF &p1,
const QPointF &p2 )
const 75 inline void init(
int size )
80 inline void start(
double x1,
double y1 )
82 path.moveTo( x1, y1 );
86 double cx2,
double cy2,
double x2,
double y2 )
88 path.cubicTo( cx1, cy1, cx2, cy2, x2, y2 );
109 controlPoints.resize( size );
110 d_cp = controlPoints.data();
113 inline void start(
double x1,
double y1 )
120 double cx2,
double cy2,
double x2,
double y2 )
126 l.setLine( cx1, cy1, cx2, cy2 );
140 const QPointF &p1,
const QPointF &p2,
double slope1 )
142 const double dx = p2.x() - p1.x();
143 const double dy = p2.y() - p1.y();
147 switch( boundaryCondition )
156 const double c2 = 0.5 * boundaryValue;
157 const double c1 = slope1;
159 m = 0.5 * ( 3.0 * dy / dx - c1 - c2 * dx );
164 const double c3 = boundaryValue / 6.0;
165 m = c3 * dx * dx + 2 * dy / dx - slope1;
170 const double s = dy / dx;
171 const double r = qBound( 0.0, boundaryValue, 1.0 );
173 m = s - r * ( s - slope1 );
186 template<
class SplineStore >
188 const QwtSplineC1 *spline,
const QPolygonF &points )
190 const int n = points.size();
192 const QVector<double> m = spline->
slopes( points );
194 return SplineStore();
196 const QPointF *pd = points.constData();
197 const double *md = m.constData();
200 store.init( m.size() - 1 );
201 store.start( pd[0].
x(), pd[0].
y() );
203 for (
int i = 0;
i < n - 1;
i++ )
205 const double dx3 = ( pd[
i+1].x() - pd[
i].x() ) / 3.0;
207 store.addCubic( pd[
i].
x() + dx3, pd[
i].
y() + md[
i] * dx3,
208 pd[
i+1].
x() - dx3, pd[
i+1].
y() - md[
i+1] * dx3,
209 pd[
i+1].
x(), pd[
i+1].
y() );
215 template<
class SplineStore >
217 const QwtSplineC1 *spline,
const QPolygonF &points )
219 const int n = points.size();
221 QPolygonF pointsFlipped( n );
222 for (
int i = 0;
i < n;
i++ )
224 pointsFlipped[
i].setX( points[
i].
y() );
225 pointsFlipped[
i].setY( points[
i].
x() );
228 const QVector<double> m = spline->
slopes( pointsFlipped );
230 return SplineStore();
232 const QPointF *pd = pointsFlipped.constData();
233 const double *md = m.constData();
236 store.init( m.size() - 1 );
237 store.start( pd[0].
y(), pd[0].
x() );
239 QVector<QLineF> lines( n );
240 for (
int i = 0;
i < n - 1;
i++ )
242 const double dx3 = ( pd[
i+1].x() - pd[
i].x() ) / 3.0;
244 store.addCubic( pd[
i].
y() + md[
i] * dx3, pd[
i].
x() + dx3,
245 pd[
i+1].
y() - md[
i+1] * dx3, pd[
i+1].
x() - dx3,
246 pd[
i+1].
y(), pd[
i+1].
x() );
252 template<
class SplineStore,
class Param >
257 const int n = points.size();
259 QPolygonF pointsX, pointsY;
260 pointsX.resize( isClosing ? n + 1 : n );
261 pointsY.resize( isClosing ? n + 1 : n );
263 QPointF *px = pointsX.data();
264 QPointF *py = pointsY.data();
265 const QPointF *p = points.constData();
269 px[0].rx() = py[0].rx() = t;
270 px[0].ry() = p[0].x();
271 py[0].ry() = p[0].y();
273 int numParamPoints = 1;
274 for (
int i = 1;
i < n;
i++ )
276 const double td =
param( points[
i-1], points[
i] );
281 px[numParamPoints].rx() = py[numParamPoints].rx() = t;
283 px[numParamPoints].ry() = p[i].x();
284 py[numParamPoints].ry() = p[i].y();
292 const double td =
param( points[n-1], points[0] );
298 px[numParamPoints].rx() = py[numParamPoints].rx() = t;
300 px[numParamPoints].ry() = p[0].x();
301 py[numParamPoints].ry() = p[0].y();
307 if ( pointsX.size() != numParamPoints )
309 pointsX.resize( numParamPoints );
310 pointsY.resize( numParamPoints );
313 const QVector<double> slopesX = spline->
slopes( pointsX );
314 const QVector<double> slopesY = spline->
slopes( pointsY );
316 const double *mx = slopesX.constData();
317 const double *my = slopesY.constData();
324 store.init( isClosing ? n : n - 1 );
325 store.start( points[0].
x(), points[0].
y() );
329 for (
int i = 0;
i < n - 1;
i++ )
331 const QPointF &p1 = p[
i];
332 const QPointF &p2 = p[
i+1];
334 const double td =
param( p1, p2 );
338 const double t3 = td / 3.0;
340 const double cx1 = p1.x() + mx[j] * t3;
341 const double cy1 = p1.y() + my[j] * t3;
343 const double cx2 = p2.x() - mx[j+1] * t3;
344 const double cy2 = p2.y() - my[j+1] * t3;
346 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
353 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
359 const QPointF &p1 = p[n-1];
360 const QPointF &p2 = p[0];
362 const double td =
param( p1, p2 );
366 const double t3 = td / 3.0;
368 const double cx1 = p1.x() + mx[j] * t3;
369 const double cy1 = p1.y() + my[j] * t3;
371 const double cx2 = p2.x() - mx[0] * t3;
372 const double cy2 = p2.y() - my[0] * t3;
374 store.addCubic( cx1, cy1, cx2, cy2, p2.x(), p2.y() );
378 store.addCubic( p1.x(), p1.y(), p2.x(), p2.y(), p2.x(), p2.y() );
387 template< QwtSplinePolynomial toPolynomial( const QPo
intF &,
double, const QPo
intF &,
double ) >
389 const QPolygonF &points,
const QVector<double> &values,
bool withNodes )
391 QPolygonF fittedPoints;
393 const QPointF *p = points.constData();
394 const double *
v = values.constData();
396 fittedPoints += p[0];
399 const int n = points.size();
401 for (
int i = 0;
i < n - 1;
i++ )
403 const QPointF &p1 = p[
i];
404 const QPointF &p2 = p[
i+1];
408 const double l = p2.x() - p1.x();
412 fittedPoints += QPointF( p1.x() + t, p1.y() + polynomial.
valueAt( t ) );
418 if ( qFuzzyCompare( fittedPoints.last().x(), p2.x() ) )
419 fittedPoints.last() = p2;
436 boundaryType(
QwtSpline::ConditionalBoundaries )
444 boundaryConditions[0].value = 0.0;
447 boundaryConditions[1].value = 0.0;
452 delete parametrization;
463 } boundaryConditions[2];
496 if ( tolerance <= 0.0 )
499 const QPainterPath
path = painterPath( points );
500 const int n = path.elementCount();
504 const QPainterPath::Element el = path.elementAt( 0 );
505 if ( el.type != QPainterPath::MoveToElement )
508 QPointF p1( el.x, el.y );
513 for (
int i = 1;
i < n;
i += 3 )
515 const QPainterPath::Element el1 = path.elementAt(
i );
516 const QPainterPath::Element el2 = path.elementAt(
i + 1 );
517 const QPainterPath::Element el3 = path.elementAt(
i + 2 );
519 const QPointF cp1( el1.x, el1.y );
520 const QPointF cp2( el2.x, el2.y );
521 const QPointF p2( el3.x, el3.y );
576 if ( d_data->parametrization->type() !=
type )
578 delete d_data->parametrization;
592 if ( ( parametrization != NULL ) && ( d_data->parametrization != parametrization ) )
594 delete d_data->parametrization;
595 d_data->parametrization = parametrization;
605 return d_data->parametrization;
617 d_data->boundaryType = boundaryType;
626 return d_data->boundaryType;
640 d_data->boundaryConditions[position].type = condition;
652 return d_data->boundaryConditions[position].type;
654 return d_data->boundaryConditions[0].type;
671 d_data->boundaryConditions[position].value = value;
683 return d_data->boundaryConditions[position].value;
685 return d_data->boundaryConditions[0].value;
699 int condition,
double valueBegin,
double valueEnd )
748 const int n = points.size();
756 path.moveTo( points[0] );
762 path.addPolygon( points );
766 const QVector<QLineF> controlLines = bezierControlLines( points );
767 if ( controlLines.size() < n - 1 )
770 const QPointF *p = points.constData();
771 const QLineF *l = controlLines.constData();
774 for (
int i = 0;
i < n - 1;
i++ )
775 path.cubicTo( l[
i].p1(), l[
i].p2(), p[
i+1] );
778 && ( controlLines.size() >= n ) )
780 path.cubicTo( l[n-1].p1(), l[n-1].p2(), p[0] );
804 const QPolygonF &points,
double tolerance )
const 806 if ( tolerance <= 0.0 )
809 const QVector<QLineF> controlLines = bezierControlLines( points );
810 if ( controlLines.isEmpty() )
817 const QPointF *p = points.constData();
818 const QLineF *cl = controlLines.constData();
820 const int n = controlLines.size();
824 for (
int i = 0;
i < n - 1;
i++ )
826 const QLineF &l = cl[
i];
830 const QPointF &pn = isClosed ? p[0] : p[n];
831 const QLineF &l = cl[n-1];
862 double distance,
bool withNodes )
const 864 if ( distance <= 0.0 )
867 const int n = points.size();
879 const QVector<QLineF> controlLines = bezierControlLines( points );
881 if ( controlLines.size() < n - 1 )
884 path += points.first();
887 const QPointF *p = points.constData();
888 const QLineF *cl = controlLines.constData();
892 for (
int i = 0;
i < n - 1;
i++ )
899 cl[i].p2(), p[i+1], t / l );
906 if ( qFuzzyCompare( path.last().x(), p[i+1].x() ) )
907 path.last() = p[i+1];
920 && ( controlLines.size() >= n ) )
927 cl[n-1].p2(), p[0], t / l );
932 if ( qFuzzyCompare( path.last().x(), p[0].x() ) )
979 if ( points.size() < 2 )
985 points[0], points[1], slopeNext );
997 const int n = points.size();
999 const QPointF p1( points[n-1].
x(), -points[n-1].
y() );
1000 const QPointF p2( points[n-2].
x(), -points[n-2].
y() );
1043 const int n = points.size();
1050 switch( parametrization()->
type() )
1054 store = qwtSplineC1PathParamX<PathStore>(
this, points );
1059 store = qwtSplineC1PathParamY<PathStore>(
this, points );
1064 store = qwtSplineC1PathParametric<PathStore>(
1070 store = qwtSplineC1PathParametric<PathStore>(
1076 store = qwtSplineC1PathParametric<PathStore>(
1082 store = qwtSplineC1PathParametric<PathStore>(
1083 this, points,
param( parametrization() ) );
1103 const int n = points.size();
1105 return QVector<QLineF>();
1108 switch( parametrization()->type() )
1112 store = qwtSplineC1PathParamX<ControlPointsStore>(
this, points );
1117 store = qwtSplineC1PathParamY<ControlPointsStore>(
this, points );
1122 store = qwtSplineC1PathParametric<ControlPointsStore>(
1128 store = qwtSplineC1PathParametric<ControlPointsStore>(
1134 store = qwtSplineC1PathParametric<ControlPointsStore>(
1140 store = qwtSplineC1PathParametric<ControlPointsStore>(
1141 this, points,
param( parametrization() ) );
1145 return store.controlPoints;
1166 double distance,
bool withNodes )
const 1170 if ( points.size() > 2 )
1172 const QVector<double> m = slopes( points );
1173 if ( m.size() != points.size() )
1176 return qwtPolygonParametric<QwtSplinePolynomial::fromSlopes>(
1177 distance, points, m, withNodes );
1200 const QPolygonF &points )
const 1202 QVector<QwtSplinePolynomial> polynomials;
1204 const QVector<double> m = slopes( points );
1208 polynomials.reserve( m.size() - 1 );
1209 for (
int i = 1;
i < m.size();
i++ )
1212 points[
i-1], m[
i-1], points[
i], m[i] );
1294 double distance,
bool withNodes )
const 1298 if ( points.size() > 2 )
1300 const QVector<double> cv = curvatures( points );
1301 if ( cv.size() != points.size() )
1304 return qwtPolygonParametric<QwtSplinePolynomial::fromCurvatures>(
1305 distance, points, cv, withNodes );
1339 const QVector<double> curvatures = this->curvatures( points );
1340 if ( curvatures.size() < 2 )
1341 return QVector<double>();
1343 QVector<double> slopes( curvatures.size() );
1345 const double *cv = curvatures.constData();
1346 double *m = slopes.data();
1348 const int n = points.size();
1349 const QPointF *p = points.constData();
1353 for (
int i = 0;
i < n - 1;
i++ )
1356 m[i] = polynomial.
c1;
1359 m[n-1] = polynomial.
slopeAt( p[n-1].
x() - p[n-2].
x() );
1381 QVector<QwtSplinePolynomial> polynomials;
1383 const QVector<double> curvatures = this->curvatures( points );
1384 if ( curvatures.size() < 2 )
1387 const QPointF *p = points.constData();
1388 const double *cv = curvatures.constData();
1389 const int n = curvatures.size();
1390 polynomials.reserve( n - 1 );
1392 for (
int i = 1;
i < n;
i++ )
1395 p[
i-1], cv[
i-1], p[
i], cv[i] );
Curve parametrization used for a spline interpolation.
static QPointF pointAt(const QPointF &p1, const QPointF &cp1, const QPointF &cp2, const QPointF &p2, double t)
virtual ~QwtSplineC1()
Destructor.
virtual QPainterPath painterPath(const QPolygonF &) const
Interpolate a curve with Bezier curves.
double operator()(const QPointF &p1, const QPointF &p2) const
virtual uint locality() const
static QPolygonF qwtPolygonParametric(double distance, const QPolygonF &points, const QVector< double > &values, bool withNodes)
void appendToPolygon(const QPointF &p1, const QPointF &cp1, const QPointF &cp2, const QPointF &p2, QPolygonF &polygon) const
Interpolate a Bézier curve by a polygon.
double c1
coefficient of the linear summand
static double valueIncrementCentripetal(const QPointF &, const QPointF &)
Calculate the ParameterCentripetal value increment for 2 points.
double slopeAt(double x) const
virtual QPainterPath painterPath(const QPolygonF &) const
Calculate an interpolated painter path.
virtual QPolygonF equidistantPolygon(const QPolygonF &, double distance, bool withNodes) const
Find an interpolated polygon with "equidistant" points.
QwtSplineParametrization * parametrization
static double valueIncrementChordal(const QPointF &, const QPointF &)
Calculate the ParameterChordal value increment for 2 points.
param(const QwtSplineParametrization *p)
static SplineStore qwtSplineC1PathParamX(const QwtSplineC1 *spline, const QPolygonF &points)
double valueAt(double x) const
QwtSplineG1()
Constructor.
virtual QVector< double > slopes(const QPolygonF &) const =0
Find the first derivative at the control points.
virtual ~QwtSplineG1()
Destructor.
virtual QVector< QwtSplinePolynomial > polynomials(const QPolygonF &) const
Calculate the interpolating polynomials for a non parametric spline.
virtual QVector< QLineF > bezierControlLines(const QPolygonF &) const
Interpolate a curve with Bezier curves.
Base class for all splines.
double operator()(const QPointF &p1, const QPointF &p2) const
double slopeBoundary(int boundaryCondition, double boundaryValue, const QPointF &p1, const QPointF &p2, double slope1)
TFSIMD_FORCE_INLINE const tfScalar & y() const
const QwtSplineParametrization * parametrization() const
the condiation is at the end of the polynomial
static SplineStore qwtSplineC1PathParametric(const QwtSplineC1 *spline, const QPolygonF &points, Param param)
void setBoundaryConditions(int condition, double valueBegin=0.0, double valueEnd=0.0)
Define the condition at the endpoints of a spline.
void setBoundaryCondition(BoundaryPosition, int condition)
Define the condition for an endpoint of the spline.
virtual ~QwtSplineC2()
Destructor.
double operator()(const QPointF &p1, const QPointF &p2) const
virtual double valueIncrement(const QPointF &, const QPointF &) const
Calculate the parameter value increment for 2 points.
QwtSplineC2()
Constructor.
virtual QPolygonF equidistantPolygon(const QPolygonF &, double distance, bool withNodes) const
Find an interpolated polygon with "equidistant" points.
QwtSpline::BoundaryType boundaryType
A cubic polynomial without constant term.
Base class for spline interpolations providing a first order parametric continuity ( C1 ) between adj...
const QwtSplineParametrization * parameter
the condiation is at the beginning of the polynomial
GraphId path[kMaxDeadlockPathLen]
An implementation of the de Casteljau’s Algorithm for interpolating Bézier curves.
virtual QPolygonF equidistantPolygon(const QPolygonF &, double distance, bool withNodes) const
Find an interpolated polygon with "equidistant" points.
virtual QPainterPath painterPath(const QPolygonF &) const
Interpolate a curve with Bezier curves.
static double valueIncrementY(const QPointF &, const QPointF &)
Calculate the ParameterY value increment for 2 points.
void setBoundaryValue(BoundaryPosition, double value)
Define the boundary value.
virtual ~QwtSplineInterpolating()
Destructor.
double operator()(const QPointF &p1, const QPointF &p2) const
TFSIMD_FORCE_INLINE const tfScalar & x() const
void addCubic(double cx1, double cy1, double cx2, double cy2, double x2, double y2)
virtual ~QwtSpline()
Destructor.
void addCubic(double cx1, double cy1, double cx2, double cy2, double x2, double y2)
int boundaryCondition(BoundaryPosition) const
double operator()(const QPointF &p1, const QPointF &p2) const
static double valueIncrementUniform(const QPointF &, const QPointF &)
Calculate the ParameterUniform value increment.
QVector< QLineF > controlPoints
static QwtSplinePolynomial fromSlopes(const QPointF &p1, double m1, const QPointF &p2, double m2)
QwtSplineC1()
Constructor.
QwtSplineInterpolating()
Constructor.
void setParametrization(int type)
virtual QPolygonF polygon(const QPolygonF &, double tolerance) const
Interpolate a curve by a polygon.
virtual QPolygonF polygon(const QPolygonF &, double tolerance) const
Interpolate a curve by a polygon.
static SplineStore qwtSplineC1PathParamY(const QwtSplineC1 *spline, const QPolygonF &points)
void start(double x1, double y1)
virtual double slopeAtBeginning(const QPolygonF &, double slopeNext) const
virtual QVector< double > slopes(const QPolygonF &) const
Find the first derivative at the control points.
static QwtSplinePolynomial fromCurvatures(const QPointF &p1, double cv1, const QPointF &p2, double cv2)
virtual QVector< QwtSplinePolynomial > polynomials(const QPolygonF &) const
Calculate the interpolating polynomials for a non parametric spline.
virtual QVector< QLineF > bezierControlLines(const QPolygonF &) const
Interpolate a curve with Bezier curves.
virtual double slopeAtEnd(const QPolygonF &, double slopeBefore) const
BoundaryType boundaryType() const
double boundaryValue(BoundaryPosition) const
void start(double x1, double y1)
void setBoundaryType(BoundaryType)
static double valueIncrementManhattan(const QPointF &, const QPointF &)
Calculate the ParameterManhattan value increment for 2 points.