# HG changeset patch # User Chris Cannam # Date 1578580555 0 # Node ID 563bab925c9b79c8decdec86fde38c2e48b33b69 # Parent 3b45788b78046e8cf5f5cbeb7e64137ecdcc8a81 Use Colour3DPlotExporter in line with SpectrogramLayer diff -r 3b45788b7804 -r 563bab925c9b layer/Colour3DPlotLayer.cpp --- a/layer/Colour3DPlotLayer.cpp Thu Jan 09 14:35:41 2020 +0000 +++ b/layer/Colour3DPlotLayer.cpp Thu Jan 09 14:35:55 2020 +0000 @@ -22,6 +22,7 @@ #include "ColourMapper.h" #include "LayerGeometryProvider.h" #include "PaintAssistant.h" +#include "Colour3DPlotExporter.h" #include "data/model/Dense3DModelPeakCache.h" @@ -70,6 +71,14 @@ Colour3DPlotLayer::~Colour3DPlotLayer() { invalidateRenderers(); + + for (auto exporterId: m_exporters) { + if (auto exporter = + ModelById::getAs(exporterId)) { + exporter->discardSources(); + } + ModelById::release(exporterId); + } } const ZoomConstraint * @@ -208,6 +217,58 @@ } ModelId +Colour3DPlotLayer::getExportModel(LayerGeometryProvider *v) const +{ + // Creating Colour3DPlotExporters is cheap, so we create one on + // every call - calls probably being infrequent - to avoid having + // to worry about view lifecycles. + + auto model = ModelById::getAs(m_model); + if (!model) return {}; + int viewId = v->getId(); + + Colour3DPlotExporter::Sources sources; + sources.verticalBinLayer = this; + sources.source = m_model; + sources.provider = v; + + double minValue = 0.0; + double maxValue = 1.0; + + if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) { + minValue = m_viewMags[viewId].getMin(); + maxValue = m_viewMags[viewId].getMax(); + } else if (m_normalization == ColumnNormalization::Hybrid) { + minValue = 0; + maxValue = log10(model->getMaximumLevel() + 1.0); + } else if (m_normalization == ColumnNormalization::None) { + minValue = model->getMinimumLevel(); + maxValue = model->getMaximumLevel(); + } + + if (maxValue <= minValue) { + maxValue = minValue + 0.1f; + + if (!(maxValue > minValue)) { // one of them must be NaN or Inf + SVCERR << "WARNING: Colour3DPlotLayer::getExportModel: resetting " + << "minValue and maxValue to zero and one" << endl; + minValue = 0.f; + maxValue = 1.f; + } + } + + Colour3DPlotExporter::Parameters params; + params.threshold = minValue; + params.gain = m_gain; // matching ColourScale in getRenderer + params.normalization = m_normalization; + + ModelId exporter = ModelById::add + (std::make_shared(sources, params)); + m_exporters.push_back(exporter); + return exporter; +} + +ModelId Colour3DPlotLayer::getPeakCache() const { if (m_peakCache.isNone()) { diff -r 3b45788b7804 -r 563bab925c9b layer/Colour3DPlotLayer.h --- a/layer/Colour3DPlotLayer.h Thu Jan 09 14:35:41 2020 +0000 +++ b/layer/Colour3DPlotLayer.h Thu Jan 09 14:35:55 2020 +0000 @@ -48,6 +48,8 @@ ModelId getModel() const override { return m_model; } + ModelId getExportModel(LayerGeometryProvider *) const override; + const ZoomConstraint *getZoomConstraint() const override; void paint(LayerGeometryProvider *v, @@ -192,6 +194,8 @@ void invalidatePeakCache(); ModelId getPeakCache() const; + mutable std::vector m_exporters; // used, waiting to be released + typedef std::map ViewMagMap; // key is view id mutable ViewMagMap m_viewMags; mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode