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@1075
|
19 #include "data/model/DenseThreeDimensionalModel.h"
|
Chris@1075
|
20 #include "data/model/Dense3DModelPeakCache.h"
|
Chris@1075
|
21 #include "data/model/FFTModel.h"
|
Chris@1075
|
22
|
Chris@1077
|
23 #include "LayerGeometryProvider.h"
|
Chris@1082
|
24 #include "VerticalBinLayer.h"
|
Chris@1075
|
25
|
Chris@1079
|
26 #include <vector>
|
Chris@1079
|
27
|
Chris@1094
|
28 //#define DEBUG_SPECTROGRAM_REPAINT 1
|
Chris@1094
|
29
|
Chris@1079
|
30 using namespace std;
|
Chris@1079
|
31
|
Chris@1073
|
32 Colour3DPlotRenderer::RenderResult
|
Chris@1090
|
33 Colour3DPlotRenderer::render(LayerGeometryProvider *v, QPainter &paint, QRect rect)
|
Chris@1076
|
34 {
|
Chris@1090
|
35 return render(v, paint, rect, false);
|
Chris@1076
|
36 }
|
Chris@1076
|
37
|
Chris@1076
|
38 Colour3DPlotRenderer::RenderResult
|
Chris@1090
|
39 Colour3DPlotRenderer::renderTimeConstrained(LayerGeometryProvider *v,
|
Chris@1090
|
40 QPainter &paint, QRect rect)
|
Chris@1076
|
41 {
|
Chris@1090
|
42 return render(v, paint, rect, true);
|
Chris@1076
|
43 }
|
Chris@1076
|
44
|
Chris@1096
|
45 QRect
|
Chris@1096
|
46 Colour3DPlotRenderer::getLargestUncachedRect()
|
Chris@1096
|
47 {
|
Chris@1096
|
48 int h = m_cache.getSize().height();
|
Chris@1096
|
49
|
Chris@1096
|
50 QRect areaLeft(0, 0, m_cache.getValidLeft(), h);
|
Chris@1096
|
51 QRect areaRight(m_cache.getValidRight(), 0,
|
Chris@1096
|
52 m_cache.getSize().width() - m_cache.getValidRight(), h);
|
Chris@1096
|
53
|
Chris@1096
|
54 if (areaRight.width() > areaLeft.width()) {
|
Chris@1096
|
55 return areaRight;
|
Chris@1096
|
56 } else {
|
Chris@1096
|
57 return areaLeft;
|
Chris@1096
|
58 }
|
Chris@1096
|
59 }
|
Chris@1096
|
60
|
Chris@1076
|
61 Colour3DPlotRenderer::RenderResult
|
Chris@1090
|
62 Colour3DPlotRenderer::render(LayerGeometryProvider *v,
|
Chris@1090
|
63 QPainter &paint, QRect rect, bool timeConstrained)
|
Chris@1073
|
64 {
|
Chris@1079
|
65 sv_frame_t startFrame = v->getStartFrame();
|
Chris@1079
|
66
|
Chris@1079
|
67 int x0 = v->getXForViewX(rect.x());
|
Chris@1079
|
68 int x1 = v->getXForViewX(rect.x() + rect.width());
|
Chris@1079
|
69 if (x0 < 0) x0 = 0;
|
Chris@1079
|
70 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
|
Chris@1079
|
71
|
Chris@1079
|
72 m_cache.resize(v->getPaintSize());
|
Chris@1079
|
73 m_cache.setZoomLevel(v->getZoomLevel());
|
Chris@1079
|
74
|
Chris@1090
|
75 cerr << "cache start " << m_cache.getStartFrame()
|
Chris@1090
|
76 << " valid left " << m_cache.getValidLeft()
|
Chris@1090
|
77 << " valid right " << m_cache.getValidRight()
|
Chris@1094
|
78 << endl;
|
Chris@1094
|
79 cerr << " view start " << startFrame
|
Chris@1090
|
80 << " x0 " << x0
|
Chris@1090
|
81 << " x1 " << x1
|
Chris@1090
|
82 << endl;
|
Chris@1090
|
83
|
Chris@1094
|
84 bool bufferIsBinResolution = useBinResolutionForDrawBuffer(v);
|
Chris@1094
|
85
|
Chris@1094
|
86 if (bufferIsBinResolution) {
|
Chris@1094
|
87 // Rendering should be fast in this situation because we are
|
Chris@1094
|
88 // quite well zoomed-in, and the sums are easier this
|
Chris@1094
|
89 // way. Calculating boundaries later will be fiddly for
|
Chris@1094
|
90 // partial paints otherwise.
|
Chris@1094
|
91 timeConstrained = false;
|
Chris@1094
|
92 }
|
Chris@1090
|
93
|
Chris@1079
|
94 if (m_cache.isValid()) { // some part of the cache is valid
|
Chris@1079
|
95
|
Chris@1079
|
96 if (v->getXForFrame(m_cache.getStartFrame()) ==
|
Chris@1079
|
97 v->getXForFrame(startFrame) &&
|
Chris@1079
|
98 m_cache.getValidLeft() <= x0 &&
|
Chris@1079
|
99 m_cache.getValidRight() >= x1) {
|
Chris@1090
|
100
|
Chris@1090
|
101 cerr << "cache hit" << endl;
|
Chris@1090
|
102
|
Chris@1079
|
103 // cache is valid for the complete requested area
|
Chris@1079
|
104 paint.drawImage(rect, m_cache.getImage(), rect);
|
Chris@1079
|
105 return { rect, {} };
|
Chris@1079
|
106
|
Chris@1079
|
107 } else {
|
Chris@1090
|
108 cerr << "cache partial hit" << endl;
|
Chris@1090
|
109
|
Chris@1079
|
110 // cache doesn't begin at the right frame or doesn't
|
Chris@1079
|
111 // contain the complete view, but might be scrollable or
|
Chris@1079
|
112 // partially usable
|
Chris@1090
|
113 m_cache.scrollTo(v, startFrame);
|
Chris@1079
|
114
|
Chris@1079
|
115 // if we are not time-constrained, then we want to paint
|
Chris@1081
|
116 // the whole area in one go; we don't return a partial
|
Chris@1081
|
117 // paint. To avoid providing the more complex logic to
|
Chris@1081
|
118 // handle painting discontiguous areas, if the only valid
|
Chris@1079
|
119 // part of cache is in the middle, just make the whole
|
Chris@1079
|
120 // thing invalid and start again.
|
Chris@1079
|
121 if (!timeConstrained) {
|
Chris@1079
|
122 if (m_cache.getValidLeft() > x0 &&
|
Chris@1079
|
123 m_cache.getValidRight() < x1) {
|
Chris@1079
|
124 m_cache.invalidate();
|
Chris@1079
|
125 }
|
Chris@1079
|
126 }
|
Chris@1079
|
127 }
|
Chris@1090
|
128 } else {
|
Chris@1090
|
129 // cache completely invalid
|
Chris@1090
|
130 m_cache.setStartFrame(startFrame);
|
Chris@1075
|
131 }
|
Chris@1075
|
132
|
Chris@1079
|
133 bool rightToLeft = false;
|
Chris@1079
|
134
|
Chris@1079
|
135 if (!m_cache.isValid() && timeConstrained) {
|
Chris@1081
|
136 // When rendering the whole area, in a context where we might
|
Chris@1081
|
137 // not be able to complete the work, start from somewhere near
|
Chris@1081
|
138 // the middle so that the region of interest appears first
|
Chris@1079
|
139
|
Chris@1079
|
140 //!!! (perhaps we should avoid doing this if past repaints
|
Chris@1079
|
141 //!!! have been fast enough to do the whole in one shot)
|
Chris@1079
|
142 if (x0 == 0 && x1 == v->getPaintWidth()) {
|
Chris@1079
|
143 x0 = int(x1 * 0.3);
|
Chris@1079
|
144 }
|
Chris@1079
|
145 }
|
Chris@1079
|
146
|
Chris@1079
|
147 if (m_cache.isValid()) {
|
Chris@1090
|
148 cerr << "cache somewhat valid" << endl;
|
Chris@1090
|
149
|
Chris@1079
|
150 // When rendering only a part of the cache, we need to make
|
Chris@1079
|
151 // sure that the part we're rendering is adjacent to (or
|
Chris@1079
|
152 // overlapping) a valid area of cache, if we have one. The
|
Chris@1079
|
153 // alternative is to ditch the valid area of cache and render
|
Chris@1079
|
154 // only the requested area, but that's risky because this can
|
Chris@1079
|
155 // happen when just waving the pointer over a small part of
|
Chris@1079
|
156 // the view -- if we lose the partly-built cache every time
|
Chris@1079
|
157 // the user does that, we'll never finish building it.
|
Chris@1079
|
158 int left = x0;
|
Chris@1079
|
159 int width = x1 - x0;
|
Chris@1079
|
160 bool isLeftOfValidArea = false;
|
Chris@1079
|
161 m_cache.adjustToTouchValidArea(left, width, isLeftOfValidArea);
|
Chris@1079
|
162 x0 = left;
|
Chris@1079
|
163 x1 = x0 + width;
|
Chris@1079
|
164
|
Chris@1079
|
165 // That call also told us whether we should be painting
|
Chris@1079
|
166 // sub-regions of our target region in right-to-left order in
|
Chris@1079
|
167 // order to ensure contiguity
|
Chris@1079
|
168 rightToLeft = isLeftOfValidArea;
|
Chris@1079
|
169 }
|
Chris@1075
|
170
|
Chris@1094
|
171 // Note, we always paint the full height. Smaller heights can be
|
Chris@1094
|
172 // used when painting direct from cache (outside this function),
|
Chris@1094
|
173 // but we want to ensure the cache is coherent without having to
|
Chris@1094
|
174 // worry about vertical matching of required and valid areas as
|
Chris@1094
|
175 // well as horizontal. That's why this function didn't take any
|
Chris@1094
|
176 // y/height parameters.
|
Chris@1094
|
177
|
Chris@1094
|
178 if (bufferIsBinResolution) {
|
Chris@1094
|
179 renderToCacheBinResolution(v, x0, x1 - x0);
|
Chris@1094
|
180 } else {
|
Chris@1094
|
181 renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained);
|
Chris@1094
|
182 }
|
Chris@1079
|
183
|
Chris@1079
|
184 QRect pr = rect & m_cache.getValidArea();
|
Chris@1079
|
185 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(),
|
Chris@1079
|
186 pr.x(), pr.y(), pr.width(), pr.height());
|
Chris@1079
|
187
|
Chris@1079
|
188 if (!timeConstrained && (pr != rect)) {
|
Chris@1079
|
189 //!!! on a first cut, there is a risk that this will happen
|
Chris@1079
|
190 //!!! when we are at start/end of model -- trap, report, and
|
Chris@1079
|
191 //!!! then fix
|
Chris@1079
|
192 throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained");
|
Chris@1079
|
193 }
|
Chris@1079
|
194
|
Chris@1079
|
195 return { pr, {} };
|
Chris@1079
|
196
|
Chris@1073
|
197 //!!! todo: timing/incomplete paint
|
Chris@1073
|
198
|
Chris@1073
|
199 //!!! todo: peak frequency style
|
Chris@1073
|
200
|
Chris@1073
|
201 //!!! todo: transparent style from Colour3DPlot
|
Chris@1074
|
202
|
Chris@1079
|
203 //!!! todo: view magnitudes / normalise visible area
|
Chris@1079
|
204
|
Chris@1079
|
205 //!!! todo: alter documentation for view mag stuff (cached paints
|
Chris@1079
|
206 //!!! do not update MagnitudeRange)
|
Chris@1079
|
207
|
Chris@1079
|
208 //!!! todo, here or in caller: illuminateLocalFeatures
|
Chris@1079
|
209
|
Chris@1079
|
210 //!!! fft model scaling?
|
Chris@1079
|
211
|
Chris@1079
|
212 //!!! should we own the Dense3DModelPeakCache here? or should it persist
|
Chris@1073
|
213 }
|
Chris@1073
|
214
|
Chris@1094
|
215 bool
|
Chris@1094
|
216 Colour3DPlotRenderer::useBinResolutionForDrawBuffer(LayerGeometryProvider *v) const
|
Chris@1094
|
217 {
|
Chris@1094
|
218 DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1094
|
219 if (!model) return false;
|
Chris@1094
|
220 int binResolution = model->getResolution();
|
Chris@1094
|
221 int zoomLevel = v->getZoomLevel();
|
Chris@1094
|
222 return (binResolution > zoomLevel);
|
Chris@1094
|
223 }
|
Chris@1094
|
224
|
Chris@1080
|
225 void
|
Chris@1094
|
226 Colour3DPlotRenderer::renderToCachePixelResolution(LayerGeometryProvider *v,
|
Chris@1094
|
227 int x0, int repaintWidth,
|
Chris@1094
|
228 bool rightToLeft,
|
Chris@1094
|
229 bool timeConstrained)
|
Chris@1079
|
230 {
|
Chris@1094
|
231 cerr << "renderToCachePixelResolution" << endl;
|
Chris@1094
|
232
|
Chris@1094
|
233 // Draw to the draw buffer, and then copy from there. The draw
|
Chris@1094
|
234 // buffer is at the same resolution as the target in the cache, so
|
Chris@1094
|
235 // no extra scaling needed.
|
Chris@1079
|
236
|
Chris@1079
|
237 DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1079
|
238 if (!model || !model->isOK() || !model->isReady()) {
|
Chris@1079
|
239 throw std::logic_error("no source model provided, or model not ready");
|
Chris@1079
|
240 }
|
Chris@1079
|
241
|
Chris@1079
|
242 int h = v->getPaintHeight();
|
Chris@1079
|
243
|
Chris@1094
|
244 clearDrawBuffer(repaintWidth, h);
|
Chris@1079
|
245
|
Chris@1094
|
246 vector<int> binforx(repaintWidth);
|
Chris@1079
|
247 vector<double> binfory(h);
|
Chris@1079
|
248
|
Chris@1079
|
249 bool usePeaksCache = false;
|
Chris@1079
|
250 int binsPerPeak = 1;
|
Chris@1094
|
251 int zoomLevel = v->getZoomLevel();
|
Chris@1094
|
252 int binResolution = model->getResolution();
|
Chris@1079
|
253
|
Chris@1094
|
254 for (int x = 0; x < repaintWidth; ++x) {
|
Chris@1094
|
255 sv_frame_t f0 = v->getFrameForX(x0 + x);
|
Chris@1094
|
256 double s0 = double(f0 - model->getStartFrame()) / binResolution;
|
Chris@1094
|
257 binforx[x] = int(s0 + 0.0001);
|
Chris@1094
|
258 }
|
Chris@1080
|
259
|
Chris@1094
|
260 if (m_sources.peaks) { // peaks cache exists
|
Chris@1080
|
261
|
Chris@1094
|
262 binsPerPeak = m_sources.peaks->getColumnsPerPeak();
|
Chris@1094
|
263 usePeaksCache = (binResolution * binsPerPeak) < zoomLevel;
|
Chris@1094
|
264
|
Chris@1094
|
265 if (m_params.colourScale.getScale() ==
|
Chris@1094
|
266 ColourScale::PhaseColourScale) {
|
Chris@1094
|
267 usePeaksCache = false;
|
Chris@1079
|
268 }
|
Chris@1079
|
269 }
|
Chris@1082
|
270
|
Chris@1094
|
271 cerr << "[PIX] zoomLevel = " << zoomLevel
|
Chris@1094
|
272 << ", binResolution " << binResolution
|
Chris@1094
|
273 << ", binsPerPeak " << binsPerPeak
|
Chris@1094
|
274 << ", peak cache " << m_sources.peaks
|
Chris@1094
|
275 << ", usePeaksCache = " << usePeaksCache
|
Chris@1094
|
276 << endl;
|
Chris@1094
|
277
|
Chris@1080
|
278 for (int y = 0; y < h; ++y) {
|
Chris@1090
|
279 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
|
Chris@1080
|
280 }
|
Chris@1079
|
281
|
Chris@1083
|
282 int attainedWidth = renderDrawBuffer(repaintWidth,
|
Chris@1080
|
283 h,
|
Chris@1080
|
284 binforx,
|
Chris@1080
|
285 binfory,
|
Chris@1080
|
286 usePeaksCache,
|
Chris@1080
|
287 rightToLeft,
|
Chris@1080
|
288 timeConstrained);
|
Chris@1083
|
289
|
Chris@1094
|
290 if (attainedWidth == 0) return;
|
Chris@1084
|
291
|
Chris@1094
|
292 // draw buffer is pixel resolution, no scaling factors or padding involved
|
Chris@1084
|
293
|
Chris@1084
|
294 int paintedLeft = x0;
|
Chris@1084
|
295 if (rightToLeft) {
|
Chris@1084
|
296 paintedLeft += (repaintWidth - attainedWidth);
|
Chris@1084
|
297 }
|
Chris@1084
|
298
|
Chris@1094
|
299 m_cache.drawImage(paintedLeft, attainedWidth,
|
Chris@1094
|
300 m_drawBuffer,
|
Chris@1094
|
301 paintedLeft - x0, attainedWidth);
|
Chris@1094
|
302 }
|
Chris@1084
|
303
|
Chris@1094
|
304 void
|
Chris@1094
|
305 Colour3DPlotRenderer::renderToCacheBinResolution(LayerGeometryProvider *v,
|
Chris@1094
|
306 int x0, int repaintWidth)
|
Chris@1094
|
307 {
|
Chris@1094
|
308 cerr << "renderToCacheBinResolution" << endl;
|
Chris@1094
|
309
|
Chris@1094
|
310 // Draw to the draw buffer, and then scale-copy from there. Draw
|
Chris@1094
|
311 // buffer is at bin resolution, i.e. buffer x == source column
|
Chris@1094
|
312 // number. We use toolkit smooth scaling for interpolation.
|
Chris@1084
|
313
|
Chris@1094
|
314 DenseThreeDimensionalModel *model = m_sources.source;
|
Chris@1094
|
315 if (!model || !model->isOK() || !model->isReady()) {
|
Chris@1094
|
316 throw std::logic_error("no source model provided, or model not ready");
|
Chris@1094
|
317 }
|
Chris@1094
|
318
|
Chris@1094
|
319 // The draw buffer will contain a fragment at bin resolution. We
|
Chris@1094
|
320 // need to ensure that it starts and ends at points where a
|
Chris@1094
|
321 // time-bin boundary occurs at an exact pixel boundary, and with a
|
Chris@1094
|
322 // certain amount of overlap across existing pixels so that we can
|
Chris@1094
|
323 // scale and draw from it without smoothing errors at the edges.
|
Chris@1094
|
324
|
Chris@1094
|
325 // If (getFrameForX(x) / increment) * increment ==
|
Chris@1094
|
326 // getFrameForX(x), then x is a time-bin boundary. We want two
|
Chris@1094
|
327 // such boundaries at either side of the draw buffer -- one which
|
Chris@1094
|
328 // we draw up to, and one which we subsequently crop at.
|
Chris@1094
|
329
|
Chris@1094
|
330 sv_frame_t leftBoundaryFrame = -1, leftCropFrame = -1;
|
Chris@1094
|
331 sv_frame_t rightBoundaryFrame = -1, rightCropFrame = -1;
|
Chris@1094
|
332
|
Chris@1094
|
333 int drawBufferWidth;
|
Chris@1094
|
334 int binResolution = model->getResolution();
|
Chris@1094
|
335
|
Chris@1094
|
336 for (int x = x0; ; --x) {
|
Chris@1094
|
337 sv_frame_t f = v->getFrameForX(x);
|
Chris@1094
|
338 if ((f / binResolution) * binResolution == f) {
|
Chris@1094
|
339 if (leftCropFrame == -1) leftCropFrame = f;
|
Chris@1094
|
340 else if (x < x0 - 2) {
|
Chris@1094
|
341 leftBoundaryFrame = f;
|
Chris@1094
|
342 break;
|
Chris@1094
|
343 }
|
Chris@1094
|
344 }
|
Chris@1094
|
345 }
|
Chris@1094
|
346 for (int x = x0 + repaintWidth; ; ++x) {
|
Chris@1094
|
347 sv_frame_t f = v->getFrameForX(x);
|
Chris@1094
|
348 if ((f / binResolution) * binResolution == f) {
|
Chris@1094
|
349 if (rightCropFrame == -1) rightCropFrame = f;
|
Chris@1094
|
350 else if (x > x0 + repaintWidth + 2) {
|
Chris@1094
|
351 rightBoundaryFrame = f;
|
Chris@1094
|
352 break;
|
Chris@1094
|
353 }
|
Chris@1094
|
354 }
|
Chris@1094
|
355 }
|
Chris@1094
|
356 drawBufferWidth = int
|
Chris@1094
|
357 ((rightBoundaryFrame - leftBoundaryFrame) / binResolution);
|
Chris@1094
|
358
|
Chris@1094
|
359 int h = v->getPaintHeight();
|
Chris@1094
|
360
|
Chris@1095
|
361 // For our purposes here, the draw buffer needs to be exactly our
|
Chris@1095
|
362 // target size (so we recreate always rather than just clear it)
|
Chris@1095
|
363
|
Chris@1095
|
364 recreateDrawBuffer(drawBufferWidth, h);
|
Chris@1094
|
365
|
Chris@1094
|
366 vector<int> binforx(drawBufferWidth);
|
Chris@1094
|
367 vector<double> binfory(h);
|
Chris@1094
|
368
|
Chris@1094
|
369 for (int x = 0; x < drawBufferWidth; ++x) {
|
Chris@1094
|
370 binforx[x] = int(leftBoundaryFrame / binResolution) + x;
|
Chris@1094
|
371 }
|
Chris@1094
|
372
|
Chris@1094
|
373 cerr << "[BIN] binResolution " << binResolution
|
Chris@1094
|
374 << endl;
|
Chris@1094
|
375
|
Chris@1094
|
376 for (int y = 0; y < h; ++y) {
|
Chris@1094
|
377 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
|
Chris@1094
|
378 }
|
Chris@1094
|
379
|
Chris@1094
|
380 int attainedWidth = renderDrawBuffer(drawBufferWidth,
|
Chris@1094
|
381 h,
|
Chris@1094
|
382 binforx,
|
Chris@1094
|
383 binfory,
|
Chris@1094
|
384 false,
|
Chris@1094
|
385 false,
|
Chris@1094
|
386 false);
|
Chris@1094
|
387
|
Chris@1094
|
388 if (attainedWidth == 0) return;
|
Chris@1094
|
389
|
Chris@1094
|
390 int scaledLeft = v->getXForFrame(leftBoundaryFrame);
|
Chris@1094
|
391 int scaledRight = v->getXForFrame(rightBoundaryFrame);
|
Chris@1095
|
392
|
Chris@1095
|
393 cerr << "scaling draw buffer from width " << m_drawBuffer.width()
|
Chris@1095
|
394 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = "
|
Chris@1095
|
395 << drawBufferWidth << ")" << endl;
|
Chris@1094
|
396
|
Chris@1094
|
397 QImage scaled = m_drawBuffer.scaled
|
Chris@1094
|
398 (scaledRight - scaledLeft, h,
|
Chris@1094
|
399 Qt::IgnoreAspectRatio, (m_params.interpolate ?
|
Chris@1094
|
400 Qt::SmoothTransformation :
|
Chris@1094
|
401 Qt::FastTransformation));
|
Chris@1084
|
402
|
Chris@1094
|
403 int scaledLeftCrop = v->getXForFrame(leftCropFrame);
|
Chris@1094
|
404 int scaledRightCrop = v->getXForFrame(rightCropFrame);
|
Chris@1094
|
405
|
Chris@1094
|
406 int targetLeft = scaledLeftCrop;
|
Chris@1094
|
407 if (targetLeft < 0) {
|
Chris@1094
|
408 targetLeft = 0;
|
Chris@1094
|
409 }
|
Chris@1094
|
410
|
Chris@1094
|
411 int targetWidth = scaledRightCrop - targetLeft;
|
Chris@1094
|
412 if (targetLeft + targetWidth > m_cache.getSize().width()) {
|
Chris@1094
|
413 targetWidth = m_cache.getSize().width() - targetLeft;
|
Chris@1094
|
414 }
|
Chris@1094
|
415
|
Chris@1094
|
416 int sourceLeft = targetLeft - scaledLeft;
|
Chris@1094
|
417 if (sourceLeft < 0) {
|
Chris@1094
|
418 sourceLeft = 0;
|
Chris@1094
|
419 }
|
Chris@1094
|
420
|
Chris@1094
|
421 int sourceWidth = targetWidth;
|
Chris@1094
|
422
|
Chris@1094
|
423 cerr << "repaintWidth = " << repaintWidth
|
Chris@1094
|
424 << ", targetWidth = " << targetWidth << endl;
|
Chris@1094
|
425
|
Chris@1094
|
426 if (targetWidth > 0) {
|
Chris@1094
|
427 m_cache.drawImage(targetLeft, targetWidth,
|
Chris@1094
|
428 scaled,
|
Chris@1094
|
429 sourceLeft, sourceWidth);
|
Chris@1084
|
430 }
|
Chris@1079
|
431 }
|
Chris@1083
|
432
|
Chris@1083
|
433 int
|
Chris@1083
|
434 Colour3DPlotRenderer::renderDrawBuffer(int w, int h,
|
Chris@1083
|
435 const vector<int> &binforx,
|
Chris@1083
|
436 const vector<double> &binfory,
|
Chris@1083
|
437 bool usePeaksCache,
|
Chris@1083
|
438 bool rightToLeft,
|
Chris@1083
|
439 bool timeConstrained)
|
Chris@1083
|
440 {
|
Chris@1083
|
441 // Callers must have checked that the appropriate subset of
|
Chris@1083
|
442 // Sources data members are set for the supplied flags (e.g. that
|
Chris@1083
|
443 // peaks model exists if usePeaksCache)
|
Chris@1083
|
444
|
Chris@1083
|
445 RenderTimer timer(timeConstrained ?
|
Chris@1083
|
446 RenderTimer::FastRender :
|
Chris@1083
|
447 RenderTimer::NoTimeout);
|
Chris@1083
|
448
|
Chris@1083
|
449 int minbin = int(binfory[0] + 0.0001);
|
Chris@1083
|
450 int maxbin = int(binfory[h-1]);
|
Chris@1083
|
451 if (minbin < 0) minbin = 0;
|
Chris@1083
|
452 if (maxbin < 0) maxbin = minbin+1;
|
Chris@1083
|
453
|
Chris@1083
|
454 int divisor = 1;
|
Chris@1083
|
455 DenseThreeDimensionalModel *sourceModel = m_sources.source;
|
Chris@1083
|
456 if (usePeaksCache) {
|
Chris@1083
|
457 divisor = m_sources.peaks->getColumnsPerPeak();
|
Chris@1083
|
458 sourceModel = m_sources.peaks;
|
Chris@1083
|
459 }
|
Chris@1083
|
460
|
Chris@1083
|
461 int psx = -1;
|
Chris@1083
|
462
|
Chris@1083
|
463 int start = 0;
|
Chris@1083
|
464 int finish = w;
|
Chris@1083
|
465 int step = 1;
|
Chris@1083
|
466
|
Chris@1083
|
467 if (rightToLeft) {
|
Chris@1083
|
468 start = w-1;
|
Chris@1083
|
469 finish = -1;
|
Chris@1083
|
470 step = -1;
|
Chris@1083
|
471 }
|
Chris@1083
|
472
|
Chris@1083
|
473 int columnCount = 0;
|
Chris@1083
|
474
|
Chris@1083
|
475 vector<float> preparedColumn;
|
Chris@1094
|
476
|
Chris@1094
|
477 int modelWidth = sourceModel->getWidth();
|
Chris@1094
|
478 cerr << "modelWidth " << modelWidth << endl;
|
Chris@1083
|
479
|
Chris@1083
|
480 for (int x = start; x != finish; x += step) {
|
Chris@1083
|
481
|
Chris@1083
|
482 // x is the on-canvas pixel coord; sx (later) will be the
|
Chris@1083
|
483 // source column index
|
Chris@1083
|
484
|
Chris@1083
|
485 ++columnCount;
|
Chris@1083
|
486
|
Chris@1083
|
487 if (binforx[x] < 0) continue;
|
Chris@1083
|
488
|
Chris@1083
|
489 int sx0 = binforx[x] / divisor;
|
Chris@1083
|
490 int sx1 = sx0;
|
Chris@1083
|
491 if (x+1 < w) sx1 = binforx[x+1] / divisor;
|
Chris@1083
|
492 if (sx0 < 0) sx0 = sx1 - 1;
|
Chris@1083
|
493 if (sx0 < 0) continue;
|
Chris@1083
|
494 if (sx1 <= sx0) sx1 = sx0 + 1;
|
Chris@1083
|
495
|
Chris@1083
|
496 vector<float> pixelPeakColumn;
|
Chris@1083
|
497
|
Chris@1083
|
498 for (int sx = sx0; sx < sx1; ++sx) {
|
Chris@1083
|
499
|
Chris@1083
|
500 #ifdef DEBUG_SPECTROGRAM_REPAINT
|
Chris@1094
|
501 cerr << "sx = " << sx << endl;
|
Chris@1083
|
502 #endif
|
Chris@1083
|
503
|
Chris@1094
|
504 if (sx < 0 || sx >= modelWidth) {
|
Chris@1083
|
505 continue;
|
Chris@1083
|
506 }
|
Chris@1083
|
507
|
Chris@1083
|
508 if (sx != psx) {
|
Chris@1083
|
509
|
Chris@1083
|
510 // order:
|
Chris@1083
|
511 // get column -> scale -> record extents ->
|
Chris@1083
|
512 // normalise -> peak pick -> apply display gain ->
|
Chris@1083
|
513 // distribute/interpolate
|
Chris@1083
|
514
|
Chris@1083
|
515 ColumnOp::Column fullColumn = sourceModel->getColumn(sx);
|
Chris@1090
|
516
|
Chris@1094
|
517 // cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size()
|
Chris@1094
|
518 // << ", minbin " << minbin << ", maxbin " << maxbin << endl;
|
Chris@1090
|
519
|
Chris@1083
|
520 ColumnOp::Column column =
|
Chris@1083
|
521 vector<float>(fullColumn.data() + minbin,
|
Chris@1083
|
522 fullColumn.data() + maxbin + 1);
|
Chris@1083
|
523
|
Chris@1083
|
524 //!!! fft scale if (m_colourScale != PhaseColourScale) {
|
Chris@1083
|
525 // column = ColumnOp::fftScale(column, m_fftSize);
|
Chris@1083
|
526 // }
|
Chris@1083
|
527
|
Chris@1083
|
528 //!!! extents recordColumnExtents(column,
|
Chris@1083
|
529 // sx,
|
Chris@1083
|
530 // overallMag,
|
Chris@1083
|
531 // overallMagChanged);
|
Chris@1083
|
532
|
Chris@1083
|
533 // if (m_colourScale != PhaseColourScale) {
|
Chris@1083
|
534 column = ColumnOp::normalize(column, m_params.normalization);
|
Chris@1083
|
535 // }
|
Chris@1083
|
536
|
Chris@1083
|
537 if (m_params.binDisplay == PeakBins) {
|
Chris@1083
|
538 column = ColumnOp::peakPick(column);
|
Chris@1083
|
539 }
|
Chris@1083
|
540
|
Chris@1083
|
541 preparedColumn =
|
Chris@1083
|
542 ColumnOp::distribute(column, //!!! gain? ColumnOp::applyGain(column, m_gain),
|
Chris@1083
|
543 h,
|
Chris@1083
|
544 binfory,
|
Chris@1083
|
545 minbin,
|
Chris@1083
|
546 m_params.interpolate);
|
Chris@1083
|
547
|
Chris@1083
|
548 psx = sx;
|
Chris@1083
|
549 }
|
Chris@1083
|
550
|
Chris@1083
|
551 if (sx == sx0) {
|
Chris@1083
|
552 pixelPeakColumn = preparedColumn;
|
Chris@1083
|
553 } else {
|
Chris@1083
|
554 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
|
Chris@1083
|
555 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
|
Chris@1083
|
556 preparedColumn[i]);
|
Chris@1083
|
557 }
|
Chris@1083
|
558 }
|
Chris@1083
|
559 }
|
Chris@1083
|
560
|
Chris@1083
|
561 if (!pixelPeakColumn.empty()) {
|
Chris@1083
|
562 for (int y = 0; y < h; ++y) {
|
Chris@1083
|
563 m_drawBuffer.setPixel
|
Chris@1083
|
564 (x,
|
Chris@1083
|
565 h-y-1,
|
Chris@1083
|
566 m_params.colourScale.getPixel(pixelPeakColumn[y]));
|
Chris@1083
|
567 }
|
Chris@1083
|
568 }
|
Chris@1083
|
569
|
Chris@1083
|
570 double fractionComplete = double(columnCount) / double(w);
|
Chris@1083
|
571 if (timer.outOfTime(fractionComplete)) {
|
Chris@1083
|
572 return columnCount;
|
Chris@1083
|
573 }
|
Chris@1083
|
574 }
|
Chris@1083
|
575
|
Chris@1083
|
576 return columnCount;
|
Chris@1083
|
577 }
|
Chris@1083
|
578
|
Chris@1079
|
579 void
|
Chris@1095
|
580 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h)
|
Chris@1079
|
581 {
|
Chris@1095
|
582 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8);
|
Chris@1079
|
583
|
Chris@1095
|
584 for (int pixel = 0; pixel < 256; ++pixel) {
|
Chris@1095
|
585 //!!! todo: colour rotation (here 0)
|
Chris@1095
|
586 m_drawBuffer.setColor
|
Chris@1095
|
587 ((unsigned char)pixel,
|
Chris@1095
|
588 m_params.colourScale.getColourForPixel(pixel, 0).rgb());
|
Chris@1079
|
589 }
|
Chris@1079
|
590
|
Chris@1079
|
591 m_drawBuffer.fill(0);
|
Chris@1079
|
592 }
|
Chris@1079
|
593
|
Chris@1095
|
594 void
|
Chris@1095
|
595 Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
|
Chris@1095
|
596 {
|
Chris@1095
|
597 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
|
Chris@1095
|
598 recreateDrawBuffer(w, h);
|
Chris@1095
|
599 } else {
|
Chris@1095
|
600 m_drawBuffer.fill(0);
|
Chris@1095
|
601 }
|
Chris@1095
|
602 }
|
Chris@1079
|
603
|
Chris@1095
|
604
|