Mercurial > hg > svgui
comparison layer/Colour3DPlotRenderer.cpp @ 1123:343887ac6766 spectrogram-minor-refactor
Some tidying
| author | Chris Cannam |
|---|---|
| date | Fri, 22 Jul 2016 14:42:36 +0100 |
| parents | 94370157b265 |
| children | b71a0491d287 |
comparison
equal
deleted
inserted
replaced
| 1122:94370157b265 | 1123:343887ac6766 |
|---|---|
| 28 | 28 |
| 29 #include "view/ViewManager.h" // for main model sample rate. Pity | 29 #include "view/ViewManager.h" // for main model sample rate. Pity |
| 30 | 30 |
| 31 #include <vector> | 31 #include <vector> |
| 32 | 32 |
| 33 #define DEBUG_SPECTROGRAM_REPAINT 1 //!!! name | 33 #define DEBUG_COLOUR_PLOT_REPAINT 1 |
| 34 | 34 |
| 35 using namespace std; | 35 using namespace std; |
| 36 | 36 |
| 37 Colour3DPlotRenderer::RenderResult | 37 Colour3DPlotRenderer::RenderResult |
| 38 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect) | 38 Colour3DPlotRenderer::render(const LayerGeometryProvider *v, QPainter &paint, QRect rect) |
| 117 if (renderType == DirectTranslucent) { | 117 if (renderType == DirectTranslucent) { |
| 118 MagnitudeRange range = renderDirectTranslucent(v, paint, rect); | 118 MagnitudeRange range = renderDirectTranslucent(v, paint, rect); |
| 119 return { rect, range }; | 119 return { rect, range }; |
| 120 } | 120 } |
| 121 | 121 |
| 122 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 122 cerr << "cache start " << m_cache.getStartFrame() | 123 cerr << "cache start " << m_cache.getStartFrame() |
| 123 << " valid left " << m_cache.getValidLeft() | 124 << " valid left " << m_cache.getValidLeft() |
| 124 << " valid right " << m_cache.getValidRight() | 125 << " valid right " << m_cache.getValidRight() |
| 125 << endl; | 126 << endl; |
| 126 cerr << " view start " << startFrame | 127 cerr << " view start " << startFrame |
| 127 << " x0 " << x0 | 128 << " x0 " << x0 |
| 128 << " x1 " << x1 | 129 << " x1 " << x1 |
| 129 << endl; | 130 << endl; |
| 131 #endif | |
| 130 | 132 |
| 131 if (m_cache.isValid()) { // some part of the cache is valid | 133 if (m_cache.isValid()) { // some part of the cache is valid |
| 132 | 134 |
| 133 if (v->getXForFrame(m_cache.getStartFrame()) == | 135 if (v->getXForFrame(m_cache.getStartFrame()) == |
| 134 v->getXForFrame(startFrame) && | 136 v->getXForFrame(startFrame) && |
| 135 m_cache.getValidLeft() <= x0 && | 137 m_cache.getValidLeft() <= x0 && |
| 136 m_cache.getValidRight() >= x1) { | 138 m_cache.getValidRight() >= x1) { |
| 137 | 139 |
| 140 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 138 cerr << "cache hit" << endl; | 141 cerr << "cache hit" << endl; |
| 142 #endif | |
| 139 | 143 |
| 140 // cache is valid for the complete requested area | 144 // cache is valid for the complete requested area |
| 141 paint.drawImage(rect, m_cache.getImage(), rect); | 145 paint.drawImage(rect, m_cache.getImage(), rect); |
| 142 | 146 |
| 143 //!!! a dev debug check | |
| 144 if (!m_magCache.areColumnsSet(x0, x1 - x0)) { | |
| 145 cerr << "NB Columns (" << x0 << " -> " << x1-x0 | |
| 146 << ") not set in mag cache" << endl; | |
| 147 // throw std::logic_error("Columns not set in mag cache"); | |
| 148 } | |
| 149 | |
| 150 MagnitudeRange range = m_magCache.getRange(x0, x1 - x0); | 147 MagnitudeRange range = m_magCache.getRange(x0, x1 - x0); |
| 151 | 148 |
| 152 return { rect, range }; | 149 return { rect, range }; |
| 153 | 150 |
| 154 } else { | 151 } else { |
| 152 #ifdef DEBUG_COLOUR_PLOT_REPAINT | |
| 155 cerr << "cache partial hit" << endl; | 153 cerr << "cache partial hit" << endl; |
| 154 #endif | |
| 156 | 155 |
| 157 // cache doesn't begin at the right frame or doesn't | 156 // cache doesn't begin at the right frame or doesn't |
| 158 // contain the complete view, but might be scrollable or | 157 // contain the complete view, but might be scrollable or |
| 159 // partially usable | 158 // partially usable |
| 160 m_cache.scrollTo(v, startFrame); | 159 m_cache.scrollTo(v, startFrame); |
| 246 | 245 |
| 247 MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); | 246 MagnitudeRange range = m_magCache.getRange(reqx0, reqx1 - reqx0); |
| 248 | 247 |
| 249 return { pr, range }; | 248 return { pr, range }; |
| 250 | 249 |
| 251 //!!! todo: timing/incomplete paint | |
| 252 | |
| 253 //!!! todo: peak frequency style | |
| 254 | |
| 255 //!!! todo: transparent style from Colour3DPlot | |
| 256 | |
| 257 //!!! todo: view magnitudes / normalise visible area | |
| 258 | |
| 259 //!!! todo: alter documentation for view mag stuff (cached paints | |
| 260 //!!! do not update MagnitudeRange) | |
| 261 | |
| 262 //!!! todo, here or in caller: illuminateLocalFeatures | 250 //!!! todo, here or in caller: illuminateLocalFeatures |
| 263 | 251 |
| 264 //!!! todo: colourmap rotation | 252 //!!! todo: handle vertical range other than full range of column |
| 265 | 253 |
| 266 //!!! fft model scaling? | 254 //!!! fft model scaling? |
| 267 | |
| 268 //!!! should we own the Dense3DModelPeakCache here? or should it persist | |
| 269 } | 255 } |
| 270 | 256 |
| 271 Colour3DPlotRenderer::RenderType | 257 Colour3DPlotRenderer::RenderType |
| 272 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const | 258 Colour3DPlotRenderer::decideRenderType(const LayerGeometryProvider *v) const |
| 273 { | 259 { |
| 367 // get column -> scale -> record extents -> | 353 // get column -> scale -> record extents -> |
| 368 // normalise -> peak pick -> apply display gain -> | 354 // normalise -> peak pick -> apply display gain -> |
| 369 // distribute/interpolate | 355 // distribute/interpolate |
| 370 | 356 |
| 371 ColumnOp::Column fullColumn = model->getColumn(sx); | 357 ColumnOp::Column fullColumn = model->getColumn(sx); |
| 372 | |
| 373 // cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size() | |
| 374 // << ", minbin " << minbin << ", maxbin " << maxbin << endl; | |
| 375 | 358 |
| 376 ColumnOp::Column column = | 359 ColumnOp::Column column = |
| 377 vector<float>(fullColumn.data() + minbin, | 360 vector<float>(fullColumn.data() + minbin, |
| 378 fullColumn.data() + maxbin + 1); | 361 fullColumn.data() + maxbin + 1); |
| 379 | 362 |
| 380 magRange.sample(column); | 363 magRange.sample(column); |
| 381 | 364 |
| 382 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { | 365 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { |
| 383 // column = ColumnOp::fftScale(column, m_fftSize); | 366 // column = ColumnOp::fftScale(column, m_fftSize); |
| 384 // } | 367 // } |
| 385 | |
| 386 //!!! extents recordColumnExtents(column, | |
| 387 // sx, | |
| 388 // overallMag, | |
| 389 // overallMagChanged); | |
| 390 | 368 |
| 391 // if (m_colourScale != ColourScaleType::Phase) { | 369 // if (m_colourScale != ColourScaleType::Phase) { |
| 392 preparedColumn = ColumnOp::normalize(column, m_params.normalization); | 370 preparedColumn = ColumnOp::normalize(column, m_params.normalization); |
| 393 // } | 371 // } |
| 394 | 372 |
| 764 // x is the on-canvas pixel coord; sx (later) will be the | 742 // x is the on-canvas pixel coord; sx (later) will be the |
| 765 // source column index | 743 // source column index |
| 766 | 744 |
| 767 ++columnCount; | 745 ++columnCount; |
| 768 | 746 |
| 769 #ifdef DEBUG_SPECTROGRAM_REPAINT | 747 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
| 770 cerr << "x = " << x << ", binforx[x] = " << binforx[x] << endl; | 748 cerr << "x = " << x << ", binforx[x] = " << binforx[x] << endl; |
| 771 #endif | 749 #endif |
| 772 | 750 |
| 773 if (binforx[x] < 0) continue; | 751 if (binforx[x] < 0) continue; |
| 774 | 752 |
| 782 vector<float> pixelPeakColumn; | 760 vector<float> pixelPeakColumn; |
| 783 MagnitudeRange magRange; | 761 MagnitudeRange magRange; |
| 784 | 762 |
| 785 for (int sx = sx0; sx < sx1; ++sx) { | 763 for (int sx = sx0; sx < sx1; ++sx) { |
| 786 | 764 |
| 787 #ifdef DEBUG_SPECTROGRAM_REPAINT | 765 #ifdef DEBUG_COLOUR_PLOT_REPAINT |
| 788 cerr << "sx = " << sx << endl; | 766 cerr << "sx = " << sx << endl; |
| 789 #endif | 767 #endif |
| 790 | 768 |
| 791 if (sx < 0 || sx >= modelWidth) { | 769 if (sx < 0 || sx >= modelWidth) { |
| 792 continue; | 770 continue; |
| 811 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { | 789 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { |
| 812 // column = ColumnOp::fftScale(column, m_fftSize); | 790 // column = ColumnOp::fftScale(column, m_fftSize); |
| 813 // } | 791 // } |
| 814 | 792 |
| 815 magRange.sample(column); | 793 magRange.sample(column); |
| 816 | |
| 817 //!!! extents recordColumnExtents(column, | |
| 818 // sx, | |
| 819 // overallMag, | |
| 820 // overallMagChanged); | |
| 821 | 794 |
| 822 // if (m_colourScale != ColourScaleType::Phase) { | 795 // if (m_colourScale != ColourScaleType::Phase) { |
| 823 column = ColumnOp::normalize(column, m_params.normalization); | 796 column = ColumnOp::normalize(column, m_params.normalization); |
| 824 // } | 797 // } |
| 825 | 798 |
| 961 | 934 |
| 962 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { | 935 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { |
| 963 // column = ColumnOp::fftScale(column, getFFTSize()); | 936 // column = ColumnOp::fftScale(column, getFFTSize()); |
| 964 // } | 937 // } |
| 965 | 938 |
| 966 //!!! extents recordColumnExtents(column, | |
| 967 // sx, | |
| 968 // overallMag, | |
| 969 // overallMagChanged); | |
| 970 | |
| 971 //!!! if (m_colourScale != ColourScaleType::Phase) { | 939 //!!! if (m_colourScale != ColourScaleType::Phase) { |
| 972 column = ColumnOp::normalize(column, m_params.normalization); | 940 column = ColumnOp::normalize(column, m_params.normalization); |
| 973 //!!! } | 941 //!!! } |
| 974 | 942 |
| 975 preparedColumn = column; | 943 preparedColumn = column; |
