comparison 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
comparison
equal deleted inserted replaced
1553:76e4302a3fc2 1566:1f80a514ce29
20 #include "base/RangeMapper.h" 20 #include "base/RangeMapper.h"
21 21
22 #include "ColourMapper.h" 22 #include "ColourMapper.h"
23 #include "LayerGeometryProvider.h" 23 #include "LayerGeometryProvider.h"
24 #include "PaintAssistant.h" 24 #include "PaintAssistant.h"
25 #include "Colour3DPlotExporter.h"
25 26
26 #include "data/model/Dense3DModelPeakCache.h" 27 #include "data/model/Dense3DModelPeakCache.h"
27 28
28 #include "view/ViewManager.h" 29 #include "view/ViewManager.h"
29 30
68 } 69 }
69 70
70 Colour3DPlotLayer::~Colour3DPlotLayer() 71 Colour3DPlotLayer::~Colour3DPlotLayer()
71 { 72 {
72 invalidateRenderers(); 73 invalidateRenderers();
74
75 for (auto exporterId: m_exporters) {
76 if (auto exporter =
77 ModelById::getAs<Colour3DPlotExporter>(exporterId)) {
78 exporter->discardSources();
79 }
80 ModelById::release(exporterId);
81 }
73 } 82 }
74 83
75 const ZoomConstraint * 84 const ZoomConstraint *
76 Colour3DPlotLayer::getZoomConstraint() const 85 Colour3DPlotLayer::getZoomConstraint() const
77 { 86 {
203 { 212 {
204 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT 213 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
205 SVDEBUG << "Colour3DPlotLayer::invalidateMagnitudes called" << endl; 214 SVDEBUG << "Colour3DPlotLayer::invalidateMagnitudes called" << endl;
206 #endif 215 #endif
207 m_viewMags.clear(); 216 m_viewMags.clear();
217 }
218
219 ModelId
220 Colour3DPlotLayer::getExportModel(LayerGeometryProvider *v) const
221 {
222 // Creating Colour3DPlotExporters is cheap, so we create one on
223 // every call - calls probably being infrequent - to avoid having
224 // to worry about view lifecycles.
225
226 auto model = ModelById::getAs<DenseThreeDimensionalModel>(m_model);
227 if (!model) return {};
228 int viewId = v->getId();
229
230 Colour3DPlotExporter::Sources sources;
231 sources.verticalBinLayer = this;
232 sources.source = m_model;
233 sources.provider = v;
234
235 double minValue = 0.0;
236 double maxValue = 1.0;
237
238 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
239 minValue = m_viewMags[viewId].getMin();
240 maxValue = m_viewMags[viewId].getMax();
241 } else if (m_normalization == ColumnNormalization::Hybrid) {
242 minValue = 0;
243 maxValue = log10(model->getMaximumLevel() + 1.0);
244 } else if (m_normalization == ColumnNormalization::None) {
245 minValue = model->getMinimumLevel();
246 maxValue = model->getMaximumLevel();
247 }
248
249 if (maxValue <= minValue) {
250 maxValue = minValue + 0.1f;
251
252 if (!(maxValue > minValue)) { // one of them must be NaN or Inf
253 SVCERR << "WARNING: Colour3DPlotLayer::getExportModel: resetting "
254 << "minValue and maxValue to zero and one" << endl;
255 minValue = 0.f;
256 maxValue = 1.f;
257 }
258 }
259
260 Colour3DPlotExporter::Parameters params;
261 params.threshold = minValue;
262 params.gain = m_gain; // matching ColourScale in getRenderer
263 params.normalization = m_normalization;
264
265 ModelId exporter = ModelById::add
266 (std::make_shared<Colour3DPlotExporter>(sources, params));
267 m_exporters.push_back(exporter);
268 return exporter;
208 } 269 }
209 270
210 ModelId 271 ModelId
211 Colour3DPlotLayer::getPeakCache() const 272 Colour3DPlotLayer::getPeakCache() const
212 { 273 {