diff layer/Colour3DPlotRenderer.cpp @ 1473:886c1cd48f9d by-id

Further layer updates for ModelById
author Chris Cannam
date Tue, 02 Jul 2019 11:49:52 +0100
parents f2525e6cbdf1
children 78d9282519b0
line wrap: on
line diff
--- a/layer/Colour3DPlotRenderer.cpp	Mon Jul 01 14:25:53 2019 +0100
+++ b/layer/Colour3DPlotRenderer.cpp	Tue Jul 02 11:49:52 2019 +0100
@@ -426,7 +426,12 @@
     if (fullColumn.empty()) {
         
         if (peakCacheIndex >= 0) {
-            fullColumn = m_sources.peakCaches[peakCacheIndex]->getColumn(sx);
+            auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
+                (m_sources.peakCaches[peakCacheIndex]);
+            if (!peakCache) {
+                return vector<float>(nbins, 0.f);
+            }                
+            fullColumn = peakCache->getColumn(sx);
         } else {
             auto model = ModelById::getAs<DenseThreeDimensionalModel>
                 (m_sources.source);
@@ -621,7 +626,10 @@
     int binResolution = model->getResolution();
     
     for (int ix = 0; in_range_for(m_sources.peakCaches, ix); ++ix) {
-        int bpp = m_sources.peakCaches[ix]->getColumnsPerPeak();
+        auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
+            (m_sources.peakCaches[ix]);
+        if (!peakCache) continue;
+        int bpp = peakCache->getColumnsPerPeak();
         ZoomLevel equivZoom(ZoomLevel::FramesPerPixel, binResolution * bpp);
 #ifdef DEBUG_COLOUR_PLOT_REPAINT
         SVDEBUG << "getPreferredPeakCache: zoomLevel = " << zoomLevel
@@ -956,14 +964,24 @@
     Profiler profiler("Colour3DPlotRenderer::renderDrawBuffer");
     
     int divisor = 1;
-    auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_sources.source);
-    if (!model) return 0;
+
+    std::shared_ptr<DenseThreeDimensionalModel> sourceModel;
+
+    if (peakCacheIndex >= 0) {
+        auto peakCache = ModelById::getAs<Dense3DModelPeakCache>
+            (m_sources.peakCaches[peakCacheIndex]);
+        if (peakCache) {
+            divisor = peakCache->getColumnsPerPeak();
+            sourceModel = peakCache;
+        }
+    }
+
+    if (!sourceModel) {
+        sourceModel = ModelById::getAs<DenseThreeDimensionalModel>
+            (m_sources.source);
+    }
     
-    const DenseThreeDimensionalModel *sourceModel = model.get();
-    if (peakCacheIndex >= 0) {
-        divisor = m_sources.peakCaches[peakCacheIndex]->getColumnsPerPeak();
-        sourceModel = m_sources.peakCaches[peakCacheIndex];
-    }
+    if (!sourceModel) return 0;
 
 #ifdef DEBUG_COLOUR_PLOT_REPAINT
     SVDEBUG << "renderDrawBuffer: w = " << w << ", h = " << h