Mercurial > hg > svgui
comparison layer/Colour3DPlotLayer.cpp @ 1374:631897ba9fca zoom
Merge from default branch
author | Chris Cannam |
---|---|
date | Tue, 06 Nov 2018 08:59:03 +0000 |
parents | a1393b4384a5 |
children | f08a3b8cdb9d |
comparison
equal
deleted
inserted
replaced
1360:e848ea0850fe | 1374:631897ba9fca |
---|---|
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), |
300 QString | 301 QString |
301 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const | 302 Colour3DPlotLayer::getPropertyGroupName(const PropertyName &name) const |
302 { | 303 { |
303 if (name == "Normalization" || | 304 if (name == "Normalization" || |
304 name == "Colour Scale" || | 305 name == "Colour Scale" || |
305 name == "Gain") return tr("Scale"); | 306 name == "Gain") { |
307 return tr("Scale"); | |
308 } | |
306 if (name == "Bin Scale" || | 309 if (name == "Bin Scale" || |
307 name == "Invert Vertical Scale") return tr("Bins"); | 310 name == "Invert Vertical Scale") { |
311 return tr("Bins"); | |
312 } | |
308 if (name == "Opaque" || | 313 if (name == "Opaque" || |
309 name == "Smooth" || | 314 name == "Smooth" || |
310 name == "Colour") return tr("Colour"); | 315 name == "Colour") { |
316 return tr("Colour"); | |
317 } | |
311 return QString(); | 318 return QString(); |
312 } | 319 } |
313 | 320 |
314 int | 321 int |
315 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name, | 322 Colour3DPlotLayer::getPropertyRangeAndValue(const PropertyName &name, |
359 *deflt = 0; | 366 *deflt = 0; |
360 | 367 |
361 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea); | 368 val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea); |
362 | 369 |
363 } else if (name == "Invert Vertical Scale") { | 370 } else if (name == "Invert Vertical Scale") { |
364 | 371 |
372 *min = 0; | |
373 *max = 1; | |
365 *deflt = 0; | 374 *deflt = 0; |
366 val = (m_invertVertical ? 1 : 0); | 375 val = (m_invertVertical ? 1 : 0); |
367 | 376 |
368 } else if (name == "Bin Scale") { | 377 } else if (name == "Bin Scale") { |
369 | 378 |
372 *deflt = int(BinScale::Linear); | 381 *deflt = int(BinScale::Linear); |
373 val = (int)m_binScale; | 382 val = (int)m_binScale; |
374 | 383 |
375 } else if (name == "Opaque") { | 384 } else if (name == "Opaque") { |
376 | 385 |
386 *min = 0; | |
387 *max = 1; | |
377 *deflt = 0; | 388 *deflt = 0; |
378 val = (m_opaque ? 1 : 0); | 389 val = (m_opaque ? 1 : 0); |
379 | 390 |
380 } else if (name == "Smooth") { | 391 } else if (name == "Smooth") { |
381 | 392 |
393 *min = 0; | |
394 *max = 1; | |
382 *deflt = 0; | 395 *deflt = 0; |
383 val = (m_smooth ? 1 : 0); | 396 val = (m_smooth ? 1 : 0); |
384 | 397 |
385 } else { | 398 } else { |
386 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); | 399 val = Layer::getPropertyRangeAndValue(name, min, max, deflt); |
392 QString | 405 QString |
393 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name, | 406 Colour3DPlotLayer::getPropertyValueLabel(const PropertyName &name, |
394 int value) const | 407 int value) const |
395 { | 408 { |
396 if (name == "Colour") { | 409 if (name == "Colour") { |
397 return ColourMapper::getColourMapName(value); | 410 return ColourMapper::getColourMapLabel(value); |
398 } | 411 } |
399 if (name == "Colour Scale") { | 412 if (name == "Colour Scale") { |
400 switch (value) { | 413 switch (value) { |
401 default: | 414 default: |
402 case 0: return tr("Linear"); | 415 case 0: return tr("Linear"); |
822 | 835 |
823 if (sy < 0 || sy >= m_model->getHeight()) { | 836 if (sy < 0 || sy >= m_model->getHeight()) { |
824 return ""; | 837 return ""; |
825 } | 838 } |
826 | 839 |
827 if (m_invertVertical) sy = m_model->getHeight() - sy - 1; | 840 if (m_invertVertical) { |
841 sy = m_model->getHeight() - sy - 1; | |
842 } | |
828 | 843 |
829 float value = m_model->getValueAt(sx0, sy); | 844 float value = m_model->getValueAt(sx0, sy); |
830 | 845 |
831 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl; | 846 // cerr << "bin value (" << sx0 << "," << sy << ") is " << value << endl; |
832 | 847 |
977 } | 992 } |
978 | 993 |
979 if (i > symin) { | 994 if (i > symin) { |
980 | 995 |
981 int idx = i - 1; | 996 int idx = i - 1; |
982 if (m_invertVertical) idx = m_model->getHeight() - idx - 1; | 997 if (m_invertVertical) { |
998 idx = m_model->getHeight() - idx - 1; | |
999 } | |
983 | 1000 |
984 QString text = m_model->getBinName(idx); | 1001 QString text = m_model->getBinName(idx); |
985 if (text == "") text = QString("[%1]").arg(idx + 1); | 1002 if (text == "") text = QString("[%1]").arg(idx + 1); |
986 | 1003 |
987 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + | 1004 int ty = y0 + (h/2) - (paint.fontMetrics().height()/2) + |
1007 sources.source = m_model; | 1024 sources.source = m_model; |
1008 sources.peakCaches.push_back(getPeakCache()); | 1025 sources.peakCaches.push_back(getPeakCache()); |
1009 | 1026 |
1010 ColourScale::Parameters cparams; | 1027 ColourScale::Parameters cparams; |
1011 cparams.colourMap = m_colourMap; | 1028 cparams.colourMap = m_colourMap; |
1029 cparams.inverted = m_colourInverted; | |
1012 cparams.scaleType = m_colourScale; | 1030 cparams.scaleType = m_colourScale; |
1013 cparams.gain = m_gain; | 1031 cparams.gain = m_gain; |
1014 | 1032 |
1015 double minValue = 0.0; | 1033 double minValue = 0.0; |
1016 double maxValue = 1.0; | 1034 double maxValue = 1.0; |
1025 minValue = m_model->getMinimumLevel(); | 1043 minValue = m_model->getMinimumLevel(); |
1026 maxValue = m_model->getMaximumLevel(); | 1044 maxValue = m_model->getMaximumLevel(); |
1027 } | 1045 } |
1028 | 1046 |
1029 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is " | 1047 SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is " |
1030 << minValue << " -> " << maxValue << endl; | 1048 << minValue << " -> " << maxValue |
1049 << " (model min = " << m_model->getMinimumLevel() | |
1050 << ", max = " << m_model->getMaximumLevel() << ")" | |
1051 << endl; | |
1031 | 1052 |
1032 if (maxValue <= minValue) { | 1053 if (maxValue <= minValue) { |
1033 maxValue = minValue + 0.1f; | 1054 maxValue = minValue + 0.1f; |
1034 } | 1055 } |
1035 | 1056 |
1170 void | 1191 void |
1171 Colour3DPlotLayer::toXml(QTextStream &stream, | 1192 Colour3DPlotLayer::toXml(QTextStream &stream, |
1172 QString indent, QString extraAttributes) const | 1193 QString indent, QString extraAttributes) const |
1173 { | 1194 { |
1174 QString s = QString("scale=\"%1\" " | 1195 QString s = QString("scale=\"%1\" " |
1175 "colourScheme=\"%2\" " | 1196 "minY=\"%2\" " |
1176 "minY=\"%3\" " | 1197 "maxY=\"%3\" " |
1177 "maxY=\"%4\" " | 1198 "invertVertical=\"%4\" " |
1178 "invertVertical=\"%5\" " | 1199 "opaque=\"%5\" %6") |
1179 "opaque=\"%6\" %7") | |
1180 .arg(convertFromColourScale(m_colourScale)) | 1200 .arg(convertFromColourScale(m_colourScale)) |
1181 .arg(m_colourMap) | |
1182 .arg(m_miny) | 1201 .arg(m_miny) |
1183 .arg(m_maxy) | 1202 .arg(m_maxy) |
1184 .arg(m_invertVertical ? "true" : "false") | 1203 .arg(m_invertVertical ? "true" : "false") |
1185 .arg(m_opaque ? "true" : "false") | 1204 .arg(m_opaque ? "true" : "false") |
1186 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") | 1205 .arg(QString("binScale=\"%1\" smooth=\"%2\" gain=\"%3\" ") |
1187 .arg(int(m_binScale)) | 1206 .arg(int(m_binScale)) |
1188 .arg(m_smooth ? "true" : "false") | 1207 .arg(m_smooth ? "true" : "false") |
1189 .arg(m_gain)); | 1208 .arg(m_gain)); |
1209 | |
1210 // New-style colour map attribute, by string id rather than by | |
1211 // number | |
1212 | |
1213 s += QString("colourMap=\"%1\" ") | |
1214 .arg(ColourMapper::getColourMapId(m_colourMap)); | |
1215 | |
1216 // Old-style colour map attribute | |
1217 | |
1218 s += QString("colourScheme=\"%1\" ") | |
1219 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap)); | |
1190 | 1220 |
1191 // New-style normalization attributes, allowing for more types of | 1221 // New-style normalization attributes, allowing for more types of |
1192 // normalization in future: write out the column normalization | 1222 // normalization in future: write out the column normalization |
1193 // type separately, and then whether we are normalizing visible | 1223 // type separately, and then whether we are normalizing visible |
1194 // area as well afterwards | 1224 // area as well afterwards |
1217 | 1247 |
1218 ColourScaleType colourScale = convertToColourScale | 1248 ColourScaleType colourScale = convertToColourScale |
1219 (attributes.value("scale").toInt(&ok)); | 1249 (attributes.value("scale").toInt(&ok)); |
1220 if (ok) setColourScale(colourScale); | 1250 if (ok) setColourScale(colourScale); |
1221 | 1251 |
1222 int colourMap = attributes.value("colourScheme").toInt(&ok); | 1252 QString colourMapId = attributes.value("colourMap"); |
1223 if (ok) setColourMap(colourMap); | 1253 int colourMap = ColourMapper::getColourMapById(colourMapId); |
1254 if (colourMap >= 0) { | |
1255 setColourMap(colourMap); | |
1256 } else { | |
1257 colourMap = attributes.value("colourScheme").toInt(&ok); | |
1258 if (ok && colourMap < ColourMapper::getColourMapCount()) { | |
1259 setColourMap(colourMap); | |
1260 } | |
1261 } | |
1224 | 1262 |
1225 BinScale binScale = (BinScale) | 1263 BinScale binScale = (BinScale) |
1226 attributes.value("binScale").toInt(&ok); | 1264 attributes.value("binScale").toInt(&ok); |
1227 if (ok) setBinScale(binScale); | 1265 if (ok) setBinScale(binScale); |
1228 | 1266 |