changeset 1453:39f1154c0e97 single-point

Smoother cache & colour management in colour 3d plots
author Chris Cannam
date Thu, 09 May 2019 13:42:18 +0100
parents 8b7f797bca86
children 4a6ca97ce783
files layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h
diffstat 2 files changed, 25 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Fri May 03 17:45:39 2019 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Thu May 09 13:42:18 2019 +0100
@@ -147,9 +147,10 @@
 
     connectSignals(m_model);
 
-    connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged()));
+    connect(m_model, SIGNAL(modelChanged()),
+            this, SLOT(handleModelChanged()));
     connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)),
-            this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t)));
+            this, SLOT(handleModelChangedWithin(sv_frame_t, sv_frame_t)));
 
     m_peakResolution = 256;
     if (model->getResolution() > 512) {
@@ -160,35 +161,22 @@
         m_peakResolution = 128;
     }
 
-    if (m_peakCache) m_peakCache->aboutToDelete();
-    delete m_peakCache;
-    m_peakCache = nullptr;
-
-    invalidateRenderers();
-    invalidateMagnitudes();
+    invalidatePeakCache();
 
     emit modelReplaced();
     emit sliceableModelReplaced(oldModel, model);
 }
 
 void
-Colour3DPlotLayer::cacheInvalid()
+Colour3DPlotLayer::invalidatePeakCache()
 {
+    // renderers use the peak cache, so we must invalidate those too
     invalidateRenderers();
     invalidateMagnitudes();
-}
-
-void
-Colour3DPlotLayer::cacheInvalid(sv_frame_t /* startFrame */,
-                                sv_frame_t /* endFrame */)
-{
-    //!!! should do this only if the range is visible
+    
     if (m_peakCache) m_peakCache->aboutToDelete();
     delete m_peakCache;
     m_peakCache = nullptr;
-    
-    invalidateRenderers();
-    invalidateMagnitudes();
 }
 
 void
@@ -220,7 +208,7 @@
 }
 
 void
-Colour3DPlotLayer::modelChanged()
+Colour3DPlotLayer::handleModelChanged()
 {
     if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
         if (m_model) {
@@ -231,11 +219,12 @@
             }
         }
     }
-    cacheInvalid();
+    invalidatePeakCache();
+    emit modelChanged();
 }
 
 void
-Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
+Colour3DPlotLayer::handleModelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame)
 {
     if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) {
         if (m_model && m_model->getWidth() > 50) {
@@ -246,7 +235,7 @@
             }
         }
     }
-    cacheInvalid(startFrame, endFrame);
+    emit modelChangedWithin(startFrame, endFrame);
 }
 
 Layer::PropertyList
@@ -620,6 +609,13 @@
     return m_smooth;
 }
 
+bool
+Colour3DPlotLayer::hasLightBackground() const 
+{
+    return ColourMapper(m_colourMap, m_colourInverted, 1.f, 255.f)
+        .hasLightBackground();
+}
+
 void
 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant)
 {
@@ -636,7 +632,7 @@
 
         Layer::setLayerDormant(v, true);
 
-        cacheInvalid();
+        invalidatePeakCache(); // for memory-saving purposes
         
     } else {
 
--- a/layer/Colour3DPlotLayer.h	Fri May 03 17:45:39 2019 +0100
+++ b/layer/Colour3DPlotLayer.h	Thu May 09 13:42:18 2019 +0100
@@ -129,6 +129,8 @@
     void setSmooth(bool i);
     bool getSmooth() const;
 
+    bool hasLightBackground() const override;
+
     bool getValueExtents(double &min, double &max,
                                  bool &logarithmic, QString &unit) const override;
 
@@ -149,10 +151,8 @@
                        QString extraAttributes = "") const override;
 
 protected slots:
-    void cacheInvalid();
-    void cacheInvalid(sv_frame_t startFrame, sv_frame_t endFrame);
-    void modelChanged();
-    void modelChangedWithin(sv_frame_t, sv_frame_t);
+    void handleModelChanged();
+    void handleModelChangedWithin(sv_frame_t, sv_frame_t);
 
 protected:
     const DenseThreeDimensionalModel *m_model; // I do not own this
@@ -185,6 +185,7 @@
     mutable Dense3DModelPeakCache *m_peakCache;
     const int m_peakCacheDivisor;
     Dense3DModelPeakCache *getPeakCache() const;
+    void invalidatePeakCache();
 
     typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id
     mutable ViewMagMap m_viewMags;