qwt_polar_fitter.cpp
Go to the documentation of this file.
1 /* -*- mode: C++ ; c-file-style: "stroustrup" -*- *****************************
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:
17  stepCount( 5 )
18  {
19  }
20 
21  int stepCount;
22 };
23 
32 {
33  d_data = new PrivateData;
35 }
36 
39 {
40  delete d_data;
41 }
42 
52 {
53  d_data->stepCount = qMax( stepCount, 0 );
54 }
55 
61 {
62  return d_data->stepCount;
63 }
64 
72 QPolygonF QwtPolarFitter::fitCurve( const QPolygonF &points ) const
73 {
74  if ( d_data->stepCount <= 0 || points.size() <= 1 )
75  return points;
76 
77  QPolygonF fittedPoints;
78 
79  int numPoints = points.size() + ( points.size() - 1 ) * d_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() ) / d_data->stepCount;
91  const double dy = ( p2.y() - p1.y() ) / d_data->stepCount;
92  for ( int j = 1; j <= d_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 }
virtual QPolygonF fitCurve(const QPolygonF &) const QWT_OVERRIDE
int stepCount() const
PrivateData * d_data
A simple curve fitter for polar points.
void setStepCount(int size)
virtual QPainterPath fitCurvePath(const QPolygonF &) const QWT_OVERRIDE
QwtPolarFitter(int stepCount=5)
virtual ~QwtPolarFitter()
Destructor.
Abstract base class for a curve fitter.


plotjuggler
Author(s): Davide Faconti
autogenerated on Sun Dec 6 2020 03:48:10