Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1143:c53ed1a6fcbd spectrogram-minor-refactor
Fixes to phase display and colour scale for it; tidy up some debug output
author | Chris Cannam |
---|---|
date | Fri, 05 Aug 2016 14:31:16 +0100 |
parents | f19dcb288123 |
children | 436df5f24bda |
comparison
equal
deleted
inserted
replaced
1142:8f4634b82e36 | 1143:c53ed1a6fcbd |
---|---|
481 int x0, int repaintWidth, | 481 int x0, int repaintWidth, |
482 bool rightToLeft, | 482 bool rightToLeft, |
483 bool timeConstrained) | 483 bool timeConstrained) |
484 { | 484 { |
485 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution"); | 485 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution"); |
486 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
486 cerr << "renderToCachePixelResolution" << endl; | 487 cerr << "renderToCachePixelResolution" << endl; |
488 #endif | |
487 | 489 |
488 // Draw to the draw buffer, and then copy from there. The draw | 490 // Draw to the draw buffer, and then copy from there. The draw |
489 // buffer is at the same resolution as the target in the cache, so | 491 // buffer is at the same resolution as the target in the cache, so |
490 // no extra scaling needed. | 492 // no extra scaling needed. |
491 | 493 |
521 ColourScaleType::Phase) { | 523 ColourScaleType::Phase) { |
522 usePeaksCache = false; | 524 usePeaksCache = false; |
523 } | 525 } |
524 } | 526 } |
525 | 527 |
528 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
526 cerr << "[PIX] zoomLevel = " << zoomLevel | 529 cerr << "[PIX] zoomLevel = " << zoomLevel |
527 << ", binResolution " << binResolution | 530 << ", binResolution " << binResolution |
528 << ", binsPerPeak " << binsPerPeak | 531 << ", binsPerPeak " << binsPerPeak |
529 << ", peak cache " << m_sources.peaks | 532 << ", peak cache " << m_sources.peaks |
530 << ", usePeaksCache = " << usePeaksCache | 533 << ", usePeaksCache = " << usePeaksCache |
531 << endl; | 534 << endl; |
535 #endif | |
532 | 536 |
533 for (int y = 0; y < h; ++y) { | 537 for (int y = 0; y < h; ++y) { |
534 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); | 538 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); |
535 } | 539 } |
536 | 540 |
576 void | 580 void |
577 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, | 581 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, |
578 int x0, int repaintWidth) | 582 int x0, int repaintWidth) |
579 { | 583 { |
580 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); | 584 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); |
585 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
581 cerr << "renderToCacheBinResolution" << endl; | 586 cerr << "renderToCacheBinResolution" << endl; |
587 #endif | |
582 | 588 |
583 // Draw to the draw buffer, and then scale-copy from there. Draw | 589 // Draw to the draw buffer, and then scale-copy from there. Draw |
584 // buffer is at bin resolution, i.e. buffer x == source column | 590 // buffer is at bin resolution, i.e. buffer x == source column |
585 // number. We use toolkit smooth scaling for interpolation. | 591 // number. We use toolkit smooth scaling for interpolation. |
586 | 592 |
641 | 647 |
642 for (int x = 0; x < drawBufferWidth; ++x) { | 648 for (int x = 0; x < drawBufferWidth; ++x) { |
643 binforx[x] = int(leftBoundaryFrame / binResolution) + x; | 649 binforx[x] = int(leftBoundaryFrame / binResolution) + x; |
644 } | 650 } |
645 | 651 |
652 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
646 cerr << "[BIN] binResolution " << binResolution | 653 cerr << "[BIN] binResolution " << binResolution |
647 << endl; | 654 << endl; |
655 #endif | |
648 | 656 |
649 for (int y = 0; y < h; ++y) { | 657 for (int y = 0; y < h; ++y) { |
650 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); | 658 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); |
651 } | 659 } |
652 | 660 |
661 if (attainedWidth == 0) return; | 669 if (attainedWidth == 0) return; |
662 | 670 |
663 int scaledLeft = v->getXForFrame(leftBoundaryFrame); | 671 int scaledLeft = v->getXForFrame(leftBoundaryFrame); |
664 int scaledRight = v->getXForFrame(rightBoundaryFrame); | 672 int scaledRight = v->getXForFrame(rightBoundaryFrame); |
665 | 673 |
674 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
666 cerr << "scaling draw buffer from width " << m_drawBuffer.width() | 675 cerr << "scaling draw buffer from width " << m_drawBuffer.width() |
667 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = " | 676 << " to " << (scaledRight - scaledLeft) << " (nb drawBufferWidth = " |
668 << drawBufferWidth << ")" << endl; | 677 << drawBufferWidth << ")" << endl; |
678 #endif | |
669 | 679 |
670 QImage scaled = m_drawBuffer.scaled | 680 QImage scaled = m_drawBuffer.scaled |
671 (scaledRight - scaledLeft, h, | 681 (scaledRight - scaledLeft, h, |
672 Qt::IgnoreAspectRatio, (m_params.interpolate ? | 682 Qt::IgnoreAspectRatio, (m_params.interpolate ? |
673 Qt::SmoothTransformation : | 683 Qt::SmoothTransformation : |
689 int sourceLeft = targetLeft - scaledLeft; | 699 int sourceLeft = targetLeft - scaledLeft; |
690 if (sourceLeft < 0) { | 700 if (sourceLeft < 0) { |
691 sourceLeft = 0; | 701 sourceLeft = 0; |
692 } | 702 } |
693 | 703 |
704 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
694 cerr << "repaintWidth = " << repaintWidth | 705 cerr << "repaintWidth = " << repaintWidth |
695 << ", targetWidth = " << targetWidth << endl; | 706 << ", targetWidth = " << targetWidth << endl; |
707 #endif | |
696 | 708 |
697 if (targetWidth > 0) { | 709 if (targetWidth > 0) { |
698 // we are copying from an image that has already been scaled, | 710 // we are copying from an image that has already been scaled, |
699 // hence using the same width in both geometries | 711 // hence using the same width in both geometries |
700 m_cache.drawImage(targetLeft, targetWidth, | 712 m_cache.drawImage(targetLeft, targetWidth, |
704 | 716 |
705 for (int i = 0; i < targetWidth; ++i) { | 717 for (int i = 0; i < targetWidth; ++i) { |
706 // but the mag range vector has not been scaled | 718 // but the mag range vector has not been scaled |
707 int sourceIx = int((double(i + sourceLeft) / scaled.width()) | 719 int sourceIx = int((double(i + sourceLeft) / scaled.width()) |
708 * int(m_magRanges.size())); | 720 * int(m_magRanges.size())); |
709 // int sourceIx = int((double(i) / targetWidth) * sourceWidth); | |
710 cerr << "mag range target ix = " << i << ", source ix = " | |
711 << sourceIx << ", of " << m_magRanges.size() << endl; | |
712 if (in_range_for(m_magRanges, sourceIx)) { | 721 if (in_range_for(m_magRanges, sourceIx)) { |
713 m_magCache.sampleColumn(i, m_magRanges.at(sourceIx)); | 722 m_magCache.sampleColumn(i, m_magRanges.at(sourceIx)); |
714 } | 723 } |
715 } | 724 } |
716 } | 725 } |
763 | 772 |
764 vector<float> preparedColumn; | 773 vector<float> preparedColumn; |
765 | 774 |
766 int modelWidth = sourceModel->getWidth(); | 775 int modelWidth = sourceModel->getWidth(); |
767 | 776 |
777 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
768 cerr << "modelWidth " << modelWidth << ", divisor " << divisor << endl; | 778 cerr << "modelWidth " << modelWidth << ", divisor " << divisor << endl; |
769 | 779 #endif |
780 | |
770 for (int x = start; x != finish; x += step) { | 781 for (int x = start; x != finish; x += step) { |
771 | 782 |
772 // x is the on-canvas pixel coord; sx (later) will be the | 783 // x is the on-canvas pixel coord; sx (later) will be the |
773 // source column index | 784 // source column index |
774 | 785 |
910 int columnCount = 0; | 921 int columnCount = 0; |
911 | 922 |
912 vector<float> preparedColumn; | 923 vector<float> preparedColumn; |
913 | 924 |
914 int modelWidth = fft->getWidth(); | 925 int modelWidth = fft->getWidth(); |
926 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
915 cerr << "modelWidth " << modelWidth << endl; | 927 cerr << "modelWidth " << modelWidth << endl; |
916 | 928 #endif |
929 | |
917 double minFreq = | 930 double minFreq = |
918 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); | 931 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); |
919 double maxFreq = | 932 double maxFreq = |
920 (double(minbin + nbins - 1) * fft->getSampleRate()) / fft->getFFTSize(); | 933 (double(minbin + nbins - 1) * fft->getSampleRate()) / fft->getFFTSize(); |
921 | 934 |