qwt_curve_fitter.h 3.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139
  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. #ifndef QWT_CURVE_FITTER_H
  10. #define QWT_CURVE_FITTER_H
  11. #include "qwt_global.h"
  12. #include <qpolygon.h>
  13. #include <qrect.h>
  14. class QwtSpline;
  15. /*!
  16. \brief Abstract base class for a curve fitter
  17. */
  18. class QWT_EXPORT QwtCurveFitter
  19. {
  20. public:
  21. virtual ~QwtCurveFitter();
  22. /*!
  23. Find a curve which has the best fit to a series of data points
  24. \param polygon Series of data points
  25. \return Curve points
  26. */
  27. virtual QPolygonF fitCurve( const QPolygonF &polygon ) const = 0;
  28. protected:
  29. QwtCurveFitter();
  30. private:
  31. QwtCurveFitter( const QwtCurveFitter & );
  32. QwtCurveFitter &operator=( const QwtCurveFitter & );
  33. };
  34. /*!
  35. \brief A curve fitter using cubic splines
  36. */
  37. class QWT_EXPORT QwtSplineCurveFitter: public QwtCurveFitter
  38. {
  39. public:
  40. /*!
  41. Spline type
  42. The default setting is Auto
  43. \sa setFitMode(), FitMode()
  44. */
  45. enum FitMode
  46. {
  47. /*!
  48. Use the default spline algorithm for polygons with
  49. increasing x values ( p[i-1] < p[i] ), otherwise use
  50. a parametric spline algorithm.
  51. */
  52. Auto,
  53. //! Use a default spline algorithm
  54. Spline,
  55. //! Use a parametric spline algorithm
  56. ParametricSpline
  57. };
  58. QwtSplineCurveFitter();
  59. virtual ~QwtSplineCurveFitter();
  60. void setFitMode( FitMode );
  61. FitMode fitMode() const;
  62. void setSpline( const QwtSpline& );
  63. const QwtSpline &spline() const;
  64. QwtSpline &spline();
  65. void setSplineSize( int );
  66. int splineSize() const;
  67. virtual QPolygonF fitCurve( const QPolygonF & ) const;
  68. private:
  69. QPolygonF fitSpline( const QPolygonF & ) const;
  70. QPolygonF fitParametric( const QPolygonF & ) const;
  71. class PrivateData;
  72. PrivateData *d_data;
  73. };
  74. /*!
  75. \brief A curve fitter implementing Douglas and Peucker algorithm
  76. The purpose of the Douglas and Peucker algorithm is that given a 'curve'
  77. composed of line segments to find a curve not too dissimilar but that
  78. has fewer points. The algorithm defines 'too dissimilar' based on the
  79. maximum distance (tolerance) between the original curve and the
  80. smoothed curve.
  81. The runtime of the algorithm increases non linear ( worst case O( n*n ) )
  82. and might be very slow for huge polygons. To avoid performance issues
  83. it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm
  84. for these smaller parts. The disadvantage of having no interpolation
  85. at the borders is for most use cases irrelevant.
  86. The smoothed curve consists of a subset of the points that defined the
  87. original curve.
  88. In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces
  89. the number of points. By adjusting the tolerance parameter according to the
  90. axis scales QwtSplineCurveFitter can be used to implement different
  91. level of details to speed up painting of curves of many points.
  92. */
  93. class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter
  94. {
  95. public:
  96. QwtWeedingCurveFitter( double tolerance = 1.0 );
  97. virtual ~QwtWeedingCurveFitter();
  98. void setTolerance( double );
  99. double tolerance() const;
  100. void setChunkSize( uint );
  101. uint chunkSize() const;
  102. virtual QPolygonF fitCurve( const QPolygonF & ) const;
  103. private:
  104. virtual QPolygonF simplify( const QPolygonF & ) const;
  105. class Line;
  106. class PrivateData;
  107. PrivateData *d_data;
  108. };
  109. #endif