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