Qwt User's Guide 6.3.0
Loading...
Searching...
No Matches
qwt_polar_fitter.cpp
1/******************************************************************************
2 * QwtPolar Widget Library
3 * Copyright (C) 2008 Uwe Rathmann
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the Qwt License, Version 1.0
7 *****************************************************************************/
8
9#include "qwt_polar_fitter.h"
10#include <qpolygon.h>
11#include <qpainterpath.h>
12
13class QwtPolarFitter::PrivateData
14{
15 public:
16 PrivateData()
17 : stepCount( 5 )
18 {
19 }
20
21 int stepCount;
22};
23
31 : QwtCurveFitter( QwtPolarFitter::Polygon )
32{
33 m_data = new PrivateData;
34 m_data->stepCount = stepCount;
35}
36
39{
40 delete m_data;
41}
42
51void QwtPolarFitter::setStepCount( int stepCount )
52{
53 m_data->stepCount = qMax( stepCount, 0 );
54}
55
61{
62 return m_data->stepCount;
63}
64
72QPolygonF QwtPolarFitter::fitCurve( const QPolygonF& points ) const
73{
74 if ( m_data->stepCount <= 0 || points.size() <= 1 )
75 return points;
76
77 QPolygonF fittedPoints;
78
79 int numPoints = points.size() + ( points.size() - 1 ) * m_data->stepCount;
80
81 fittedPoints.resize( numPoints );
82
83 int index = 0;
84 fittedPoints[index++] = points[0];
85 for ( int i = 1; i < points.size(); i++ )
86 {
87 const QPointF& p1 = points[i - 1];
88 const QPointF& p2 = points[i];
89
90 const double dx = ( p2.x() - p1.x() ) / m_data->stepCount;
91 const double dy = ( p2.y() - p1.y() ) / m_data->stepCount;
92 for ( int j = 1; j <= m_data->stepCount; j++ )
93 {
94 const double x = p1.x() + j * dx;
95 const double y = p1.y() + j * dy;
96
97 fittedPoints[index++] = QPointF( x, y );
98 }
99 }
100 fittedPoints.resize( index );
101
102 return fittedPoints;
103}
104
110QPainterPath QwtPolarFitter::fitCurvePath( const QPolygonF& points ) const
111{
112 QPainterPath path;
113 path.addPolygon( fitCurve( points ) );
114 return path;
115}
Abstract base class for a curve fitter.
A simple curve fitter for polar points.
int stepCount() const
void setStepCount(int size)
virtual QPainterPath fitCurvePath(const QPolygonF &) const override
QwtPolarFitter(int stepCount=5)
virtual QPolygonF fitCurve(const QPolygonF &) const override
virtual ~QwtPolarFitter()
Destructor.