Chris@58
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@0
|
2
|
Chris@0
|
3 /*
|
Chris@59
|
4 Sonic Visualiser
|
Chris@59
|
5 An audio file viewer and annotation editor.
|
Chris@59
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@182
|
7 This file copyright 2006 Chris Cannam and QMUL.
|
Chris@0
|
8
|
Chris@59
|
9 This program is free software; you can redistribute it and/or
|
Chris@59
|
10 modify it under the terms of the GNU General Public License as
|
Chris@59
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@59
|
12 License, or (at your option) any later version. See the file
|
Chris@59
|
13 COPYING included with this distribution for more information.
|
Chris@0
|
14 */
|
Chris@0
|
15
|
Chris@0
|
16 #include "Colour3DPlotLayer.h"
|
Chris@0
|
17
|
Chris@0
|
18 #include "base/Profiler.h"
|
Chris@197
|
19 #include "base/LogRange.h"
|
Chris@444
|
20 #include "base/RangeMapper.h"
|
Chris@1077
|
21
|
Chris@376
|
22 #include "ColourMapper.h"
|
Chris@1077
|
23 #include "LayerGeometryProvider.h"
|
Chris@1078
|
24 #include "PaintAssistant.h"
|
Chris@1077
|
25
|
Chris@1077
|
26 #include "view/ViewManager.h"
|
Chris@0
|
27
|
Chris@0
|
28 #include <QPainter>
|
Chris@0
|
29 #include <QImage>
|
Chris@0
|
30 #include <QRect>
|
Chris@316
|
31 #include <QTextStream>
|
Chris@1018
|
32 #include <QSettings>
|
Chris@0
|
33
|
Chris@0
|
34 #include <iostream>
|
Chris@0
|
35
|
Chris@0
|
36 #include <cassert>
|
Chris@0
|
37
|
Chris@545
|
38 #ifndef __GNUC__
|
Chris@545
|
39 #include <alloca.h>
|
Chris@545
|
40 #endif
|
Chris@545
|
41
|
Chris@903
|
42 using std::vector;
|
Chris@903
|
43
|
Chris@353
|
44 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
|
Chris@125
|
45
|
Chris@0
|
46
|
Chris@44
|
47 Colour3DPlotLayer::Colour3DPlotLayer() :
|
Chris@0
|
48 m_model(0),
|
Chris@159
|
49 m_cache(0),
|
Chris@469
|
50 m_peaksCache(0),
|
Chris@461
|
51 m_cacheValidStart(0),
|
Chris@461
|
52 m_cacheValidEnd(0),
|
Chris@1099
|
53 m_colourScale(ColourScale::LinearColourScale),
|
Chris@461
|
54 m_colourScaleSet(false),
|
Chris@197
|
55 m_colourMap(0),
|
Chris@534
|
56 m_gain(1.0),
|
Chris@1099
|
57 m_binScale(Colour3DPlotRenderer::LinearBinScale),
|
Chris@1099
|
58 m_normalization(ColumnOp::NoNormalization),
|
Chris@444
|
59 m_invertVertical(false),
|
Chris@465
|
60 m_opaque(false),
|
Chris@535
|
61 m_smooth(false),
|
Chris@805
|
62 m_peakResolution(256),
|
Chris@444
|
63 m_miny(0),
|
Chris@444
|
64 m_maxy(0)
|
Chris@0
|
65 {
|
Chris@1018
|
66 QSettings settings;
|
Chris@1018
|
67 settings.beginGroup("Preferences");
|
Chris@1018
|
68 setColourMap(settings.value("colour-3d-plot-colour", ColourMapper::Green).toInt());
|
Chris@1018
|
69 settings.endGroup();
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 Colour3DPlotLayer::~Colour3DPlotLayer()
|
Chris@0
|
73 {
|
Chris@461
|
74 delete m_cache;
|
Chris@469
|
75 delete m_peaksCache;
|
Chris@0
|
76 }
|
Chris@0
|
77
|
Chris@0
|
78 void
|
Chris@0
|
79 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model)
|
Chris@0
|
80 {
|
Chris@193
|
81 if (m_model == model) return;
|
Chris@193
|
82 const DenseThreeDimensionalModel *oldModel = m_model;
|
Chris@0
|
83 m_model = model;
|
Chris@0
|
84 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
85
|
Chris@320
|
86 connectSignals(m_model);
|
Chris@0
|
87
|
Chris@461
|
88 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
|
Chris@908
|
89 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
|
Chris@908
|
90 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
|
Chris@0
|
91
|
Chris@474
|
92 m_peakResolution = 256;
|
Chris@474
|
93 if (model->getResolution() > 512) {
|
Chris@474
|
94 m_peakResolution = 16;
|
Chris@474
|
95 } else if (model->getResolution() > 128) {
|
Chris@474
|
96 m_peakResolution = 64;
|
Chris@474
|
97 } else if (model->getResolution() > 2) {
|
Chris@474
|
98 m_peakResolution = 128;
|
Chris@474
|
99 }
|
Chris@474
|
100 cacheInvalid();
|
Chris@474
|
101
|
Chris@0
|
102 emit modelReplaced();
|
Chris@193
|
103 emit sliceableModelReplaced(oldModel, model);
|
Chris@0
|
104 }
|
Chris@0
|
105
|
Chris@0
|
106 void
|
Chris@0
|
107 Colour3DPlotLayer::cacheInvalid()
|
Chris@0
|
108 {
|
Chris@469
|
109 delete m_cache;
|
Chris@469
|
110 delete m_peaksCache;
|
Chris@0
|
111 m_cache = 0;
|
Chris@469
|
112 m_peaksCache = 0;
|
Chris@461
|
113 m_cacheValidStart = 0;
|
Chris@461
|
114 m_cacheValidEnd = 0;
|
Chris@0
|
115 }
|
Chris@0
|
116
|
Chris@0
|
117 void
|
Chris@908
|
118 Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@0
|
119 {
|
Chris@843
|
120 if (!m_cache || !m_model) return;
|
Chris@461
|
121
|
Chris@805
|
122 int modelResolution = m_model->getResolution();
|
Chris@908
|
123 int start = int(startFrame / modelResolution);
|
Chris@908
|
124 int end = int(endFrame / modelResolution + 1);
|
Chris@461
|
125 if (m_cacheValidStart < end) m_cacheValidStart = end;
|
Chris@461
|
126 if (m_cacheValidEnd > start) m_cacheValidEnd = start;
|
Chris@461
|
127 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
|
Chris@461
|
128 }
|
Chris@461
|
129
|
Chris@461
|
130 void
|
Chris@461
|
131 Colour3DPlotLayer::modelChanged()
|
Chris@461
|
132 {
|
Chris@1099
|
133 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) {
|
Chris@461
|
134 if (m_model) {
|
Chris@461
|
135 if (m_model->shouldUseLogValueScale()) {
|
Chris@1099
|
136 setColourScale(ColourScale::LogColourScale);
|
Chris@461
|
137 } else {
|
Chris@461
|
138 m_colourScaleSet = true;
|
Chris@461
|
139 }
|
Chris@461
|
140 }
|
Chris@461
|
141 }
|
Chris@0
|
142 cacheInvalid();
|
Chris@0
|
143 }
|
Chris@0
|
144
|
Chris@461
|
145 void
|
Chris@908
|
146 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@461
|
147 {
|
Chris@1099
|
148 if (!m_colourScaleSet && m_colourScale == ColourScale::LinearColourScale) {
|
Chris@461
|
149 if (m_model && m_model->getWidth() > 50) {
|
Chris@461
|
150 if (m_model->shouldUseLogValueScale()) {
|
Chris@1099
|
151 setColourScale(ColourScale::LogColourScale);
|
Chris@461
|
152 } else {
|
Chris@461
|
153 m_colourScaleSet = true;
|
Chris@461
|
154 }
|
Chris@461
|
155 }
|
Chris@461
|
156 }
|
Chris@461
|
157 cacheInvalid(startFrame, endFrame);
|
Chris@461
|
158 }
|
Chris@461
|
159
|
Chris@159
|
160 Layer::PropertyList
|
Chris@159
|
161 Colour3DPlotLayer::getProperties() const
|
Chris@159
|
162 {
|
Chris@159
|
163 PropertyList list;
|
Chris@197
|
164 list.push_back("Colour");
|
Chris@159
|
165 list.push_back("Colour Scale");
|
Chris@197
|
166 list.push_back("Normalize Columns");
|
Chris@197
|
167 list.push_back("Normalize Visible Area");
|
Chris@534
|
168 list.push_back("Gain");
|
Chris@531
|
169 list.push_back("Bin Scale");
|
Chris@357
|
170 list.push_back("Invert Vertical Scale");
|
Chris@465
|
171 list.push_back("Opaque");
|
Chris@535
|
172 list.push_back("Smooth");
|
Chris@159
|
173 return list;
|
Chris@159
|
174 }
|
Chris@159
|
175
|
Chris@159
|
176 QString
|
Chris@159
|
177 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@159
|
178 {
|
Chris@197
|
179 if (name == "Colour") return tr("Colour");
|
Chris@197
|
180 if (name == "Colour Scale") return tr("Scale");
|
Chris@197
|
181 if (name == "Normalize Columns") return tr("Normalize Columns");
|
Chris@197
|
182 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
|
Chris@357
|
183 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
|
Chris@534
|
184 if (name == "Gain") return tr("Gain");
|
Chris@465
|
185 if (name == "Opaque") return tr("Always Opaque");
|
Chris@535
|
186 if (name == "Smooth") return tr("Smooth");
|
Chris@531
|
187 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@159
|
188 return "";
|
Chris@159
|
189 }
|
Chris@159
|
190
|
Chris@346
|
191 QString
|
Chris@346
|
192 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@346
|
193 {
|
Chris@346
|
194 if (name == "Normalize Columns") return "normalise-columns";
|
Chris@346
|
195 if (name == "Normalize Visible Area") return "normalise";
|
Chris@357
|
196 if (name == "Invert Vertical Scale") return "invert-vertical";
|
Chris@465
|
197 if (name == "Opaque") return "opaque";
|
Chris@535
|
198 if (name == "Smooth") return "smooth";
|
Chris@346
|
199 return "";
|
Chris@346
|
200 }
|
Chris@346
|
201
|
Chris@159
|
202 Layer::PropertyType
|
Chris@159
|
203 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
|
Chris@159
|
204 {
|
Chris@534
|
205 if (name == "Gain") return RangeProperty;
|
Chris@197
|
206 if (name == "Normalize Columns") return ToggleProperty;
|
Chris@197
|
207 if (name == "Normalize Visible Area") return ToggleProperty;
|
Chris@357
|
208 if (name == "Invert Vertical Scale") return ToggleProperty;
|
Chris@465
|
209 if (name == "Opaque") return ToggleProperty;
|
Chris@535
|
210 if (name == "Smooth") return ToggleProperty;
|
Chris@159
|
211 return ValueProperty;
|
Chris@159
|
212 }
|
Chris@159
|
213
|
Chris@159
|
214 QString
|
Chris@159
|
215 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@159
|
216 {
|
Chris@197
|
217 if (name == "Normalize Columns" ||
|
Chris@197
|
218 name == "Normalize Visible Area" ||
|
Chris@534
|
219 name == "Colour Scale" ||
|
Chris@534
|
220 name == "Gain") return tr("Scale");
|
Chris@531
|
221 if (name == "Bin Scale" ||
|
Chris@531
|
222 name == "Invert Vertical Scale") return tr("Bins");
|
Chris@465
|
223 if (name == "Opaque" ||
|
Chris@535
|
224 name == "Smooth" ||
|
Chris@465
|
225 name == "Colour") return tr("Colour");
|
Chris@159
|
226 return QString();
|
Chris@159
|
227 }
|
Chris@159
|
228
|
Chris@159
|
229 int
|
Chris@159
|
230 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
231 int *min, int *max, int *deflt) const
|
Chris@159
|
232 {
|
Chris@216
|
233 int val = 0;
|
Chris@159
|
234
|
Chris@216
|
235 int garbage0, garbage1, garbage2;
|
Chris@159
|
236 if (!min) min = &garbage0;
|
Chris@159
|
237 if (!max) max = &garbage1;
|
Chris@216
|
238 if (!deflt) deflt = &garbage2;
|
Chris@159
|
239
|
Chris@534
|
240 if (name == "Gain") {
|
Chris@534
|
241
|
Chris@534
|
242 *min = -50;
|
Chris@534
|
243 *max = 50;
|
Chris@534
|
244
|
Chris@902
|
245 *deflt = int(lrint(log10(1.0) * 20.0));
|
Chris@534
|
246 if (*deflt < *min) *deflt = *min;
|
Chris@534
|
247 if (*deflt > *max) *deflt = *max;
|
Chris@534
|
248
|
Chris@902
|
249 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@534
|
250 if (val < *min) val = *min;
|
Chris@534
|
251 if (val > *max) val = *max;
|
Chris@534
|
252
|
Chris@534
|
253 } else if (name == "Colour Scale") {
|
Chris@159
|
254
|
Chris@1099
|
255 // linear, log, +/-1, abs
|
Chris@159
|
256 *min = 0;
|
Chris@509
|
257 *max = 3;
|
Chris@1099
|
258 *deflt = 0;
|
Chris@159
|
259
|
Chris@216
|
260 val = (int)m_colourScale;
|
Chris@159
|
261
|
Chris@197
|
262 } else if (name == "Colour") {
|
Chris@197
|
263
|
Chris@197
|
264 *min = 0;
|
Chris@197
|
265 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@216
|
266 *deflt = 0;
|
Chris@197
|
267
|
Chris@216
|
268 val = m_colourMap;
|
Chris@197
|
269
|
Chris@1099
|
270 } else if (name == "Normalization") {
|
Chris@197
|
271
|
Chris@1099
|
272 *min = 0;
|
Chris@1099
|
273 *max = 3;
|
Chris@1099
|
274 *deflt = int(ColumnOp::NoNormalization);
|
Chris@1099
|
275 val = (int)m_normalization;
|
Chris@197
|
276
|
Chris@357
|
277 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
278
|
Chris@357
|
279 *deflt = 0;
|
Chris@357
|
280 val = (m_invertVertical ? 1 : 0);
|
Chris@357
|
281
|
Chris@531
|
282 } else if (name == "Bin Scale") {
|
Chris@531
|
283
|
Chris@531
|
284 *min = 0;
|
Chris@531
|
285 *max = 1;
|
Chris@1099
|
286 *deflt = int(Colour3DPlotRenderer::LinearBinScale);
|
Chris@531
|
287 val = (int)m_binScale;
|
Chris@531
|
288
|
Chris@465
|
289 } else if (name == "Opaque") {
|
Chris@465
|
290
|
Chris@465
|
291 *deflt = 0;
|
Chris@465
|
292 val = (m_opaque ? 1 : 0);
|
Chris@465
|
293
|
Chris@535
|
294 } else if (name == "Smooth") {
|
Chris@535
|
295
|
Chris@535
|
296 *deflt = 0;
|
Chris@535
|
297 val = (m_smooth ? 1 : 0);
|
Chris@535
|
298
|
Chris@159
|
299 } else {
|
Chris@216
|
300 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@159
|
301 }
|
Chris@159
|
302
|
Chris@216
|
303 return val;
|
Chris@159
|
304 }
|
Chris@159
|
305
|
Chris@159
|
306 QString
|
Chris@159
|
307 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@159
|
308 int value) const
|
Chris@159
|
309 {
|
Chris@197
|
310 if (name == "Colour") {
|
Chris@197
|
311 return ColourMapper::getColourMapName(value);
|
Chris@197
|
312 }
|
Chris@159
|
313 if (name == "Colour Scale") {
|
Chris@159
|
314 switch (value) {
|
Chris@159
|
315 default:
|
Chris@1099
|
316 //!!! yuck
|
Chris@198
|
317 case 0: return tr("Linear");
|
Chris@198
|
318 case 1: return tr("Log");
|
Chris@198
|
319 case 2: return tr("+/-1");
|
Chris@509
|
320 case 3: return tr("Absolute");
|
Chris@159
|
321 }
|
Chris@159
|
322 }
|
Chris@1099
|
323 if (name == "Normalization") {
|
Chris@1099
|
324 return ""; // icon only
|
Chris@1099
|
325 }
|
Chris@531
|
326 if (name == "Bin Scale") {
|
Chris@531
|
327 switch (value) {
|
Chris@531
|
328 default:
|
Chris@531
|
329 case 0: return tr("Linear");
|
Chris@531
|
330 case 1: return tr("Log");
|
Chris@531
|
331 }
|
Chris@531
|
332 }
|
Chris@159
|
333 return tr("<unknown>");
|
Chris@159
|
334 }
|
Chris@159
|
335
|
Chris@1099
|
336 QString
|
Chris@1099
|
337 Colour3DPlotLayer::getPropertyValueIconName(const PropertyName &name,
|
Chris@1099
|
338 int value) const
|
Chris@1099
|
339 {
|
Chris@1099
|
340 if (name == "Normalization") {
|
Chris@1099
|
341 switch(value) {
|
Chris@1099
|
342 default:
|
Chris@1099
|
343 case 0: return "normalise-none";
|
Chris@1099
|
344 case 1: return "normalise-columns";
|
Chris@1099
|
345 case 2: return "normalise";
|
Chris@1099
|
346 case 3: return "normalise-hybrid";
|
Chris@1099
|
347 }
|
Chris@1099
|
348 }
|
Chris@1099
|
349 return "";
|
Chris@1099
|
350 }
|
Chris@1099
|
351
|
Chris@534
|
352 RangeMapper *
|
Chris@534
|
353 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@534
|
354 {
|
Chris@534
|
355 if (name == "Gain") {
|
Chris@534
|
356 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@534
|
357 }
|
Chris@534
|
358 return 0;
|
Chris@534
|
359 }
|
Chris@534
|
360
|
Chris@159
|
361 void
|
Chris@159
|
362 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
|
Chris@159
|
363 {
|
Chris@534
|
364 if (name == "Gain") {
|
Chris@902
|
365 setGain(float(pow(10, value/20.0)));
|
Chris@534
|
366 } else if (name == "Colour Scale") {
|
Chris@159
|
367 switch (value) {
|
Chris@159
|
368 default:
|
Chris@1099
|
369 case 0: setColourScale(ColourScale::LinearColourScale); break;
|
Chris@1099
|
370 case 1: setColourScale(ColourScale::LogColourScale); break;
|
Chris@1099
|
371 case 2: setColourScale(ColourScale::PlusMinusOneScale); break;
|
Chris@1099
|
372 case 3: setColourScale(ColourScale::AbsoluteScale); break;
|
Chris@159
|
373 }
|
Chris@197
|
374 } else if (name == "Colour") {
|
Chris@197
|
375 setColourMap(value);
|
Chris@357
|
376 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
377 setInvertVertical(value ? true : false);
|
Chris@465
|
378 } else if (name == "Opaque") {
|
Chris@465
|
379 setOpaque(value ? true : false);
|
Chris@535
|
380 } else if (name == "Smooth") {
|
Chris@535
|
381 setSmooth(value ? true : false);
|
Chris@531
|
382 } else if (name == "Bin Scale") {
|
Chris@531
|
383 switch (value) {
|
Chris@531
|
384 default:
|
Chris@1099
|
385 case 0: setBinScale(Colour3DPlotRenderer::LinearBinScale); break;
|
Chris@1099
|
386 case 1: setBinScale(Colour3DPlotRenderer::LogBinScale); break;
|
Chris@531
|
387 }
|
Chris@1099
|
388 } else if (name == "Normalization") {
|
Chris@1099
|
389 switch (value) {
|
Chris@1099
|
390 default:
|
Chris@1099
|
391 case 0: setNormalization(ColumnOp::NoNormalization); break;
|
Chris@1099
|
392 case 1: setNormalization(ColumnOp::NormalizeColumns); break;
|
Chris@1099
|
393 case 2: setNormalization(ColumnOp::NormalizeVisibleArea); break;
|
Chris@1099
|
394 case 3: setNormalization(ColumnOp::NormalizeHybrid); break;
|
Chris@1099
|
395 }
|
Chris@159
|
396 }
|
Chris@159
|
397 }
|
Chris@159
|
398
|
Chris@159
|
399 void
|
Chris@1099
|
400 Colour3DPlotLayer::setColourScale(ColourScale::Scale scale)
|
Chris@159
|
401 {
|
Chris@159
|
402 if (m_colourScale == scale) return;
|
Chris@159
|
403 m_colourScale = scale;
|
Chris@461
|
404 m_colourScaleSet = true;
|
Chris@159
|
405 cacheInvalid();
|
Chris@159
|
406 emit layerParametersChanged();
|
Chris@159
|
407 }
|
Chris@159
|
408
|
Chris@197
|
409 void
|
Chris@197
|
410 Colour3DPlotLayer::setColourMap(int map)
|
Chris@197
|
411 {
|
Chris@197
|
412 if (m_colourMap == map) return;
|
Chris@197
|
413 m_colourMap = map;
|
Chris@197
|
414 cacheInvalid();
|
Chris@197
|
415 emit layerParametersChanged();
|
Chris@197
|
416 }
|
Chris@197
|
417
|
Chris@197
|
418 void
|
Chris@534
|
419 Colour3DPlotLayer::setGain(float gain)
|
Chris@534
|
420 {
|
Chris@534
|
421 if (m_gain == gain) return;
|
Chris@534
|
422 m_gain = gain;
|
Chris@534
|
423 cacheInvalid();
|
Chris@534
|
424 emit layerParametersChanged();
|
Chris@534
|
425 }
|
Chris@534
|
426
|
Chris@534
|
427 float
|
Chris@534
|
428 Colour3DPlotLayer::getGain() const
|
Chris@534
|
429 {
|
Chris@534
|
430 return m_gain;
|
Chris@534
|
431 }
|
Chris@534
|
432
|
Chris@534
|
433 void
|
Chris@1099
|
434 Colour3DPlotLayer::setBinScale(Colour3DPlotRenderer::BinScale binScale)
|
Chris@531
|
435 {
|
Chris@531
|
436 if (m_binScale == binScale) return;
|
Chris@531
|
437 m_binScale = binScale;
|
Chris@531
|
438 cacheInvalid();
|
Chris@531
|
439 emit layerParametersChanged();
|
Chris@531
|
440 }
|
Chris@531
|
441
|
Chris@1099
|
442 Colour3DPlotRenderer::BinScale
|
Chris@531
|
443 Colour3DPlotLayer::getBinScale() const
|
Chris@531
|
444 {
|
Chris@531
|
445 return m_binScale;
|
Chris@531
|
446 }
|
Chris@531
|
447
|
Chris@531
|
448 void
|
Chris@1099
|
449 Colour3DPlotLayer::setNormalization(ColumnOp::Normalization n)
|
Chris@197
|
450 {
|
Chris@1099
|
451 if (m_normalization == n) return;
|
Chris@1099
|
452
|
Chris@1099
|
453 m_normalization = n;
|
Chris@197
|
454 cacheInvalid();
|
Chris@1099
|
455
|
Chris@197
|
456 emit layerParametersChanged();
|
Chris@197
|
457 }
|
Chris@197
|
458
|
Chris@1099
|
459 ColumnOp::Normalization
|
Chris@1099
|
460 Colour3DPlotLayer::getNormalization() const
|
Chris@197
|
461 {
|
Chris@1099
|
462 return m_normalization;
|
Chris@197
|
463 }
|
Chris@197
|
464
|
Chris@357
|
465 void
|
Chris@357
|
466 Colour3DPlotLayer::setInvertVertical(bool n)
|
Chris@357
|
467 {
|
Chris@357
|
468 if (m_invertVertical == n) return;
|
Chris@357
|
469 m_invertVertical = n;
|
Chris@357
|
470 cacheInvalid();
|
Chris@357
|
471 emit layerParametersChanged();
|
Chris@357
|
472 }
|
Chris@357
|
473
|
Chris@465
|
474 void
|
Chris@465
|
475 Colour3DPlotLayer::setOpaque(bool n)
|
Chris@465
|
476 {
|
Chris@465
|
477 if (m_opaque == n) return;
|
Chris@465
|
478 m_opaque = n;
|
Chris@465
|
479 emit layerParametersChanged();
|
Chris@465
|
480 }
|
Chris@465
|
481
|
Chris@535
|
482 void
|
Chris@535
|
483 Colour3DPlotLayer::setSmooth(bool n)
|
Chris@535
|
484 {
|
Chris@535
|
485 if (m_smooth == n) return;
|
Chris@535
|
486 m_smooth = n;
|
Chris@535
|
487 emit layerParametersChanged();
|
Chris@535
|
488 }
|
Chris@535
|
489
|
Chris@357
|
490 bool
|
Chris@357
|
491 Colour3DPlotLayer::getInvertVertical() const
|
Chris@357
|
492 {
|
Chris@357
|
493 return m_invertVertical;
|
Chris@357
|
494 }
|
Chris@357
|
495
|
Chris@25
|
496 bool
|
Chris@465
|
497 Colour3DPlotLayer::getOpaque() const
|
Chris@465
|
498 {
|
Chris@465
|
499 return m_opaque;
|
Chris@465
|
500 }
|
Chris@465
|
501
|
Chris@535
|
502 bool
|
Chris@535
|
503 Colour3DPlotLayer::getSmooth() const
|
Chris@535
|
504 {
|
Chris@535
|
505 return m_smooth;
|
Chris@535
|
506 }
|
Chris@535
|
507
|
Chris@475
|
508 void
|
Chris@916
|
509 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
|
Chris@475
|
510 {
|
Chris@475
|
511 if (dormant) {
|
Chris@475
|
512
|
Chris@475
|
513 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
514 cerr << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")"
|
Chris@585
|
515 << endl;
|
Chris@475
|
516 #endif
|
Chris@475
|
517
|
Chris@475
|
518 if (isLayerDormant(v)) {
|
Chris@475
|
519 return;
|
Chris@475
|
520 }
|
Chris@475
|
521
|
Chris@475
|
522 Layer::setLayerDormant(v, true);
|
Chris@475
|
523
|
Chris@475
|
524 cacheInvalid();
|
Chris@475
|
525
|
Chris@475
|
526 } else {
|
Chris@475
|
527
|
Chris@475
|
528 Layer::setLayerDormant(v, false);
|
Chris@475
|
529 }
|
Chris@475
|
530 }
|
Chris@475
|
531
|
Chris@465
|
532 bool
|
Chris@916
|
533 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider *v) const
|
Chris@25
|
534 {
|
Chris@1099
|
535 if (m_normalization == ColumnOp::NormalizeVisibleArea) {
|
Chris@812
|
536 return false;
|
Chris@812
|
537 }
|
Chris@812
|
538 if (shouldPaintDenseIn(v)) {
|
Chris@812
|
539 return true;
|
Chris@812
|
540 }
|
Chris@25
|
541 QPoint discard;
|
Chris@44
|
542 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@25
|
543 }
|
Chris@25
|
544
|
Chris@444
|
545 bool
|
Chris@904
|
546 Colour3DPlotLayer::getValueExtents(double &min, double &max,
|
Chris@444
|
547 bool &logarithmic, QString &unit) const
|
Chris@444
|
548 {
|
Chris@444
|
549 if (!m_model) return false;
|
Chris@444
|
550
|
Chris@444
|
551 min = 0;
|
Chris@904
|
552 max = double(m_model->getHeight());
|
Chris@444
|
553
|
Chris@444
|
554 logarithmic = false;
|
Chris@444
|
555 unit = "";
|
Chris@444
|
556
|
Chris@444
|
557 return true;
|
Chris@444
|
558 }
|
Chris@444
|
559
|
Chris@444
|
560 bool
|
Chris@904
|
561 Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const
|
Chris@444
|
562 {
|
Chris@444
|
563 if (!m_model) return false;
|
Chris@444
|
564
|
Chris@904
|
565 double hmax = double(m_model->getHeight());
|
Chris@902
|
566
|
Chris@904
|
567 min = m_miny;
|
Chris@904
|
568 max = m_maxy;
|
Chris@444
|
569 if (max <= min) {
|
Chris@444
|
570 min = 0;
|
Chris@902
|
571 max = hmax;
|
Chris@444
|
572 }
|
Chris@444
|
573 if (min < 0) min = 0;
|
Chris@902
|
574 if (max > hmax) max = hmax;
|
Chris@444
|
575
|
Chris@444
|
576 return true;
|
Chris@444
|
577 }
|
Chris@444
|
578
|
Chris@444
|
579 bool
|
Chris@904
|
580 Colour3DPlotLayer::setDisplayExtents(double min, double max)
|
Chris@444
|
581 {
|
Chris@444
|
582 if (!m_model) return false;
|
Chris@444
|
583
|
Chris@904
|
584 m_miny = int(lrint(min));
|
Chris@904
|
585 m_maxy = int(lrint(max));
|
Chris@444
|
586
|
Chris@444
|
587 emit layerParametersChanged();
|
Chris@444
|
588 return true;
|
Chris@444
|
589 }
|
Chris@444
|
590
|
Chris@725
|
591 bool
|
Chris@916
|
592 Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int,
|
Chris@904
|
593 double &, QString &) const
|
Chris@725
|
594 {
|
Chris@725
|
595 return false;//!!!
|
Chris@725
|
596 }
|
Chris@725
|
597
|
Chris@444
|
598 int
|
Chris@444
|
599 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@444
|
600 {
|
Chris@444
|
601 if (!m_model) return 0;
|
Chris@444
|
602
|
Chris@444
|
603 defaultStep = 0;
|
Chris@444
|
604 int h = m_model->getHeight();
|
Chris@444
|
605 return h;
|
Chris@444
|
606 }
|
Chris@444
|
607
|
Chris@444
|
608 int
|
Chris@444
|
609 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
|
Chris@444
|
610 {
|
Chris@444
|
611 if (!m_model) return 0;
|
Chris@444
|
612
|
Chris@904
|
613 double min, max;
|
Chris@444
|
614 getDisplayExtents(min, max);
|
Chris@904
|
615 return m_model->getHeight() - int(lrint(max - min));
|
Chris@444
|
616 }
|
Chris@444
|
617
|
Chris@444
|
618 void
|
Chris@444
|
619 Colour3DPlotLayer::setVerticalZoomStep(int step)
|
Chris@444
|
620 {
|
Chris@444
|
621 if (!m_model) return;
|
Chris@444
|
622
|
Chris@587
|
623 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl;
|
Chris@444
|
624
|
Chris@444
|
625 int dist = m_model->getHeight() - step;
|
Chris@444
|
626 if (dist < 1) dist = 1;
|
Chris@904
|
627 double centre = m_miny + (m_maxy - m_miny) / 2.0;
|
Chris@904
|
628 m_miny = int(lrint(centre - dist/2.0));
|
Chris@444
|
629 if (m_miny < 0) m_miny = 0;
|
Chris@444
|
630 m_maxy = m_miny + dist;
|
Chris@444
|
631 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight();
|
Chris@444
|
632
|
Chris@587
|
633 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl;
|
Chris@444
|
634
|
Chris@444
|
635 emit layerParametersChanged();
|
Chris@444
|
636 }
|
Chris@444
|
637
|
Chris@444
|
638 RangeMapper *
|
Chris@444
|
639 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
|
Chris@444
|
640 {
|
Chris@444
|
641 if (!m_model) return 0;
|
Chris@444
|
642
|
Chris@444
|
643 return new LinearRangeMapper(0, m_model->getHeight(),
|
Chris@444
|
644 0, m_model->getHeight(), "");
|
Chris@444
|
645 }
|
Chris@444
|
646
|
Chris@904
|
647 double
|
Chris@916
|
648 Colour3DPlotLayer::getYForBin(LayerGeometryProvider *v, double bin) const
|
Chris@532
|
649 {
|
Chris@904
|
650 double y = bin;
|
Chris@532
|
651 if (!m_model) return y;
|
Chris@904
|
652 double mn = 0, mx = m_model->getHeight();
|
Chris@532
|
653 getDisplayExtents(mn, mx);
|
Chris@916
|
654 double h = v->getPaintHeight();
|
Chris@1099
|
655 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
|
Chris@532
|
656 y = h - (((bin - mn) * h) / (mx - mn));
|
Chris@532
|
657 } else {
|
Chris@904
|
658 double logmin = mn + 1, logmax = mx + 1;
|
Chris@532
|
659 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
660 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
|
Chris@532
|
661 }
|
Chris@532
|
662 return y;
|
Chris@532
|
663 }
|
Chris@532
|
664
|
Chris@904
|
665 double
|
Chris@916
|
666 Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const
|
Chris@532
|
667 {
|
Chris@904
|
668 double bin = y;
|
Chris@532
|
669 if (!m_model) return bin;
|
Chris@904
|
670 double mn = 0, mx = m_model->getHeight();
|
Chris@532
|
671 getDisplayExtents(mn, mx);
|
Chris@916
|
672 double h = v->getPaintHeight();
|
Chris@1099
|
673 if (m_binScale == Colour3DPlotRenderer::LinearBinScale) {
|
Chris@532
|
674 bin = mn + ((h - y) * (mx - mn)) / h;
|
Chris@532
|
675 } else {
|
Chris@904
|
676 double logmin = mn + 1, logmax = mx + 1;
|
Chris@532
|
677 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
678 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1;
|
Chris@532
|
679 }
|
Chris@532
|
680 return bin;
|
Chris@532
|
681 }
|
Chris@532
|
682
|
Chris@25
|
683 QString
|
Chris@916
|
684 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
|
Chris@25
|
685 {
|
Chris@25
|
686 if (!m_model) return "";
|
Chris@25
|
687
|
Chris@25
|
688 int x = pos.x();
|
Chris@25
|
689 int y = pos.y();
|
Chris@25
|
690
|
Chris@902
|
691 sv_frame_t modelStart = m_model->getStartFrame();
|
Chris@805
|
692 int modelResolution = m_model->getResolution();
|
Chris@25
|
693
|
Chris@902
|
694 double srRatio =
|
Chris@902
|
695 v->getViewManager()->getMainModelSampleRate() /
|
Chris@902
|
696 m_model->getSampleRate();
|
Chris@159
|
697
|
Chris@902
|
698 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
|
Chris@812
|
699 modelResolution);
|
Chris@25
|
700
|
Chris@160
|
701 int f0 = sx0 * modelResolution;
|
Chris@160
|
702 int f1 = f0 + modelResolution;
|
Chris@160
|
703
|
Chris@447
|
704 int sh = m_model->getHeight();
|
Chris@447
|
705
|
Chris@447
|
706 int symin = m_miny;
|
Chris@447
|
707 int symax = m_maxy;
|
Chris@447
|
708 if (symax <= symin) {
|
Chris@447
|
709 symin = 0;
|
Chris@447
|
710 symax = sh;
|
Chris@447
|
711 }
|
Chris@447
|
712 if (symin < 0) symin = 0;
|
Chris@447
|
713 if (symax > sh) symax = sh;
|
Chris@447
|
714
|
Chris@916
|
715 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
|
Chris@916
|
716 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
|
Chris@534
|
717
|
Chris@903
|
718 int sy = getIBinForY(v, y);
|
Chris@25
|
719
|
Chris@812
|
720 if (sy < 0 || sy >= m_model->getHeight()) {
|
Chris@812
|
721 return "";
|
Chris@812
|
722 }
|
Chris@812
|
723
|
Chris@357
|
724 if (m_invertVertical) sy = m_model->getHeight() - sy - 1;
|
Chris@357
|
725
|
Chris@160
|
726 float value = m_model->getValueAt(sx0, sy);
|
Chris@159
|
727
|
Chris@682
|
728 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl;
|
Chris@25
|
729
|
Chris@25
|
730 QString binName = m_model->getBinName(sy);
|
Chris@25
|
731 if (binName == "") binName = QString("[%1]").arg(sy + 1);
|
Chris@25
|
732 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
|
Chris@25
|
733
|
Chris@25
|
734 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
|
Chris@160
|
735 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
|
Chris@25
|
736 .toText(true).c_str())
|
Chris@160
|
737 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
|
Chris@25
|
738 .toText(true).c_str())
|
Chris@25
|
739 .arg(binName)
|
Chris@25
|
740 .arg(value);
|
Chris@25
|
741
|
Chris@25
|
742 return text;
|
Chris@25
|
743 }
|
Chris@25
|
744
|
Chris@25
|
745 int
|
Chris@969
|
746 Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const
|
Chris@159
|
747 {
|
Chris@969
|
748 // Font is rotated
|
Chris@969
|
749 int cw = p.fontMetrics().height();
|
Chris@159
|
750 return cw;
|
Chris@159
|
751 }
|
Chris@159
|
752
|
Chris@159
|
753 int
|
Chris@916
|
754 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@25
|
755 {
|
Chris@25
|
756 if (!m_model) return 0;
|
Chris@25
|
757
|
Chris@160
|
758 QString sampleText = QString("[%1]").arg(m_model->getHeight());
|
Chris@25
|
759 int tw = paint.fontMetrics().width(sampleText);
|
Chris@98
|
760 bool another = false;
|
Chris@25
|
761
|
Chris@805
|
762 for (int i = 0; i < m_model->getHeight(); ++i) {
|
Chris@25
|
763 if (m_model->getBinName(i).length() > sampleText.length()) {
|
Chris@25
|
764 sampleText = m_model->getBinName(i);
|
Chris@98
|
765 another = true;
|
Chris@25
|
766 }
|
Chris@25
|
767 }
|
Chris@98
|
768 if (another) {
|
Chris@25
|
769 tw = std::max(tw, paint.fontMetrics().width(sampleText));
|
Chris@25
|
770 }
|
Chris@25
|
771
|
Chris@159
|
772 return tw + 13 + getColourScaleWidth(paint);
|
Chris@25
|
773 }
|
Chris@25
|
774
|
Chris@25
|
775 void
|
Chris@916
|
776 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@25
|
777 {
|
Chris@25
|
778 if (!m_model) return;
|
Chris@25
|
779
|
Chris@25
|
780 int h = rect.height(), w = rect.width();
|
Chris@25
|
781
|
Chris@159
|
782 int cw = getColourScaleWidth(paint);
|
Chris@159
|
783
|
Chris@159
|
784 int ch = h - 20;
|
Chris@159
|
785 if (ch > 20 && m_cache) {
|
Chris@159
|
786
|
Chris@904
|
787 double min = m_model->getMinimumLevel();
|
Chris@904
|
788 double max = m_model->getMaximumLevel();
|
Chris@447
|
789
|
Chris@904
|
790 double mmin = min;
|
Chris@904
|
791 double mmax = max;
|
Chris@447
|
792
|
Chris@1099
|
793 if (m_colourScale == ColourScale::LogColourScale) {
|
Chris@447
|
794 LogRange::mapRange(mmin, mmax);
|
Chris@1099
|
795 } else if (m_colourScale == ColourScale::PlusMinusOneScale) {
|
Chris@447
|
796 mmin = -1.f;
|
Chris@447
|
797 mmax = 1.f;
|
Chris@1099
|
798 } else if (m_colourScale == ColourScale::AbsoluteScale) {
|
Chris@509
|
799 if (mmin < 0) {
|
Chris@904
|
800 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin);
|
Chris@904
|
801 else mmax = fabs(mmax);
|
Chris@509
|
802 mmin = 0;
|
Chris@509
|
803 } else {
|
Chris@904
|
804 mmin = fabs(mmin);
|
Chris@904
|
805 mmax = fabs(mmax);
|
Chris@509
|
806 }
|
Chris@447
|
807 }
|
Chris@447
|
808
|
Chris@902
|
809 if (max == min) max = min + 1.f;
|
Chris@902
|
810 if (mmax == mmin) mmax = mmin + 1.f;
|
Chris@447
|
811
|
Chris@287
|
812 paint.setPen(v->getForeground());
|
Chris@447
|
813 paint.drawRect(4, 10, cw - 8, ch+1);
|
Chris@159
|
814
|
Chris@446
|
815 for (int y = 0; y < ch; ++y) {
|
Chris@904
|
816 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
|
Chris@1099
|
817 if (m_colourScale == ColourScale::LogColourScale) {
|
Chris@447
|
818 value = LogRange::map(value);
|
Chris@447
|
819 }
|
Chris@447
|
820 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
|
Chris@465
|
821 if (pixel >= 0 && pixel < 256) {
|
Chris@465
|
822 QRgb c = m_cache->color(pixel);
|
Chris@465
|
823 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
|
Chris@465
|
824 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
|
Chris@465
|
825 } else {
|
Chris@682
|
826 cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << endl;
|
Chris@465
|
827 }
|
Chris@159
|
828 }
|
Chris@446
|
829
|
Chris@446
|
830 QString minstr = QString("%1").arg(min);
|
Chris@446
|
831 QString maxstr = QString("%1").arg(max);
|
Chris@446
|
832
|
Chris@446
|
833 paint.save();
|
Chris@446
|
834
|
Chris@446
|
835 QFont font = paint.font();
|
Chris@1053
|
836 if (font.pixelSize() > 0) {
|
Chris@1053
|
837 int newSize = int(font.pixelSize() * 0.65);
|
Chris@1053
|
838 if (newSize < 6) newSize = 6;
|
Chris@1053
|
839 font.setPixelSize(newSize);
|
Chris@1053
|
840 paint.setFont(font);
|
Chris@1053
|
841 }
|
Chris@446
|
842
|
Chris@446
|
843 int msw = paint.fontMetrics().width(maxstr);
|
Chris@446
|
844
|
Chris@446
|
845 QMatrix m;
|
Chris@446
|
846 m.translate(cw - 6, ch + 10);
|
Chris@446
|
847 m.rotate(-90);
|
Chris@446
|
848
|
Chris@446
|
849 paint.setWorldMatrix(m);
|
Chris@446
|
850
|
Chris@1078
|
851 PaintAssistant::drawVisibleText(v, paint, 2, 0, minstr, PaintAssistant::OutlinedText);
|
Chris@446
|
852
|
Chris@446
|
853 m.translate(ch - msw - 2, 0);
|
Chris@446
|
854 paint.setWorldMatrix(m);
|
Chris@446
|
855
|
Chris@1078
|
856 PaintAssistant::drawVisibleText(v, paint, 0, 0, maxstr, PaintAssistant::OutlinedText);
|
Chris@446
|
857
|
Chris@446
|
858 paint.restore();
|
Chris@159
|
859 }
|
Chris@159
|
860
|
Chris@287
|
861 paint.setPen(v->getForeground());
|
Chris@159
|
862
|
Chris@445
|
863 int sh = m_model->getHeight();
|
Chris@445
|
864
|
Chris@445
|
865 int symin = m_miny;
|
Chris@445
|
866 int symax = m_maxy;
|
Chris@445
|
867 if (symax <= symin) {
|
Chris@445
|
868 symin = 0;
|
Chris@445
|
869 symax = sh;
|
Chris@445
|
870 }
|
Chris@445
|
871 if (symin < 0) symin = 0;
|
Chris@445
|
872 if (symax > sh) symax = sh;
|
Chris@445
|
873
|
Chris@532
|
874 paint.save();
|
Chris@456
|
875
|
Chris@533
|
876 int py = h;
|
Chris@25
|
877
|
Chris@969
|
878 int defaultFontHeight = paint.fontMetrics().height();
|
Chris@969
|
879
|
Chris@805
|
880 for (int i = symin; i <= symax; ++i) {
|
Chris@98
|
881
|
Chris@532
|
882 int y0;
|
Chris@534
|
883
|
Chris@903
|
884 y0 = getIYForBin(v, i);
|
Chris@532
|
885 int h = py - y0;
|
Chris@532
|
886
|
Chris@532
|
887 if (i > symin) {
|
Chris@532
|
888 if (paint.fontMetrics().height() >= h) {
|
Chris@969
|
889 if (h >= defaultFontHeight * 0.8) {
|
Chris@532
|
890 QFont tf = paint.font();
|
Chris@973
|
891 tf.setPixelSize(int(h * 0.8));
|
Chris@532
|
892 paint.setFont(tf);
|
Chris@532
|
893 } else {
|
Chris@532
|
894 continue;
|
Chris@532
|
895 }
|
Chris@532
|
896 }
|
Chris@532
|
897 }
|
Chris@25
|
898
|
Chris@532
|
899 py = y0;
|
Chris@532
|
900
|
Chris@534
|
901 if (i < symax) {
|
Chris@534
|
902 paint.drawLine(cw, y0, w, y0);
|
Chris@534
|
903 }
|
Chris@25
|
904
|
Chris@532
|
905 if (i > symin) {
|
Chris@534
|
906
|
Chris@805
|
907 int idx = i - 1;
|
Chris@534
|
908 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
|
Chris@534
|
909
|
Chris@534
|
910 QString text = m_model->getBinName(idx);
|
Chris@534
|
911 if (text == "") text = QString("[%1]").arg(idx + 1);
|
Chris@534
|
912
|
Chris@534
|
913 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
|
Chris@534
|
914 paint.fontMetrics().ascent() + 1;
|
Chris@534
|
915
|
Chris@534
|
916 paint.drawText(cw + 5, ty, text);
|
Chris@457
|
917 }
|
Chris@25
|
918 }
|
Chris@456
|
919
|
Chris@456
|
920 paint.restore();
|
Chris@25
|
921 }
|
Chris@25
|
922
|
Chris@467
|
923 DenseThreeDimensionalModel::Column
|
Chris@805
|
924 Colour3DPlotLayer::getColumn(int col) const
|
Chris@197
|
925 {
|
Chris@812
|
926 Profiler profiler("Colour3DPlotLayer::getColumn");
|
Chris@812
|
927
|
Chris@467
|
928 DenseThreeDimensionalModel::Column values = m_model->getColumn(col);
|
Chris@1019
|
929 values.resize(m_model->getHeight(), 0.f);
|
Chris@1099
|
930 if (m_normalization != ColumnOp::NormalizeColumns &&
|
Chris@1099
|
931 m_normalization != ColumnOp::NormalizeHybrid) {
|
Chris@1099
|
932 return values;
|
Chris@1099
|
933 }
|
Chris@461
|
934
|
Chris@904
|
935 double colMax = 0.f, colMin = 0.f;
|
Chris@904
|
936 double min = 0.f, max = 0.f;
|
Chris@197
|
937
|
Chris@1019
|
938 int nv = int(values.size());
|
Chris@1019
|
939
|
Chris@461
|
940 min = m_model->getMinimumLevel();
|
Chris@461
|
941 max = m_model->getMaximumLevel();
|
Chris@461
|
942
|
Chris@1019
|
943 for (int y = 0; y < nv; ++y) {
|
Chris@467
|
944 if (y == 0 || values.at(y) > colMax) colMax = values.at(y);
|
Chris@467
|
945 if (y == 0 || values.at(y) < colMin) colMin = values.at(y);
|
Chris@197
|
946 }
|
Chris@461
|
947 if (colMin == colMax) colMax = colMin + 1;
|
Chris@197
|
948
|
Chris@1019
|
949 for (int y = 0; y < nv; ++y) {
|
Chris@461
|
950
|
Chris@904
|
951 double value = values.at(y);
|
Chris@904
|
952 double norm = (value - colMin) / (colMax - colMin);
|
Chris@904
|
953 double newvalue = min + (max - min) * norm;
|
Chris@197
|
954
|
Chris@904
|
955 if (value != newvalue) values[y] = float(newvalue);
|
Chris@468
|
956 }
|
Chris@468
|
957
|
Chris@1099
|
958 if (m_normalization == ColumnOp::NormalizeHybrid
|
Chris@1099
|
959 && (colMax > 0.0)) {
|
Chris@904
|
960 double logmax = log10(colMax);
|
Chris@1019
|
961 for (int y = 0; y < nv; ++y) {
|
Chris@904
|
962 values[y] = float(values[y] * logmax);
|
Chris@719
|
963 }
|
Chris@719
|
964 }
|
Chris@719
|
965
|
Chris@468
|
966 return values;
|
Chris@197
|
967 }
|
Chris@197
|
968
|
Chris@197
|
969 void
|
Chris@1046
|
970 Colour3DPlotLayer::fillCache(int firstColumn, int lastColumn) const
|
Chris@197
|
971 {
|
Chris@1046
|
972 // This call requests a (perhaps partial) fill of the cache
|
Chris@1046
|
973 // between model columns firstColumn and lastColumn inclusive.
|
Chris@1046
|
974 // The cache itself always has size sufficient to contain the
|
Chris@1046
|
975 // whole model, but its validity may be less, depending on which
|
Chris@1046
|
976 // regions have been requested via calls to this function. Note
|
Chris@1046
|
977 // that firstColumn and lastColumn are *model* column numbers. If
|
Chris@1046
|
978 // the model starts at a frame > 0, a firstColumn of zero still
|
Chris@1046
|
979 // corresponds to the first column in the model, not the first
|
Chris@1046
|
980 // column on the resulting rendered layer.
|
Chris@1046
|
981
|
Chris@812
|
982 Profiler profiler("Colour3DPlotLayer::fillCache", true);
|
Chris@476
|
983
|
Chris@1046
|
984 int cacheWidth = m_model->getWidth();
|
Chris@1046
|
985 int cacheHeight = m_model->getHeight();
|
Chris@461
|
986
|
Chris@812
|
987 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1046
|
988 cerr << "Colour3DPlotLayer::fillCache: range " << firstColumn << " -> " << lastColumn << " (cache size will be " << cacheWidth << " x " << cacheHeight << ")" << endl;
|
Chris@812
|
989 #endif
|
Chris@812
|
990
|
Chris@812
|
991 if (m_cache && m_cache->height() != cacheHeight) {
|
Chris@742
|
992 // height has changed: delete everything rather than resizing
|
Chris@812
|
993 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
994 cerr << "Colour3DPlotLayer::fillCache: Cache height has changed, recreating" << endl;
|
Chris@812
|
995 #endif
|
Chris@461
|
996 delete m_cache;
|
Chris@469
|
997 delete m_peaksCache;
|
Chris@461
|
998 m_cache = 0;
|
Chris@469
|
999 m_peaksCache = 0;
|
Chris@461
|
1000 }
|
Chris@461
|
1001
|
Chris@812
|
1002 if (m_cache && m_cache->width() != cacheWidth) {
|
Chris@742
|
1003 // width has changed and we have an existing cache: resize it
|
Chris@812
|
1004 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1005 cerr << "Colour3DPlotLayer::fillCache: Cache width has changed, resizing existing cache" << endl;
|
Chris@812
|
1006 #endif
|
Chris@469
|
1007 QImage *newCache =
|
Chris@469
|
1008 new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight));
|
Chris@461
|
1009 delete m_cache;
|
Chris@461
|
1010 m_cache = newCache;
|
Chris@469
|
1011 if (m_peaksCache) {
|
Chris@469
|
1012 QImage *newPeaksCache =
|
Chris@469
|
1013 new QImage(m_peaksCache->copy
|
Chris@742
|
1014 (0, 0, cacheWidth / m_peakResolution + 1, cacheHeight));
|
Chris@469
|
1015 delete m_peaksCache;
|
Chris@469
|
1016 m_peaksCache = newPeaksCache;
|
Chris@469
|
1017 }
|
Chris@197
|
1018 }
|
Chris@197
|
1019
|
Chris@461
|
1020 if (!m_cache) {
|
Chris@812
|
1021 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1022 cerr << "Colour3DPlotLayer::fillCache: Have no cache, making one" << endl;
|
Chris@812
|
1023 #endif
|
Chris@1046
|
1024 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
|
Chris@812
|
1025 m_cache->setColorCount(256);
|
Chris@514
|
1026 m_cache->fill(0);
|
Chris@1099
|
1027 if (m_normalization != ColumnOp::NormalizeVisibleArea) {
|
Chris@469
|
1028 m_peaksCache = new QImage
|
Chris@469
|
1029 (cacheWidth / m_peakResolution + 1, cacheHeight,
|
Chris@469
|
1030 QImage::Format_Indexed8);
|
Chris@812
|
1031 m_peaksCache->setColorCount(256);
|
Chris@514
|
1032 m_peaksCache->fill(0);
|
Chris@469
|
1033 } else if (m_peaksCache) {
|
Chris@469
|
1034 delete m_peaksCache;
|
Chris@469
|
1035 m_peaksCache = 0;
|
Chris@469
|
1036 }
|
Chris@461
|
1037 m_cacheValidStart = 0;
|
Chris@461
|
1038 m_cacheValidEnd = 0;
|
Chris@197
|
1039 }
|
Chris@197
|
1040
|
Chris@812
|
1041 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1042 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
|
Chris@812
|
1043 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
|
Chris@812
|
1044 #endif
|
Chris@742
|
1045
|
Chris@1046
|
1046 if (m_cacheValidStart <= firstColumn && m_cacheValidEnd >= lastColumn) {
|
Chris@519
|
1047 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@682
|
1048 cerr << "Cache is valid in this region already" << endl;
|
Chris@519
|
1049 #endif
|
Chris@461
|
1050 return;
|
Chris@461
|
1051 }
|
Chris@461
|
1052
|
Chris@1046
|
1053 int fillStart = firstColumn;
|
Chris@1046
|
1054 int fillEnd = lastColumn;
|
Chris@197
|
1055
|
Chris@1046
|
1056 if (fillStart >= cacheWidth) fillStart = cacheWidth-1;
|
Chris@1046
|
1057 if (fillStart < 0) fillStart = 0;
|
Chris@1046
|
1058 if (fillEnd >= cacheWidth) fillEnd = cacheWidth-1;
|
Chris@1046
|
1059 if (fillEnd < 0) fillEnd = 0;
|
Chris@1046
|
1060 if (fillEnd < fillStart) fillEnd = fillStart;
|
Chris@197
|
1061
|
Chris@1099
|
1062 bool normalizeVisible = (m_normalization == ColumnOp::NormalizeVisibleArea);
|
Chris@197
|
1063
|
Chris@461
|
1064 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) {
|
Chris@461
|
1065
|
Chris@461
|
1066 if (m_cacheValidEnd < fillStart) {
|
Chris@461
|
1067 fillStart = m_cacheValidEnd + 1;
|
Chris@461
|
1068 }
|
Chris@461
|
1069 if (m_cacheValidStart > fillEnd) {
|
Chris@461
|
1070 fillEnd = m_cacheValidStart - 1;
|
Chris@461
|
1071 }
|
Chris@461
|
1072
|
Chris@461
|
1073 m_cacheValidStart = std::min(fillStart, m_cacheValidStart);
|
Chris@461
|
1074 m_cacheValidEnd = std::max(fillEnd, m_cacheValidEnd);
|
Chris@461
|
1075
|
Chris@461
|
1076 } else {
|
Chris@461
|
1077
|
Chris@812
|
1078 // when normalising the visible area, the only valid area,
|
Chris@812
|
1079 // ever, is the currently visible one
|
Chris@461
|
1080
|
Chris@461
|
1081 m_cacheValidStart = fillStart;
|
Chris@461
|
1082 m_cacheValidEnd = fillEnd;
|
Chris@461
|
1083 }
|
Chris@461
|
1084
|
Chris@519
|
1085 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1086 cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " will be valid from " << m_cacheValidStart << " to " << m_cacheValidEnd << " (fillStart = " << fillStart << ", fillEnd = " << fillEnd << ")" << endl;
|
Chris@519
|
1087 #endif
|
Chris@461
|
1088
|
Chris@197
|
1089 DenseThreeDimensionalModel::Column values;
|
Chris@197
|
1090
|
Chris@904
|
1091 double min = m_model->getMinimumLevel();
|
Chris@904
|
1092 double max = m_model->getMaximumLevel();
|
Chris@197
|
1093
|
Chris@1099
|
1094 if (m_colourScale == ColourScale::LogColourScale) {
|
Chris@197
|
1095 LogRange::mapRange(min, max);
|
Chris@1099
|
1096 } else if (m_colourScale == ColourScale::PlusMinusOneScale) {
|
Chris@197
|
1097 min = -1.f;
|
Chris@197
|
1098 max = 1.f;
|
Chris@1099
|
1099 } else if (m_colourScale == ColourScale::AbsoluteScale) {
|
Chris@509
|
1100 if (min < 0) {
|
Chris@904
|
1101 if (fabs(min) > fabs(max)) max = fabs(min);
|
Chris@904
|
1102 else max = fabs(max);
|
Chris@509
|
1103 min = 0;
|
Chris@509
|
1104 } else {
|
Chris@904
|
1105 min = fabs(min);
|
Chris@904
|
1106 max = fabs(max);
|
Chris@509
|
1107 }
|
Chris@197
|
1108 }
|
Chris@197
|
1109
|
Chris@902
|
1110 if (max == min) max = min + 1.f;
|
Chris@197
|
1111
|
Chris@197
|
1112 ColourMapper mapper(m_colourMap, 0.f, 255.f);
|
Chris@197
|
1113
|
Chris@197
|
1114 for (int index = 0; index < 256; ++index) {
|
Chris@197
|
1115 QColor colour = mapper.map(index);
|
Chris@469
|
1116 m_cache->setColor
|
Chris@469
|
1117 (index, qRgb(colour.red(), colour.green(), colour.blue()));
|
Chris@469
|
1118 if (m_peaksCache) {
|
Chris@469
|
1119 m_peaksCache->setColor
|
Chris@469
|
1120 (index, qRgb(colour.red(), colour.green(), colour.blue()));
|
Chris@469
|
1121 }
|
Chris@197
|
1122 }
|
Chris@197
|
1123
|
Chris@904
|
1124 double visibleMax = 0.f, visibleMin = 0.f;
|
Chris@197
|
1125
|
Chris@461
|
1126 if (normalizeVisible) {
|
Chris@197
|
1127
|
Chris@805
|
1128 for (int c = fillStart; c <= fillEnd; ++c) {
|
Chris@197
|
1129
|
Chris@467
|
1130 values = getColumn(c);
|
Chris@197
|
1131
|
Chris@904
|
1132 double colMax = 0.f, colMin = 0.f;
|
Chris@197
|
1133
|
Chris@805
|
1134 for (int y = 0; y < cacheHeight; ++y) {
|
Chris@1019
|
1135 if (!in_range_for(values, y)) break;
|
Chris@197
|
1136 if (y == 0 || values[y] > colMax) colMax = values[y];
|
Chris@224
|
1137 if (y == 0 || values[y] < colMin) colMin = values[y];
|
Chris@197
|
1138 }
|
Chris@197
|
1139
|
Chris@461
|
1140 if (c == fillStart || colMax > visibleMax) visibleMax = colMax;
|
Chris@461
|
1141 if (c == fillStart || colMin < visibleMin) visibleMin = colMin;
|
Chris@461
|
1142 }
|
Chris@461
|
1143
|
Chris@1099
|
1144 if (m_colourScale == ColourScale::LogColourScale) {
|
Chris@461
|
1145 visibleMin = LogRange::map(visibleMin);
|
Chris@461
|
1146 visibleMax = LogRange::map(visibleMax);
|
Chris@461
|
1147 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax);
|
Chris@1099
|
1148 } else if (m_colourScale == ColourScale::AbsoluteScale) {
|
Chris@509
|
1149 if (visibleMin < 0) {
|
Chris@904
|
1150 if (fabs(visibleMin) > fabs(visibleMax)) visibleMax = fabs(visibleMin);
|
Chris@904
|
1151 else visibleMax = fabs(visibleMax);
|
Chris@509
|
1152 visibleMin = 0;
|
Chris@509
|
1153 } else {
|
Chris@904
|
1154 visibleMin = fabs(visibleMin);
|
Chris@904
|
1155 visibleMax = fabs(visibleMax);
|
Chris@509
|
1156 }
|
Chris@197
|
1157 }
|
Chris@197
|
1158 }
|
Chris@197
|
1159
|
Chris@224
|
1160 if (visibleMin == visibleMax) visibleMax = visibleMin + 1;
|
Chris@224
|
1161
|
Chris@469
|
1162 int *peaks = 0;
|
Chris@469
|
1163 if (m_peaksCache) {
|
Chris@469
|
1164 peaks = new int[cacheHeight];
|
Chris@469
|
1165 for (int y = 0; y < cacheHeight; ++y) {
|
Chris@469
|
1166 peaks[y] = 0;
|
Chris@469
|
1167 }
|
Chris@469
|
1168 }
|
Chris@469
|
1169
|
Chris@812
|
1170 Profiler profiler2("Colour3DPlotLayer::fillCache: filling", true);
|
Chris@812
|
1171
|
Chris@805
|
1172 for (int c = fillStart; c <= fillEnd; ++c) {
|
Chris@197
|
1173
|
Chris@467
|
1174 values = getColumn(c);
|
Chris@197
|
1175
|
Chris@742
|
1176 if (c >= m_cache->width()) {
|
Chris@742
|
1177 cerr << "ERROR: column " << c << " >= cache width "
|
Chris@742
|
1178 << m_cache->width() << endl;
|
Chris@742
|
1179 continue;
|
Chris@742
|
1180 }
|
Chris@742
|
1181
|
Chris@805
|
1182 for (int y = 0; y < cacheHeight; ++y) {
|
Chris@197
|
1183
|
Chris@904
|
1184 double value = min;
|
Chris@1019
|
1185 if (in_range_for(values, y)) {
|
Chris@469
|
1186 value = values.at(y);
|
Chris@197
|
1187 }
|
Chris@224
|
1188
|
Chris@534
|
1189 value = value * m_gain;
|
Chris@534
|
1190
|
Chris@1099
|
1191 if (m_colourScale == ColourScale::LogColourScale) {
|
Chris@224
|
1192 value = LogRange::map(value);
|
Chris@1099
|
1193 } else if (m_colourScale == ColourScale::AbsoluteScale) {
|
Chris@904
|
1194 value = fabs(value);
|
Chris@197
|
1195 }
|
Chris@461
|
1196
|
Chris@461
|
1197 if (normalizeVisible) {
|
Chris@904
|
1198 double norm = (value - visibleMin) / (visibleMax - visibleMin);
|
Chris@461
|
1199 value = min + (max - min) * norm;
|
Chris@461
|
1200 }
|
Chris@197
|
1201
|
Chris@197
|
1202 int pixel = int(((value - min) * 256) / (max - min));
|
Chris@197
|
1203 if (pixel < 0) pixel = 0;
|
Chris@197
|
1204 if (pixel > 255) pixel = 255;
|
Chris@469
|
1205 if (peaks && (pixel > peaks[y])) peaks[y] = pixel;
|
Chris@197
|
1206
|
Chris@357
|
1207 if (m_invertVertical) {
|
Chris@461
|
1208 m_cache->setPixel(c, cacheHeight - y - 1, pixel);
|
Chris@357
|
1209 } else {
|
Chris@742
|
1210 if (y >= m_cache->height()) {
|
Chris@742
|
1211 cerr << "ERROR: row " << y << " >= cache height " << m_cache->height() << endl;
|
Chris@742
|
1212 } else {
|
Chris@742
|
1213 m_cache->setPixel(c, y, pixel);
|
Chris@742
|
1214 }
|
Chris@357
|
1215 }
|
Chris@197
|
1216 }
|
Chris@469
|
1217
|
Chris@469
|
1218 if (peaks) {
|
Chris@805
|
1219 int notch = (c % m_peakResolution);
|
Chris@469
|
1220 if (notch == m_peakResolution-1 || c == fillEnd) {
|
Chris@805
|
1221 int pc = c / m_peakResolution;
|
Chris@742
|
1222 if (pc >= m_peaksCache->width()) {
|
Chris@742
|
1223 cerr << "ERROR: peak column " << pc
|
Chris@742
|
1224 << " (from col " << c << ") >= peaks cache width "
|
Chris@742
|
1225 << m_peaksCache->width() << endl;
|
Chris@742
|
1226 continue;
|
Chris@742
|
1227 }
|
Chris@805
|
1228 for (int y = 0; y < cacheHeight; ++y) {
|
Chris@469
|
1229 if (m_invertVertical) {
|
Chris@469
|
1230 m_peaksCache->setPixel(pc, cacheHeight - y - 1, peaks[y]);
|
Chris@469
|
1231 } else {
|
Chris@742
|
1232 if (y >= m_peaksCache->height()) {
|
Chris@742
|
1233 cerr << "ERROR: row " << y
|
Chris@742
|
1234 << " >= peaks cache height "
|
Chris@742
|
1235 << m_peaksCache->height() << endl;
|
Chris@742
|
1236 } else {
|
Chris@742
|
1237 m_peaksCache->setPixel(pc, y, peaks[y]);
|
Chris@742
|
1238 }
|
Chris@469
|
1239 }
|
Chris@469
|
1240 }
|
Chris@469
|
1241 for (int y = 0; y < cacheHeight; ++y) {
|
Chris@469
|
1242 peaks[y] = 0;
|
Chris@469
|
1243 }
|
Chris@469
|
1244 }
|
Chris@469
|
1245 }
|
Chris@197
|
1246 }
|
Chris@469
|
1247
|
Chris@469
|
1248 delete[] peaks;
|
Chris@197
|
1249 }
|
Chris@197
|
1250
|
Chris@812
|
1251 bool
|
Chris@916
|
1252 Colour3DPlotLayer::shouldPaintDenseIn(const LayerGeometryProvider *v) const
|
Chris@812
|
1253 {
|
Chris@812
|
1254 if (!m_model || !v || !(v->getViewManager())) {
|
Chris@812
|
1255 return false;
|
Chris@812
|
1256 }
|
Chris@902
|
1257 double srRatio =
|
Chris@902
|
1258 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
|
Chris@812
|
1259 if (m_opaque ||
|
Chris@812
|
1260 m_smooth ||
|
Chris@916
|
1261 m_model->getHeight() >= v->getPaintHeight() ||
|
Chris@812
|
1262 ((m_model->getResolution() * srRatio) / v->getZoomLevel()) < 2) {
|
Chris@812
|
1263 return true;
|
Chris@812
|
1264 }
|
Chris@812
|
1265 return false;
|
Chris@812
|
1266 }
|
Chris@812
|
1267
|
Chris@197
|
1268 void
|
Chris@916
|
1269 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@0
|
1270 {
|
Chris@514
|
1271 /*
|
Chris@443
|
1272 if (m_model) {
|
Chris@587
|
1273 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << endl;
|
Chris@443
|
1274 }
|
Chris@514
|
1275 */
|
Chris@466
|
1276 Profiler profiler("Colour3DPlotLayer::paint");
|
Chris@125
|
1277 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1278 cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << ", rect is (" << rect.x() << "," << rect.y() << ") " << rect.width() << "x" << rect.height() << endl;
|
Chris@125
|
1279 #endif
|
Chris@0
|
1280
|
Chris@0
|
1281 int completion = 0;
|
Chris@0
|
1282 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
|
Chris@0
|
1283 if (completion > 0) {
|
Chris@916
|
1284 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
|
Chris@0
|
1285 10, QColor(120, 120, 120));
|
Chris@0
|
1286 }
|
Chris@0
|
1287 return;
|
Chris@0
|
1288 }
|
Chris@0
|
1289
|
Chris@1053
|
1290 if (m_model->getWidth() == 0) {
|
Chris@1053
|
1291 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1053
|
1292 cerr << "Colour3DPlotLayer::paint(): model width == 0, "
|
Chris@1053
|
1293 << "nothing to paint (yet)" << endl;
|
Chris@1053
|
1294 #endif
|
Chris@1053
|
1295 return;
|
Chris@1053
|
1296 }
|
Chris@1053
|
1297
|
Chris@1099
|
1298 if (m_normalization == ColumnOp::NormalizeVisibleArea) {
|
Chris@1099
|
1299 rect = v->getPaintRect();
|
Chris@1099
|
1300 }
|
Chris@197
|
1301
|
Chris@902
|
1302 sv_frame_t modelStart = m_model->getStartFrame();
|
Chris@902
|
1303 sv_frame_t modelEnd = m_model->getEndFrame();
|
Chris@805
|
1304 int modelResolution = m_model->getResolution();
|
Chris@0
|
1305
|
Chris@197
|
1306 // The cache is from the model's start frame to the model's end
|
Chris@197
|
1307 // frame at the model's window increment frames per pixel. We
|
Chris@197
|
1308 // want to draw from our start frame + x0 * zoomLevel to our start
|
Chris@197
|
1309 // frame + x1 * zoomLevel at zoomLevel frames per pixel.
|
Chris@12
|
1310
|
Chris@197
|
1311 // We have quite different paint mechanisms for rendering "large"
|
Chris@197
|
1312 // bins (more than one bin per pixel in both directions) and
|
Chris@197
|
1313 // "small". This is "large"; see paintDense below for "small".
|
Chris@12
|
1314
|
Chris@197
|
1315 int x0 = rect.left();
|
Chris@197
|
1316 int x1 = rect.right() + 1;
|
Chris@12
|
1317
|
Chris@916
|
1318 int h = v->getPaintHeight();
|
Chris@0
|
1319
|
Chris@902
|
1320 double srRatio =
|
Chris@902
|
1321 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
|
Chris@0
|
1322
|
Chris@1047
|
1323 // the s-prefix values are source, i.e. model, column and bin numbers
|
Chris@902
|
1324 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart))
|
Chris@812
|
1325 / modelResolution);
|
Chris@902
|
1326 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart))
|
Chris@812
|
1327 / modelResolution);
|
Chris@197
|
1328 int sh = m_model->getHeight();
|
Chris@159
|
1329
|
Chris@444
|
1330 int symin = m_miny;
|
Chris@444
|
1331 int symax = m_maxy;
|
Chris@444
|
1332 if (symax <= symin) {
|
Chris@444
|
1333 symin = 0;
|
Chris@444
|
1334 symax = sh;
|
Chris@444
|
1335 }
|
Chris@444
|
1336 if (symin < 0) symin = 0;
|
Chris@444
|
1337 if (symax > sh) symax = sh;
|
Chris@444
|
1338
|
Chris@197
|
1339 if (sx0 > 0) --sx0;
|
Chris@197
|
1340 fillCache(sx0 < 0 ? 0 : sx0,
|
Chris@197
|
1341 sx1 < 0 ? 0 : sx1);
|
Chris@0
|
1342
|
Chris@351
|
1343 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1344 cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << " (zoom level = " << v->getZoomLevel() << ", srRatio = " << srRatio << ")" << endl;
|
Chris@351
|
1345 #endif
|
Chris@351
|
1346
|
Chris@812
|
1347 if (shouldPaintDenseIn(v)) {
|
Chris@347
|
1348 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1349 cerr << "calling paintDense" << endl;
|
Chris@347
|
1350 #endif
|
Chris@98
|
1351 paintDense(v, paint, rect);
|
Chris@98
|
1352 return;
|
Chris@98
|
1353 }
|
Chris@98
|
1354
|
Chris@125
|
1355 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1356 cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << endl;
|
Chris@682
|
1357 cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << endl;
|
Chris@125
|
1358 #endif
|
Chris@0
|
1359
|
Chris@25
|
1360 QPoint illuminatePos;
|
Chris@44
|
1361 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
|
Chris@864
|
1362
|
Chris@864
|
1363 const int buflen = 40;
|
Chris@864
|
1364 char labelbuf[buflen];
|
Chris@25
|
1365
|
Chris@197
|
1366 for (int sx = sx0; sx <= sx1; ++sx) {
|
Chris@0
|
1367
|
Chris@1047
|
1368 sv_frame_t fx = sx * modelResolution + modelStart;
|
Chris@0
|
1369
|
Chris@812
|
1370 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
|
Chris@0
|
1371
|
Chris@1047
|
1372 int rx0 = v->getXForFrame(int(double(fx) * srRatio));
|
Chris@1047
|
1373 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * srRatio));
|
Chris@54
|
1374
|
Chris@159
|
1375 int rw = rx1 - rx0;
|
Chris@159
|
1376 if (rw < 1) rw = 1;
|
Chris@54
|
1377
|
Chris@159
|
1378 bool showLabel = (rw > 10 &&
|
Chris@159
|
1379 paint.fontMetrics().width("0.000000") < rw - 3 &&
|
Chris@54
|
1380 paint.fontMetrics().height() < (h / sh));
|
Chris@98
|
1381
|
Chris@444
|
1382 for (int sy = symin; sy < symax; ++sy) {
|
Chris@0
|
1383
|
Chris@903
|
1384 int ry0 = getIYForBin(v, sy);
|
Chris@903
|
1385 int ry1 = getIYForBin(v, sy + 1);
|
Chris@534
|
1386 QRect r(rx0, ry1, rw, ry0 - ry1);
|
Chris@534
|
1387
|
Chris@0
|
1388 QRgb pixel = qRgb(255, 255, 255);
|
Chris@461
|
1389 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@0
|
1390 sy >= 0 && sy < m_cache->height()) {
|
Chris@461
|
1391 pixel = m_cache->pixel(sx, sy);
|
Chris@0
|
1392 }
|
Chris@0
|
1393
|
Chris@159
|
1394 if (rw == 1) {
|
Chris@159
|
1395 paint.setPen(pixel);
|
Chris@159
|
1396 paint.setBrush(Qt::NoBrush);
|
Chris@159
|
1397 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
|
Chris@159
|
1398 continue;
|
Chris@159
|
1399 }
|
Chris@159
|
1400
|
Chris@0
|
1401 QColor pen(255, 255, 255, 80);
|
Chris@0
|
1402 QColor brush(pixel);
|
Chris@159
|
1403
|
Chris@159
|
1404 if (rw > 3 && r.height() > 3) {
|
Chris@159
|
1405 brush.setAlpha(160);
|
Chris@159
|
1406 }
|
Chris@159
|
1407
|
Chris@0
|
1408 paint.setPen(Qt::NoPen);
|
Chris@0
|
1409 paint.setBrush(brush);
|
Chris@0
|
1410
|
Chris@25
|
1411 if (illuminate) {
|
Chris@25
|
1412 if (r.contains(illuminatePos)) {
|
Chris@287
|
1413 paint.setPen(v->getForeground());
|
Chris@25
|
1414 }
|
Chris@25
|
1415 }
|
Chris@76
|
1416
|
Chris@125
|
1417 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@682
|
1418 // cerr << "rect " << r.x() << "," << r.y() << " "
|
Chris@682
|
1419 // << r.width() << "x" << r.height() << endl;
|
Chris@125
|
1420 #endif
|
Chris@25
|
1421
|
Chris@25
|
1422 paint.drawRect(r);
|
Chris@0
|
1423
|
Chris@54
|
1424 if (showLabel) {
|
Chris@461
|
1425 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@54
|
1426 sy >= 0 && sy < m_cache->height()) {
|
Chris@904
|
1427 double value = m_model->getValueAt(sx, sy);
|
Chris@864
|
1428 snprintf(labelbuf, buflen, "%06f", value);
|
Chris@54
|
1429 QString text(labelbuf);
|
Chris@1078
|
1430 PaintAssistant::drawVisibleText
|
Chris@1078
|
1431 (v,
|
Chris@1078
|
1432 paint,
|
Chris@1048
|
1433 rx0 + 2,
|
Chris@1048
|
1434 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
|
Chris@1048
|
1435 text,
|
Chris@1078
|
1436 PaintAssistant::OutlinedText);
|
Chris@0
|
1437 }
|
Chris@0
|
1438 }
|
Chris@0
|
1439 }
|
Chris@0
|
1440 }
|
Chris@98
|
1441 }
|
Chris@0
|
1442
|
Chris@98
|
1443 void
|
Chris@916
|
1444 Colour3DPlotLayer::paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@98
|
1445 {
|
Chris@812
|
1446 Profiler profiler("Colour3DPlotLayer::paintDense", true);
|
Chris@463
|
1447 if (!m_cache) return;
|
Chris@463
|
1448
|
Chris@903
|
1449 double modelStart = double(m_model->getStartFrame());
|
Chris@903
|
1450 double modelResolution = double(m_model->getResolution());
|
Chris@0
|
1451
|
Chris@903
|
1452 sv_samplerate_t mmsr = v->getViewManager()->getMainModelSampleRate();
|
Chris@903
|
1453 sv_samplerate_t msr = m_model->getSampleRate();
|
Chris@903
|
1454 double srRatio = mmsr / msr;
|
Chris@159
|
1455
|
Chris@98
|
1456 int x0 = rect.left();
|
Chris@98
|
1457 int x1 = rect.right() + 1;
|
Chris@0
|
1458
|
Chris@470
|
1459 const int w = x1 - x0; // const so it can be used as array size below
|
Chris@916
|
1460 int h = v->getPaintHeight(); // we always paint full height
|
Chris@160
|
1461 int sh = m_model->getHeight();
|
Chris@98
|
1462
|
Chris@444
|
1463 int symin = m_miny;
|
Chris@444
|
1464 int symax = m_maxy;
|
Chris@444
|
1465 if (symax <= symin) {
|
Chris@444
|
1466 symin = 0;
|
Chris@444
|
1467 symax = sh;
|
Chris@444
|
1468 }
|
Chris@444
|
1469 if (symin < 0) symin = 0;
|
Chris@444
|
1470 if (symax > sh) symax = sh;
|
Chris@444
|
1471
|
Chris@466
|
1472 QImage img(w, h, QImage::Format_Indexed8);
|
Chris@466
|
1473 img.setColorTable(m_cache->colorTable());
|
Chris@98
|
1474
|
Chris@466
|
1475 uchar *peaks = new uchar[w];
|
Chris@466
|
1476 memset(peaks, 0, w);
|
Chris@98
|
1477
|
Chris@469
|
1478 int zoomLevel = v->getZoomLevel();
|
Chris@469
|
1479
|
Chris@469
|
1480 QImage *source = m_cache;
|
Chris@812
|
1481
|
Chris@812
|
1482 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1483 cerr << "modelResolution " << modelResolution << ", srRatio "
|
Chris@812
|
1484 << srRatio << ", m_peakResolution " << m_peakResolution
|
Chris@812
|
1485 << ", zoomLevel " << zoomLevel << ", result "
|
Chris@812
|
1486 << ((modelResolution * srRatio * m_peakResolution) / zoomLevel)
|
Chris@812
|
1487 << endl;
|
Chris@812
|
1488 #endif
|
Chris@474
|
1489
|
Chris@474
|
1490 if (m_peaksCache) {
|
Chris@474
|
1491 if (((modelResolution * srRatio * m_peakResolution) / zoomLevel) < 1) {
|
Chris@812
|
1492 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1493 cerr << "using peaks cache" << endl;
|
Chris@812
|
1494 #endif
|
Chris@474
|
1495 source = m_peaksCache;
|
Chris@474
|
1496 modelResolution *= m_peakResolution;
|
Chris@474
|
1497 } else {
|
Chris@812
|
1498 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1499 cerr << "not using peaks cache" << endl;
|
Chris@812
|
1500 #endif
|
Chris@474
|
1501 }
|
Chris@469
|
1502 } else {
|
Chris@812
|
1503 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1504 cerr << "have no peaks cache" << endl;
|
Chris@812
|
1505 #endif
|
Chris@469
|
1506 }
|
Chris@469
|
1507
|
Chris@469
|
1508 int sw = source->width();
|
Chris@470
|
1509
|
Chris@903
|
1510 sv_frame_t xf = -1;
|
Chris@903
|
1511 sv_frame_t nxf = v->getFrameForX(x0);
|
Chris@470
|
1512
|
Chris@903
|
1513 double epsilon = 0.000001;
|
Chris@535
|
1514
|
Chris@903
|
1515 vector<double> sxa(w*2);
|
Chris@903
|
1516
|
Chris@470
|
1517 for (int x = 0; x < w; ++x) {
|
Chris@470
|
1518
|
Chris@470
|
1519 xf = nxf;
|
Chris@470
|
1520 nxf = xf + zoomLevel;
|
Chris@470
|
1521
|
Chris@903
|
1522 double sx0 = (double(xf) / srRatio - modelStart) / modelResolution;
|
Chris@903
|
1523 double sx1 = (double(nxf) / srRatio - modelStart) / modelResolution;
|
Chris@470
|
1524
|
Chris@535
|
1525 sxa[x*2] = sx0;
|
Chris@535
|
1526 sxa[x*2 + 1] = sx1;
|
Chris@470
|
1527 }
|
Chris@466
|
1528
|
Chris@904
|
1529 double logmin = symin+1, logmax = symax+1;
|
Chris@532
|
1530 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
1531
|
Chris@812
|
1532 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1533 cerr << "m_smooth = " << m_smooth << ", w = " << w << ", h = " << h << endl;
|
Chris@812
|
1534 #endif
|
Chris@812
|
1535
|
Chris@535
|
1536 if (m_smooth) {
|
Chris@535
|
1537
|
Chris@535
|
1538 for (int y = 0; y < h; ++y) {
|
Chris@466
|
1539
|
Chris@904
|
1540 double sy = getBinForY(v, y) - 0.5;
|
Chris@535
|
1541 int syi = int(sy + epsilon);
|
Chris@535
|
1542 if (syi < 0 || syi >= source->height()) continue;
|
Chris@531
|
1543
|
Chris@535
|
1544 uchar *targetLine = img.scanLine(y);
|
Chris@535
|
1545 uchar *sourceLine = source->scanLine(syi);
|
Chris@535
|
1546 uchar *nextSource;
|
Chris@535
|
1547 if (syi + 1 < source->height()) {
|
Chris@535
|
1548 nextSource = source->scanLine(syi + 1);
|
Chris@535
|
1549 } else {
|
Chris@535
|
1550 nextSource = sourceLine;
|
Chris@535
|
1551 }
|
Chris@466
|
1552
|
Chris@466
|
1553 for (int x = 0; x < w; ++x) {
|
Chris@98
|
1554
|
Chris@535
|
1555 targetLine[x] = 0;
|
Chris@474
|
1556
|
Chris@903
|
1557 double sx0 = sxa[x*2];
|
Chris@537
|
1558 if (sx0 < 0) continue;
|
Chris@535
|
1559 int sx0i = int(sx0 + epsilon);
|
Chris@474
|
1560 if (sx0i >= sw) break;
|
Chris@98
|
1561
|
Chris@903
|
1562 double a = sourceLine[sx0i];
|
Chris@903
|
1563 double b = a;
|
Chris@903
|
1564 double value;
|
Chris@535
|
1565
|
Chris@903
|
1566 double sx1 = sxa[x*2+1];
|
Chris@535
|
1567 if (sx1 > sx0 + 1.f) {
|
Chris@535
|
1568 int sx1i = int(sx1);
|
Chris@535
|
1569 bool have = false;
|
Chris@535
|
1570 for (int sx = sx0i; sx <= sx1i; ++sx) {
|
Chris@535
|
1571 if (sx < 0 || sx >= sw) continue;
|
Chris@535
|
1572 if (!have) {
|
Chris@903
|
1573 a = sourceLine[sx];
|
Chris@903
|
1574 b = nextSource[sx];
|
Chris@535
|
1575 have = true;
|
Chris@535
|
1576 } else {
|
Chris@903
|
1577 a = std::max(a, double(sourceLine[sx]));
|
Chris@903
|
1578 b = std::max(b, double(nextSource[sx]));
|
Chris@535
|
1579 }
|
Chris@535
|
1580 }
|
Chris@903
|
1581 double yprop = sy - syi;
|
Chris@535
|
1582 value = (a * (1.f - yprop) + b * yprop);
|
Chris@535
|
1583 } else {
|
Chris@903
|
1584 a = sourceLine[sx0i];
|
Chris@903
|
1585 b = nextSource[sx0i];
|
Chris@903
|
1586 double yprop = sy - syi;
|
Chris@535
|
1587 value = (a * (1.f - yprop) + b * yprop);
|
Chris@535
|
1588 int oi = sx0i + 1;
|
Chris@903
|
1589 double xprop = sx0 - sx0i;
|
Chris@535
|
1590 xprop -= 0.5;
|
Chris@535
|
1591 if (xprop < 0) {
|
Chris@535
|
1592 oi = sx0i - 1;
|
Chris@535
|
1593 xprop = -xprop;
|
Chris@535
|
1594 }
|
Chris@535
|
1595 if (oi < 0 || oi >= sw) oi = sx0i;
|
Chris@903
|
1596 a = sourceLine[oi];
|
Chris@903
|
1597 b = nextSource[oi];
|
Chris@535
|
1598 value = (value * (1.f - xprop) +
|
Chris@535
|
1599 (a * (1.f - yprop) + b * yprop) * xprop);
|
Chris@98
|
1600 }
|
Chris@535
|
1601
|
Chris@903
|
1602 int vi = int(lrint(value));
|
Chris@535
|
1603 if (vi > 255) vi = 255;
|
Chris@535
|
1604 if (vi < 0) vi = 0;
|
Chris@535
|
1605 targetLine[x] = uchar(vi);
|
Chris@98
|
1606 }
|
Chris@466
|
1607 }
|
Chris@535
|
1608 } else {
|
Chris@535
|
1609
|
Chris@904
|
1610 double sy0 = getBinForY(v, 0);
|
Chris@812
|
1611
|
Chris@812
|
1612 int psy0i = -1, psy1i = -1;
|
Chris@812
|
1613
|
Chris@535
|
1614 for (int y = 0; y < h; ++y) {
|
Chris@535
|
1615
|
Chris@904
|
1616 double sy1 = sy0;
|
Chris@904
|
1617 sy0 = getBinForY(v, double(y + 1));
|
Chris@535
|
1618
|
Chris@535
|
1619 int sy0i = int(sy0 + epsilon);
|
Chris@535
|
1620 int sy1i = int(sy1);
|
Chris@535
|
1621
|
Chris@535
|
1622 uchar *targetLine = img.scanLine(y);
|
Chris@535
|
1623
|
Chris@812
|
1624 if (sy0i == psy0i && sy1i == psy1i) {
|
Chris@812
|
1625 // same source scan line as just computed
|
Chris@535
|
1626 goto copy;
|
Chris@535
|
1627 }
|
Chris@535
|
1628
|
Chris@812
|
1629 psy0i = sy0i;
|
Chris@812
|
1630 psy1i = sy1i;
|
Chris@812
|
1631
|
Chris@535
|
1632 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1633 peaks[x] = 0;
|
Chris@535
|
1634 }
|
Chris@466
|
1635
|
Chris@535
|
1636 for (int sy = sy0i; sy <= sy1i; ++sy) {
|
Chris@535
|
1637
|
Chris@535
|
1638 if (sy < 0 || sy >= source->height()) continue;
|
Chris@535
|
1639
|
Chris@535
|
1640 uchar *sourceLine = source->scanLine(sy);
|
Chris@535
|
1641
|
Chris@535
|
1642 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1643
|
Chris@903
|
1644 double sx1 = sxa[x*2 + 1];
|
Chris@537
|
1645 if (sx1 < 0) continue;
|
Chris@537
|
1646 int sx1i = int(sx1);
|
Chris@535
|
1647
|
Chris@903
|
1648 double sx0 = sxa[x*2];
|
Chris@537
|
1649 if (sx0 < 0) continue;
|
Chris@537
|
1650 int sx0i = int(sx0 + epsilon);
|
Chris@535
|
1651 if (sx0i >= sw) break;
|
Chris@535
|
1652
|
Chris@535
|
1653 uchar peak = 0;
|
Chris@535
|
1654 for (int sx = sx0i; sx <= sx1i; ++sx) {
|
Chris@535
|
1655 if (sx < 0 || sx >= sw) continue;
|
Chris@535
|
1656 if (sourceLine[sx] > peak) peak = sourceLine[sx];
|
Chris@535
|
1657 }
|
Chris@535
|
1658 peaks[x] = peak;
|
Chris@535
|
1659 }
|
Chris@535
|
1660 }
|
Chris@535
|
1661
|
Chris@535
|
1662 copy:
|
Chris@535
|
1663 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1664 targetLine[x] = peaks[x];
|
Chris@535
|
1665 }
|
Chris@98
|
1666 }
|
Chris@0
|
1667 }
|
Chris@0
|
1668
|
Chris@469
|
1669 delete[] peaks;
|
Chris@469
|
1670
|
Chris@98
|
1671 paint.drawImage(x0, 0, img);
|
Chris@0
|
1672 }
|
Chris@0
|
1673
|
Chris@28
|
1674 bool
|
Chris@916
|
1675 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
|
Chris@805
|
1676 int &resolution,
|
Chris@28
|
1677 SnapType snap) const
|
Chris@24
|
1678 {
|
Chris@24
|
1679 if (!m_model) {
|
Chris@44
|
1680 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@24
|
1681 }
|
Chris@24
|
1682
|
Chris@130
|
1683 resolution = m_model->getResolution();
|
Chris@904
|
1684 sv_frame_t left = (frame / resolution) * resolution;
|
Chris@904
|
1685 sv_frame_t right = left + resolution;
|
Chris@28
|
1686
|
Chris@28
|
1687 switch (snap) {
|
Chris@28
|
1688 case SnapLeft: frame = left; break;
|
Chris@28
|
1689 case SnapRight: frame = right; break;
|
Chris@28
|
1690 case SnapNearest:
|
Chris@28
|
1691 case SnapNeighbouring:
|
Chris@28
|
1692 if (frame - left > right - frame) frame = right;
|
Chris@28
|
1693 else frame = left;
|
Chris@28
|
1694 break;
|
Chris@28
|
1695 }
|
Chris@24
|
1696
|
Chris@28
|
1697 return true;
|
Chris@24
|
1698 }
|
Chris@24
|
1699
|
Chris@1099
|
1700 static ColourScale::Scale
|
Chris@1099
|
1701 convertInColourScale(int fileScale)
|
Chris@1099
|
1702 {
|
Chris@1099
|
1703 //!!! this is very badly handled, switching the enum directly for
|
Chris@1099
|
1704 //!!! the ColourScale one did not work out well!
|
Chris@1099
|
1705
|
Chris@1099
|
1706 switch (fileScale) {
|
Chris@1099
|
1707 default:
|
Chris@1099
|
1708 case 0: return ColourScale::LinearColourScale;
|
Chris@1099
|
1709 case 1: return ColourScale::LogColourScale;
|
Chris@1099
|
1710 case 2: return ColourScale::PlusMinusOneScale;
|
Chris@1099
|
1711 case 3: return ColourScale::AbsoluteScale;
|
Chris@1099
|
1712 }
|
Chris@1099
|
1713 }
|
Chris@1099
|
1714
|
Chris@1099
|
1715 static int
|
Chris@1099
|
1716 convertOutColourScale(ColourScale::Scale scale)
|
Chris@1099
|
1717 {
|
Chris@1099
|
1718 switch (scale) {
|
Chris@1099
|
1719 case ColourScale::LinearColourScale: return 0;
|
Chris@1099
|
1720 case ColourScale::LogColourScale: return 1;
|
Chris@1099
|
1721 case ColourScale::PlusMinusOneScale: return 2;
|
Chris@1099
|
1722 case ColourScale::AbsoluteScale: return 3;
|
Chris@1099
|
1723
|
Chris@1099
|
1724 case ColourScale::MeterColourScale:
|
Chris@1099
|
1725 case ColourScale::PhaseColourScale:
|
Chris@1099
|
1726 default: return 0;
|
Chris@1099
|
1727 }
|
Chris@1099
|
1728 }
|
Chris@1099
|
1729
|
Chris@316
|
1730 void
|
Chris@316
|
1731 Colour3DPlotLayer::toXml(QTextStream &stream,
|
Chris@316
|
1732 QString indent, QString extraAttributes) const
|
Chris@197
|
1733 {
|
Chris@316
|
1734 QString s = QString("scale=\"%1\" "
|
Chris@316
|
1735 "colourScheme=\"%2\" "
|
Chris@1099
|
1736 "minY=\"%3\" "
|
Chris@1099
|
1737 "maxY=\"%4\" "
|
Chris@1099
|
1738 "invertVertical=\"%5\" "
|
Chris@1099
|
1739 "opaque=\"%6\" %7")
|
Chris@1099
|
1740 .arg(convertOutColourScale(m_colourScale))
|
Chris@197
|
1741 .arg(m_colourMap)
|
Chris@445
|
1742 .arg(m_miny)
|
Chris@465
|
1743 .arg(m_maxy)
|
Chris@465
|
1744 .arg(m_invertVertical ? "true" : "false")
|
Chris@534
|
1745 .arg(m_opaque ? "true" : "false")
|
Chris@536
|
1746 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
|
Chris@535
|
1747 .arg((int)m_binScale)
|
Chris@536
|
1748 .arg(m_smooth ? "true" : "false")
|
Chris@536
|
1749 .arg(m_gain));
|
Chris@535
|
1750
|
Chris@1099
|
1751 // New-style normalization attributes, allowing for more types of
|
Chris@1099
|
1752 // normalization in future: write out the column normalization
|
Chris@1099
|
1753 // type separately, and then whether we are normalizing visible
|
Chris@1099
|
1754 // area as well afterwards
|
Chris@1099
|
1755
|
Chris@1099
|
1756 s += QString("columnNormalization=\"%1\" ")
|
Chris@1099
|
1757 .arg(m_normalization == ColumnOp::NormalizeColumns ? "peak" :
|
Chris@1099
|
1758 m_normalization == ColumnOp::NormalizeHybrid ? "hybrid" : "none");
|
Chris@1099
|
1759
|
Chris@1099
|
1760 // Old-style normalization attribute, for backward compatibility
|
Chris@1099
|
1761
|
Chris@1099
|
1762 s += QString("normalizeColumns=\"%1\" ")
|
Chris@1099
|
1763 .arg(m_normalization == ColumnOp::NormalizeColumns ? "true" : "false");
|
Chris@1099
|
1764
|
Chris@1099
|
1765 // And this applies to both old- and new-style attributes
|
Chris@1099
|
1766
|
Chris@1099
|
1767 s += QString("normalizeVisibleArea=\"%1\" ")
|
Chris@1099
|
1768 .arg(m_normalization == ColumnOp::NormalizeVisibleArea ? "true" : "false");
|
Chris@1099
|
1769
|
Chris@316
|
1770 Layer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@197
|
1771 }
|
Chris@197
|
1772
|
Chris@197
|
1773 void
|
Chris@197
|
1774 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@197
|
1775 {
|
Chris@445
|
1776 bool ok = false, alsoOk = false;
|
Chris@197
|
1777
|
Chris@1099
|
1778 ColourScale::Scale colourScale = convertInColourScale
|
Chris@1099
|
1779 (attributes.value("colourScale").toInt(&ok));
|
Chris@1099
|
1780 if (ok) setColourScale(colourScale);
|
Chris@197
|
1781
|
Chris@197
|
1782 int colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@197
|
1783 if (ok) setColourMap(colourMap);
|
Chris@197
|
1784
|
Chris@1099
|
1785 Colour3DPlotRenderer::BinScale binScale = (Colour3DPlotRenderer::BinScale)
|
Chris@1099
|
1786 attributes.value("binScale").toInt(&ok);
|
Chris@1099
|
1787 if (ok) setBinScale(binScale);
|
Chris@445
|
1788
|
Chris@465
|
1789 bool invertVertical =
|
Chris@465
|
1790 (attributes.value("invertVertical").trimmed() == "true");
|
Chris@465
|
1791 setInvertVertical(invertVertical);
|
Chris@465
|
1792
|
Chris@465
|
1793 bool opaque =
|
Chris@465
|
1794 (attributes.value("opaque").trimmed() == "true");
|
Chris@535
|
1795 setOpaque(opaque);
|
Chris@535
|
1796
|
Chris@535
|
1797 bool smooth =
|
Chris@535
|
1798 (attributes.value("smooth").trimmed() == "true");
|
Chris@535
|
1799 setSmooth(smooth);
|
Chris@465
|
1800
|
Chris@536
|
1801 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@536
|
1802 if (ok) setGain(gain);
|
Chris@536
|
1803
|
Chris@445
|
1804 float min = attributes.value("minY").toFloat(&ok);
|
Chris@445
|
1805 float max = attributes.value("maxY").toFloat(&alsoOk);
|
Chris@445
|
1806 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@1099
|
1807
|
Chris@1099
|
1808 bool haveNewStyleNormalization = false;
|
Chris@1099
|
1809
|
Chris@1099
|
1810 QString columnNormalization = attributes.value("columnNormalization");
|
Chris@1099
|
1811
|
Chris@1099
|
1812 if (columnNormalization != "") {
|
Chris@1099
|
1813
|
Chris@1099
|
1814 haveNewStyleNormalization = true;
|
Chris@1099
|
1815
|
Chris@1099
|
1816 if (columnNormalization == "peak") {
|
Chris@1099
|
1817 setNormalization(ColumnOp::NormalizeColumns);
|
Chris@1099
|
1818 } else if (columnNormalization == "hybrid") {
|
Chris@1099
|
1819 setNormalization(ColumnOp::NormalizeHybrid);
|
Chris@1099
|
1820 } else if (columnNormalization == "none") {
|
Chris@1099
|
1821 // do nothing
|
Chris@1099
|
1822 } else {
|
Chris@1099
|
1823 cerr << "NOTE: Unknown or unsupported columnNormalization attribute \""
|
Chris@1099
|
1824 << columnNormalization << "\"" << endl;
|
Chris@1099
|
1825 }
|
Chris@1099
|
1826 }
|
Chris@1099
|
1827
|
Chris@1099
|
1828 if (!haveNewStyleNormalization) {
|
Chris@1099
|
1829
|
Chris@1099
|
1830 bool normalizeColumns =
|
Chris@1099
|
1831 (attributes.value("normalizeColumns").trimmed() == "true");
|
Chris@1099
|
1832 if (normalizeColumns) {
|
Chris@1099
|
1833 setNormalization(ColumnOp::NormalizeColumns);
|
Chris@1099
|
1834 }
|
Chris@1099
|
1835
|
Chris@1099
|
1836 bool normalizeHybrid =
|
Chris@1099
|
1837 (attributes.value("normalizeHybrid").trimmed() == "true");
|
Chris@1099
|
1838 if (normalizeHybrid) {
|
Chris@1099
|
1839 setNormalization(ColumnOp::NormalizeHybrid);
|
Chris@1099
|
1840 }
|
Chris@1099
|
1841 }
|
Chris@1099
|
1842
|
Chris@1099
|
1843 bool normalizeVisibleArea =
|
Chris@1099
|
1844 (attributes.value("normalizeVisibleArea").trimmed() == "true");
|
Chris@1099
|
1845 if (normalizeVisibleArea) {
|
Chris@1099
|
1846 setNormalization(ColumnOp::NormalizeVisibleArea);
|
Chris@1099
|
1847 }
|
Chris@1099
|
1848
|
Chris@1099
|
1849 //!!! todo: check save/reload scaling, compare with
|
Chris@1099
|
1850 //!!! SpectrogramLayer, compare with prior SV versions, compare
|
Chris@1099
|
1851 //!!! with Tony v1 and v2 and their save files
|
Chris@197
|
1852 }
|
Chris@197
|
1853
|