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@1100
|
26 #include "data/model/Dense3DModelPeakCache.h"
|
Chris@1100
|
27
|
Chris@1077
|
28 #include "view/ViewManager.h"
|
Chris@0
|
29
|
Chris@0
|
30 #include <QPainter>
|
Chris@0
|
31 #include <QImage>
|
Chris@0
|
32 #include <QRect>
|
Chris@316
|
33 #include <QTextStream>
|
Chris@1018
|
34 #include <QSettings>
|
Chris@0
|
35
|
Chris@0
|
36 #include <iostream>
|
Chris@0
|
37
|
Chris@0
|
38 #include <cassert>
|
Chris@0
|
39
|
Chris@903
|
40 using std::vector;
|
Chris@903
|
41
|
Chris@353
|
42 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
|
Chris@125
|
43
|
Chris@0
|
44
|
Chris@44
|
45 Colour3DPlotLayer::Colour3DPlotLayer() :
|
Chris@1105
|
46 m_colourScale(ColourScaleType::Linear),
|
Chris@461
|
47 m_colourScaleSet(false),
|
Chris@197
|
48 m_colourMap(0),
|
Chris@1362
|
49 m_colourInverted(false),
|
Chris@534
|
50 m_gain(1.0),
|
Chris@1103
|
51 m_binScale(BinScale::Linear),
|
Chris@1104
|
52 m_normalization(ColumnNormalization::None),
|
Chris@1104
|
53 m_normalizeVisibleArea(false),
|
Chris@444
|
54 m_invertVertical(false),
|
Chris@465
|
55 m_opaque(false),
|
Chris@535
|
56 m_smooth(false),
|
Chris@805
|
57 m_peakResolution(256),
|
Chris@444
|
58 m_miny(0),
|
Chris@1100
|
59 m_maxy(0),
|
Chris@1101
|
60 m_synchronous(false),
|
Chris@1100
|
61 m_peakCacheDivisor(8)
|
Chris@0
|
62 {
|
Chris@1018
|
63 QSettings settings;
|
Chris@1018
|
64 settings.beginGroup("Preferences");
|
Chris@1469
|
65 setColourMap(settings.value("colour-3d-plot-colour",
|
Chris@1469
|
66 ColourMapper::Green).toInt());
|
Chris@1018
|
67 settings.endGroup();
|
Chris@0
|
68 }
|
Chris@0
|
69
|
Chris@0
|
70 Colour3DPlotLayer::~Colour3DPlotLayer()
|
Chris@0
|
71 {
|
Chris@1107
|
72 invalidateRenderers();
|
Chris@1469
|
73 }
|
Chris@1469
|
74
|
Chris@1469
|
75 const ZoomConstraint *
|
Chris@1469
|
76 Colour3DPlotLayer::getZoomConstraint() const
|
Chris@1469
|
77 {
|
Chris@1469
|
78 auto model = ModelById::get(m_model);
|
Chris@1469
|
79 if (model) return model->getZoomConstraint();
|
Chris@1469
|
80 else return nullptr;
|
Chris@0
|
81 }
|
Chris@0
|
82
|
Chris@1105
|
83 ColourScaleType
|
Chris@1104
|
84 Colour3DPlotLayer::convertToColourScale(int value)
|
Chris@1104
|
85 {
|
Chris@1104
|
86 switch (value) {
|
Chris@1104
|
87 default:
|
Chris@1105
|
88 case 0: return ColourScaleType::Linear;
|
Chris@1105
|
89 case 1: return ColourScaleType::Log;
|
Chris@1105
|
90 case 2: return ColourScaleType::PlusMinusOne;
|
Chris@1105
|
91 case 3: return ColourScaleType::Absolute;
|
Chris@1104
|
92 }
|
Chris@1104
|
93 }
|
Chris@1104
|
94
|
Chris@1104
|
95 int
|
Chris@1105
|
96 Colour3DPlotLayer::convertFromColourScale(ColourScaleType scale)
|
Chris@1104
|
97 {
|
Chris@1104
|
98 switch (scale) {
|
Chris@1105
|
99 case ColourScaleType::Linear: return 0;
|
Chris@1105
|
100 case ColourScaleType::Log: return 1;
|
Chris@1105
|
101 case ColourScaleType::PlusMinusOne: return 2;
|
Chris@1105
|
102 case ColourScaleType::Absolute: return 3;
|
Chris@1104
|
103
|
Chris@1105
|
104 case ColourScaleType::Meter:
|
Chris@1105
|
105 case ColourScaleType::Phase:
|
Chris@1104
|
106 default: return 0;
|
Chris@1104
|
107 }
|
Chris@1104
|
108 }
|
Chris@1104
|
109
|
Chris@1104
|
110 std::pair<ColumnNormalization, bool>
|
Chris@1104
|
111 Colour3DPlotLayer::convertToColumnNorm(int value)
|
Chris@1104
|
112 {
|
Chris@1104
|
113 switch (value) {
|
Chris@1104
|
114 default:
|
Chris@1104
|
115 case 0: return { ColumnNormalization::None, false };
|
Chris@1245
|
116 case 1: return { ColumnNormalization::Range01, false };
|
Chris@1104
|
117 case 2: return { ColumnNormalization::None, true }; // visible area
|
Chris@1104
|
118 case 3: return { ColumnNormalization::Hybrid, false };
|
Chris@1104
|
119 }
|
Chris@1104
|
120 }
|
Chris@1104
|
121
|
Chris@1104
|
122 int
|
Chris@1104
|
123 Colour3DPlotLayer::convertFromColumnNorm(ColumnNormalization norm, bool visible)
|
Chris@1104
|
124 {
|
Chris@1104
|
125 if (visible) return 2;
|
Chris@1104
|
126 switch (norm) {
|
Chris@1104
|
127 case ColumnNormalization::None: return 0;
|
Chris@1245
|
128 case ColumnNormalization::Range01: return 1;
|
Chris@1104
|
129 case ColumnNormalization::Hybrid: return 3;
|
Chris@1104
|
130
|
Chris@1104
|
131 case ColumnNormalization::Sum1:
|
Chris@1245
|
132 case ColumnNormalization::Max1:
|
Chris@1104
|
133 default: return 0;
|
Chris@1104
|
134 }
|
Chris@1104
|
135 }
|
Chris@1104
|
136
|
Chris@0
|
137 void
|
Chris@1101
|
138 Colour3DPlotLayer::setSynchronousPainting(bool synchronous)
|
Chris@1101
|
139 {
|
Chris@1101
|
140 m_synchronous = synchronous;
|
Chris@1101
|
141 }
|
Chris@1101
|
142
|
Chris@1101
|
143 void
|
Chris@1469
|
144 Colour3DPlotLayer::setModel(ModelId modelId)
|
Chris@0
|
145 {
|
Chris@1471
|
146 auto newModel = ModelById::getAs<DenseThreeDimensionalModel>(modelId);
|
Chris@1471
|
147
|
Chris@1471
|
148 if (!modelId.isNone() && !newModel) {
|
Chris@1471
|
149 throw std::logic_error("Not a DenseThreeDimensionalModel");
|
Chris@1471
|
150 }
|
Chris@1471
|
151
|
Chris@1469
|
152 if (m_model == modelId) return;
|
Chris@1469
|
153 m_model = modelId;
|
Chris@0
|
154
|
Chris@1471
|
155 if (newModel) {
|
Chris@1471
|
156 connectSignals(m_model);
|
Chris@0
|
157
|
Chris@1471
|
158 connect(newModel.get(), SIGNAL(modelChanged()),
|
Chris@1471
|
159 this, SLOT(handleModelChanged()));
|
Chris@1471
|
160 connect(newModel.get(), SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
|
Chris@1471
|
161 this, SLOT(handleModelChangedWithin(sv_frame_t, sv_frame_t)));
|
Chris@0
|
162
|
Chris@1471
|
163 m_peakResolution = 256;
|
Chris@1471
|
164 if (newModel->getResolution() > 512) {
|
Chris@1471
|
165 m_peakResolution = 16;
|
Chris@1471
|
166 } else if (newModel->getResolution() > 128) {
|
Chris@1471
|
167 m_peakResolution = 64;
|
Chris@1471
|
168 } else if (newModel->getResolution() > 2) {
|
Chris@1471
|
169 m_peakResolution = 128;
|
Chris@1471
|
170 }
|
Chris@474
|
171 }
|
Chris@1471
|
172
|
Chris@1453
|
173 invalidatePeakCache();
|
Chris@474
|
174
|
Chris@0
|
175 emit modelReplaced();
|
Chris@1469
|
176 //!!! emit sliceableModelReplaced(oldModel, model);
|
Chris@0
|
177 }
|
Chris@0
|
178
|
Chris@0
|
179 void
|
Chris@1453
|
180 Colour3DPlotLayer::invalidatePeakCache()
|
Chris@0
|
181 {
|
Chris@1453
|
182 // renderers use the peak cache, so we must invalidate those too
|
Chris@1107
|
183 invalidateRenderers();
|
Chris@1235
|
184 invalidateMagnitudes();
|
Chris@1469
|
185
|
Chris@1107
|
186 delete m_peakCache;
|
Chris@1408
|
187 m_peakCache = nullptr;
|
Chris@1107
|
188 }
|
Chris@1107
|
189
|
Chris@1107
|
190 void
|
Chris@1107
|
191 Colour3DPlotLayer::invalidateRenderers()
|
Chris@1107
|
192 {
|
Chris@1102
|
193 for (ViewRendererMap::iterator i = m_renderers.begin();
|
Chris@1102
|
194 i != m_renderers.end(); ++i) {
|
Chris@1102
|
195 delete i->second;
|
Chris@1102
|
196 }
|
Chris@1102
|
197 m_renderers.clear();
|
Chris@0
|
198 }
|
Chris@0
|
199
|
Chris@1235
|
200 void
|
Chris@1235
|
201 Colour3DPlotLayer::invalidateMagnitudes()
|
Chris@1235
|
202 {
|
Chris@1235
|
203 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
204 SVDEBUG << "Colour3DPlotLayer::invalidateMagnitudes called" << endl;
|
Chris@1235
|
205 #endif
|
Chris@1235
|
206 m_viewMags.clear();
|
Chris@1235
|
207 }
|
Chris@1235
|
208
|
Chris@1100
|
209 Dense3DModelPeakCache *
|
Chris@1100
|
210 Colour3DPlotLayer::getPeakCache() const
|
Chris@1100
|
211 {
|
Chris@1100
|
212 if (!m_peakCache) {
|
Chris@1100
|
213 m_peakCache = new Dense3DModelPeakCache(m_model, m_peakCacheDivisor);
|
Chris@1100
|
214 }
|
Chris@1100
|
215 return m_peakCache;
|
Chris@1100
|
216 }
|
Chris@1100
|
217
|
Chris@461
|
218 void
|
Chris@1453
|
219 Colour3DPlotLayer::handleModelChanged()
|
Chris@461
|
220 {
|
Chris@1105
|
221 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
|
Chris@1469
|
222 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
223 if (model) {
|
Chris@1469
|
224 if (model->shouldUseLogValueScale()) {
|
Chris@1105
|
225 setColourScale(ColourScaleType::Log);
|
Chris@461
|
226 } else {
|
Chris@461
|
227 m_colourScaleSet = true;
|
Chris@461
|
228 }
|
Chris@461
|
229 }
|
Chris@461
|
230 }
|
Chris@1453
|
231 invalidatePeakCache();
|
Chris@1453
|
232 emit modelChanged();
|
Chris@0
|
233 }
|
Chris@0
|
234
|
Chris@461
|
235 void
|
Chris@1453
|
236 Colour3DPlotLayer::handleModelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@461
|
237 {
|
Chris@1105
|
238 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
|
Chris@1469
|
239 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
240 if (model && model->getWidth() > 50) {
|
Chris@1469
|
241 if (model->shouldUseLogValueScale()) {
|
Chris@1105
|
242 setColourScale(ColourScaleType::Log);
|
Chris@461
|
243 } else {
|
Chris@461
|
244 m_colourScaleSet = true;
|
Chris@461
|
245 }
|
Chris@461
|
246 }
|
Chris@461
|
247 }
|
Chris@1453
|
248 emit modelChangedWithin(startFrame, endFrame);
|
Chris@461
|
249 }
|
Chris@461
|
250
|
Chris@159
|
251 Layer::PropertyList
|
Chris@159
|
252 Colour3DPlotLayer::getProperties() const
|
Chris@159
|
253 {
|
Chris@159
|
254 PropertyList list;
|
Chris@197
|
255 list.push_back("Colour");
|
Chris@159
|
256 list.push_back("Colour Scale");
|
Chris@1104
|
257 list.push_back("Normalization");
|
Chris@534
|
258 list.push_back("Gain");
|
Chris@531
|
259 list.push_back("Bin Scale");
|
Chris@357
|
260 list.push_back("Invert Vertical Scale");
|
Chris@465
|
261 list.push_back("Opaque");
|
Chris@535
|
262 list.push_back("Smooth");
|
Chris@159
|
263 return list;
|
Chris@159
|
264 }
|
Chris@159
|
265
|
Chris@159
|
266 QString
|
Chris@159
|
267 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@159
|
268 {
|
Chris@197
|
269 if (name == "Colour") return tr("Colour");
|
Chris@197
|
270 if (name == "Colour Scale") return tr("Scale");
|
Chris@1104
|
271 if (name == "Normalization") return tr("Normalization");
|
Chris@357
|
272 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
|
Chris@534
|
273 if (name == "Gain") return tr("Gain");
|
Chris@465
|
274 if (name == "Opaque") return tr("Always Opaque");
|
Chris@535
|
275 if (name == "Smooth") return tr("Smooth");
|
Chris@531
|
276 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@159
|
277 return "";
|
Chris@159
|
278 }
|
Chris@159
|
279
|
Chris@346
|
280 QString
|
Chris@346
|
281 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@346
|
282 {
|
Chris@357
|
283 if (name == "Invert Vertical Scale") return "invert-vertical";
|
Chris@465
|
284 if (name == "Opaque") return "opaque";
|
Chris@535
|
285 if (name == "Smooth") return "smooth";
|
Chris@346
|
286 return "";
|
Chris@346
|
287 }
|
Chris@346
|
288
|
Chris@159
|
289 Layer::PropertyType
|
Chris@159
|
290 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
|
Chris@159
|
291 {
|
Chris@534
|
292 if (name == "Gain") return RangeProperty;
|
Chris@357
|
293 if (name == "Invert Vertical Scale") return ToggleProperty;
|
Chris@465
|
294 if (name == "Opaque") return ToggleProperty;
|
Chris@535
|
295 if (name == "Smooth") return ToggleProperty;
|
Chris@1198
|
296 if (name == "Colour") return ColourMapProperty;
|
Chris@159
|
297 return ValueProperty;
|
Chris@159
|
298 }
|
Chris@159
|
299
|
Chris@159
|
300 QString
|
Chris@159
|
301 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@159
|
302 {
|
Chris@1104
|
303 if (name == "Normalization" ||
|
Chris@1104
|
304 name == "Colour Scale" ||
|
Chris@1365
|
305 name == "Gain") {
|
Chris@1365
|
306 return tr("Scale");
|
Chris@1365
|
307 }
|
Chris@531
|
308 if (name == "Bin Scale" ||
|
Chris@1365
|
309 name == "Invert Vertical Scale") {
|
Chris@1365
|
310 return tr("Bins");
|
Chris@1365
|
311 }
|
Chris@465
|
312 if (name == "Opaque" ||
|
Chris@535
|
313 name == "Smooth" ||
|
Chris@1365
|
314 name == "Colour") {
|
Chris@1365
|
315 return tr("Colour");
|
Chris@1365
|
316 }
|
Chris@159
|
317 return QString();
|
Chris@159
|
318 }
|
Chris@159
|
319
|
Chris@159
|
320 int
|
Chris@159
|
321 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
322 int *min, int *max, int *deflt) const
|
Chris@159
|
323 {
|
Chris@216
|
324 int val = 0;
|
Chris@159
|
325
|
Chris@216
|
326 int garbage0, garbage1, garbage2;
|
Chris@159
|
327 if (!min) min = &garbage0;
|
Chris@159
|
328 if (!max) max = &garbage1;
|
Chris@216
|
329 if (!deflt) deflt = &garbage2;
|
Chris@159
|
330
|
Chris@534
|
331 if (name == "Gain") {
|
Chris@534
|
332
|
Chris@1266
|
333 *min = -50;
|
Chris@1266
|
334 *max = 50;
|
Chris@534
|
335
|
Chris@902
|
336 *deflt = int(lrint(log10(1.0) * 20.0));
|
Chris@1266
|
337 if (*deflt < *min) *deflt = *min;
|
Chris@1266
|
338 if (*deflt > *max) *deflt = *max;
|
Chris@534
|
339
|
Chris@1266
|
340 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@1266
|
341 if (val < *min) val = *min;
|
Chris@1266
|
342 if (val > *max) val = *max;
|
Chris@534
|
343
|
Chris@534
|
344 } else if (name == "Colour Scale") {
|
Chris@159
|
345
|
Chris@1099
|
346 // linear, log, +/-1, abs
|
Chris@1266
|
347 *min = 0;
|
Chris@1266
|
348 *max = 3;
|
Chris@1099
|
349 *deflt = 0;
|
Chris@159
|
350
|
Chris@1266
|
351 val = convertFromColourScale(m_colourScale);
|
Chris@159
|
352
|
Chris@197
|
353 } else if (name == "Colour") {
|
Chris@197
|
354
|
Chris@1266
|
355 *min = 0;
|
Chris@1266
|
356 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@216
|
357 *deflt = 0;
|
Chris@197
|
358
|
Chris@1266
|
359 val = m_colourMap;
|
Chris@197
|
360
|
Chris@1099
|
361 } else if (name == "Normalization") {
|
Chris@1266
|
362
|
Chris@1099
|
363 *min = 0;
|
Chris@1099
|
364 *max = 3;
|
Chris@1104
|
365 *deflt = 0;
|
Chris@1104
|
366
|
Chris@1104
|
367 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea);
|
Chris@197
|
368
|
Chris@357
|
369 } else if (name == "Invert Vertical Scale") {
|
Chris@1365
|
370
|
Chris@1365
|
371 *min = 0;
|
Chris@1365
|
372 *max = 1;
|
Chris@357
|
373 *deflt = 0;
|
Chris@1266
|
374 val = (m_invertVertical ? 1 : 0);
|
Chris@357
|
375
|
Chris@531
|
376 } else if (name == "Bin Scale") {
|
Chris@531
|
377
|
Chris@1266
|
378 *min = 0;
|
Chris@1266
|
379 *max = 1;
|
Chris@1103
|
380 *deflt = int(BinScale::Linear);
|
Chris@1266
|
381 val = (int)m_binScale;
|
Chris@531
|
382
|
Chris@465
|
383 } else if (name == "Opaque") {
|
Chris@1266
|
384
|
Chris@1365
|
385 *min = 0;
|
Chris@1365
|
386 *max = 1;
|
Chris@465
|
387 *deflt = 0;
|
Chris@1266
|
388 val = (m_opaque ? 1 : 0);
|
Chris@465
|
389
|
Chris@535
|
390 } else if (name == "Smooth") {
|
Chris@1266
|
391
|
Chris@1365
|
392 *min = 0;
|
Chris@1365
|
393 *max = 1;
|
Chris@535
|
394 *deflt = 0;
|
Chris@1266
|
395 val = (m_smooth ? 1 : 0);
|
Chris@535
|
396
|
Chris@159
|
397 } else {
|
Chris@1266
|
398 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@159
|
399 }
|
Chris@159
|
400
|
Chris@216
|
401 return val;
|
Chris@159
|
402 }
|
Chris@159
|
403
|
Chris@159
|
404 QString
|
Chris@159
|
405 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@1266
|
406 int value) const
|
Chris@159
|
407 {
|
Chris@197
|
408 if (name == "Colour") {
|
Chris@1362
|
409 return ColourMapper::getColourMapLabel(value);
|
Chris@197
|
410 }
|
Chris@159
|
411 if (name == "Colour Scale") {
|
Chris@1266
|
412 switch (value) {
|
Chris@1266
|
413 default:
|
Chris@1266
|
414 case 0: return tr("Linear");
|
Chris@1266
|
415 case 1: return tr("Log");
|
Chris@1266
|
416 case 2: return tr("+/-1");
|
Chris@1266
|
417 case 3: return tr("Absolute");
|
Chris@1266
|
418 }
|
Chris@159
|
419 }
|
Chris@1099
|
420 if (name == "Normalization") {
|
Chris@1209
|
421 switch(value) {
|
Chris@1209
|
422 default:
|
Chris@1209
|
423 case 0: return tr("None");
|
Chris@1209
|
424 case 1: return tr("Col");
|
Chris@1209
|
425 case 2: return tr("View");
|
Chris@1209
|
426 case 3: return tr("Hybrid");
|
Chris@1209
|
427 }
|
Chris@1209
|
428 // return ""; // icon only
|
Chris@1099
|
429 }
|
Chris@531
|
430 if (name == "Bin Scale") {
|
Chris@1266
|
431 switch (value) {
|
Chris@1266
|
432 default:
|
Chris@1266
|
433 case 0: return tr("Linear");
|
Chris@1266
|
434 case 1: return tr("Log");
|
Chris@1266
|
435 }
|
Chris@531
|
436 }
|
Chris@159
|
437 return tr("<unknown>");
|
Chris@159
|
438 }
|
Chris@159
|
439
|
Chris@1099
|
440 QString
|
Chris@1099
|
441 Colour3DPlotLayer::getPropertyValueIconName(const PropertyName &name,
|
Chris@1099
|
442 int value) const
|
Chris@1099
|
443 {
|
Chris@1099
|
444 if (name == "Normalization") {
|
Chris@1099
|
445 switch(value) {
|
Chris@1099
|
446 default:
|
Chris@1099
|
447 case 0: return "normalise-none";
|
Chris@1099
|
448 case 1: return "normalise-columns";
|
Chris@1099
|
449 case 2: return "normalise";
|
Chris@1099
|
450 case 3: return "normalise-hybrid";
|
Chris@1099
|
451 }
|
Chris@1099
|
452 }
|
Chris@1099
|
453 return "";
|
Chris@1099
|
454 }
|
Chris@1099
|
455
|
Chris@534
|
456 RangeMapper *
|
Chris@534
|
457 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@534
|
458 {
|
Chris@534
|
459 if (name == "Gain") {
|
Chris@534
|
460 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@534
|
461 }
|
Chris@1408
|
462 return nullptr;
|
Chris@534
|
463 }
|
Chris@534
|
464
|
Chris@159
|
465 void
|
Chris@159
|
466 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
|
Chris@159
|
467 {
|
Chris@534
|
468 if (name == "Gain") {
|
Chris@1266
|
469 setGain(float(pow(10, value/20.0)));
|
Chris@534
|
470 } else if (name == "Colour Scale") {
|
Chris@1104
|
471 setColourScale(convertToColourScale(value));
|
Chris@197
|
472 } else if (name == "Colour") {
|
Chris@197
|
473 setColourMap(value);
|
Chris@357
|
474 } else if (name == "Invert Vertical Scale") {
|
Chris@1266
|
475 setInvertVertical(value ? true : false);
|
Chris@465
|
476 } else if (name == "Opaque") {
|
Chris@1266
|
477 setOpaque(value ? true : false);
|
Chris@535
|
478 } else if (name == "Smooth") {
|
Chris@1266
|
479 setSmooth(value ? true : false);
|
Chris@531
|
480 } else if (name == "Bin Scale") {
|
Chris@1266
|
481 switch (value) {
|
Chris@1266
|
482 default:
|
Chris@1266
|
483 case 0: setBinScale(BinScale::Linear); break;
|
Chris@1266
|
484 case 1: setBinScale(BinScale::Log); break;
|
Chris@1266
|
485 }
|
Chris@1099
|
486 } else if (name == "Normalization") {
|
Chris@1104
|
487 auto n = convertToColumnNorm(value);
|
Chris@1104
|
488 setNormalization(n.first);
|
Chris@1104
|
489 setNormalizeVisibleArea(n.second);
|
Chris@159
|
490 }
|
Chris@159
|
491 }
|
Chris@159
|
492
|
Chris@159
|
493 void
|
Chris@1105
|
494 Colour3DPlotLayer::setColourScale(ColourScaleType scale)
|
Chris@159
|
495 {
|
Chris@1254
|
496 m_colourScaleSet = true; // even if setting to the same thing
|
Chris@159
|
497 if (m_colourScale == scale) return;
|
Chris@159
|
498 m_colourScale = scale;
|
Chris@1107
|
499 invalidateRenderers();
|
Chris@159
|
500 emit layerParametersChanged();
|
Chris@159
|
501 }
|
Chris@159
|
502
|
Chris@197
|
503 void
|
Chris@197
|
504 Colour3DPlotLayer::setColourMap(int map)
|
Chris@197
|
505 {
|
Chris@197
|
506 if (m_colourMap == map) return;
|
Chris@197
|
507 m_colourMap = map;
|
Chris@1107
|
508 invalidateRenderers();
|
Chris@197
|
509 emit layerParametersChanged();
|
Chris@197
|
510 }
|
Chris@197
|
511
|
Chris@197
|
512 void
|
Chris@534
|
513 Colour3DPlotLayer::setGain(float gain)
|
Chris@534
|
514 {
|
Chris@534
|
515 if (m_gain == gain) return;
|
Chris@534
|
516 m_gain = gain;
|
Chris@1107
|
517 invalidateRenderers();
|
Chris@534
|
518 emit layerParametersChanged();
|
Chris@534
|
519 }
|
Chris@534
|
520
|
Chris@534
|
521 float
|
Chris@534
|
522 Colour3DPlotLayer::getGain() const
|
Chris@534
|
523 {
|
Chris@534
|
524 return m_gain;
|
Chris@534
|
525 }
|
Chris@534
|
526
|
Chris@534
|
527 void
|
Chris@1103
|
528 Colour3DPlotLayer::setBinScale(BinScale binScale)
|
Chris@531
|
529 {
|
Chris@531
|
530 if (m_binScale == binScale) return;
|
Chris@531
|
531 m_binScale = binScale;
|
Chris@1107
|
532 invalidateRenderers();
|
Chris@531
|
533 emit layerParametersChanged();
|
Chris@531
|
534 }
|
Chris@531
|
535
|
Chris@1103
|
536 BinScale
|
Chris@531
|
537 Colour3DPlotLayer::getBinScale() const
|
Chris@531
|
538 {
|
Chris@531
|
539 return m_binScale;
|
Chris@531
|
540 }
|
Chris@531
|
541
|
Chris@531
|
542 void
|
Chris@1104
|
543 Colour3DPlotLayer::setNormalization(ColumnNormalization n)
|
Chris@197
|
544 {
|
Chris@1099
|
545 if (m_normalization == n) return;
|
Chris@1099
|
546
|
Chris@1099
|
547 m_normalization = n;
|
Chris@1107
|
548 invalidateRenderers();
|
Chris@1099
|
549
|
Chris@197
|
550 emit layerParametersChanged();
|
Chris@197
|
551 }
|
Chris@197
|
552
|
Chris@1104
|
553 ColumnNormalization
|
Chris@1099
|
554 Colour3DPlotLayer::getNormalization() const
|
Chris@197
|
555 {
|
Chris@1099
|
556 return m_normalization;
|
Chris@197
|
557 }
|
Chris@197
|
558
|
Chris@357
|
559 void
|
Chris@1104
|
560 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
|
Chris@1104
|
561 {
|
Chris@1104
|
562 if (m_normalizeVisibleArea == n) return;
|
Chris@1104
|
563
|
Chris@1235
|
564 invalidateRenderers();
|
Chris@1235
|
565 invalidateMagnitudes();
|
Chris@1104
|
566 m_normalizeVisibleArea = n;
|
Chris@1104
|
567
|
Chris@1104
|
568 emit layerParametersChanged();
|
Chris@1104
|
569 }
|
Chris@1104
|
570
|
Chris@1104
|
571 bool
|
Chris@1104
|
572 Colour3DPlotLayer::getNormalizeVisibleArea() const
|
Chris@1104
|
573 {
|
Chris@1104
|
574 return m_normalizeVisibleArea;
|
Chris@1104
|
575 }
|
Chris@1104
|
576
|
Chris@1104
|
577 void
|
Chris@357
|
578 Colour3DPlotLayer::setInvertVertical(bool n)
|
Chris@357
|
579 {
|
Chris@357
|
580 if (m_invertVertical == n) return;
|
Chris@357
|
581 m_invertVertical = n;
|
Chris@1107
|
582 invalidateRenderers();
|
Chris@357
|
583 emit layerParametersChanged();
|
Chris@357
|
584 }
|
Chris@357
|
585
|
Chris@465
|
586 void
|
Chris@465
|
587 Colour3DPlotLayer::setOpaque(bool n)
|
Chris@465
|
588 {
|
Chris@465
|
589 if (m_opaque == n) return;
|
Chris@465
|
590 m_opaque = n;
|
Chris@1107
|
591 invalidateRenderers();
|
Chris@465
|
592 emit layerParametersChanged();
|
Chris@465
|
593 }
|
Chris@465
|
594
|
Chris@535
|
595 void
|
Chris@535
|
596 Colour3DPlotLayer::setSmooth(bool n)
|
Chris@535
|
597 {
|
Chris@535
|
598 if (m_smooth == n) return;
|
Chris@535
|
599 m_smooth = n;
|
Chris@1107
|
600 invalidateRenderers();
|
Chris@535
|
601 emit layerParametersChanged();
|
Chris@535
|
602 }
|
Chris@535
|
603
|
Chris@357
|
604 bool
|
Chris@357
|
605 Colour3DPlotLayer::getInvertVertical() const
|
Chris@357
|
606 {
|
Chris@357
|
607 return m_invertVertical;
|
Chris@357
|
608 }
|
Chris@357
|
609
|
Chris@25
|
610 bool
|
Chris@465
|
611 Colour3DPlotLayer::getOpaque() const
|
Chris@465
|
612 {
|
Chris@465
|
613 return m_opaque;
|
Chris@465
|
614 }
|
Chris@465
|
615
|
Chris@535
|
616 bool
|
Chris@535
|
617 Colour3DPlotLayer::getSmooth() const
|
Chris@535
|
618 {
|
Chris@535
|
619 return m_smooth;
|
Chris@535
|
620 }
|
Chris@535
|
621
|
Chris@1453
|
622 bool
|
Chris@1453
|
623 Colour3DPlotLayer::hasLightBackground() const
|
Chris@1453
|
624 {
|
Chris@1453
|
625 return ColourMapper(m_colourMap, m_colourInverted, 1.f, 255.f)
|
Chris@1453
|
626 .hasLightBackground();
|
Chris@1453
|
627 }
|
Chris@1453
|
628
|
Chris@475
|
629 void
|
Chris@916
|
630 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
|
Chris@475
|
631 {
|
Chris@475
|
632 if (dormant) {
|
Chris@475
|
633
|
Chris@475
|
634 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
635 SVDEBUG << "Colour3DPlotLayer::setLayerDormant(" << dormant << ")"
|
Chris@585
|
636 << endl;
|
Chris@475
|
637 #endif
|
Chris@475
|
638
|
Chris@475
|
639 if (isLayerDormant(v)) {
|
Chris@475
|
640 return;
|
Chris@475
|
641 }
|
Chris@475
|
642
|
Chris@475
|
643 Layer::setLayerDormant(v, true);
|
Chris@475
|
644
|
Chris@1453
|
645 invalidatePeakCache(); // for memory-saving purposes
|
Chris@1266
|
646
|
Chris@475
|
647 } else {
|
Chris@475
|
648
|
Chris@475
|
649 Layer::setLayerDormant(v, false);
|
Chris@475
|
650 }
|
Chris@475
|
651 }
|
Chris@475
|
652
|
Chris@465
|
653 bool
|
Chris@1150
|
654 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider * /* v */) const
|
Chris@25
|
655 {
|
Chris@1419
|
656 // we do our own cacheing, and don't want to be responsible for
|
Chris@1419
|
657 // guaranteeing to get an invisible seam if someone else scrolls
|
Chris@1419
|
658 // us and we just fill in
|
Chris@1121
|
659 return false;
|
Chris@25
|
660 }
|
Chris@25
|
661
|
Chris@1469
|
662 int
|
Chris@1469
|
663 Colour3DPlotLayer::getCompletion(LayerGeometryProvider *) const
|
Chris@1469
|
664 {
|
Chris@1469
|
665 auto model = ModelById::get(m_model);
|
Chris@1469
|
666 if (model) return model->getCompletion();
|
Chris@1469
|
667 else return 0;
|
Chris@1469
|
668 }
|
Chris@1469
|
669
|
Chris@444
|
670 bool
|
Chris@904
|
671 Colour3DPlotLayer::getValueExtents(double &min, double &max,
|
Chris@444
|
672 bool &logarithmic, QString &unit) const
|
Chris@444
|
673 {
|
Chris@1469
|
674 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
675 if (!model) return false;
|
Chris@444
|
676
|
Chris@444
|
677 min = 0;
|
Chris@1469
|
678 max = double(model->getHeight());
|
Chris@444
|
679
|
Chris@1238
|
680 logarithmic = (m_binScale == BinScale::Log);
|
Chris@444
|
681 unit = "";
|
Chris@444
|
682
|
Chris@444
|
683 return true;
|
Chris@444
|
684 }
|
Chris@444
|
685
|
Chris@444
|
686 bool
|
Chris@904
|
687 Colour3DPlotLayer::getDisplayExtents(double &min, double &max) const
|
Chris@444
|
688 {
|
Chris@1469
|
689 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
690 if (!model) return false;
|
Chris@444
|
691
|
Chris@1469
|
692 double hmax = double(model->getHeight());
|
Chris@902
|
693
|
Chris@904
|
694 min = m_miny;
|
Chris@904
|
695 max = m_maxy;
|
Chris@444
|
696 if (max <= min) {
|
Chris@444
|
697 min = 0;
|
Chris@902
|
698 max = hmax;
|
Chris@444
|
699 }
|
Chris@444
|
700 if (min < 0) min = 0;
|
Chris@902
|
701 if (max > hmax) max = hmax;
|
Chris@444
|
702
|
Chris@444
|
703 return true;
|
Chris@444
|
704 }
|
Chris@444
|
705
|
Chris@444
|
706 bool
|
Chris@904
|
707 Colour3DPlotLayer::setDisplayExtents(double min, double max)
|
Chris@444
|
708 {
|
Chris@904
|
709 m_miny = int(lrint(min));
|
Chris@904
|
710 m_maxy = int(lrint(max));
|
Chris@444
|
711
|
Chris@1133
|
712 invalidateRenderers();
|
Chris@1133
|
713
|
Chris@444
|
714 emit layerParametersChanged();
|
Chris@444
|
715 return true;
|
Chris@444
|
716 }
|
Chris@444
|
717
|
Chris@725
|
718 bool
|
Chris@916
|
719 Colour3DPlotLayer::getYScaleValue(const LayerGeometryProvider *, int,
|
Chris@904
|
720 double &, QString &) const
|
Chris@725
|
721 {
|
Chris@725
|
722 return false;//!!!
|
Chris@725
|
723 }
|
Chris@725
|
724
|
Chris@444
|
725 int
|
Chris@444
|
726 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@444
|
727 {
|
Chris@1469
|
728 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
729 if (!model) return 0;
|
Chris@444
|
730
|
Chris@444
|
731 defaultStep = 0;
|
Chris@1469
|
732 int h = model->getHeight();
|
Chris@444
|
733 return h;
|
Chris@444
|
734 }
|
Chris@444
|
735
|
Chris@444
|
736 int
|
Chris@444
|
737 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
|
Chris@444
|
738 {
|
Chris@1469
|
739 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
740 if (!model) return 0;
|
Chris@444
|
741
|
Chris@904
|
742 double min, max;
|
Chris@444
|
743 getDisplayExtents(min, max);
|
Chris@1469
|
744 return model->getHeight() - int(lrint(max - min));
|
Chris@444
|
745 }
|
Chris@444
|
746
|
Chris@444
|
747 void
|
Chris@444
|
748 Colour3DPlotLayer::setVerticalZoomStep(int step)
|
Chris@444
|
749 {
|
Chris@1469
|
750 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
751 if (!model) return;
|
Chris@444
|
752
|
Chris@587
|
753 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << endl;
|
Chris@444
|
754
|
Chris@1469
|
755 int dist = model->getHeight() - step;
|
Chris@444
|
756 if (dist < 1) dist = 1;
|
Chris@904
|
757 double centre = m_miny + (m_maxy - m_miny) / 2.0;
|
Chris@904
|
758 m_miny = int(lrint(centre - dist/2.0));
|
Chris@444
|
759 if (m_miny < 0) m_miny = 0;
|
Chris@444
|
760 m_maxy = m_miny + dist;
|
Chris@1469
|
761 if (m_maxy > model->getHeight()) m_maxy = model->getHeight();
|
Chris@444
|
762
|
Chris@1133
|
763 invalidateRenderers();
|
Chris@1133
|
764
|
Chris@587
|
765 // SVDEBUG << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << endl;
|
Chris@444
|
766
|
Chris@444
|
767 emit layerParametersChanged();
|
Chris@444
|
768 }
|
Chris@444
|
769
|
Chris@444
|
770 RangeMapper *
|
Chris@444
|
771 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
|
Chris@444
|
772 {
|
Chris@1469
|
773 //!!! most of our uses of model in these functions is just to
|
Chris@1469
|
774 //!!! retrieve the model's height - perhaps we should cache it
|
Chris@1469
|
775
|
Chris@1469
|
776 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
777 if (!model) return nullptr;
|
Chris@444
|
778
|
Chris@1469
|
779 return new LinearRangeMapper(0, model->getHeight(),
|
Chris@1469
|
780 0, model->getHeight(), "");
|
Chris@444
|
781 }
|
Chris@444
|
782
|
Chris@904
|
783 double
|
Chris@1113
|
784 Colour3DPlotLayer::getYForBin(const LayerGeometryProvider *v, double bin) const
|
Chris@532
|
785 {
|
Chris@904
|
786 double y = bin;
|
Chris@1469
|
787 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
788 if (!model) return y;
|
Chris@1469
|
789 double mn = 0, mx = model->getHeight();
|
Chris@532
|
790 getDisplayExtents(mn, mx);
|
Chris@916
|
791 double h = v->getPaintHeight();
|
Chris@1103
|
792 if (m_binScale == BinScale::Linear) {
|
Chris@532
|
793 y = h - (((bin - mn) * h) / (mx - mn));
|
Chris@532
|
794 } else {
|
Chris@904
|
795 double logmin = mn + 1, logmax = mx + 1;
|
Chris@532
|
796 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
797 y = h - (((LogRange::map(bin + 1) - logmin) * h) / (logmax - logmin));
|
Chris@532
|
798 }
|
Chris@532
|
799 return y;
|
Chris@532
|
800 }
|
Chris@532
|
801
|
Chris@904
|
802 double
|
Chris@1113
|
803 Colour3DPlotLayer::getBinForY(const LayerGeometryProvider *v, double y) const
|
Chris@532
|
804 {
|
Chris@904
|
805 double bin = y;
|
Chris@1469
|
806 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
807 if (!model) return bin;
|
Chris@1469
|
808 double mn = 0, mx = model->getHeight();
|
Chris@532
|
809 getDisplayExtents(mn, mx);
|
Chris@916
|
810 double h = v->getPaintHeight();
|
Chris@1103
|
811 if (m_binScale == BinScale::Linear) {
|
Chris@1220
|
812 // Arrange that the first bin (mn) appears as the exact result
|
Chris@1220
|
813 // for the first pixel (which is pixel h-1) and the first
|
Chris@1220
|
814 // out-of-range bin (mx) would appear as the exact result for
|
Chris@1220
|
815 // the first out-of-range pixel (which would be pixel -1)
|
Chris@1220
|
816 bin = mn + ((h - y - 1) * (mx - mn)) / h;
|
Chris@532
|
817 } else {
|
Chris@904
|
818 double logmin = mn + 1, logmax = mx + 1;
|
Chris@532
|
819 LogRange::mapRange(logmin, logmax);
|
Chris@1220
|
820 bin = LogRange::unmap(logmin + ((h - y - 1) * (logmax - logmin)) / h) - 1;
|
Chris@532
|
821 }
|
Chris@532
|
822 return bin;
|
Chris@532
|
823 }
|
Chris@532
|
824
|
Chris@25
|
825 QString
|
Chris@916
|
826 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
|
Chris@25
|
827 {
|
Chris@1469
|
828 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
829 if (!model) return "";
|
Chris@25
|
830
|
Chris@25
|
831 int x = pos.x();
|
Chris@25
|
832 int y = pos.y();
|
Chris@25
|
833
|
Chris@1469
|
834 sv_frame_t modelStart = model->getStartFrame();
|
Chris@1469
|
835 int modelResolution = model->getResolution();
|
Chris@25
|
836
|
Chris@902
|
837 double srRatio =
|
Chris@902
|
838 v->getViewManager()->getMainModelSampleRate() /
|
Chris@1469
|
839 model->getSampleRate();
|
Chris@159
|
840
|
Chris@902
|
841 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
|
Chris@812
|
842 modelResolution);
|
Chris@25
|
843
|
Chris@160
|
844 int f0 = sx0 * modelResolution;
|
Chris@160
|
845 int f1 = f0 + modelResolution;
|
Chris@160
|
846
|
Chris@1469
|
847 int sh = model->getHeight();
|
Chris@447
|
848
|
Chris@447
|
849 int symin = m_miny;
|
Chris@447
|
850 int symax = m_maxy;
|
Chris@447
|
851 if (symax <= symin) {
|
Chris@447
|
852 symin = 0;
|
Chris@447
|
853 symax = sh;
|
Chris@447
|
854 }
|
Chris@447
|
855 if (symin < 0) symin = 0;
|
Chris@447
|
856 if (symax > sh) symax = sh;
|
Chris@447
|
857
|
Chris@916
|
858 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
|
Chris@916
|
859 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
|
Chris@534
|
860
|
Chris@903
|
861 int sy = getIBinForY(v, y);
|
Chris@25
|
862
|
Chris@1469
|
863 if (sy < 0 || sy >= model->getHeight()) {
|
Chris@812
|
864 return "";
|
Chris@812
|
865 }
|
Chris@812
|
866
|
Chris@1362
|
867 if (m_invertVertical) {
|
Chris@1469
|
868 sy = model->getHeight() - sy - 1;
|
Chris@1362
|
869 }
|
Chris@357
|
870
|
Chris@1469
|
871 float value = model->getValueAt(sx0, sy);
|
Chris@159
|
872
|
Chris@682
|
873 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl;
|
Chris@25
|
874
|
Chris@1469
|
875 QString binName = model->getBinName(sy);
|
Chris@25
|
876 if (binName == "") binName = QString("[%1]").arg(sy + 1);
|
Chris@25
|
877 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
|
Chris@25
|
878
|
Chris@25
|
879 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
|
Chris@1469
|
880 .arg(RealTime::frame2RealTime(f0, model->getSampleRate())
|
Chris@1266
|
881 .toText(true).c_str())
|
Chris@1469
|
882 .arg(RealTime::frame2RealTime(f1, model->getSampleRate())
|
Chris@1266
|
883 .toText(true).c_str())
|
Chris@1266
|
884 .arg(binName)
|
Chris@1266
|
885 .arg(value);
|
Chris@25
|
886
|
Chris@25
|
887 return text;
|
Chris@25
|
888 }
|
Chris@25
|
889
|
Chris@25
|
890 int
|
Chris@969
|
891 Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const
|
Chris@159
|
892 {
|
Chris@969
|
893 // Font is rotated
|
Chris@969
|
894 int cw = p.fontMetrics().height();
|
Chris@159
|
895 return cw;
|
Chris@159
|
896 }
|
Chris@159
|
897
|
Chris@159
|
898 int
|
Chris@916
|
899 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@25
|
900 {
|
Chris@1469
|
901 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
902 if (!model) return 0;
|
Chris@25
|
903
|
Chris@1471
|
904 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
|
Chris@1471
|
905 // replacement (horizontalAdvance) was only added in Qt 5.11 which
|
Chris@1471
|
906 // is too new for us
|
Chris@1471
|
907 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
|
Chris@1471
|
908
|
Chris@1469
|
909 QString sampleText = QString("[%1]").arg(model->getHeight());
|
Chris@25
|
910 int tw = paint.fontMetrics().width(sampleText);
|
Chris@98
|
911 bool another = false;
|
Chris@25
|
912
|
Chris@1469
|
913 for (int i = 0; i < model->getHeight(); ++i) {
|
Chris@1469
|
914 if (model->getBinName(i).length() > sampleText.length()) {
|
Chris@1469
|
915 sampleText = model->getBinName(i);
|
Chris@98
|
916 another = true;
|
Chris@1266
|
917 }
|
Chris@25
|
918 }
|
Chris@98
|
919 if (another) {
|
Chris@1266
|
920 tw = std::max(tw, paint.fontMetrics().width(sampleText));
|
Chris@25
|
921 }
|
Chris@25
|
922
|
Chris@159
|
923 return tw + 13 + getColourScaleWidth(paint);
|
Chris@25
|
924 }
|
Chris@25
|
925
|
Chris@25
|
926 void
|
Chris@916
|
927 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@25
|
928 {
|
Chris@1469
|
929 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
930 if (!model) return;
|
Chris@25
|
931
|
Chris@25
|
932 int h = rect.height(), w = rect.width();
|
Chris@25
|
933
|
Chris@159
|
934 int cw = getColourScaleWidth(paint);
|
Chris@159
|
935
|
Chris@159
|
936 int ch = h - 20;
|
Chris@1107
|
937 if (ch > 20) {
|
Chris@159
|
938
|
Chris@1131
|
939 double min = m_viewMags[v->getId()].getMin();
|
Chris@1131
|
940 double max = m_viewMags[v->getId()].getMax();
|
Chris@447
|
941
|
Chris@1131
|
942 if (max <= min) max = min + 0.1;
|
Chris@447
|
943
|
Chris@287
|
944 paint.setPen(v->getForeground());
|
Chris@447
|
945 paint.drawRect(4, 10, cw - 8, ch+1);
|
Chris@159
|
946
|
Chris@446
|
947 for (int y = 0; y < ch; ++y) {
|
Chris@904
|
948 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
|
Chris@1131
|
949 paint.setPen(getRenderer(v)->getColour(value));
|
Chris@1131
|
950 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
|
Chris@159
|
951 }
|
Chris@446
|
952
|
Chris@446
|
953 QString minstr = QString("%1").arg(min);
|
Chris@446
|
954 QString maxstr = QString("%1").arg(max);
|
Chris@446
|
955
|
Chris@446
|
956 paint.save();
|
Chris@446
|
957
|
Chris@446
|
958 QFont font = paint.font();
|
Chris@1053
|
959 if (font.pixelSize() > 0) {
|
Chris@1053
|
960 int newSize = int(font.pixelSize() * 0.65);
|
Chris@1053
|
961 if (newSize < 6) newSize = 6;
|
Chris@1053
|
962 font.setPixelSize(newSize);
|
Chris@1053
|
963 paint.setFont(font);
|
Chris@1053
|
964 }
|
Chris@446
|
965
|
Chris@446
|
966 int msw = paint.fontMetrics().width(maxstr);
|
Chris@446
|
967
|
Chris@1471
|
968 QTransform m;
|
Chris@446
|
969 m.translate(cw - 6, ch + 10);
|
Chris@446
|
970 m.rotate(-90);
|
Chris@446
|
971
|
Chris@1471
|
972 paint.setWorldTransform(m);
|
Chris@446
|
973
|
Chris@1471
|
974 PaintAssistant::drawVisibleText(v, paint, 2, 0, minstr,
|
Chris@1471
|
975 PaintAssistant::OutlinedText);
|
Chris@446
|
976
|
Chris@446
|
977 m.translate(ch - msw - 2, 0);
|
Chris@1471
|
978 paint.setWorldTransform(m);
|
Chris@446
|
979
|
Chris@1471
|
980 PaintAssistant::drawVisibleText(v, paint, 0, 0, maxstr,
|
Chris@1471
|
981 PaintAssistant::OutlinedText);
|
Chris@446
|
982
|
Chris@446
|
983 paint.restore();
|
Chris@159
|
984 }
|
Chris@159
|
985
|
Chris@287
|
986 paint.setPen(v->getForeground());
|
Chris@159
|
987
|
Chris@1469
|
988 int sh = model->getHeight();
|
Chris@445
|
989
|
Chris@445
|
990 int symin = m_miny;
|
Chris@445
|
991 int symax = m_maxy;
|
Chris@445
|
992 if (symax <= symin) {
|
Chris@445
|
993 symin = 0;
|
Chris@445
|
994 symax = sh;
|
Chris@445
|
995 }
|
Chris@445
|
996 if (symin < 0) symin = 0;
|
Chris@445
|
997 if (symax > sh) symax = sh;
|
Chris@445
|
998
|
Chris@532
|
999 paint.save();
|
Chris@456
|
1000
|
Chris@533
|
1001 int py = h;
|
Chris@25
|
1002
|
Chris@969
|
1003 int defaultFontHeight = paint.fontMetrics().height();
|
Chris@969
|
1004
|
Chris@805
|
1005 for (int i = symin; i <= symax; ++i) {
|
Chris@98
|
1006
|
Chris@532
|
1007 int y0;
|
Chris@534
|
1008
|
Chris@903
|
1009 y0 = getIYForBin(v, i);
|
Chris@532
|
1010 int h = py - y0;
|
Chris@532
|
1011
|
Chris@532
|
1012 if (i > symin) {
|
Chris@532
|
1013 if (paint.fontMetrics().height() >= h) {
|
Chris@969
|
1014 if (h >= defaultFontHeight * 0.8) {
|
Chris@532
|
1015 QFont tf = paint.font();
|
Chris@973
|
1016 tf.setPixelSize(int(h * 0.8));
|
Chris@532
|
1017 paint.setFont(tf);
|
Chris@532
|
1018 } else {
|
Chris@532
|
1019 continue;
|
Chris@532
|
1020 }
|
Chris@532
|
1021 }
|
Chris@532
|
1022 }
|
Chris@1266
|
1023
|
Chris@532
|
1024 py = y0;
|
Chris@532
|
1025
|
Chris@534
|
1026 if (i < symax) {
|
Chris@534
|
1027 paint.drawLine(cw, y0, w, y0);
|
Chris@534
|
1028 }
|
Chris@25
|
1029
|
Chris@532
|
1030 if (i > symin) {
|
Chris@534
|
1031
|
Chris@805
|
1032 int idx = i - 1;
|
Chris@1362
|
1033 if (m_invertVertical) {
|
Chris@1469
|
1034 idx = model->getHeight() - idx - 1;
|
Chris@1362
|
1035 }
|
Chris@534
|
1036
|
Chris@1469
|
1037 QString text = model->getBinName(idx);
|
Chris@534
|
1038 if (text == "") text = QString("[%1]").arg(idx + 1);
|
Chris@534
|
1039
|
Chris@534
|
1040 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
|
Chris@534
|
1041 paint.fontMetrics().ascent() + 1;
|
Chris@534
|
1042
|
Chris@534
|
1043 paint.drawText(cw + 5, ty, text);
|
Chris@457
|
1044 }
|
Chris@25
|
1045 }
|
Chris@456
|
1046
|
Chris@456
|
1047 paint.restore();
|
Chris@25
|
1048 }
|
Chris@25
|
1049
|
Chris@1100
|
1050 Colour3DPlotRenderer *
|
Chris@1113
|
1051 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const
|
Chris@1100
|
1052 {
|
Chris@1469
|
1053 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
1054 if (!model) return nullptr;
|
Chris@1469
|
1055
|
Chris@1235
|
1056 int viewId = v->getId();
|
Chris@1235
|
1057
|
Chris@1235
|
1058 if (m_renderers.find(viewId) == m_renderers.end()) {
|
Chris@1100
|
1059
|
Chris@1100
|
1060 Colour3DPlotRenderer::Sources sources;
|
Chris@1100
|
1061 sources.verticalBinLayer = this;
|
Chris@1100
|
1062 sources.source = m_model;
|
Chris@1212
|
1063 sources.peakCaches.push_back(getPeakCache());
|
Chris@1100
|
1064
|
Chris@1100
|
1065 ColourScale::Parameters cparams;
|
Chris@1100
|
1066 cparams.colourMap = m_colourMap;
|
Chris@1362
|
1067 cparams.inverted = m_colourInverted;
|
Chris@1137
|
1068 cparams.scaleType = m_colourScale;
|
Chris@1100
|
1069 cparams.gain = m_gain;
|
Chris@1100
|
1070
|
Chris@1235
|
1071 double minValue = 0.0;
|
Chris@1235
|
1072 double maxValue = 1.0;
|
Chris@1235
|
1073
|
Chris@1235
|
1074 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
|
Chris@1235
|
1075 minValue = m_viewMags[viewId].getMin();
|
Chris@1235
|
1076 maxValue = m_viewMags[viewId].getMax();
|
Chris@1245
|
1077 } else if (m_normalization == ColumnNormalization::Hybrid) {
|
Chris@1245
|
1078 minValue = 0;
|
Chris@1469
|
1079 maxValue = log10(model->getMaximumLevel() + 1.0);
|
Chris@1235
|
1080 } else if (m_normalization == ColumnNormalization::None) {
|
Chris@1469
|
1081 minValue = model->getMinimumLevel();
|
Chris@1469
|
1082 maxValue = model->getMaximumLevel();
|
Chris@1131
|
1083 }
|
Chris@1131
|
1084
|
Chris@1244
|
1085 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is "
|
Chris@1362
|
1086 << minValue << " -> " << maxValue
|
Chris@1469
|
1087 << " (model min = " << model->getMinimumLevel()
|
Chris@1469
|
1088 << ", max = " << model->getMaximumLevel() << ")"
|
Chris@1362
|
1089 << endl;
|
Chris@1378
|
1090
|
Chris@1235
|
1091 if (maxValue <= minValue) {
|
Chris@1235
|
1092 maxValue = minValue + 0.1f;
|
Chris@1378
|
1093
|
Chris@1378
|
1094 if (!(maxValue > minValue)) { // one of them must be NaN or Inf
|
Chris@1378
|
1095 SVCERR << "WARNING: Colour3DPlotLayer::getRenderer: resetting "
|
Chris@1378
|
1096 << "minValue and maxValue to zero and one" << endl;
|
Chris@1378
|
1097 minValue = 0.f;
|
Chris@1378
|
1098 maxValue = 1.f;
|
Chris@1378
|
1099 }
|
Chris@1131
|
1100 }
|
Chris@1235
|
1101
|
Chris@1247
|
1102 cparams.threshold = minValue;
|
Chris@1235
|
1103 cparams.minValue = minValue;
|
Chris@1235
|
1104 cparams.maxValue = maxValue;
|
Chris@1131
|
1105
|
Chris@1235
|
1106 m_lastRenderedMags[viewId] = MagnitudeRange(float(minValue),
|
Chris@1235
|
1107 float(maxValue));
|
Chris@1235
|
1108
|
Chris@1100
|
1109 Colour3DPlotRenderer::Parameters params;
|
Chris@1100
|
1110 params.colourScale = ColourScale(cparams);
|
Chris@1100
|
1111 params.normalization = m_normalization;
|
Chris@1100
|
1112 params.binScale = m_binScale;
|
Chris@1100
|
1113 params.alwaysOpaque = m_opaque;
|
Chris@1100
|
1114 params.invertVertical = m_invertVertical;
|
Chris@1100
|
1115 params.interpolate = m_smooth;
|
Chris@1100
|
1116
|
Chris@1235
|
1117 m_renderers[viewId] = new Colour3DPlotRenderer(sources, params);
|
Chris@1100
|
1118 }
|
Chris@1100
|
1119
|
Chris@1235
|
1120 return m_renderers[viewId];
|
Chris@1100
|
1121 }
|
Chris@1100
|
1122
|
Chris@197
|
1123 void
|
Chris@1107
|
1124 Colour3DPlotLayer::paintWithRenderer(LayerGeometryProvider *v,
|
Chris@1107
|
1125 QPainter &paint, QRect rect) const
|
Chris@1101
|
1126 {
|
Chris@1101
|
1127 Colour3DPlotRenderer *renderer = getRenderer(v);
|
Chris@1101
|
1128
|
Chris@1121
|
1129 Colour3DPlotRenderer::RenderResult result;
|
Chris@1123
|
1130 MagnitudeRange magRange;
|
Chris@1123
|
1131 int viewId = v->getId();
|
Chris@1123
|
1132
|
Chris@1235
|
1133 bool continuingPaint = !renderer->geometryChanged(v);
|
Chris@1235
|
1134
|
Chris@1235
|
1135 if (continuingPaint) {
|
Chris@1123
|
1136 magRange = m_viewMags[viewId];
|
Chris@1123
|
1137 }
|
Chris@1121
|
1138
|
Chris@1101
|
1139 if (m_synchronous) {
|
Chris@1121
|
1140
|
Chris@1121
|
1141 result = renderer->render(v, paint, rect);
|
Chris@1121
|
1142
|
Chris@1121
|
1143 } else {
|
Chris@1121
|
1144
|
Chris@1121
|
1145 result = renderer->renderTimeConstrained(v, paint, rect);
|
Chris@1121
|
1146
|
Chris@1121
|
1147 QRect uncached = renderer->getLargestUncachedRect(v);
|
Chris@1121
|
1148 if (uncached.width() > 0) {
|
Chris@1121
|
1149 v->updatePaintRect(uncached);
|
Chris@1121
|
1150 }
|
Chris@1101
|
1151 }
|
Chris@1121
|
1152
|
Chris@1123
|
1153 magRange.sample(result.range);
|
Chris@1101
|
1154
|
Chris@1123
|
1155 if (magRange.isSet()) {
|
Chris@1235
|
1156 if (m_viewMags[viewId] != magRange) {
|
Chris@1123
|
1157 m_viewMags[viewId] = magRange;
|
Chris@1235
|
1158 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
1159 SVDEBUG << "mag range in this view has changed: "
|
Chris@1412
|
1160 << magRange.getMin() << " -> "
|
Chris@1412
|
1161 << magRange.getMax() << endl;
|
Chris@1235
|
1162 #endif
|
Chris@1123
|
1163 }
|
Chris@1123
|
1164 }
|
Chris@1101
|
1165
|
Chris@1235
|
1166 if (!continuingPaint && m_normalizeVisibleArea &&
|
Chris@1235
|
1167 m_viewMags[viewId] != m_lastRenderedMags[viewId]) {
|
Chris@1235
|
1168 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
1169 SVDEBUG << "mag range has changed from last rendered range: re-rendering"
|
Chris@1235
|
1170 << endl;
|
Chris@1235
|
1171 #endif
|
Chris@1235
|
1172 delete m_renderers[viewId];
|
Chris@1235
|
1173 m_renderers.erase(viewId);
|
Chris@1235
|
1174 v->updatePaintRect(v->getPaintRect());
|
Chris@1235
|
1175 }
|
Chris@1101
|
1176 }
|
Chris@1101
|
1177
|
Chris@1101
|
1178 void
|
Chris@916
|
1179 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@0
|
1180 {
|
Chris@1469
|
1181 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@514
|
1182 /*
|
Chris@1469
|
1183 if (model) {
|
Chris@1469
|
1184 SVDEBUG << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << model->shouldUseLogValueScale() << endl;
|
Chris@443
|
1185 }
|
Chris@514
|
1186 */
|
Chris@466
|
1187 Profiler profiler("Colour3DPlotLayer::paint");
|
Chris@125
|
1188 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
1189 SVDEBUG << "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
|
1190 #endif
|
Chris@0
|
1191
|
Chris@0
|
1192 int completion = 0;
|
Chris@1469
|
1193 if (!model || !model->isOK() || !model->isReady(&completion)) {
|
Chris@1266
|
1194 if (completion > 0) {
|
Chris@1266
|
1195 paint.fillRect(0, 10, v->getPaintWidth() * completion / 100,
|
Chris@1266
|
1196 10, QColor(120, 120, 120));
|
Chris@1266
|
1197 }
|
Chris@1266
|
1198 return;
|
Chris@0
|
1199 }
|
Chris@0
|
1200
|
Chris@1469
|
1201 if (model->getWidth() == 0) {
|
Chris@1053
|
1202 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1412
|
1203 SVDEBUG << "Colour3DPlotLayer::paint(): model width == 0, "
|
Chris@1053
|
1204 << "nothing to paint (yet)" << endl;
|
Chris@1053
|
1205 #endif
|
Chris@1053
|
1206 return;
|
Chris@1053
|
1207 }
|
Chris@1101
|
1208
|
Chris@1107
|
1209 paintWithRenderer(v, paint, rect);
|
Chris@1107
|
1210 }
|
Chris@1107
|
1211
|
Chris@28
|
1212 bool
|
Chris@916
|
1213 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
|
Chris@1266
|
1214 int &resolution,
|
Chris@1266
|
1215 SnapType snap) const
|
Chris@24
|
1216 {
|
Chris@1469
|
1217 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
|
Chris@1469
|
1218 if (!model) {
|
Chris@1266
|
1219 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@24
|
1220 }
|
Chris@24
|
1221
|
Chris@1469
|
1222 resolution = model->getResolution();
|
Chris@904
|
1223 sv_frame_t left = (frame / resolution) * resolution;
|
Chris@904
|
1224 sv_frame_t right = left + resolution;
|
Chris@28
|
1225
|
Chris@28
|
1226 switch (snap) {
|
Chris@28
|
1227 case SnapLeft: frame = left; break;
|
Chris@28
|
1228 case SnapRight: frame = right; break;
|
Chris@28
|
1229 case SnapNeighbouring:
|
Chris@1266
|
1230 if (frame - left > right - frame) frame = right;
|
Chris@1266
|
1231 else frame = left;
|
Chris@1266
|
1232 break;
|
Chris@28
|
1233 }
|
Chris@24
|
1234
|
Chris@28
|
1235 return true;
|
Chris@24
|
1236 }
|
Chris@24
|
1237
|
Chris@316
|
1238 void
|
Chris@316
|
1239 Colour3DPlotLayer::toXml(QTextStream &stream,
|
Chris@316
|
1240 QString indent, QString extraAttributes) const
|
Chris@197
|
1241 {
|
Chris@316
|
1242 QString s = QString("scale=\"%1\" "
|
Chris@1362
|
1243 "minY=\"%2\" "
|
Chris@1362
|
1244 "maxY=\"%3\" "
|
Chris@1362
|
1245 "invertVertical=\"%4\" "
|
Chris@1362
|
1246 "opaque=\"%5\" %6")
|
Chris@1266
|
1247 .arg(convertFromColourScale(m_colourScale))
|
Chris@445
|
1248 .arg(m_miny)
|
Chris@465
|
1249 .arg(m_maxy)
|
Chris@465
|
1250 .arg(m_invertVertical ? "true" : "false")
|
Chris@534
|
1251 .arg(m_opaque ? "true" : "false")
|
Chris@536
|
1252 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
|
Chris@1103
|
1253 .arg(int(m_binScale))
|
Chris@536
|
1254 .arg(m_smooth ? "true" : "false")
|
Chris@536
|
1255 .arg(m_gain));
|
Chris@1362
|
1256
|
Chris@1362
|
1257 // New-style colour map attribute, by string id rather than by
|
Chris@1362
|
1258 // number
|
Chris@1362
|
1259
|
Chris@1362
|
1260 s += QString("colourMap=\"%1\" ")
|
Chris@1362
|
1261 .arg(ColourMapper::getColourMapId(m_colourMap));
|
Chris@1362
|
1262
|
Chris@1362
|
1263 // Old-style colour map attribute
|
Chris@1362
|
1264
|
Chris@1362
|
1265 s += QString("colourScheme=\"%1\" ")
|
Chris@1362
|
1266 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
|
Chris@535
|
1267
|
Chris@1099
|
1268 // New-style normalization attributes, allowing for more types of
|
Chris@1099
|
1269 // normalization in future: write out the column normalization
|
Chris@1099
|
1270 // type separately, and then whether we are normalizing visible
|
Chris@1099
|
1271 // area as well afterwards
|
Chris@1099
|
1272
|
Chris@1099
|
1273 s += QString("columnNormalization=\"%1\" ")
|
Chris@1245
|
1274 .arg(m_normalization == ColumnNormalization::Range01 ? "peak" :
|
Chris@1104
|
1275 m_normalization == ColumnNormalization::Hybrid ? "hybrid" : "none");
|
Chris@1099
|
1276
|
Chris@1099
|
1277 // Old-style normalization attribute, for backward compatibility
|
Chris@1099
|
1278
|
Chris@1099
|
1279 s += QString("normalizeColumns=\"%1\" ")
|
Chris@1266
|
1280 .arg(m_normalization == ColumnNormalization::Range01 ? "true" : "false");
|
Chris@1099
|
1281
|
Chris@1099
|
1282 // And this applies to both old- and new-style attributes
|
Chris@1099
|
1283
|
Chris@1099
|
1284 s += QString("normalizeVisibleArea=\"%1\" ")
|
Chris@1104
|
1285 .arg(m_normalizeVisibleArea ? "true" : "false");
|
Chris@1099
|
1286
|
Chris@316
|
1287 Layer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@197
|
1288 }
|
Chris@197
|
1289
|
Chris@197
|
1290 void
|
Chris@197
|
1291 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@197
|
1292 {
|
Chris@445
|
1293 bool ok = false, alsoOk = false;
|
Chris@197
|
1294
|
Chris@1105
|
1295 ColourScaleType colourScale = convertToColourScale
|
Chris@1252
|
1296 (attributes.value("scale").toInt(&ok));
|
Chris@1099
|
1297 if (ok) setColourScale(colourScale);
|
Chris@197
|
1298
|
Chris@1362
|
1299 QString colourMapId = attributes.value("colourMap");
|
Chris@1362
|
1300 int colourMap = ColourMapper::getColourMapById(colourMapId);
|
Chris@1362
|
1301 if (colourMap >= 0) {
|
Chris@1362
|
1302 setColourMap(colourMap);
|
Chris@1362
|
1303 } else {
|
Chris@1362
|
1304 colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@1362
|
1305 if (ok && colourMap < ColourMapper::getColourMapCount()) {
|
Chris@1362
|
1306 setColourMap(colourMap);
|
Chris@1362
|
1307 }
|
Chris@1362
|
1308 }
|
Chris@197
|
1309
|
Chris@1103
|
1310 BinScale binScale = (BinScale)
|
Chris@1266
|
1311 attributes.value("binScale").toInt(&ok);
|
Chris@1099
|
1312 if (ok) setBinScale(binScale);
|
Chris@445
|
1313
|
Chris@465
|
1314 bool invertVertical =
|
Chris@465
|
1315 (attributes.value("invertVertical").trimmed() == "true");
|
Chris@465
|
1316 setInvertVertical(invertVertical);
|
Chris@465
|
1317
|
Chris@465
|
1318 bool opaque =
|
Chris@465
|
1319 (attributes.value("opaque").trimmed() == "true");
|
Chris@535
|
1320 setOpaque(opaque);
|
Chris@535
|
1321
|
Chris@535
|
1322 bool smooth =
|
Chris@535
|
1323 (attributes.value("smooth").trimmed() == "true");
|
Chris@535
|
1324 setSmooth(smooth);
|
Chris@465
|
1325
|
Chris@536
|
1326 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@536
|
1327 if (ok) setGain(gain);
|
Chris@536
|
1328
|
Chris@445
|
1329 float min = attributes.value("minY").toFloat(&ok);
|
Chris@445
|
1330 float max = attributes.value("maxY").toFloat(&alsoOk);
|
Chris@445
|
1331 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@1099
|
1332
|
Chris@1099
|
1333 bool haveNewStyleNormalization = false;
|
Chris@1099
|
1334
|
Chris@1099
|
1335 QString columnNormalization = attributes.value("columnNormalization");
|
Chris@1099
|
1336
|
Chris@1099
|
1337 if (columnNormalization != "") {
|
Chris@1099
|
1338
|
Chris@1099
|
1339 haveNewStyleNormalization = true;
|
Chris@1099
|
1340
|
Chris@1099
|
1341 if (columnNormalization == "peak") {
|
Chris@1245
|
1342 setNormalization(ColumnNormalization::Range01);
|
Chris@1099
|
1343 } else if (columnNormalization == "hybrid") {
|
Chris@1104
|
1344 setNormalization(ColumnNormalization::Hybrid);
|
Chris@1099
|
1345 } else if (columnNormalization == "none") {
|
Chris@1104
|
1346 setNormalization(ColumnNormalization::None);
|
Chris@1099
|
1347 } else {
|
Chris@1412
|
1348 SVCERR << "NOTE: Unknown or unsupported columnNormalization attribute \""
|
Chris@1412
|
1349 << columnNormalization << "\"" << endl;
|
Chris@1099
|
1350 }
|
Chris@1099
|
1351 }
|
Chris@1099
|
1352
|
Chris@1099
|
1353 if (!haveNewStyleNormalization) {
|
Chris@1099
|
1354
|
Chris@1104
|
1355 setNormalization(ColumnNormalization::None);
|
Chris@1104
|
1356
|
Chris@1099
|
1357 bool normalizeColumns =
|
Chris@1099
|
1358 (attributes.value("normalizeColumns").trimmed() == "true");
|
Chris@1099
|
1359 if (normalizeColumns) {
|
Chris@1245
|
1360 setNormalization(ColumnNormalization::Range01);
|
Chris@1099
|
1361 }
|
Chris@1099
|
1362
|
Chris@1099
|
1363 bool normalizeHybrid =
|
Chris@1099
|
1364 (attributes.value("normalizeHybrid").trimmed() == "true");
|
Chris@1099
|
1365 if (normalizeHybrid) {
|
Chris@1104
|
1366 setNormalization(ColumnNormalization::Hybrid);
|
Chris@1099
|
1367 }
|
Chris@1099
|
1368 }
|
Chris@1099
|
1369
|
Chris@1099
|
1370 bool normalizeVisibleArea =
|
Chris@1099
|
1371 (attributes.value("normalizeVisibleArea").trimmed() == "true");
|
Chris@1104
|
1372 setNormalizeVisibleArea(normalizeVisibleArea);
|
Chris@1099
|
1373
|
Chris@1099
|
1374 //!!! todo: check save/reload scaling, compare with
|
Chris@1099
|
1375 //!!! SpectrogramLayer, compare with prior SV versions, compare
|
Chris@1099
|
1376 //!!! with Tony v1 and v2 and their save files
|
Chris@197
|
1377 }
|
Chris@197
|
1378
|