Mercurial > hg > svgui
changeset 1119:be5b91ec81a0 spectrogram-minor-refactor
Inch toward using the mag cache (currently will crash with debug exception)
author | Chris Cannam |
---|---|
date | Wed, 20 Jul 2016 08:42:04 +0100 |
parents | 175d4e15884d |
children | 65cdaf8d6b50 |
files | layer/Colour3DPlotRenderer.cpp layer/Colour3DPlotRenderer.h layer/ScrollableMagRangeCache.h |
diffstat | 3 files changed, 53 insertions(+), 7 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp Wed Jul 20 08:30:20 2016 +0100 +++ b/layer/Colour3DPlotRenderer.cpp Wed Jul 20 08:42:04 2016 +0100 @@ -92,6 +92,9 @@ m_cache.resize(v->getPaintSize()); m_cache.setZoomLevel(v->getZoomLevel()); + m_magCache.resize(v->getPaintSize().width()); + m_magCache.setZoomLevel(v->getZoomLevel()); + cerr << "cache start " << m_cache.getStartFrame() << " valid left " << m_cache.getValidLeft() << " valid right " << m_cache.getValidRight() @@ -112,7 +115,17 @@ // cache is valid for the complete requested area paint.drawImage(rect, m_cache.getImage(), rect); - return { rect, {} }; + + //!!! a dev debug check + if (!m_magCache.areColumnsSet(x0, x1 - x0)) { + cerr << "Columns (" << x0 << " -> " << x1-x0 + << ") not set in mag cache" << endl; + throw std::logic_error("Columns not set in mag cache"); + } + + MagnitudeRange range = m_magCache.getRange(x0, x1-x0); + + return { rect, range }; } else { cerr << "cache partial hit" << endl; @@ -121,6 +134,7 @@ // contain the complete view, but might be scrollable or // partially usable m_cache.scrollTo(v, startFrame); + m_magCache.scrollTo(v, startFrame); // if we are not time-constrained, then we want to paint // the whole area in one go; we don't return a partial @@ -138,6 +152,7 @@ } else { // cache is completely invalid m_cache.setStartFrame(startFrame); + m_magCache.setStartFrame(startFrame); } bool rightToLeft = false;
--- a/layer/Colour3DPlotRenderer.h Wed Jul 20 08:30:20 2016 +0100 +++ b/layer/Colour3DPlotRenderer.h Wed Jul 20 08:42:04 2016 +0100 @@ -18,6 +18,7 @@ #include "ColourScale.h" #include "ScrollableImageCache.h" +#include "ScrollableMagRangeCache.h" #include "base/ColumnOp.h" #include "base/MagnitudeRange.h" @@ -183,15 +184,24 @@ // member is to avoid reallocation. QImage m_drawBuffer; - // Image cache is our persistent record of the visible area. It is - // always the same size as the view (i.e. the paint size reported - // by the LayerGeometryProvider) and is scrolled and partially - // repainted internally as appropriate. A render request is - // carried out by repainting to cache (via the draw buffer) any + // The image cache is our persistent record of the visible + // area. It is always the same size as the view (i.e. the paint + // size reported by the LayerGeometryProvider) and is scrolled and + // partially repainted internally as appropriate. A render request + // is carried out by repainting to cache (via the draw buffer) any // area that is being requested but is not valid in the cache, and // then repainting from cache to the requested painter. ScrollableImageCache m_cache; + // The mag range cache is our record of the column magnitude + // ranges for each of the columns in the cache. It always has the + // same start frame and width as the image cache, and the column + // indices match up across both. Our cache update mechanism + // guarantees that every valid column in the image cache has a + // valid range in the magnitude cache, but not necessarily vice + // versa (as the image cache is limited to contiguous ranges). + ScrollableMagRangeCache m_magCache; + RenderResult render(const LayerGeometryProvider *v, QPainter &paint, QRect rect, bool timeConstrained);
--- a/layer/ScrollableMagRangeCache.h Wed Jul 20 08:30:20 2016 +0100 +++ b/layer/ScrollableMagRangeCache.h Wed Jul 20 08:42:04 2016 +0100 @@ -95,12 +95,33 @@ bool isColumnSet(int column) const { return in_range_for(m_ranges, column) && m_ranges.at(column).isSet(); } + + bool areColumnsSet(int x, int count) const { + for (int i = 0; i < count; ++i) { + if (!isColumnSet(x + i)) return false; + } + return true; + } - const MagnitudeRange &getRange(int column) const { + /** + * Get the magnitude range for a single column. + */ + MagnitudeRange getRange(int column) const { return m_ranges.at(column); } /** + * Get the magnitude range for a range of columns. + */ + MagnitudeRange getRange(int x, int count) const { + MagnitudeRange r; + for (int i = 0; i < count; ++i) { + r.sample(m_ranges.at(x + i)); + } + return r; + } + + /** * Set the new start frame for the cache, according to the * geometry of the supplied LayerGeometryProvider, if possible * also moving along any existing valid data within the cache so