Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1166:d89e04b0eff3 3.0-integration
Backed out changeset c036560a7205
author | Chris Cannam |
---|---|
date | Thu, 17 Nov 2016 11:48:59 +0000 |
parents | c036560a7205 |
children | 236ecb2c0758 |
comparison
equal
deleted
inserted
replaced
1165:c036560a7205 | 1166:d89e04b0eff3 |
---|---|
29 | 29 |
30 #include "view/ViewManager.h" // for main model sample rate. Pity | 30 #include "view/ViewManager.h" // for main model sample rate. Pity |
31 | 31 |
32 #include <vector> | 32 #include <vector> |
33 | 33 |
34 #define DEBUG_COLOUR_PLOT_REPAINT 1 | 34 //#define DEBUG_COLOUR_PLOT_REPAINT 1 |
35 | 35 |
36 using namespace std; | 36 using namespace std; |
37 | 37 |
38 Colour3DPlotRenderer::RenderResult | 38 Colour3DPlotRenderer::RenderResult |
39 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect) | 39 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect) |
576 for (int i = 0; in_range_for(m_magRanges, i); ++i) { | 576 for (int i = 0; in_range_for(m_magRanges, i); ++i) { |
577 m_magCache.sampleColumn(i, m_magRanges.at(i)); | 577 m_magCache.sampleColumn(i, m_magRanges.at(i)); |
578 } | 578 } |
579 } | 579 } |
580 | 580 |
581 QImage | |
582 Colour3DPlotRenderer::scaleDrawBufferImage(QImage image, | |
583 int targetWidth, | |
584 int targetHeight) const | |
585 { | |
586 int sourceWidth = image.width(); | |
587 int sourceHeight = image.height(); | |
588 | |
589 // We can only do this if we're making the image larger -- | |
590 // otherwise peaks may be lost. So this should be called only when | |
591 // rendering in DrawBufferBinResolution mode. Whenever the bin | |
592 // size is smaller than the pixel size, in either x or y axis, we | |
593 // should be using DrawBufferPixelResolution mode instead | |
594 | |
595 if (targetWidth < sourceWidth || targetHeight < sourceHeight) { | |
596 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Can only use this function when making the image larger; should be rendering DrawBufferPixelResolution instead"); | |
597 } | |
598 | |
599 if (sourceWidth <= 0 || sourceHeight <= 0) { | |
600 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Source image is empty"); | |
601 } | |
602 | |
603 if (targetWidth <= 0 || targetHeight <= 0) { | |
604 throw std::logic_error("Colour3DPlotRenderer::scaleDrawBufferImage: Target image is empty"); | |
605 } | |
606 | |
607 // This function exists because of some unpredictable behaviour | |
608 // from Qt when scaling images with FastTransformation mode. We | |
609 // continue to use Qt's scaler for SmoothTransformation but let's | |
610 // bring the non-interpolated version "in-house" so we know what | |
611 // it's really doing. | |
612 | |
613 if (m_params.interpolate) { | |
614 return image.scaled(targetWidth, targetHeight, | |
615 Qt::IgnoreAspectRatio, | |
616 Qt::SmoothTransformation); | |
617 } | |
618 | |
619 // Same format as the target cache | |
620 QImage target(targetWidth, targetHeight, QImage::Format_ARGB32_Premultiplied); | |
621 | |
622 for (int y = 0; y < targetHeight; ++y) { | |
623 | |
624 QRgb *targetLine = reinterpret_cast<QRgb *>(target.scanLine(y)); | |
625 | |
626 int sy = int((uint64_t(y) * sourceHeight) / targetHeight); | |
627 if (sy == sourceHeight) --sy; | |
628 | |
629 for (int x = 0; x < targetWidth; ++x) { | |
630 | |
631 int sx = int((uint64_t(x) * sourceWidth) / targetWidth); | |
632 if (sx == sourceWidth) --sx; | |
633 | |
634 targetLine[x] = image.pixel(sx, sy); | |
635 } | |
636 } | |
637 | |
638 return target; | |
639 } | |
640 | |
641 void | 581 void |
642 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, | 582 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, |
643 int x0, int repaintWidth) | 583 int x0, int repaintWidth) |
644 { | 584 { |
645 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); | 585 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); |
708 | 648 |
709 for (int x = 0; x < drawBufferWidth; ++x) { | 649 for (int x = 0; x < drawBufferWidth; ++x) { |
710 binforx[x] = int(leftBoundaryFrame / binResolution) + x; | 650 binforx[x] = int(leftBoundaryFrame / binResolution) + x; |
711 } | 651 } |
712 | 652 |
713 SVDEBUG << "[BIN] binResolution " << binResolution << endl; | 653 SVDEBUG << "[BIN] binResolution " << binResolution |
654 << endl; | |
714 | 655 |
715 for (int y = 0; y < h; ++y) { | 656 for (int y = 0; y < h; ++y) { |
716 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); | 657 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); |
717 } | 658 } |
718 | 659 |
732 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 673 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
733 cerr << "scaling draw buffer from width " << m_drawBuffer.width() | 674 cerr << "scaling draw buffer from width " << m_drawBuffer.width() |
734 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = " | 675 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = " |
735 << drawBufferWidth << ")" << endl; | 676 << drawBufferWidth << ")" << endl; |
736 #endif | 677 #endif |
737 | 678 |
738 QImage scaled = scaleDrawBufferImage | 679 QImage scaled = m_drawBuffer.scaled |
739 (m_drawBuffer, scaledRight - scaledLeft, h); | 680 (scaledRight - scaledLeft, h, |
681 Qt::IgnoreAspectRatio, (m_params.interpolate ? | |
682 Qt::SmoothTransformation : | |
683 Qt::FastTransformation)); | |
740 | 684 |
741 int scaledLeftCrop = v->getXForFrame(leftCropFrame); | 685 int scaledLeftCrop = v->getXForFrame(leftCropFrame); |
742 int scaledRightCrop = v->getXForFrame(rightCropFrame); | 686 int scaledRightCrop = v->getXForFrame(rightCropFrame); |
743 | 687 |
744 int targetLeft = scaledLeftCrop; | 688 int targetLeft = scaledLeftCrop; |
798 Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer"); | 742 Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer"); |
799 | 743 |
800 int divisor = 1; | 744 int divisor = 1; |
801 const DenseThreeDimensionalModel *sourceModel = m_sources.source; | 745 const DenseThreeDimensionalModel *sourceModel = m_sources.source; |
802 if (usePeakCache) { | 746 if (usePeakCache) { |
803 cerr << "usePeakCache is true, with divisor " << divisor << endl; | |
804 divisor = m_sources.peakCache->getColumnsPerPeak(); | 747 divisor = m_sources.peakCache->getColumnsPerPeak(); |
805 sourceModel = m_sources.peakCache; | 748 sourceModel = m_sources.peakCache; |
806 } else { | |
807 cerr << "usePeakCache is false" << endl; | |
808 } | 749 } |
809 | 750 |
810 int sh = sourceModel->getHeight(); | 751 int sh = sourceModel->getHeight(); |
811 | 752 |
812 int minbin = int(binfory[0] + 0.0001); | 753 int minbin = int(binfory[0] + 0.0001); |
858 if (sx0 < 0) sx0 = sx1 - 1; | 799 if (sx0 < 0) sx0 = sx1 - 1; |
859 if (sx0 < 0) continue; | 800 if (sx0 < 0) continue; |
860 if (sx1 <= sx0) sx1 = sx0 + 1; | 801 if (sx1 <= sx0) sx1 = sx0 + 1; |
861 | 802 |
862 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 803 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
863 // cerr << "x = " << x << ", binforx[x] = " << binforx[x] << ", sx range " << sx0 << " -> " << sx1 << endl; | 804 cerr << "x = " << x << ", binforx[x] = " << binforx[x] << ", sx range " << sx0 << " -> " << sx1 << endl; |
864 #endif | 805 #endif |
865 | 806 |
866 vector<float> pixelPeakColumn; | 807 vector<float> pixelPeakColumn; |
867 MagnitudeRange magRange; | 808 MagnitudeRange magRange; |
868 | 809 |