annotate layer/Colour3DPlotRenderer.cpp @ 1500:ac5a82e57d23

More debug bits
author Chris Cannam
date Wed, 11 Sep 2019 11:21:00 +0100
parents e4c9d38d304d
children 62aad7969f8b
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@1117 19 #include "base/Profiler.h"
Chris@1214 20 #include "base/HitCount.h"
Chris@1117 21
Chris@1075 22 #include "data/model/DenseThreeDimensionalModel.h"
Chris@1075 23 #include "data/model/Dense3DModelPeakCache.h"
Chris@1075 24 #include "data/model/FFTModel.h"
Chris@1075 25
Chris@1077 26 #include "LayerGeometryProvider.h"
Chris@1082 27 #include "VerticalBinLayer.h"
Chris@1109 28 #include "PaintAssistant.h"
Chris@1139 29 #include "ImageRegionFinder.h"
Chris@1109 30
Chris@1109 31 #include "view/ViewManager.h" // for main model sample rate. Pity
Chris@1075 32
Chris@1079 33 #include <vector>
Chris@1079 34
Chris@1325 35 #include <utility>
Chris@1325 36 using namespace std::rel_ops;
Chris@1325 37
Chris@1362 38 //#define DEBUG_COLOUR_PLOT_REPAINT 1
Chris@1094 39
Chris@1079 40 using namespace std;
Chris@1079 41
Chris@1073 42 Colour3DPlotRenderer::RenderResult
Chris@1113 43 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect)
Chris@1076 44 {
Chris@1090 45 return render(v, paint, rect, false);
Chris@1076 46 }
Chris@1076 47
Chris@1076 48 Colour3DPlotRenderer::RenderResult
Chris@1113 49 Colour3DPlotRenderer::renderTimeConstrained(const LayerGeometryProvider *v,
Chris@1090 50 QPainter &paint, QRect rect)
Chris@1076 51 {
Chris@1090 52 return render(v, paint, rect, true);
Chris@1076 53 }
Chris@1076 54
Chris@1096 55 QRect
Chris@1121 56 Colour3DPlotRenderer::getLargestUncachedRect(const LayerGeometryProvider *v)
Chris@1096 57 {
Chris@1121 58 RenderType renderType = decideRenderType(v);
Chris@1121 59
Chris@1121 60 if (renderType == DirectTranslucent) {
Chris@1121 61 return QRect(); // never cached
Chris@1121 62 }
Chris@1121 63
Chris@1096 64 int h = m_cache.getSize().height();
Chris@1096 65
Chris@1096 66 QRect areaLeft(0, 0, m_cache.getValidLeft(), h);
Chris@1096 67 QRect areaRight(m_cache.getValidRight(), 0,
Chris@1096 68 m_cache.getSize().width() - m_cache.getValidRight(), h);
Chris@1096 69
Chris@1096 70 if (areaRight.width() > areaLeft.width()) {
Chris@1096 71 return areaRight;
Chris@1096 72 } else {
Chris@1096 73 return areaLeft;
Chris@1096 74 }
Chris@1096 75 }
Chris@1096 76
Chris@1122 77 bool
Chris@1122 78 Colour3DPlotRenderer::geometryChanged(const LayerGeometryProvider *v)
Chris@1122 79 {
Chris@1122 80 RenderType renderType = decideRenderType(v);
Chris@1122 81
Chris@1122 82 if (renderType == DirectTranslucent) {
Chris@1122 83 return true; // never cached
Chris@1122 84 }
Chris@1122 85
Chris@1122 86 if (m_cache.getSize() == v->getPaintSize() &&
Chris@1122 87 m_cache.getZoomLevel() == v->getZoomLevel() &&
Chris@1122 88 m_cache.getStartFrame() == v->getStartFrame()) {
Chris@1122 89 return false;
Chris@1122 90 } else {
Chris@1122 91 return true;
Chris@1122 92 }
Chris@1122 93 }
Chris@1122 94
Chris@1076 95 Colour3DPlotRenderer::RenderResult
Chris@1113 96 Colour3DPlotRenderer::render(const LayerGeometryProvider *v,
Chris@1090 97 QPainter &paint, QRect rect, bool timeConstrained)
Chris@1073 98 {
Chris@1109 99 RenderType renderType = decideRenderType(v);
Chris@1109 100
Chris@1221 101 if (timeConstrained) {
Chris@1221 102 if (renderType != DrawBufferPixelResolution) {
Chris@1221 103 // Rendering should be fast in bin-resolution and direct
Chris@1221 104 // draw cases because we are quite well zoomed-in, and the
Chris@1221 105 // sums are easier this way. Calculating boundaries later
Chris@1221 106 // will be fiddly for partial paints otherwise.
Chris@1221 107 timeConstrained = false;
Chris@1221 108
Chris@1221 109 } else if (m_secondsPerXPixelValid) {
Chris@1221 110 double predicted = m_secondsPerXPixel * rect.width();
Chris@1236 111 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 112 SVDEBUG << "render " << m_sources.source
Chris@1499 113 << ": Predicted time for width " << rect.width() << " = "
Chris@1236 114 << predicted << " (" << m_secondsPerXPixel << " x "
Chris@1236 115 << rect.width() << ")" << endl;
Chris@1221 116 #endif
Chris@1450 117 if (predicted < 0.175) {
Chris@1221 118 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 119 SVDEBUG << "render " << m_sources.source
Chris@1499 120 << ": Predicted time looks fast enough: no partial renders"
Chris@1221 121 << endl;
Chris@1221 122 #endif
Chris@1221 123 timeConstrained = false;
Chris@1221 124 }
Chris@1221 125 }
Chris@1109 126 }
Chris@1221 127
Chris@1079 128 int x0 = v->getXForViewX(rect.x());
Chris@1079 129 int x1 = v->getXForViewX(rect.x() + rect.width());
Chris@1079 130 if (x0 < 0) x0 = 0;
Chris@1079 131 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
Chris@1079 132
Chris@1120 133 sv_frame_t startFrame = v->getStartFrame();
Chris@1451 134
Chris@1451 135 bool justInvalidated =
Chris@1451 136 (m_cache.getSize() != v->getPaintSize() ||
Chris@1451 137 m_cache.getZoomLevel() != v->getZoomLevel());
Chris@1120 138
Chris@1079 139 m_cache.resize(v->getPaintSize());
Chris@1079 140 m_cache.setZoomLevel(v->getZoomLevel());
Chris@1079 141
Chris@1119 142 m_magCache.resize(v->getPaintSize().width());
Chris@1119 143 m_magCache.setZoomLevel(v->getZoomLevel());
Chris@1119 144
Chris@1120 145 if (renderType == DirectTranslucent) {
Chris@1121 146 MagnitudeRange range = renderDirectTranslucent(v, paint, rect);
Chris@1121 147 return { rect, range };
Chris@1120 148 }
Chris@1120 149
Chris@1123 150 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 151 SVDEBUG << "render " << m_sources.source
Chris@1499 152 << ": cache start " << m_cache.getStartFrame()
Chris@1499 153 << " valid left " << m_cache.getValidLeft()
Chris@1499 154 << " valid right " << m_cache.getValidRight()
Chris@1499 155 << endl;
Chris@1500 156 SVDEBUG << "render " << m_sources.source
Chris@1500 157 << ": view start " << startFrame
Chris@1499 158 << " x0 " << x0
Chris@1499 159 << " x1 " << x1
Chris@1499 160 << endl;
Chris@1123 161 #endif
Chris@1214 162
Chris@1214 163 static HitCount count("Colour3DPlotRenderer: image cache");
Chris@1451 164
Chris@1079 165 if (m_cache.isValid()) { // some part of the cache is valid
Chris@1079 166
Chris@1079 167 if (v->getXForFrame(m_cache.getStartFrame()) ==
Chris@1079 168 v->getXForFrame(startFrame) &&
Chris@1079 169 m_cache.getValidLeft() <= x0 &&
Chris@1079 170 m_cache.getValidRight() >= x1) {
Chris@1090 171
Chris@1123 172 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 173 SVDEBUG << "render " << m_sources.source
Chris@1500 174 << ": cache hit" << endl;
Chris@1123 175 #endif
Chris@1214 176 count.hit();
Chris@1090 177
Chris@1079 178 // cache is valid for the complete requested area
Chris@1079 179 paint.drawImage(rect, m_cache.getImage(), rect);
Chris@1119 180
Chris@1122 181 MagnitudeRange range = m_magCache.getRange(x0, x1 - x0);
Chris@1119 182
Chris@1119 183 return { rect, range };
Chris@1079 184
Chris@1079 185 } else {
Chris@1123 186 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 187 SVDEBUG << "render " << m_sources.source
Chris@1500 188 << ": cache partial hit" << endl;
Chris@1123 189 #endif
Chris@1214 190 count.partial();
Chris@1090 191
Chris@1079 192 // cache doesn't begin at the right frame or doesn't
Chris@1079 193 // contain the complete view, but might be scrollable or
Chris@1079 194 // partially usable
Chris@1090 195 m_cache.scrollTo(v, startFrame);
Chris@1119 196 m_magCache.scrollTo(v, startFrame);
Chris@1079 197
Chris@1079 198 // if we are not time-constrained, then we want to paint
Chris@1081 199 // the whole area in one go; we don't return a partial
Chris@1081 200 // paint. To avoid providing the more complex logic to
Chris@1081 201 // handle painting discontiguous areas, if the only valid
Chris@1079 202 // part of cache is in the middle, just make the whole
Chris@1079 203 // thing invalid and start again.
Chris@1079 204 if (!timeConstrained) {
Chris@1079 205 if (m_cache.getValidLeft() > x0 &&
Chris@1079 206 m_cache.getValidRight() < x1) {
Chris@1079 207 m_cache.invalidate();
Chris@1079 208 }
Chris@1079 209 }
Chris@1079 210 }
Chris@1090 211 } else {
Chris@1118 212 // cache is completely invalid
Chris@1214 213 count.miss();
Chris@1090 214 m_cache.setStartFrame(startFrame);
Chris@1119 215 m_magCache.setStartFrame(startFrame);
Chris@1075 216 }
Chris@1075 217
Chris@1079 218 bool rightToLeft = false;
Chris@1079 219
Chris@1122 220 int reqx0 = x0;
Chris@1122 221 int reqx1 = x1;
Chris@1122 222
Chris@1079 223 if (!m_cache.isValid() && timeConstrained) {
Chris@1079 224 if (x0 == 0 && x1 == v->getPaintWidth()) {
Chris@1237 225
Chris@1237 226 // When rendering the whole area, in a context where we
Chris@1237 227 // might not be able to complete the work, start from
Chris@1237 228 // somewhere near the middle so that the region of
Chris@1237 229 // interest appears first.
Chris@1237 230 //
Chris@1237 231 // This is very useful if we actually are slow to render,
Chris@1237 232 // but if we're not sure how fast we'll be, we should
Chris@1237 233 // prefer not to because it can be distracting to render
Chris@1237 234 // fast from the middle and then jump back to fill in the
Chris@1237 235 // start. That is:
Chris@1237 236 //
Chris@1237 237 // - if our seconds-per-x-pixel count is invalid, then we
Chris@1237 238 // don't do this: we've probably only just been created
Chris@1237 239 // and don't know how fast we'll be yet (this happens
Chris@1237 240 // often while zooming rapidly in and out). The exception
Chris@1237 241 // to the exception is if we're displaying peak
Chris@1237 242 // frequencies; this we can assume to be slow. (Note that
Chris@1237 243 // if the seconds-per-x-pixel is valid and we know we're
Chris@1237 244 // fast, then we've already set timeConstrained false
Chris@1237 245 // above so this doesn't apply)
Chris@1237 246 //
Chris@1237 247 // - if we're using a peak cache, we don't do this;
Chris@1237 248 // drawing from peak cache is often (even if not always)
Chris@1237 249 // fast.
Chris@1237 250
Chris@1237 251 bool drawFromTheMiddle = true;
Chris@1237 252
Chris@1237 253 if (!m_secondsPerXPixelValid &&
Chris@1237 254 (m_params.binDisplay != BinDisplay::PeakFrequencies)) {
Chris@1237 255 drawFromTheMiddle = false;
Chris@1237 256 } else {
Chris@1237 257 int peakCacheIndex = -1, binsPerPeak = -1;
Chris@1237 258 getPreferredPeakCache(v, peakCacheIndex, binsPerPeak);
Chris@1237 259 if (peakCacheIndex >= 0) { // have a peak cache
Chris@1237 260 drawFromTheMiddle = false;
Chris@1237 261 }
Chris@1237 262 }
Chris@1237 263
Chris@1237 264 if (drawFromTheMiddle) {
Chris@1222 265 double offset = 0.5 * (double(rand()) / double(RAND_MAX));
Chris@1222 266 x0 = int(x1 * offset);
Chris@1213 267 }
Chris@1079 268 }
Chris@1079 269 }
Chris@1079 270
Chris@1079 271 if (m_cache.isValid()) {
Chris@1090 272
Chris@1079 273 // When rendering only a part of the cache, we need to make
Chris@1079 274 // sure that the part we're rendering is adjacent to (or
Chris@1079 275 // overlapping) a valid area of cache, if we have one. The
Chris@1079 276 // alternative is to ditch the valid area of cache and render
Chris@1079 277 // only the requested area, but that's risky because this can
Chris@1079 278 // happen when just waving the pointer over a small part of
Chris@1079 279 // the view -- if we lose the partly-built cache every time
Chris@1079 280 // the user does that, we'll never finish building it.
Chris@1079 281 int left = x0;
Chris@1079 282 int width = x1 - x0;
Chris@1079 283 bool isLeftOfValidArea = false;
Chris@1079 284 m_cache.adjustToTouchValidArea(left, width, isLeftOfValidArea);
Chris@1079 285 x0 = left;
Chris@1079 286 x1 = x0 + width;
Chris@1079 287
Chris@1079 288 // That call also told us whether we should be painting
Chris@1079 289 // sub-regions of our target region in right-to-left order in
Chris@1079 290 // order to ensure contiguity
Chris@1079 291 rightToLeft = isLeftOfValidArea;
Chris@1079 292 }
Chris@1075 293
Chris@1109 294 // Note, we always paint the full height to cache. We want to
Chris@1109 295 // ensure the cache is coherent without having to worry about
Chris@1109 296 // vertical matching of required and valid areas as well as
Chris@1109 297 // horizontal.
Chris@1094 298
Chris@1109 299 if (renderType == DrawBufferBinResolution) {
Chris@1109 300
Chris@1094 301 renderToCacheBinResolution(v, x0, x1 - x0);
Chris@1109 302
Chris@1109 303 } else { // must be DrawBufferPixelResolution, handled DirectTranslucent earlier
Chris@1109 304
Chris@1451 305 if (timeConstrained && justInvalidated) {
Chris@1500 306 SVDEBUG << "render " << m_sources.source
Chris@1500 307 << ": invalidated cache in time-constrained context, that's all we're doing for now - wait for next update to start filling" << endl;
Chris@1451 308 } else {
Chris@1451 309 renderToCachePixelResolution(v, x0, x1 - x0, rightToLeft, timeConstrained);
Chris@1451 310 }
Chris@1094 311 }
Chris@1079 312
Chris@1079 313 QRect pr = rect & m_cache.getValidArea();
Chris@1079 314 paint.drawImage(pr.x(), pr.y(), m_cache.getImage(),
Chris@1079 315 pr.x(), pr.y(), pr.width(), pr.height());
Chris@1079 316
Chris@1079 317 if (!timeConstrained && (pr != rect)) {
Chris@1494 318 QRect cva = m_cache.getValidArea();
Chris@1265 319 SVCERR << "WARNING: failed to render entire requested rect "
Chris@1451 320 << "even when not time-constrained: wanted "
Chris@1450 321 << rect.x() << "," << rect.y() << " "
Chris@1451 322 << rect.width() << "x" << rect.height() << ", got "
Chris@1450 323 << pr.x() << "," << pr.y() << " "
Chris@1450 324 << pr.width() << "x" << pr.height()
Chris@1451 325 << ", after request of width " << (x1 - x0)
Chris@1494 326 << endl
Chris@1494 327 << "(cache valid area is "
Chris@1494 328 << cva.x() << "," << cva.y() << " "
Chris@1494 329 << cva.width() << "x" << cva.height() << ")"
Chris@1450 330 << endl;
Chris@1079 331 }
Chris@1120 332
Chris@1122 333 MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0);
Chris@1412 334
Chris@1412 335 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 336 SVDEBUG << "render " << m_sources.source
Chris@1499 337 << ": returning rect rendered as " << pr.x() << "," << pr.y()
Chris@1412 338 << " " << pr.width() << "x" << pr.height() << endl;
Chris@1499 339 SVDEBUG << "render " << m_sources.source
Chris@1499 340 << ": mag range from cache in x-range " << reqx0
Chris@1412 341 << " to " << reqx1 << " is " << range.getMin() << " -> "
Chris@1412 342 << range.getMax() << endl;
Chris@1412 343 #endif
Chris@1120 344
Chris@1120 345 return { pr, range };
Chris@1073 346 }
Chris@1073 347
Chris@1109 348 Colour3DPlotRenderer::RenderType
Chris@1113 349 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const
Chris@1094 350 {
Chris@1469 351 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1109 352 if (!model || !v || !(v->getViewManager())) {
Chris@1109 353 return DrawBufferPixelResolution; // or anything
Chris@1109 354 }
Chris@1109 355
Chris@1094 356 int binResolution = model->getResolution();
Chris@1325 357 ZoomLevel zoomLevel = v->getZoomLevel();
Chris@1109 358 sv_samplerate_t modelRate = model->getSampleRate();
Chris@1109 359
Chris@1109 360 double rateRatio = v->getViewManager()->getMainModelSampleRate() / modelRate;
Chris@1109 361 double relativeBinResolution = binResolution * rateRatio;
Chris@1109 362
Chris@1109 363 if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
Chris@1109 364 // no alternative works here
Chris@1109 365 return DrawBufferPixelResolution;
Chris@1109 366 }
Chris@1109 367
Chris@1109 368 if (!m_params.alwaysOpaque && !m_params.interpolate) {
Chris@1109 369
Chris@1109 370 // consider translucent option -- only if not smoothing & not
Chris@1109 371 // explicitly requested opaque & sufficiently zoomed-in
Chris@1109 372
Chris@1117 373 if (model->getHeight() * 3 < v->getPaintHeight() &&
Chris@1325 374 zoomLevel < ZoomLevel(ZoomLevel::FramesPerPixel,
Chris@1325 375 int(round(relativeBinResolution / 3)))) {
Chris@1109 376 return DirectTranslucent;
Chris@1109 377 }
Chris@1109 378 }
Chris@1109 379
Chris@1325 380 if (ZoomLevel(ZoomLevel::FramesPerPixel,
Chris@1325 381 int(round(relativeBinResolution))) > zoomLevel) {
Chris@1109 382 return DrawBufferBinResolution;
Chris@1109 383 } else {
Chris@1109 384 return DrawBufferPixelResolution;
Chris@1109 385 }
Chris@1109 386 }
Chris@1109 387
Chris@1138 388 ColumnOp::Column
Chris@1161 389 Colour3DPlotRenderer::getColumn(int sx, int minbin, int nbins,
Chris@1212 390 int peakCacheIndex) const
Chris@1138 391 {
Chris@1138 392 // order:
Chris@1138 393 // get column -> scale -> normalise -> record extents ->
Chris@1138 394 // peak pick -> distribute/interpolate -> apply display gain
Chris@1138 395
Chris@1138 396 // we do the first bit here:
Chris@1138 397 // get column -> scale -> normalise
Chris@1138 398
Chris@1138 399 ColumnOp::Column column;
Chris@1364 400
Chris@1364 401 if (m_params.showDerivative && sx > 0) {
Chris@1364 402
Chris@1364 403 auto prev = getColumnRaw(sx - 1, minbin, nbins, peakCacheIndex);
Chris@1364 404 column = getColumnRaw(sx, minbin, nbins, peakCacheIndex);
Chris@1364 405
Chris@1364 406 for (int i = 0; i < nbins; ++i) {
Chris@1364 407 column[i] -= prev[i];
Chris@1364 408 }
Chris@1364 409
Chris@1364 410 } else {
Chris@1364 411 column = getColumnRaw(sx, minbin, nbins, peakCacheIndex);
Chris@1364 412 }
Chris@1364 413
Chris@1364 414 if (m_params.colourScale.getScale() == ColourScaleType::Phase &&
Chris@1469 415 !m_sources.fft.isNone()) {
Chris@1364 416 return column;
Chris@1364 417 } else {
Chris@1364 418 column = ColumnOp::applyGain(column, m_params.scaleFactor);
Chris@1364 419 column = ColumnOp::normalize(column, m_params.normalization);
Chris@1364 420 return column;
Chris@1364 421 }
Chris@1364 422 }
Chris@1364 423
Chris@1364 424 ColumnOp::Column
Chris@1364 425 Colour3DPlotRenderer::getColumnRaw(int sx, int minbin, int nbins,
Chris@1364 426 int peakCacheIndex) const
Chris@1364 427 {
Chris@1364 428 Profiler profiler("Colour3DPlotRenderer::getColumn");
Chris@1364 429
Chris@1364 430 ColumnOp::Column column;
Chris@1469 431 ColumnOp::Column fullColumn;
Chris@1364 432
Chris@1469 433 if (m_params.colourScale.getScale() == ColourScaleType::Phase) {
Chris@1469 434 auto fftModel = ModelById::getAs<FFTModel>(m_sources.fft);
Chris@1469 435 if (fftModel) {
Chris@1469 436 fullColumn = fftModel->getPhases(sx);
Chris@1469 437 }
Chris@1138 438 }
Chris@1138 439
Chris@1469 440 if (fullColumn.empty()) {
Chris@1469 441
Chris@1469 442 if (peakCacheIndex >= 0) {
Chris@1473 443 auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
Chris@1473 444 (m_sources.peakCaches[peakCacheIndex]);
Chris@1473 445 if (!peakCache) {
Chris@1473 446 return vector<float>(nbins, 0.f);
Chris@1473 447 }
Chris@1473 448 fullColumn = peakCache->getColumn(sx);
Chris@1469 449 } else {
Chris@1469 450 auto model = ModelById::getAs<DenseThreeDimensionalModel>
Chris@1469 451 (m_sources.source);
Chris@1469 452 if (!model) {
Chris@1469 453 return vector<float>(nbins, 0.f);
Chris@1469 454 }
Chris@1469 455 fullColumn = model->getColumn(sx);
Chris@1469 456 }
Chris@1469 457 }
Chris@1469 458
Chris@1469 459 column = vector<float>(fullColumn.data() + minbin,
Chris@1469 460 fullColumn.data() + minbin + nbins);
Chris@1138 461 return column;
Chris@1138 462 }
Chris@1138 463
Chris@1121 464 MagnitudeRange
Chris@1113 465 Colour3DPlotRenderer::renderDirectTranslucent(const LayerGeometryProvider *v,
Chris@1109 466 QPainter &paint,
Chris@1109 467 QRect rect)
Chris@1109 468 {
Chris@1117 469 Profiler profiler("Colour3DPlotRenderer::renderDirectTranslucent");
Chris@1117 470
Chris@1121 471 MagnitudeRange magRange;
Chris@1121 472
Chris@1115 473 QPoint illuminatePos;
Chris@1115 474 bool illuminate = v->shouldIlluminateLocalFeatures
Chris@1115 475 (m_sources.verticalBinLayer, illuminatePos);
Chris@1109 476
Chris@1469 477 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1469 478 if (!model) return magRange;
Chris@1109 479
Chris@1109 480 int x0 = rect.left();
Chris@1109 481 int x1 = rect.right() + 1;
Chris@1109 482
Chris@1109 483 int h = v->getPaintHeight();
Chris@1109 484
Chris@1109 485 sv_frame_t modelStart = model->getStartFrame();
Chris@1109 486 sv_frame_t modelEnd = model->getEndFrame();
Chris@1109 487 int modelResolution = model->getResolution();
Chris@1109 488
Chris@1109 489 double rateRatio =
Chris@1109 490 v->getViewManager()->getMainModelSampleRate() / model->getSampleRate();
Chris@1109 491
Chris@1109 492 // the s-prefix values are source, i.e. model, column and bin numbers
Chris@1109 493 int sx0 = int((double(v->getFrameForX(x0)) / rateRatio - double(modelStart))
Chris@1109 494 / modelResolution);
Chris@1109 495 int sx1 = int((double(v->getFrameForX(x1)) / rateRatio - double(modelStart))
Chris@1109 496 / modelResolution);
Chris@1109 497
Chris@1109 498 int sh = model->getHeight();
Chris@1109 499
Chris@1109 500 const int buflen = 40;
Chris@1109 501 char labelbuf[buflen];
Chris@1109 502
Chris@1133 503 int minbin = m_sources.verticalBinLayer->getIBinForY(v, h);
Chris@1135 504 if (minbin >= sh) minbin = sh - 1;
Chris@1135 505 if (minbin < 0) minbin = 0;
Chris@1135 506
Chris@1135 507 int nbins = m_sources.verticalBinLayer->getIBinForY(v, 0) - minbin + 1;
Chris@1135 508 if (minbin + nbins > sh) nbins = sh - minbin;
Chris@1133 509
Chris@1109 510 int psx = -1;
Chris@1109 511
Chris@1109 512 vector<float> preparedColumn;
Chris@1109 513
Chris@1109 514 int modelWidth = model->getWidth();
Chris@1109 515
Chris@1109 516 for (int sx = sx0; sx <= sx1; ++sx) {
Chris@1109 517
Chris@1109 518 if (sx < 0 || sx >= modelWidth) {
Chris@1109 519 continue;
Chris@1109 520 }
Chris@1109 521
Chris@1109 522 if (sx != psx) {
Chris@1109 523
Chris@1138 524 // order:
Chris@1138 525 // get column -> scale -> normalise -> record extents ->
Chris@1138 526 // peak pick -> distribute/interpolate -> apply display gain
Chris@1109 527
Chris@1138 528 // this does the first three:
Chris@1219 529 preparedColumn = getColumn(sx, minbin, nbins, -1);
Chris@1131 530
Chris@1131 531 magRange.sample(preparedColumn);
Chris@1109 532
Chris@1109 533 if (m_params.binDisplay == BinDisplay::PeakBins) {
Chris@1115 534 preparedColumn = ColumnOp::peakPick(preparedColumn);
Chris@1109 535 }
Chris@1109 536
Chris@1124 537 // Display gain belongs to the colour scale and is
Chris@1124 538 // applied by the colour scale object when mapping it
Chris@1124 539
Chris@1109 540 psx = sx;
Chris@1109 541 }
Chris@1109 542
Chris@1266 543 sv_frame_t fx = sx * modelResolution + modelStart;
Chris@1109 544
Chris@1266 545 if (fx + modelResolution <= modelStart || fx > modelEnd) continue;
Chris@1109 546
Chris@1109 547 int rx0 = v->getXForFrame(int(double(fx) * rateRatio));
Chris@1266 548 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * rateRatio));
Chris@1109 549
Chris@1266 550 int rw = rx1 - rx0;
Chris@1266 551 if (rw < 1) rw = 1;
Chris@1109 552
Chris@1471 553 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested
Chris@1471 554 // replacement (horizontalAdvance) was only added in Qt 5.11
Chris@1471 555 // which is too new for us
Chris@1471 556 #pragma GCC diagnostic ignored "-Wdeprecated-declarations"
Chris@1471 557
Chris@1266 558 bool showLabel = (rw > 10 &&
Chris@1266 559 paint.fontMetrics().width("0.000000") < rw - 3 &&
Chris@1266 560 paint.fontMetrics().height() < (h / sh));
Chris@1109 561
Chris@1266 562 for (int sy = minbin; sy < minbin + nbins; ++sy) {
Chris@1109 563
Chris@1109 564 int ry0 = m_sources.verticalBinLayer->getIYForBin(v, sy);
Chris@1109 565 int ry1 = m_sources.verticalBinLayer->getIYForBin(v, sy + 1);
Chris@1116 566
Chris@1116 567 if (m_params.invertVertical) {
Chris@1116 568 ry0 = h - ry0 - 1;
Chris@1116 569 ry1 = h - ry1 - 1;
Chris@1116 570 }
Chris@1116 571
Chris@1109 572 QRect r(rx0, ry1, rw, ry0 - ry1);
Chris@1109 573
Chris@1109 574 float value = preparedColumn[sy - minbin];
Chris@1112 575 QColor colour = m_params.colourScale.getColour(value,
Chris@1112 576 m_params.colourRotation);
Chris@1109 577
Chris@1109 578 if (rw == 1) {
Chris@1109 579 paint.setPen(colour);
Chris@1109 580 paint.setBrush(Qt::NoBrush);
Chris@1109 581 paint.drawLine(r.x(), r.y(), r.x(), r.y() + r.height() - 1);
Chris@1109 582 continue;
Chris@1109 583 }
Chris@1109 584
Chris@1266 585 QColor pen(255, 255, 255, 80);
Chris@1266 586 QColor brush(colour);
Chris@1109 587
Chris@1109 588 if (rw > 3 && r.height() > 3) {
Chris@1109 589 brush.setAlpha(160);
Chris@1109 590 }
Chris@1109 591
Chris@1266 592 paint.setPen(Qt::NoPen);
Chris@1266 593 paint.setBrush(brush);
Chris@1109 594
Chris@1266 595 if (illuminate) {
Chris@1266 596 if (r.contains(illuminatePos)) {
Chris@1266 597 paint.setPen(v->getForeground());
Chris@1266 598 }
Chris@1266 599 }
Chris@1109 600
Chris@1214 601 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1214 602 // SVDEBUG << "rect " << r.x() << "," << r.y() << " "
Chris@1109 603 // << r.width() << "x" << r.height() << endl;
Chris@1109 604 #endif
Chris@1109 605
Chris@1266 606 paint.drawRect(r);
Chris@1109 607
Chris@1266 608 if (showLabel) {
Chris@1109 609 double value = model->getValueAt(sx, sy);
Chris@1109 610 snprintf(labelbuf, buflen, "%06f", value);
Chris@1109 611 QString text(labelbuf);
Chris@1109 612 PaintAssistant::drawVisibleText
Chris@1109 613 (v,
Chris@1109 614 paint,
Chris@1109 615 rx0 + 2,
Chris@1109 616 ry0 - h / sh - 1 + 2 + paint.fontMetrics().ascent(),
Chris@1109 617 text,
Chris@1109 618 PaintAssistant::OutlinedText);
Chris@1266 619 }
Chris@1266 620 }
Chris@1109 621 }
Chris@1121 622
Chris@1121 623 return magRange;
Chris@1094 624 }
Chris@1094 625
Chris@1080 626 void
Chris@1213 627 Colour3DPlotRenderer::getPreferredPeakCache(const LayerGeometryProvider *v,
Chris@1213 628 int &peakCacheIndex,
Chris@1213 629 int &binsPerPeak) const
Chris@1213 630 {
Chris@1213 631 peakCacheIndex = -1;
Chris@1213 632 binsPerPeak = -1;
Chris@1213 633
Chris@1469 634 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1213 635 if (!model) return;
Chris@1217 636 if (m_params.binDisplay == BinDisplay::PeakFrequencies) return;
Chris@1217 637 if (m_params.colourScale.getScale() == ColourScaleType::Phase) return;
Chris@1213 638
Chris@1325 639 ZoomLevel zoomLevel = v->getZoomLevel();
Chris@1213 640 int binResolution = model->getResolution();
Chris@1213 641
Chris@1213 642 for (int ix = 0; in_range_for(m_sources.peakCaches, ix); ++ix) {
Chris@1473 643 auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
Chris@1473 644 (m_sources.peakCaches[ix]);
Chris@1473 645 if (!peakCache) continue;
Chris@1473 646 int bpp = peakCache->getColumnsPerPeak();
Chris@1325 647 ZoomLevel equivZoom(ZoomLevel::FramesPerPixel, binResolution * bpp);
Chris@1450 648 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 649 SVDEBUG << "render " << m_sources.source
Chris@1500 650 << ": getPreferredPeakCache: zoomLevel = " << zoomLevel
Chris@1450 651 << ", cache " << ix << " has bpp = " << bpp
Chris@1450 652 << " for equivZoom = " << equivZoom << endl;
Chris@1450 653 #endif
Chris@1213 654 if (zoomLevel >= equivZoom) {
Chris@1213 655 // this peak cache would work, though it might not be best
Chris@1213 656 if (bpp > binsPerPeak) {
Chris@1213 657 // ok, it's better than the best one we've found so far
Chris@1213 658 peakCacheIndex = ix;
Chris@1213 659 binsPerPeak = bpp;
Chris@1213 660 }
Chris@1213 661 }
Chris@1213 662 }
Chris@1213 663
Chris@1214 664 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 665 SVDEBUG << "render " << m_sources.source
Chris@1499 666 << ": getPreferredPeakCache: zoomLevel = " << zoomLevel
Chris@1213 667 << ", binResolution " << binResolution
Chris@1213 668 << ", peakCaches " << m_sources.peakCaches.size()
Chris@1450 669 << ": preferring peakCacheIndex " << peakCacheIndex
Chris@1450 670 << " for binsPerPeak " << binsPerPeak
Chris@1213 671 << endl;
Chris@1214 672 #endif
Chris@1213 673 }
Chris@1213 674
Chris@1213 675 void
Chris@1113 676 Colour3DPlotRenderer::renderToCachePixelResolution(const LayerGeometryProvider *v,
Chris@1094 677 int x0, int repaintWidth,
Chris@1094 678 bool rightToLeft,
Chris@1094 679 bool timeConstrained)
Chris@1079 680 {
Chris@1117 681 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution");
Chris@1143 682 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 683 SVDEBUG << "render " << m_sources.source
Chris@1500 684 << ": [PIXEL] renderToCachePixelResolution" << endl;
Chris@1143 685 #endif
Chris@1094 686
Chris@1094 687 // Draw to the draw buffer, and then copy from there. The draw
Chris@1094 688 // buffer is at the same resolution as the target in the cache, so
Chris@1094 689 // no extra scaling needed.
Chris@1079 690
Chris@1469 691 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1469 692 if (!model) return;
Chris@1079 693
Chris@1079 694 int h = v->getPaintHeight();
Chris@1079 695
Chris@1094 696 clearDrawBuffer(repaintWidth, h);
Chris@1079 697
Chris@1094 698 vector<int> binforx(repaintWidth);
Chris@1079 699 vector<double> binfory(h);
Chris@1079 700
Chris@1094 701 int binResolution = model->getResolution();
Chris@1079 702
Chris@1094 703 for (int x = 0; x < repaintWidth; ++x) {
Chris@1094 704 sv_frame_t f0 = v->getFrameForX(x0 + x);
Chris@1094 705 double s0 = double(f0 - model->getStartFrame()) / binResolution;
Chris@1094 706 binforx[x] = int(s0 + 0.0001);
Chris@1094 707 }
Chris@1080 708
Chris@1212 709 int peakCacheIndex = -1;
Chris@1212 710 int binsPerPeak = -1;
Chris@1212 711
Chris@1217 712 getPreferredPeakCache(v, peakCacheIndex, binsPerPeak);
Chris@1094 713
Chris@1080 714 for (int y = 0; y < h; ++y) {
Chris@1090 715 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
Chris@1080 716 }
Chris@1079 717
Chris@1097 718 int attainedWidth;
Chris@1097 719
Chris@1103 720 if (m_params.binDisplay == BinDisplay::PeakFrequencies) {
Chris@1097 721 attainedWidth = renderDrawBufferPeakFrequencies(v,
Chris@1097 722 repaintWidth,
Chris@1097 723 h,
Chris@1097 724 binforx,
Chris@1097 725 binfory,
Chris@1097 726 rightToLeft,
Chris@1097 727 timeConstrained);
Chris@1097 728
Chris@1097 729 } else {
Chris@1097 730 attainedWidth = renderDrawBuffer(repaintWidth,
Chris@1080 731 h,
Chris@1080 732 binforx,
Chris@1080 733 binfory,
Chris@1212 734 peakCacheIndex,
Chris@1080 735 rightToLeft,
Chris@1080 736 timeConstrained);
Chris@1097 737 }
Chris@1083 738
Chris@1094 739 if (attainedWidth == 0) return;
Chris@1084 740
Chris@1094 741 // draw buffer is pixel resolution, no scaling factors or padding involved
Chris@1084 742
Chris@1084 743 int paintedLeft = x0;
Chris@1084 744 if (rightToLeft) {
Chris@1084 745 paintedLeft += (repaintWidth - attainedWidth);
Chris@1084 746 }
Chris@1084 747
Chris@1094 748 m_cache.drawImage(paintedLeft, attainedWidth,
Chris@1094 749 m_drawBuffer,
Chris@1094 750 paintedLeft - x0, attainedWidth);
Chris@1121 751
Chris@1121 752 for (int i = 0; in_range_for(m_magRanges, i); ++i) {
Chris@1121 753 m_magCache.sampleColumn(i, m_magRanges.at(i));
Chris@1121 754 }
Chris@1094 755 }
Chris@1084 756
Chris@1167 757 QImage
Chris@1167 758 Colour3DPlotRenderer::scaleDrawBufferImage(QImage image,
Chris@1167 759 int targetWidth,
Chris@1167 760 int targetHeight) const
Chris@1167 761 {
Chris@1167 762 int sourceWidth = image.width();
Chris@1167 763 int sourceHeight = image.height();
Chris@1167 764
Chris@1167 765 // We can only do this if we're making the image larger --
Chris@1167 766 // otherwise peaks may be lost. So this should be called only when
Chris@1167 767 // rendering in DrawBufferBinResolution mode. Whenever the bin
Chris@1167 768 // size is smaller than the pixel size, in either x or y axis, we
Chris@1167 769 // should be using DrawBufferPixelResolution mode instead
Chris@1167 770
Chris@1167 771 if (targetWidth < sourceWidth || targetHeight < sourceHeight) {
Chris@1167 772 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Can only use this function when making the image larger; should be rendering DrawBufferPixelResolution instead");
Chris@1167 773 }
Chris@1167 774
Chris@1167 775 if (sourceWidth <= 0 || sourceHeight <= 0) {
Chris@1167 776 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Source image is empty");
Chris@1167 777 }
Chris@1167 778
Chris@1167 779 if (targetWidth <= 0 || targetHeight <= 0) {
Chris@1167 780 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Target image is empty");
Chris@1167 781 }
Chris@1167 782
Chris@1167 783 // This function exists because of some unpredictable behaviour
Chris@1167 784 // from Qt when scaling images with FastTransformation mode. We
Chris@1167 785 // continue to use Qt's scaler for SmoothTransformation but let's
Chris@1167 786 // bring the non-interpolated version "in-house" so we know what
Chris@1167 787 // it's really doing.
Chris@1167 788
Chris@1167 789 if (m_params.interpolate) {
Chris@1167 790 return image.scaled(targetWidth, targetHeight,
Chris@1167 791 Qt::IgnoreAspectRatio,
Chris@1167 792 Qt::SmoothTransformation);
Chris@1167 793 }
Chris@1167 794
Chris@1167 795 // Same format as the target cache
Chris@1167 796 QImage target(targetWidth, targetHeight, QImage::Format_ARGB32_Premultiplied);
Chris@1167 797
Chris@1167 798 for (int y = 0; y < targetHeight; ++y) {
Chris@1167 799
Chris@1167 800 QRgb *targetLine = reinterpret_cast<QRgb *>(target.scanLine(y));
Chris@1167 801
Chris@1167 802 int sy = int((uint64_t(y) * sourceHeight) / targetHeight);
Chris@1167 803 if (sy == sourceHeight) --sy;
Chris@1167 804
Chris@1167 805 for (int x = 0; x < targetWidth; ++x) {
Chris@1167 806
Chris@1167 807 int sx = int((uint64_t(x) * sourceWidth) / targetWidth);
Chris@1167 808 if (sx == sourceWidth) --sx;
Chris@1167 809
Chris@1167 810 targetLine[x] = image.pixel(sx, sy);
Chris@1167 811 }
Chris@1167 812 }
Chris@1167 813
Chris@1167 814 return target;
Chris@1167 815 }
Chris@1167 816
Chris@1094 817 void
Chris@1113 818 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v,
Chris@1094 819 int x0, int repaintWidth)
Chris@1094 820 {
Chris@1117 821 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution");
Chris@1143 822 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1499 823 SVDEBUG << "render " << m_sources.source
Chris@1500 824 << ": [BIN] renderToCacheBinResolution" << endl;
Chris@1143 825 #endif
Chris@1094 826
Chris@1094 827 // Draw to the draw buffer, and then scale-copy from there. Draw
Chris@1094 828 // buffer is at bin resolution, i.e. buffer x == source column
Chris@1094 829 // number. We use toolkit smooth scaling for interpolation.
Chris@1084 830
Chris@1469 831 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
Chris@1469 832 if (!model) return;
Chris@1094 833
Chris@1094 834 // The draw buffer will contain a fragment at bin resolution. We
Chris@1094 835 // need to ensure that it starts and ends at points where a
Chris@1094 836 // time-bin boundary occurs at an exact pixel boundary, and with a
Chris@1094 837 // certain amount of overlap across existing pixels so that we can
Chris@1094 838 // scale and draw from it without smoothing errors at the edges.
Chris@1094 839
Chris@1094 840 // If (getFrameForX(x) / increment) * increment ==
Chris@1094 841 // getFrameForX(x), then x is a time-bin boundary. We want two
Chris@1094 842 // such boundaries at either side of the draw buffer -- one which
Chris@1094 843 // we draw up to, and one which we subsequently crop at.
Chris@1094 844
Chris@1094 845 sv_frame_t leftBoundaryFrame = -1, leftCropFrame = -1;
Chris@1094 846 sv_frame_t rightBoundaryFrame = -1, rightCropFrame = -1;
Chris@1094 847
Chris@1094 848 int drawBufferWidth;
Chris@1094 849 int binResolution = model->getResolution();
Chris@1094 850
Chris@1330 851 // These loops should eventually terminate provided that
Chris@1330 852 // getFrameForX always returns a multiple of the zoom level,
Chris@1330 853 // i.e. there is some x for which getFrameForX(x) == 0 and
Chris@1330 854 // subsequent return values are equally spaced
Chris@1329 855
Chris@1330 856 for (int x = x0; ; --x) {
Chris@1094 857 sv_frame_t f = v->getFrameForX(x);
Chris@1330 858 if ((f / binResolution) * binResolution == f) {
Chris@1094 859 if (leftCropFrame == -1) leftCropFrame = f;
Chris@1094 860 else if (x < x0 - 2) {
Chris@1094 861 leftBoundaryFrame = f;
Chris@1094 862 break;
Chris@1094 863 }
Chris@1094 864 }
Chris@1094 865 }
Chris@1329 866
Chris@1330 867 for (int x = x0 + repaintWidth; ; ++x) {
Chris@1094 868 sv_frame_t f = v->getFrameForX(x);
Chris@1330 869 if ((f / binResolution) * binResolution == f) {
Chris@1494 870 if (v->getXForFrame(f) < x0 + repaintWidth) {
Chris@1494 871 continue;
Chris@1494 872 }
Chris@1094 873 if (rightCropFrame == -1) rightCropFrame = f;
Chris@1094 874 else if (x > x0 + repaintWidth + 2) {
Chris@1094 875 rightBoundaryFrame = f;
Chris@1094 876 break;
Chris@1094 877 }
Chris@1094 878 }
Chris@1094 879 }
Chris@1329 880
Chris@1094 881 drawBufferWidth = int
Chris@1094 882 ((rightBoundaryFrame - leftBoundaryFrame) / binResolution);
Chris@1094 883
Chris@1094 884 int h = v->getPaintHeight();
Chris@1094 885
Chris@1095 886 // For our purposes here, the draw buffer needs to be exactly our
Chris@1095 887 // target size (so we recreate always rather than just clear it)
Chris@1095 888
Chris@1095 889 recreateDrawBuffer(drawBufferWidth, h);
Chris@1094 890
Chris@1094 891 vector<int> binforx(drawBufferWidth);
Chris@1094 892 vector<double> binfory(h);
Chris@1094 893
Chris@1094 894 for (int x = 0; x < drawBufferWidth; ++x) {
Chris@1094 895 binforx[x] = int(leftBoundaryFrame / binResolution) + x;
Chris@1094 896 }
Chris@1094 897
Chris@1214 898 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 899 SVDEBUG << "render " << m_sources.source
Chris@1500 900 << ": binResolution " << binResolution << endl;
Chris@1214 901 #endif
Chris@1094 902
Chris@1094 903 for (int y = 0; y < h; ++y) {
Chris@1094 904 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1);
Chris@1094 905 }
Chris@1094 906
Chris@1094 907 int attainedWidth = renderDrawBuffer(drawBufferWidth,
Chris@1094 908 h,
Chris@1094 909 binforx,
Chris@1094 910 binfory,
Chris@1212 911 -1,
Chris@1094 912 false,
Chris@1094 913 false);
Chris@1094 914
Chris@1094 915 if (attainedWidth == 0) return;
Chris@1094 916
Chris@1094 917 int scaledLeft = v->getXForFrame(leftBoundaryFrame);
Chris@1094 918 int scaledRight = v->getXForFrame(rightBoundaryFrame);
Chris@1095 919
Chris@1143 920 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 921 SVDEBUG << "render " << m_sources.source
Chris@1500 922 << ": scaling draw buffer from width " << m_drawBuffer.width()
Chris@1494 923 << " to " << (scaledRight - scaledLeft)
Chris@1494 924 << " (nb drawBufferWidth = "
Chris@1494 925 << drawBufferWidth << ", attainedWidth = "
Chris@1494 926 << attainedWidth << ")" << endl;
Chris@1143 927 #endif
Chris@1167 928
Chris@1167 929 QImage scaled = scaleDrawBufferImage
Chris@1167 930 (m_drawBuffer, scaledRight - scaledLeft, h);
Chris@1084 931
Chris@1094 932 int scaledLeftCrop = v->getXForFrame(leftCropFrame);
Chris@1094 933 int scaledRightCrop = v->getXForFrame(rightCropFrame);
Chris@1094 934
Chris@1094 935 int targetLeft = scaledLeftCrop;
Chris@1094 936 if (targetLeft < 0) {
Chris@1094 937 targetLeft = 0;
Chris@1094 938 }
Chris@1094 939
Chris@1094 940 int targetWidth = scaledRightCrop - targetLeft;
Chris@1094 941 if (targetLeft + targetWidth > m_cache.getSize().width()) {
Chris@1094 942 targetWidth = m_cache.getSize().width() - targetLeft;
Chris@1094 943 }
Chris@1094 944
Chris@1094 945 int sourceLeft = targetLeft - scaledLeft;
Chris@1094 946 if (sourceLeft < 0) {
Chris@1094 947 sourceLeft = 0;
Chris@1094 948 }
Chris@1494 949
Chris@1494 950 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 951 SVDEBUG << "render " << m_sources.source
Chris@1500 952 << ": leftBoundaryFrame = " << leftBoundaryFrame
Chris@1494 953 << ", leftCropFrame = " << leftCropFrame
Chris@1494 954 << ", scaledLeft = " << scaledLeft
Chris@1494 955 << ", scaledLeftCrop = " << scaledLeftCrop
Chris@1494 956 << endl;
Chris@1500 957 SVDEBUG << "render " << m_sources.source
Chris@1500 958 << ": rightBoundaryFrame = " << rightBoundaryFrame
Chris@1494 959 << ", rightCropFrame = " << rightCropFrame
Chris@1494 960 << ", scaledRight = " << scaledRight
Chris@1494 961 << ", scaledRightCrop = " << scaledRightCrop
Chris@1494 962 << endl;
Chris@1494 963 #endif
Chris@1094 964
Chris@1143 965 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 966 SVDEBUG << "render " << m_sources.source
Chris@1500 967 << ": x0 = " << x0
Chris@1494 968 << ", repaintWidth = " << repaintWidth
Chris@1494 969 << ", targetLeft = " << targetLeft
Chris@1214 970 << ", targetWidth = " << targetWidth << endl;
Chris@1143 971 #endif
Chris@1094 972
Chris@1094 973 if (targetWidth > 0) {
Chris@1136 974 // we are copying from an image that has already been scaled,
Chris@1136 975 // hence using the same width in both geometries
Chris@1094 976 m_cache.drawImage(targetLeft, targetWidth,
Chris@1094 977 scaled,
Chris@1136 978 sourceLeft, targetWidth);
Chris@1084 979 }
Chris@1121 980
Chris@1121 981 for (int i = 0; i < targetWidth; ++i) {
Chris@1136 982 // but the mag range vector has not been scaled
Chris@1136 983 int sourceIx = int((double(i + sourceLeft) / scaled.width())
Chris@1136 984 * int(m_magRanges.size()));
Chris@1121 985 if (in_range_for(m_magRanges, sourceIx)) {
Chris@1121 986 m_magCache.sampleColumn(i, m_magRanges.at(sourceIx));
Chris@1121 987 }
Chris@1121 988 }
Chris@1079 989 }
Chris@1083 990
Chris@1083 991 int
Chris@1083 992 Colour3DPlotRenderer::renderDrawBuffer(int w, int h,
Chris@1083 993 const vector<int> &binforx,
Chris@1083 994 const vector<double> &binfory,
Chris@1212 995 int peakCacheIndex,
Chris@1083 996 bool rightToLeft,
Chris@1083 997 bool timeConstrained)
Chris@1083 998 {
Chris@1083 999 // Callers must have checked that the appropriate subset of
Chris@1083 1000 // Sources data members are set for the supplied flags (e.g. that
Chris@1212 1001 // peakCache corresponding to peakCacheIndex exists)
Chris@1083 1002
Chris@1083 1003 RenderTimer timer(timeConstrained ?
Chris@1083 1004 RenderTimer::FastRender :
Chris@1083 1005 RenderTimer::NoTimeout);
Chris@1083 1006
Chris@1164 1007 Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer");
Chris@1164 1008
Chris@1083 1009 int divisor = 1;
Chris@1473 1010
Chris@1473 1011 std::shared_ptr<DenseThreeDimensionalModel> sourceModel;
Chris@1473 1012
Chris@1473 1013 if (peakCacheIndex >= 0) {
Chris@1473 1014 auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
Chris@1473 1015 (m_sources.peakCaches[peakCacheIndex]);
Chris@1473 1016 if (peakCache) {
Chris@1473 1017 divisor = peakCache->getColumnsPerPeak();
Chris@1473 1018 sourceModel = peakCache;
Chris@1473 1019 }
Chris@1473 1020 }
Chris@1473 1021
Chris@1473 1022 if (!sourceModel) {
Chris@1473 1023 sourceModel = ModelById::getAs<DenseThreeDimensionalModel>
Chris@1473 1024 (m_sources.source);
Chris@1473 1025 }
Chris@1469 1026
Chris@1473 1027 if (!sourceModel) return 0;
Chris@1083 1028
Chris@1214 1029 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1030 SVDEBUG << "render " << m_sources.source
Chris@1500 1031 << ": renderDrawBuffer: w = " << w << ", h = " << h
Chris@1212 1032 << ", peakCacheIndex = " << peakCacheIndex << " (divisor = "
cannam@1171 1033 << divisor << "), rightToLeft = " << rightToLeft
cannam@1171 1034 << ", timeConstrained = " << timeConstrained << endl;
Chris@1500 1035 SVDEBUG << "render " << m_sources.source
Chris@1500 1036 << ": renderDrawBuffer: normalization = " << int(m_params.normalization)
cannam@1171 1037 << ", binDisplay = " << int(m_params.binDisplay)
cannam@1171 1038 << ", binScale = " << int(m_params.binScale)
cannam@1171 1039 << ", alwaysOpaque = " << m_params.alwaysOpaque
cannam@1171 1040 << ", interpolate = " << m_params.interpolate << endl;
Chris@1214 1041 #endif
cannam@1171 1042
Chris@1135 1043 int sh = sourceModel->getHeight();
Chris@1135 1044
Chris@1135 1045 int minbin = int(binfory[0] + 0.0001);
Chris@1135 1046 if (minbin >= sh) minbin = sh - 1;
Chris@1135 1047 if (minbin < 0) minbin = 0;
Chris@1135 1048
Chris@1170 1049 int nbins = int(binfory[h-1] + 0.0001) - minbin + 1;
Chris@1135 1050 if (minbin + nbins > sh) nbins = sh - minbin;
Chris@1162 1051
Chris@1162 1052 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1053 SVDEBUG << "render " << m_sources.source
Chris@1500 1054 << ": minbin = " << minbin << ", nbins = " << nbins
Chris@1500 1055 << ", last binfory = " << binfory[h-1]
Chris@1500 1056 << " (rounds to " << int(binfory[h-1])
Chris@1500 1057 << ") (model height " << sh << ")" << endl;
Chris@1162 1058 #endif
Chris@1135 1059
Chris@1083 1060 int psx = -1;
Chris@1083 1061
Chris@1083 1062 int start = 0;
Chris@1083 1063 int finish = w;
Chris@1083 1064 int step = 1;
Chris@1083 1065
Chris@1083 1066 if (rightToLeft) {
Chris@1083 1067 start = w-1;
Chris@1083 1068 finish = -1;
Chris@1083 1069 step = -1;
Chris@1083 1070 }
Chris@1083 1071
Chris@1221 1072 int xPixelCount = 0;
Chris@1083 1073
Chris@1083 1074 vector<float> preparedColumn;
Chris@1094 1075
Chris@1094 1076 int modelWidth = sourceModel->getWidth();
Chris@1121 1077
Chris@1143 1078 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1079 SVDEBUG << "render " << m_sources.source
Chris@1500 1080 << ": modelWidth " << modelWidth << ", divisor " << divisor << endl;
Chris@1500 1081 SVDEBUG << "render " << m_sources.source
Chris@1500 1082 << ": start = " << start << ", finish = " << finish << ", step = " << step << endl;
Chris@1143 1083 #endif
Chris@1143 1084
Chris@1083 1085 for (int x = start; x != finish; x += step) {
Chris@1083 1086
Chris@1083 1087 // x is the on-canvas pixel coord; sx (later) will be the
Chris@1083 1088 // source column index
Chris@1083 1089
Chris@1221 1090 ++xPixelCount;
Chris@1083 1091
Chris@1083 1092 if (binforx[x] < 0) continue;
Chris@1083 1093
Chris@1083 1094 int sx0 = binforx[x] / divisor;
Chris@1083 1095 int sx1 = sx0;
Chris@1083 1096 if (x+1 < w) sx1 = binforx[x+1] / divisor;
Chris@1083 1097 if (sx0 < 0) sx0 = sx1 - 1;
Chris@1083 1098 if (sx0 < 0) continue;
Chris@1083 1099 if (sx1 <= sx0) sx1 = sx0 + 1;
Chris@1083 1100
Chris@1161 1101 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1214 1102 // SVDEBUG << "x = " << x << ", binforx[x] = " << binforx[x] << ", sx range " << sx0 << " -> " << sx1 << endl;
Chris@1161 1103 #endif
Chris@1161 1104
Chris@1083 1105 vector<float> pixelPeakColumn;
Chris@1121 1106 MagnitudeRange magRange;
Chris@1083 1107
Chris@1083 1108 for (int sx = sx0; sx < sx1; ++sx) {
Chris@1083 1109
Chris@1094 1110 if (sx < 0 || sx >= modelWidth) {
Chris@1083 1111 continue;
Chris@1083 1112 }
Chris@1083 1113
Chris@1083 1114 if (sx != psx) {
Chris@1138 1115
Chris@1138 1116 // order:
Chris@1138 1117 // get column -> scale -> normalise -> record extents ->
Chris@1138 1118 // peak pick -> distribute/interpolate -> apply display gain
Chris@1083 1119
Chris@1138 1120 // this does the first three:
Chris@1161 1121 ColumnOp::Column column = getColumn(sx, minbin, nbins,
Chris@1212 1122 peakCacheIndex);
Chris@1083 1123
Chris@1131 1124 magRange.sample(column);
Chris@1162 1125
Chris@1103 1126 if (m_params.binDisplay == BinDisplay::PeakBins) {
Chris@1083 1127 column = ColumnOp::peakPick(column);
Chris@1083 1128 }
Chris@1083 1129
Chris@1083 1130 preparedColumn =
Chris@1124 1131 ColumnOp::distribute(column,
Chris@1083 1132 h,
Chris@1083 1133 binfory,
Chris@1083 1134 minbin,
Chris@1083 1135 m_params.interpolate);
Chris@1124 1136
Chris@1124 1137 // Display gain belongs to the colour scale and is
Chris@1124 1138 // applied by the colour scale object when mapping it
Chris@1083 1139
Chris@1083 1140 psx = sx;
Chris@1083 1141 }
Chris@1083 1142
Chris@1083 1143 if (sx == sx0) {
Chris@1083 1144 pixelPeakColumn = preparedColumn;
Chris@1083 1145 } else {
Chris@1083 1146 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
Chris@1083 1147 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
Chris@1083 1148 preparedColumn[i]);
Chris@1083 1149 }
Chris@1083 1150 }
Chris@1083 1151 }
Chris@1083 1152
Chris@1083 1153 if (!pixelPeakColumn.empty()) {
Chris@1121 1154
Chris@1083 1155 for (int y = 0; y < h; ++y) {
Chris@1116 1156 int py;
Chris@1116 1157 if (m_params.invertVertical) {
Chris@1116 1158 py = y;
Chris@1116 1159 } else {
Chris@1116 1160 py = h - y - 1;
Chris@1116 1161 }
Chris@1083 1162 m_drawBuffer.setPixel
Chris@1083 1163 (x,
Chris@1116 1164 py,
Chris@1083 1165 m_params.colourScale.getPixel(pixelPeakColumn[y]));
Chris@1083 1166 }
Chris@1121 1167
Chris@1121 1168 m_magRanges.push_back(magRange);
Chris@1083 1169 }
Chris@1083 1170
Chris@1221 1171 double fractionComplete = double(xPixelCount) / double(w);
Chris@1083 1172 if (timer.outOfTime(fractionComplete)) {
Chris@1214 1173 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1174 SVDEBUG << "render " << m_sources.source
Chris@1500 1175 << ": out of time with xPixelCount = " << xPixelCount << endl;
Chris@1214 1176 #endif
Chris@1221 1177 updateTimings(timer, xPixelCount);
Chris@1221 1178 return xPixelCount;
Chris@1083 1179 }
Chris@1083 1180 }
Chris@1083 1181
Chris@1221 1182 updateTimings(timer, xPixelCount);
Chris@1451 1183
Chris@1451 1184 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1185 SVDEBUG << "render " << m_sources.source
Chris@1500 1186 << ": completed with xPixelCount = " << xPixelCount << endl;
Chris@1451 1187 #endif
Chris@1221 1188 return xPixelCount;
Chris@1083 1189 }
Chris@1083 1190
Chris@1097 1191 int
Chris@1113 1192 Colour3DPlotRenderer::renderDrawBufferPeakFrequencies(const LayerGeometryProvider *v,
Chris@1097 1193 int w, int h,
Chris@1097 1194 const vector<int> &binforx,
Chris@1097 1195 const vector<double> &binfory,
Chris@1097 1196 bool rightToLeft,
Chris@1097 1197 bool timeConstrained)
Chris@1097 1198 {
Chris@1500 1199 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1200 SVDEBUG << "render " << m_sources.source
Chris@1500 1201 << ": [PEAK] renderDrawBufferPeakFrequencies" << endl;
Chris@1500 1202 #endif
Chris@1500 1203
Chris@1097 1204 // Callers must have checked that the appropriate subset of
Chris@1097 1205 // Sources data members are set for the supplied flags (e.g. that
Chris@1097 1206 // fft model exists)
Chris@1097 1207
Chris@1097 1208 RenderTimer timer(timeConstrained ?
Chris@1221 1209 RenderTimer::SlowRender :
Chris@1097 1210 RenderTimer::NoTimeout);
Chris@1097 1211
Chris@1469 1212 auto fft = ModelById::getAs<FFTModel>(m_sources.fft);
Chris@1469 1213 if (!fft) return 0;
Chris@1135 1214
Chris@1135 1215 int sh = fft->getHeight();
Chris@1135 1216
Chris@1097 1217 int minbin = int(binfory[0] + 0.0001);
Chris@1135 1218 if (minbin >= sh) minbin = sh - 1;
Chris@1097 1219 if (minbin < 0) minbin = 0;
Chris@1097 1220
Chris@1135 1221 int nbins = int(binfory[h-1]) - minbin + 1;
Chris@1135 1222 if (minbin + nbins > sh) nbins = sh - minbin;
Chris@1097 1223
Chris@1097 1224 FFTModel::PeakSet peakfreqs;
Chris@1097 1225
Chris@1097 1226 int psx = -1;
Chris@1097 1227
Chris@1097 1228 int start = 0;
Chris@1097 1229 int finish = w;
Chris@1097 1230 int step = 1;
Chris@1097 1231
Chris@1097 1232 if (rightToLeft) {
Chris@1097 1233 start = w-1;
Chris@1097 1234 finish = -1;
Chris@1097 1235 step = -1;
Chris@1097 1236 }
Chris@1097 1237
Chris@1221 1238 int xPixelCount = 0;
Chris@1097 1239
Chris@1097 1240 vector<float> preparedColumn;
Chris@1097 1241
Chris@1097 1242 int modelWidth = fft->getWidth();
Chris@1143 1243 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1244 SVDEBUG << "render " << m_sources.source
Chris@1500 1245 << ": modelWidth " << modelWidth << endl;
Chris@1143 1246 #endif
Chris@1143 1247
Chris@1135 1248 double minFreq =
Chris@1135 1249 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize();
Chris@1135 1250 double maxFreq =
Chris@1135 1251 (double(minbin + nbins - 1) * fft->getSampleRate()) / fft->getFFTSize();
Chris@1097 1252
Chris@1103 1253 bool logarithmic = (m_params.binScale == BinScale::Log);
Chris@1217 1254
Chris@1218 1255 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1256 SVDEBUG << "render " << m_sources.source
Chris@1500 1257 << ": start = " << start << ", finish = " << finish
Chris@1218 1258 << ", step = " << step << endl;
Chris@1218 1259 #endif
Chris@1218 1260
Chris@1097 1261 for (int x = start; x != finish; x += step) {
Chris@1097 1262
Chris@1097 1263 // x is the on-canvas pixel coord; sx (later) will be the
Chris@1097 1264 // source column index
Chris@1097 1265
Chris@1221 1266 ++xPixelCount;
Chris@1097 1267
Chris@1097 1268 if (binforx[x] < 0) continue;
Chris@1097 1269
Chris@1097 1270 int sx0 = binforx[x];
Chris@1097 1271 int sx1 = sx0;
Chris@1097 1272 if (x+1 < w) sx1 = binforx[x+1];
Chris@1097 1273 if (sx0 < 0) sx0 = sx1 - 1;
Chris@1097 1274 if (sx0 < 0) continue;
Chris@1097 1275 if (sx1 <= sx0) sx1 = sx0 + 1;
Chris@1097 1276
Chris@1097 1277 vector<float> pixelPeakColumn;
Chris@1121 1278 MagnitudeRange magRange;
Chris@1097 1279
Chris@1097 1280 for (int sx = sx0; sx < sx1; ++sx) {
Chris@1097 1281
Chris@1097 1282 if (sx < 0 || sx >= modelWidth) {
Chris@1097 1283 continue;
Chris@1097 1284 }
Chris@1097 1285
Chris@1097 1286 if (sx != psx) {
Chris@1219 1287 preparedColumn = getColumn(sx, minbin, nbins, -1);
Chris@1131 1288 magRange.sample(preparedColumn);
Chris@1097 1289 psx = sx;
Chris@1097 1290 }
Chris@1097 1291
Chris@1097 1292 if (sx == sx0) {
Chris@1097 1293 pixelPeakColumn = preparedColumn;
Chris@1097 1294 peakfreqs = fft->getPeakFrequencies(FFTModel::AllPeaks, sx,
Chris@1135 1295 minbin, minbin + nbins - 1);
Chris@1097 1296 } else {
Chris@1097 1297 for (int i = 0; in_range_for(pixelPeakColumn, i); ++i) {
Chris@1097 1298 pixelPeakColumn[i] = std::max(pixelPeakColumn[i],
Chris@1097 1299 preparedColumn[i]);
Chris@1097 1300 }
Chris@1097 1301 }
Chris@1097 1302 }
Chris@1097 1303
Chris@1097 1304 if (!pixelPeakColumn.empty()) {
Chris@1164 1305
Chris@1218 1306 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1221 1307 // SVDEBUG << "found " << peakfreqs.size() << " peak freqs at column "
Chris@1221 1308 // << sx0 << endl;
Chris@1218 1309 #endif
Chris@1218 1310
Chris@1097 1311 for (FFTModel::PeakSet::const_iterator pi = peakfreqs.begin();
Chris@1097 1312 pi != peakfreqs.end(); ++pi) {
Chris@1097 1313
Chris@1097 1314 int bin = pi->first;
Chris@1097 1315 double freq = pi->second;
Chris@1097 1316
Chris@1097 1317 if (bin < minbin) continue;
Chris@1135 1318 if (bin >= minbin + nbins) break;
Chris@1097 1319
Chris@1097 1320 double value = pixelPeakColumn[bin - minbin];
Chris@1097 1321
Chris@1097 1322 double y = v->getYForFrequency
Chris@1097 1323 (freq, minFreq, maxFreq, logarithmic);
Chris@1097 1324
Chris@1097 1325 int iy = int(y + 0.5);
Chris@1097 1326 if (iy < 0 || iy >= h) continue;
Chris@1097 1327
Chris@1219 1328 auto pixel = m_params.colourScale.getPixel(value);
Chris@1219 1329
Chris@1219 1330 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1219 1331 // SVDEBUG << "frequency " << freq << " for bin " << bin
Chris@1219 1332 // << " -> y = " << y << ", iy = " << iy << ", value = "
Chris@1219 1333 // << value << ", pixel " << pixel << "\n";
Chris@1219 1334 #endif
Chris@1219 1335
Chris@1219 1336 m_drawBuffer.setPixel(x, iy, pixel);
Chris@1097 1337 }
Chris@1121 1338
Chris@1121 1339 m_magRanges.push_back(magRange);
Chris@1218 1340
Chris@1218 1341 } else {
Chris@1218 1342 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1343 SVDEBUG << "render " << m_sources.source
Chris@1500 1344 << ": pixel peak column for range " << sx0 << " to " << sx1
Chris@1218 1345 << " is empty" << endl;
Chris@1218 1346 #endif
Chris@1097 1347 }
Chris@1097 1348
Chris@1221 1349 double fractionComplete = double(xPixelCount) / double(w);
Chris@1097 1350 if (timer.outOfTime(fractionComplete)) {
Chris@1218 1351 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1352 SVDEBUG << "render " << m_sources.source
Chris@1500 1353 << ": out of time" << endl;
Chris@1218 1354 #endif
Chris@1221 1355 updateTimings(timer, xPixelCount);
Chris@1221 1356 return xPixelCount;
Chris@1097 1357 }
Chris@1097 1358 }
Chris@1097 1359
Chris@1221 1360 updateTimings(timer, xPixelCount);
Chris@1221 1361 return xPixelCount;
Chris@1221 1362 }
Chris@1221 1363
Chris@1221 1364 void
Chris@1221 1365 Colour3DPlotRenderer::updateTimings(const RenderTimer &timer, int xPixelCount)
Chris@1221 1366 {
Chris@1237 1367 double secondsPerXPixel = timer.secondsPerItem(xPixelCount);
Chris@1221 1368
Chris@1237 1369 // valid if we have enough data points, or if the overall time is
Chris@1237 1370 // massively slow anyway (as we definitely need to warn about that)
Chris@1237 1371 bool valid = (xPixelCount > 20 || secondsPerXPixel > 0.01);
Chris@1237 1372
Chris@1237 1373 if (valid) {
Chris@1237 1374 m_secondsPerXPixel = secondsPerXPixel;
Chris@1237 1375 m_secondsPerXPixelValid = true;
Chris@1237 1376
Chris@1221 1377 #ifdef DEBUG_COLOUR_PLOT_REPAINT
Chris@1500 1378 SVDEBUG << "render " << m_sources.source
Chris@1500 1379 << ": across " << xPixelCount
Chris@1500 1380 << " x-pixels, seconds per x-pixel = "
Chris@1450 1381 << m_secondsPerXPixel << " (total = "
Chris@1499 1382 << (xPixelCount * m_secondsPerXPixel) << ")" << endl;
Chris@1221 1383 #endif
Chris@1237 1384 }
Chris@1097 1385 }
Chris@1097 1386
Chris@1079 1387 void
Chris@1095 1388 Colour3DPlotRenderer::recreateDrawBuffer(int w, int h)
Chris@1079 1389 {
Chris@1095 1390 m_drawBuffer = QImage(w, h, QImage::Format_Indexed8);
Chris@1079 1391
Chris@1095 1392 for (int pixel = 0; pixel < 256; ++pixel) {
Chris@1095 1393 m_drawBuffer.setColor
Chris@1095 1394 ((unsigned char)pixel,
Chris@1112 1395 m_params.colourScale.getColourForPixel
Chris@1112 1396 (pixel, m_params.colourRotation).rgb());
Chris@1079 1397 }
Chris@1079 1398
Chris@1079 1399 m_drawBuffer.fill(0);
Chris@1121 1400 m_magRanges.clear();
Chris@1079 1401 }
Chris@1079 1402
Chris@1095 1403 void
Chris@1095 1404 Colour3DPlotRenderer::clearDrawBuffer(int w, int h)
Chris@1095 1405 {
Chris@1095 1406 if (m_drawBuffer.width() < w || m_drawBuffer.height() != h) {
Chris@1095 1407 recreateDrawBuffer(w, h);
Chris@1095 1408 } else {
Chris@1095 1409 m_drawBuffer.fill(0);
Chris@1121 1410 m_magRanges.clear();
Chris@1095 1411 }
Chris@1095 1412 }
Chris@1079 1413
Chris@1139 1414 QRect
Chris@1139 1415 Colour3DPlotRenderer::findSimilarRegionExtents(QPoint p) const
Chris@1139 1416 {
Chris@1139 1417 QImage image = m_cache.getImage();
Chris@1139 1418 ImageRegionFinder finder;
Chris@1139 1419 QRect rect = finder.findRegionExtents(&image, p);
Chris@1139 1420 return rect;
Chris@1139 1421 }