Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1486:ac0a8addabcf
Merge from branch by-id
author | Chris Cannam |
---|---|
date | Wed, 17 Jul 2019 14:25:16 +0100 |
parents | 886c1cd48f9d |
children | 78d9282519b0 |
comparison
equal
deleted
inserted
replaced
1468:de41a11cabc2 | 1486:ac0a8addabcf |
---|---|
332 } | 332 } |
333 | 333 |
334 Colour3DPlotRenderer::RenderType | 334 Colour3DPlotRenderer::RenderType |
335 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const | 335 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const |
336 { | 336 { |
337 const DenseThreeDimensionalModel *model = m_sources.source; | 337 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
338 if (!model || !v || !(v->getViewManager())) { | 338 if (!model || !v || !(v->getViewManager())) { |
339 return DrawBufferPixelResolution; // or anything | 339 return DrawBufferPixelResolution; // or anything |
340 } | 340 } |
341 | 341 |
342 int binResolution = model->getResolution(); | 342 int binResolution = model->getResolution(); |
396 } else { | 396 } else { |
397 column = getColumnRaw(sx, minbin, nbins, peakCacheIndex); | 397 column = getColumnRaw(sx, minbin, nbins, peakCacheIndex); |
398 } | 398 } |
399 | 399 |
400 if (m_params.colourScale.getScale() == ColourScaleType::Phase && | 400 if (m_params.colourScale.getScale() == ColourScaleType::Phase && |
401 m_sources.fft) { | 401 !m_sources.fft.isNone()) { |
402 return column; | 402 return column; |
403 } else { | 403 } else { |
404 column = ColumnOp::applyGain(column, m_params.scaleFactor); | 404 column = ColumnOp::applyGain(column, m_params.scaleFactor); |
405 column = ColumnOp::normalize(column, m_params.normalization); | 405 column = ColumnOp::normalize(column, m_params.normalization); |
406 return column; | 406 return column; |
412 int peakCacheIndex) const | 412 int peakCacheIndex) const |
413 { | 413 { |
414 Profiler profiler("Colour3DPlotRenderer::getColumn"); | 414 Profiler profiler("Colour3DPlotRenderer::getColumn"); |
415 | 415 |
416 ColumnOp::Column column; | 416 ColumnOp::Column column; |
417 | 417 ColumnOp::Column fullColumn; |
418 if (m_params.colourScale.getScale() == ColourScaleType::Phase && | 418 |
419 m_sources.fft) { | 419 if (m_params.colourScale.getScale() == ColourScaleType::Phase) { |
420 | 420 auto fftModel = ModelById::getAs<FFTModel>(m_sources.fft); |
421 ColumnOp::Column fullColumn = m_sources.fft->getPhases(sx); | 421 if (fftModel) { |
422 | 422 fullColumn = fftModel->getPhases(sx); |
423 column = vector<float>(fullColumn.data() + minbin, | 423 } |
424 fullColumn.data() + minbin + nbins); | 424 } |
425 | 425 |
426 } else { | 426 if (fullColumn.empty()) { |
427 | 427 |
428 ColumnOp::Column fullColumn = | 428 if (peakCacheIndex >= 0) { |
429 (peakCacheIndex >= 0 ? | 429 auto peakCache = ModelById::getAs<Dense3DModelPeakCache> |
430 m_sources.peakCaches[peakCacheIndex] : | 430 (m_sources.peakCaches[peakCacheIndex]); |
431 m_sources.source) | 431 if (!peakCache) { |
432 ->getColumn(sx); | 432 return vector<float>(nbins, 0.f); |
433 | 433 } |
434 column = vector<float>(fullColumn.data() + minbin, | 434 fullColumn = peakCache->getColumn(sx); |
435 fullColumn.data() + minbin + nbins); | 435 } else { |
436 } | 436 auto model = ModelById::getAs<DenseThreeDimensionalModel> |
437 | 437 (m_sources.source); |
438 if (!model) { | |
439 return vector<float>(nbins, 0.f); | |
440 } | |
441 fullColumn = model->getColumn(sx); | |
442 } | |
443 } | |
444 | |
445 column = vector<float>(fullColumn.data() + minbin, | |
446 fullColumn.data() + minbin + nbins); | |
438 return column; | 447 return column; |
439 } | 448 } |
440 | 449 |
441 MagnitudeRange | 450 MagnitudeRange |
442 Colour3DPlotRenderer::renderDirectTranslucent(const LayerGeometryProvider *v, | 451 Colour3DPlotRenderer::renderDirectTranslucent(const LayerGeometryProvider *v, |
449 | 458 |
450 QPoint illuminatePos; | 459 QPoint illuminatePos; |
451 bool illuminate = v->shouldIlluminateLocalFeatures | 460 bool illuminate = v->shouldIlluminateLocalFeatures |
452 (m_sources.verticalBinLayer, illuminatePos); | 461 (m_sources.verticalBinLayer, illuminatePos); |
453 | 462 |
454 const DenseThreeDimensionalModel *model = m_sources.source; | 463 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
464 if (!model) return magRange; | |
455 | 465 |
456 int x0 = rect.left(); | 466 int x0 = rect.left(); |
457 int x1 = rect.right() + 1; | 467 int x1 = rect.right() + 1; |
458 | 468 |
459 int h = v->getPaintHeight(); | 469 int h = v->getPaintHeight(); |
524 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * rateRatio)); | 534 int rx1 = v->getXForFrame(int(double(fx + modelResolution + 1) * rateRatio)); |
525 | 535 |
526 int rw = rx1 - rx0; | 536 int rw = rx1 - rx0; |
527 if (rw < 1) rw = 1; | 537 if (rw < 1) rw = 1; |
528 | 538 |
539 // Qt 5.13 deprecates QFontMetrics::width(), but its suggested | |
540 // replacement (horizontalAdvance) was only added in Qt 5.11 | |
541 // which is too new for us | |
542 #pragma GCC diagnostic ignored "-Wdeprecated-declarations" | |
543 | |
529 bool showLabel = (rw > 10 && | 544 bool showLabel = (rw > 10 && |
530 paint.fontMetrics().width("0.000000") < rw - 3 && | 545 paint.fontMetrics().width("0.000000") < rw - 3 && |
531 paint.fontMetrics().height() < (h / sh)); | 546 paint.fontMetrics().height() < (h / sh)); |
532 | 547 |
533 for (int sy = minbin; sy < minbin + nbins; ++sy) { | 548 for (int sy = minbin; sy < minbin + nbins; ++sy) { |
600 int &binsPerPeak) const | 615 int &binsPerPeak) const |
601 { | 616 { |
602 peakCacheIndex = -1; | 617 peakCacheIndex = -1; |
603 binsPerPeak = -1; | 618 binsPerPeak = -1; |
604 | 619 |
605 const DenseThreeDimensionalModel *model = m_sources.source; | 620 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
606 if (!model) return; | 621 if (!model) return; |
607 if (m_params.binDisplay == BinDisplay::PeakFrequencies) return; | 622 if (m_params.binDisplay == BinDisplay::PeakFrequencies) return; |
608 if (m_params.colourScale.getScale() == ColourScaleType::Phase) return; | 623 if (m_params.colourScale.getScale() == ColourScaleType::Phase) return; |
609 | 624 |
610 ZoomLevel zoomLevel = v->getZoomLevel(); | 625 ZoomLevel zoomLevel = v->getZoomLevel(); |
611 int binResolution = model->getResolution(); | 626 int binResolution = model->getResolution(); |
612 | 627 |
613 for (int ix = 0; in_range_for(m_sources.peakCaches, ix); ++ix) { | 628 for (int ix = 0; in_range_for(m_sources.peakCaches, ix); ++ix) { |
614 int bpp = m_sources.peakCaches[ix]->getColumnsPerPeak(); | 629 auto peakCache = ModelById::getAs<Dense3DModelPeakCache> |
630 (m_sources.peakCaches[ix]); | |
631 if (!peakCache) continue; | |
632 int bpp = peakCache->getColumnsPerPeak(); | |
615 ZoomLevel equivZoom(ZoomLevel::FramesPerPixel, binResolution * bpp); | 633 ZoomLevel equivZoom(ZoomLevel::FramesPerPixel, binResolution * bpp); |
616 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 634 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
617 SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel | 635 SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel |
618 << ", cache " << ix << " has bpp = " << bpp | 636 << ", cache " << ix << " has bpp = " << bpp |
619 << " for equivZoom = " << equivZoom << endl; | 637 << " for equivZoom = " << equivZoom << endl; |
651 | 669 |
652 // Draw to the draw buffer, and then copy from there. The draw | 670 // Draw to the draw buffer, and then copy from there. The draw |
653 // buffer is at the same resolution as the target in the cache, so | 671 // buffer is at the same resolution as the target in the cache, so |
654 // no extra scaling needed. | 672 // no extra scaling needed. |
655 | 673 |
656 const DenseThreeDimensionalModel *model = m_sources.source; | 674 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
657 if (!model || !model->isOK() || !model->isReady()) { | 675 if (!model) return; |
658 throw std::logic_error("no source model provided, or model not ready"); | |
659 } | |
660 | 676 |
661 int h = v->getPaintHeight(); | 677 int h = v->getPaintHeight(); |
662 | 678 |
663 clearDrawBuffer(repaintWidth, h); | 679 clearDrawBuffer(repaintWidth, h); |
664 | 680 |
792 | 808 |
793 // Draw to the draw buffer, and then scale-copy from there. Draw | 809 // Draw to the draw buffer, and then scale-copy from there. Draw |
794 // buffer is at bin resolution, i.e. buffer x == source column | 810 // buffer is at bin resolution, i.e. buffer x == source column |
795 // number. We use toolkit smooth scaling for interpolation. | 811 // number. We use toolkit smooth scaling for interpolation. |
796 | 812 |
797 const DenseThreeDimensionalModel *model = m_sources.source; | 813 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source); |
798 if (!model || !model->isOK() || !model->isReady()) { | 814 if (!model) return; |
799 throw std::logic_error("no source model provided, or model not ready"); | |
800 } | |
801 | 815 |
802 // The draw buffer will contain a fragment at bin resolution. We | 816 // The draw buffer will contain a fragment at bin resolution. We |
803 // need to ensure that it starts and ends at points where a | 817 // need to ensure that it starts and ends at points where a |
804 // time-bin boundary occurs at an exact pixel boundary, and with a | 818 // time-bin boundary occurs at an exact pixel boundary, and with a |
805 // certain amount of overlap across existing pixels so that we can | 819 // certain amount of overlap across existing pixels so that we can |
948 RenderTimer::NoTimeout); | 962 RenderTimer::NoTimeout); |
949 | 963 |
950 Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer"); | 964 Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer"); |
951 | 965 |
952 int divisor = 1; | 966 int divisor = 1; |
953 const DenseThreeDimensionalModel *sourceModel = m_sources.source; | 967 |
968 std::shared_ptr<DenseThreeDimensionalModel> sourceModel; | |
969 | |
954 if (peakCacheIndex >= 0) { | 970 if (peakCacheIndex >= 0) { |
955 divisor = m_sources.peakCaches[peakCacheIndex]->getColumnsPerPeak(); | 971 auto peakCache = ModelById::getAs<Dense3DModelPeakCache> |
956 sourceModel = m_sources.peakCaches[peakCacheIndex]; | 972 (m_sources.peakCaches[peakCacheIndex]); |
957 } | 973 if (peakCache) { |
974 divisor = peakCache->getColumnsPerPeak(); | |
975 sourceModel = peakCache; | |
976 } | |
977 } | |
978 | |
979 if (!sourceModel) { | |
980 sourceModel = ModelById::getAs<DenseThreeDimensionalModel> | |
981 (m_sources.source); | |
982 } | |
983 | |
984 if (!sourceModel) return 0; | |
958 | 985 |
959 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 986 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
960 SVDEBUG << "renderDrawBuffer: w = " << w << ", h = " << h | 987 SVDEBUG << "renderDrawBuffer: w = " << w << ", h = " << h |
961 << ", peakCacheIndex = " << peakCacheIndex << " (divisor = " | 988 << ", peakCacheIndex = " << peakCacheIndex << " (divisor = " |
962 << divisor << "), rightToLeft = " << rightToLeft | 989 << divisor << "), rightToLeft = " << rightToLeft |
1123 | 1150 |
1124 RenderTimer timer(timeConstrained ? | 1151 RenderTimer timer(timeConstrained ? |
1125 RenderTimer::SlowRender : | 1152 RenderTimer::SlowRender : |
1126 RenderTimer::NoTimeout); | 1153 RenderTimer::NoTimeout); |
1127 | 1154 |
1128 const FFTModel *fft = m_sources.fft; | 1155 auto fft = ModelById::getAs<FFTModel>(m_sources.fft); |
1156 if (!fft) return 0; | |
1129 | 1157 |
1130 int sh = fft->getHeight(); | 1158 int sh = fft->getHeight(); |
1131 | 1159 |
1132 int minbin = int(binfory[0] + 0.0001); | 1160 int minbin = int(binfory[0] + 0.0001); |
1133 if (minbin >= sh) minbin = sh - 1; | 1161 if (minbin >= sh) minbin = sh - 1; |