Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1453:39f1154c0e97 single-point
Smoother cache & colour management in colour 3d plots
author | Chris Cannam |
---|---|
date | Thu, 09 May 2019 13:42:18 +0100 |
parents | af824022bffd |
children | 11a150e65ee1 |
comparison
equal
deleted
inserted
replaced
1452:8b7f797bca86 | 1453:39f1154c0e97 |
---|---|
145 m_model = model; | 145 m_model = model; |
146 if (!m_model || !m_model->isOK()) return; | 146 if (!m_model || !m_model->isOK()) return; |
147 | 147 |
148 connectSignals(m_model); | 148 connectSignals(m_model); |
149 | 149 |
150 connect(m_model, SIGNAL(modelChanged()), this, SLOT(modelChanged())); | 150 connect(m_model, SIGNAL(modelChanged()), |
151 this, SLOT(handleModelChanged())); | |
151 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), | 152 connect(m_model, SIGNAL(modelChangedWithin(sv_frame_t, sv_frame_t)), |
152 this, SLOT(modelChangedWithin(sv_frame_t, sv_frame_t))); | 153 this, SLOT(handleModelChangedWithin(sv_frame_t, sv_frame_t))); |
153 | 154 |
154 m_peakResolution = 256; | 155 m_peakResolution = 256; |
155 if (model->getResolution() > 512) { | 156 if (model->getResolution() > 512) { |
156 m_peakResolution = 16; | 157 m_peakResolution = 16; |
157 } else if (model->getResolution() > 128) { | 158 } else if (model->getResolution() > 128) { |
158 m_peakResolution = 64; | 159 m_peakResolution = 64; |
159 } else if (model->getResolution() > 2) { | 160 } else if (model->getResolution() > 2) { |
160 m_peakResolution = 128; | 161 m_peakResolution = 128; |
161 } | 162 } |
162 | 163 |
164 invalidatePeakCache(); | |
165 | |
166 emit modelReplaced(); | |
167 emit sliceableModelReplaced(oldModel, model); | |
168 } | |
169 | |
170 void | |
171 Colour3DPlotLayer::invalidatePeakCache() | |
172 { | |
173 // renderers use the peak cache, so we must invalidate those too | |
174 invalidateRenderers(); | |
175 invalidateMagnitudes(); | |
176 | |
163 if (m_peakCache) m_peakCache->aboutToDelete(); | 177 if (m_peakCache) m_peakCache->aboutToDelete(); |
164 delete m_peakCache; | 178 delete m_peakCache; |
165 m_peakCache = nullptr; | 179 m_peakCache = nullptr; |
166 | |
167 invalidateRenderers(); | |
168 invalidateMagnitudes(); | |
169 | |
170 emit modelReplaced(); | |
171 emit sliceableModelReplaced(oldModel, model); | |
172 } | |
173 | |
174 void | |
175 Colour3DPlotLayer::cacheInvalid() | |
176 { | |
177 invalidateRenderers(); | |
178 invalidateMagnitudes(); | |
179 } | |
180 | |
181 void | |
182 Colour3DPlotLayer::cacheInvalid(sv_frame_t /* startFrame */, | |
183 sv_frame_t /* endFrame */) | |
184 { | |
185 //!!! should do this only if the range is visible | |
186 if (m_peakCache) m_peakCache->aboutToDelete(); | |
187 delete m_peakCache; | |
188 m_peakCache = nullptr; | |
189 | |
190 invalidateRenderers(); | |
191 invalidateMagnitudes(); | |
192 } | 180 } |
193 | 181 |
194 void | 182 void |
195 Colour3DPlotLayer::invalidateRenderers() | 183 Colour3DPlotLayer::invalidateRenderers() |
196 { | 184 { |
218 } | 206 } |
219 return m_peakCache; | 207 return m_peakCache; |
220 } | 208 } |
221 | 209 |
222 void | 210 void |
223 Colour3DPlotLayer::modelChanged() | 211 Colour3DPlotLayer::handleModelChanged() |
224 { | 212 { |
225 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { | 213 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { |
226 if (m_model) { | 214 if (m_model) { |
227 if (m_model->shouldUseLogValueScale()) { | 215 if (m_model->shouldUseLogValueScale()) { |
228 setColourScale(ColourScaleType::Log); | 216 setColourScale(ColourScaleType::Log); |
229 } else { | 217 } else { |
230 m_colourScaleSet = true; | 218 m_colourScaleSet = true; |
231 } | 219 } |
232 } | 220 } |
233 } | 221 } |
234 cacheInvalid(); | 222 invalidatePeakCache(); |
235 } | 223 emit modelChanged(); |
236 | 224 } |
237 void | 225 |
238 Colour3DPlotLayer::modelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) | 226 void |
227 Colour3DPlotLayer::handleModelChangedWithin(sv_frame_t startFrame, sv_frame_t endFrame) | |
239 { | 228 { |
240 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { | 229 if (!m_colourScaleSet && m_colourScale == ColourScaleType::Linear) { |
241 if (m_model && m_model->getWidth() > 50) { | 230 if (m_model && m_model->getWidth() > 50) { |
242 if (m_model->shouldUseLogValueScale()) { | 231 if (m_model->shouldUseLogValueScale()) { |
243 setColourScale(ColourScaleType::Log); | 232 setColourScale(ColourScaleType::Log); |
244 } else { | 233 } else { |
245 m_colourScaleSet = true; | 234 m_colourScaleSet = true; |
246 } | 235 } |
247 } | 236 } |
248 } | 237 } |
249 cacheInvalid(startFrame, endFrame); | 238 emit modelChangedWithin(startFrame, endFrame); |
250 } | 239 } |
251 | 240 |
252 Layer::PropertyList | 241 Layer::PropertyList |
253 Colour3DPlotLayer::getProperties() const | 242 Colour3DPlotLayer::getProperties() const |
254 { | 243 { |
618 Colour3DPlotLayer::getSmooth() const | 607 Colour3DPlotLayer::getSmooth() const |
619 { | 608 { |
620 return m_smooth; | 609 return m_smooth; |
621 } | 610 } |
622 | 611 |
612 bool | |
613 Colour3DPlotLayer::hasLightBackground() const | |
614 { | |
615 return ColourMapper(m_colourMap, m_colourInverted, 1.f, 255.f) | |
616 .hasLightBackground(); | |
617 } | |
618 | |
623 void | 619 void |
624 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) | 620 Colour3DPlotLayer::setLayerDormant(const LayerGeometryProvider *v, bool dormant) |
625 { | 621 { |
626 if (dormant) { | 622 if (dormant) { |
627 | 623 |
634 return; | 630 return; |
635 } | 631 } |
636 | 632 |
637 Layer::setLayerDormant(v, true); | 633 Layer::setLayerDormant(v, true); |
638 | 634 |
639 cacheInvalid(); | 635 invalidatePeakCache(); // for memory-saving purposes |
640 | 636 |
641 } else { | 637 } else { |
642 | 638 |
643 Layer::setLayerDormant(v, false); | 639 Layer::setLayerDormant(v, false); |
644 } | 640 } |