Changeset 11158 in ntrip for trunk/BNC/qwt/qwt_spline.h


Ignore:
Timestamp:
Nov 3, 2026, 10:53:35 AM (4 weeks ago)
Author:
stuerze
Message:

deprecated functions exchanged libs updated

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/BNC/qwt/qwt_spline.h

    r4271 r11158  
    1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
     1/******************************************************************************
    22 * Qwt Widget Library
    33 * Copyright (C) 1997   Josef Wilgen
    … …  
    1212
    1313#include "qwt_global.h"
    14 #include <qpolygon.h>
    15 #include <qvector.h>
    16 
    17 /*!
    18   \brief A class for spline interpolation
    19 
    20   The QwtSpline class is used for cubical spline interpolation.
    21   Two types of splines, natural and periodic, are supported.
    22 
    23   \par Usage:
    24   <ol>
    25   <li>First call setPoints() to determine the spline coefficients
    26       for a tabulated function y(x).
    27   <li>After the coefficients have been set up, the interpolated
    28       function value for an argument x can be determined by calling
    29       QwtSpline::value().
    30   </ol>
    31 
    32   \par Example:
    33   \code
    34 #include <qwt_spline.h>
    35 
    36 QPolygonF interpolate(const QPolygonF& points, int numValues)
    37 {
    38     QwtSpline spline;
    39     if ( !spline.setPoints(points) )
    40         return points;
    41 
    42     QPolygonF interpolatedPoints(numValues);
    43 
    44     const double delta =
    45         (points[numPoints - 1].x() - points[0].x()) / (points.size() - 1);
    46     for(i = 0; i < points.size(); i++)  / interpolate
     14#include "qwt_spline.h"
     15
     16class QwtSplineParametrization;
     17class QwtSplinePolynomial;
     18class QPainterPath;
     19class QLineF;
     20class QPolygonF;
     21
     22#if QT_VERSION < 0x060000
     23template< typename T > class QVector;
     24#endif
     25
     26/*!
     27   \brief Base class for all splines
     28
     29   A spline is a curve represented by a sequence of polynomials. Spline approximation
     30   is the process of finding polynomials for a given set of points.
     31   When the algorithm preserves the initial points it is called interpolating.
     32
     33   Splines can be classified according to conditions of the polynomials that
     34   are met at the start/endpoints of the pieces:
     35
     36   - Geometric Continuity
     37
     38    - G0: polynomials are joined
     39    - G1: first derivatives are proportional at the join point
     40          The curve tangents thus have the same direction, but not necessarily the
     41          same magnitude. i.e., C1'(1) = (a,b,c) and C2'(0) = (k*a, k*b, k*c).
     42    - G2: first and second derivatives are proportional at join point
     43
     44   - Parametric Continuity
     45
     46    - C0: curves are joined
     47    - C1: first derivatives equal
     48    - C2: first and second derivatives are equal
     49
     50   Geometric continuity requires the geometry to be continuous, while parametric
     51   continuity requires that the underlying parameterization be continuous as well.
     52   Parametric continuity of order n implies geometric continuity of order n,
     53   but not vice-versa.
     54
     55   QwtSpline is the base class for spline approximations of any continuity.
     56 */
     57class QWT_EXPORT QwtSpline
     58{
     59  public:
     60    /*!
     61       Boundary type specifying the spline at its endpoints
     62
     63       \sa setBoundaryType(), boundaryType()
     64     */
     65    enum BoundaryType
    4766    {
    48         const double x = points[0].x() + i * delta;
    49         interpolatedPoints[i].setX(x);
    50         interpolatedPoints[i].setY(spline.value(x));
    51     }
    52     return interpolatedPoints;
    53 }
    54   \endcode
    55 */
    56 
    57 class QWT_EXPORT QwtSpline
    58 {
    59 public:
    60     //! Spline type
    61     enum SplineType
     67        /*!
     68           The polynomials at the start/endpoint depend on specific conditions
     69
     70           \sa QwtSpline::BoundaryCondition
     71         */
     72        ConditionalBoundaries,
     73
     74        /*!
     75           The polynomials at the start/endpoint are found by using
     76           imaginary additional points. Additional points at the end
     77           are found by translating points from the beginning or v.v.
     78         */
     79        PeriodicPolygon,
     80
     81        /*!
     82           ClosedPolygon is similar to PeriodicPolygon beside, that
     83           the interpolation includes the connection between the last
     84           and the first control point.
     85
     86           \note Only works for parametrizations, where the parameter increment
     87                for the the final closing line is positive.
     88                This excludes QwtSplineParametrization::ParameterX and
     89                QwtSplineParametrization::ParameterY
     90         */
     91
     92        ClosedPolygon
     93    };
     94
     95    /*!
     96       position of a boundary condition
     97       \sa boundaryCondition(), boundaryValue()
     98     */
     99    enum BoundaryPosition
    62100    {
    63         //! A natural spline
    64         Natural,
    65 
    66         //! A periodic spline
    67         Periodic
     101        //! the condition is at the beginning of the polynomial
     102        AtBeginning,
     103
     104        //! the condition is at the end of the polynomial
     105        AtEnd
    68106    };
    69107
     108    /*!
     109       \brief Boundary condition
     110
     111       A spline algorithm calculates polynomials by looking
     112       a couple of points back/ahead ( locality() ). At the ends
     113       additional rules are necessary to compensate the missing
     114       points.
     115
     116       \sa boundaryCondition(), boundaryValue()
     117       \sa QwtSplineC2::BoundaryConditionC2
     118     */
     119    enum BoundaryCondition
     120    {
     121        /*!
     122           The first derivative at the end point is given
     123           \sa boundaryValue()
     124         */
     125        Clamped1,
     126
     127        /*!
     128           The second derivative at the end point is given
     129
     130           \sa boundaryValue()
     131           \note a condition having a second derivative of 0
     132                is also called "natural".
     133         */
     134        Clamped2,
     135
     136        /*!
     137           The third derivative at the end point is given
     138
     139           \sa boundaryValue()
     140           \note a condition having a third derivative of 0
     141                is also called "parabolic runout".
     142         */
     143        Clamped3,
     144
     145        /*!
     146           The first derivate at the endpoint is related to the first derivative
     147           at its neighbour by the boundary value. F,e when the boundary
     148           value at the end is 1.0 then the slope at the last 2 points is
     149           the same.
     150
     151           \sa boundaryValue().
     152         */
     153        LinearRunout
     154    };
     155
    70156    QwtSpline();
    71     QwtSpline( const QwtSpline & );
    72 
    73     ~QwtSpline();
    74 
    75     QwtSpline &operator=( const QwtSpline & );
    76 
    77     void setSplineType( SplineType );
    78     SplineType splineType() const;
    79 
    80     bool setPoints( const QPolygonF& points );
    81     QPolygonF points() const;
    82 
    83     void reset();
    84 
    85     bool isValid() const;
    86     double value( double x ) const;
    87 
    88     const QVector<double> &coefficientsA() const;
    89     const QVector<double> &coefficientsB() const;
    90     const QVector<double> &coefficientsC() const;
    91 
    92 protected:
    93     bool buildNaturalSpline( const QPolygonF & );
    94     bool buildPeriodicSpline( const QPolygonF & );
    95 
    96 private:
     157    virtual ~QwtSpline();
     158
     159    void setParametrization( int type );
     160    void setParametrization( QwtSplineParametrization* );
     161    const QwtSplineParametrization* parametrization() const;
     162
     163    void setBoundaryType( BoundaryType );
     164    BoundaryType boundaryType() const;
     165
     166    void setBoundaryValue( BoundaryPosition, double value );
     167    double boundaryValue( BoundaryPosition ) const;
     168
     169    void setBoundaryCondition( BoundaryPosition, int condition );
     170    int boundaryCondition( BoundaryPosition ) const;
     171
     172    void setBoundaryConditions( int condition,
     173        double valueBegin = 0.0, double valueEnd = 0.0 );
     174
     175    virtual QPolygonF polygon( const QPolygonF&, double tolerance ) const;
     176    virtual QPainterPath painterPath( const QPolygonF& ) const = 0;
     177
     178    virtual uint locality() const;
     179
     180  private:
     181    Q_DISABLE_COPY(QwtSpline)
     182
    97183    class PrivateData;
    98     PrivateData *d_data;
     184    PrivateData* m_data;
     185};
     186
     187/*!
     188   \brief Base class for a spline interpolation
     189
     190   Spline interpolation is the process of interpolating a set of points
     191   piecewise with polynomials. The initial set of points is preserved.
     192 */
     193class QWT_EXPORT QwtSplineInterpolating : public QwtSpline
     194{
     195  public:
     196    QwtSplineInterpolating();
     197    virtual ~QwtSplineInterpolating();
     198
     199    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     200        double distance, bool withNodes ) const;
     201
     202    virtual QPolygonF polygon(
     203        const QPolygonF&, double tolerance ) const QWT_OVERRIDE;
     204
     205    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     206    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const = 0;
     207
     208  private:
     209    Q_DISABLE_COPY(QwtSplineInterpolating)
     210};
     211
     212/*!
     213   \brief Base class for spline interpolations providing a
     214         first order geometric continuity ( G1 ) between adjoining curves
     215 */
     216class QWT_EXPORT QwtSplineG1 : public QwtSplineInterpolating
     217{
     218  public:
     219    QwtSplineG1();
     220    virtual ~QwtSplineG1();
     221};
     222
     223/*!
     224   \brief Base class for spline interpolations providing a
     225         first order parametric continuity ( C1 ) between adjoining curves
     226
     227   All interpolations with C1 continuity are based on rules for finding
     228   the 1. derivate at some control points.
     229
     230   In case of non parametric splines those points are the curve points, while
     231   for parametric splines the calculation is done twice using a parameter value t.
     232
     233   \sa QwtSplineParametrization
     234 */
     235class QWT_EXPORT QwtSplineC1 : public QwtSplineG1
     236{
     237  public:
     238    QwtSplineC1();
     239    virtual ~QwtSplineC1();
     240
     241    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     242    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE;
     243
     244    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     245        double distance, bool withNodes ) const QWT_OVERRIDE;
     246
     247    // these methods are the non parametric part
     248    virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const;
     249    virtual QVector< double > slopes( const QPolygonF& ) const = 0;
     250
     251    virtual double slopeAtBeginning( const QPolygonF&, double slopeNext ) const;
     252    virtual double slopeAtEnd( const QPolygonF&, double slopeBefore ) const;
     253};
     254
     255/*!
     256   \brief Base class for spline interpolations providing a
     257         second order parametric continuity ( C2 ) between adjoining curves
     258
     259   All interpolations with C2 continuity are based on rules for finding
     260   the 2. derivate at some control points.
     261
     262   In case of non parametric splines those points are the curve points, while
     263   for parametric splines the calculation is done twice using a parameter value t.
     264
     265   \sa QwtSplineParametrization
     266 */
     267class QWT_EXPORT QwtSplineC2 : public QwtSplineC1
     268{
     269  public:
     270    /*!
     271       Boundary condition that requires C2 continuity
     272
     273       \sa QwtSpline::boundaryCondition, QwtSpline::BoundaryCondition
     274     */
     275    enum BoundaryConditionC2
     276    {
     277        /*!
     278           The second derivate at the endpoint is related to the second derivatives
     279           at the 2 neighbours: cv[0] := 2.0 * cv[1] - cv[2].
     280
     281           \note boundaryValue() is ignored
     282         */
     283        CubicRunout = LinearRunout + 1,
     284
     285        /*!
     286           The 3rd derivate at the endpoint matches the 3rd derivate at its neighbours.
     287           Or in other words: the first/last curve segment extents the polynomial of its
     288           neighboured polynomial
     289
     290           \note boundaryValue() is ignored
     291         */
     292        NotAKnot
     293    };
     294
     295    QwtSplineC2();
     296    virtual ~QwtSplineC2();
     297
     298    virtual QPainterPath painterPath( const QPolygonF& ) const QWT_OVERRIDE;
     299    virtual QVector< QLineF > bezierControlLines( const QPolygonF& ) const QWT_OVERRIDE;
     300
     301    virtual QPolygonF equidistantPolygon( const QPolygonF&,
     302        double distance, bool withNodes ) const QWT_OVERRIDE;
     303
     304    // calculating the parametric equations
     305    virtual QVector< QwtSplinePolynomial > polynomials( const QPolygonF& ) const QWT_OVERRIDE;
     306    virtual QVector< double > slopes( const QPolygonF& ) const QWT_OVERRIDE;
     307    virtual QVector< double > curvatures( const QPolygonF& ) const = 0;
    99308};
    100309
Note: See TracChangeset for help on using the changeset viewer.