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