diff layer/Colour3DPlotLayer.cpp @ 224:9465b5375235

* Fix #1672407 confused by plugin-named files in cwd (or home?) * Fix #1491848 crash when loading new file while transform plugin runs * Fix #1502287 Background remains black after spectrogram layer deleted * Fix #1604477 Replacing the main audio file silences secondary audio file * Fix failure to initialise property box layout to last preference on startup * Fix resample/wrong-rate display in Pane, ensure that right rate is chosen if all current models have an acceptable rate even if previous main model had a different one * Fix "global zoom" broken in previous commit * Some fixes to spectrogram cache area updating (makes spectrogram appear more quickly, previously it had a tendency to refresh with empty space) * Fixes to colour 3d plot normalization
author Chris Cannam
date Thu, 08 Mar 2007 16:53:08 +0000
parents 34bbbcb3c01f
children 28c8e8e3c537
line wrap: on
line diff
--- a/layer/Colour3DPlotLayer.cpp	Wed Mar 07 18:00:49 2007 +0000
+++ b/layer/Colour3DPlotLayer.cpp	Thu Mar 08 16:53:08 2007 +0000
@@ -384,7 +384,7 @@
 {
     m_model->getColumn(col, values);
 
-    float colMax = 0.f;
+    float colMax = 0.f, colMin = 0.f;
 
     float min = 0.f, max = 0.f;
     if (m_normalizeColumns) {
@@ -394,11 +394,10 @@
 
     if (m_normalizeColumns) {
         for (size_t y = 0; y < values.size(); ++y) {
-            if (values[y] > colMax || y == 0) colMax = values[y];
+            if (y == 0 || values[y] > colMax) colMax = values[y];
+            if (y == 0 || values[y] < colMin) colMin = values[y];
         }
-        if (m_colourScale == LogScale) {
-            colMax = LogRange::map(colMax);
-        }
+        if (colMin == colMax) colMax = colMin + 1;
     }
     
     for (size_t y = 0; y < values.size(); ++y) {
@@ -406,16 +405,10 @@
         float value = min;
 
         value = values[y];
-        if (m_colourScale == LogScale) {
-            value = LogRange::map(value);
-        }
 
         if (m_normalizeColumns) {
-            if (colMax != 0) {
-                value = max * (value / colMax);
-            } else {
-                value = 0;
-            }
+            float norm = (value - colMin) / (colMax - colMin);
+            value = min + (max - min) * norm;
         }
 
         values[y] = value;
@@ -429,7 +422,7 @@
     size_t modelEnd = m_model->getEndFrame();
     size_t modelResolution = m_model->getResolution();
 
-    std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl;
+//    std::cerr << "Colour3DPlotLayer::fillCache: " << firstBin << " -> " << lastBin << std::endl;
 
     if (!m_normalizeVisibleArea || m_normalizeColumns) {
         firstBin = modelStart / modelResolution;
@@ -453,7 +446,7 @@
     m_cache = new QImage(cacheWidth, cacheHeight, QImage::Format_Indexed8);
     m_cacheStart = firstBin;
 
-    std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " starting " << m_cacheStart << std::endl;
+//    std::cerr << "Cache size " << cacheWidth << "x" << cacheHeight << " starting " << m_cacheStart << std::endl;
 
     m_cache->setNumColors(256);
     DenseThreeDimensionalModel::Column values;
@@ -480,7 +473,7 @@
     
     m_cache->fill(0);
 
-    float visibleMax = 0.f;
+    float visibleMax = 0.f, visibleMin = 0.f;
 
     if (m_normalizeVisibleArea && !m_normalizeColumns) {
         
@@ -489,17 +482,21 @@
             values.clear();
             getColumn(c, values);
 
-            float colMax = 0.f;
+            float colMax = 0.f, colMin = 0.f;
 
             for (size_t y = 0; y < m_model->getHeight(); ++y) {
                 if (y >= values.size()) break;
                 if (y == 0 || values[y] > colMax) colMax = values[y];
+                if (y == 0 || values[y] < colMin) colMin = values[y];
             }
 
             if (c == firstBin || colMax > visibleMax) visibleMax = colMax;
+            if (c == firstBin || colMin < visibleMin) visibleMin = colMin;
         }
     }
     
+    if (visibleMin == visibleMax) visibleMax = visibleMin + 1;
+
     for (size_t c = firstBin; c <= lastBin; ++c) {
 	
         values.clear();
@@ -513,9 +510,12 @@
             }
             
             if (m_normalizeVisibleArea && !m_normalizeColumns) {
-                if (visibleMax != 0) {
-                    value = max * (value / visibleMax);
-                }
+                float norm = (value - visibleMin) / (visibleMax - visibleMin);
+                value = min + (max - min) * norm;
+            }
+
+            if (m_colourScale == LogScale) {
+                value = LogRange::map(value);
             }
 
             int pixel = int(((value - min) * 256) / (max - min));