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

Last change on this file since 4327 was 4327, checked in by mervart, 12 years ago
File size: 3.8 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#include <qwt_color_map.h>
23
24#include "polarplot.h"
25
26class t_colorMap: public QwtLinearColorMap {
27 public:
28 t_colorMap() : QwtLinearColorMap(Qt::darkBlue, Qt::yellow) {
29 addColorStop(0.05, Qt::blue);
30 addColorStop(0.30, Qt::cyan);
31 addColorStop(0.60, Qt::green);
32 addColorStop(0.98, Qt::red);
33 }
34};
35
36t_colorMap colorMap;
37
38// Draw Symbols (virtual) - change symbol's color
39////////////////////////////////////////////////////////////////////////////
40void t_polarCurve::drawSymbols(QPainter* painter, const QwtSymbol& symbol,
41 const QwtScaleMap& azimuthMap,
42 const QwtScaleMap& radialMap,
43 const QPointF& pole, int from, int to) const {
44 for (int ii = from; ii <= to; ii++) {
45 QwtSymbol ss(symbol);
46 const t_polarData* polarData = reinterpret_cast<const t_polarData*>(data());
47 const t_polarPoint& point = polarData->sample(ii);
48 const QColor color = colorMap.color(QwtInterval(0.0, 1.0), point._value);
49 ss.setBrush(QBrush(color));
50 ss.setPen(QPen(color));
51 QwtPolarCurve::drawSymbols(painter, ss, azimuthMap, radialMap, pole, ii,ii);
52 }
53}
54
55// Sample (virtual) - this is for testing only
56////////////////////////////////////////////////////////////////////////////
57t_polarPoint t_polarData::sample(size_t ii) const {
58 const QwtInterval zenithInterval(0.0, 90.0);
59 const QwtInterval azimuthInterval(0.0, 360.0 );
60
61 const double stepA = 4 * azimuthInterval.width() / _size;
62 const double aa = azimuthInterval.minValue() + ii * stepA;
63
64 const double stepR = zenithInterval.width() / _size;
65 const double rr = zenithInterval.minValue() + ii * stepR;
66
67 double value = static_cast<double>(ii) / _size;
68
69 return t_polarPoint(aa, rr, value);
70}
71
72//
73////////////////////////////////////////////////////////////////////////////
74t_polarCurve* t_polarPlot::createCurve() const {
75 const int numPoints = 200;
76 t_polarCurve* curve = new t_polarCurve();
77 curve->setStyle(QwtPolarCurve::NoCurve); // draw only symbols
78 curve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,
79 QBrush(Qt::red), QPen(Qt::red),
80 QSize(3, 3)));
81 t_polarData* data = new t_polarData(numPoints);
82 curve->setData(reinterpret_cast<QwtSeriesData<QwtPointPolar>*>(data));
83 return curve;
84}
85
86// Constructor
87////////////////////////////////////////////////////////////////////////////
88t_polarPlot::t_polarPlot(QWidget* parent) :
89 QwtPolarPlot(QwtText("Polar Plot"), parent) {
90
91 setPlotBackground(Qt::white);
92
93 setAzimuthOrigin(M_PI/2.0);
94
95 // Scales
96 // ------
97 setScale(QwtPolar::Radius, 0.0, 90.0);
98 setScale(QwtPolar::Azimuth, 360.0, 0.0, 30.0);
99
100 // Grids, Axes
101 // -----------
102 QwtPolarGrid* grid = new QwtPolarGrid();
103 grid->setPen(QPen(Qt::black));
104 for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ ) {
105 grid->showGrid(scaleId);
106 }
107
108 grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
109
110 grid->showAxis(QwtPolar::AxisAzimuth, true);
111 grid->showAxis(QwtPolar::AxisTop, true);
112 grid->showAxis(QwtPolar::AxisBottom, false);
113 grid->showAxis(QwtPolar::AxisLeft, false);
114 grid->showAxis(QwtPolar::AxisRight, false);
115
116 grid->showGrid(QwtPolar::Azimuth, true);
117 grid->showGrid(QwtPolar::Radius, true);
118
119 grid->attach(this);
120
121 // Curves
122 // ------
123 t_polarCurve* curve = createCurve();
124 curve->attach(this);
125}
126
Note: See TracBrowser for help on using the repository browser.