Mercurial > hg > svgui
changeset 1563:563bab925c9b spectrogram-export
Use Colour3DPlotExporter in line with SpectrogramLayer
author | Chris Cannam |
---|---|
date | Thu, 09 Jan 2020 14:35:55 +0000 |
parents | 3b45788b7804 |
children | 62b7699e5bfe |
files | layer/Colour3DPlotLayer.cpp layer/Colour3DPlotLayer.h |
diffstat | 2 files changed, 65 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- 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<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()) {
--- 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<ModelId> m_exporters; // used, waiting to be released + typedef std::map<int, MagnitudeRange> ViewMagMap; // key is view id mutable ViewMagMap m_viewMags; mutable ViewMagMap m_lastRenderedMags; // when in normalizeVisibleArea mode