Mercurial > hg > svgui
diff layer/Colour3DPlotLayer.cpp @ 1566:1f80a514ce29
Merge from branch spectrogram-export
author | Chris Cannam |
---|---|
date | Fri, 10 Jan 2020 14:54:27 +0000 |
parents | 563bab925c9b |
children | 5f6fdd525158 |
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp Fri Nov 22 14:12:50 2019 +0000 +++ b/layer/Colour3DPlotLayer.cpp Fri Jan 10 14:54:27 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<Colour3DPlotExporter>(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<DenseThreeDimensionalModel>(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<Colour3DPlotExporter>(sources, params)); + m_exporters.push_back(exporter); + return exporter; +} + +ModelId Colour3DPlotLayer::getPeakCache() const { if (m_peakCache.isNone()) {