Mercurial > hg > svcore
comparison data/model/EditableDenseThreeDimensionalModel.cpp @ 533:55ad231c9db7
* try some qvectors
author | Chris Cannam |
---|---|
date | Thu, 22 Jan 2009 17:58:33 +0000 |
parents | 1405f4a2caf3 |
children | 6038cb6fcd30 |
comparison
equal
deleted
inserted
replaced
532:59dd6d1bcfb0 | 533:55ad231c9db7 |
---|---|
75 model->m_minimum = m_minimum; | 75 model->m_minimum = m_minimum; |
76 model->m_maximum = m_maximum; | 76 model->m_maximum = m_maximum; |
77 model->m_haveExtents = m_haveExtents; | 77 model->m_haveExtents = m_haveExtents; |
78 | 78 |
79 for (size_t i = 0; i < m_data.size(); ++i) { | 79 for (size_t i = 0; i < m_data.size(); ++i) { |
80 model->setColumn(i, m_data[i]); | 80 model->setColumn(i, m_data.at(i)); |
81 } | 81 } |
82 | 82 |
83 return model; | 83 return model; |
84 } | 84 } |
85 | 85 |
135 EditableDenseThreeDimensionalModel::setMaximumLevel(float level) | 135 EditableDenseThreeDimensionalModel::setMaximumLevel(float level) |
136 { | 136 { |
137 m_maximum = level; | 137 m_maximum = level; |
138 } | 138 } |
139 | 139 |
140 void | 140 EditableDenseThreeDimensionalModel::Column |
141 EditableDenseThreeDimensionalModel::getColumn(size_t index, | 141 EditableDenseThreeDimensionalModel::getColumn(size_t index) const |
142 Column &result) const | |
143 { | 142 { |
144 QMutexLocker locker(&m_mutex); | 143 QMutexLocker locker(&m_mutex); |
145 | 144 |
145 Column result; | |
146 | |
146 if (index < m_data.size()) { | 147 if (index < m_data.size()) { |
147 result = m_data[index]; | 148 result = m_data.at(index); |
148 } else { | 149 } else { |
149 result.clear(); | 150 result.clear(); |
150 } | 151 } |
151 | 152 |
152 while (result.size() < m_yBinCount) result.push_back(m_minimum); | 153 while (result.size() < m_yBinCount) result.push_back(m_minimum); |
154 return result; | |
153 } | 155 } |
154 | 156 |
155 float | 157 float |
156 EditableDenseThreeDimensionalModel::getValueAt(size_t index, size_t n) const | 158 EditableDenseThreeDimensionalModel::getValueAt(size_t index, size_t n) const |
157 { | 159 { |
158 QMutexLocker locker(&m_mutex); | 160 QMutexLocker locker(&m_mutex); |
159 | 161 |
160 if (index < m_data.size()) { | 162 if (index < m_data.size()) { |
161 const Column &s = m_data[index]; | 163 const Column &s = m_data.at(index); |
162 // std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size() | 164 // std::cerr << "index " << index << ", n " << n << ", res " << m_resolution << ", size " << s.size() |
163 // << std::endl; | 165 // << std::endl; |
164 if (n < s.size()) return s[n]; | 166 if (n < s.size()) return s.at(n); |
165 } | 167 } |
166 | 168 |
167 return m_minimum; | 169 return m_minimum; |
168 } | 170 } |
169 | 171 |
249 } | 251 } |
250 | 252 |
251 bool | 253 bool |
252 EditableDenseThreeDimensionalModel::shouldUseLogValueScale() const | 254 EditableDenseThreeDimensionalModel::shouldUseLogValueScale() const |
253 { | 255 { |
254 std::vector<float> sample; | 256 QVector<float> sample; |
255 std::vector<int> n; | 257 QVector<int> n; |
256 | 258 |
257 for (int i = 0; i < 10; ++i) { | 259 for (int i = 0; i < 10; ++i) { |
258 size_t index = i * 10; | 260 size_t index = i * 10; |
259 if (index < m_data.size()) { | 261 if (index < m_data.size()) { |
260 const Column &c = m_data[index]; | 262 const Column &c = m_data.at(index); |
261 while (c.size() > sample.size()) { | 263 while (c.size() > sample.size()) { |
262 sample.push_back(0.f); | 264 sample.push_back(0.f); |
263 n.push_back(0); | 265 n.push_back(0); |
264 } | 266 } |
265 for (int j = 0; j < c.size(); ++j) { | 267 for (int j = 0; j < c.size(); ++j) { |
266 sample[j] += c[j]; | 268 sample[j] += c.at(j); |
267 ++n[j]; | 269 ++n[j]; |
268 } | 270 } |
269 } | 271 } |
270 } | 272 } |
271 | 273 |
272 if (sample.empty()) return false; | 274 if (sample.empty()) return false; |
273 for (int j = 0; j < sample.size(); ++j) { | 275 for (int j = 0; j < sample.size(); ++j) { |
274 if (n[j]) sample[j] /= n[j]; | 276 if (n[j]) sample[j] /= n[j]; |
275 } | 277 } |
276 | 278 |
277 return LogRange::useLogScale(sample); | 279 return LogRange::useLogScale(sample.toStdVector()); |
278 } | 280 } |
279 | 281 |
280 void | 282 void |
281 EditableDenseThreeDimensionalModel::setCompletion(int completion, bool update) | 283 EditableDenseThreeDimensionalModel::setCompletion(int completion, bool update) |
282 { | 284 { |
309 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const | 311 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const |
310 { | 312 { |
311 QString s; | 313 QString s; |
312 for (size_t i = 0; i < m_data.size(); ++i) { | 314 for (size_t i = 0; i < m_data.size(); ++i) { |
313 QStringList list; | 315 QStringList list; |
314 for (size_t j = 0; j < m_data[i].size(); ++j) { | 316 for (size_t j = 0; j < m_data.at(i).size(); ++j) { |
315 list << QString("%1").arg(m_data[i][j]); | 317 list << QString("%1").arg(m_data.at(i).at(j)); |
316 } | 318 } |
317 s += list.join(delimiter) + "\n"; | 319 s += list.join(delimiter) + "\n"; |
318 } | 320 } |
319 return s; | 321 return s; |
320 } | 322 } |
351 } | 353 } |
352 | 354 |
353 for (size_t i = 0; i < m_data.size(); ++i) { | 355 for (size_t i = 0; i < m_data.size(); ++i) { |
354 out << indent + " "; | 356 out << indent + " "; |
355 out << QString("<row n=\"%1\">").arg(i); | 357 out << QString("<row n=\"%1\">").arg(i); |
356 for (size_t j = 0; j < m_data[i].size(); ++j) { | 358 for (size_t j = 0; j < m_data.at(i).size(); ++j) { |
357 if (j > 0) out << " "; | 359 if (j > 0) out << " "; |
358 out << m_data[i][j]; | 360 out << m_data.at(i).at(j); |
359 } | 361 } |
360 out << QString("</row>\n"); | 362 out << QString("</row>\n"); |
361 out.flush(); | 363 out.flush(); |
362 } | 364 } |
363 | 365 |