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
13 class QwtPolarFitter::PrivateData
14{
15 public:
16 PrivateData()
17 : stepCount( 5 )
18 {
19 }
20
21 int stepCount;
22};
23
30 QwtPolarFitter::QwtPolarFitter( int stepCount )
31 : QwtCurveFitter( QwtPolarFitter::Polygon )
32{
33 m_data = new PrivateData;
34 m_data->stepCount = stepCount;
35}
36
38 QwtPolarFitter::~QwtPolarFitter()
39{
40 delete m_data;
41}
42
51 void QwtPolarFitter::setStepCount( int stepCount )
52{
53 m_data->stepCount = qMax( stepCount, 0 );
54}
55
60 int QwtPolarFitter::stepCount() const
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}
QwtCurveFitter
Abstract base class for a curve fitter.
Definition qwt_curve_fitter.h:22
QwtPolarFitter
A simple curve fitter for polar points.
Definition qwt_polar_fitter.h:25
QwtPolarFitter::stepCount
int stepCount() const
Definition qwt_polar_fitter.cpp:60
QwtPolarFitter::setStepCount
void setStepCount(int size)
Definition qwt_polar_fitter.cpp:51
QwtPolarFitter::fitCurvePath
virtual QPainterPath fitCurvePath(const QPolygonF &) const override
Definition qwt_polar_fitter.cpp:110
QwtPolarFitter::QwtPolarFitter
QwtPolarFitter(int stepCount=5)
Definition qwt_polar_fitter.cpp:30
QwtPolarFitter::fitCurve
virtual QPolygonF fitCurve(const QPolygonF &) const override
Definition qwt_polar_fitter.cpp:72
QwtPolarFitter::~QwtPolarFitter
virtual ~QwtPolarFitter()
Destructor.
Definition qwt_polar_fitter.cpp:38