[89] | 1 | /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
|
---|
| 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_H
|
---|
| 11 | #define QWT_SPLINE_H
|
---|
| 12 |
|
---|
| 13 | #include "qwt_global.h"
|
---|
| 14 | #include "qwt_double_rect.h"
|
---|
| 15 |
|
---|
| 16 | #if QT_VERSION >= 0x040000
|
---|
| 17 | #include <QPolygonF>
|
---|
| 18 | #else
|
---|
| 19 | #include "qwt_array.h"
|
---|
| 20 | #endif
|
---|
| 21 |
|
---|
| 22 | // MOC_SKIP_BEGIN
|
---|
| 23 |
|
---|
| 24 | #if defined(QWT_TEMPLATEDLL)
|
---|
| 25 |
|
---|
| 26 | #if QT_VERSION < 0x040000
|
---|
| 27 | #ifndef QWTARRAY_TEMPLATE_QWTDOUBLEPOINT // by mjo3
|
---|
| 28 | #define QWTARRAY_TEMPLATE_QWTDOUBLEPOINT
|
---|
| 29 | template class QWT_EXPORT QwtArray<QwtDoublePoint>;
|
---|
| 30 | #endif //end of QWTARRAY_TEMPLATE_QWTDOUBLEPOINT
|
---|
| 31 | #endif
|
---|
| 32 |
|
---|
| 33 | #endif
|
---|
| 34 |
|
---|
| 35 | // MOC_SKIP_END
|
---|
| 36 |
|
---|
| 37 | /*!
|
---|
| 38 | \brief A class for spline interpolation
|
---|
| 39 |
|
---|
| 40 | The QwtSpline class is used for cubical spline interpolation.
|
---|
| 41 | Two types of splines, natural and periodic, are supported.
|
---|
| 42 |
|
---|
| 43 | \par Usage:
|
---|
| 44 | <ol>
|
---|
| 45 | <li>First call setPoints() to determine the spline coefficients
|
---|
| 46 | for a tabulated function y(x).
|
---|
| 47 | <li>After the coefficients have been set up, the interpolated
|
---|
| 48 | function value for an argument x can be determined by calling
|
---|
| 49 | QwtSpline::value().
|
---|
| 50 | </ol>
|
---|
| 51 |
|
---|
| 52 | \par Example:
|
---|
| 53 | \code
|
---|
| 54 | #include <qwt_spline.h>
|
---|
| 55 |
|
---|
| 56 | QPolygonF interpolate(const QPolygonF& points, int numValues)
|
---|
| 57 | {
|
---|
| 58 | QwtSpline spline;
|
---|
| 59 | if ( !spline.setPoints(points) )
|
---|
| 60 | return points;
|
---|
| 61 |
|
---|
| 62 | QPolygonF interpolatedPoints(numValues);
|
---|
| 63 |
|
---|
| 64 | const double delta =
|
---|
| 65 | (points[numPoints - 1].x() - points[0].x()) / (points.size() - 1);
|
---|
| 66 | for(i = 0; i < points.size(); i++) / interpolate
|
---|
| 67 | {
|
---|
| 68 | const double x = points[0].x() + i * delta;
|
---|
| 69 | interpolatedPoints[i].setX(x);
|
---|
| 70 | interpolatedPoints[i].setY(spline.value(x));
|
---|
| 71 | }
|
---|
| 72 | return interpolatedPoints;
|
---|
| 73 | }
|
---|
| 74 | \endcode
|
---|
| 75 | */
|
---|
| 76 |
|
---|
| 77 | class QWT_EXPORT QwtSpline
|
---|
| 78 | {
|
---|
| 79 | public:
|
---|
| 80 | //! Spline type
|
---|
| 81 | enum SplineType
|
---|
| 82 | {
|
---|
| 83 | Natural,
|
---|
| 84 | Periodic
|
---|
| 85 | };
|
---|
| 86 |
|
---|
| 87 | QwtSpline();
|
---|
| 88 | QwtSpline( const QwtSpline & );
|
---|
| 89 |
|
---|
| 90 | ~QwtSpline();
|
---|
| 91 |
|
---|
| 92 | QwtSpline &operator=( const QwtSpline & );
|
---|
| 93 |
|
---|
| 94 | void setSplineType(SplineType);
|
---|
| 95 | SplineType splineType() const;
|
---|
| 96 |
|
---|
| 97 | #if QT_VERSION < 0x040000
|
---|
| 98 | bool setPoints(const QwtArray<QwtDoublePoint>& points);
|
---|
| 99 | QwtArray<QwtDoublePoint> points() const;
|
---|
| 100 | #else
|
---|
| 101 | bool setPoints(const QPolygonF& points);
|
---|
| 102 | QPolygonF points() const;
|
---|
| 103 | #endif
|
---|
| 104 |
|
---|
| 105 | void reset();
|
---|
| 106 |
|
---|
| 107 | bool isValid() const;
|
---|
| 108 | double value(double x) const;
|
---|
| 109 |
|
---|
| 110 | const QwtArray<double> &coefficientsA() const;
|
---|
| 111 | const QwtArray<double> &coefficientsB() const;
|
---|
| 112 | const QwtArray<double> &coefficientsC() const;
|
---|
| 113 |
|
---|
| 114 | protected:
|
---|
| 115 |
|
---|
| 116 | #if QT_VERSION < 0x040000
|
---|
| 117 | bool buildNaturalSpline(
|
---|
| 118 | const QwtArray<QwtDoublePoint> &);
|
---|
| 119 | bool buildPeriodicSpline(
|
---|
| 120 | const QwtArray<QwtDoublePoint> &);
|
---|
| 121 | #else
|
---|
| 122 | bool buildNaturalSpline(const QPolygonF &);
|
---|
| 123 | bool buildPeriodicSpline(const QPolygonF &);
|
---|
| 124 | #endif
|
---|
| 125 |
|
---|
| 126 | class PrivateData;
|
---|
| 127 | PrivateData *d_data;
|
---|
| 128 | };
|
---|
| 129 |
|
---|
| 130 | #endif
|
---|