qwt_polar_fitter.cpp
Go to the documentation of this file.
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 
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;
35 }
36 
39 {
40  delete m_data;
41 }
42 
51 void QwtPolarFitter::setStepCount( int stepCount )
52 {
53  m_data->stepCount = qMax( stepCount, 0 );
54 }
55 
61 {
62  return m_data->stepCount;
63 }
64 
72 QPolygonF 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 
110 QPainterPath QwtPolarFitter::fitCurvePath( const QPolygonF& points ) const
111 {
112  QPainterPath path;
113  path.addPolygon( fitCurve( points ) );
114  return path;
115 }
QwtPolarFitter::~QwtPolarFitter
virtual ~QwtPolarFitter()
Destructor.
Definition: qwt_polar_fitter.cpp:38
QwtPolarFitter
A simple curve fitter for polar points.
Definition: qwt_polar_fitter.h:24
QwtPolarFitter::stepCount
int stepCount() const
Definition: qwt_polar_fitter.cpp:60
QwtPolarFitter::QwtPolarFitter
QwtPolarFitter(int stepCount=5)
Definition: qwt_polar_fitter.cpp:30
qwt_polar_fitter.h
mqtt_test_proto.x
x
Definition: mqtt_test_proto.py:34
QwtPolarFitter::fitCurvePath
virtual QPainterPath fitCurvePath(const QPolygonF &) const QWT_OVERRIDE
Definition: qwt_polar_fitter.cpp:110
mqtt_test_proto.y
y
Definition: mqtt_test_proto.py:35
QwtPolarFitter::m_data
PrivateData * m_data
Definition: qwt_polar_fitter.h:43
QwtPolarFitter::PrivateData::PrivateData
PrivateData()
Definition: qwt_polar_fitter.cpp:22
QwtCurveFitter
Abstract base class for a curve fitter.
Definition: qwt_curve_fitter.h:21
QwtPolarFitter::PrivateData
Definition: qwt_polar_fitter.cpp:13
QwtPolarFitter::setStepCount
void setStepCount(int size)
Definition: qwt_polar_fitter.cpp:51
QwtPolarFitter::PrivateData::stepCount
int stepCount
Definition: qwt_polar_fitter.cpp:27
QwtPolarFitter::fitCurve
virtual QPolygonF fitCurve(const QPolygonF &) const QWT_OVERRIDE
Definition: qwt_polar_fitter.cpp:72


plotjuggler
Author(s): Davide Faconti
autogenerated on Mon Nov 11 2024 03:23:46