Chris@1071
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
Chris@1071
|
2
|
Chris@1071
|
3 /*
|
Chris@1071
|
4 Sonic Visualiser
|
Chris@1071
|
5 An audio file viewer and annotation editor.
|
Chris@1071
|
6 Centre for Digital Music, Queen Mary, University of London.
|
Chris@1071
|
7 This file copyright 2006-2016 Chris Cannam and QMUL.
|
Chris@1071
|
8
|
Chris@1071
|
9 This program is free software; you can redistribute it and/or
|
Chris@1071
|
10 modify it under the terms of the GNU General Public License as
|
Chris@1071
|
11 published by the Free Software Foundation; either version 2 of the
|
Chris@1071
|
12 License, or (at your option) any later version. See the file
|
Chris@1071
|
13 COPYING included with this distribution for more information.
|
Chris@1071
|
14 */
|
Chris@1071
|
15
|
Chris@1071
|
16 #include "Colour3DPlotRenderer.h"
|
Chris@1074
|
17 #include "RenderTimer.h"
|
Chris@1071
|
18
|
Chris@1117
|
19 #include "base/Profiler.h"
|
Chris@1117
|
20
|
Chris@1075
|
21 #include "data/model/DenseThreeDimensionalModel.h"
|
Chris@1075
|
22 #include "data/model/Dense3DModelPeakCache.h"
|
Chris@1075
|
23 #include "data/model/FFTModel.h"
|
Chris@1075
|
24
|
Chris@1077
|
25 #include "LayerGeometryProvider.h"
|
Chris@1082
|
26 #include "VerticalBinLayer.h"
|
Chris@1109
|
27 #include "PaintAssistant.h"
|
Chris@1109
|
28
|
Chris@1109
|
29 #include "view/ViewManager.h" // for main model sample rate. Pity
|
Chris@1075
|
30
|
Chris@1079
|
31 #include <vector>
|
Chris@1079
|
32
|
Chris@1120
|
33 #define DEBUG_SPECTROGRAM_REPAINT 1 //!!! name
|
Chris@1094
|
34
|
Chris@1079
|
35 using namespace std;
|
Chris@1079
|
36
|
Chris@1073
|
37 Colour3DPlotRenderer::RenderResult
|
Chris@1113
|
38 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect)
|
Chris@1076
|
39 {
|
Chris@1090
|
40 return render(v, paint, rect, false);
|
Chris@1076
|
41 }
|
Chris@1076
|
42
|
Chris@1076
|
43 Colour3DPlotRenderer::RenderResult
|
Chris@1113
|
44 Colour3DPlotRenderer::renderTimeConstrained(const LayerGeometryProvider *v,
|
Chris@1090
|
45 QPainter &paint, QRect rect)
|
Chris@1076
|
46 {
|
Chris@1090
|
47 return render(v, paint, rect, true);
|
Chris@1076
|
48 }
|
Chris@1076
|
49
|
Chris@1096
|
50 QRect
|
Chris@1096
|
51 Colour3DPlotRenderer::getLargestUncachedRect()
|
Chris@1096
|
52 {
|
Chris@1096
|
53 int h = m_cache.getSize().height();
|
Chris@1096
|
54
|
Chris@1096
|
55 QRect areaLeft(0, 0, m_cache.getValidLeft(), h);
|
Chris@1096
|
56 QRect areaRight(m_cache.getValidRight(), 0,
|
Chris@1096
|
57 m_cache.getSize().width() - m_cache.getValidRight(), h);
|
Chris@1096
|
58
|
Chris@1096
|
59 if (areaRight.width() > areaLeft.width()) {
|
Chris@1096
|
60 return areaRight;
|
Chris@1096
|
61 } else {
|
Chris@1096
|
62 return areaLeft;
|
Chris@1096
|
63 }
|
Chris@1096
|
64 }
|
Chris@1096
|
65
|
Chris@1076
|
66 Colour3DPlotRenderer::RenderResult
|
Chris@1113
|
67 Colour3DPlotRenderer::render(const LayerGeometryProvider *v,
|
Chris@1090
|
68 QPainter &paint, QRect rect, bool timeConstrained)
|
Chris@1073
|
69 {
|
Chris@1109
|
70 RenderType renderType = decideRenderType(v);
|
Chris@1109
|
71
|
Chris@1109
|
72 if (renderType != DrawBufferPixelResolution) {
|
Chris@1109
|
73 // Rendering should be fast in bin-resolution and direct draw
|
Chris@1109
|
74 // cases because we are quite well zoomed-in, and the sums are
|
Chris@1109
|
75 // easier this way. Calculating boundaries later will be
|
Chris@1109
|
76 // fiddly for partial paints otherwise.
|
Chris@1109
|
77 timeConstrained = false;
|
Chris@1109
|
78 }
|
Chris@1109
|
79
|
Chris@1079
|
80 int x0 = v->getXForViewX(rect.x());
|
Chris@1079
|
81 int x1 = v->getXForViewX(rect.x() + rect.width());
|
Chris@1079
|
82 if (x0 < 0) x0 = 0;
|
Chris@1079
|
83 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
|
Chris@1079
|
84
|
Chris@1120
|
85 sv_frame_t startFrame = v->getStartFrame();
|
Chris@1120
|
86
|
Chris@1079
|
87 m_cache.resize(v->getPaintSize());
|
Chris@1079
|
88 m_cache.setZoomLevel(v->getZoomLevel());
|
Chris@1079
|
89
|
Chris@1119
|
90 m_magCache.resize(v->getPaintSize().width());
|
Chris@1119
|
91 m_magCache.setZoomLevel(v->getZoomLevel());
|
Chris@1119
|
92
|
Chris@1120
|
93 if (renderType == DirectTranslucent) {
|
Chris@1120
|
94 renderDirectTranslucent(v, paint, rect);
|
Chris@1120
|
95 //!!! mag range!
|
Chris@1120
|
96
|
Chris@1120
|
97 //!!! a dev debug check
|
Chris@1120
|
98 if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
|
Chris@1120
|
99 cerr << "Columns (" << x0 << " -> " << x1-x0
|
Chris@1120
|
100 << ") not set in mag cache" << endl;
|
Chris@1120
|
101 throw std::logic_error("Columns not set in mag cache");
|
Chris@1120
|
102 }
|
Chris@1120
|
103
|
Chris@1120
|
104 //!!! this is wrong
|
Chris@1120
|
105 MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
|
Chris@1120
|
106
|
Chris@1120
|
107 return { rect, range }; //!!! this return arg is not very useful
|
Chris@1120
|
108 }
|
Chris@1120
|
109
|
Chris@1090
|
110 cerr << "cache start " << m_cache.getStartFrame()
|
Chris@1090
|
111 << " valid left " << m_cache.getValidLeft()
|
Chris@1090
|
112 << " valid right " << m_cache.getValidRight()
|
Chris@1094
|
113 << endl;
|
Chris@1094
|
114 cerr << " view start " << startFrame
|
Chris@1090
|
115 << " x0 " << x0
|
Chris@1090
|
116 << " x1 " << x1
|
Chris@1090
|
117 << endl;
|
Chris@1090
|
118
|
Chris@1079
|
119 if (m_cache.isValid()) { // some part of the cache is valid
|
Chris@1079
|
120
|
Chris@1079
|
121 if (v->getXForFrame(m_cache.getStartFrame()) ==
|
Chris@1079
|
122 v->getXForFrame(startFrame) &&
|
Chris@1079
|
123 m_cache.getValidLeft() <= x0 &&
|
Chris@1079
|
124 m_cache.getValidRight() >= x1) {
|
Chris@1090
|
125
|
Chris@1090
|
126 cerr << "cache hit" << endl;
|
Chris@1090
|
127
|
Chris@1079
|
128 // cache is valid for the complete requested area
|
Chris@1079
|
129 paint.drawImage(rect, m_cache.getImage(), rect);
|
Chris@1119
|
130
|
Chris@1119
|
131 //!!! a dev debug check
|
Chris@1119
|
132 if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
|
Chris@1119
|
133 cerr << "Columns (" << x0 << " -> " << x1-x0
|
Chris@1119
|
134 << ") not set in mag cache" << endl;
|
Chris@1119
|
135 throw std::logic_error("Columns not set in mag cache");
|
Chris@1119
|
136 }
|
Chris@1119
|
137
|
Chris@1119
|
138 MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
|
Chris@1119
|
139
|
Chris@1119
|
140 return { rect, range };
|
Chris@1079
|
141
|
Chris@1079
|
142 } else {
|
Chris@1090
|
143 cerr << "cache partial hit" << endl;
|
Chris@1090
|
144
|
Chris@1079
|
145 // cache doesn't begin at the right frame or doesn't
|
Chris@1079
|
146 // contain the complete view, but might be scrollable or
|
Chris@1079
|
147 // partially usable
|
Chris@1090
|
148 m_cache.scrollTo(v, startFrame);
|
Chris@1119
|
149 m_magCache.scrollTo(v, startFrame);
|
Chris@1079
|
150
|
Chris@1079
|
151 // if we are not time-constrained, then we want to paint
|
Chris@1081
|
152 // the whole area in one go; we don't return a partial
|
Chris@1081
|
153 // paint. To avoid providing the more complex logic to
|
Chris@1081
|
154 // handle painting discontiguous areas, if the only valid
|
Chris@1079
|
155 // part of cache is in the middle, just make the whole
|
Chris@1079
|
156 // thing invalid and start again.
|
Chris@1079
|
157 if (!timeConstrained) {
|
Chris@1079
|
158 if (m_cache.getValidLeft() > x0 &&
|
Chris@1079
|
159 m_cache.getValidRight() < x1) {
|
Chris@1079
|
160 m_cache.invalidate();
|
Chris@1079
|
161 }
|
Chris@1079
|
162 }
|
Chris@1079
|
163 }
|
Chris@1090
|
164 } else {
|
Chris@1118
|
165 // cache is completely invalid
|
Chris@1090
|
166 m_cache.setStartFrame(startFrame);
|
Chris@1119
|
167 m_magCache.setStartFrame(startFrame);
|
Chris@1075
|
168 }
|
Chris@1075
|
169
|
Chris@1079
|
170 bool rightToLeft = false;
|
Chris@1079
|
171
|
Chris@1079
|
172 if (!m_cache.isValid() && timeConstrained) {
|
Chris@1081
|
173 // When rendering the whole area, in a context where we might
|
Chris@1081
|
174 // not be able to complete the work, start from somewhere near
|
Chris@1081
|
175 // the middle so that the region of interest appears first
|
Chris@1079
|
176
|
Chris@1079
|
177 //!!! (perhaps we should avoid doing this if past repaints
|
Chris@1079
|
178 //!!! have been fast enough to do the whole in one shot)
|
Chris@1079
|
179 if (x0 == 0 && x1 == v->getPaintWidth()) {
|
Chris@1079
|
180 x0 = int(x1 * 0.3);
|
Chris@1079
|
181 }
|
Chris@1079
|
182 }
|
Chris@1079
|
183
|
Chris@1079
|
184 if (m_cache.isValid()) {
|
Chris@1090
|
185
|
Chris@1079
|
186 // When rendering only a part of the cache, we need to make
|
Chris@1079
|
187 // sure that the part we're rendering is adjacent to (or
|
Chris@1079
|
188 // overlapping) a valid area of cache, if we have one. The
|
Chris@1079
|
189 // alternative is to ditch the valid area of cache and render
|
Chris@1079
|
190 // only the requested area, but that's risky because this can
|
Chris@1079
|
191 // happen when just waving the pointer over a small part of
|
Chris@1079
|
192 // the view -- if we lose the partly-built cache every time
|
Chris@1079
|
193 // the user does that, we'll never finish building it.
|
Chris@1079
|
194 int left = x0;
|
Chris@1079
|
195 int width = x1 - x0;
|
Chris@1079
|
196 bool isLeftOfValidArea = false;
|
Chris@1079
|
197 m_cache.adjustToTouchValidArea(left, width, isLeftOfValidArea);
|
Chris@1079
|
198 x0 = left;
|
Chris@1079
|
199 x1 = x0 + width;
|
Chris@1079
|
200
|
Chris@1079
|
201 // That call also told us whether we should be painting
|
Chris@1079
|
202 // sub-regions of our target region in right-to-left order in
|
Chris@1079
|
203 // order to ensure contiguity
|
Chris@1079
|
204 rightToLeft = isLeftOfValidArea;
|
Chris@1079
|
205 }
|
Chris@1075
|
206
|
Chris@1109
|
207 // Note, we always paint the full height to cache. We want to
|
Chris@1109
|
208 // ensure the cache is coherent without having to worry about
|
Chris@1109
|
209 // vertical matching of required and valid areas as well as
|
Chris@1109
|
210 // horizontal.
|
Chris@1094
|
211
|
Chris@1109
|
212 if (renderType == DrawBufferBinResolution) {
|
Chris@1109
|
213
|
Chris@1094
|
214 renderToCacheBinResolution(v, x0, x1 - x0);
|
Chris@1109
|
215
|
Chris@1109
|
216 } else { // must be DrawBufferPixelResolution, handled DirectTranslucent earlier
|
Chris@1109
|
217
|
Chris@1094
|
218 renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained);
|
Chris@1094
|
219 }
|
Chris@1079
|
220
|
Chris@1079
|
221 QRect pr = rect & m_cache.getValidArea();
|
Chris@1079
|
222 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(),
|
Chris@1079
|
223 pr.x(), pr.y(), pr.width(), pr.height());
|
Chris@1079
|
224
|
Chris@1079
|
225 if (!timeConstrained && (pr != rect)) {
|
Chris@1079
|
226 //!!! on a first cut, there is a risk that this will happen
|
Chris@1079
|
227 //!!! when we are at start/end of model -- trap, report, and
|
Chris@1079
|
228 //!!! then fix
|
Chris@1079
|
229 throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained");
|
Chris@1079
|
230 }
|
Chris@1120
|
231
|
Chris@1120
|
232 //!!! a dev debug check
|
Chris@1120
|
233 if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
|
Chris@1120
|
234 cerr << "Columns (" << x0 << " -> " << x1-x0
|
Chris@1120
|
235 << ") not set in mag cache" << endl;
|
Chris@1120
|
236 throw std::logic_error("Columns not set in mag cache");
|
Chris@1120
|
237 }
|
Chris@1079
|
238
|
Chris@1120
|
239 MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
|
Chris@1120
|
240
|
Chris@1120
|
241 return { pr, range };
|
Chris@1079
|
242
|
Chris@1073
|
243 //!!! todo: timing/incomplete paint
|
Chris@1073
|
244
|
Chris@1073
|
245 //!!! todo: peak frequency style
|
Chris@1073
|
246
|
Chris@1073
|
247 //!!! todo: transparent style from Colour3DPlot
|
Chris@1074
|
248
|
Chris@1079
|
249 //!!! todo: view magnitudes / normalise visible area
|
Chris@1079
|
250
|
Chris@1079
|
251 //!!! todo: alter documentation for view mag stuff (cached paints
|
Chris@1079
|
252 //!!! do not update MagnitudeRange)
|
Chris@1079
|
253
|
Chris@1079
|
254 //!!! todo, here or in caller: illuminateLocalFeatures
|
Chris@1079
|
255
|
Chris@1110
|
256 //!!! todo: colourmap rotation
|
Chris@1110
|
257
|
Chris@1079
|
258 //!!! fft model scaling?
|
Chris@1079
|
259
|
Chris@1079
|
260 //!!! should we own the Dense3DModelPeakCache here? or should it persist
|
Chris@1073
|
261 }
|
Chris@1073
|
262
|
Chris@1109
|
263 Colour3DPlotRenderer::RenderType
|
Chris@1113
|
264 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const
|
Chris@1094
|
265 {
|
Chris@1100
|
266 const DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1109
|
267 if (!model || !v || !(v->getViewManager())) {
|
Chris@1109
|
268 return DrawBufferPixelResolution; // or anything
|
Chris@1109
|
269 }
|
Chris@1109
|
270
|
Chris@1094
|
271 int binResolution = model->getResolution();
|
Chris@1094
|
272 int zoomLevel = v->getZoomLevel();
|
Chris@1109
|
273 sv_samplerate_t modelRate = model->getSampleRate();
|
Chris@1109
|
274
|
Chris@1109
|
275 double rateRatio = v->getViewManager()->getMainModelSampleRate() / modelRate;
|
Chris@1109
|
276 double relativeBinResolution = binResolution * rateRatio;
|
Chris@1109
|
277
|
Chris@1109
|
278 if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
|
Chris@1109
|
279 // no alternative works here
|
Chris@1109
|
280 return DrawBufferPixelResolution;
|
Chris@1109
|
281 }
|
Chris@1109
|
282
|
Chris@1109
|
283 if (!m_params.alwaysOpaque && !m_params.interpolate) {
|
Chris@1109
|
284
|
Chris@1109
|
285 // consider translucent option -- only if not smoothing & not
|
Chris@1109
|
286 // explicitly requested opaque & sufficiently zoomed-in
|
Chris@1109
|
287
|
Chris@1117
|
288 if (model->getHeight() * 3 < v->getPaintHeight() &&
|
Chris@1117
|
289 relativeBinResolution >= 3 * zoomLevel) {
|
Chris@1109
|
290 return DirectTranslucent;
|
Chris@1109
|
291 }
|
Chris@1109
|
292 }
|
Chris@1109
|
293
|
Chris@1109
|
294 if (relativeBinResolution > zoomLevel) {
|
Chris@1109
|
295 return DrawBufferBinResolution;
|
Chris@1109
|
296 } else {
|
Chris@1109
|
297 return DrawBufferPixelResolution;
|
Chris@1109
|
298 }
|
Chris@1109
|
299 }
|
Chris@1109
|
300
|
Chris@1109
|
301 void
|
Chris@1113
|
302 Colour3DPlotRenderer::renderDirectTranslucent(const LayerGeometryProvider *v,
|
Chris@1109
|
303 QPainter &paint,
|
Chris@1109
|
304 QRect rect)
|
Chris@1109
|
305 {
|
Chris@1117
|
306 Profiler profiler("Colour3DPlotRenderer::renderDirectTranslucent");
|
Chris@1117
|
307
|
Chris@1115
|
308 QPoint illuminatePos;
|
Chris@1115
|
309 bool illuminate = v->shouldIlluminateLocalFeatures
|
Chris@1115
|
310 (m_sources.verticalBinLayer, illuminatePos);
|
Chris@1109
|
311
|
Chris@1109
|
312 const DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1109
|
313
|
Chris@1109
|
314 int x0 = rect.left();
|
Chris@1109
|
315 int x1 = rect.right() + 1;
|
Chris@1109
|
316
|
Chris@1109
|
317 int h = v->getPaintHeight();
|
Chris@1109
|
318
|
Chris@1109
|
319 sv_frame_t modelStart = model->getStartFrame();
|
Chris@1109
|
320 sv_frame_t modelEnd = model->getEndFrame();
|
Chris@1109
|
321 int modelResolution = model->getResolution();
|
Chris@1109
|
322
|
Chris@1109
|
323 double rateRatio =
|
Chris@1109
|
324 v->getViewManager()->getMainModelSampleRate() / model->getSampleRate();
|
Chris@1109
|
325
|
Chris@1109
|
326 // the s-prefix values are source, i.e. model, column and bin numbers
|
Chris@1109
|
327 int sx0 = int((double(v->getFrameForX(x0)) / rateRatio - double(modelStart))
|
Chris@1109
|
328 / modelResolution);
|
Chris@1109
|
329 int sx1 = int((double(v->getFrameForX(x1)) / rateRatio - double(modelStart))
|
Chris@1109
|
330 / modelResolution);
|
Chris@1109
|
331
|
Chris@1109
|
332 int sh = model->getHeight();
|
Chris@1109
|
333
|
Chris@1109
|
334 const int buflen = 40;
|
Chris@1109
|
335 char labelbuf[buflen];
|
Chris@1109
|
336
|
Chris@1115
|
337 int minbin = 0; //!!!
|
Chris@1109
|
338 int maxbin = sh - 1; //!!!
|
Chris@1109
|
339
|
Chris@1109
|
340 int psx = -1;
|
Chris@1109
|
341
|
Chris@1109
|
342 vector<float> preparedColumn;
|
Chris@1109
|
343
|
Chris@1109
|
344 int modelWidth = model->getWidth();
|
Chris@1109
|
345
|
Chris@1109
|
346 for (int sx = sx0; sx <= sx1; ++sx) {
|
Chris@1109
|
347
|
Chris@1109
|
348 if (sx < 0 || sx >= modelWidth) {
|
Chris@1109
|
349 continue;
|
Chris@1109
|
350 }
|
Chris@1109
|
351
|
Chris@1109
|
352 if (sx != psx) {
|
Chris@1109
|
353
|
Chris@1109
|
354 //!!! this is in common with renderDrawBuffer - pull it out
|
Chris@1109
|
355
|
Chris@1109
|
356 // order:
|
Chris@1109
|
357 // get column -> scale -> record extents ->
|
Chris@1109
|
358 // normalise -> peak pick -> apply display gain ->
|
Chris@1109
|
359 // distribute/interpolate
|
Chris@1109
|
360
|
Chris@1109
|
361 ColumnOp::Column fullColumn = model->getColumn(sx);
|
Chris@1109
|
362
|
Chris@1109
|
363 // cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size()
|
Chris@1109
|
364 // << ", minbin " << minbin << ", maxbin " << maxbin << endl;
|
Chris@1109
|
365
|
Chris@1109
|
366 ColumnOp::Column column =
|
Chris@1109
|
367 vector<float>(fullColumn.data() + minbin,
|
Chris@1109
|
368 fullColumn.data() + maxbin + 1);
|
Chris@1109
|
369
|
Chris@1109
|
370 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1109
|
371 // column = ColumnOp::fftScale(column, m_fftSize);
|
Chris@1109
|
372 // }
|
Chris@1109
|
373
|
Chris@1109
|
374 //!!! extents recordColumnExtents(column,
|
Chris@1109
|
375 // sx,
|
Chris@1109
|
376 // overallMag,
|
Chris@1109
|
377 // overallMagChanged);
|
Chris@1109
|
378
|
Chris@1109
|
379 // if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1115
|
380 preparedColumn = ColumnOp::normalize(column, m_params.normalization);
|
Chris@1109
|
381 // }
|
Chris@1109
|
382
|
Chris@1109
|
383 if (m_params.binDisplay == BinDisplay::PeakBins) {
|
Chris@1115
|
384 preparedColumn = ColumnOp::peakPick(preparedColumn);
|
Chris@1109
|
385 }
|
Chris@1109
|
386
|
Chris@1109
|
387 psx = sx;
|
Chris@1109
|
388 }
|
Chris@1109
|
389
|
Chris@1109
|
390 sv_frame_t fx = sx * modelResolution + modelStart;
|
Chris@1109
|
391
|
Chris@1109
|
392 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
|
Chris@1109
|
393
|
Chris@1109
|
394 int rx0 = v->getXForFrame(int(double(fx) * rateRatio));
|
Chris@1109
|
395 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * rateRatio));
|
Chris@1109
|
396
|
Chris@1109
|
397 int rw = rx1 - rx0;
|
Chris@1109
|
398 if (rw < 1) rw = 1;
|
Chris@1109
|
399
|
Chris@1109
|
400 bool showLabel = (rw > 10 &&
|
Chris@1109
|
401 paint.fontMetrics().width("0.000000") < rw - 3 &&
|
Chris@1109
|
402 paint.fontMetrics().height() < (h / sh));
|
Chris@1109
|
403
|
Chris@1109
|
404 for (int sy = minbin; sy <= maxbin; ++sy) {
|
Chris@1109
|
405
|
Chris@1109
|
406 int ry0 = m_sources.verticalBinLayer->getIYForBin(v, sy);
|
Chris@1109
|
407 int ry1 = m_sources.verticalBinLayer->getIYForBin(v, sy + 1);
|
Chris@1116
|
408
|
Chris@1116
|
409 if (m_params.invertVertical) {
|
Chris@1116
|
410 ry0 = h - ry0 - 1;
|
Chris@1116
|
411 ry1 = h - ry1 - 1;
|
Chris@1116
|
412 }
|
Chris@1116
|
413
|
Chris@1109
|
414 QRect r(rx0, ry1, rw, ry0 - ry1);
|
Chris@1109
|
415
|
Chris@1109
|
416 float value = preparedColumn[sy - minbin];
|
Chris@1112
|
417 QColor colour = m_params.colourScale.getColour(value,
|
Chris@1112
|
418 m_params.colourRotation);
|
Chris@1109
|
419
|
Chris@1109
|
420 if (rw == 1) {
|
Chris@1109
|
421 paint.setPen(colour);
|
Chris@1109
|
422 paint.setBrush(Qt::NoBrush);
|
Chris@1109
|
423 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
|
Chris@1109
|
424 continue;
|
Chris@1109
|
425 }
|
Chris@1109
|
426
|
Chris@1109
|
427 QColor pen(255, 255, 255, 80);
|
Chris@1109
|
428 QColor brush(colour);
|
Chris@1109
|
429
|
Chris@1109
|
430 if (rw > 3 && r.height() > 3) {
|
Chris@1109
|
431 brush.setAlpha(160);
|
Chris@1109
|
432 }
|
Chris@1109
|
433
|
Chris@1109
|
434 paint.setPen(Qt::NoPen);
|
Chris@1109
|
435 paint.setBrush(brush);
|
Chris@1109
|
436
|
Chris@1115
|
437 if (illuminate) {
|
Chris@1115
|
438 if (r.contains(illuminatePos)) {
|
Chris@1115
|
439 paint.setPen(v->getForeground());
|
Chris@1115
|
440 }
|
Chris@1115
|
441 }
|
Chris@1109
|
442
|
Chris@1109
|
443 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
|
Chris@1109
|
444 // cerr << "rect " << r.x() << "," << r.y() << " "
|
Chris@1109
|
445 // << r.width() << "x" << r.height() << endl;
|
Chris@1109
|
446 #endif
|
Chris@1109
|
447
|
Chris@1109
|
448 paint.drawRect(r);
|
Chris@1109
|
449
|
Chris@1109
|
450 if (showLabel) {
|
Chris@1109
|
451 double value = model->getValueAt(sx, sy);
|
Chris@1109
|
452 snprintf(labelbuf, buflen, "%06f", value);
|
Chris@1109
|
453 QString text(labelbuf);
|
Chris@1109
|
454 PaintAssistant::drawVisibleText
|
Chris@1109
|
455 (v,
|
Chris@1109
|
456 paint,
|
Chris@1109
|
457 rx0 + 2,
|
Chris@1109
|
458 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
|
Chris@1109
|
459 text,
|
Chris@1109
|
460 PaintAssistant::OutlinedText);
|
Chris@1109
|
461 }
|
Chris@1109
|
462 }
|
Chris@1109
|
463 }
|
Chris@1109
|
464
|
Chris@1094
|
465 }
|
Chris@1094
|
466
|
Chris@1080
|
467 void
|
Chris@1113
|
468 Colour3DPlotRenderer::renderToCachePixelResolution(const LayerGeometryProvider *v,
|
Chris@1094
|
469 int x0, int repaintWidth,
|
Chris@1094
|
470 bool rightToLeft,
|
Chris@1094
|
471 bool timeConstrained)
|
Chris@1079
|
472 {
|
Chris@1117
|
473 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution");
|
Chris@1094
|
474 cerr << "renderToCachePixelResolution" << endl;
|
Chris@1094
|
475
|
Chris@1094
|
476 // Draw to the draw buffer, and then copy from there. The draw
|
Chris@1094
|
477 // buffer is at the same resolution as the target in the cache, so
|
Chris@1094
|
478 // no extra scaling needed.
|
Chris@1079
|
479
|
Chris@1100
|
480 const DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1079
|
481 if (!model || !model->isOK() || !model->isReady()) {
|
Chris@1079
|
482 throw std::logic_error("no source model provided, or model not ready");
|
Chris@1079
|
483 }
|
Chris@1079
|
484
|
Chris@1079
|
485 int h = v->getPaintHeight();
|
Chris@1079
|
486
|
Chris@1094
|
487 clearDrawBuffer(repaintWidth, h);
|
Chris@1079
|
488
|
Chris@1094
|
489 vector<int> binforx(repaintWidth);
|
Chris@1079
|
490 vector<double> binfory(h);
|
Chris@1079
|
491
|
Chris@1079
|
492 bool usePeaksCache = false;
|
Chris@1079
|
493 int binsPerPeak = 1;
|
Chris@1094
|
494 int zoomLevel = v->getZoomLevel();
|
Chris@1094
|
495 int binResolution = model->getResolution();
|
Chris@1079
|
496
|
Chris@1094
|
497 for (int x = 0; x < repaintWidth; ++x) {
|
Chris@1094
|
498 sv_frame_t f0 = v->getFrameForX(x0 + x);
|
Chris@1094
|
499 double s0 = double(f0 - model->getStartFrame()) / binResolution;
|
Chris@1094
|
500 binforx[x] = int(s0 + 0.0001);
|
Chris@1094
|
501 }
|
Chris@1080
|
502
|
Chris@1094
|
503 if (m_sources.peaks) { // peaks cache exists
|
Chris@1080
|
504
|
Chris@1094
|
505 binsPerPeak = m_sources.peaks->getColumnsPerPeak();
|
Chris@1094
|
506 usePeaksCache = (binResolution * binsPerPeak) < zoomLevel;
|
Chris@1094
|
507
|
Chris@1094
|
508 if (m_params.colourScale.getScale() ==
|
Chris@1105
|
509 ColourScaleType::Phase) {
|
Chris@1094
|
510 usePeaksCache = false;
|
Chris@1079
|
511 }
|
Chris@1079
|
512 }
|
Chris@1082
|
513
|
Chris@1094
|
514 cerr << "[PIX] zoomLevel = " << zoomLevel
|
Chris@1094
|
515 << ", binResolution " << binResolution
|
Chris@1094
|
516 << ", binsPerPeak " << binsPerPeak
|
Chris@1094
|
517 << ", peak cache " << m_sources.peaks
|
Chris@1094
|
518 << ", usePeaksCache = " << usePeaksCache
|
Chris@1094
|
519 << endl;
|
Chris@1094
|
520
|
Chris@1080
|
521 for (int y = 0; y < h; ++y) {
|
Chris@1090
|
522 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
|
Chris@1080
|
523 }
|
Chris@1079
|
524
|
Chris@1097
|
525 int attainedWidth;
|
Chris@1097
|
526
|
Chris@1103
|
527 if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
|
Chris@1097
|
528 attainedWidth = renderDrawBufferPeakFrequencies(v,
|
Chris@1097
|
529 repaintWidth,
|
Chris@1097
|
530 h,
|
Chris@1097
|
531 binforx,
|
Chris@1097
|
532 binfory,
|
Chris@1097
|
533 rightToLeft,
|
Chris@1097
|
534 timeConstrained);
|
Chris@1097
|
535
|
Chris@1097
|
536 } else {
|
Chris@1097
|
537 attainedWidth = renderDrawBuffer(repaintWidth,
|
Chris@1080
|
538 h,
|
Chris@1080
|
539 binforx,
|
Chris@1080
|
540 binfory,
|
Chris@1080
|
541 usePeaksCache,
|
Chris@1080
|
542 rightToLeft,
|
Chris@1080
|
543 timeConstrained);
|
Chris@1097
|
544 }
|
Chris@1083
|
545
|
Chris@1094
|
546 if (attainedWidth == 0) return;
|
Chris@1084
|
547
|
Chris@1094
|
548 // draw buffer is pixel resolution, no scaling factors or padding involved
|
Chris@1084
|
549
|
Chris@1084
|
550 int paintedLeft = x0;
|
Chris@1084
|
551 if (rightToLeft) {
|
Chris@1084
|
552 paintedLeft += (repaintWidth - attainedWidth);
|
Chris@1084
|
553 }
|
Chris@1084
|
554
|
Chris@1094
|
555 m_cache.drawImage(paintedLeft, attainedWidth,
|
Chris@1094
|
556 m_drawBuffer,
|
Chris@1094
|
557 paintedLeft - x0, attainedWidth);
|
Chris@1094
|
558 }
|
Chris@1084
|
559
|
Chris@1094
|
560 void
|
Chris@1113
|
561 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v,
|
Chris@1094
|
562 int x0, int repaintWidth)
|
Chris@1094
|
563 {
|
Chris@1117
|
564 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution");
|
Chris@1094
|
565 cerr << "renderToCacheBinResolution" << endl;
|
Chris@1094
|
566
|
Chris@1094
|
567 // Draw to the draw buffer, and then scale-copy from there. Draw
|
Chris@1094
|
568 // buffer is at bin resolution, i.e. buffer x == source column
|
Chris@1094
|
569 // number. We use toolkit smooth scaling for interpolation.
|
Chris@1084
|
570
|
Chris@1100
|
571 const DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1094
|
572 if (!model || !model->isOK() || !model->isReady()) {
|
Chris@1094
|
573 throw std::logic_error("no source model provided, or model not ready");
|
Chris@1094
|
574 }
|
Chris@1094
|
575
|
Chris@1094
|
576 // The draw buffer will contain a fragment at bin resolution. We
|
Chris@1094
|
577 // need to ensure that it starts and ends at points where a
|
Chris@1094
|
578 // time-bin boundary occurs at an exact pixel boundary, and with a
|
Chris@1094
|
579 // certain amount of overlap across existing pixels so that we can
|
Chris@1094
|
580 // scale and draw from it without smoothing errors at the edges.
|
Chris@1094
|
581
|
Chris@1094
|
582 // If (getFrameForX(x) / increment) * increment ==
|
Chris@1094
|
583 // getFrameForX(x), then x is a time-bin boundary. We want two
|
Chris@1094
|
584 // such boundaries at either side of the draw buffer -- one which
|
Chris@1094
|
585 // we draw up to, and one which we subsequently crop at.
|
Chris@1094
|
586
|
Chris@1094
|
587 sv_frame_t leftBoundaryFrame = -1, leftCropFrame = -1;
|
Chris@1094
|
588 sv_frame_t rightBoundaryFrame = -1, rightCropFrame = -1;
|
Chris@1094
|
589
|
Chris@1094
|
590 int drawBufferWidth;
|
Chris@1094
|
591 int binResolution = model->getResolution();
|
Chris@1094
|
592
|
Chris@1094
|
593 for (int x = x0; ; --x) {
|
Chris@1094
|
594 sv_frame_t f = v->getFrameForX(x);
|
Chris@1094
|
595 if ((f / binResolution) * binResolution == f) {
|
Chris@1094
|
596 if (leftCropFrame == -1) leftCropFrame = f;
|
Chris@1094
|
597 else if (x < x0 - 2) {
|
Chris@1094
|
598 leftBoundaryFrame = f;
|
Chris@1094
|
599 break;
|
Chris@1094
|
600 }
|
Chris@1094
|
601 }
|
Chris@1094
|
602 }
|
Chris@1094
|
603 for (int x = x0 + repaintWidth; ; ++x) {
|
Chris@1094
|
604 sv_frame_t f = v->getFrameForX(x);
|
Chris@1094
|
605 if ((f / binResolution) * binResolution == f) {
|
Chris@1094
|
606 if (rightCropFrame == -1) rightCropFrame = f;
|
Chris@1094
|
607 else if (x > x0 + repaintWidth + 2) {
|
Chris@1094
|
608 rightBoundaryFrame = f;
|
Chris@1094
|
609 break;
|
Chris@1094
|
610 }
|
Chris@1094
|
611 }
|
Chris@1094
|
612 }
|
Chris@1094
|
613 drawBufferWidth = int
|
Chris@1094
|
614 ((rightBoundaryFrame - leftBoundaryFrame) / binResolution);
|
Chris@1094
|
615
|
Chris@1094
|
616 int h = v->getPaintHeight();
|
Chris@1094
|
617
|
Chris@1095
|
618 // For our purposes here, the draw buffer needs to be exactly our
|
Chris@1095
|
619 // target size (so we recreate always rather than just clear it)
|
Chris@1095
|
620
|
Chris@1095
|
621 recreateDrawBuffer(drawBufferWidth, h);
|
Chris@1094
|
622
|
Chris@1094
|
623 vector<int> binforx(drawBufferWidth);
|
Chris@1094
|
624 vector<double> binfory(h);
|
Chris@1094
|
625
|
Chris@1094
|
626 for (int x = 0; x < drawBufferWidth; ++x) {
|
Chris@1094
|
627 binforx[x] = int(leftBoundaryFrame / binResolution) + x;
|
Chris@1094
|
628 }
|
Chris@1094
|
629
|
Chris@1094
|
630 cerr << "[BIN] binResolution " << binResolution
|
Chris@1094
|
631 << endl;
|
Chris@1094
|
632
|
Chris@1094
|
633 for (int y = 0; y < h; ++y) {
|
Chris@1094
|
634 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
|
Chris@1094
|
635 }
|
Chris@1094
|
636
|
Chris@1094
|
637 int attainedWidth = renderDrawBuffer(drawBufferWidth,
|
Chris@1094
|
638 h,
|
Chris@1094
|
639 binforx,
|
Chris@1094
|
640 binfory,
|
Chris@1094
|
641 false,
|
Chris@1094
|
642 false,
|
Chris@1094
|
643 false);
|
Chris@1094
|
644
|
Chris@1094
|
645 if (attainedWidth == 0) return;
|
Chris@1094
|
646
|
Chris@1094
|
647 int scaledLeft = v->getXForFrame(leftBoundaryFrame);
|
Chris@1094
|
648 int scaledRight = v->getXForFrame(rightBoundaryFrame);
|
Chris@1095
|
649
|
Chris@1095
|
650 cerr << "scaling draw buffer from width " << m_drawBuffer.width()
|
Chris@1095
|
651 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = "
|
Chris@1095
|
652 << drawBufferWidth << ")" << endl;
|
Chris@1094
|
653
|
Chris@1094
|
654 QImage scaled = m_drawBuffer.scaled
|
Chris@1094
|
655 (scaledRight - scaledLeft, h,
|
Chris@1094
|
656 Qt::IgnoreAspectRatio, (m_params.interpolate ?
|
Chris@1094
|
657 Qt::SmoothTransformation :
|
Chris@1094
|
658 Qt::FastTransformation));
|
Chris@1084
|
659
|
Chris@1094
|
660 int scaledLeftCrop = v->getXForFrame(leftCropFrame);
|
Chris@1094
|
661 int scaledRightCrop = v->getXForFrame(rightCropFrame);
|
Chris@1094
|
662
|
Chris@1094
|
663 int targetLeft = scaledLeftCrop;
|
Chris@1094
|
664 if (targetLeft < 0) {
|
Chris@1094
|
665 targetLeft = 0;
|
Chris@1094
|
666 }
|
Chris@1094
|
667
|
Chris@1094
|
668 int targetWidth = scaledRightCrop - targetLeft;
|
Chris@1094
|
669 if (targetLeft + targetWidth > m_cache.getSize().width()) {
|
Chris@1094
|
670 targetWidth = m_cache.getSize().width() - targetLeft;
|
Chris@1094
|
671 }
|
Chris@1094
|
672
|
Chris@1094
|
673 int sourceLeft = targetLeft - scaledLeft;
|
Chris@1094
|
674 if (sourceLeft < 0) {
|
Chris@1094
|
675 sourceLeft = 0;
|
Chris@1094
|
676 }
|
Chris@1094
|
677
|
Chris@1094
|
678 int sourceWidth = targetWidth;
|
Chris@1094
|
679
|
Chris@1094
|
680 cerr << "repaintWidth = " << repaintWidth
|
Chris@1094
|
681 << ", targetWidth = " << targetWidth << endl;
|
Chris@1094
|
682
|
Chris@1094
|
683 if (targetWidth > 0) {
|
Chris@1094
|
684 m_cache.drawImage(targetLeft, targetWidth,
|
Chris@1094
|
685 scaled,
|
Chris@1094
|
686 sourceLeft, sourceWidth);
|
Chris@1084
|
687 }
|
Chris@1079
|
688 }
|
Chris@1083
|
689
|
Chris@1083
|
690 int
|
Chris@1083
|
691 Colour3DPlotRenderer::renderDrawBuffer(int w, int h,
|
Chris@1083
|
692 const vector<int> &binforx,
|
Chris@1083
|
693 const vector<double> &binfory,
|
Chris@1083
|
694 bool usePeaksCache,
|
Chris@1083
|
695 bool rightToLeft,
|
Chris@1083
|
696 bool timeConstrained)
|
Chris@1083
|
697 {
|
Chris@1083
|
698 // Callers must have checked that the appropriate subset of
|
Chris@1083
|
699 // Sources data members are set for the supplied flags (e.g. that
|
Chris@1083
|
700 // peaks model exists if usePeaksCache)
|
Chris@1083
|
701
|
Chris@1083
|
702 RenderTimer timer(timeConstrained ?
|
Chris@1083
|
703 RenderTimer::FastRender :
|
Chris@1083
|
704 RenderTimer::NoTimeout);
|
Chris@1083
|
705
|
Chris@1083
|
706 int minbin = int(binfory[0] + 0.0001);
|
Chris@1083
|
707 int maxbin = int(binfory[h-1]);
|
Chris@1083
|
708 if (minbin < 0) minbin = 0;
|
Chris@1083
|
709 if (maxbin < 0) maxbin = minbin+1;
|
Chris@1083
|
710
|
Chris@1083
|
711 int divisor = 1;
|
Chris@1100
|
712 const DenseThreeDimensionalModel *sourceModel = m_sources.source;
|
Chris@1083
|
713 if (usePeaksCache) {
|
Chris@1083
|
714 divisor = m_sources.peaks->getColumnsPerPeak();
|
Chris@1083
|
715 sourceModel = m_sources.peaks;
|
Chris@1083
|
716 }
|
Chris@1083
|
717
|
Chris@1083
|
718 int psx = -1;
|
Chris@1083
|
719
|
Chris@1083
|
720 int start = 0;
|
Chris@1083
|
721 int finish = w;
|
Chris@1083
|
722 int step = 1;
|
Chris@1083
|
723
|
Chris@1083
|
724 if (rightToLeft) {
|
Chris@1083
|
725 start = w-1;
|
Chris@1083
|
726 finish = -1;
|
Chris@1083
|
727 step = -1;
|
Chris@1083
|
728 }
|
Chris@1083
|
729
|
Chris@1083
|
730 int columnCount = 0;
|
Chris@1083
|
731
|
Chris@1083
|
732 vector<float> preparedColumn;
|
Chris@1094
|
733
|
Chris@1094
|
734 int modelWidth = sourceModel->getWidth();
|
Chris@1094
|
735 cerr << "modelWidth " << modelWidth << endl;
|
Chris@1083
|
736
|
Chris@1083
|
737 for (int x = start; x != finish; x += step) {
|
Chris@1083
|
738
|
Chris@1083
|
739 // x is the on-canvas pixel coord; sx (later) will be the
|
Chris@1083
|
740 // source column index
|
Chris@1083
|
741
|
Chris@1083
|
742 ++columnCount;
|
Chris@1120
|
743
|
Chris@1120
|
744 #ifdef DEBUG_SPECTROGRAM_REPAINT
|
Chris@1120
|
745 cerr << "x = " << x << endl;
|
Chris@1120
|
746 #endif
|
Chris@1083
|
747
|
Chris@1083
|
748 if (binforx[x] < 0) continue;
|
Chris@1083
|
749
|
Chris@1083
|
750 int sx0 = binforx[x] / divisor;
|
Chris@1083
|
751 int sx1 = sx0;
|
Chris@1083
|
752 if (x+1 < w) sx1 = binforx[x+1] / divisor;
|
Chris@1083
|
753 if (sx0 < 0) sx0 = sx1 - 1;
|
Chris@1083
|
754 if (sx0 < 0) continue;
|
Chris@1083
|
755 if (sx1 <= sx0) sx1 = sx0 + 1;
|
Chris@1083
|
756
|
Chris@1083
|
757 vector<float> pixelPeakColumn;
|
Chris@1083
|
758
|
Chris@1083
|
759 for (int sx = sx0; sx < sx1; ++sx) {
|
Chris@1083
|
760
|
Chris@1083
|
761 #ifdef DEBUG_SPECTROGRAM_REPAINT
|
Chris@1094
|
762 cerr << "sx = " << sx << endl;
|
Chris@1083
|
763 #endif
|
Chris@1083
|
764
|
Chris@1094
|
765 if (sx < 0 || sx >= modelWidth) {
|
Chris@1083
|
766 continue;
|
Chris@1083
|
767 }
|
Chris@1083
|
768
|
Chris@1083
|
769 if (sx != psx) {
|
Chris@1083
|
770
|
Chris@1083
|
771 // order:
|
Chris@1083
|
772 // get column -> scale -> record extents ->
|
Chris@1083
|
773 // normalise -> peak pick -> apply display gain ->
|
Chris@1083
|
774 // distribute/interpolate
|
Chris@1083
|
775
|
Chris@1083
|
776 ColumnOp::Column fullColumn = sourceModel->getColumn(sx);
|
Chris@1090
|
777
|
Chris@1094
|
778 // cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size()
|
Chris@1094
|
779 // << ", minbin " << minbin << ", maxbin " << maxbin << endl;
|
Chris@1090
|
780
|
Chris@1083
|
781 ColumnOp::Column column =
|
Chris@1083
|
782 vector<float>(fullColumn.data() + minbin,
|
Chris@1083
|
783 fullColumn.data() + maxbin + 1);
|
Chris@1083
|
784
|
Chris@1105
|
785 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1083
|
786 // column = ColumnOp::fftScale(column, m_fftSize);
|
Chris@1083
|
787 // }
|
Chris@1083
|
788
|
Chris@1120
|
789 MagnitudeRange r;
|
Chris@1120
|
790 r.sample(column);
|
Chris@1120
|
791 int magColIndex = sx - int(m_magCache.getStartFrame() /
|
Chris@1120
|
792 sourceModel->getResolution());
|
Chris@1120
|
793 cerr << "magColIndex = " << magColIndex << endl;
|
Chris@1120
|
794 m_magCache.sampleColumn(magColIndex, r);
|
Chris@1120
|
795
|
Chris@1083
|
796 //!!! extents recordColumnExtents(column,
|
Chris@1083
|
797 // sx,
|
Chris@1083
|
798 // overallMag,
|
Chris@1083
|
799 // overallMagChanged);
|
Chris@1083
|
800
|
Chris@1105
|
801 // if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1083
|
802 column = ColumnOp::normalize(column, m_params.normalization);
|
Chris@1083
|
803 // }
|
Chris@1083
|
804
|
Chris@1103
|
805 if (m_params.binDisplay == BinDisplay::PeakBins) {
|
Chris@1083
|
806 column = ColumnOp::peakPick(column);
|
Chris@1083
|
807 }
|
Chris@1083
|
808
|
Chris@1083
|
809 preparedColumn =
|
Chris@1083
|
810 ColumnOp::distribute(column, //!!! gain? ColumnOp::applyGain(column, m_gain),
|
Chris@1083
|
811 h,
|
Chris@1083
|
812 binfory,
|
Chris@1083
|
813 minbin,
|
Chris@1083
|
814 m_params.interpolate);
|
Chris@1083
|
815
|
Chris@1083
|
816 psx = sx;
|
Chris@1083
|
817 }
|
Chris@1083
|
818
|
Chris@1083
|
819 if (sx == sx0) {
|
Chris@1083
|
820 pixelPeakColumn = preparedColumn;
|
Chris@1083
|
821 } else {
|
Chris@1083
|
822 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
|
Chris@1083
|
823 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
|
Chris@1083
|
824 preparedColumn[i]);
|
Chris@1083
|
825 }
|
Chris@1083
|
826 }
|
Chris@1083
|
827 }
|
Chris@1083
|
828
|
Chris@1083
|
829 if (!pixelPeakColumn.empty()) {
|
Chris@1083
|
830 for (int y = 0; y < h; ++y) {
|
Chris@1116
|
831 int py;
|
Chris@1116
|
832 if (m_params.invertVertical) {
|
Chris@1116
|
833 py = y;
|
Chris@1116
|
834 } else {
|
Chris@1116
|
835 py = h - y - 1;
|
Chris@1116
|
836 }
|
Chris@1083
|
837 m_drawBuffer.setPixel
|
Chris@1083
|
838 (x,
|
Chris@1116
|
839 py,
|
Chris@1083
|
840 m_params.colourScale.getPixel(pixelPeakColumn[y]));
|
Chris@1083
|
841 }
|
Chris@1083
|
842 }
|
Chris@1083
|
843
|
Chris@1083
|
844 double fractionComplete = double(columnCount) / double(w);
|
Chris@1083
|
845 if (timer.outOfTime(fractionComplete)) {
|
Chris@1083
|
846 return columnCount;
|
Chris@1083
|
847 }
|
Chris@1083
|
848 }
|
Chris@1083
|
849
|
Chris@1083
|
850 return columnCount;
|
Chris@1083
|
851 }
|
Chris@1083
|
852
|
Chris@1097
|
853 int
|
Chris@1113
|
854 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,
|
Chris@1097
|
855 int w, int h,
|
Chris@1097
|
856 const vector<int> &binforx,
|
Chris@1097
|
857 const vector<double> &binfory,
|
Chris@1097
|
858 bool rightToLeft,
|
Chris@1097
|
859 bool timeConstrained)
|
Chris@1097
|
860 {
|
Chris@1097
|
861 // Callers must have checked that the appropriate subset of
|
Chris@1097
|
862 // Sources data members are set for the supplied flags (e.g. that
|
Chris@1097
|
863 // fft model exists)
|
Chris@1097
|
864
|
Chris@1097
|
865 RenderTimer timer(timeConstrained ?
|
Chris@1097
|
866 RenderTimer::FastRender :
|
Chris@1097
|
867 RenderTimer::NoTimeout);
|
Chris@1097
|
868
|
Chris@1097
|
869 int minbin = int(binfory[0] + 0.0001);
|
Chris@1097
|
870 int maxbin = int(binfory[h-1]);
|
Chris@1097
|
871 if (minbin < 0) minbin = 0;
|
Chris@1097
|
872 if (maxbin < 0) maxbin = minbin+1;
|
Chris@1097
|
873
|
Chris@1100
|
874 const FFTModel *fft = m_sources.fft;
|
Chris@1097
|
875
|
Chris@1097
|
876 FFTModel::PeakSet peakfreqs;
|
Chris@1097
|
877
|
Chris@1097
|
878 int psx = -1;
|
Chris@1097
|
879
|
Chris@1097
|
880 int start = 0;
|
Chris@1097
|
881 int finish = w;
|
Chris@1097
|
882 int step = 1;
|
Chris@1097
|
883
|
Chris@1097
|
884 if (rightToLeft) {
|
Chris@1097
|
885 start = w-1;
|
Chris@1097
|
886 finish = -1;
|
Chris@1097
|
887 step = -1;
|
Chris@1097
|
888 }
|
Chris@1097
|
889
|
Chris@1097
|
890 int columnCount = 0;
|
Chris@1097
|
891
|
Chris@1097
|
892 vector<float> preparedColumn;
|
Chris@1097
|
893
|
Chris@1097
|
894 int modelWidth = fft->getWidth();
|
Chris@1097
|
895 cerr << "modelWidth " << modelWidth << endl;
|
Chris@1097
|
896
|
Chris@1097
|
897 double minFreq = (double(minbin) * fft->getSampleRate()) / fft->getFFTSize();
|
Chris@1097
|
898 double maxFreq = (double(maxbin) * fft->getSampleRate()) / fft->getFFTSize();
|
Chris@1097
|
899
|
Chris@1103
|
900 bool logarithmic = (m_params.binScale == BinScale::Log);
|
Chris@1097
|
901
|
Chris@1097
|
902 for (int x = start; x != finish; x += step) {
|
Chris@1097
|
903
|
Chris@1097
|
904 // x is the on-canvas pixel coord; sx (later) will be the
|
Chris@1097
|
905 // source column index
|
Chris@1097
|
906
|
Chris@1097
|
907 ++columnCount;
|
Chris@1097
|
908
|
Chris@1097
|
909 if (binforx[x] < 0) continue;
|
Chris@1097
|
910
|
Chris@1097
|
911 int sx0 = binforx[x];
|
Chris@1097
|
912 int sx1 = sx0;
|
Chris@1097
|
913 if (x+1 < w) sx1 = binforx[x+1];
|
Chris@1097
|
914 if (sx0 < 0) sx0 = sx1 - 1;
|
Chris@1097
|
915 if (sx0 < 0) continue;
|
Chris@1097
|
916 if (sx1 <= sx0) sx1 = sx0 + 1;
|
Chris@1097
|
917
|
Chris@1097
|
918 vector<float> pixelPeakColumn;
|
Chris@1097
|
919
|
Chris@1097
|
920 for (int sx = sx0; sx < sx1; ++sx) {
|
Chris@1097
|
921
|
Chris@1097
|
922 if (sx < 0 || sx >= modelWidth) {
|
Chris@1097
|
923 continue;
|
Chris@1097
|
924 }
|
Chris@1097
|
925
|
Chris@1097
|
926 if (sx != psx) {
|
Chris@1097
|
927
|
Chris@1097
|
928 ColumnOp::Column fullColumn = fft->getColumn(sx);
|
Chris@1097
|
929
|
Chris@1097
|
930 ColumnOp::Column column =
|
Chris@1097
|
931 vector<float>(fullColumn.data() + minbin,
|
Chris@1097
|
932 fullColumn.data() + maxbin + 1);
|
Chris@1097
|
933
|
Chris@1105
|
934 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1097
|
935 // column = ColumnOp::fftScale(column, getFFTSize());
|
Chris@1097
|
936 // }
|
Chris@1097
|
937
|
Chris@1097
|
938 //!!! extents recordColumnExtents(column,
|
Chris@1097
|
939 // sx,
|
Chris@1097
|
940 // overallMag,
|
Chris@1097
|
941 // overallMagChanged);
|
Chris@1097
|
942
|
Chris@1105
|
943 //!!! if (m_colourScale != ColourScaleType::Phase) {
|
Chris@1097
|
944 column = ColumnOp::normalize(column, m_params.normalization);
|
Chris@1097
|
945 //!!! }
|
Chris@1097
|
946
|
Chris@1097
|
947 preparedColumn = column;
|
Chris@1097
|
948 //!!! gain? preparedColumn = ColumnOp::applyGain(column, m_params.gain);
|
Chris@1097
|
949
|
Chris@1097
|
950 psx = sx;
|
Chris@1097
|
951 }
|
Chris@1097
|
952
|
Chris@1097
|
953 if (sx == sx0) {
|
Chris@1097
|
954 pixelPeakColumn = preparedColumn;
|
Chris@1097
|
955 peakfreqs = fft->getPeakFrequencies(FFTModel::AllPeaks, sx,
|
Chris@1097
|
956 minbin, maxbin - 1);
|
Chris@1097
|
957 } else {
|
Chris@1097
|
958 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
|
Chris@1097
|
959 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
|
Chris@1097
|
960 preparedColumn[i]);
|
Chris@1097
|
961 }
|
Chris@1097
|
962 }
|
Chris@1097
|
963 }
|
Chris@1097
|
964
|
Chris@1097
|
965 if (!pixelPeakColumn.empty()) {
|
Chris@1097
|
966 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin();
|
Chris@1097
|
967 pi != peakfreqs.end(); ++pi) {
|
Chris@1097
|
968
|
Chris@1097
|
969 int bin = pi->first;
|
Chris@1097
|
970 double freq = pi->second;
|
Chris@1097
|
971
|
Chris@1097
|
972 if (bin < minbin) continue;
|
Chris@1097
|
973 if (bin > maxbin) break;
|
Chris@1097
|
974
|
Chris@1097
|
975 double value = pixelPeakColumn[bin - minbin];
|
Chris@1097
|
976
|
Chris@1097
|
977 double y = v->getYForFrequency
|
Chris@1097
|
978 (freq, minFreq, maxFreq, logarithmic);
|
Chris@1097
|
979
|
Chris@1097
|
980 int iy = int(y + 0.5);
|
Chris@1097
|
981 if (iy < 0 || iy >= h) continue;
|
Chris@1097
|
982
|
Chris@1097
|
983 m_drawBuffer.setPixel
|
Chris@1097
|
984 (x,
|
Chris@1097
|
985 iy,
|
Chris@1097
|
986 m_params.colourScale.getPixel(value));
|
Chris@1097
|
987 }
|
Chris@1097
|
988 }
|
Chris@1097
|
989
|
Chris@1097
|
990 double fractionComplete = double(columnCount) / double(w);
|
Chris@1097
|
991 if (timer.outOfTime(fractionComplete)) {
|
Chris@1097
|
992 return columnCount;
|
Chris@1097
|
993 }
|
Chris@1097
|
994 }
|
Chris@1097
|
995
|
Chris@1097
|
996 return columnCount;
|
Chris@1097
|
997 }
|
Chris@1097
|
998
|
Chris@1079
|
999 void
|
Chris@1095
|
1000 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h)
|
Chris@1079
|
1001 {
|
Chris@1095
|
1002 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8);
|
Chris@1079
|
1003
|
Chris@1095
|
1004 for (int pixel = 0; pixel < 256; ++pixel) {
|
Chris@1095
|
1005 m_drawBuffer.setColor
|
Chris@1095
|
1006 ((unsigned char)pixel,
|
Chris@1112
|
1007 m_params.colourScale.getColourForPixel
|
Chris@1112
|
1008 (pixel, m_params.colourRotation).rgb());
|
Chris@1079
|
1009 }
|
Chris@1079
|
1010
|
Chris@1079
|
1011 m_drawBuffer.fill(0);
|
Chris@1079
|
1012 }
|
Chris@1079
|
1013
|
Chris@1095
|
1014 void
|
Chris@1095
|
1015 Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
|
Chris@1095
|
1016 {
|
Chris@1095
|
1017 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
|
Chris@1095
|
1018 recreateDrawBuffer(w, h);
|
Chris@1095
|
1019 } else {
|
Chris@1095
|
1020 m_drawBuffer.fill(0);
|
Chris@1095
|
1021 }
|
Chris@1095
|
1022 }
|
Chris@1079
|
1023
|
Chris@1095
|
1024
|