| 1 | /******************************************************************************
|
|---|
| 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_WEEDING_CURVE_FITTER_H
|
|---|
| 11 | #define QWT_WEEDING_CURVE_FITTER_H
|
|---|
| 12 |
|
|---|
| 13 | #include "qwt_curve_fitter.h"
|
|---|
| 14 |
|
|---|
| 15 | /*!
|
|---|
| 16 | \brief A curve fitter implementing Douglas and Peucker algorithm
|
|---|
| 17 |
|
|---|
| 18 | The purpose of the Douglas and Peucker algorithm is that given a 'curve'
|
|---|
| 19 | composed of line segments to find a curve not too dissimilar but that
|
|---|
| 20 | has fewer points. The algorithm defines 'too dissimilar' based on the
|
|---|
| 21 | maximum distance (tolerance) between the original curve and the
|
|---|
| 22 | smoothed curve.
|
|---|
| 23 |
|
|---|
| 24 | The runtime of the algorithm increases non linear ( worst case O( n*n ) )
|
|---|
| 25 | and might be very slow for huge polygons. To avoid performance issues
|
|---|
| 26 | it might be useful to split the polygon ( setChunkSize() ) and to run the algorithm
|
|---|
| 27 | for these smaller parts. The disadvantage of having no interpolation
|
|---|
| 28 | at the borders is for most use cases irrelevant.
|
|---|
| 29 |
|
|---|
| 30 | The smoothed curve consists of a subset of the points that defined the
|
|---|
| 31 | original curve.
|
|---|
| 32 |
|
|---|
| 33 | In opposite to QwtSplineCurveFitter the Douglas and Peucker algorithm reduces
|
|---|
| 34 | the number of points. By adjusting the tolerance parameter according to the
|
|---|
| 35 | axis scales QwtSplineCurveFitter can be used to implement different
|
|---|
| 36 | level of details to speed up painting of curves of many points.
|
|---|
| 37 | */
|
|---|
| 38 | class QWT_EXPORT QwtWeedingCurveFitter : public QwtCurveFitter
|
|---|
| 39 | {
|
|---|
| 40 | public:
|
|---|
| 41 | explicit QwtWeedingCurveFitter( double tolerance = 1.0 );
|
|---|
| 42 | virtual ~QwtWeedingCurveFitter();
|
|---|
| 43 |
|
|---|
| 44 | void setTolerance( double );
|
|---|
| 45 | double tolerance() const;
|
|---|
| 46 |
|
|---|
| 47 | void setChunkSize( uint );
|
|---|
| 48 | uint chunkSize() const;
|
|---|
| 49 |
|
|---|
| 50 | virtual QPolygonF fitCurve( const QPolygonF& ) const QWT_OVERRIDE;
|
|---|
| 51 | virtual QPainterPath fitCurvePath( const QPolygonF& ) const QWT_OVERRIDE;
|
|---|
| 52 |
|
|---|
| 53 | private:
|
|---|
| 54 | virtual QPolygonF simplify( const QPolygonF& ) const;
|
|---|
| 55 |
|
|---|
| 56 | class Line;
|
|---|
| 57 |
|
|---|
| 58 | class PrivateData;
|
|---|
| 59 | PrivateData* m_data;
|
|---|
| 60 | };
|
|---|
| 61 |
|
|---|
| 62 | #endif
|
|---|