diff data/model/SparseValueModel.h @ 256:9c85517ff0f5

* Fix #1706927 NaNs from plugin outputs should not be used
author Chris Cannam
date Fri, 27 Apr 2007 15:39:48 +0000
parents 4b2ea82fd0ed
children 46398ab6ff58
line wrap: on
line diff
--- a/data/model/SparseValueModel.h	Thu Apr 19 15:19:51 2007 +0000
+++ b/data/model/SparseValueModel.h	Fri Apr 27 15:39:48 2007 +0000
@@ -30,11 +30,20 @@
 {
 public:
     SparseValueModel(size_t sampleRate, size_t resolution,
+		     bool notifyOnAdd = true) :
+	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
+	m_valueMinimum(0.f),
+	m_valueMaximum(0.f),
+        m_haveExtents(false)
+    { }
+
+    SparseValueModel(size_t sampleRate, size_t resolution,
 		     float valueMinimum, float valueMaximum,
 		     bool notifyOnAdd = true) :
 	SparseModel<PointType>(sampleRate, resolution, notifyOnAdd),
 	m_valueMinimum(valueMinimum),
-	m_valueMaximum(valueMaximum)
+	m_valueMaximum(valueMaximum),
+        m_haveExtents(true)
     { }
 
     using SparseModel<PointType>::m_points;
@@ -52,12 +61,16 @@
     virtual void addPoint(const PointType &point)
     {
 	bool allChange = false;
-	if (m_points.empty() || point.value < m_valueMinimum) {
-	    m_valueMinimum = point.value; allChange = true;
-	}
-	if (m_points.empty() || point.value > m_valueMaximum) {
-	    m_valueMaximum = point.value; allChange = true;
-	}
+
+        if (!isnan(point.value) && !isinf(point.value)) {
+            if (!m_haveExtents || point.value < m_valueMinimum) {
+                m_valueMinimum = point.value; allChange = true;
+            }
+            if (!m_haveExtents || point.value > m_valueMaximum) {
+                m_valueMaximum = point.value; allChange = true;
+            }
+            m_haveExtents = true;
+        }
 
 	SparseModel<PointType>::addPoint(point);
 	if (allChange) emit modelChanged();
@@ -103,6 +116,7 @@
 protected:
     float m_valueMinimum;
     float m_valueMaximum;
+    bool m_haveExtents;
     QString m_units;
 };