Mercurial > hg > svgui
changeset 1136:9ff838a64461 spectrogram-minor-refactor
Re-enable (little-used) normalise-visible-range option in spectrogram layer
author | Chris Cannam |
---|---|
date | Wed, 03 Aug 2016 16:16:23 +0100 |
parents | 628cd329c241 |
children | 4e7ed3252d80 |
files | layer/Colour3DPlotRenderer.cpp layer/ScrollableMagRangeCache.cpp layer/SpectrogramLayer.cpp layer/SpectrogramLayer.h |
diffstat | 4 files changed, 56 insertions(+), 29 deletions(-) [+] |
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp Wed Aug 03 14:20:27 2016 +0100 +++ b/layer/Colour3DPlotRenderer.cpp Wed Aug 03 16:16:23 2016 +0100 @@ -674,19 +674,24 @@ sourceLeft = 0; } - int sourceWidth = targetWidth; - cerr << "repaintWidth = " << repaintWidth << ", targetWidth = " << targetWidth << endl; if (targetWidth > 0) { + // we are copying from an image that has already been scaled, + // hence using the same width in both geometries m_cache.drawImage(targetLeft, targetWidth, scaled, - sourceLeft, sourceWidth); + sourceLeft, targetWidth); } for (int i = 0; i < targetWidth; ++i) { - int sourceIx = int((double(i) / targetWidth) * sourceWidth); + // but the mag range vector has not been scaled + int sourceIx = int((double(i + sourceLeft) / scaled.width()) + * int(m_magRanges.size())); +// int sourceIx = int((double(i) / targetWidth) * sourceWidth); + cerr << "mag range target ix = " << i << ", source ix = " + << sourceIx << ", of " << m_magRanges.size() << endl; if (in_range_for(m_magRanges, sourceIx)) { m_magCache.sampleColumn(i, m_magRanges.at(sourceIx)); } @@ -787,8 +792,8 @@ ColumnOp::Column fullColumn = sourceModel->getColumn(sx); - cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size() - << ", minbin " << minbin << ", nbins " << nbins << endl; +// cerr << "x " << x << ", sx " << sx << ", col height " << fullColumn.size() +// << ", minbin " << minbin << ", nbins " << nbins << endl; ColumnOp::Column column = vector<float>(fullColumn.data() + minbin,
--- a/layer/ScrollableMagRangeCache.cpp Wed Aug 03 14:20:27 2016 +0100 +++ b/layer/ScrollableMagRangeCache.cpp Wed Aug 03 16:16:23 2016 +0100 @@ -76,11 +76,11 @@ m_ranges = newRanges; } -//!!! cerr << "maxes now: "; -// for (int i = 0; in_range_for(m_ranges, i); ++i) { -// cerr << m_ranges[i].getMax() << " "; -// } -// cerr << endl; + cerr << "maxes (" << m_ranges.size() << ") now: "; + for (int i = 0; in_range_for(m_ranges, i); ++i) { + cerr << m_ranges[i].getMax() << " "; + } + cerr << endl; } MagnitudeRange
--- a/layer/SpectrogramLayer.cpp Wed Aug 03 14:20:27 2016 +0100 +++ b/layer/SpectrogramLayer.cpp Wed Aug 03 16:16:23 2016 +0100 @@ -1396,7 +1396,9 @@ Colour3DPlotRenderer * SpectrogramLayer::getRenderer(LayerGeometryProvider *v) const { - if (m_renderers.find(v->getId()) == m_renderers.end()) { + int viewId = v->getId(); + + if (m_renderers.find(viewId) == m_renderers.end()) { Colour3DPlotRenderer::Sources sources; sources.verticalBinLayer = this; @@ -1413,15 +1415,30 @@ cparams.threshold = m_threshold; } - if (m_colourScale == ColourScaleType::Linear && - m_normalization == ColumnNormalization::None) { + float minValue = 0.0f; + float maxValue = 1.0f; + + if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) { + minValue = m_viewMags[viewId].getMin(); + maxValue = m_viewMags[viewId].getMax(); + } else if (m_colourScale == ColourScaleType::Linear && + m_normalization == ColumnNormalization::None) { //!!! This should not be necessary -- what is the actual range - cparams.maxValue = 0.1; - if (cparams.maxValue <= m_threshold) { - cparams.maxValue = m_threshold + 0.1; - } + maxValue = 0.1f; } + if (maxValue <= minValue) { + maxValue = minValue + 0.1f; + } + if (maxValue <= m_threshold) { + maxValue = m_threshold + 0.1f; + } + + cparams.minValue = minValue; + cparams.maxValue = maxValue; + + m_lastRenderedMags[viewId] = MagnitudeRange(minValue, maxValue); + Colour3DPlotRenderer::Parameters params; params.colourScale = ColourScale(cparams); params.normalization = m_normalization; @@ -1457,7 +1474,9 @@ MagnitudeRange magRange; int viewId = v->getId(); - if (!renderer->geometryChanged(v)) { + bool continuingPaint = !renderer->geometryChanged(v); + + if (continuingPaint) { magRange = m_viewMags[viewId]; } @@ -1482,17 +1501,21 @@ magRange.sample(result.range); if (magRange.isSet()) { - if (!(m_viewMags[viewId] == magRange)) { + if (m_viewMags[viewId] != magRange) { m_viewMags[viewId] = magRange; - //!!! now need to do the normalise-visible thing + cerr << "mag range in this view has changed: " + << magRange.getMin() << " -> " << magRange.getMax() << endl; } } - - cerr << "mag range in this view: " - << m_viewMags[viewId].getMin() - << " -> " - << m_viewMags[viewId].getMax() - << endl; + + if (!continuingPaint && m_normalizeVisibleArea && + m_viewMags[viewId] != m_lastRenderedMags[viewId]) { + cerr << "mag range has changed from last rendered range: re-rendering" + << endl; + delete m_renderers[viewId]; + m_renderers.erase(viewId); + v->updatePaintRect(v->getPaintRect()); + } } void
--- a/layer/SpectrogramLayer.h Wed Aug 03 14:20:27 2016 +0100 +++ b/layer/SpectrogramLayer.h Wed Aug 03 16:16:23 2016 +0100 @@ -300,9 +300,8 @@ typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id mutable ViewMagMap m_viewMags; -//!!! mutable std::vector<MagnitudeRange> m_columnMags; + mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode void invalidateMagnitudes(); -//!!! bool updateViewMagnitudes(LayerGeometryProvider *v) const; typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id mutable ViewRendererMap m_renderers;