diff 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
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Fri Oct 05 10:25:52 2018 +0100
+++ b/layer/Colour3DPlotLayer.cpp	Tue Nov 06 08:59:03 2018 +0000
@@ -47,6 +47,7 @@
     m_colourScale(ColourScaleType::Linear),
     m_colourScaleSet(false),
     m_colourMap(0),
+    m_colourInverted(false),
     m_gain(1.0),
     m_binScale(BinScale::Linear),
     m_normalization(ColumnNormalization::None),
@@ -302,12 +303,18 @@
 {
     if (name == "Normalization" ||
         name == "Colour Scale" ||
-        name == "Gain") return tr("Scale");
+        name == "Gain") {
+        return tr("Scale");
+    }
     if (name == "Bin Scale" ||
-        name == "Invert Vertical Scale") return tr("Bins");
+        name == "Invert Vertical Scale") {
+        return tr("Bins");
+    }
     if (name == "Opaque" ||
         name == "Smooth" ||
-        name == "Colour") return tr("Colour");
+        name == "Colour") {
+        return tr("Colour");
+    }
     return QString();
 }
 
@@ -361,7 +368,9 @@
         val = convertFromColumnNorm(m_normalization, m_normalizeVisibleArea);
 
     } else if (name == "Invert Vertical Scale") {
-        
+
+        *min = 0;
+        *max = 1;
         *deflt = 0;
         val = (m_invertVertical ? 1 : 0);
 
@@ -374,11 +383,15 @@
 
     } else if (name == "Opaque") {
         
+        *min = 0;
+        *max = 1;
         *deflt = 0;
         val = (m_opaque ? 1 : 0);
         
     } else if (name == "Smooth") {
         
+        *min = 0;
+        *max = 1;
         *deflt = 0;
         val = (m_smooth ? 1 : 0);
         
@@ -394,7 +407,7 @@
                                     int value) const
 {
     if (name == "Colour") {
-        return ColourMapper::getColourMapName(value);
+        return ColourMapper::getColourMapLabel(value);
     }
     if (name == "Colour Scale") {
         switch (value) {
@@ -824,7 +837,9 @@
         return "";
     }
 
-    if (m_invertVertical) sy = m_model->getHeight() - sy - 1;
+    if (m_invertVertical) {
+        sy = m_model->getHeight() - sy - 1;
+    }
 
     float value = m_model->getValueAt(sx0, sy);
 
@@ -979,7 +994,9 @@
         if (i > symin) {
 
             int idx = i - 1;
-            if (m_invertVertical) idx = m_model->getHeight() - idx - 1;
+            if (m_invertVertical) {
+                idx = m_model->getHeight() - idx - 1;
+            }
 
             QString text = m_model->getBinName(idx);
             if (text == "") text = QString("[%1]").arg(idx + 1);
@@ -1009,6 +1026,7 @@
 
         ColourScale::Parameters cparams;
         cparams.colourMap = m_colourMap;
+        cparams.inverted = m_colourInverted;
         cparams.scaleType = m_colourScale;
         cparams.gain = m_gain;
 
@@ -1027,7 +1045,10 @@
         }
 
         SVDEBUG << "Colour3DPlotLayer: rebuilding renderer, value range is "
-                << minValue << " -> " << maxValue << endl;
+                << minValue << " -> " << maxValue
+                << " (model min = " << m_model->getMinimumLevel()
+                << ", max = " << m_model->getMaximumLevel() << ")"
+                << endl;
         
         if (maxValue <= minValue) {
             maxValue = minValue + 0.1f;
@@ -1172,13 +1193,11 @@
                          QString indent, QString extraAttributes) const
 {
     QString s = QString("scale=\"%1\" "
-                        "colourScheme=\"%2\" "
-                        "minY=\"%3\" "
-                        "maxY=\"%4\" "
-                        "invertVertical=\"%5\" "
-                        "opaque=\"%6\" %7")
+                        "minY=\"%2\" "
+                        "maxY=\"%3\" "
+                        "invertVertical=\"%4\" "
+                        "opaque=\"%5\" %6")
         .arg(convertFromColourScale(m_colourScale))
-        .arg(m_colourMap)
         .arg(m_miny)
         .arg(m_maxy)
         .arg(m_invertVertical ? "true" : "false")
@@ -1187,6 +1206,17 @@
              .arg(int(m_binScale))
              .arg(m_smooth ? "true" : "false")
              .arg(m_gain));
+
+    // New-style colour map attribute, by string id rather than by
+    // number
+
+    s += QString("colourMap=\"%1\" ")
+        .arg(ColourMapper::getColourMapId(m_colourMap));
+
+    // Old-style colour map attribute
+
+    s += QString("colourScheme=\"%1\" ")
+        .arg(ColourMapper::getBackwardCompatibilityColourMap(m_colourMap));
     
     // New-style normalization attributes, allowing for more types of
     // normalization in future: write out the column normalization
@@ -1219,8 +1249,16 @@
         (attributes.value("scale").toInt(&ok));
     if (ok) setColourScale(colourScale);
 
-    int colourMap = attributes.value("colourScheme").toInt(&ok);
-    if (ok) setColourMap(colourMap);
+    QString colourMapId = attributes.value("colourMap");
+    int colourMap = ColourMapper::getColourMapById(colourMapId);
+    if (colourMap >= 0) {
+        setColourMap(colourMap);
+    } else {
+        colourMap = attributes.value("colourScheme").toInt(&ok);
+        if (ok && colourMap < ColourMapper::getColourMapCount()) {
+            setColourMap(colourMap);
+        }
+    }
 
     BinScale binScale = (BinScale)
         attributes.value("binScale").toInt(&ok);