comparison layer/Colour3DPlotRenderer.cpp @ 1120:65cdaf8d6b50 spectrogram-minor-refactor

Toward updating mag cache
author Chris Cannam
date Wed, 20 Jul 2016 13:40:23 +0100
parents be5b91ec81a0
children d930ff725f64
comparison
equal deleted inserted replaced
1119:be5b91ec81a0 1120:65cdaf8d6b50
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 33 #define DEBUG_SPECTROGRAM_REPAINT 1 //!!! name
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)
74 // cases because we are quite well zoomed-in, and the sums are 74 // cases because we are quite well zoomed-in, and the sums are
75 // easier this way. Calculating boundaries later will be 75 // easier this way. Calculating boundaries later will be
76 // fiddly for partial paints otherwise. 76 // fiddly for partial paints otherwise.
77 timeConstrained = false; 77 timeConstrained = false;
78 } 78 }
79 79
80 if (renderType == DirectTranslucent) {
81 renderDirectTranslucent(v, paint, rect);
82 return { rect, {} }; //!!! this return arg is not very useful
83 }
84
85 sv_frame_t startFrame = v->getStartFrame();
86
87 int x0 = v->getXForViewX(rect.x()); 80 int x0 = v->getXForViewX(rect.x());
88 int x1 = v->getXForViewX(rect.x() + rect.width()); 81 int x1 = v->getXForViewX(rect.x() + rect.width());
89 if (x0 < 0) x0 = 0; 82 if (x0 < 0) x0 = 0;
90 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth(); 83 if (x1 > v->getPaintWidth()) x1 = v->getPaintWidth();
91 84
85 sv_frame_t startFrame = v->getStartFrame();
86
92 m_cache.resize(v->getPaintSize()); 87 m_cache.resize(v->getPaintSize());
93 m_cache.setZoomLevel(v->getZoomLevel()); 88 m_cache.setZoomLevel(v->getZoomLevel());
94 89
95 m_magCache.resize(v->getPaintSize().width()); 90 m_magCache.resize(v->getPaintSize().width());
96 m_magCache.setZoomLevel(v->getZoomLevel()); 91 m_magCache.setZoomLevel(v->getZoomLevel());
92
93 if (renderType == DirectTranslucent) {
94 renderDirectTranslucent(v, paint, rect);
95 //!!! mag range!
96
97 //!!! a dev debug check
98 if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
99 cerr << "Columns (" << x0 << " -> " << x1-x0
100 << ") not set in mag cache" << endl;
101 throw std::logic_error("Columns not set in mag cache");
102 }
103
104 //!!! this is wrong
105 MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
106
107 return { rect, range }; //!!! this return arg is not very useful
108 }
97 109
98 cerr << "cache start " << m_cache.getStartFrame() 110 cerr << "cache start " << m_cache.getStartFrame()
99 << " valid left " << m_cache.getValidLeft() 111 << " valid left " << m_cache.getValidLeft()
100 << " valid right " << m_cache.getValidRight() 112 << " valid right " << m_cache.getValidRight()
101 << endl; 113 << endl;
214 //!!! on a first cut, there is a risk that this will happen 226 //!!! on a first cut, there is a risk that this will happen
215 //!!! when we are at start/end of model -- trap, report, and 227 //!!! when we are at start/end of model -- trap, report, and
216 //!!! then fix 228 //!!! then fix
217 throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained"); 229 throw std::logic_error("internal error: failed to render entire requested rect even when not time-constrained");
218 } 230 }
219 231
220 return { pr, {} }; 232 //!!! a dev debug check
233 if (!m_magCache.areColumnsSet(x0, x1 - x0)) {
234 cerr << "Columns (" << x0 << " -> " << x1-x0
235 << ") not set in mag cache" << endl;
236 throw std::logic_error("Columns not set in mag cache");
237 }
238
239 MagnitudeRange range = m_magCache.getRange(x0, x1-x0);
240
241 return { pr, range };
221 242
222 //!!! todo: timing/incomplete paint 243 //!!! todo: timing/incomplete paint
223 244
224 //!!! todo: peak frequency style 245 //!!! todo: peak frequency style
225 246
717 738
718 // x is the on-canvas pixel coord; sx (later) will be the 739 // x is the on-canvas pixel coord; sx (later) will be the
719 // source column index 740 // source column index
720 741
721 ++columnCount; 742 ++columnCount;
743
744 #ifdef DEBUG_SPECTROGRAM_REPAINT
745 cerr << "x = " << x << endl;
746 #endif
722 747
723 if (binforx[x] < 0) continue; 748 if (binforx[x] < 0) continue;
724 749
725 int sx0 = binforx[x] / divisor; 750 int sx0 = binforx[x] / divisor;
726 int sx1 = sx0; 751 int sx1 = sx0;
759 784
760 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) { 785 //!!! fft scale if (m_colourScale != ColourScaleType::Phase) {
761 // column = ColumnOp::fftScale(column, m_fftSize); 786 // column = ColumnOp::fftScale(column, m_fftSize);
762 // } 787 // }
763 788
789 MagnitudeRange r;
790 r.sample(column);
791 int magColIndex = sx - int(m_magCache.getStartFrame() /
792 sourceModel->getResolution());
793 cerr << "magColIndex = " << magColIndex << endl;
794 m_magCache.sampleColumn(magColIndex, r);
795
764 //!!! extents recordColumnExtents(column, 796 //!!! extents recordColumnExtents(column,
765 // sx, 797 // sx,
766 // overallMag, 798 // overallMag,
767 // overallMagChanged); 799 // overallMagChanged);
768 800