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