source: ntrip/trunk/BNC/src/rinex/polarplot.cpp@ 4316

Last change on this file since 4316 was 4316, checked in by mervart, 12 years ago
File size: 4.5 KB
Line 
1
2/* -------------------------------------------------------------------------
3 * BKG NTRIP Client
4 * -------------------------------------------------------------------------
5 *
6 * Class: t_polarPlot
7 *
8 * Purpose: Polar Plot
9 *
10 * Author: L. Mervart
11 *
12 * Created: 23-Jun-2012
13 *
14 * Changes:
15 *
16 * -----------------------------------------------------------------------*/
17
18#include <qpen.h>
19#include <qwt_series_data.h>
20#include <qwt_symbol.h>
21#include <qwt_polar_grid.h>
22
23#include "polarplot.h"
24
25// Constructor
26////////////////////////////////////////////////////////////////////////////
27t_polarCurve::t_polarCurve() {
28}
29
30// Destructor (virtual)
31////////////////////////////////////////////////////////////////////////////
32t_polarCurve::~t_polarCurve() {
33}
34
35// drawSymbols (virtual)
36////////////////////////////////////////////////////////////////////////////
37void t_polarCurve::drawSymbols(QPainter* painter, const QwtSymbol& symbol,
38 const QwtScaleMap& azimuthMap,
39 const QwtScaleMap& radialMap,
40 const QPointF& pole, int from, int to) const {
41 for (int ii = from; ii <= to; ii++) {
42 QwtPolarCurve::drawSymbols(painter, symbol, azimuthMap,
43 radialMap, pole, ii, ii);
44 }
45}
46
47
48const QwtInterval zenithInterval(0.0, 90.0);
49const QwtInterval azimuthInterval(0.0, 360.0);
50
51// Data Class
52////////////////////////////////////////////////////////////////////////////
53class Data: public QwtSeriesData<QwtPointPolar> {
54 public:
55 Data(const QwtInterval &zenithInterval,
56 const QwtInterval &azimuthInterval, size_t size) :
57 _zenithInterval(zenithInterval), _azimuthInterval(azimuthInterval),
58 _size(size) {}
59
60 virtual size_t size() const {return _size;}
61
62 protected:
63 QwtInterval _zenithInterval;
64 QwtInterval _azimuthInterval;
65 size_t _size;
66};
67
68// Spiral Data Class
69////////////////////////////////////////////////////////////////////////////
70class SpiralData: public Data {
71 public:
72 SpiralData(const QwtInterval &zenithInterval,
73 const QwtInterval &azimuthInterval, size_t size) :
74 Data(zenithInterval, azimuthInterval, size) {}
75
76 virtual QwtPointPolar sample(size_t ii) const {
77 const double stepA = 4 * _azimuthInterval.width() / _size;
78 const double aa = _azimuthInterval.minValue() + ii * stepA;
79
80 const double stepR = _zenithInterval.width() / _size;
81 const double rr = _zenithInterval.minValue() + ii * stepR;
82
83 return QwtPointPolar(aa, rr);
84 }
85
86 virtual QRectF boundingRect() const {
87 if (d_boundingRect.width() < 0.0) {
88 d_boundingRect = qwtBoundingRect(*this);
89 }
90 return d_boundingRect;
91 }
92};
93
94// Constructor
95////////////////////////////////////////////////////////////////////////////
96t_polarPlot::t_polarPlot( QWidget *parent ) :
97QwtPolarPlot(QwtText("Polar Plot"), parent) {
98
99 setPlotBackground(Qt::white);
100
101 // Scales
102 // ------
103 setScale(QwtPolar::Radius,
104 zenithInterval.minValue(), zenithInterval.maxValue());
105
106 setScale(QwtPolar::Azimuth,
107 azimuthInterval.minValue(), azimuthInterval.maxValue(),
108 azimuthInterval.width() / 12);
109
110 // Grids, Axes
111 // -----------
112 QwtPolarGrid* grid = new QwtPolarGrid();
113 grid->setPen(QPen(Qt::black));
114 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
115 grid->showGrid(scaleId);
116 }
117
118 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
119
120 grid->showAxis(QwtPolar::AxisAzimuth, true);
121 grid->showAxis(QwtPolar::AxisTop, true);
122 grid->showAxis(QwtPolar::AxisBottom, false);
123 grid->showAxis(QwtPolar::AxisLeft, false);
124 grid->showAxis(QwtPolar::AxisRight, false);
125
126 grid->showGrid(QwtPolar::Azimuth, true);
127 grid->showGrid(QwtPolar::Radius, true);
128
129 grid->attach(this);
130
131 // Curves
132 // ------
133 t_polarCurve* curve = createCurve();
134 curve->attach(this);
135}
136
137// Destructor
138////////////////////////////////////////////////////////////////////////////
139t_polarPlot::~t_polarPlot() {
140}
141
142//
143////////////////////////////////////////////////////////////////////////////
144t_polarCurve* t_polarPlot::createCurve() const {
145 const int numPoints = 200;
146 t_polarCurve* curve = new t_polarCurve();
147 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
148 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
149 QBrush(Qt::red), QPen(Qt::red),
150 QSize(3, 3)));
151 curve->setData(new SpiralData(zenithInterval, azimuthInterval, numPoints));
152 return curve;
153}
Note: See TracBrowser for help on using the repository browser.