| 1 | /******************************************************************************
|
|---|
| 2 | * Qwt Widget Library
|
|---|
| 3 | * Copyright (C) 1997 Josef Wilgen
|
|---|
| 4 | * Copyright (C) 2002 Uwe Rathmann
|
|---|
| 5 | *
|
|---|
| 6 | * This library is free software; you can redistribute it and/or
|
|---|
| 7 | * modify it under the terms of the Qwt License, Version 1.0
|
|---|
| 8 | *****************************************************************************/
|
|---|
| 9 |
|
|---|
| 10 | #ifndef QWT_SPLINE_PARAMETRIZATION_H
|
|---|
| 11 | #define QWT_SPLINE_PARAMETRIZATION_H
|
|---|
| 12 |
|
|---|
| 13 | #include "qwt_global.h"
|
|---|
| 14 | #include "qwt_math.h"
|
|---|
| 15 |
|
|---|
| 16 | #include <qpoint.h>
|
|---|
| 17 |
|
|---|
| 18 | /*!
|
|---|
| 19 | \brief Curve parametrization used for a spline interpolation
|
|---|
| 20 |
|
|---|
| 21 | Parametrization is the process of finding a parameter value for
|
|---|
| 22 | each curve point - usually related to some physical quantity
|
|---|
| 23 | ( distance, time ... ).
|
|---|
| 24 |
|
|---|
| 25 | Often accumulating the curve length is the intended way of parametrization,
|
|---|
| 26 | but as the interpolated curve is not known in advance an approximation
|
|---|
| 27 | needs to be used.
|
|---|
| 28 |
|
|---|
| 29 | The values are calculated by cumulating increments, that are provided
|
|---|
| 30 | by QwtSplineParametrization. As the curve parameters need to be
|
|---|
| 31 | montonically increasing, each increment need to be positive.
|
|---|
| 32 |
|
|---|
| 33 | - t[0] = 0;
|
|---|
| 34 | - t[i] = t[i-1] + valueIncrement( point[i-1], p[i] );
|
|---|
| 35 |
|
|---|
| 36 | QwtSplineParametrization provides the most common used type of
|
|---|
| 37 | parametrizations and offers an interface to inject custom implementations.
|
|---|
| 38 |
|
|---|
| 39 | \note The most relevant types of parametrization are trying to provide an
|
|---|
| 40 | approximation of the curve length.
|
|---|
| 41 |
|
|---|
| 42 | \sa QwtSpline::setParametrization()
|
|---|
| 43 | */
|
|---|
| 44 | class QWT_EXPORT QwtSplineParametrization
|
|---|
| 45 | {
|
|---|
| 46 | public:
|
|---|
| 47 | //! Parametrization type
|
|---|
| 48 | enum Type
|
|---|
| 49 | {
|
|---|
| 50 | /*!
|
|---|
| 51 | No parametrization: t[i] = x[i]
|
|---|
| 52 | \sa valueIncrementX()
|
|---|
| 53 | */
|
|---|
| 54 | ParameterX,
|
|---|
| 55 |
|
|---|
| 56 | /*!
|
|---|
| 57 | No parametrization: t[i] = y[i]
|
|---|
| 58 | \sa valueIncrementY()
|
|---|
| 59 | */
|
|---|
| 60 | ParameterY,
|
|---|
| 61 |
|
|---|
| 62 | /*!
|
|---|
| 63 | Uniform parametrization: t[i] = i;
|
|---|
| 64 |
|
|---|
| 65 | A very fast parametrization, with good results, when the geometry
|
|---|
| 66 | of the control points is somehow "equidistant". F.e. when
|
|---|
| 67 | recording the position of a body, that is moving with constant
|
|---|
| 68 | speed every n seconds.
|
|---|
| 69 |
|
|---|
| 70 | \sa valueIncrementUniform()
|
|---|
| 71 | */
|
|---|
| 72 | ParameterUniform,
|
|---|
| 73 |
|
|---|
| 74 | /*!
|
|---|
| 75 | Parametrization using the chordal length between two control points
|
|---|
| 76 |
|
|---|
| 77 | The chordal length is the most commonly used approximation for
|
|---|
| 78 | the curve length.
|
|---|
| 79 |
|
|---|
| 80 | \sa valueIncrementChordal()
|
|---|
| 81 | */
|
|---|
| 82 | ParameterChordal,
|
|---|
| 83 |
|
|---|
| 84 | /*!
|
|---|
| 85 | Centripetal parametrization
|
|---|
| 86 |
|
|---|
| 87 | Based on the square root of the chordal length.
|
|---|
| 88 |
|
|---|
| 89 | Its name stems from the physical observations regarding
|
|---|
| 90 | the centripetal force, of a body moving along the curve.
|
|---|
| 91 |
|
|---|
| 92 | \sa valueIncrementCentripetal()
|
|---|
| 93 | */
|
|---|
| 94 | ParameterCentripetal,
|
|---|
| 95 |
|
|---|
| 96 |
|
|---|
| 97 | /*!
|
|---|
| 98 | Parametrization using the manhattan length between two control points
|
|---|
| 99 |
|
|---|
| 100 | Approximating the curve length by the manhattan length is faster
|
|---|
| 101 | than the chordal length, but usually gives worse results.
|
|---|
| 102 |
|
|---|
| 103 | \sa valueIncrementManhattan()
|
|---|
| 104 | */
|
|---|
| 105 | ParameterManhattan
|
|---|
| 106 | };
|
|---|
| 107 |
|
|---|
| 108 | explicit QwtSplineParametrization( int type );
|
|---|
| 109 | virtual ~QwtSplineParametrization();
|
|---|
| 110 |
|
|---|
| 111 | int type() const;
|
|---|
| 112 |
|
|---|
| 113 | virtual double valueIncrement( const QPointF&, const QPointF& ) const;
|
|---|
| 114 |
|
|---|
| 115 | static double valueIncrementX( const QPointF&, const QPointF& );
|
|---|
| 116 | static double valueIncrementY( const QPointF&, const QPointF& );
|
|---|
| 117 | static double valueIncrementUniform( const QPointF&, const QPointF& );
|
|---|
| 118 | static double valueIncrementChordal( const QPointF&, const QPointF& );
|
|---|
| 119 | static double valueIncrementCentripetal( const QPointF&, const QPointF& );
|
|---|
| 120 | static double valueIncrementManhattan( const QPointF&, const QPointF& );
|
|---|
| 121 |
|
|---|
| 122 | private:
|
|---|
| 123 | const int m_type;
|
|---|
| 124 | };
|
|---|
| 125 |
|
|---|
| 126 | /*!
|
|---|
| 127 | \brief Calculate the ParameterX value increment for 2 points
|
|---|
| 128 |
|
|---|
| 129 | \param point1 First point
|
|---|
| 130 | \param point2 Second point
|
|---|
| 131 |
|
|---|
| 132 | \return point2.x() - point1.x();
|
|---|
| 133 | */
|
|---|
| 134 | inline double QwtSplineParametrization::valueIncrementX(
|
|---|
| 135 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 136 | {
|
|---|
| 137 | return point2.x() - point1.x();
|
|---|
| 138 | }
|
|---|
| 139 |
|
|---|
| 140 | /*!
|
|---|
| 141 | \brief Calculate the ParameterY value increment for 2 points
|
|---|
| 142 |
|
|---|
| 143 | \param point1 First point
|
|---|
| 144 | \param point2 Second point
|
|---|
| 145 |
|
|---|
| 146 | \return point2.y() - point1.y();
|
|---|
| 147 | */
|
|---|
| 148 | inline double QwtSplineParametrization::valueIncrementY(
|
|---|
| 149 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 150 | {
|
|---|
| 151 | return point2.y() - point1.y();
|
|---|
| 152 | }
|
|---|
| 153 |
|
|---|
| 154 | /*!
|
|---|
| 155 | \brief Calculate the ParameterUniform value increment
|
|---|
| 156 |
|
|---|
| 157 | \param point1 First point
|
|---|
| 158 | \param point2 Second point
|
|---|
| 159 |
|
|---|
| 160 | \return 1.0
|
|---|
| 161 | */
|
|---|
| 162 | inline double QwtSplineParametrization::valueIncrementUniform(
|
|---|
| 163 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 164 | {
|
|---|
| 165 | Q_UNUSED( point1 )
|
|---|
| 166 | Q_UNUSED( point2 )
|
|---|
| 167 |
|
|---|
| 168 | return 1.0;
|
|---|
| 169 | }
|
|---|
| 170 |
|
|---|
| 171 | /*!
|
|---|
| 172 | \brief Calculate the ParameterChordal value increment for 2 points
|
|---|
| 173 |
|
|---|
| 174 | \param point1 First point
|
|---|
| 175 | \param point2 Second point
|
|---|
| 176 |
|
|---|
| 177 | \return qSqrt( dx * dx + dy * dy );
|
|---|
| 178 | */
|
|---|
| 179 | inline double QwtSplineParametrization::valueIncrementChordal(
|
|---|
| 180 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 181 | {
|
|---|
| 182 | const double dx = point2.x() - point1.x();
|
|---|
| 183 | const double dy = point2.y() - point1.y();
|
|---|
| 184 |
|
|---|
| 185 | return std::sqrt( dx * dx + dy * dy );
|
|---|
| 186 | }
|
|---|
| 187 |
|
|---|
| 188 | /*!
|
|---|
| 189 | \brief Calculate the ParameterCentripetal value increment for 2 points
|
|---|
| 190 |
|
|---|
| 191 | \param point1 First point
|
|---|
| 192 | \param point2 Second point
|
|---|
| 193 |
|
|---|
| 194 | \return The square root of a chordal increment
|
|---|
| 195 | */
|
|---|
| 196 | inline double QwtSplineParametrization::valueIncrementCentripetal(
|
|---|
| 197 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 198 | {
|
|---|
| 199 | return std::sqrt( valueIncrementChordal( point1, point2 ) );
|
|---|
| 200 | }
|
|---|
| 201 |
|
|---|
| 202 | /*!
|
|---|
| 203 | \brief Calculate the ParameterManhattan value increment for 2 points
|
|---|
| 204 |
|
|---|
| 205 | \param point1 First point
|
|---|
| 206 | \param point2 Second point
|
|---|
| 207 |
|
|---|
| 208 | \return | point2.x() - point1.x() | + | point2.y() - point1.y() |
|
|---|
| 209 | */
|
|---|
| 210 | inline double QwtSplineParametrization::valueIncrementManhattan(
|
|---|
| 211 | const QPointF& point1, const QPointF& point2 )
|
|---|
| 212 | {
|
|---|
| 213 | return qAbs( point2.x() - point1.x() ) + qAbs( point2.y() - point1.y() );
|
|---|
| 214 | }
|
|---|
| 215 |
|
|---|
| 216 | #endif
|
|---|