comparison layer/Colour3DPlotLayer.cpp @ 1235:dd3901fe8623

Wire up normalise-visible-area mode in colour 3d plot
author Chris Cannam
date Fri, 27 Jan 2017 11:39:42 +0000
parents eaab8bab3522
children 4d0ca1ab4cd0
comparison
equal deleted inserted replaced
1234:81dfe06a45c9 1235:dd3901fe8623
157 157
158 delete m_peakCache; 158 delete m_peakCache;
159 m_peakCache = 0; 159 m_peakCache = 0;
160 160
161 invalidateRenderers(); 161 invalidateRenderers();
162 invalidateMagnitudes();
162 163
163 emit modelReplaced(); 164 emit modelReplaced();
164 emit sliceableModelReplaced(oldModel, model); 165 emit sliceableModelReplaced(oldModel, model);
165 } 166 }
166 167
167 void 168 void
168 Colour3DPlotLayer::cacheInvalid() 169 Colour3DPlotLayer::cacheInvalid()
169 { 170 {
170 invalidateRenderers(); 171 invalidateRenderers();
172 invalidateMagnitudes();
171 } 173 }
172 174
173 void 175 void
174 Colour3DPlotLayer::cacheInvalid(sv_frame_t /* startFrame */, 176 Colour3DPlotLayer::cacheInvalid(sv_frame_t /* startFrame */,
175 sv_frame_t /* endFrame */) 177 sv_frame_t /* endFrame */)
177 //!!! should do this only if the range is visible 179 //!!! should do this only if the range is visible
178 delete m_peakCache; 180 delete m_peakCache;
179 m_peakCache = 0; 181 m_peakCache = 0;
180 182
181 invalidateRenderers(); 183 invalidateRenderers();
184 invalidateMagnitudes();
182 } 185 }
183 186
184 void 187 void
185 Colour3DPlotLayer::invalidateRenderers() 188 Colour3DPlotLayer::invalidateRenderers()
186 { 189 {
187 for (ViewRendererMap::iterator i = m_renderers.begin(); 190 for (ViewRendererMap::iterator i = m_renderers.begin();
188 i != m_renderers.end(); ++i) { 191 i != m_renderers.end(); ++i) {
189 delete i->second; 192 delete i->second;
190 } 193 }
191 m_renderers.clear(); 194 m_renderers.clear();
195 }
196
197 void
198 Colour3DPlotLayer::invalidateMagnitudes()
199 {
200 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
201 cerr << "Colour3DPlotLayer::invalidateMagnitudes called" << endl;
202 #endif
203 m_viewMags.clear();
192 } 204 }
193 205
194 Dense3DModelPeakCache * 206 Dense3DModelPeakCache *
195 Colour3DPlotLayer::getPeakCache() const 207 Colour3DPlotLayer::getPeakCache() const
196 { 208 {
529 void 541 void
530 Colour3DPlotLayer::setNormalizeVisibleArea(bool n) 542 Colour3DPlotLayer::setNormalizeVisibleArea(bool n)
531 { 543 {
532 if (m_normalizeVisibleArea == n) return; 544 if (m_normalizeVisibleArea == n) return;
533 545
546 invalidateRenderers();
547 invalidateMagnitudes();
534 m_normalizeVisibleArea = n; 548 m_normalizeVisibleArea = n;
535 invalidateRenderers();
536 549
537 emit layerParametersChanged(); 550 emit layerParametersChanged();
538 } 551 }
539 552
540 bool 553 bool
613 } 626 }
614 627
615 bool 628 bool
616 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider * /* v */) const 629 Colour3DPlotLayer::isLayerScrollable(const LayerGeometryProvider * /* v */) const
617 { 630 {
618 if (m_normalizeVisibleArea) {
619 return false;
620 }
621 //!!! ah hang on, if we're potentially rendering incrementally
622 //!!! they we can't be scrollable
623 return false; 631 return false;
624 // if (getRenderer(v)->willRenderOpaque(v)) {
625 // return true;
626 // }
627 // QPoint discard;
628 // return !v->shouldIlluminateLocalFeatures(this, discard);
629 } 632 }
630 633
631 bool 634 bool
632 Colour3DPlotLayer::getValueExtents(double &min, double &max, 635 Colour3DPlotLayer::getValueExtents(double &min, double &max,
633 bool &logarithmic, QString &unit) const 636 bool &logarithmic, QString &unit) const
1032 } 1035 }
1033 1036
1034 Colour3DPlotRenderer * 1037 Colour3DPlotRenderer *
1035 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const 1038 Colour3DPlotLayer::getRenderer(const LayerGeometryProvider *v) const
1036 { 1039 {
1037 if (m_renderers.find(v->getId()) == m_renderers.end()) { 1040 int viewId = v->getId();
1041
1042 if (m_renderers.find(viewId) == m_renderers.end()) {
1038 1043
1039 Colour3DPlotRenderer::Sources sources; 1044 Colour3DPlotRenderer::Sources sources;
1040 sources.verticalBinLayer = this; 1045 sources.verticalBinLayer = this;
1041 sources.fft = 0; 1046 sources.fft = 0;
1042 sources.source = m_model; 1047 sources.source = m_model;
1045 ColourScale::Parameters cparams; 1050 ColourScale::Parameters cparams;
1046 cparams.colourMap = m_colourMap; 1051 cparams.colourMap = m_colourMap;
1047 cparams.scaleType = m_colourScale; 1052 cparams.scaleType = m_colourScale;
1048 cparams.gain = m_gain; 1053 cparams.gain = m_gain;
1049 1054
1050 if (m_normalization == ColumnNormalization::None) { 1055 double minValue = 0.0;
1051 cparams.minValue = m_model->getMinimumLevel(); 1056 double maxValue = 1.0;
1052 cparams.maxValue = m_model->getMaximumLevel(); 1057
1058 if (m_normalizeVisibleArea && m_viewMags[viewId].isSet()) {
1059 minValue = m_viewMags[viewId].getMin();
1060 maxValue = m_viewMags[viewId].getMax();
1061 } else if (m_normalization == ColumnNormalization::None) {
1062 minValue = m_model->getMinimumLevel();
1063 maxValue = m_model->getMaximumLevel();
1053 } else if (m_normalization == ColumnNormalization::Hybrid) { 1064 } else if (m_normalization == ColumnNormalization::Hybrid) {
1054 cparams.minValue = 0; 1065 minValue = 0;
1055 cparams.maxValue = log10(m_model->getMaximumLevel() + 1.0); 1066 maxValue = log10(m_model->getMaximumLevel() + 1.0);
1056 } 1067 }
1057 1068
1058 if (cparams.maxValue <= cparams.minValue) { 1069 if (maxValue <= minValue) {
1059 cparams.maxValue = cparams.minValue + 0.1; 1070 maxValue = minValue + 0.1f;
1060 } 1071 }
1072
1073 cparams.minValue = minValue;
1074 cparams.maxValue = maxValue;
1061 1075
1076 m_lastRenderedMags[viewId] = MagnitudeRange(float(minValue),
1077 float(maxValue));
1078
1062 Colour3DPlotRenderer::Parameters params; 1079 Colour3DPlotRenderer::Parameters params;
1063 params.colourScale = ColourScale(cparams); 1080 params.colourScale = ColourScale(cparams);
1064 params.normalization = m_normalization; 1081 params.normalization = m_normalization;
1065 params.binScale = m_binScale; 1082 params.binScale = m_binScale;
1066 params.alwaysOpaque = m_opaque; 1083 params.alwaysOpaque = m_opaque;
1067 params.invertVertical = m_invertVertical; 1084 params.invertVertical = m_invertVertical;
1068 params.interpolate = m_smooth; 1085 params.interpolate = m_smooth;
1069 1086
1070 m_renderers[v->getId()] = new Colour3DPlotRenderer(sources, params); 1087 m_renderers[viewId] = new Colour3DPlotRenderer(sources, params);
1071 } 1088 }
1072 1089
1073 return m_renderers[v->getId()]; 1090 return m_renderers[viewId];
1074 } 1091 }
1075 1092
1076 void 1093 void
1077 Colour3DPlotLayer::paintWithRenderer(LayerGeometryProvider *v, 1094 Colour3DPlotLayer::paintWithRenderer(LayerGeometryProvider *v,
1078 QPainter &paint, QRect rect) const 1095 QPainter &paint, QRect rect) const
1081 1098
1082 Colour3DPlotRenderer::RenderResult result; 1099 Colour3DPlotRenderer::RenderResult result;
1083 MagnitudeRange magRange; 1100 MagnitudeRange magRange;
1084 int viewId = v->getId(); 1101 int viewId = v->getId();
1085 1102
1086 if (!renderer->geometryChanged(v)) { 1103 bool continuingPaint = !renderer->geometryChanged(v);
1104
1105 if (continuingPaint) {
1087 magRange = m_viewMags[viewId]; 1106 magRange = m_viewMags[viewId];
1088 } 1107 }
1089 1108
1090 if (m_synchronous) { 1109 if (m_synchronous) {
1091 1110
1102 } 1121 }
1103 1122
1104 magRange.sample(result.range); 1123 magRange.sample(result.range);
1105 1124
1106 if (magRange.isSet()) { 1125 if (magRange.isSet()) {
1107 if (!(m_viewMags[viewId] == magRange)) { 1126 if (m_viewMags[viewId] != magRange) {
1108 m_viewMags[viewId] = magRange; 1127 m_viewMags[viewId] = magRange;
1109 //!!! now need to do the normalise-visible thing 1128 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1110 } 1129 cerr << "mag range in this view has changed: "
1111 } 1130 << magRange.getMin() << " -> " << magRange.getMax() << endl;
1112 1131 #endif
1113 SVDEBUG << "Colour3DPlotRenderer::paintWithRenderer: mag range in this view: " 1132 }
1114 << m_viewMags[v->getId()].getMin() 1133 }
1115 << " -> " 1134
1116 << m_viewMags[v->getId()].getMax() 1135 if (!continuingPaint && m_normalizeVisibleArea &&
1117 << endl; 1136 m_viewMags[viewId] != m_lastRenderedMags[viewId]) {
1137 #ifdef DEBUG_COLOUR_3D_PLOT_LAYER_PAINT
1138 cerr << "mag range has changed from last rendered range: re-rendering"
1139 << endl;
1140 #endif
1141 delete m_renderers[viewId];
1142 m_renderers.erase(viewId);
1143 v->updatePaintRect(v->getPaintRect());
1144 }
1118 } 1145 }
1119 1146
1120 void 1147 void
1121 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const 1148 Colour3DPlotLayer::paint(LayerGeometryProvider *v, QPainter &paint, QRect rect) const
1122 { 1149 {
1144 cerr << "Colour3DPlotLayer::paint(): model width == 0, " 1171 cerr << "Colour3DPlotLayer::paint(): model width == 0, "
1145 << "nothing to paint (yet)" << endl; 1172 << "nothing to paint (yet)" << endl;
1146 #endif 1173 #endif
1147 return; 1174 return;
1148 } 1175 }
1149
1150 //!!!???
1151
1152 if (m_normalizeVisibleArea) {
1153 rect = v->getPaintRect();
1154 }
1155
1156 //!!! why is the setLayerDormant(false) found here in
1157 //!!! SpectrogramLayer not present in Colour3DPlotLayer?
1158 //!!! unnecessary? vestigial? forgotten?
1159 1176
1160 paintWithRenderer(v, paint, rect); 1177 paintWithRenderer(v, paint, rect);
1161 } 1178 }
1162 1179
1163 bool 1180 bool