annotate layer/Colour3DPlotRenderer.cpp @ 1094:8a815776151c spectrogram-minor-refactor

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