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@461
|
39 m_cacheValidStart(0),
|
Chris@461
|
40 m_cacheValidEnd(0),
|
Chris@197
|
41 m_colourScale(LinearScale),
|
Chris@461
|
42 m_colourScaleSet(false),
|
Chris@197
|
43 m_colourMap(0),
|
Chris@197
|
44 m_normalizeColumns(false),
|
Chris@357
|
45 m_normalizeVisibleArea(false),
|
Chris@444
|
46 m_invertVertical(false),
|
Chris@444
|
47 m_miny(0),
|
Chris@444
|
48 m_maxy(0)
|
Chris@0
|
49 {
|
Chris@44
|
50
|
Chris@0
|
51 }
|
Chris@0
|
52
|
Chris@0
|
53 Colour3DPlotLayer::~Colour3DPlotLayer()
|
Chris@0
|
54 {
|
Chris@461
|
55 delete m_cache;
|
Chris@0
|
56 }
|
Chris@0
|
57
|
Chris@0
|
58 void
|
Chris@0
|
59 Colour3DPlotLayer::setModel(const DenseThreeDimensionalModel *model)
|
Chris@0
|
60 {
|
Chris@193
|
61 if (m_model == model) return;
|
Chris@193
|
62 const DenseThreeDimensionalModel *oldModel = m_model;
|
Chris@0
|
63 m_model = model;
|
Chris@0
|
64 if (!m_model || !m_model->isOK()) return;
|
Chris@0
|
65
|
Chris@320
|
66 connectSignals(m_model);
|
Chris@0
|
67
|
Chris@461
|
68 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
|
Chris@0
|
69 connect(m_model, SIGNAL(modelChanged(size_t, size_t)),
|
Chris@461
|
70 this, SLOT(modelChanged(size_t, size_t)));
|
Chris@0
|
71
|
Chris@0
|
72 emit modelReplaced();
|
Chris@193
|
73 emit sliceableModelReplaced(oldModel, model);
|
Chris@0
|
74 }
|
Chris@0
|
75
|
Chris@0
|
76 void
|
Chris@0
|
77 Colour3DPlotLayer::cacheInvalid()
|
Chris@0
|
78 {
|
Chris@0
|
79 delete m_cache;
|
Chris@0
|
80 m_cache = 0;
|
Chris@461
|
81 m_cacheValidStart = 0;
|
Chris@461
|
82 m_cacheValidEnd = 0;
|
Chris@0
|
83 }
|
Chris@0
|
84
|
Chris@0
|
85 void
|
Chris@461
|
86 Colour3DPlotLayer::cacheInvalid(size_t startFrame, size_t endFrame)
|
Chris@0
|
87 {
|
Chris@461
|
88 if (!m_cache) return;
|
Chris@461
|
89
|
Chris@461
|
90 size_t modelResolution = m_model->getResolution();
|
Chris@461
|
91 size_t start = startFrame / modelResolution;
|
Chris@461
|
92 size_t end = endFrame / modelResolution + 1;
|
Chris@461
|
93 if (m_cacheValidStart < end) m_cacheValidStart = end;
|
Chris@461
|
94 if (m_cacheValidEnd > start) m_cacheValidEnd = start;
|
Chris@461
|
95 if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
|
Chris@461
|
96 }
|
Chris@461
|
97
|
Chris@461
|
98 void
|
Chris@461
|
99 Colour3DPlotLayer::modelChanged()
|
Chris@461
|
100 {
|
Chris@461
|
101 if (!m_colourScaleSet && m_colourScale == LinearScale) {
|
Chris@461
|
102 if (m_model) {
|
Chris@461
|
103 if (m_model->shouldUseLogValueScale()) {
|
Chris@461
|
104 setColourScale(LogScale);
|
Chris@461
|
105 } else {
|
Chris@461
|
106 m_colourScaleSet = true;
|
Chris@461
|
107 }
|
Chris@461
|
108 }
|
Chris@461
|
109 }
|
Chris@0
|
110 cacheInvalid();
|
Chris@0
|
111 }
|
Chris@0
|
112
|
Chris@461
|
113 void
|
Chris@461
|
114 Colour3DPlotLayer::modelChanged(size_t startFrame, size_t endFrame)
|
Chris@461
|
115 {
|
Chris@461
|
116 if (!m_colourScaleSet && m_colourScale == LinearScale) {
|
Chris@461
|
117 if (m_model && m_model->getWidth() > 50) {
|
Chris@461
|
118 if (m_model->shouldUseLogValueScale()) {
|
Chris@461
|
119 setColourScale(LogScale);
|
Chris@461
|
120 } else {
|
Chris@461
|
121 m_colourScaleSet = true;
|
Chris@461
|
122 }
|
Chris@461
|
123 }
|
Chris@461
|
124 }
|
Chris@461
|
125 cacheInvalid(startFrame, endFrame);
|
Chris@461
|
126 }
|
Chris@461
|
127
|
Chris@159
|
128 Layer::PropertyList
|
Chris@159
|
129 Colour3DPlotLayer::getProperties() const
|
Chris@159
|
130 {
|
Chris@159
|
131 PropertyList list;
|
Chris@197
|
132 list.push_back("Colour");
|
Chris@159
|
133 list.push_back("Colour Scale");
|
Chris@197
|
134 list.push_back("Normalize Columns");
|
Chris@197
|
135 list.push_back("Normalize Visible Area");
|
Chris@357
|
136 list.push_back("Invert Vertical Scale");
|
Chris@159
|
137 return list;
|
Chris@159
|
138 }
|
Chris@159
|
139
|
Chris@159
|
140 QString
|
Chris@159
|
141 Colour3DPlotLayer::getPropertyLabel(const PropertyName &name) const
|
Chris@159
|
142 {
|
Chris@197
|
143 if (name == "Colour") return tr("Colour");
|
Chris@197
|
144 if (name == "Colour Scale") return tr("Scale");
|
Chris@197
|
145 if (name == "Normalize Columns") return tr("Normalize Columns");
|
Chris@197
|
146 if (name == "Normalize Visible Area") return tr("Normalize Visible Area");
|
Chris@357
|
147 if (name == "Invert Vertical Scale") return tr("Invert Vertical Scale");
|
Chris@159
|
148 return "";
|
Chris@159
|
149 }
|
Chris@159
|
150
|
Chris@346
|
151 QString
|
Chris@346
|
152 Colour3DPlotLayer::getPropertyIconName(const PropertyName &name) const
|
Chris@346
|
153 {
|
Chris@346
|
154 if (name == "Normalize Columns") return "normalise-columns";
|
Chris@346
|
155 if (name == "Normalize Visible Area") return "normalise";
|
Chris@357
|
156 if (name == "Invert Vertical Scale") return "invert-vertical";
|
Chris@346
|
157 return "";
|
Chris@346
|
158 }
|
Chris@346
|
159
|
Chris@159
|
160 Layer::PropertyType
|
Chris@159
|
161 Colour3DPlotLayer::getPropertyType(const PropertyName &name) const
|
Chris@159
|
162 {
|
Chris@197
|
163 if (name == "Normalize Columns") return ToggleProperty;
|
Chris@197
|
164 if (name == "Normalize Visible Area") return ToggleProperty;
|
Chris@357
|
165 if (name == "Invert Vertical Scale") return ToggleProperty;
|
Chris@159
|
166 return ValueProperty;
|
Chris@159
|
167 }
|
Chris@159
|
168
|
Chris@159
|
169 QString
|
Chris@159
|
170 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const
|
Chris@159
|
171 {
|
Chris@197
|
172 if (name == "Normalize Columns" ||
|
Chris@197
|
173 name == "Normalize Visible Area" ||
|
Chris@357
|
174 name == "Invert Vertical Scale" ||
|
Chris@197
|
175 name == "Colour Scale") return tr("Scale");
|
Chris@159
|
176 return QString();
|
Chris@159
|
177 }
|
Chris@159
|
178
|
Chris@159
|
179 int
|
Chris@159
|
180 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name,
|
Chris@216
|
181 int *min, int *max, int *deflt) const
|
Chris@159
|
182 {
|
Chris@216
|
183 int val = 0;
|
Chris@159
|
184
|
Chris@216
|
185 int garbage0, garbage1, garbage2;
|
Chris@159
|
186 if (!min) min = &garbage0;
|
Chris@159
|
187 if (!max) max = &garbage1;
|
Chris@216
|
188 if (!deflt) deflt = &garbage2;
|
Chris@159
|
189
|
Chris@159
|
190 if (name == "Colour Scale") {
|
Chris@159
|
191
|
Chris@159
|
192 *min = 0;
|
Chris@197
|
193 *max = 2;
|
Chris@216
|
194 *deflt = (int)LinearScale;
|
Chris@159
|
195
|
Chris@216
|
196 val = (int)m_colourScale;
|
Chris@159
|
197
|
Chris@197
|
198 } else if (name == "Colour") {
|
Chris@197
|
199
|
Chris@197
|
200 *min = 0;
|
Chris@197
|
201 *max = ColourMapper::getColourMapCount() - 1;
|
Chris@216
|
202 *deflt = 0;
|
Chris@197
|
203
|
Chris@216
|
204 val = m_colourMap;
|
Chris@197
|
205
|
Chris@197
|
206 } else if (name == "Normalize Columns") {
|
Chris@197
|
207
|
Chris@216
|
208 *deflt = 0;
|
Chris@216
|
209 val = (m_normalizeColumns ? 1 : 0);
|
Chris@197
|
210
|
Chris@197
|
211 } else if (name == "Normalize Visible Area") {
|
Chris@197
|
212
|
Chris@216
|
213 *deflt = 0;
|
Chris@216
|
214 val = (m_normalizeVisibleArea ? 1 : 0);
|
Chris@197
|
215
|
Chris@357
|
216 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
217
|
Chris@357
|
218 *deflt = 0;
|
Chris@357
|
219 val = (m_invertVertical ? 1 : 0);
|
Chris@357
|
220
|
Chris@159
|
221 } else {
|
Chris@216
|
222 val = Layer::getPropertyRangeAndValue(name, min, max, deflt);
|
Chris@159
|
223 }
|
Chris@159
|
224
|
Chris@216
|
225 return val;
|
Chris@159
|
226 }
|
Chris@159
|
227
|
Chris@159
|
228 QString
|
Chris@159
|
229 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name,
|
Chris@159
|
230 int value) const
|
Chris@159
|
231 {
|
Chris@197
|
232 if (name == "Colour") {
|
Chris@197
|
233 return ColourMapper::getColourMapName(value);
|
Chris@197
|
234 }
|
Chris@159
|
235 if (name == "Colour Scale") {
|
Chris@159
|
236 switch (value) {
|
Chris@159
|
237 default:
|
Chris@198
|
238 case 0: return tr("Linear");
|
Chris@198
|
239 case 1: return tr("Log");
|
Chris@198
|
240 case 2: return tr("+/-1");
|
Chris@159
|
241 }
|
Chris@159
|
242 }
|
Chris@159
|
243 return tr("<unknown>");
|
Chris@159
|
244 }
|
Chris@159
|
245
|
Chris@159
|
246 void
|
Chris@159
|
247 Colour3DPlotLayer::setProperty(const PropertyName &name, int value)
|
Chris@159
|
248 {
|
Chris@159
|
249 if (name == "Colour Scale") {
|
Chris@159
|
250 switch (value) {
|
Chris@159
|
251 default:
|
Chris@159
|
252 case 0: setColourScale(LinearScale); break;
|
Chris@197
|
253 case 1: setColourScale(LogScale); break;
|
Chris@197
|
254 case 2: setColourScale(PlusMinusOneScale); break;
|
Chris@159
|
255 }
|
Chris@197
|
256 } else if (name == "Colour") {
|
Chris@197
|
257 setColourMap(value);
|
Chris@197
|
258 } else if (name == "Normalize Columns") {
|
Chris@197
|
259 setNormalizeColumns(value ? true : false);
|
Chris@197
|
260 } else if (name == "Normalize Visible Area") {
|
Chris@197
|
261 setNormalizeVisibleArea(value ? true : false);
|
Chris@357
|
262 } else if (name == "Invert Vertical Scale") {
|
Chris@357
|
263 setInvertVertical(value ? true : false);
|
Chris@159
|
264 }
|
Chris@159
|
265 }
|
Chris@159
|
266
|
Chris@159
|
267 void
|
Chris@159
|
268 Colour3DPlotLayer::setColourScale(ColourScale scale)
|
Chris@159
|
269 {
|
Chris@159
|
270 if (m_colourScale == scale) return;
|
Chris@159
|
271 m_colourScale = scale;
|
Chris@461
|
272 m_colourScaleSet = true;
|
Chris@159
|
273 cacheInvalid();
|
Chris@159
|
274 emit layerParametersChanged();
|
Chris@159
|
275 }
|
Chris@159
|
276
|
Chris@197
|
277 void
|
Chris@197
|
278 Colour3DPlotLayer::setColourMap(int map)
|
Chris@197
|
279 {
|
Chris@197
|
280 if (m_colourMap == map) return;
|
Chris@197
|
281 m_colourMap = map;
|
Chris@197
|
282 cacheInvalid();
|
Chris@197
|
283 emit layerParametersChanged();
|
Chris@197
|
284 }
|
Chris@197
|
285
|
Chris@197
|
286 void
|
Chris@197
|
287 Colour3DPlotLayer::setNormalizeColumns(bool n)
|
Chris@197
|
288 {
|
Chris@197
|
289 if (m_normalizeColumns == n) return;
|
Chris@197
|
290 m_normalizeColumns = n;
|
Chris@197
|
291 cacheInvalid();
|
Chris@197
|
292 emit layerParametersChanged();
|
Chris@197
|
293 }
|
Chris@197
|
294
|
Chris@197
|
295 bool
|
Chris@197
|
296 Colour3DPlotLayer::getNormalizeColumns() const
|
Chris@197
|
297 {
|
Chris@197
|
298 return m_normalizeColumns;
|
Chris@197
|
299 }
|
Chris@197
|
300
|
Chris@197
|
301 void
|
Chris@197
|
302 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
|
Chris@197
|
303 {
|
Chris@197
|
304 if (m_normalizeVisibleArea == n) return;
|
Chris@197
|
305 m_normalizeVisibleArea = n;
|
Chris@197
|
306 cacheInvalid();
|
Chris@197
|
307 emit layerParametersChanged();
|
Chris@197
|
308 }
|
Chris@197
|
309
|
Chris@197
|
310 bool
|
Chris@197
|
311 Colour3DPlotLayer::getNormalizeVisibleArea() const
|
Chris@197
|
312 {
|
Chris@197
|
313 return m_normalizeVisibleArea;
|
Chris@197
|
314 }
|
Chris@197
|
315
|
Chris@357
|
316 void
|
Chris@357
|
317 Colour3DPlotLayer::setInvertVertical(bool n)
|
Chris@357
|
318 {
|
Chris@357
|
319 if (m_invertVertical == n) return;
|
Chris@357
|
320 m_invertVertical = n;
|
Chris@357
|
321 cacheInvalid();
|
Chris@357
|
322 emit layerParametersChanged();
|
Chris@357
|
323 }
|
Chris@357
|
324
|
Chris@357
|
325 bool
|
Chris@357
|
326 Colour3DPlotLayer::getInvertVertical() const
|
Chris@357
|
327 {
|
Chris@357
|
328 return m_invertVertical;
|
Chris@357
|
329 }
|
Chris@357
|
330
|
Chris@25
|
331 bool
|
Chris@44
|
332 Colour3DPlotLayer::isLayerScrollable(const View *v) const
|
Chris@25
|
333 {
|
Chris@197
|
334 if (m_normalizeVisibleArea) return false;
|
Chris@25
|
335 QPoint discard;
|
Chris@44
|
336 return !v->shouldIlluminateLocalFeatures(this, discard);
|
Chris@25
|
337 }
|
Chris@25
|
338
|
Chris@444
|
339 bool
|
Chris@444
|
340 Colour3DPlotLayer::getValueExtents(float &min, float &max,
|
Chris@444
|
341 bool &logarithmic, QString &unit) const
|
Chris@444
|
342 {
|
Chris@444
|
343 if (!m_model) return false;
|
Chris@444
|
344
|
Chris@444
|
345 min = 0;
|
Chris@444
|
346 max = m_model->getHeight();
|
Chris@444
|
347
|
Chris@444
|
348 logarithmic = false;
|
Chris@444
|
349 unit = "";
|
Chris@444
|
350
|
Chris@444
|
351 return true;
|
Chris@444
|
352 }
|
Chris@444
|
353
|
Chris@444
|
354 bool
|
Chris@444
|
355 Colour3DPlotLayer::getDisplayExtents(float &min, float &max) const
|
Chris@444
|
356 {
|
Chris@444
|
357 if (!m_model) return false;
|
Chris@444
|
358
|
Chris@444
|
359 min = m_miny;
|
Chris@444
|
360 max = m_maxy;
|
Chris@444
|
361 if (max <= min) {
|
Chris@444
|
362 min = 0;
|
Chris@444
|
363 max = m_model->getHeight();
|
Chris@444
|
364 }
|
Chris@444
|
365 if (min < 0) min = 0;
|
Chris@444
|
366 if (max > m_model->getHeight()) max = m_model->getHeight();
|
Chris@444
|
367
|
Chris@444
|
368 return true;
|
Chris@444
|
369 }
|
Chris@444
|
370
|
Chris@444
|
371 bool
|
Chris@444
|
372 Colour3DPlotLayer::setDisplayExtents(float min, float max)
|
Chris@444
|
373 {
|
Chris@444
|
374 if (!m_model) return false;
|
Chris@444
|
375
|
Chris@444
|
376 m_miny = lrintf(min);
|
Chris@444
|
377 m_maxy = lrintf(max);
|
Chris@444
|
378
|
Chris@444
|
379 emit layerParametersChanged();
|
Chris@444
|
380 return true;
|
Chris@444
|
381 }
|
Chris@444
|
382
|
Chris@444
|
383 int
|
Chris@444
|
384 Colour3DPlotLayer::getVerticalZoomSteps(int &defaultStep) const
|
Chris@444
|
385 {
|
Chris@444
|
386 if (!m_model) return 0;
|
Chris@444
|
387
|
Chris@444
|
388 defaultStep = 0;
|
Chris@444
|
389 int h = m_model->getHeight();
|
Chris@444
|
390 return h;
|
Chris@444
|
391 }
|
Chris@444
|
392
|
Chris@444
|
393 int
|
Chris@444
|
394 Colour3DPlotLayer::getCurrentVerticalZoomStep() const
|
Chris@444
|
395 {
|
Chris@444
|
396 if (!m_model) return 0;
|
Chris@444
|
397
|
Chris@444
|
398 float min, max;
|
Chris@444
|
399 getDisplayExtents(min, max);
|
Chris@444
|
400 return m_model->getHeight() - lrintf(max - min);
|
Chris@444
|
401 }
|
Chris@444
|
402
|
Chris@444
|
403 void
|
Chris@444
|
404 Colour3DPlotLayer::setVerticalZoomStep(int step)
|
Chris@444
|
405 {
|
Chris@444
|
406 if (!m_model) return;
|
Chris@444
|
407
|
Chris@445
|
408 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): before: miny = " << m_miny << ", maxy = " << m_maxy << std::endl;
|
Chris@444
|
409
|
Chris@444
|
410 int dist = m_model->getHeight() - step;
|
Chris@444
|
411 if (dist < 1) dist = 1;
|
Chris@444
|
412 float centre = m_miny + (float(m_maxy) - float(m_miny)) / 2.f;
|
Chris@444
|
413 m_miny = lrintf(centre - float(dist)/2);
|
Chris@444
|
414 if (m_miny < 0) m_miny = 0;
|
Chris@444
|
415 m_maxy = m_miny + dist;
|
Chris@444
|
416 if (m_maxy > m_model->getHeight()) m_maxy = m_model->getHeight();
|
Chris@444
|
417
|
Chris@445
|
418 // std::cerr << "Colour3DPlotLayer::setVerticalZoomStep(" <<step <<"): after: miny = " << m_miny << ", maxy = " << m_maxy << std::endl;
|
Chris@444
|
419
|
Chris@444
|
420 emit layerParametersChanged();
|
Chris@444
|
421 }
|
Chris@444
|
422
|
Chris@444
|
423 RangeMapper *
|
Chris@444
|
424 Colour3DPlotLayer::getNewVerticalZoomRangeMapper() const
|
Chris@444
|
425 {
|
Chris@444
|
426 if (!m_model) return 0;
|
Chris@444
|
427
|
Chris@444
|
428 return new LinearRangeMapper(0, m_model->getHeight(),
|
Chris@444
|
429 0, m_model->getHeight(), "");
|
Chris@444
|
430 }
|
Chris@444
|
431
|
Chris@25
|
432 QString
|
Chris@44
|
433 Colour3DPlotLayer::getFeatureDescription(View *v, QPoint &pos) const
|
Chris@25
|
434 {
|
Chris@25
|
435 if (!m_model) return "";
|
Chris@25
|
436
|
Chris@25
|
437 int x = pos.x();
|
Chris@25
|
438 int y = pos.y();
|
Chris@25
|
439
|
Chris@25
|
440 size_t modelStart = m_model->getStartFrame();
|
Chris@130
|
441 size_t modelResolution = m_model->getResolution();
|
Chris@25
|
442
|
Chris@159
|
443 float srRatio =
|
Chris@159
|
444 float(v->getViewManager()->getMainModelSampleRate()) /
|
Chris@159
|
445 float(m_model->getSampleRate());
|
Chris@159
|
446
|
Chris@160
|
447 int sx0 = int((v->getFrameForX(x) / srRatio - long(modelStart)) /
|
Chris@160
|
448 long(modelResolution));
|
Chris@25
|
449
|
Chris@160
|
450 int f0 = sx0 * modelResolution;
|
Chris@160
|
451 int f1 = f0 + modelResolution;
|
Chris@160
|
452
|
Chris@447
|
453 int sh = m_model->getHeight();
|
Chris@447
|
454
|
Chris@447
|
455 int symin = m_miny;
|
Chris@447
|
456 int symax = m_maxy;
|
Chris@447
|
457 if (symax <= symin) {
|
Chris@447
|
458 symin = 0;
|
Chris@447
|
459 symax = sh;
|
Chris@447
|
460 }
|
Chris@447
|
461 if (symin < 0) symin = 0;
|
Chris@447
|
462 if (symax > sh) symax = sh;
|
Chris@447
|
463
|
Chris@447
|
464 float binHeight = float(v->height()) / (symax - symin);
|
Chris@447
|
465 int sy = int((v->height() - y) / binHeight) + symin;
|
Chris@25
|
466
|
Chris@357
|
467 if (m_invertVertical) sy = m_model->getHeight() - sy - 1;
|
Chris@357
|
468
|
Chris@160
|
469 float value = m_model->getValueAt(sx0, sy);
|
Chris@159
|
470
|
Chris@159
|
471 // std::cerr << "bin value (" << sx0 << "," << sy << ") is " << value << std::endl;
|
Chris@25
|
472
|
Chris@25
|
473 QString binName = m_model->getBinName(sy);
|
Chris@25
|
474 if (binName == "") binName = QString("[%1]").arg(sy + 1);
|
Chris@25
|
475 else binName = QString("%1 [%2]").arg(binName).arg(sy + 1);
|
Chris@25
|
476
|
Chris@25
|
477 QString text = tr("Time:\t%1 - %2\nBin:\t%3\nValue:\t%4")
|
Chris@160
|
478 .arg(RealTime::frame2RealTime(f0, m_model->getSampleRate())
|
Chris@25
|
479 .toText(true).c_str())
|
Chris@160
|
480 .arg(RealTime::frame2RealTime(f1, m_model->getSampleRate())
|
Chris@25
|
481 .toText(true).c_str())
|
Chris@25
|
482 .arg(binName)
|
Chris@25
|
483 .arg(value);
|
Chris@25
|
484
|
Chris@25
|
485 return text;
|
Chris@25
|
486 }
|
Chris@25
|
487
|
Chris@25
|
488 int
|
Chris@248
|
489 Colour3DPlotLayer::getColourScaleWidth(QPainter &) const
|
Chris@159
|
490 {
|
Chris@159
|
491 int cw = 20;
|
Chris@159
|
492 return cw;
|
Chris@159
|
493 }
|
Chris@159
|
494
|
Chris@159
|
495 int
|
Chris@248
|
496 Colour3DPlotLayer::getVerticalScaleWidth(View *, QPainter &paint) const
|
Chris@25
|
497 {
|
Chris@25
|
498 if (!m_model) return 0;
|
Chris@25
|
499
|
Chris@160
|
500 QString sampleText = QString("[%1]").arg(m_model->getHeight());
|
Chris@25
|
501 int tw = paint.fontMetrics().width(sampleText);
|
Chris@98
|
502 bool another = false;
|
Chris@25
|
503
|
Chris@160
|
504 for (size_t i = 0; i < m_model->getHeight(); ++i) {
|
Chris@25
|
505 if (m_model->getBinName(i).length() > sampleText.length()) {
|
Chris@25
|
506 sampleText = m_model->getBinName(i);
|
Chris@98
|
507 another = true;
|
Chris@25
|
508 }
|
Chris@25
|
509 }
|
Chris@98
|
510 if (another) {
|
Chris@25
|
511 tw = std::max(tw, paint.fontMetrics().width(sampleText));
|
Chris@25
|
512 }
|
Chris@25
|
513
|
Chris@159
|
514 return tw + 13 + getColourScaleWidth(paint);
|
Chris@25
|
515 }
|
Chris@25
|
516
|
Chris@25
|
517 void
|
Chris@44
|
518 Colour3DPlotLayer::paintVerticalScale(View *v, QPainter &paint, QRect rect) const
|
Chris@25
|
519 {
|
Chris@25
|
520 if (!m_model) return;
|
Chris@25
|
521
|
Chris@25
|
522 int h = rect.height(), w = rect.width();
|
Chris@25
|
523
|
Chris@159
|
524 int cw = getColourScaleWidth(paint);
|
Chris@159
|
525
|
Chris@159
|
526 int ch = h - 20;
|
Chris@159
|
527 if (ch > 20 && m_cache) {
|
Chris@159
|
528
|
Chris@447
|
529 float min = m_model->getMinimumLevel();
|
Chris@447
|
530 float max = m_model->getMaximumLevel();
|
Chris@447
|
531
|
Chris@447
|
532 float mmin = min;
|
Chris@447
|
533 float mmax = max;
|
Chris@447
|
534
|
Chris@447
|
535 if (m_colourScale == LogScale) {
|
Chris@447
|
536 LogRange::mapRange(mmin, mmax);
|
Chris@447
|
537 } else if (m_colourScale == PlusMinusOneScale) {
|
Chris@447
|
538 mmin = -1.f;
|
Chris@447
|
539 mmax = 1.f;
|
Chris@447
|
540 }
|
Chris@447
|
541
|
Chris@447
|
542 if (max == min) max = min + 1.0;
|
Chris@447
|
543
|
Chris@287
|
544 paint.setPen(v->getForeground());
|
Chris@447
|
545 paint.drawRect(4, 10, cw - 8, ch+1);
|
Chris@159
|
546
|
Chris@446
|
547 for (int y = 0; y < ch; ++y) {
|
Chris@447
|
548 float value = ((max - min) * (ch - y - 1)) / ch + min;
|
Chris@447
|
549 if (m_colourScale == LogScale) {
|
Chris@447
|
550 value = LogRange::map(value);
|
Chris@447
|
551 }
|
Chris@447
|
552 int pixel = int(((value - mmin) * 256) / (mmax - mmin));
|
Chris@447
|
553 QRgb c = m_cache->color(pixel);
|
Chris@447
|
554 // QRgb c = m_cache->color(((ch - y) * 255) / ch);
|
Chris@159
|
555 paint.setPen(QColor(qRed(c), qGreen(c), qBlue(c)));
|
Chris@159
|
556 paint.drawLine(5, 11 + y, cw - 5, 11 + y);
|
Chris@159
|
557 }
|
Chris@446
|
558
|
Chris@446
|
559 QString minstr = QString("%1").arg(min);
|
Chris@446
|
560 QString maxstr = QString("%1").arg(max);
|
Chris@446
|
561
|
Chris@446
|
562 paint.save();
|
Chris@446
|
563
|
Chris@446
|
564 QFont font = paint.font();
|
Chris@446
|
565 font.setPixelSize(10);
|
Chris@446
|
566 paint.setFont(font);
|
Chris@446
|
567
|
Chris@446
|
568 int msw = paint.fontMetrics().width(maxstr);
|
Chris@446
|
569
|
Chris@446
|
570 QMatrix m;
|
Chris@446
|
571 m.translate(cw - 6, ch + 10);
|
Chris@446
|
572 m.rotate(-90);
|
Chris@446
|
573
|
Chris@446
|
574 paint.setWorldMatrix(m);
|
Chris@446
|
575
|
Chris@446
|
576 v->drawVisibleText(paint, 2, 0, minstr, View::OutlinedText);
|
Chris@446
|
577
|
Chris@446
|
578 m.translate(ch - msw - 2, 0);
|
Chris@446
|
579 paint.setWorldMatrix(m);
|
Chris@446
|
580
|
Chris@446
|
581 v->drawVisibleText(paint, 0, 0, maxstr, View::OutlinedText);
|
Chris@446
|
582
|
Chris@446
|
583 paint.restore();
|
Chris@159
|
584 }
|
Chris@159
|
585
|
Chris@287
|
586 paint.setPen(v->getForeground());
|
Chris@159
|
587
|
Chris@445
|
588 int sh = m_model->getHeight();
|
Chris@445
|
589
|
Chris@445
|
590 int symin = m_miny;
|
Chris@445
|
591 int symax = m_maxy;
|
Chris@445
|
592 if (symax <= symin) {
|
Chris@445
|
593 symin = 0;
|
Chris@445
|
594 symax = sh;
|
Chris@445
|
595 }
|
Chris@445
|
596 if (symin < 0) symin = 0;
|
Chris@445
|
597 if (symax > sh) symax = sh;
|
Chris@445
|
598
|
Chris@456
|
599 float binHeight = float(v->height()) / (symax - symin);
|
Chris@456
|
600
|
Chris@456
|
601 paint.save();
|
Chris@456
|
602
|
Chris@456
|
603 QFont tf = paint.font();
|
Chris@456
|
604 if (paint.fontMetrics().height() >= binHeight) {
|
Chris@457
|
605 tf.setPixelSize(binHeight > 7 ? binHeight - 2 : 5);
|
Chris@456
|
606 paint.setFont(tf);
|
Chris@456
|
607 }
|
Chris@456
|
608
|
Chris@98
|
609 int count = v->height() / paint.fontMetrics().height();
|
Chris@445
|
610 int step = (symax - symin) / count;
|
Chris@98
|
611 if (step == 0) step = 1;
|
Chris@25
|
612
|
Chris@445
|
613 for (size_t i = symin; i < symax; ++i) {
|
Chris@25
|
614
|
Chris@357
|
615 size_t idx = i;
|
Chris@357
|
616 if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
|
Chris@357
|
617
|
Chris@357
|
618 if ((idx % step) != 0) continue;
|
Chris@98
|
619
|
Chris@445
|
620 int y0 = int(v->height() - ((i - symin) * binHeight) - 1);
|
Chris@25
|
621
|
Chris@357
|
622 QString text = m_model->getBinName(idx);
|
Chris@357
|
623 if (text == "") text = QString("[%1]").arg(idx + 1);
|
Chris@25
|
624
|
Chris@159
|
625 paint.drawLine(cw, y0, w, y0);
|
Chris@25
|
626
|
Chris@457
|
627 if (step > 1) {
|
Chris@457
|
628 paint.drawLine(w - 1, y0 - (step * binHeight) + 1,
|
Chris@457
|
629 w - 1, y0 - binHeight - 1);
|
Chris@457
|
630 paint.drawLine(w - 2, y0 - (step * binHeight) + 1,
|
Chris@457
|
631 w - 2, y0 - binHeight - 2);
|
Chris@457
|
632 }
|
Chris@457
|
633
|
Chris@248
|
634 int cy = int(y0 - (step * binHeight)/2);
|
Chris@25
|
635 int ty = cy + paint.fontMetrics().ascent()/2;
|
Chris@25
|
636
|
Chris@159
|
637 paint.drawText(cw + 5, ty, text);
|
Chris@25
|
638 }
|
Chris@456
|
639
|
Chris@456
|
640 paint.restore();
|
Chris@25
|
641 }
|
Chris@25
|
642
|
Chris@0
|
643 void
|
Chris@197
|
644 Colour3DPlotLayer::getColumn(size_t col,
|
Chris@197
|
645 DenseThreeDimensionalModel::Column &values) const
|
Chris@197
|
646 {
|
Chris@197
|
647 m_model->getColumn(col, values);
|
Chris@197
|
648
|
Chris@461
|
649 if (!m_normalizeColumns) return;
|
Chris@461
|
650
|
Chris@224
|
651 float colMax = 0.f, colMin = 0.f;
|
Chris@461
|
652 float min = 0.f, max = 0.f;
|
Chris@197
|
653
|
Chris@461
|
654 min = m_model->getMinimumLevel();
|
Chris@461
|
655 max = m_model->getMaximumLevel();
|
Chris@461
|
656
|
Chris@461
|
657 for (size_t y = 0; y < values.size(); ++y) {
|
Chris@461
|
658 if (y == 0 || values[y] > colMax) colMax = values[y];
|
Chris@461
|
659 if (y == 0 || values[y] < colMin) colMin = values[y];
|
Chris@197
|
660 }
|
Chris@461
|
661 if (colMin == colMax) colMax = colMin + 1;
|
Chris@197
|
662
|
Chris@197
|
663 for (size_t y = 0; y < values.size(); ++y) {
|
Chris@461
|
664
|
Chris@461
|
665 float value = values[y];
|
Chris@461
|
666 float norm = (value - colMin) / (colMax - colMin);
|
Chris@461
|
667 value = min + (max - min) * norm;
|
Chris@197
|
668
|
Chris@197
|
669 values[y] = value;
|
Chris@197
|
670 }
|
Chris@197
|
671 }
|
Chris@197
|
672
|
Chris@197
|
673 void
|
Chris@197
|
674 Colour3DPlotLayer::fillCache(size_t firstBin, size_t lastBin) const
|
Chris@197
|
675 {
|
Chris@197
|
676 size_t modelStart = m_model->getStartFrame();
|
Chris@197
|
677 size_t modelEnd = m_model->getEndFrame();
|
Chris@197
|
678 size_t modelResolution = m_model->getResolution();
|
Chris@197
|
679
|
Chris@224
|
680 // std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl;
|
Chris@197
|
681
|
Chris@461
|
682 size_t modelStartBin = modelStart / modelResolution;
|
Chris@461
|
683 size_t modelEndBin = modelEnd / modelResolution;
|
Chris@461
|
684
|
Chris@461
|
685 size_t cacheWidth = modelEndBin - modelStartBin + 1;
|
Chris@461
|
686 size_t cacheHeight = m_model->getHeight();
|
Chris@461
|
687
|
Chris@461
|
688 if (m_cache && (m_cache->height() != int(cacheHeight))) {
|
Chris@461
|
689 delete m_cache;
|
Chris@461
|
690 m_cache = 0;
|
Chris@461
|
691 }
|
Chris@461
|
692
|
Chris@461
|
693 if (m_cache && (m_cache->width() != int(cacheWidth))) {
|
Chris@461
|
694 QImage *newCache = new QImage(m_cache->copy(0, 0, cacheWidth, cacheHeight));
|
Chris@461
|
695 delete m_cache;
|
Chris@461
|
696 m_cache = newCache;
|
Chris@197
|
697 }
|
Chris@197
|
698
|
Chris@461
|
699 if (!m_cache) {
|
Chris@461
|
700 m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
|
Chris@461
|
701 m_cache->setNumColors(256);
|
Chris@461
|
702 m_cacheValidStart = 0;
|
Chris@461
|
703 m_cacheValidEnd = 0;
|
Chris@197
|
704 }
|
Chris@197
|
705
|
Chris@461
|
706 if (m_cacheValidStart <= firstBin && m_cacheValidEnd >= lastBin) {
|
Chris@461
|
707 return;
|
Chris@461
|
708 }
|
Chris@461
|
709
|
Chris@461
|
710 size_t fillStart = firstBin;
|
Chris@461
|
711 size_t fillEnd = lastBin;
|
Chris@197
|
712
|
Chris@461
|
713 if (fillStart < modelStartBin) fillStart = modelStartBin;
|
Chris@461
|
714 if (fillStart > modelEndBin) fillStart = modelEndBin;
|
Chris@461
|
715 if (fillEnd < modelStartBin) fillEnd = modelStartBin;
|
Chris@461
|
716 if (fillEnd > modelEndBin) fillEnd = modelEndBin;
|
Chris@197
|
717
|
Chris@461
|
718 bool normalizeVisible = (m_normalizeVisibleArea && !m_normalizeColumns);
|
Chris@197
|
719
|
Chris@461
|
720 if (!normalizeVisible && (m_cacheValidStart < m_cacheValidEnd)) {
|
Chris@461
|
721
|
Chris@461
|
722 if (m_cacheValidEnd < fillStart) {
|
Chris@461
|
723 fillStart = m_cacheValidEnd + 1;
|
Chris@461
|
724 }
|
Chris@461
|
725 if (m_cacheValidStart > fillEnd) {
|
Chris@461
|
726 fillEnd = m_cacheValidStart - 1;
|
Chris@461
|
727 }
|
Chris@461
|
728
|
Chris@461
|
729 m_cacheValidStart = std::min(fillStart, m_cacheValidStart);
|
Chris@461
|
730 m_cacheValidEnd = std::max(fillEnd, m_cacheValidEnd);
|
Chris@461
|
731
|
Chris@461
|
732 } else {
|
Chris@461
|
733
|
Chris@461
|
734 // the only valid area, ever, is the currently visible one
|
Chris@461
|
735
|
Chris@461
|
736 m_cacheValidStart = fillStart;
|
Chris@461
|
737 m_cacheValidEnd = fillEnd;
|
Chris@461
|
738 }
|
Chris@461
|
739
|
Chris@461
|
740 // std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " will be valid from " << m_cacheValidStart << " to " << m_cacheValidEnd << std::endl;
|
Chris@461
|
741
|
Chris@197
|
742 DenseThreeDimensionalModel::Column values;
|
Chris@461
|
743 values.reserve(cacheHeight);
|
Chris@197
|
744
|
Chris@197
|
745 float min = m_model->getMinimumLevel();
|
Chris@197
|
746 float max = m_model->getMaximumLevel();
|
Chris@197
|
747
|
Chris@197
|
748 if (m_colourScale == LogScale) {
|
Chris@197
|
749 LogRange::mapRange(min, max);
|
Chris@197
|
750 } else if (m_colourScale == PlusMinusOneScale) {
|
Chris@197
|
751 min = -1.f;
|
Chris@197
|
752 max = 1.f;
|
Chris@197
|
753 }
|
Chris@197
|
754
|
Chris@197
|
755 if (max == min) max = min + 1.0;
|
Chris@197
|
756
|
Chris@197
|
757 ColourMapper mapper(m_colourMap, 0.f, 255.f);
|
Chris@197
|
758
|
Chris@197
|
759 for (int index = 0; index < 256; ++index) {
|
Chris@197
|
760 QColor colour = mapper.map(index);
|
Chris@197
|
761 m_cache->setColor(index, qRgb(colour.red(), colour.green(), colour.blue()));
|
Chris@197
|
762 }
|
Chris@197
|
763
|
Chris@461
|
764 // m_cache->fill(0);
|
Chris@197
|
765
|
Chris@224
|
766 float visibleMax = 0.f, visibleMin = 0.f;
|
Chris@197
|
767
|
Chris@461
|
768 if (normalizeVisible) {
|
Chris@197
|
769
|
Chris@461
|
770 for (size_t c = fillStart; c <= fillEnd; ++c) {
|
Chris@197
|
771
|
Chris@197
|
772 values.clear();
|
Chris@197
|
773 getColumn(c, values);
|
Chris@197
|
774
|
Chris@224
|
775 float colMax = 0.f, colMin = 0.f;
|
Chris@197
|
776
|
Chris@461
|
777 for (size_t y = 0; y < cacheHeight; ++y) {
|
Chris@197
|
778 if (y >= values.size()) break;
|
Chris@197
|
779 if (y == 0 || values[y] > colMax) colMax = values[y];
|
Chris@224
|
780 if (y == 0 || values[y] < colMin) colMin = values[y];
|
Chris@197
|
781 }
|
Chris@197
|
782
|
Chris@461
|
783 if (c == fillStart || colMax > visibleMax) visibleMax = colMax;
|
Chris@461
|
784 if (c == fillStart || colMin < visibleMin) visibleMin = colMin;
|
Chris@461
|
785 }
|
Chris@461
|
786
|
Chris@461
|
787 if (m_colourScale == LogScale) {
|
Chris@461
|
788 visibleMin = LogRange::map(visibleMin);
|
Chris@461
|
789 visibleMax = LogRange::map(visibleMax);
|
Chris@461
|
790 if (visibleMin > visibleMax) std::swap(visibleMin, visibleMax);
|
Chris@197
|
791 }
|
Chris@197
|
792 }
|
Chris@197
|
793
|
Chris@224
|
794 if (visibleMin == visibleMax) visibleMax = visibleMin + 1;
|
Chris@224
|
795
|
Chris@461
|
796 for (size_t c = fillStart; c <= fillEnd; ++c) {
|
Chris@197
|
797
|
Chris@197
|
798 values.clear();
|
Chris@197
|
799 getColumn(c, values);
|
Chris@197
|
800
|
Chris@461
|
801 for (size_t y = 0; y < cacheHeight; ++y) {
|
Chris@197
|
802
|
Chris@197
|
803 float value = min;
|
Chris@197
|
804 if (y < values.size()) {
|
Chris@197
|
805 value = values[y];
|
Chris@197
|
806 }
|
Chris@224
|
807
|
Chris@224
|
808 if (m_colourScale == LogScale) {
|
Chris@224
|
809 value = LogRange::map(value);
|
Chris@197
|
810 }
|
Chris@461
|
811
|
Chris@461
|
812 if (normalizeVisible) {
|
Chris@461
|
813 float norm = (value - visibleMin) / (visibleMax - visibleMin);
|
Chris@461
|
814 value = min + (max - min) * norm;
|
Chris@461
|
815 }
|
Chris@197
|
816
|
Chris@197
|
817 int pixel = int(((value - min) * 256) / (max - min));
|
Chris@197
|
818 if (pixel < 0) pixel = 0;
|
Chris@197
|
819 if (pixel > 255) pixel = 255;
|
Chris@197
|
820
|
Chris@357
|
821 if (m_invertVertical) {
|
Chris@461
|
822 m_cache->setPixel(c, cacheHeight - y - 1, pixel);
|
Chris@357
|
823 } else {
|
Chris@461
|
824 m_cache->setPixel(c, y, pixel);
|
Chris@357
|
825 }
|
Chris@197
|
826 }
|
Chris@197
|
827 }
|
Chris@197
|
828 }
|
Chris@197
|
829
|
Chris@197
|
830 void
|
Chris@44
|
831 Colour3DPlotLayer::paint(View *v, QPainter &paint, QRect rect) const
|
Chris@0
|
832 {
|
Chris@443
|
833 /*!!!
|
Chris@443
|
834 if (m_model) {
|
Chris@443
|
835 std::cerr << "Colour3DPlotLayer::paint: model says shouldUseLogValueScale = " << m_model->shouldUseLogValueScale() << std::endl;
|
Chris@443
|
836 }
|
Chris@443
|
837 */
|
Chris@0
|
838 // Profiler profiler("Colour3DPlotLayer::paint");
|
Chris@125
|
839 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@125
|
840 std::cerr << "Colour3DPlotLayer::paint(): m_model is " << m_model << ", zoom level is " << v->getZoomLevel() << std::endl;
|
Chris@125
|
841 #endif
|
Chris@0
|
842
|
Chris@0
|
843 int completion = 0;
|
Chris@0
|
844 if (!m_model || !m_model->isOK() || !m_model->isReady(&completion)) {
|
Chris@0
|
845 if (completion > 0) {
|
Chris@44
|
846 paint.fillRect(0, 10, v->width() * completion / 100,
|
Chris@0
|
847 10, QColor(120, 120, 120));
|
Chris@0
|
848 }
|
Chris@0
|
849 return;
|
Chris@0
|
850 }
|
Chris@0
|
851
|
Chris@197
|
852 if (m_normalizeVisibleArea && !m_normalizeColumns) rect = v->rect();
|
Chris@197
|
853
|
Chris@0
|
854 size_t modelStart = m_model->getStartFrame();
|
Chris@0
|
855 size_t modelEnd = m_model->getEndFrame();
|
Chris@130
|
856 size_t modelResolution = m_model->getResolution();
|
Chris@0
|
857
|
Chris@197
|
858 // The cache is from the model's start frame to the model's end
|
Chris@197
|
859 // frame at the model's window increment frames per pixel. We
|
Chris@197
|
860 // want to draw from our start frame + x0 * zoomLevel to our start
|
Chris@197
|
861 // frame + x1 * zoomLevel at zoomLevel frames per pixel.
|
Chris@12
|
862
|
Chris@197
|
863 // We have quite different paint mechanisms for rendering "large"
|
Chris@197
|
864 // bins (more than one bin per pixel in both directions) and
|
Chris@197
|
865 // "small". This is "large"; see paintDense below for "small".
|
Chris@12
|
866
|
Chris@197
|
867 int x0 = rect.left();
|
Chris@197
|
868 int x1 = rect.right() + 1;
|
Chris@12
|
869
|
Chris@197
|
870 int h = v->height();
|
Chris@0
|
871
|
Chris@197
|
872 float srRatio =
|
Chris@197
|
873 float(v->getViewManager()->getMainModelSampleRate()) /
|
Chris@197
|
874 float(m_model->getSampleRate());
|
Chris@0
|
875
|
Chris@197
|
876 int sx0 = int((v->getFrameForX(x0) / srRatio - long(modelStart))
|
Chris@197
|
877 / long(modelResolution));
|
Chris@197
|
878 int sx1 = int((v->getFrameForX(x1) / srRatio - long(modelStart))
|
Chris@197
|
879 / long(modelResolution));
|
Chris@197
|
880 int sh = m_model->getHeight();
|
Chris@159
|
881
|
Chris@444
|
882 int symin = m_miny;
|
Chris@444
|
883 int symax = m_maxy;
|
Chris@444
|
884 if (symax <= symin) {
|
Chris@444
|
885 symin = 0;
|
Chris@444
|
886 symax = sh;
|
Chris@444
|
887 }
|
Chris@444
|
888 if (symin < 0) symin = 0;
|
Chris@444
|
889 if (symax > sh) symax = sh;
|
Chris@444
|
890
|
Chris@197
|
891 if (sx0 > 0) --sx0;
|
Chris@197
|
892 fillCache(sx0 < 0 ? 0 : sx0,
|
Chris@197
|
893 sx1 < 0 ? 0 : sx1);
|
Chris@0
|
894
|
Chris@351
|
895 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@351
|
896 std::cerr << "Colour3DPlotLayer::paint: height = "<< m_model->getHeight() << ", modelStart = " << modelStart << ", resolution = " << modelResolution << ", model rate = " << m_model->getSampleRate() << std::endl;
|
Chris@351
|
897 #endif
|
Chris@351
|
898
|
Chris@248
|
899 if (int(m_model->getHeight()) >= v->height() ||
|
Chris@348
|
900 int(modelResolution * m_model->getSampleRate()) < v->getZoomLevel() / 2) {
|
Chris@347
|
901 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@351
|
902 std::cerr << "calling paintDense" << std::endl;
|
Chris@347
|
903 #endif
|
Chris@98
|
904 paintDense(v, paint, rect);
|
Chris@98
|
905 return;
|
Chris@98
|
906 }
|
Chris@98
|
907
|
Chris@125
|
908 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@347
|
909 std::cerr << "Colour3DPlotLayer::paint: w " << x1-x0 << ", h " << h << ", sx0 " << sx0 << ", sx1 " << sx1 << ", sw " << sx1-sx0 << ", sh " << sh << std::endl;
|
Chris@130
|
910 std::cerr << "Colour3DPlotLayer: sample rate is " << m_model->getSampleRate() << ", resolution " << m_model->getResolution() << std::endl;
|
Chris@125
|
911 #endif
|
Chris@0
|
912
|
Chris@25
|
913 QPoint illuminatePos;
|
Chris@44
|
914 bool illuminate = v->shouldIlluminateLocalFeatures(this, illuminatePos);
|
Chris@54
|
915 char labelbuf[10];
|
Chris@25
|
916
|
Chris@197
|
917 for (int sx = sx0; sx <= sx1; ++sx) {
|
Chris@0
|
918
|
Chris@130
|
919 int fx = sx * int(modelResolution);
|
Chris@0
|
920
|
Chris@351
|
921 if (fx + int(modelResolution) <= int(modelStart) ||
|
Chris@0
|
922 fx > int(modelEnd)) continue;
|
Chris@0
|
923
|
Chris@248
|
924 int rx0 = v->getXForFrame(int((fx + int(modelStart)) * srRatio));
|
Chris@248
|
925 int rx1 = v->getXForFrame(int((fx + int(modelStart) + int(modelResolution) + 1) * srRatio));
|
Chris@54
|
926
|
Chris@159
|
927 int rw = rx1 - rx0;
|
Chris@159
|
928 if (rw < 1) rw = 1;
|
Chris@54
|
929
|
Chris@159
|
930 bool showLabel = (rw > 10 &&
|
Chris@159
|
931 paint.fontMetrics().width("0.000000") < rw - 3 &&
|
Chris@54
|
932 paint.fontMetrics().height() < (h / sh));
|
Chris@98
|
933
|
Chris@444
|
934 for (int sy = symin; sy < symax; ++sy) {
|
Chris@0
|
935
|
Chris@444
|
936 int ry0 = h - ((sy - symin) * h) / (symax - symin) - 1;
|
Chris@0
|
937 QRgb pixel = qRgb(255, 255, 255);
|
Chris@461
|
938 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@0
|
939 sy >= 0 && sy < m_cache->height()) {
|
Chris@461
|
940 pixel = m_cache->pixel(sx, sy);
|
Chris@0
|
941 }
|
Chris@0
|
942
|
Chris@444
|
943 QRect r(rx0, ry0 - h / (symax - symin) - 1,
|
Chris@444
|
944 rw, h / (symax - symin) + 1);
|
Chris@159
|
945
|
Chris@159
|
946 if (rw == 1) {
|
Chris@159
|
947 paint.setPen(pixel);
|
Chris@159
|
948 paint.setBrush(Qt::NoBrush);
|
Chris@159
|
949 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
|
Chris@159
|
950 continue;
|
Chris@159
|
951 }
|
Chris@159
|
952
|
Chris@0
|
953 QColor pen(255, 255, 255, 80);
|
Chris@0
|
954 QColor brush(pixel);
|
Chris@159
|
955
|
Chris@159
|
956 if (rw > 3 && r.height() > 3) {
|
Chris@159
|
957 brush.setAlpha(160);
|
Chris@159
|
958 }
|
Chris@159
|
959
|
Chris@0
|
960 paint.setPen(Qt::NoPen);
|
Chris@0
|
961 paint.setBrush(brush);
|
Chris@0
|
962
|
Chris@25
|
963 if (illuminate) {
|
Chris@25
|
964 if (r.contains(illuminatePos)) {
|
Chris@287
|
965 paint.setPen(v->getForeground());
|
Chris@25
|
966 }
|
Chris@25
|
967 }
|
Chris@76
|
968
|
Chris@125
|
969 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@159
|
970 std::cerr << "rect " << r.x() << "," << r.y() << " "
|
Chris@159
|
971 << r.width() << "x" << r.height() << std::endl;
|
Chris@125
|
972 #endif
|
Chris@25
|
973
|
Chris@25
|
974 paint.drawRect(r);
|
Chris@0
|
975
|
Chris@54
|
976 if (showLabel) {
|
Chris@461
|
977 if (sx >= 0 && sx < m_cache->width() &&
|
Chris@54
|
978 sy >= 0 && sy < m_cache->height()) {
|
Chris@461
|
979 float value = m_model->getValueAt(sx, sy);
|
Chris@54
|
980 sprintf(labelbuf, "%06f", value);
|
Chris@54
|
981 QString text(labelbuf);
|
Chris@287
|
982 paint.setPen(v->getBackground());
|
Chris@54
|
983 paint.drawText(rx0 + 2,
|
Chris@54
|
984 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
|
Chris@54
|
985 text);
|
Chris@0
|
986 }
|
Chris@0
|
987 }
|
Chris@0
|
988 }
|
Chris@0
|
989 }
|
Chris@98
|
990 }
|
Chris@0
|
991
|
Chris@98
|
992 void
|
Chris@98
|
993 Colour3DPlotLayer::paintDense(View *v, QPainter &paint, QRect rect) const
|
Chris@98
|
994 {
|
Chris@98
|
995 size_t modelStart = m_model->getStartFrame();
|
Chris@130
|
996 size_t modelResolution = m_model->getResolution();
|
Chris@0
|
997
|
Chris@159
|
998 float srRatio =
|
Chris@159
|
999 float(v->getViewManager()->getMainModelSampleRate()) /
|
Chris@159
|
1000 float(m_model->getSampleRate());
|
Chris@159
|
1001
|
Chris@98
|
1002 int x0 = rect.left();
|
Chris@98
|
1003 int x1 = rect.right() + 1;
|
Chris@0
|
1004
|
Chris@98
|
1005 int w = x1 - x0;
|
Chris@98
|
1006 int h = v->height();
|
Chris@160
|
1007 int sh = m_model->getHeight();
|
Chris@98
|
1008
|
Chris@444
|
1009 int symin = m_miny;
|
Chris@444
|
1010 int symax = m_maxy;
|
Chris@444
|
1011 if (symax <= symin) {
|
Chris@444
|
1012 symin = 0;
|
Chris@444
|
1013 symax = sh;
|
Chris@444
|
1014 }
|
Chris@444
|
1015 if (symin < 0) symin = 0;
|
Chris@444
|
1016 if (symax > sh) symax = sh;
|
Chris@444
|
1017
|
Chris@98
|
1018 QImage img(w, h, QImage::Format_RGB32);
|
Chris@98
|
1019
|
Chris@98
|
1020 for (int x = x0; x < x1; ++x) {
|
Chris@98
|
1021
|
Chris@347
|
1022 long xf = long(v->getFrameForX(x));
|
Chris@105
|
1023 if (xf < 0) {
|
Chris@105
|
1024 for (int y = 0; y < h; ++y) {
|
Chris@105
|
1025 img.setPixel(x - x0, y, m_cache->color(0));
|
Chris@105
|
1026 }
|
Chris@105
|
1027 continue;
|
Chris@105
|
1028 }
|
Chris@105
|
1029
|
Chris@347
|
1030 xf /= srRatio;
|
Chris@347
|
1031
|
Chris@130
|
1032 float sx0 = (float(xf) - modelStart) / modelResolution;
|
Chris@159
|
1033 float sx1 = (float(v->getFrameForX(x+1) / srRatio) - modelStart) / modelResolution;
|
Chris@98
|
1034
|
Chris@98
|
1035 int sx0i = int(sx0 + 0.001);
|
Chris@98
|
1036 int sx1i = int(sx1);
|
Chris@98
|
1037
|
Chris@98
|
1038 for (int y = 0; y < h; ++y) {
|
Chris@98
|
1039
|
Chris@444
|
1040 float sy0 = symin + (float(h - y - 1) * (symax - symin)) / h;
|
Chris@444
|
1041 float sy1 = symin + (float(h - y) * (symax - symin)) / h;
|
Chris@98
|
1042
|
Chris@98
|
1043 int sy0i = int(sy0 + 0.001);
|
Chris@98
|
1044 int sy1i = int(sy1);
|
Chris@98
|
1045
|
Chris@98
|
1046 float mag = 0.0, div = 0.0;
|
Chris@159
|
1047 int max = 0;
|
Chris@98
|
1048
|
Chris@98
|
1049 for (int sx = sx0i; sx <= sx1i; ++sx) {
|
Chris@98
|
1050
|
Chris@461
|
1051 if (sx < 0 || sx >= m_cache->width()) continue;
|
Chris@98
|
1052
|
Chris@98
|
1053 for (int sy = sy0i; sy <= sy1i; ++sy) {
|
Chris@98
|
1054
|
Chris@98
|
1055 if (sy < 0 || sy >= m_cache->height()) continue;
|
Chris@98
|
1056
|
Chris@98
|
1057 float prop = 1.0;
|
Chris@98
|
1058 if (sx == sx0i) prop *= (sx + 1) - sx0;
|
Chris@98
|
1059 if (sx == sx1i) prop *= sx1 - sx;
|
Chris@98
|
1060 if (sy == sy0i) prop *= (sy + 1) - sy0;
|
Chris@98
|
1061 if (sy == sy1i) prop *= sy1 - sy;
|
Chris@98
|
1062
|
Chris@461
|
1063 mag += prop * m_cache->pixelIndex(sx, sy);
|
Chris@461
|
1064 max = std::max(max, m_cache->pixelIndex(sx, sy));
|
Chris@98
|
1065 div += prop;
|
Chris@98
|
1066 }
|
Chris@98
|
1067 }
|
Chris@98
|
1068
|
Chris@98
|
1069 if (div != 0) mag /= div;
|
Chris@98
|
1070 if (mag < 0) mag = 0;
|
Chris@98
|
1071 if (mag > 255) mag = 255;
|
Chris@159
|
1072 if (max < 0) max = 0;
|
Chris@159
|
1073 if (max > 255) max = 255;
|
Chris@98
|
1074
|
Chris@98
|
1075 img.setPixel(x - x0, y, m_cache->color(int(mag + 0.001)));
|
Chris@98
|
1076 }
|
Chris@0
|
1077 }
|
Chris@0
|
1078
|
Chris@98
|
1079 paint.drawImage(x0, 0, img);
|
Chris@0
|
1080 }
|
Chris@0
|
1081
|
Chris@28
|
1082 bool
|
Chris@44
|
1083 Colour3DPlotLayer::snapToFeatureFrame(View *v, int &frame,
|
Chris@28
|
1084 size_t &resolution,
|
Chris@28
|
1085 SnapType snap) const
|
Chris@24
|
1086 {
|
Chris@24
|
1087 if (!m_model) {
|
Chris@44
|
1088 return Layer::snapToFeatureFrame(v, frame, resolution, snap);
|
Chris@24
|
1089 }
|
Chris@24
|
1090
|
Chris@130
|
1091 resolution = m_model->getResolution();
|
Chris@28
|
1092 int left = (frame / resolution) * resolution;
|
Chris@28
|
1093 int right = left + resolution;
|
Chris@28
|
1094
|
Chris@28
|
1095 switch (snap) {
|
Chris@28
|
1096 case SnapLeft: frame = left; break;
|
Chris@28
|
1097 case SnapRight: frame = right; break;
|
Chris@28
|
1098 case SnapNearest:
|
Chris@28
|
1099 case SnapNeighbouring:
|
Chris@28
|
1100 if (frame - left > right - frame) frame = right;
|
Chris@28
|
1101 else frame = left;
|
Chris@28
|
1102 break;
|
Chris@28
|
1103 }
|
Chris@24
|
1104
|
Chris@28
|
1105 return true;
|
Chris@24
|
1106 }
|
Chris@24
|
1107
|
Chris@316
|
1108 void
|
Chris@316
|
1109 Colour3DPlotLayer::toXml(QTextStream &stream,
|
Chris@316
|
1110 QString indent, QString extraAttributes) const
|
Chris@197
|
1111 {
|
Chris@316
|
1112 QString s = QString("scale=\"%1\" "
|
Chris@316
|
1113 "colourScheme=\"%2\" "
|
Chris@316
|
1114 "normalizeColumns=\"%3\" "
|
Chris@445
|
1115 "normalizeVisibleArea=\"%4\" "
|
Chris@445
|
1116 "minY=\"%5\" "
|
Chris@445
|
1117 "maxY=\"%6\" ")
|
Chris@197
|
1118 .arg((int)m_colourScale)
|
Chris@197
|
1119 .arg(m_colourMap)
|
Chris@197
|
1120 .arg(m_normalizeColumns ? "true" : "false")
|
Chris@445
|
1121 .arg(m_normalizeVisibleArea ? "true" : "false")
|
Chris@445
|
1122 .arg(m_miny)
|
Chris@445
|
1123 .arg(m_maxy);
|
Chris@197
|
1124
|
Chris@316
|
1125 Layer::toXml(stream, indent, extraAttributes + " " + s);
|
Chris@197
|
1126 }
|
Chris@197
|
1127
|
Chris@197
|
1128 void
|
Chris@197
|
1129 Colour3DPlotLayer::setProperties(const QXmlAttributes &attributes)
|
Chris@197
|
1130 {
|
Chris@445
|
1131 bool ok = false, alsoOk = false;
|
Chris@197
|
1132
|
Chris@197
|
1133 ColourScale scale = (ColourScale)attributes.value("scale").toInt(&ok);
|
Chris@197
|
1134 if (ok) setColourScale(scale);
|
Chris@197
|
1135
|
Chris@197
|
1136 int colourMap = attributes.value("colourScheme").toInt(&ok);
|
Chris@197
|
1137 if (ok) setColourMap(colourMap);
|
Chris@197
|
1138
|
Chris@197
|
1139 bool normalizeColumns =
|
Chris@197
|
1140 (attributes.value("normalizeColumns").trimmed() == "true");
|
Chris@197
|
1141 setNormalizeColumns(normalizeColumns);
|
Chris@197
|
1142
|
Chris@197
|
1143 bool normalizeVisibleArea =
|
Chris@197
|
1144 (attributes.value("normalizeVisibleArea").trimmed() == "true");
|
Chris@197
|
1145 setNormalizeVisibleArea(normalizeVisibleArea);
|
Chris@445
|
1146
|
Chris@445
|
1147 float min = attributes.value("minY").toFloat(&ok);
|
Chris@445
|
1148 float max = attributes.value("maxY").toFloat(&alsoOk);
|
Chris@445
|
1149 if (ok && alsoOk) setDisplayExtents(min, max);
|
Chris@197
|
1150 }
|
Chris@197
|
1151
|