Merged in f5soh/librepilot/update_credits (pull request #529)
[librepilot.git] / ground / gcs / src / libs / qwt / src / qwt_curve_fitter.h
blobeac376a34d2cc57d26342607002dda1f49bf9b76
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
2 * Qwt Widget Library
3 * Copyright (C) 1997 Josef Wilgen
4 * Copyright (C) 2002 Uwe Rathmann
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 *****************************************************************************/
10 #ifndef QWT_CURVE_FITTER_H
11 #define QWT_CURVE_FITTER_H
13 #include "qwt_global.h"
14 #include <qpolygon.h>
15 #include <qrect.h>
17 class QwtSpline;
19 /*!
20 \brief Abstract base class for a curve fitter
22 class QWT_EXPORT QwtCurveFitter
24 public:
25 virtual ~QwtCurveFitter();
27 /*!
28 Find a curve which has the best fit to a series of data points
30 \param polygon Series of data points
31 \return Curve points
33 virtual QPolygonF fitCurve( const QPolygonF &polygon ) const = 0;
35 protected:
36 QwtCurveFitter();
38 private:
39 QwtCurveFitter( const QwtCurveFitter & );
40 QwtCurveFitter &operator=( const QwtCurveFitter & );
43 /*!
44 \brief A curve fitter using cubic splines
46 class QWT_EXPORT QwtSplineCurveFitter: public QwtCurveFitter
48 public:
49 /*!
50 Spline type
51 The default setting is Auto
52 \sa setFitMode(), FitMode()
54 enum FitMode
56 /*!
57 Use the default spline algorithm for polygons with
58 increasing x values ( p[i-1] < p[i] ), otherwise use
59 a parametric spline algorithm.
61 Auto,
63 //! Use a default spline algorithm
64 Spline,
66 //! Use a parametric spline algorithm
67 ParametricSpline
70 QwtSplineCurveFitter();
71 virtual ~QwtSplineCurveFitter();
73 void setFitMode( FitMode );
74 FitMode fitMode() const;
76 void setSpline( const QwtSpline& );
77 const QwtSpline &spline() const;
78 QwtSpline &spline();
80 void setSplineSize( int size );
81 int splineSize() const;
83 virtual QPolygonF fitCurve( const QPolygonF & ) const;
85 private:
86 QPolygonF fitSpline( const QPolygonF & ) const;
87 QPolygonF fitParametric( const QPolygonF & ) const;
89 class PrivateData;
90 PrivateData *d_data;
93 /*!
94 \brief A curve fitter implementing Douglas and Peucker algorithm
96 The purpose of the Douglas and Peucker algorithm is that given a 'curve'
97 composed of line segments to find a curve not too dissimilar but that
98 has fewer points. The algorithm defines 'too dissimilar' based on the
99 maximum distance (tolerance) between the original curve and the
100 smoothed curve.
102 The runtime of the algorithm increases non linear ( worst case O( n*n ) )
103 and might be very slow for huge polygons. To avoid performance issues
104 it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm
105 for these smaller parts. The disadvantage of having no interpolation
106 at the borders is for most use cases irrelevant.
108 The smoothed curve consists of a subset of the points that defined the
109 original curve.
111 In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces
112 the number of points. By adjusting the tolerance parameter according to the
113 axis scales QwtSplineCurveFitter can be used to implement different
114 level of details to speed up painting of curves of many points.
116 class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter
118 public:
119 QwtWeedingCurveFitter( double tolerance = 1.0 );
120 virtual ~QwtWeedingCurveFitter();
122 void setTolerance( double );
123 double tolerance() const;
125 void setChunkSize( uint );
126 uint chunkSize() const;
128 virtual QPolygonF fitCurve( const QPolygonF & ) const;
130 private:
131 virtual QPolygonF simplify( const QPolygonF & ) const;
133 class Line;
135 class PrivateData;
136 PrivateData *d_data;
139 #endif