Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1362:d79e21855aef
Add mechanism for saving/loading colour maps by name/id rather than by numerical index, for future compatibility when adding to or changing the supported colour maps. Add two new colour maps (and one old one). Write out backward-compatible numerical indices for use when reloading in older versions. Also add a mechanism to invert the colour map, though I don't think it turns out useful enough to include in the UI.
author | Chris Cannam |
---|---|
date | Thu, 18 Oct 2018 13:21:56 +0100 |
parents | a34a2a25907c |
children | a1393b4384a5 |
comparison
equal
deleted
inserted
replaced
1361:2e3b3fadba27 | 1362:d79e21855aef |
---|---|
45 Colour3DPlotLayer::Colour3DPlotLayer() : | 45 Colour3DPlotLayer::Colour3DPlotLayer() : |
46 m_model(0), | 46 m_model(0), |
47 m_colourScale(ColourScaleType::Linear), | 47 m_colourScale(ColourScaleType::Linear), |
48 m_colourScaleSet(false), | 48 m_colourScaleSet(false), |
49 m_colourMap(0), | 49 m_colourMap(0), |
50 m_colourInverted(false), | |
50 m_gain(1.0), | 51 m_gain(1.0), |
51 m_binScale(BinScale::Linear), | 52 m_binScale(BinScale::Linear), |
52 m_normalization(ColumnNormalization::None), | 53 m_normalization(ColumnNormalization::None), |
53 m_normalizeVisibleArea(false), | 54 m_normalizeVisibleArea(false), |
54 m_invertVertical(false), | 55 m_invertVertical(false), |
392 QString | 393 QString |
393 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name, | 394 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name, |
394 int value) const | 395 int value) const |
395 { | 396 { |
396 if (name == "Colour") { | 397 if (name == "Colour") { |
397 return ColourMapper::getColourMapName(value); | 398 return ColourMapper::getColourMapLabel(value); |
398 } | 399 } |
399 if (name == "Colour Scale") { | 400 if (name == "Colour Scale") { |
400 switch (value) { | 401 switch (value) { |
401 default: | 402 default: |
402 case 0: return tr("Linear"); | 403 case 0: return tr("Linear"); |
822 | 823 |
823 if (sy < 0 || sy >= m_model->getHeight()) { | 824 if (sy < 0 || sy >= m_model->getHeight()) { |
824 return ""; | 825 return ""; |
825 } | 826 } |
826 | 827 |
827 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; | 828 if (m_invertVertical) { |
829 sy = m_model->getHeight() - sy - 1; | |
830 } | |
828 | 831 |
829 float value = m_model->getValueAt(sx0, sy); | 832 float value = m_model->getValueAt(sx0, sy); |
830 | 833 |
831 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl; | 834 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl; |
832 | 835 |
977 } | 980 } |
978 | 981 |
979 if (i > symin) { | 982 if (i > symin) { |
980 | 983 |
981 int idx = i - 1; | 984 int idx = i - 1; |
982 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; | 985 if (m_invertVertical) { |
986 idx = m_model->getHeight() - idx - 1; | |
987 } | |
983 | 988 |
984 QString text = m_model->getBinName(idx); | 989 QString text = m_model->getBinName(idx); |
985 if (text == "") text = QString("[%1]").arg(idx + 1); | 990 if (text == "") text = QString("[%1]").arg(idx + 1); |
986 | 991 |
987 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + | 992 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + |
1007 sources.source = m_model; | 1012 sources.source = m_model; |
1008 sources.peakCaches.push_back(getPeakCache()); | 1013 sources.peakCaches.push_back(getPeakCache()); |
1009 | 1014 |
1010 ColourScale::Parameters cparams; | 1015 ColourScale::Parameters cparams; |
1011 cparams.colourMap = m_colourMap; | 1016 cparams.colourMap = m_colourMap; |
1017 cparams.inverted = m_colourInverted; | |
1012 cparams.scaleType = m_colourScale; | 1018 cparams.scaleType = m_colourScale; |
1013 cparams.gain = m_gain; | 1019 cparams.gain = m_gain; |
1014 | 1020 |
1015 double minValue = 0.0; | 1021 double minValue = 0.0; |
1016 double maxValue = 1.0; | 1022 double maxValue = 1.0; |
1025 minValue = m_model->getMinimumLevel(); | 1031 minValue = m_model->getMinimumLevel(); |
1026 maxValue = m_model->getMaximumLevel(); | 1032 maxValue = m_model->getMaximumLevel(); |
1027 } | 1033 } |
1028 | 1034 |
1029 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is " | 1035 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is " |
1030 << minValue << " -> " << maxValue << endl; | 1036 << minValue << " -> " << maxValue |
1037 << " (model min = " << m_model->getMinimumLevel() | |
1038 << ", max = " << m_model->getMaximumLevel() << ")" | |
1039 << endl; | |
1031 | 1040 |
1032 if (maxValue <= minValue) { | 1041 if (maxValue <= minValue) { |
1033 maxValue = minValue + 0.1f; | 1042 maxValue = minValue + 0.1f; |
1034 } | 1043 } |
1035 | 1044 |
1170 void | 1179 void |
1171 Colour3DPlotLayer::toXml(QTextStream &stream, | 1180 Colour3DPlotLayer::toXml(QTextStream &stream, |
1172 QString indent, QString extraAttributes) const | 1181 QString indent, QString extraAttributes) const |
1173 { | 1182 { |
1174 QString s = QString("scale=\"%1\" " | 1183 QString s = QString("scale=\"%1\" " |
1175 "colourScheme=\"%2\" " | 1184 "minY=\"%2\" " |
1176 "minY=\"%3\" " | 1185 "maxY=\"%3\" " |
1177 "maxY=\"%4\" " | 1186 "invertVertical=\"%4\" " |
1178 "invertVertical=\"%5\" " | 1187 "opaque=\"%5\" %6") |
1179 "opaque=\"%6\" %7") | |
1180 .arg(convertFromColourScale(m_colourScale)) | 1188 .arg(convertFromColourScale(m_colourScale)) |
1181 .arg(m_colourMap) | |
1182 .arg(m_miny) | 1189 .arg(m_miny) |
1183 .arg(m_maxy) | 1190 .arg(m_maxy) |
1184 .arg(m_invertVertical ? "true" : "false") | 1191 .arg(m_invertVertical ? "true" : "false") |
1185 .arg(m_opaque ? "true" : "false") | 1192 .arg(m_opaque ? "true" : "false") |
1186 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") | 1193 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") |
1187 .arg(int(m_binScale)) | 1194 .arg(int(m_binScale)) |
1188 .arg(m_smooth ? "true" : "false") | 1195 .arg(m_smooth ? "true" : "false") |
1189 .arg(m_gain)); | 1196 .arg(m_gain)); |
1197 | |
1198 // New-style colour map attribute, by string id rather than by | |
1199 // number | |
1200 | |
1201 s += QString("colourMap=\"%1\" ") | |
1202 .arg(ColourMapper::getColourMapId(m_colourMap)); | |
1203 | |
1204 // Old-style colour map attribute | |
1205 | |
1206 s += QString("colourScheme=\"%1\" ") | |
1207 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap)); | |
1190 | 1208 |
1191 // New-style normalization attributes, allowing for more types of | 1209 // New-style normalization attributes, allowing for more types of |
1192 // normalization in future: write out the column normalization | 1210 // normalization in future: write out the column normalization |
1193 // type separately, and then whether we are normalizing visible | 1211 // type separately, and then whether we are normalizing visible |
1194 // area as well afterwards | 1212 // area as well afterwards |
1217 | 1235 |
1218 ColourScaleType colourScale = convertToColourScale | 1236 ColourScaleType colourScale = convertToColourScale |
1219 (attributes.value("scale").toInt(&ok)); | 1237 (attributes.value("scale").toInt(&ok)); |
1220 if (ok) setColourScale(colourScale); | 1238 if (ok) setColourScale(colourScale); |
1221 | 1239 |
1222 int colourMap = attributes.value("colourScheme").toInt(&ok); | 1240 QString colourMapId = attributes.value("colourMap"); |
1223 if (ok) setColourMap(colourMap); | 1241 int colourMap = ColourMapper::getColourMapById(colourMapId); |
1242 if (colourMap >= 0) { | |
1243 setColourMap(colourMap); | |
1244 } else { | |
1245 colourMap = attributes.value("colourScheme").toInt(&ok); | |
1246 if (ok && colourMap < ColourMapper::getColourMapCount()) { | |
1247 setColourMap(colourMap); | |
1248 } | |
1249 } | |
1224 | 1250 |
1225 BinScale binScale = (BinScale) | 1251 BinScale binScale = (BinScale) |
1226 attributes.value("binScale").toInt(&ok); | 1252 attributes.value("binScale").toInt(&ok); |
1227 if (ok) setBinScale(binScale); | 1253 if (ok) setBinScale(binScale); |
1228 | 1254 |