changeset 1100:102f986ec032 spectrogram-minor-refactor

Create, but don't yet use, a renderer in the colour 3d plot layer
author Chris Cannam
date Wed, 13 Jul 2016 13:06:28 +0100
parents 5c6271734790
children 1364cbf4453d
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h layer/Colour3DPlotRenderer.cpp layer/Colour3DPlotRenderer.h
diffstat 4 files changed, 71 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Wed Jul 13 10:00:21 2016 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Wed Jul 13 13:06:28 2016 +0100
@@ -23,6 +23,8 @@
 #include "LayerGeometryProvider.h"
 #include "PaintAssistant.h"
 
+#include "data/model/Dense3DModelPeakCache.h"
+
 #include "view/ViewManager.h"
 
 #include <QPainter>
@@ -61,7 +63,9 @@
     m_smooth(false),
     m_peakResolution(256),
     m_miny(0),
-    m_maxy(0)
+    m_maxy(0),
+    m_peakCache(0),
+    m_peakCacheDivisor(8)
 {
     QSettings settings;
     settings.beginGroup("Preferences");
@@ -72,7 +76,8 @@
 Colour3DPlotLayer::~Colour3DPlotLayer()
 {
     delete m_cache;
-    delete m_peaksCache;
+    delete m_peaksCache; //!!! this one is to go...
+    delete m_peakCache;
 }
 
 void
@@ -97,6 +102,10 @@
     } else if (model->getResolution() > 2) {
         m_peakResolution = 128;
     }
+
+    delete m_peakCache;
+    m_peakCache = 0;
+
     cacheInvalid();
 
     emit modelReplaced();
@@ -106,6 +115,8 @@
 void
 Colour3DPlotLayer::cacheInvalid()
 {
+    //!!! to go
+    
     delete m_cache;
     delete m_peaksCache;
     m_cache = 0;
@@ -117,6 +128,8 @@
 void
 Colour3DPlotLayer::cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame)
 {
+    //!!! to go
+    
     if (!m_cache || !m_model) return;
 
     int modelResolution = m_model->getResolution();
@@ -127,6 +140,15 @@
     if (m_cacheValidStart > m_cacheValidEnd) m_cacheValidEnd = m_cacheValidStart;
 }
 
+Dense3DModelPeakCache *
+Colour3DPlotLayer::getPeakCache() const
+{
+    if (!m_peakCache) {
+        m_peakCache = new Dense3DModelPeakCache(m_model, m_peakCacheDivisor);
+    }
+    return m_peakCache;
+}
+
 void
 Colour3DPlotLayer::modelChanged()
 {
@@ -1265,6 +1287,36 @@
     return false;
 }
 
+Colour3DPlotRenderer *
+Colour3DPlotLayer::getRenderer(LayerGeometryProvider *v) const
+{
+    if (m_renderers.find(v->getId()) == m_renderers.end()) {
+
+        Colour3DPlotRenderer::Sources sources;
+        sources.verticalBinLayer = this;
+        sources.fft = 0;
+        sources.source = m_model;
+        sources.peaks = getPeakCache();
+
+        ColourScale::Parameters cparams;
+        cparams.colourMap = m_colourMap;
+        cparams.scale = m_colourScale;
+        cparams.gain = m_gain;
+
+        Colour3DPlotRenderer::Parameters params;
+        params.colourScale = ColourScale(cparams);
+        params.normalization = m_normalization;
+        params.binScale = m_binScale;
+        params.alwaysOpaque = m_opaque;
+        params.invertVertical = m_invertVertical;
+        params.interpolate = m_smooth;
+
+        m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params);
+    }
+
+    return m_renderers[v->getId()];
+}
+
 void
 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
 {
--- a/layer/Colour3DPlotLayer.h	Wed Jul 13 10:00:21 2016 +0100
+++ b/layer/Colour3DPlotLayer.h	Wed Jul 13 13:06:28 2016 +0100
@@ -171,7 +171,15 @@
     // always snap to whole bins at view edges.
     int         m_miny;
     int         m_maxy;
-    
+
+    mutable Dense3DModelPeakCache *m_peakCache;
+    const int m_peakCacheDivisor;
+    Dense3DModelPeakCache *getPeakCache() const;
+
+    typedef std::map<int, Colour3DPlotRenderer *> ViewRendererMap; // key is view id
+    mutable ViewRendererMap m_renderers;
+    Colour3DPlotRenderer *getRenderer(LayerGeometryProvider *) const;
+        
     /**
      * Return the y coordinate at which the given bin "starts"
      * (i.e. at the bottom of the bin, if the given bin is an integer
--- a/layer/Colour3DPlotRenderer.cpp	Wed Jul 13 10:00:21 2016 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Wed Jul 13 13:06:28 2016 +0100
@@ -215,7 +215,7 @@
 bool
 Colour3DPlotRenderer::useBinResolutionForDrawBuffer(LayerGeometryProvider *v) const
 {
-    DenseThreeDimensionalModel *model = m_sources.source;
+    const DenseThreeDimensionalModel *model = m_sources.source;
     if (!model) return false;
     int binResolution = model->getResolution();
     int zoomLevel = v->getZoomLevel();
@@ -234,7 +234,7 @@
     // buffer is at the same resolution as the target in the cache, so
     // no extra scaling needed.
 
-    DenseThreeDimensionalModel *model = m_sources.source;
+    const DenseThreeDimensionalModel *model = m_sources.source;
     if (!model || !model->isOK() || !model->isReady()) {
 	throw std::logic_error("no source model provided, or model not ready");
     }
@@ -324,7 +324,7 @@
     // buffer is at bin resolution, i.e. buffer x == source column
     // number. We use toolkit smooth scaling for interpolation.
 
-    DenseThreeDimensionalModel *model = m_sources.source;
+    const DenseThreeDimensionalModel *model = m_sources.source;
     if (!model || !model->isOK() || !model->isReady()) {
 	throw std::logic_error("no source model provided, or model not ready");
     }
@@ -465,7 +465,7 @@
     if (maxbin < 0) maxbin = minbin+1;
 
     int divisor = 1;
-    DenseThreeDimensionalModel *sourceModel = m_sources.source;
+    const DenseThreeDimensionalModel *sourceModel = m_sources.source;
     if (usePeaksCache) {
         divisor = m_sources.peaks->getColumnsPerPeak();
         sourceModel = m_sources.peaks;
@@ -610,7 +610,7 @@
     if (minbin < 0) minbin = 0;
     if (maxbin < 0) maxbin = minbin+1;
 
-    FFTModel *fft = m_sources.fft;
+    const FFTModel *fft = m_sources.fft;
 
     FFTModel::PeakSet peakfreqs;
 
--- a/layer/Colour3DPlotRenderer.h	Wed Jul 13 10:00:21 2016 +0100
+++ b/layer/Colour3DPlotRenderer.h	Wed Jul 13 13:06:28 2016 +0100
@@ -51,9 +51,9 @@
         
         // These must all outlive this class
         const VerticalBinLayer *verticalBinLayer;  // always
-	DenseThreeDimensionalModel *source;        // always
-	Dense3DModelPeakCache *peaks;	           // optionally
-	FFTModel *fft;			           // optionally
+	const DenseThreeDimensionalModel *source;  // always
+	const Dense3DModelPeakCache *peaks;        // optionally
+	const FFTModel *fft;                       // optionally
     };        
 
     struct Parameters {