Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1214:be42a33a3db6 3.0-integration
More cache hit counts; make debug output from colour 3d plot renderer (even though it is to SVDEBUG) appear only with explicit debug flag
| author | Chris Cannam | 
|---|---|
| date | Thu, 05 Jan 2017 14:30:49 +0000 | 
| parents | 34df6ff25472 | 
| children | 51b6381fc413 | 
   comparison
  equal
  deleted
  inserted
  replaced
| 1213:34df6ff25472 | 1214:be42a33a3db6 | 
|---|---|
| 15 | 15 | 
| 16 #include "Colour3DPlotRenderer.h" | 16 #include "Colour3DPlotRenderer.h" | 
| 17 #include "RenderTimer.h" | 17 #include "RenderTimer.h" | 
| 18 | 18 | 
| 19 #include "base/Profiler.h" | 19 #include "base/Profiler.h" | 
| 20 #include "base/HitCount.h" | |
| 20 | 21 | 
| 21 #include "data/model/DenseThreeDimensionalModel.h" | 22 #include "data/model/DenseThreeDimensionalModel.h" | 
| 22 #include "data/model/Dense3DModelPeakCache.h" | 23 #include "data/model/Dense3DModelPeakCache.h" | 
| 23 #include "data/model/FFTModel.h" | 24 #include "data/model/FFTModel.h" | 
| 24 | 25 | 
| 119 MagnitudeRange range = renderDirectTranslucent(v, paint, rect); | 120 MagnitudeRange range = renderDirectTranslucent(v, paint, rect); | 
| 120 return { rect, range }; | 121 return { rect, range }; | 
| 121 } | 122 } | 
| 122 | 123 | 
| 123 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 124 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 124 cerr << "cache start " << m_cache.getStartFrame() | 125 SVDEBUG << "cache start " << m_cache.getStartFrame() | 
| 125 << " valid left " << m_cache.getValidLeft() | 126 << " valid left " << m_cache.getValidLeft() | 
| 126 << " valid right " << m_cache.getValidRight() | 127 << " valid right " << m_cache.getValidRight() | 
| 127 << endl; | 128 << endl; | 
| 128 cerr << " view start " << startFrame | 129 SVDEBUG << " view start " << startFrame | 
| 129 << " x0 " << x0 | 130 << " x0 " << x0 | 
| 130 << " x1 " << x1 | 131 << " x1 " << x1 | 
| 131 << endl; | 132 << endl; | 
| 132 #endif | 133 #endif | 
| 134 | |
| 135 static HitCount count("Colour3DPlotRenderer: image cache"); | |
| 133 | 136 | 
| 134 if (m_cache.isValid()) { // some part of the cache is valid | 137 if (m_cache.isValid()) { // some part of the cache is valid | 
| 135 | 138 | 
| 136 if (v->getXForFrame(m_cache.getStartFrame()) == | 139 if (v->getXForFrame(m_cache.getStartFrame()) == | 
| 137 v->getXForFrame(startFrame) && | 140 v->getXForFrame(startFrame) && | 
| 138 m_cache.getValidLeft() <= x0 && | 141 m_cache.getValidLeft() <= x0 && | 
| 139 m_cache.getValidRight() >= x1) { | 142 m_cache.getValidRight() >= x1) { | 
| 140 | 143 | 
| 141 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 144 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 142 cerr << "cache hit" << endl; | 145 SVDEBUG << "cache hit" << endl; | 
| 143 #endif | 146 #endif | 
| 147 count.hit(); | |
| 144 | 148 | 
| 145 // cache is valid for the complete requested area | 149 // cache is valid for the complete requested area | 
| 146 paint.drawImage(rect, m_cache.getImage(), rect); | 150 paint.drawImage(rect, m_cache.getImage(), rect); | 
| 147 | 151 | 
| 148 MagnitudeRange range = m_magCache.getRange(x0, x1 - x0); | 152 MagnitudeRange range = m_magCache.getRange(x0, x1 - x0); | 
| 149 | 153 | 
| 150 return { rect, range }; | 154 return { rect, range }; | 
| 151 | 155 | 
| 152 } else { | 156 } else { | 
| 153 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 157 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 154 cerr << "cache partial hit" << endl; | 158 SVDEBUG << "cache partial hit" << endl; | 
| 155 #endif | 159 #endif | 
| 160 count.partial(); | |
| 156 | 161 | 
| 157 // cache doesn't begin at the right frame or doesn't | 162 // cache doesn't begin at the right frame or doesn't | 
| 158 // contain the complete view, but might be scrollable or | 163 // contain the complete view, but might be scrollable or | 
| 159 // partially usable | 164 // partially usable | 
| 160 m_cache.scrollTo(v, startFrame); | 165 m_cache.scrollTo(v, startFrame); | 
| 173 } | 178 } | 
| 174 } | 179 } | 
| 175 } | 180 } | 
| 176 } else { | 181 } else { | 
| 177 // cache is completely invalid | 182 // cache is completely invalid | 
| 183 count.miss(); | |
| 178 m_cache.setStartFrame(startFrame); | 184 m_cache.setStartFrame(startFrame); | 
| 179 m_magCache.setStartFrame(startFrame); | 185 m_magCache.setStartFrame(startFrame); | 
| 180 } | 186 } | 
| 181 | 187 | 
| 182 bool rightToLeft = false; | 188 bool rightToLeft = false; | 
| 461 if (r.contains(illuminatePos)) { | 467 if (r.contains(illuminatePos)) { | 
| 462 paint.setPen(v->getForeground()); | 468 paint.setPen(v->getForeground()); | 
| 463 } | 469 } | 
| 464 } | 470 } | 
| 465 | 471 | 
| 466 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT | 472 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 467 // cerr << "rect " << r.x() << "," << r.y() << " " | 473 // SVDEBUG << "rect " << r.x() << "," << r.y() << " " | 
| 468 // << r.width() << "x" << r.height() << endl; | 474 // << r.width() << "x" << r.height() << endl; | 
| 469 #endif | 475 #endif | 
| 470 | 476 | 
| 471 paint.drawRect(r); | 477 paint.drawRect(r); | 
| 472 | 478 | 
| 513 binsPerPeak = bpp; | 519 binsPerPeak = bpp; | 
| 514 } | 520 } | 
| 515 } | 521 } | 
| 516 } | 522 } | 
| 517 | 523 | 
| 524 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 518 SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel | 525 SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel | 
| 519 << ", binResolution " << binResolution | 526 << ", binResolution " << binResolution | 
| 520 << ", binsPerPeak " << binsPerPeak | 527 << ", binsPerPeak " << binsPerPeak | 
| 521 << ", peakCacheIndex " << peakCacheIndex | 528 << ", peakCacheIndex " << peakCacheIndex | 
| 522 << ", peakCaches " << m_sources.peakCaches.size() | 529 << ", peakCaches " << m_sources.peakCaches.size() | 
| 523 << endl; | 530 << endl; | 
| 531 #endif | |
| 524 } | 532 } | 
| 525 | 533 | 
| 526 void | 534 void | 
| 527 Colour3DPlotRenderer::renderToCachePixelResolution(const LayerGeometryProvider *v, | 535 Colour3DPlotRenderer::renderToCachePixelResolution(const LayerGeometryProvider *v, | 
| 528 int x0, int repaintWidth, | 536 int x0, int repaintWidth, | 
| 529 bool rightToLeft, | 537 bool rightToLeft, | 
| 530 bool timeConstrained) | 538 bool timeConstrained) | 
| 531 { | 539 { | 
| 532 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution"); | 540 Profiler profiler("Colour3DPlotRenderer::renderToCachePixelResolution"); | 
| 533 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 541 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 534 cerr << "renderToCachePixelResolution" << endl; | 542 SVDEBUG << "renderToCachePixelResolution" << endl; | 
| 535 #endif | 543 #endif | 
| 536 | 544 | 
| 537 // Draw to the draw buffer, and then copy from there. The draw | 545 // Draw to the draw buffer, and then copy from there. The draw | 
| 538 // buffer is at the same resolution as the target in the cache, so | 546 // buffer is at the same resolution as the target in the cache, so | 
| 539 // no extra scaling needed. | 547 // no extra scaling needed. | 
| 672 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, | 680 Colour3DPlotRenderer::renderToCacheBinResolution(const LayerGeometryProvider *v, | 
| 673 int x0, int repaintWidth) | 681 int x0, int repaintWidth) | 
| 674 { | 682 { | 
| 675 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); | 683 Profiler profiler("Colour3DPlotRenderer::renderToCacheBinResolution"); | 
| 676 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 684 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 677 cerr << "renderToCacheBinResolution" << endl; | 685 SVDEBUG << "renderToCacheBinResolution" << endl; | 
| 678 #endif | 686 #endif | 
| 679 | 687 | 
| 680 // Draw to the draw buffer, and then scale-copy from there. Draw | 688 // Draw to the draw buffer, and then scale-copy from there. Draw | 
| 681 // buffer is at bin resolution, i.e. buffer x == source column | 689 // buffer is at bin resolution, i.e. buffer x == source column | 
| 682 // number. We use toolkit smooth scaling for interpolation. | 690 // number. We use toolkit smooth scaling for interpolation. | 
| 738 | 746 | 
| 739 for (int x = 0; x < drawBufferWidth; ++x) { | 747 for (int x = 0; x < drawBufferWidth; ++x) { | 
| 740 binforx[x] = int(leftBoundaryFrame / binResolution) + x; | 748 binforx[x] = int(leftBoundaryFrame / binResolution) + x; | 
| 741 } | 749 } | 
| 742 | 750 | 
| 751 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 743 SVDEBUG << "[BIN] binResolution " << binResolution << endl; | 752 SVDEBUG << "[BIN] binResolution " << binResolution << endl; | 
| 753 #endif | |
| 744 | 754 | 
| 745 for (int y = 0; y < h; ++y) { | 755 for (int y = 0; y < h; ++y) { | 
| 746 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); | 756 binfory[y] = m_sources.verticalBinLayer->getBinForY(v, h - y - 1); | 
| 747 } | 757 } | 
| 748 | 758 | 
| 785 if (sourceLeft < 0) { | 795 if (sourceLeft < 0) { | 
| 786 sourceLeft = 0; | 796 sourceLeft = 0; | 
| 787 } | 797 } | 
| 788 | 798 | 
| 789 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 799 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 790 cerr << "repaintWidth = " << repaintWidth | 800 SVDEBUG << "repaintWidth = " << repaintWidth | 
| 791 << ", targetWidth = " << targetWidth << endl; | 801 << ", targetWidth = " << targetWidth << endl; | 
| 792 #endif | 802 #endif | 
| 793 | 803 | 
| 794 if (targetWidth > 0) { | 804 if (targetWidth > 0) { | 
| 795 // we are copying from an image that has already been scaled, | 805 // we are copying from an image that has already been scaled, | 
| 796 // hence using the same width in both geometries | 806 // hence using the same width in both geometries | 
| 832 if (peakCacheIndex >= 0) { | 842 if (peakCacheIndex >= 0) { | 
| 833 divisor = m_sources.peakCaches[peakCacheIndex]->getColumnsPerPeak(); | 843 divisor = m_sources.peakCaches[peakCacheIndex]->getColumnsPerPeak(); | 
| 834 sourceModel = m_sources.peakCaches[peakCacheIndex]; | 844 sourceModel = m_sources.peakCaches[peakCacheIndex]; | 
| 835 } | 845 } | 
| 836 | 846 | 
| 847 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 837 SVDEBUG << "renderDrawBuffer: w = " << w << ", h = " << h | 848 SVDEBUG << "renderDrawBuffer: w = " << w << ", h = " << h | 
| 838 << ", peakCacheIndex = " << peakCacheIndex << " (divisor = " | 849 << ", peakCacheIndex = " << peakCacheIndex << " (divisor = " | 
| 839 << divisor << "), rightToLeft = " << rightToLeft | 850 << divisor << "), rightToLeft = " << rightToLeft | 
| 840 << ", timeConstrained = " << timeConstrained << endl; | 851 << ", timeConstrained = " << timeConstrained << endl; | 
| 841 SVDEBUG << "renderDrawBuffer: normalization = " << int(m_params.normalization) | 852 SVDEBUG << "renderDrawBuffer: normalization = " << int(m_params.normalization) | 
| 842 << ", binDisplay = " << int(m_params.binDisplay) | 853 << ", binDisplay = " << int(m_params.binDisplay) | 
| 843 << ", binScale = " << int(m_params.binScale) | 854 << ", binScale = " << int(m_params.binScale) | 
| 844 << ", alwaysOpaque = " << m_params.alwaysOpaque | 855 << ", alwaysOpaque = " << m_params.alwaysOpaque | 
| 845 << ", interpolate = " << m_params.interpolate << endl; | 856 << ", interpolate = " << m_params.interpolate << endl; | 
| 857 #endif | |
| 846 | 858 | 
| 847 int sh = sourceModel->getHeight(); | 859 int sh = sourceModel->getHeight(); | 
| 848 | 860 | 
| 849 int minbin = int(binfory[0] + 0.0001); | 861 int minbin = int(binfory[0] + 0.0001); | 
| 850 if (minbin >= sh) minbin = sh - 1; | 862 if (minbin >= sh) minbin = sh - 1; | 
| 852 | 864 | 
| 853 int nbins = int(binfory[h-1] + 0.0001) - minbin + 1; | 865 int nbins = int(binfory[h-1] + 0.0001) - minbin + 1; | 
| 854 if (minbin + nbins > sh) nbins = sh - minbin; | 866 if (minbin + nbins > sh) nbins = sh - minbin; | 
| 855 | 867 | 
| 856 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 868 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 857 cerr << "minbin = " << minbin << ", nbins = " << nbins << ", last binfory = " | 869 SVDEBUG << "minbin = " << minbin << ", nbins = " << nbins << ", last binfory = " | 
| 858 << binfory[h-1] << " (rounds to " << int(binfory[h-1]) << ") (model height " << sh << ")" << endl; | 870 << binfory[h-1] << " (rounds to " << int(binfory[h-1]) << ") (model height " << sh << ")" << endl; | 
| 859 #endif | 871 #endif | 
| 860 | 872 | 
| 861 int psx = -1; | 873 int psx = -1; | 
| 862 | 874 | 
| 875 vector<float> preparedColumn; | 887 vector<float> preparedColumn; | 
| 876 | 888 | 
| 877 int modelWidth = sourceModel->getWidth(); | 889 int modelWidth = sourceModel->getWidth(); | 
| 878 | 890 | 
| 879 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 891 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 880 cerr << "modelWidth " << modelWidth << ", divisor " << divisor << endl; | 892 SVDEBUG << "modelWidth " << modelWidth << ", divisor " << divisor << endl; | 
| 881 #endif | 893 #endif | 
| 882 | 894 | 
| 883 for (int x = start; x != finish; x += step) { | 895 for (int x = start; x != finish; x += step) { | 
| 884 | 896 | 
| 885 // x is the on-canvas pixel coord; sx (later) will be the | 897 // x is the on-canvas pixel coord; sx (later) will be the | 
| 895 if (sx0 < 0) sx0 = sx1 - 1; | 907 if (sx0 < 0) sx0 = sx1 - 1; | 
| 896 if (sx0 < 0) continue; | 908 if (sx0 < 0) continue; | 
| 897 if (sx1 <= sx0) sx1 = sx0 + 1; | 909 if (sx1 <= sx0) sx1 = sx0 + 1; | 
| 898 | 910 | 
| 899 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 911 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 900 // cerr << "x = " << x << ", binforx[x] = " << binforx[x] << ", sx range " << sx0 << " -> " << sx1 << endl; | 912 // SVDEBUG << "x = " << x << ", binforx[x] = " << binforx[x] << ", sx range " << sx0 << " -> " << sx1 << endl; | 
| 901 #endif | 913 #endif | 
| 902 | 914 | 
| 903 vector<float> pixelPeakColumn; | 915 vector<float> pixelPeakColumn; | 
| 904 MagnitudeRange magRange; | 916 MagnitudeRange magRange; | 
| 905 | 917 | 
| 966 m_magRanges.push_back(magRange); | 978 m_magRanges.push_back(magRange); | 
| 967 } | 979 } | 
| 968 | 980 | 
| 969 double fractionComplete = double(columnCount) / double(w); | 981 double fractionComplete = double(columnCount) / double(w); | 
| 970 if (timer.outOfTime(fractionComplete)) { | 982 if (timer.outOfTime(fractionComplete)) { | 
| 983 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 971 SVDEBUG << "out of time" << endl; | 984 SVDEBUG << "out of time" << endl; | 
| 985 #endif | |
| 972 return columnCount; | 986 return columnCount; | 
| 973 } | 987 } | 
| 974 } | 988 } | 
| 975 | 989 | 
| 976 return columnCount; | 990 return columnCount; | 
| 1021 | 1035 | 
| 1022 vector<float> preparedColumn; | 1036 vector<float> preparedColumn; | 
| 1023 | 1037 | 
| 1024 int modelWidth = fft->getWidth(); | 1038 int modelWidth = fft->getWidth(); | 
| 1025 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 1039 #ifdef DEBUG_COLOUR_PLOT_REPAINT | 
| 1026 cerr << "modelWidth " << modelWidth << endl; | 1040 SVDEBUG << "modelWidth " << modelWidth << endl; | 
| 1027 #endif | 1041 #endif | 
| 1028 | 1042 | 
| 1029 double minFreq = | 1043 double minFreq = | 
| 1030 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); | 1044 (double(minbin) * fft->getSampleRate()) / fft->getFFTSize(); | 
| 1031 double maxFreq = | 1045 double maxFreq = | 
