comparison layer/SliceLayer.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 51e6125627fa
children 2df1af7ac752
comparison
equal deleted inserted replaced
1361:2e3b3fadba27 1362:d79e21855aef
30 30
31 31
32 SliceLayer::SliceLayer() : 32 SliceLayer::SliceLayer() :
33 m_sliceableModel(0), 33 m_sliceableModel(0),
34 m_colourMap(int(ColourMapper::Ice)), 34 m_colourMap(int(ColourMapper::Ice)),
35 m_colourInverted(false),
35 m_energyScale(dBScale), 36 m_energyScale(dBScale),
36 m_samplingMode(SampleMean), 37 m_samplingMode(SampleMean),
37 m_plotStyle(PlotLines), 38 m_plotStyle(PlotLines),
38 m_binScale(LinearBins), 39 m_binScale(LinearBins),
39 m_normalize(false), 40 m_normalize(false),
467 } 468 }
468 } 469 }
469 470
470 double nx = getXForBin(v, bin0); 471 double nx = getXForBin(v, bin0);
471 472
472 ColourMapper mapper(m_colourMap, 0, 1); 473 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
473 474
474 for (int bin = 0; bin < mh; ++bin) { 475 for (int bin = 0; bin < mh; ++bin) {
475 476
476 double x = nx; 477 double x = nx;
477 nx = getXForBin(v, bin + bin0 + 1); 478 nx = getXForBin(v, bin + bin0 + 1);
578 579
579 bool 580 bool
580 SliceLayer::hasLightBackground() const 581 SliceLayer::hasLightBackground() const
581 { 582 {
582 if (usesSolidColour()) { 583 if (usesSolidColour()) {
583 ColourMapper mapper(m_colourMap, 0, 1); 584 ColourMapper mapper(m_colourMap, m_colourInverted, 0, 1);
584 return mapper.hasLightBackground(); 585 return mapper.hasLightBackground();
585 } else { 586 } else {
586 return SingleColourLayer::hasLightBackground(); 587 return SingleColourLayer::hasLightBackground();
587 } 588 }
588 } 589 }
740 QString 741 QString
741 SliceLayer::getPropertyValueLabel(const PropertyName &name, 742 SliceLayer::getPropertyValueLabel(const PropertyName &name,
742 int value) const 743 int value) const
743 { 744 {
744 if (name == "Colour" && usesSolidColour()) { 745 if (name == "Colour" && usesSolidColour()) {
745 return ColourMapper::getColourMapName(value); 746 return ColourMapper::getColourMapLabel(value);
746 } 747 }
747 if (name == "Scale") { 748 if (name == "Scale") {
748 switch (value) { 749 switch (value) {
749 default: 750 default:
750 case 0: return tr("Linear"); 751 case 0: return tr("Linear");
923 SliceLayer::toXml(QTextStream &stream, 924 SliceLayer::toXml(QTextStream &stream,
924 QString indent, QString extraAttributes) const 925 QString indent, QString extraAttributes) const
925 { 926 {
926 QString s; 927 QString s;
927 928
928 s += QString("colourScheme=\"%1\" " 929 s += QString("energyScale=\"%1\" "
929 "energyScale=\"%2\" " 930 "samplingMode=\"%2\" "
930 "samplingMode=\"%3\" " 931 "plotStyle=\"%3\" "
931 "plotStyle=\"%4\" " 932 "binScale=\"%4\" "
932 "binScale=\"%5\" " 933 "gain=\"%5\" "
933 "gain=\"%6\" " 934 "threshold=\"%6\" "
934 "threshold=\"%7\" " 935 "normalize=\"%7\" %8 ")
935 "normalize=\"%8\" %9")
936 .arg(m_colourMap)
937 .arg(m_energyScale) 936 .arg(m_energyScale)
938 .arg(m_samplingMode) 937 .arg(m_samplingMode)
939 .arg(m_plotStyle) 938 .arg(m_plotStyle)
940 .arg(m_binScale) 939 .arg(m_binScale)
941 .arg(m_gain) 940 .arg(m_gain)
944 .arg(QString("minbin=\"%1\" " 943 .arg(QString("minbin=\"%1\" "
945 "maxbin=\"%2\"") 944 "maxbin=\"%2\"")
946 .arg(m_minbin) 945 .arg(m_minbin)
947 .arg(m_maxbin)); 946 .arg(m_maxbin));
948 947
948 // New-style colour map attribute, by string id rather than by
949 // number
950
951 s += QString("fillColourMap=\"%1\" ")
952 .arg(ColourMapper::getColourMapId(m_colourMap));
953
954 // Old-style colour map attribute
955
956 s += QString("colourScheme=\"%1\" ")
957 .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
958
949 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s); 959 SingleColourLayer::toXml(stream, indent, extraAttributes + " " + s);
950 } 960 }
951 961
952 void 962 void
953 SliceLayer::setProperties(const QXmlAttributes &attributes) 963 SliceLayer::setProperties(const QXmlAttributes &attributes)
962 972
963 SamplingMode mode = (SamplingMode) 973 SamplingMode mode = (SamplingMode)
964 attributes.value("samplingMode").toInt(&ok); 974 attributes.value("samplingMode").toInt(&ok);
965 if (ok) setSamplingMode(mode); 975 if (ok) setSamplingMode(mode);
966 976
967 int colourMap = attributes.value("colourScheme").toInt(&ok); 977 QString colourMapId = attributes.value("fillColourMap");
968 if (ok) setFillColourMap(colourMap); 978 int colourMap = ColourMapper::getColourMapById(colourMapId);
979 if (colourMap >= 0) {
980 setFillColourMap(colourMap);
981 } else {
982 colourMap = attributes.value("colourScheme").toInt(&ok);
983 if (ok && colourMap < ColourMapper::getColourMapCount()) {
984 setFillColourMap(colourMap);
985 }
986 }
969 987
970 PlotStyle s = (PlotStyle) 988 PlotStyle s = (PlotStyle)
971 attributes.value("plotStyle").toInt(&ok); 989 attributes.value("plotStyle").toInt(&ok);
972 if (ok) setPlotStyle(s); 990 if (ok) setPlotStyle(s);
973 991