comparison data/model/EditableDenseThreeDimensionalModel.cpp @ 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 3e6fee4e4257
children 46398ab6ff58
comparison
equal deleted inserted replaced
255:7033e188b2b2 256:9c85517ff0f5
17 17
18 #include <QTextStream> 18 #include <QTextStream>
19 19
20 #include <iostream> 20 #include <iostream>
21 21
22 #include <cmath>
23
22 EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(size_t sampleRate, 24 EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(size_t sampleRate,
23 size_t resolution, 25 size_t resolution,
24 size_t yBinCount, 26 size_t yBinCount,
25 bool notifyOnAdd) : 27 bool notifyOnAdd) :
26 m_sampleRate(sampleRate), 28 m_sampleRate(sampleRate),
27 m_resolution(resolution), 29 m_resolution(resolution),
28 m_yBinCount(yBinCount), 30 m_yBinCount(yBinCount),
29 m_minimum(0.0), 31 m_minimum(0.0),
30 m_maximum(0.0), 32 m_maximum(0.0),
33 m_haveExtents(false),
31 m_notifyOnAdd(notifyOnAdd), 34 m_notifyOnAdd(notifyOnAdd),
32 m_sinceLastNotifyMin(-1), 35 m_sinceLastNotifyMin(-1),
33 m_sinceLastNotifyMax(-1), 36 m_sinceLastNotifyMax(-1),
34 m_completion(100) 37 m_completion(100)
35 { 38 {
66 new EditableDenseThreeDimensionalModel 69 new EditableDenseThreeDimensionalModel
67 (m_sampleRate, m_resolution, m_yBinCount); 70 (m_sampleRate, m_resolution, m_yBinCount);
68 71
69 model->m_minimum = m_minimum; 72 model->m_minimum = m_minimum;
70 model->m_maximum = m_maximum; 73 model->m_maximum = m_maximum;
74 model->m_haveExtents = m_haveExtents;
71 75
72 for (size_t i = 0; i < m_data.size(); ++i) { 76 for (size_t i = 0; i < m_data.size(); ++i) {
73 model->setColumn(i, m_data[i]); 77 model->setColumn(i, m_data[i]);
74 } 78 }
75 79
150 { 154 {
151 QMutexLocker locker(&m_mutex); 155 QMutexLocker locker(&m_mutex);
152 156
153 if (index < m_data.size()) { 157 if (index < m_data.size()) {
154 const Column &s = m_data[index]; 158 const Column &s = m_data[index];
155 std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size() 159 // std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size()
156 << std::endl; 160 // << std::endl;
157 if (n < s.size()) return s[n]; 161 if (n < s.size()) return s[n];
158 } 162 }
159 163
160 return m_minimum; 164 return m_minimum;
161 } 165 }
168 172
169 while (index >= m_data.size()) { 173 while (index >= m_data.size()) {
170 m_data.push_back(Column()); 174 m_data.push_back(Column());
171 } 175 }
172 176
173 bool newExtents = (m_data.empty() && (m_minimum == m_maximum));
174 bool allChange = false; 177 bool allChange = false;
175 178
176 for (size_t i = 0; i < values.size(); ++i) { 179 for (size_t i = 0; i < values.size(); ++i) {
177 if (newExtents || values[i] < m_minimum) { 180 float value = values[i];
178 m_minimum = values[i]; 181 if (isnan(value) || isinf(value)) {
182 continue;
183 }
184 if (!m_haveExtents || value < m_minimum) {
185 m_minimum = value;
179 allChange = true; 186 allChange = true;
180 } 187 }
181 if (newExtents || values[i] > m_maximum) { 188 if (!m_haveExtents || value > m_maximum) {
182 m_maximum = values[i]; 189 m_maximum = value;
183 allChange = true; 190 allChange = true;
184 } 191 }
192 m_haveExtents = true;
185 } 193 }
186 194
187 m_data[index] = values; 195 m_data[index] = values;
188 196
189 long windowStart = index; 197 long windowStart = index;