qwt_curve_fitter.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  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\n
  42. Use a default spline algorithm
  43. - ParametricSpline\n
  44. Use a parametric spline algorithm
  45. - Auto\n
  46. Use the default spline algorithm for polygons with
  47. increasing x values ( p[i-1] < p[i] ), otherwise use
  48. a parametric spline algorithm.
  49. The default setting is Auto
  50. \sa setFitMode(), FitMode()
  51. */
  52. enum FitMode
  53. {
  54. Auto,
  55. Spline,
  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 size );
  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 smoothed curve consists of a subset of the points that defined the
  82. original curve.
  83. In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces
  84. the number of points. By adjusting the tolerance parameter according to the
  85. axis scales QwtSplineCurveFitter can be used to implement different
  86. level of details to speed up painting of curves of many points.
  87. */
  88. class QWT_EXPORT QwtWeedingCurveFitter: public QwtCurveFitter
  89. {
  90. public:
  91. QwtWeedingCurveFitter( double tolerance = 1.0 );
  92. virtual ~QwtWeedingCurveFitter();
  93. void setTolerance( double );
  94. double tolerance() const;
  95. virtual QPolygonF fitCurve( const QPolygonF & ) const;
  96. private:
  97. class Line;
  98. class PrivateData;
  99. PrivateData *d_data;
  100. };
  101. #endif