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@128
|
18 #include "view/View.h"
|
Chris@0
|
19 #include "base/Profiler.h"
|
Chris@197
|
20 #include "base/LogRange.h"
|
Chris@444
|
21 #include "base/RangeMapper.h"
|
Chris@376
|
22 #include "ColourMapper.h"
|
Chris@0
|
23
|
Chris@0
|
24 #include <QPainter>
|
Chris@0
|
25 #include <QImage>
|
Chris@0
|
26 #include <QRect>
|
Chris@316
|
27 #include <QTextStream>
|
Chris@0
|
28
|
Chris@0
|
29 #include <iostream>
|
Chris@0
|
30
|
Chris@0
|
31 #include <cassert>
|
Chris@0
|
32
|
Chris@545
|
33 #ifndef __GNUC__
|
Chris@545
|
34 #include <alloca.h>
|
Chris@545
|
35 #endif
|
Chris@545
|
36
|
Chris@903
|
37 using std::vector;
|
Chris@903
|
38
|
Chris@353
|
39 //#define DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 1
|
Chris@125
|
40
|
Chris@0
|
41
|
Chris@44
|
42 Colour3DPlotLayer::Colour3DPlotLayer() :
|
Chris@0
|
43 m_model(0),
|
Chris@159
|
44 m_cache(0),
|
Chris@469
|
45 m_peaksCache(0),
|
Chris@461
|
46 m_cacheValidStart(0),
|
Chris@461
|
47 m_cacheValidEnd(0),
|
Chris@197
|
48 m_colourScale(LinearScale),
|
Chris@461
|
49 m_colourScaleSet(false),
|
Chris@197
|
50 m_colourMap(0),
|
Chris@534
|
51 m_gain(1.0),
|
Chris@531
|
52 m_binScale(LinearBinScale),
|
Chris@197
|
53 m_normalizeColumns(false),
|
Chris@357
|
54 m_normalizeVisibleArea(false),
|
Chris@719
|
55 m_normalizeHybrid(false),
|
Chris@444
|
56 m_invertVertical(false),
|
Chris@465
|
57 m_opaque(false),
|
Chris@535
|
58 m_smooth(false),
|
Chris@805
|
59 m_peakResolution(256),
|
Chris@444
|
60 m_miny(0),
|
Chris@444
|
61 m_maxy(0)
|
Chris@0
|
62 {
|
Chris@44
|
63
|
Chris@0
|
64 }
|
Chris@0
|
65
|
Chris@0
|
66 Colour3DPlotLayer::~Colour3DPlotLayer()
|
Chris@0
|
67 {
|
Chris@461
|
68 delete m_cache;
|
Chris@469
|
69 delete m_peaksCache;
|
Chris@0
|
70 }
|
Chris@0
|
71
|
Chris@0
|
72 void
|
Chris@0
|
73 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model)
|
Chris@0
|
74 {
|
Chris@193
|
75 if (m_model == model) return;
|
Chris@193
|
76 const DenseThreeDimensionalModel *oldModel = m_model;
|
Chris@0
|
77 m_model = model;
|
Chris@0
|
78 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
79
|
Chris@320
|
80 connectSignals(m_model);
|
Chris@0
|
81
|
Chris@461
|
82 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
|
Chris@908
|
83 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
|
Chris@908
|
84 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
|
Chris@0
|
85
|
Chris@474
|
86 m_peakResolution = 256;
|
Chris@474
|
87 if (model->getResolution() > 512) {
|
Chris@474
|
88 m_peakResolution = 16;
|
Chris@474
|
89 } else if (model->getResolution() > 128) {
|
Chris@474
|
90 m_peakResolution = 64;
|
Chris@474
|
91 } else if (model->getResolution() > 2) {
|
Chris@474
|
92 m_peakResolution = 128;
|
Chris@474
|
93 }
|
Chris@474
|
94 cacheInvalid();
|
Chris@474
|
95
|
Chris@0
|
96 emit modelReplaced();
|
Chris@193
|
97 emit sliceableModelReplaced(oldModel, model);
|
Chris@0
|
98 }
|
Chris@0
|
99
|
Chris@0
|
100 void
|
Chris@0
|
101 Colour3DPlotLayer::cacheInvalid()
|
Chris@0
|
102 {
|
Chris@469
|
103 delete m_cache;
|
Chris@469
|
104 delete m_peaksCache;
|
Chris@0
|
105 m_cache = 0;
|
Chris@469
|
106 m_peaksCache = 0;
|
Chris@461
|
107 m_cacheValidStart = 0;
|
Chris@461
|
108 m_cacheValidEnd = 0;
|
Chris@0
|
109 }
|
Chris@0
|
110
|
Chris@0
|
111 void
|
Chris@908
|
112 Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@0
|
113 {
|
Chris@843
|
114 if (!m_cache || !m_model) return;
|
Chris@461
|
115
|
Chris@805
|
116 int modelResolution = m_model->getResolution();
|
Chris@908
|
117 int start = int(startFrame / modelResolution);
|
Chris@908
|
118 int end = int(endFrame / modelResolution + 1);
|
Chris@461
|
119 if (m_cacheValidStart < end) m_cacheValidStart = end;
|
Chris@461
|
120 if (m_cacheValidEnd > start) m_cacheValidEnd = start;
|
Chris@461
|
121 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
|
Chris@461
|
122 }
|
Chris@461
|
123
|
Chris@461
|
124 void
|
Chris@461
|
125 Colour3DPlotLayer::modelChanged()
|
Chris@461
|
126 {
|
Chris@461
|
127 if (!m_colourScaleSet && m_colourScale == LinearScale) {
|
Chris@461
|
128 if (m_model) {
|
Chris@461
|
129 if (m_model->shouldUseLogValueScale()) {
|
Chris@461
|
130 setColourScale(LogScale);
|
Chris@461
|
131 } else {
|
Chris@461
|
132 m_colourScaleSet = true;
|
Chris@461
|
133 }
|
Chris@461
|
134 }
|
Chris@461
|
135 }
|
Chris@0
|
136 cacheInvalid();
|
Chris@0
|
137 }
|
Chris@0
|
138
|
Chris@461
|
139 void
|
Chris@908
|
140 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
|
Chris@461
|
141 {
|
Chris@461
|
142 if (!m_colourScaleSet && m_colourScale == LinearScale) {
|
Chris@461
|
143 if (m_model && m_model->getWidth() > 50) {
|
Chris@461
|
144 if (m_model->shouldUseLogValueScale()) {
|
Chris@461
|
145 setColourScale(LogScale);
|
Chris@461
|
146 } else {
|
Chris@461
|
147 m_colourScaleSet = true;
|
Chris@461
|
148 }
|
Chris@461
|
149 }
|
Chris@461
|
150 }
|
Chris@461
|
151 cacheInvalid(startFrame, endFrame);
|
Chris@461
|
152 }
|
Chris@461
|
153
|
Chris@159
|
154 Layer::PropertyList
|
Chris@159
|
155 Colour3DPlotLayer::getProperties() const
|
Chris@159
|
156 {
|
Chris@159
|
157 PropertyList list;
|
Chris@197
|
158 list.push_back("Colour");
|
Chris@159
|
159 list.push_back("Colour Scale");
|
Chris@197
|
160 list.push_back("Normalize Columns");
|
Chris@197
|
161 list.push_back("Normalize Visible Area");
|
Chris@534
|
162 list.push_back("Gain");
|
Chris@531
|
163 list.push_back("Bin Scale");
|
Chris@357
|
164 list.push_back("Invert Vertical Scale");
|
Chris@465
|
165 list.push_back("Opaque");
|
Chris@535
|
166 list.push_back("Smooth");
|
Chris@159
|
167 return list;
|
Chris@159
|
168 }
|
Chris@159
|
169
|
Chris@159
|
170 QString
|
Chris@159
|
171 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@159
|
172 {
|
Chris@197
|
173 if (name == "Colour") return tr("Colour");
|
Chris@197
|
174 if (name == "Colour Scale") return tr("Scale");
|
Chris@197
|
175 if (name == "Normalize Columns") return tr("Normalize Columns");
|
Chris@197
|
176 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
|
Chris@357
|
177 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
|
Chris@534
|
178 if (name == "Gain") return tr("Gain");
|
Chris@465
|
179 if (name == "Opaque") return tr("Always Opaque");
|
Chris@535
|
180 if (name == "Smooth") return tr("Smooth");
|
Chris@531
|
181 if (name == "Bin Scale") return tr("Bin Scale");
|
Chris@159
|
182 return "";
|
Chris@159
|
183 }
|
Chris@159
|
184
|
Chris@346
|
185 QString
|
Chris@346
|
186 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@346
|
187 {
|
Chris@346
|
188 if (name == "Normalize Columns") return "normalise-columns";
|
Chris@346
|
189 if (name == "Normalize Visible Area") return "normalise";
|
Chris@357
|
190 if (name == "Invert Vertical Scale") return "invert-vertical";
|
Chris@465
|
191 if (name == "Opaque") return "opaque";
|
Chris@535
|
192 if (name == "Smooth") return "smooth";
|
Chris@346
|
193 return "";
|
Chris@346
|
194 }
|
Chris@346
|
195
|
Chris@159
|
196 Layer::PropertyType
|
Chris@159
|
197 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
|
Chris@159
|
198 {
|
Chris@534
|
199 if (name == "Gain") return RangeProperty;
|
Chris@197
|
200 if (name == "Normalize Columns") return ToggleProperty;
|
Chris@197
|
201 if (name == "Normalize Visible Area") return ToggleProperty;
|
Chris@357
|
202 if (name == "Invert Vertical Scale") return ToggleProperty;
|
Chris@465
|
203 if (name == "Opaque") return ToggleProperty;
|
Chris@535
|
204 if (name == "Smooth") return ToggleProperty;
|
Chris@159
|
205 return ValueProperty;
|
Chris@159
|
206 }
|
Chris@159
|
207
|
Chris@159
|
208 QString
|
Chris@159
|
209 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@159
|
210 {
|
Chris@197
|
211 if (name == "Normalize Columns" ||
|
Chris@197
|
212 name == "Normalize Visible Area" ||
|
Chris@534
|
213 name == "Colour Scale" ||
|
Chris@534
|
214 name == "Gain") return tr("Scale");
|
Chris@531
|
215 if (name == "Bin Scale" ||
|
Chris@531
|
216 name == "Invert Vertical Scale") return tr("Bins");
|
Chris@465
|
217 if (name == "Opaque" ||
|
Chris@535
|
218 name == "Smooth" ||
|
Chris@465
|
219 name == "Colour") return tr("Colour");
|
Chris@159
|
220 return QString();
|
Chris@159
|
221 }
|
Chris@159
|
222
|
Chris@159
|
223 int
|
Chris@159
|
224 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
225 int *min, int *max, int *deflt) const
|
Chris@159
|
226 {
|
Chris@216
|
227 int val = 0;
|
Chris@159
|
228
|
Chris@216
|
229 int garbage0, garbage1, garbage2;
|
Chris@159
|
230 if (!min) min = &garbage0;
|
Chris@159
|
231 if (!max) max = &garbage1;
|
Chris@216
|
232 if (!deflt) deflt = &garbage2;
|
Chris@159
|
233
|
Chris@534
|
234 if (name == "Gain") {
|
Chris@534
|
235
|
Chris@534
|
236 *min = -50;
|
Chris@534
|
237 *max = 50;
|
Chris@534
|
238
|
Chris@902
|
239 *deflt = int(lrint(log10(1.0) * 20.0));
|
Chris@534
|
240 if (*deflt < *min) *deflt = *min;
|
Chris@534
|
241 if (*deflt > *max) *deflt = *max;
|
Chris@534
|
242
|
Chris@902
|
243 val = int(lrint(log10(m_gain) * 20.0));
|
Chris@534
|
244 if (val < *min) val = *min;
|
Chris@534
|
245 if (val > *max) val = *max;
|
Chris@534
|
246
|
Chris@534
|
247 } else if (name == "Colour Scale") {
|
Chris@159
|
248
|
Chris@159
|
249 *min = 0;
|
Chris@509
|
250 *max = 3;
|
Chris@216
|
251 *deflt = (int)LinearScale;
|
Chris@159
|
252
|
Chris@216
|
253 val = (int)m_colourScale;
|
Chris@159
|
254
|
Chris@197
|
255 } else if (name == "Colour") {
|
Chris@197
|
256
|
Chris@197
|
257 *min = 0;
|
Chris@197
|
258 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@216
|
259 *deflt = 0;
|
Chris@197
|
260
|
Chris@216
|
261 val = m_colourMap;
|
Chris@197
|
262
|
Chris@197
|
263 } else if (name == "Normalize Columns") {
|
Chris@197
|
264
|
Chris@216
|
265 *deflt = 0;
|
Chris@216
|
266 val = (m_normalizeColumns ? 1 : 0);
|
Chris@197
|
267
|
Chris@197
|
268 } else if (name == "Normalize Visible Area") {
|
Chris@197
|
269
|
Chris@216
|
270 *deflt = 0;
|
Chris@216
|
271 val = (m_normalizeVisibleArea ? 1 : 0);
|
Chris@197
|
272
|
Chris@357
|
273 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
274
|
Chris@357
|
275 *deflt = 0;
|
Chris@357
|
276 val = (m_invertVertical ? 1 : 0);
|
Chris@357
|
277
|
Chris@531
|
278 } else if (name == "Bin Scale") {
|
Chris@531
|
279
|
Chris@531
|
280 *min = 0;
|
Chris@531
|
281 *max = 1;
|
Chris@531
|
282 *deflt = int(LinearBinScale);
|
Chris@531
|
283 val = (int)m_binScale;
|
Chris@531
|
284
|
Chris@465
|
285 } else if (name == "Opaque") {
|
Chris@465
|
286
|
Chris@465
|
287 *deflt = 0;
|
Chris@465
|
288 val = (m_opaque ? 1 : 0);
|
Chris@465
|
289
|
Chris@535
|
290 } else if (name == "Smooth") {
|
Chris@535
|
291
|
Chris@535
|
292 *deflt = 0;
|
Chris@535
|
293 val = (m_smooth ? 1 : 0);
|
Chris@535
|
294
|
Chris@159
|
295 } else {
|
Chris@216
|
296 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@159
|
297 }
|
Chris@159
|
298
|
Chris@216
|
299 return val;
|
Chris@159
|
300 }
|
Chris@159
|
301
|
Chris@159
|
302 QString
|
Chris@159
|
303 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@159
|
304 int value) const
|
Chris@159
|
305 {
|
Chris@197
|
306 if (name == "Colour") {
|
Chris@197
|
307 return ColourMapper::getColourMapName(value);
|
Chris@197
|
308 }
|
Chris@159
|
309 if (name == "Colour Scale") {
|
Chris@159
|
310 switch (value) {
|
Chris@159
|
311 default:
|
Chris@198
|
312 case 0: return tr("Linear");
|
Chris@198
|
313 case 1: return tr("Log");
|
Chris@198
|
314 case 2: return tr("+/-1");
|
Chris@509
|
315 case 3: return tr("Absolute");
|
Chris@159
|
316 }
|
Chris@159
|
317 }
|
Chris@531
|
318 if (name == "Bin Scale") {
|
Chris@531
|
319 switch (value) {
|
Chris@531
|
320 default:
|
Chris@531
|
321 case 0: return tr("Linear");
|
Chris@531
|
322 case 1: return tr("Log");
|
Chris@531
|
323 }
|
Chris@531
|
324 }
|
Chris@159
|
325 return tr("<unknown>");
|
Chris@159
|
326 }
|
Chris@159
|
327
|
Chris@534
|
328 RangeMapper *
|
Chris@534
|
329 Colour3DPlotLayer::getNewPropertyRangeMapper(const PropertyName &name) const
|
Chris@534
|
330 {
|
Chris@534
|
331 if (name == "Gain") {
|
Chris@534
|
332 return new LinearRangeMapper(-50, 50, -25, 25, tr("dB"));
|
Chris@534
|
333 }
|
Chris@534
|
334 return 0;
|
Chris@534
|
335 }
|
Chris@534
|
336
|
Chris@159
|
337 void
|
Chris@159
|
338 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
|
Chris@159
|
339 {
|
Chris@534
|
340 if (name == "Gain") {
|
Chris@902
|
341 setGain(float(pow(10, value/20.0)));
|
Chris@534
|
342 } else if (name == "Colour Scale") {
|
Chris@159
|
343 switch (value) {
|
Chris@159
|
344 default:
|
Chris@159
|
345 case 0: setColourScale(LinearScale); break;
|
Chris@197
|
346 case 1: setColourScale(LogScale); break;
|
Chris@197
|
347 case 2: setColourScale(PlusMinusOneScale); break;
|
Chris@509
|
348 case 3: setColourScale(AbsoluteScale); break;
|
Chris@159
|
349 }
|
Chris@197
|
350 } else if (name == "Colour") {
|
Chris@197
|
351 setColourMap(value);
|
Chris@197
|
352 } else if (name == "Normalize Columns") {
|
Chris@197
|
353 setNormalizeColumns(value ? true : false);
|
Chris@197
|
354 } else if (name == "Normalize Visible Area") {
|
Chris@197
|
355 setNormalizeVisibleArea(value ? true : false);
|
Chris@357
|
356 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
357 setInvertVertical(value ? true : false);
|
Chris@465
|
358 } else if (name == "Opaque") {
|
Chris@465
|
359 setOpaque(value ? true : false);
|
Chris@535
|
360 } else if (name == "Smooth") {
|
Chris@535
|
361 setSmooth(value ? true : false);
|
Chris@531
|
362 } else if (name == "Bin Scale") {
|
Chris@531
|
363 switch (value) {
|
Chris@531
|
364 default:
|
Chris@531
|
365 case 0: setBinScale(LinearBinScale); break;
|
Chris@531
|
366 case 1: setBinScale(LogBinScale); break;
|
Chris@531
|
367 }
|
Chris@159
|
368 }
|
Chris@159
|
369 }
|
Chris@159
|
370
|
Chris@159
|
371 void
|
Chris@159
|
372 Colour3DPlotLayer::setColourScale(ColourScale scale)
|
Chris@159
|
373 {
|
Chris@159
|
374 if (m_colourScale == scale) return;
|
Chris@159
|
375 m_colourScale = scale;
|
Chris@461
|
376 m_colourScaleSet = true;
|
Chris@159
|
377 cacheInvalid();
|
Chris@159
|
378 emit layerParametersChanged();
|
Chris@159
|
379 }
|
Chris@159
|
380
|
Chris@197
|
381 void
|
Chris@197
|
382 Colour3DPlotLayer::setColourMap(int map)
|
Chris@197
|
383 {
|
Chris@197
|
384 if (m_colourMap == map) return;
|
Chris@197
|
385 m_colourMap = map;
|
Chris@197
|
386 cacheInvalid();
|
Chris@197
|
387 emit layerParametersChanged();
|
Chris@197
|
388 }
|
Chris@197
|
389
|
Chris@197
|
390 void
|
Chris@534
|
391 Colour3DPlotLayer::setGain(float gain)
|
Chris@534
|
392 {
|
Chris@534
|
393 if (m_gain == gain) return;
|
Chris@534
|
394 m_gain = gain;
|
Chris@534
|
395 cacheInvalid();
|
Chris@534
|
396 emit layerParametersChanged();
|
Chris@534
|
397 }
|
Chris@534
|
398
|
Chris@534
|
399 float
|
Chris@534
|
400 Colour3DPlotLayer::getGain() const
|
Chris@534
|
401 {
|
Chris@534
|
402 return m_gain;
|
Chris@534
|
403 }
|
Chris@534
|
404
|
Chris@534
|
405 void
|
Chris@531
|
406 Colour3DPlotLayer::setBinScale(BinScale binScale)
|
Chris@531
|
407 {
|
Chris@531
|
408 if (m_binScale == binScale) return;
|
Chris@531
|
409 m_binScale = binScale;
|
Chris@531
|
410 cacheInvalid();
|
Chris@531
|
411 emit layerParametersChanged();
|
Chris@531
|
412 }
|
Chris@531
|
413
|
Chris@531
|
414 Colour3DPlotLayer::BinScale
|
Chris@531
|
415 Colour3DPlotLayer::getBinScale() const
|
Chris@531
|
416 {
|
Chris@531
|
417 return m_binScale;
|
Chris@531
|
418 }
|
Chris@531
|
419
|
Chris@531
|
420 void
|
Chris@197
|
421 Colour3DPlotLayer::setNormalizeColumns(bool n)
|
Chris@197
|
422 {
|
Chris@197
|
423 if (m_normalizeColumns == n) return;
|
Chris@197
|
424 m_normalizeColumns = n;
|
Chris@197
|
425 cacheInvalid();
|
Chris@197
|
426 emit layerParametersChanged();
|
Chris@197
|
427 }
|
Chris@197
|
428
|
Chris@197
|
429 bool
|
Chris@197
|
430 Colour3DPlotLayer::getNormalizeColumns() const
|
Chris@197
|
431 {
|
Chris@197
|
432 return m_normalizeColumns;
|
Chris@197
|
433 }
|
Chris@197
|
434
|
Chris@197
|
435 void
|
Chris@719
|
436 Colour3DPlotLayer::setNormalizeHybrid(bool n)
|
Chris@719
|
437 {
|
Chris@719
|
438 if (m_normalizeHybrid == n) return;
|
Chris@719
|
439 m_normalizeHybrid = n;
|
Chris@719
|
440 cacheInvalid();
|
Chris@719
|
441 emit layerParametersChanged();
|
Chris@719
|
442 }
|
Chris@719
|
443
|
Chris@719
|
444 bool
|
Chris@719
|
445 Colour3DPlotLayer::getNormalizeHybrid() const
|
Chris@719
|
446 {
|
Chris@719
|
447 return m_normalizeHybrid;
|
Chris@719
|
448 }
|
Chris@719
|
449
|
Chris@719
|
450 void
|
Chris@197
|
451 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
|
Chris@197
|
452 {
|
Chris@197
|
453 if (m_normalizeVisibleArea == n) return;
|
Chris@197
|
454 m_normalizeVisibleArea = n;
|
Chris@197
|
455 cacheInvalid();
|
Chris@197
|
456 emit layerParametersChanged();
|
Chris@197
|
457 }
|
Chris@197
|
458
|
Chris@197
|
459 bool
|
Chris@197
|
460 Colour3DPlotLayer::getNormalizeVisibleArea() const
|
Chris@197
|
461 {
|
Chris@197
|
462 return m_normalizeVisibleArea;
|
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@812
|
535 if (m_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@532
|
655 if (m_binScale == 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@903
|
665 int
|
Chris@916
|
666 Colour3DPlotLayer::getIYForBin(LayerGeometryProvider *v, int bin) const
|
Chris@903
|
667 {
|
Chris@904
|
668 return int(round(getYForBin(v, bin)));
|
Chris@903
|
669 }
|
Chris@903
|
670
|
Chris@904
|
671 double
|
Chris@916
|
672 Colour3DPlotLayer::getBinForY(LayerGeometryProvider *v, double y) const
|
Chris@532
|
673 {
|
Chris@904
|
674 double bin = y;
|
Chris@532
|
675 if (!m_model) return bin;
|
Chris@904
|
676 double mn = 0, mx = m_model->getHeight();
|
Chris@532
|
677 getDisplayExtents(mn, mx);
|
Chris@916
|
678 double h = v->getPaintHeight();
|
Chris@532
|
679 if (m_binScale == LinearBinScale) {
|
Chris@532
|
680 bin = mn + ((h - y) * (mx - mn)) / h;
|
Chris@532
|
681 } else {
|
Chris@904
|
682 double logmin = mn + 1, logmax = mx + 1;
|
Chris@532
|
683 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
684 bin = LogRange::unmap(logmin + ((h - y) * (logmax - logmin)) / h) - 1;
|
Chris@532
|
685 }
|
Chris@532
|
686 return bin;
|
Chris@532
|
687 }
|
Chris@532
|
688
|
Chris@903
|
689 int
|
Chris@916
|
690 Colour3DPlotLayer::getIBinForY(LayerGeometryProvider *v, int y) const
|
Chris@903
|
691 {
|
Chris@904
|
692 return int(floor(getBinForY(v, y)));
|
Chris@903
|
693 }
|
Chris@903
|
694
|
Chris@25
|
695 QString
|
Chris@916
|
696 Colour3DPlotLayer::getFeatureDescription(LayerGeometryProvider *v, QPoint &pos) const
|
Chris@25
|
697 {
|
Chris@25
|
698 if (!m_model) return "";
|
Chris@25
|
699
|
Chris@25
|
700 int x = pos.x();
|
Chris@25
|
701 int y = pos.y();
|
Chris@25
|
702
|
Chris@902
|
703 sv_frame_t modelStart = m_model->getStartFrame();
|
Chris@805
|
704 int modelResolution = m_model->getResolution();
|
Chris@25
|
705
|
Chris@902
|
706 double srRatio =
|
Chris@902
|
707 v->getViewManager()->getMainModelSampleRate() /
|
Chris@902
|
708 m_model->getSampleRate();
|
Chris@159
|
709
|
Chris@902
|
710 int sx0 = int((double(v->getFrameForX(x)) / srRatio - double(modelStart)) /
|
Chris@812
|
711 modelResolution);
|
Chris@25
|
712
|
Chris@160
|
713 int f0 = sx0 * modelResolution;
|
Chris@160
|
714 int f1 = f0 + modelResolution;
|
Chris@160
|
715
|
Chris@447
|
716 int sh = m_model->getHeight();
|
Chris@447
|
717
|
Chris@447
|
718 int symin = m_miny;
|
Chris@447
|
719 int symax = m_maxy;
|
Chris@447
|
720 if (symax <= symin) {
|
Chris@447
|
721 symin = 0;
|
Chris@447
|
722 symax = sh;
|
Chris@447
|
723 }
|
Chris@447
|
724 if (symin < 0) symin = 0;
|
Chris@447
|
725 if (symax > sh) symax = sh;
|
Chris@447
|
726
|
Chris@916
|
727 // double binHeight = double(v->getPaintHeight()) / (symax - symin);
|
Chris@916
|
728 // int sy = int((v->getPaintHeight() - y) / binHeight) + symin;
|
Chris@534
|
729
|
Chris@903
|
730 int sy = getIBinForY(v, y);
|
Chris@25
|
731
|
Chris@812
|
732 if (sy < 0 || sy >= m_model->getHeight()) {
|
Chris@812
|
733 return "";
|
Chris@812
|
734 }
|
Chris@812
|
735
|
Chris@357
|
736 if (m_invertVertical) sy = m_model->getHeight() - sy - 1;
|
Chris@357
|
737
|
Chris@160
|
738 float value = m_model->getValueAt(sx0, sy);
|
Chris@159
|
739
|
Chris@682
|
740 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl;
|
Chris@25
|
741
|
Chris@25
|
742 QString binName = m_model->getBinName(sy);
|
Chris@25
|
743 if (binName == "") binName = QString("[%1]").arg(sy + 1);
|
Chris@25
|
744 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
|
Chris@25
|
745
|
Chris@25
|
746 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
|
Chris@160
|
747 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
|
Chris@25
|
748 .toText(true).c_str())
|
Chris@160
|
749 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
|
Chris@25
|
750 .toText(true).c_str())
|
Chris@25
|
751 .arg(binName)
|
Chris@25
|
752 .arg(value);
|
Chris@25
|
753
|
Chris@25
|
754 return text;
|
Chris@25
|
755 }
|
Chris@25
|
756
|
Chris@25
|
757 int
|
Chris@969
|
758 Colour3DPlotLayer::getColourScaleWidth(QPainter &p) const
|
Chris@159
|
759 {
|
Chris@969
|
760 // Font is rotated
|
Chris@969
|
761 int cw = p.fontMetrics().height();
|
Chris@159
|
762 return cw;
|
Chris@159
|
763 }
|
Chris@159
|
764
|
Chris@159
|
765 int
|
Chris@916
|
766 Colour3DPlotLayer::getVerticalScaleWidth(LayerGeometryProvider *, bool, QPainter &paint) const
|
Chris@25
|
767 {
|
Chris@25
|
768 if (!m_model) return 0;
|
Chris@25
|
769
|
Chris@160
|
770 QString sampleText = QString("[%1]").arg(m_model->getHeight());
|
Chris@25
|
771 int tw = paint.fontMetrics().width(sampleText);
|
Chris@98
|
772 bool another = false;
|
Chris@25
|
773
|
Chris@805
|
774 for (int i = 0; i < m_model->getHeight(); ++i) {
|
Chris@25
|
775 if (m_model->getBinName(i).length() > sampleText.length()) {
|
Chris@25
|
776 sampleText = m_model->getBinName(i);
|
Chris@98
|
777 another = true;
|
Chris@25
|
778 }
|
Chris@25
|
779 }
|
Chris@98
|
780 if (another) {
|
Chris@25
|
781 tw = std::max(tw, paint.fontMetrics().width(sampleText));
|
Chris@25
|
782 }
|
Chris@25
|
783
|
Chris@159
|
784 return tw + 13 + getColourScaleWidth(paint);
|
Chris@25
|
785 }
|
Chris@25
|
786
|
Chris@25
|
787 void
|
Chris@916
|
788 Colour3DPlotLayer::paintVerticalScale(LayerGeometryProvider *v, bool, QPainter &paint, QRect rect) const
|
Chris@25
|
789 {
|
Chris@25
|
790 if (!m_model) return;
|
Chris@25
|
791
|
Chris@25
|
792 int h = rect.height(), w = rect.width();
|
Chris@25
|
793
|
Chris@159
|
794 int cw = getColourScaleWidth(paint);
|
Chris@159
|
795
|
Chris@159
|
796 int ch = h - 20;
|
Chris@159
|
797 if (ch > 20 && m_cache) {
|
Chris@159
|
798
|
Chris@904
|
799 double min = m_model->getMinimumLevel();
|
Chris@904
|
800 double max = m_model->getMaximumLevel();
|
Chris@447
|
801
|
Chris@904
|
802 double mmin = min;
|
Chris@904
|
803 double mmax = max;
|
Chris@447
|
804
|
Chris@447
|
805 if (m_colourScale == LogScale) {
|
Chris@447
|
806 LogRange::mapRange(mmin, mmax);
|
Chris@447
|
807 } else if (m_colourScale == PlusMinusOneScale) {
|
Chris@447
|
808 mmin = -1.f;
|
Chris@447
|
809 mmax = 1.f;
|
Chris@509
|
810 } else if (m_colourScale == AbsoluteScale) {
|
Chris@509
|
811 if (mmin < 0) {
|
Chris@904
|
812 if (fabs(mmin) > fabs(mmax)) mmax = fabs(mmin);
|
Chris@904
|
813 else mmax = fabs(mmax);
|
Chris@509
|
814 mmin = 0;
|
Chris@509
|
815 } else {
|
Chris@904
|
816 mmin = fabs(mmin);
|
Chris@904
|
817 mmax = fabs(mmax);
|
Chris@509
|
818 }
|
Chris@447
|
819 }
|
Chris@447
|
820
|
Chris@902
|
821 if (max == min) max = min + 1.f;
|
Chris@902
|
822 if (mmax == mmin) mmax = mmin + 1.f;
|
Chris@447
|
823
|
Chris@287
|
824 paint.setPen(v->getForeground());
|
Chris@447
|
825 paint.drawRect(4, 10, cw - 8, ch+1);
|
Chris@159
|
826
|
Chris@446
|
827 for (int y = 0; y < ch; ++y) {
|
Chris@904
|
828 double value = ((max - min) * (double(ch-y) - 1.0)) / double(ch) + min;
|
Chris@447
|
829 if (m_colourScale == LogScale) {
|
Chris@447
|
830 value = LogRange::map(value);
|
Chris@447
|
831 }
|
Chris@447
|
832 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
|
Chris@465
|
833 if (pixel >= 0 && pixel < 256) {
|
Chris@465
|
834 QRgb c = m_cache->color(pixel);
|
Chris@465
|
835 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
|
Chris@465
|
836 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
|
Chris@465
|
837 } else {
|
Chris@682
|
838 cerr << "WARNING: Colour3DPlotLayer::paintVerticalScale: value " << value << ", mmin " << mmin << ", mmax " << mmax << " leads to invalid pixel " << pixel << endl;
|
Chris@465
|
839 }
|
Chris@159
|
840 }
|
Chris@446
|
841
|
Chris@446
|
842 QString minstr = QString("%1").arg(min);
|
Chris@446
|
843 QString maxstr = QString("%1").arg(max);
|
Chris@446
|
844
|
Chris@446
|
845 paint.save();
|
Chris@446
|
846
|
Chris@446
|
847 QFont font = paint.font();
|
Chris@969
|
848 font.setPixelSize(font.pixelSize() * 0.65);
|
Chris@446
|
849 paint.setFont(font);
|
Chris@446
|
850
|
Chris@446
|
851 int msw = paint.fontMetrics().width(maxstr);
|
Chris@446
|
852
|
Chris@446
|
853 QMatrix m;
|
Chris@446
|
854 m.translate(cw - 6, ch + 10);
|
Chris@446
|
855 m.rotate(-90);
|
Chris@446
|
856
|
Chris@446
|
857 paint.setWorldMatrix(m);
|
Chris@446
|
858
|
Chris@446
|
859 v->drawVisibleText(paint, 2, 0, minstr, View::OutlinedText);
|
Chris@446
|
860
|
Chris@446
|
861 m.translate(ch - msw - 2, 0);
|
Chris@446
|
862 paint.setWorldMatrix(m);
|
Chris@446
|
863
|
Chris@446
|
864 v->drawVisibleText(paint, 0, 0, maxstr, View::OutlinedText);
|
Chris@446
|
865
|
Chris@446
|
866 paint.restore();
|
Chris@159
|
867 }
|
Chris@159
|
868
|
Chris@287
|
869 paint.setPen(v->getForeground());
|
Chris@159
|
870
|
Chris@445
|
871 int sh = m_model->getHeight();
|
Chris@445
|
872
|
Chris@445
|
873 int symin = m_miny;
|
Chris@445
|
874 int symax = m_maxy;
|
Chris@445
|
875 if (symax <= symin) {
|
Chris@445
|
876 symin = 0;
|
Chris@445
|
877 symax = sh;
|
Chris@445
|
878 }
|
Chris@445
|
879 if (symin < 0) symin = 0;
|
Chris@445
|
880 if (symax > sh) symax = sh;
|
Chris@445
|
881
|
Chris@532
|
882 paint.save();
|
Chris@456
|
883
|
Chris@533
|
884 int py = h;
|
Chris@25
|
885
|
Chris@969
|
886 int defaultFontHeight = paint.fontMetrics().height();
|
Chris@969
|
887
|
Chris@805
|
888 for (int i = symin; i <= symax; ++i) {
|
Chris@98
|
889
|
Chris@532
|
890 int y0;
|
Chris@534
|
891
|
Chris@903
|
892 y0 = getIYForBin(v, i);
|
Chris@532
|
893 int h = py - y0;
|
Chris@532
|
894
|
Chris@532
|
895 if (i > symin) {
|
Chris@532
|
896 if (paint.fontMetrics().height() >= h) {
|
Chris@969
|
897 if (h >= defaultFontHeight * 0.8) {
|
Chris@532
|
898 QFont tf = paint.font();
|
Chris@969
|
899 tf.setPixelSize(h * 0.8);
|
Chris@532
|
900 paint.setFont(tf);
|
Chris@532
|
901 } else {
|
Chris@532
|
902 continue;
|
Chris@532
|
903 }
|
Chris@532
|
904 }
|
Chris@532
|
905 }
|
Chris@25
|
906
|
Chris@532
|
907 py = y0;
|
Chris@532
|
908
|
Chris@534
|
909 if (i < symax) {
|
Chris@534
|
910 paint.drawLine(cw, y0, w, y0);
|
Chris@534
|
911 }
|
Chris@25
|
912
|
Chris@532
|
913 if (i > symin) {
|
Chris@534
|
914
|
Chris@805
|
915 int idx = i - 1;
|
Chris@534
|
916 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
|
Chris@534
|
917
|
Chris@534
|
918 QString text = m_model->getBinName(idx);
|
Chris@534
|
919 if (text == "") text = QString("[%1]").arg(idx + 1);
|
Chris@534
|
920
|
Chris@534
|
921 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) +
|
Chris@534
|
922 paint.fontMetrics().ascent() + 1;
|
Chris@534
|
923
|
Chris@534
|
924 paint.drawText(cw + 5, ty, text);
|
Chris@457
|
925 }
|
Chris@25
|
926 }
|
Chris@456
|
927
|
Chris@456
|
928 paint.restore();
|
Chris@25
|
929 }
|
Chris@25
|
930
|
Chris@467
|
931 DenseThreeDimensionalModel::Column
|
Chris@805
|
932 Colour3DPlotLayer::getColumn(int col) const
|
Chris@197
|
933 {
|
Chris@812
|
934 Profiler profiler("Colour3DPlotLayer::getColumn");
|
Chris@812
|
935
|
Chris@467
|
936 DenseThreeDimensionalModel::Column values = m_model->getColumn(col);
|
Chris@468
|
937 while (values.size() < m_model->getHeight()) values.push_back(0.f);
|
Chris@719
|
938 if (!m_normalizeColumns && !m_normalizeHybrid) return values;
|
Chris@461
|
939
|
Chris@904
|
940 double colMax = 0.f, colMin = 0.f;
|
Chris@904
|
941 double min = 0.f, max = 0.f;
|
Chris@197
|
942
|
Chris@461
|
943 min = m_model->getMinimumLevel();
|
Chris@461
|
944 max = m_model->getMaximumLevel();
|
Chris@461
|
945
|
Chris@805
|
946 for (int y = 0; y < values.size(); ++y) {
|
Chris@467
|
947 if (y == 0 || values.at(y) > colMax) colMax = values.at(y);
|
Chris@467
|
948 if (y == 0 || values.at(y) < colMin) colMin = values.at(y);
|
Chris@197
|
949 }
|
Chris@461
|
950 if (colMin == colMax) colMax = colMin + 1;
|
Chris@197
|
951
|
Chris@805
|
952 for (int y = 0; y < values.size(); ++y) {
|
Chris@461
|
953
|
Chris@904
|
954 double value = values.at(y);
|
Chris@904
|
955 double norm = (value - colMin) / (colMax - colMin);
|
Chris@904
|
956 double newvalue = min + (max - min) * norm;
|
Chris@197
|
957
|
Chris@904
|
958 if (value != newvalue) values[y] = float(newvalue);
|
Chris@468
|
959 }
|
Chris@468
|
960
|
Chris@719
|
961 if (m_normalizeHybrid && (colMax > 0.0)) {
|
Chris@904
|
962 double logmax = log10(colMax);
|
Chris@805
|
963 for (int y = 0; y < values.size(); ++y) {
|
Chris@904
|
964 values[y] = float(values[y] * logmax);
|
Chris@719
|
965 }
|
Chris@719
|
966 }
|
Chris@719
|
967
|
Chris@468
|
968 return values;
|
Chris@197
|
969 }
|
Chris@197
|
970
|
Chris@197
|
971 void
|
Chris@805
|
972 Colour3DPlotLayer::fillCache(int firstBin, int lastBin) const
|
Chris@197
|
973 {
|
Chris@812
|
974 Profiler profiler("Colour3DPlotLayer::fillCache", true);
|
Chris@476
|
975
|
Chris@902
|
976 sv_frame_t modelStart = m_model->getStartFrame();
|
Chris@902
|
977 sv_frame_t modelEnd = m_model->getEndFrame();
|
Chris@805
|
978 int modelResolution = m_model->getResolution();
|
Chris@197
|
979
|
Chris@902
|
980 int modelStartBin = int(modelStart / modelResolution);
|
Chris@902
|
981 int modelEndBin = int(modelEnd / modelResolution);
|
Chris@461
|
982
|
Chris@812
|
983 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
984 cerr << "Colour3DPlotLayer::fillCache: range " << firstBin << " -> " << lastBin << " of model range " << modelStartBin << " -> " << modelEndBin << " (model resolution " << modelResolution << ")" << endl;
|
Chris@812
|
985 #endif
|
Chris@812
|
986
|
Chris@805
|
987 int cacheWidth = modelEndBin - modelStartBin + 1;
|
Chris@471
|
988 if (lastBin > modelEndBin) cacheWidth = lastBin - modelStartBin + 1;
|
Chris@805
|
989 int cacheHeight = m_model->getHeight();
|
Chris@461
|
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@469
|
1024 m_cache = new QImage
|
Chris@469
|
1025 (cacheWidth, cacheHeight, QImage::Format_Indexed8);
|
Chris@812
|
1026 m_cache->setColorCount(256);
|
Chris@514
|
1027 m_cache->fill(0);
|
Chris@474
|
1028 if (!m_normalizeVisibleArea) {
|
Chris@469
|
1029 m_peaksCache = new QImage
|
Chris@469
|
1030 (cacheWidth / m_peakResolution + 1, cacheHeight,
|
Chris@469
|
1031 QImage::Format_Indexed8);
|
Chris@812
|
1032 m_peaksCache->setColorCount(256);
|
Chris@514
|
1033 m_peaksCache->fill(0);
|
Chris@469
|
1034 } else if (m_peaksCache) {
|
Chris@469
|
1035 delete m_peaksCache;
|
Chris@469
|
1036 m_peaksCache = 0;
|
Chris@469
|
1037 }
|
Chris@461
|
1038 m_cacheValidStart = 0;
|
Chris@461
|
1039 m_cacheValidEnd = 0;
|
Chris@197
|
1040 }
|
Chris@197
|
1041
|
Chris@812
|
1042 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1043 cerr << "cache size = " << m_cache->width() << "x" << m_cache->height()
|
Chris@812
|
1044 << " peaks cache size = " << m_peaksCache->width() << "x" << m_peaksCache->height() << endl;
|
Chris@812
|
1045 #endif
|
Chris@742
|
1046
|
Chris@461
|
1047 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) {
|
Chris@519
|
1048 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@682
|
1049 cerr << "Cache is valid in this region already" << endl;
|
Chris@519
|
1050 #endif
|
Chris@461
|
1051 return;
|
Chris@461
|
1052 }
|
Chris@461
|
1053
|
Chris@805
|
1054 int fillStart = firstBin;
|
Chris@805
|
1055 int fillEnd = lastBin;
|
Chris@197
|
1056
|
Chris@461
|
1057 if (fillStart < modelStartBin) fillStart = modelStartBin;
|
Chris@461
|
1058 if (fillStart > modelEndBin) fillStart = modelEndBin;
|
Chris@461
|
1059 if (fillEnd < modelStartBin) fillEnd = modelStartBin;
|
Chris@461
|
1060 if (fillEnd > modelEndBin) fillEnd = modelEndBin;
|
Chris@197
|
1061
|
Chris@461
|
1062 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);
|
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@197
|
1094 if (m_colourScale == LogScale) {
|
Chris@197
|
1095 LogRange::mapRange(min, max);
|
Chris@197
|
1096 } else if (m_colourScale == PlusMinusOneScale) {
|
Chris@197
|
1097 min = -1.f;
|
Chris@197
|
1098 max = 1.f;
|
Chris@509
|
1099 } else if (m_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@197
|
1135 if (y >= values.size()) 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@461
|
1144 if (m_colourScale == LogScale) {
|
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@509
|
1148 } else if (m_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@197
|
1185 if (y < values.size()) {
|
Chris@469
|
1186 value = values.at(y);
|
Chris@197
|
1187 }
|
Chris@224
|
1188
|
Chris@534
|
1189 value = value * m_gain;
|
Chris@534
|
1190
|
Chris@224
|
1191 if (m_colourScale == LogScale) {
|
Chris@224
|
1192 value = LogRange::map(value);
|
Chris@509
|
1193 } else if (m_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@916
|
1290 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->getPaintRect();
|
Chris@197
|
1291
|
Chris@902
|
1292 sv_frame_t modelStart = m_model->getStartFrame();
|
Chris@902
|
1293 sv_frame_t modelEnd = m_model->getEndFrame();
|
Chris@805
|
1294 int modelResolution = m_model->getResolution();
|
Chris@0
|
1295
|
Chris@197
|
1296 // The cache is from the model's start frame to the model's end
|
Chris@197
|
1297 // frame at the model's window increment frames per pixel. We
|
Chris@197
|
1298 // want to draw from our start frame + x0 * zoomLevel to our start
|
Chris@197
|
1299 // frame + x1 * zoomLevel at zoomLevel frames per pixel.
|
Chris@12
|
1300
|
Chris@197
|
1301 // We have quite different paint mechanisms for rendering "large"
|
Chris@197
|
1302 // bins (more than one bin per pixel in both directions) and
|
Chris@197
|
1303 // "small". This is "large"; see paintDense below for "small".
|
Chris@12
|
1304
|
Chris@197
|
1305 int x0 = rect.left();
|
Chris@197
|
1306 int x1 = rect.right() + 1;
|
Chris@12
|
1307
|
Chris@916
|
1308 int h = v->getPaintHeight();
|
Chris@0
|
1309
|
Chris@902
|
1310 double srRatio =
|
Chris@902
|
1311 v->getViewManager()->getMainModelSampleRate() / m_model->getSampleRate();
|
Chris@0
|
1312
|
Chris@902
|
1313 int sx0 = int((double(v->getFrameForX(x0)) / srRatio - double(modelStart))
|
Chris@812
|
1314 / modelResolution);
|
Chris@902
|
1315 int sx1 = int((double(v->getFrameForX(x1)) / srRatio - double(modelStart))
|
Chris@812
|
1316 / modelResolution);
|
Chris@197
|
1317 int sh = m_model->getHeight();
|
Chris@159
|
1318
|
Chris@444
|
1319 int symin = m_miny;
|
Chris@444
|
1320 int symax = m_maxy;
|
Chris@444
|
1321 if (symax <= symin) {
|
Chris@444
|
1322 symin = 0;
|
Chris@444
|
1323 symax = sh;
|
Chris@444
|
1324 }
|
Chris@444
|
1325 if (symin < 0) symin = 0;
|
Chris@444
|
1326 if (symax > sh) symax = sh;
|
Chris@444
|
1327
|
Chris@197
|
1328 if (sx0 > 0) --sx0;
|
Chris@197
|
1329 fillCache(sx0 < 0 ? 0 : sx0,
|
Chris@197
|
1330 sx1 < 0 ? 0 : sx1);
|
Chris@0
|
1331
|
Chris@351
|
1332 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1333 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
|
1334 #endif
|
Chris@351
|
1335
|
Chris@812
|
1336 if (shouldPaintDenseIn(v)) {
|
Chris@347
|
1337 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1338 cerr << "calling paintDense" << endl;
|
Chris@347
|
1339 #endif
|
Chris@98
|
1340 paintDense(v, paint, rect);
|
Chris@98
|
1341 return;
|
Chris@98
|
1342 }
|
Chris@98
|
1343
|
Chris@125
|
1344 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1345 cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << endl;
|
Chris@682
|
1346 cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << endl;
|
Chris@125
|
1347 #endif
|
Chris@0
|
1348
|
Chris@25
|
1349 QPoint illuminatePos;
|
Chris@44
|
1350 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
|
Chris@864
|
1351
|
Chris@864
|
1352 const int buflen = 40;
|
Chris@864
|
1353 char labelbuf[buflen];
|
Chris@25
|
1354
|
Chris@197
|
1355 for (int sx = sx0; sx <= sx1; ++sx) {
|
Chris@0
|
1356
|
Chris@902
|
1357 sv_frame_t fx = sx * modelResolution;
|
Chris@0
|
1358
|
Chris@812
|
1359 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
|
Chris@0
|
1360
|
Chris@902
|
1361 int rx0 = v->getXForFrame(int(double(fx + modelStart) * srRatio));
|
Chris@902
|
1362 int rx1 = v->getXForFrame(int(double(fx + modelStart + modelResolution + 1) * srRatio));
|
Chris@54
|
1363
|
Chris@159
|
1364 int rw = rx1 - rx0;
|
Chris@159
|
1365 if (rw < 1) rw = 1;
|
Chris@54
|
1366
|
Chris@159
|
1367 bool showLabel = (rw > 10 &&
|
Chris@159
|
1368 paint.fontMetrics().width("0.000000") < rw - 3 &&
|
Chris@54
|
1369 paint.fontMetrics().height() < (h / sh));
|
Chris@98
|
1370
|
Chris@444
|
1371 for (int sy = symin; sy < symax; ++sy) {
|
Chris@0
|
1372
|
Chris@903
|
1373 int ry0 = getIYForBin(v, sy);
|
Chris@903
|
1374 int ry1 = getIYForBin(v, sy + 1);
|
Chris@534
|
1375 QRect r(rx0, ry1, rw, ry0 - ry1);
|
Chris@534
|
1376
|
Chris@0
|
1377 QRgb pixel = qRgb(255, 255, 255);
|
Chris@461
|
1378 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@0
|
1379 sy >= 0 && sy < m_cache->height()) {
|
Chris@461
|
1380 pixel = m_cache->pixel(sx, sy);
|
Chris@0
|
1381 }
|
Chris@0
|
1382
|
Chris@159
|
1383 if (rw == 1) {
|
Chris@159
|
1384 paint.setPen(pixel);
|
Chris@159
|
1385 paint.setBrush(Qt::NoBrush);
|
Chris@159
|
1386 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
|
Chris@159
|
1387 continue;
|
Chris@159
|
1388 }
|
Chris@159
|
1389
|
Chris@0
|
1390 QColor pen(255, 255, 255, 80);
|
Chris@0
|
1391 QColor brush(pixel);
|
Chris@159
|
1392
|
Chris@159
|
1393 if (rw > 3 && r.height() > 3) {
|
Chris@159
|
1394 brush.setAlpha(160);
|
Chris@159
|
1395 }
|
Chris@159
|
1396
|
Chris@0
|
1397 paint.setPen(Qt::NoPen);
|
Chris@0
|
1398 paint.setBrush(brush);
|
Chris@0
|
1399
|
Chris@25
|
1400 if (illuminate) {
|
Chris@25
|
1401 if (r.contains(illuminatePos)) {
|
Chris@287
|
1402 paint.setPen(v->getForeground());
|
Chris@25
|
1403 }
|
Chris@25
|
1404 }
|
Chris@76
|
1405
|
Chris@125
|
1406 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@682
|
1407 // cerr << "rect " << r.x() << "," << r.y() << " "
|
Chris@682
|
1408 // << r.width() << "x" << r.height() << endl;
|
Chris@125
|
1409 #endif
|
Chris@25
|
1410
|
Chris@25
|
1411 paint.drawRect(r);
|
Chris@0
|
1412
|
Chris@54
|
1413 if (showLabel) {
|
Chris@461
|
1414 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@54
|
1415 sy >= 0 && sy < m_cache->height()) {
|
Chris@904
|
1416 double value = m_model->getValueAt(sx, sy);
|
Chris@864
|
1417 snprintf(labelbuf, buflen, "%06f", value);
|
Chris@54
|
1418 QString text(labelbuf);
|
Chris@287
|
1419 paint.setPen(v->getBackground());
|
Chris@54
|
1420 paint.drawText(rx0 + 2,
|
Chris@54
|
1421 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
|
Chris@54
|
1422 text);
|
Chris@0
|
1423 }
|
Chris@0
|
1424 }
|
Chris@0
|
1425 }
|
Chris@0
|
1426 }
|
Chris@98
|
1427 }
|
Chris@0
|
1428
|
Chris@98
|
1429 void
|
Chris@916
|
1430 Colour3DPlotLayer::paintDense(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
|
Chris@98
|
1431 {
|
Chris@812
|
1432 Profiler profiler("Colour3DPlotLayer::paintDense", true);
|
Chris@463
|
1433 if (!m_cache) return;
|
Chris@463
|
1434
|
Chris@903
|
1435 double modelStart = double(m_model->getStartFrame());
|
Chris@903
|
1436 double modelResolution = double(m_model->getResolution());
|
Chris@0
|
1437
|
Chris@903
|
1438 sv_samplerate_t mmsr = v->getViewManager()->getMainModelSampleRate();
|
Chris@903
|
1439 sv_samplerate_t msr = m_model->getSampleRate();
|
Chris@903
|
1440 double srRatio = mmsr / msr;
|
Chris@159
|
1441
|
Chris@98
|
1442 int x0 = rect.left();
|
Chris@98
|
1443 int x1 = rect.right() + 1;
|
Chris@0
|
1444
|
Chris@470
|
1445 const int w = x1 - x0; // const so it can be used as array size below
|
Chris@916
|
1446 int h = v->getPaintHeight(); // we always paint full height
|
Chris@160
|
1447 int sh = m_model->getHeight();
|
Chris@98
|
1448
|
Chris@444
|
1449 int symin = m_miny;
|
Chris@444
|
1450 int symax = m_maxy;
|
Chris@444
|
1451 if (symax <= symin) {
|
Chris@444
|
1452 symin = 0;
|
Chris@444
|
1453 symax = sh;
|
Chris@444
|
1454 }
|
Chris@444
|
1455 if (symin < 0) symin = 0;
|
Chris@444
|
1456 if (symax > sh) symax = sh;
|
Chris@444
|
1457
|
Chris@466
|
1458 QImage img(w, h, QImage::Format_Indexed8);
|
Chris@466
|
1459 img.setColorTable(m_cache->colorTable());
|
Chris@98
|
1460
|
Chris@466
|
1461 uchar *peaks = new uchar[w];
|
Chris@466
|
1462 memset(peaks, 0, w);
|
Chris@98
|
1463
|
Chris@469
|
1464 int zoomLevel = v->getZoomLevel();
|
Chris@469
|
1465
|
Chris@469
|
1466 QImage *source = m_cache;
|
Chris@812
|
1467
|
Chris@812
|
1468 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1469 cerr << "modelResolution " << modelResolution << ", srRatio "
|
Chris@812
|
1470 << srRatio << ", m_peakResolution " << m_peakResolution
|
Chris@812
|
1471 << ", zoomLevel " << zoomLevel << ", result "
|
Chris@812
|
1472 << ((modelResolution * srRatio * m_peakResolution) / zoomLevel)
|
Chris@812
|
1473 << endl;
|
Chris@812
|
1474 #endif
|
Chris@474
|
1475
|
Chris@474
|
1476 if (m_peaksCache) {
|
Chris@474
|
1477 if (((modelResolution * srRatio * m_peakResolution) / zoomLevel) < 1) {
|
Chris@812
|
1478 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1479 cerr << "using peaks cache" << endl;
|
Chris@812
|
1480 #endif
|
Chris@474
|
1481 source = m_peaksCache;
|
Chris@474
|
1482 modelResolution *= m_peakResolution;
|
Chris@474
|
1483 } else {
|
Chris@812
|
1484 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1485 cerr << "not using peaks cache" << endl;
|
Chris@812
|
1486 #endif
|
Chris@474
|
1487 }
|
Chris@469
|
1488 } else {
|
Chris@812
|
1489 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1490 cerr << "have no peaks cache" << endl;
|
Chris@812
|
1491 #endif
|
Chris@469
|
1492 }
|
Chris@469
|
1493
|
Chris@469
|
1494 int sw = source->width();
|
Chris@470
|
1495
|
Chris@903
|
1496 sv_frame_t xf = -1;
|
Chris@903
|
1497 sv_frame_t nxf = v->getFrameForX(x0);
|
Chris@470
|
1498
|
Chris@903
|
1499 double epsilon = 0.000001;
|
Chris@535
|
1500
|
Chris@903
|
1501 vector<double> sxa(w*2);
|
Chris@903
|
1502
|
Chris@470
|
1503 for (int x = 0; x < w; ++x) {
|
Chris@470
|
1504
|
Chris@470
|
1505 xf = nxf;
|
Chris@470
|
1506 nxf = xf + zoomLevel;
|
Chris@470
|
1507
|
Chris@903
|
1508 double sx0 = (double(xf) / srRatio - modelStart) / modelResolution;
|
Chris@903
|
1509 double sx1 = (double(nxf) / srRatio - modelStart) / modelResolution;
|
Chris@470
|
1510
|
Chris@535
|
1511 sxa[x*2] = sx0;
|
Chris@535
|
1512 sxa[x*2 + 1] = sx1;
|
Chris@470
|
1513 }
|
Chris@466
|
1514
|
Chris@904
|
1515 double logmin = symin+1, logmax = symax+1;
|
Chris@532
|
1516 LogRange::mapRange(logmin, logmax);
|
Chris@532
|
1517
|
Chris@812
|
1518 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@812
|
1519 cerr << "m_smooth = " << m_smooth << ", w = " << w << ", h = " << h << endl;
|
Chris@812
|
1520 #endif
|
Chris@812
|
1521
|
Chris@535
|
1522 if (m_smooth) {
|
Chris@535
|
1523
|
Chris@535
|
1524 for (int y = 0; y < h; ++y) {
|
Chris@466
|
1525
|
Chris@904
|
1526 double sy = getBinForY(v, y) - 0.5;
|
Chris@535
|
1527 int syi = int(sy + epsilon);
|
Chris@535
|
1528 if (syi < 0 || syi >= source->height()) continue;
|
Chris@531
|
1529
|
Chris@535
|
1530 uchar *targetLine = img.scanLine(y);
|
Chris@535
|
1531 uchar *sourceLine = source->scanLine(syi);
|
Chris@535
|
1532 uchar *nextSource;
|
Chris@535
|
1533 if (syi + 1 < source->height()) {
|
Chris@535
|
1534 nextSource = source->scanLine(syi + 1);
|
Chris@535
|
1535 } else {
|
Chris@535
|
1536 nextSource = sourceLine;
|
Chris@535
|
1537 }
|
Chris@466
|
1538
|
Chris@466
|
1539 for (int x = 0; x < w; ++x) {
|
Chris@98
|
1540
|
Chris@535
|
1541 targetLine[x] = 0;
|
Chris@474
|
1542
|
Chris@903
|
1543 double sx0 = sxa[x*2];
|
Chris@537
|
1544 if (sx0 < 0) continue;
|
Chris@535
|
1545 int sx0i = int(sx0 + epsilon);
|
Chris@474
|
1546 if (sx0i >= sw) break;
|
Chris@98
|
1547
|
Chris@903
|
1548 double a = sourceLine[sx0i];
|
Chris@903
|
1549 double b = a;
|
Chris@903
|
1550 double value;
|
Chris@535
|
1551
|
Chris@903
|
1552 double sx1 = sxa[x*2+1];
|
Chris@535
|
1553 if (sx1 > sx0 + 1.f) {
|
Chris@535
|
1554 int sx1i = int(sx1);
|
Chris@535
|
1555 bool have = false;
|
Chris@535
|
1556 for (int sx = sx0i; sx <= sx1i; ++sx) {
|
Chris@535
|
1557 if (sx < 0 || sx >= sw) continue;
|
Chris@535
|
1558 if (!have) {
|
Chris@903
|
1559 a = sourceLine[sx];
|
Chris@903
|
1560 b = nextSource[sx];
|
Chris@535
|
1561 have = true;
|
Chris@535
|
1562 } else {
|
Chris@903
|
1563 a = std::max(a, double(sourceLine[sx]));
|
Chris@903
|
1564 b = std::max(b, double(nextSource[sx]));
|
Chris@535
|
1565 }
|
Chris@535
|
1566 }
|
Chris@903
|
1567 double yprop = sy - syi;
|
Chris@535
|
1568 value = (a * (1.f - yprop) + b * yprop);
|
Chris@535
|
1569 } else {
|
Chris@903
|
1570 a = sourceLine[sx0i];
|
Chris@903
|
1571 b = nextSource[sx0i];
|
Chris@903
|
1572 double yprop = sy - syi;
|
Chris@535
|
1573 value = (a * (1.f - yprop) + b * yprop);
|
Chris@535
|
1574 int oi = sx0i + 1;
|
Chris@903
|
1575 double xprop = sx0 - sx0i;
|
Chris@535
|
1576 xprop -= 0.5;
|
Chris@535
|
1577 if (xprop < 0) {
|
Chris@535
|
1578 oi = sx0i - 1;
|
Chris@535
|
1579 xprop = -xprop;
|
Chris@535
|
1580 }
|
Chris@535
|
1581 if (oi < 0 || oi >= sw) oi = sx0i;
|
Chris@903
|
1582 a = sourceLine[oi];
|
Chris@903
|
1583 b = nextSource[oi];
|
Chris@535
|
1584 value = (value * (1.f - xprop) +
|
Chris@535
|
1585 (a * (1.f - yprop) + b * yprop) * xprop);
|
Chris@98
|
1586 }
|
Chris@535
|
1587
|
Chris@903
|
1588 int vi = int(lrint(value));
|
Chris@535
|
1589 if (vi > 255) vi = 255;
|
Chris@535
|
1590 if (vi < 0) vi = 0;
|
Chris@535
|
1591 targetLine[x] = uchar(vi);
|
Chris@98
|
1592 }
|
Chris@466
|
1593 }
|
Chris@535
|
1594 } else {
|
Chris@535
|
1595
|
Chris@904
|
1596 double sy0 = getBinForY(v, 0);
|
Chris@812
|
1597
|
Chris@812
|
1598 int psy0i = -1, psy1i = -1;
|
Chris@812
|
1599
|
Chris@535
|
1600 for (int y = 0; y < h; ++y) {
|
Chris@535
|
1601
|
Chris@904
|
1602 double sy1 = sy0;
|
Chris@904
|
1603 sy0 = getBinForY(v, double(y + 1));
|
Chris@535
|
1604
|
Chris@535
|
1605 int sy0i = int(sy0 + epsilon);
|
Chris@535
|
1606 int sy1i = int(sy1);
|
Chris@535
|
1607
|
Chris@535
|
1608 uchar *targetLine = img.scanLine(y);
|
Chris@535
|
1609
|
Chris@812
|
1610 if (sy0i == psy0i && sy1i == psy1i) {
|
Chris@812
|
1611 // same source scan line as just computed
|
Chris@535
|
1612 goto copy;
|
Chris@535
|
1613 }
|
Chris@535
|
1614
|
Chris@812
|
1615 psy0i = sy0i;
|
Chris@812
|
1616 psy1i = sy1i;
|
Chris@812
|
1617
|
Chris@535
|
1618 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1619 peaks[x] = 0;
|
Chris@535
|
1620 }
|
Chris@466
|
1621
|
Chris@535
|
1622 for (int sy = sy0i; sy <= sy1i; ++sy) {
|
Chris@535
|
1623
|
Chris@535
|
1624 if (sy < 0 || sy >= source->height()) continue;
|
Chris@535
|
1625
|
Chris@535
|
1626 uchar *sourceLine = source->scanLine(sy);
|
Chris@535
|
1627
|
Chris@535
|
1628 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1629
|
Chris@903
|
1630 double sx1 = sxa[x*2 + 1];
|
Chris@537
|
1631 if (sx1 < 0) continue;
|
Chris@537
|
1632 int sx1i = int(sx1);
|
Chris@535
|
1633
|
Chris@903
|
1634 double sx0 = sxa[x*2];
|
Chris@537
|
1635 if (sx0 < 0) continue;
|
Chris@537
|
1636 int sx0i = int(sx0 + epsilon);
|
Chris@535
|
1637 if (sx0i >= sw) break;
|
Chris@535
|
1638
|
Chris@535
|
1639 uchar peak = 0;
|
Chris@535
|
1640 for (int sx = sx0i; sx <= sx1i; ++sx) {
|
Chris@535
|
1641 if (sx < 0 || sx >= sw) continue;
|
Chris@535
|
1642 if (sourceLine[sx] > peak) peak = sourceLine[sx];
|
Chris@535
|
1643 }
|
Chris@535
|
1644 peaks[x] = peak;
|
Chris@535
|
1645 }
|
Chris@535
|
1646 }
|
Chris@535
|
1647
|
Chris@535
|
1648 copy:
|
Chris@535
|
1649 for (int x = 0; x < w; ++x) {
|
Chris@535
|
1650 targetLine[x] = peaks[x];
|
Chris@535
|
1651 }
|
Chris@98
|
1652 }
|
Chris@0
|
1653 }
|
Chris@0
|
1654
|
Chris@469
|
1655 delete[] peaks;
|
Chris@469
|
1656
|
Chris@98
|
1657 paint.drawImage(x0, 0, img);
|
Chris@0
|
1658 }
|
Chris@0
|
1659
|
Chris@28
|
1660 bool
|
Chris@916
|
1661 Colour3DPlotLayer::snapToFeatureFrame(LayerGeometryProvider *v, sv_frame_t &frame,
|
Chris@805
|
1662 int &resolution,
|
Chris@28
|
1663 SnapType snap) const
|
Chris@24
|
1664 {
|
Chris@24
|
1665 if (!m_model) {
|
Chris@44
|
1666 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@24
|
1667 }
|
Chris@24
|
1668
|
Chris@130
|
1669 resolution = m_model->getResolution();
|
Chris@904
|
1670 sv_frame_t left = (frame / resolution) * resolution;
|
Chris@904
|
1671 sv_frame_t right = left + resolution;
|
Chris@28
|
1672
|
Chris@28
|
1673 switch (snap) {
|
Chris@28
|
1674 case SnapLeft: frame = left; break;
|
Chris@28
|
1675 case SnapRight: frame = right; break;
|
Chris@28
|
1676 case SnapNearest:
|
Chris@28
|
1677 case SnapNeighbouring:
|
Chris@28
|
1678 if (frame - left > right - frame) frame = right;
|
Chris@28
|
1679 else frame = left;
|
Chris@28
|
1680 break;
|
Chris@28
|
1681 }
|
Chris@24
|
1682
|
Chris@28
|
1683 return true;
|
Chris@24
|
1684 }
|
Chris@24
|
1685
|
Chris@316
|
1686 void
|
Chris@316
|
1687 Colour3DPlotLayer::toXml(QTextStream &stream,
|
Chris@316
|
1688 QString indent, QString extraAttributes) const
|
Chris@197
|
1689 {
|
Chris@316
|
1690 QString s = QString("scale=\"%1\" "
|
Chris@316
|
1691 "colourScheme=\"%2\" "
|
Chris@316
|
1692 "normalizeColumns=\"%3\" "
|
Chris@445
|
1693 "normalizeVisibleArea=\"%4\" "
|
Chris@445
|
1694 "minY=\"%5\" "
|
Chris@465
|
1695 "maxY=\"%6\" "
|
Chris@465
|
1696 "invertVertical=\"%7\" "
|
Chris@535
|
1697 "opaque=\"%8\" %9")
|
Chris@197
|
1698 .arg((int)m_colourScale)
|
Chris@197
|
1699 .arg(m_colourMap)
|
Chris@197
|
1700 .arg(m_normalizeColumns ? "true" : "false")
|
Chris@445
|
1701 .arg(m_normalizeVisibleArea ? "true" : "false")
|
Chris@445
|
1702 .arg(m_miny)
|
Chris@465
|
1703 .arg(m_maxy)
|
Chris@465
|
1704 .arg(m_invertVertical ? "true" : "false")
|
Chris@534
|
1705 .arg(m_opaque ? "true" : "false")
|
Chris@536
|
1706 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ")
|
Chris@535
|
1707 .arg((int)m_binScale)
|
Chris@536
|
1708 .arg(m_smooth ? "true" : "false")
|
Chris@536
|
1709 .arg(m_gain));
|
Chris@535
|
1710
|
Chris@316
|
1711 Layer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@197
|
1712 }
|
Chris@197
|
1713
|
Chris@197
|
1714 void
|
Chris@197
|
1715 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@197
|
1716 {
|
Chris@445
|
1717 bool ok = false, alsoOk = false;
|
Chris@197
|
1718
|
Chris@197
|
1719 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok);
|
Chris@197
|
1720 if (ok) setColourScale(scale);
|
Chris@197
|
1721
|
Chris@197
|
1722 int colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@197
|
1723 if (ok) setColourMap(colourMap);
|
Chris@197
|
1724
|
Chris@534
|
1725 BinScale binscale = (BinScale)attributes.value("binScale").toInt(&ok);
|
Chris@534
|
1726 if (ok) setBinScale(binscale);
|
Chris@534
|
1727
|
Chris@197
|
1728 bool normalizeColumns =
|
Chris@197
|
1729 (attributes.value("normalizeColumns").trimmed() == "true");
|
Chris@197
|
1730 setNormalizeColumns(normalizeColumns);
|
Chris@197
|
1731
|
Chris@197
|
1732 bool normalizeVisibleArea =
|
Chris@197
|
1733 (attributes.value("normalizeVisibleArea").trimmed() == "true");
|
Chris@197
|
1734 setNormalizeVisibleArea(normalizeVisibleArea);
|
Chris@445
|
1735
|
Chris@465
|
1736 bool invertVertical =
|
Chris@465
|
1737 (attributes.value("invertVertical").trimmed() == "true");
|
Chris@465
|
1738 setInvertVertical(invertVertical);
|
Chris@465
|
1739
|
Chris@465
|
1740 bool opaque =
|
Chris@465
|
1741 (attributes.value("opaque").trimmed() == "true");
|
Chris@535
|
1742 setOpaque(opaque);
|
Chris@535
|
1743
|
Chris@535
|
1744 bool smooth =
|
Chris@535
|
1745 (attributes.value("smooth").trimmed() == "true");
|
Chris@535
|
1746 setSmooth(smooth);
|
Chris@465
|
1747
|
Chris@536
|
1748 float gain = attributes.value("gain").toFloat(&ok);
|
Chris@536
|
1749 if (ok) setGain(gain);
|
Chris@536
|
1750
|
Chris@445
|
1751 float min = attributes.value("minY").toFloat(&ok);
|
Chris@445
|
1752 float max = attributes.value("maxY").toFloat(&alsoOk);
|
Chris@445
|
1753 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@197
|
1754 }
|
Chris@197
|
1755
|