-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathqwtsurfaceplotterplot.cpp
More file actions
161 lines (134 loc) · 4.36 KB
/
qwtsurfaceplotterplot.cpp
File metadata and controls
161 lines (134 loc) · 4.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
#include <cassert>
#include <qwt/qwt_plot_spectrogram.h>
#include <qwt/qwt_scale_widget.h>
#include <qwt/qwt_plot_panner.h>
#include <qwt/qwt_plot_layout.h>
#include <qwt/qwt_color_map.h>
#include "fparser.hh"
#include "qwtsurfaceplotterplot.h"
#include "qwtsurfaceplotterzoomer.h"
#include "qwtsurfaceplotterdata.h"
//#include "qwtsurfaceplottercolormap.h"
ribi::QwtSurfacePlotterPlot::QwtSurfacePlotterPlot(QWidget *parent)
: QwtPlot(parent),
m_spectrogram(new QwtPlotSpectrogram)
{
m_spectrogram->setRenderThreadCount(0); // use system specific thread count
m_spectrogram->setCachePolicy(QwtPlotRasterItem::PaintCache );
{
this->SetData(
"cos(x*y*10)",
-1.0,1.0,
-1.0,1.0,
-1.0,1.0
);
}
m_spectrogram->attach(this);
enableAxis(QwtPlot::yRight );
plotLayout()->setAlignCanvasToScales(true);
replot();
// LeftButton for the zooming
// MidButton for the panning
// RightButton: zoom out by 1
// Ctrl+RighButton: zoom out to full size
{
QwtSurfacePlotterZoomer * const zoomer = new QwtSurfacePlotterZoomer(canvas());
zoomer->setMousePattern( QwtEventPattern::MouseSelect2,Qt::RightButton, Qt::ControlModifier );
zoomer->setMousePattern( QwtEventPattern::MouseSelect3,Qt::RightButton );
const QColor c(Qt::white);
zoomer->setRubberBandPen(c);
zoomer->setTrackerPen(c);
}
QwtPlotPanner *panner = new QwtPlotPanner(canvas());
panner->setAxisEnabled(QwtPlot::yRight, false);
panner->setMouseButton(Qt::MidButton);
// Avoid jumping when labels with more/less digits
// appear/disappear when scrolling vertically
const QFontMetrics fm(axisWidget(QwtPlot::yLeft)->font());
QwtScaleDraw *sd = axisScaleDraw(QwtPlot::yLeft);
sd->setMinimumExtent( fm.width("100.00") );
}
QwtLinearColorMap * ribi::CreateColorMap() noexcept
{
QwtLinearColorMap * const color_map = new QwtLinearColorMap(Qt::red,Qt::blue);
color_map->addColorStop(0.2,Qt::yellow);
color_map->addColorStop(0.4,Qt::green);
color_map->addColorStop(0.6,Qt::cyan);
color_map->addColorStop(0.8,Qt::blue);
return color_map;
}
void ribi::QwtSurfacePlotterPlot::SetData(
const std::string& function_str,
const double minx, const double maxx,
const double miny, const double maxy,
const double minz, const double maxz
)
{
const auto f = std::make_shared<FunctionParser>();
f->Parse(function_str,"x,y");
if (f->GetParseErrorType() != FunctionParser::FP_NO_ERROR)
{
std::stringstream s;
s << "ribi::QwtSurfacePlotterPlot::SetData: Cannot parse " << function_str;
throw std::logic_error(s.str().c_str());
}
SetData(
f,
minx,maxx,
miny,maxy,
minz,maxz
);
}
void ribi::QwtSurfacePlotterPlot::SetData(
const std::shared_ptr<FunctionParser>& function_parser,
const double minx, const double maxx,
const double miny, const double maxy,
const double minz, const double maxz
)
{
//data will be deleted by m_spectogram
QwtSurfacePlotterData * const data
= new QwtSurfacePlotterData(
function_parser,
minx,maxx,
miny,maxy,
minz,maxz
);
assert(data);
m_spectrogram->setData(data);
replot();
//Set the contour levels and colors
{
QList<double> contour_levels;
const double dz = (maxz-minz)/6.0;
contour_levels.append(minz + (0.0 * dz));
contour_levels.append(minz + (1.0 * dz));
contour_levels.append(minz + (2.0 * dz));
contour_levels.append(minz + (3.0 * dz));
contour_levels.append(minz + (4.0 * dz));
contour_levels.append(minz + (5.0 * dz));
m_spectrogram->setContourLevels(contour_levels );
}
assert(m_spectrogram->data());
const QwtInterval zInterval = m_spectrogram->data()->interval(Qt::ZAxis );
// A color bar on the right axis
QwtScaleWidget * const rightAxis = axisWidget( QwtPlot::yRight );
rightAxis->setColorBarEnabled(true);
rightAxis->setColorMap(zInterval,CreateColorMap());
m_spectrogram->setColorMap(CreateColorMap());
setAxisScale( QwtPlot::yRight,minz,maxz);
rightAxis->repaint();
replot();
}
void ribi::QwtSurfacePlotterPlot::showContour(const bool do_show)
{
m_spectrogram->setDisplayMode(QwtPlotSpectrogram::ContourMode,do_show);
replot();
}
void ribi::QwtSurfacePlotterPlot::showSpectrogram(const bool do_show)
{
m_spectrogram->setDisplayMode( QwtPlotSpectrogram::ImageMode,do_show);
m_spectrogram->setDefaultContourPen(
do_show ? QPen(Qt::black, 0) : QPen(Qt::NoPen) );
replot();
}