comparison data/model/EditableDenseThreeDimensionalModel.cpp @ 929:59e7fe1b1003 warnfix_no_size_t

Unsigned removals and warning fixes in data/
author Chris Cannam
date Tue, 17 Jun 2014 14:33:42 +0100
parents 48410857b03c
children df82da55e86a
comparison
equal deleted inserted replaced
928:6a94bb528e9d 929:59e7fe1b1003
27 #include <cmath> 27 #include <cmath>
28 #include <cassert> 28 #include <cassert>
29 29
30 #include "system/System.h" 30 #include "system/System.h"
31 31
32 EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(size_t sampleRate, 32 EditableDenseThreeDimensionalModel::EditableDenseThreeDimensionalModel(int sampleRate,
33 size_t resolution, 33 int resolution,
34 size_t yBinCount, 34 int yBinCount,
35 CompressionType compression, 35 CompressionType compression,
36 bool notifyOnAdd) : 36 bool notifyOnAdd) :
37 m_startFrame(0), 37 m_startFrame(0),
38 m_sampleRate(sampleRate), 38 m_sampleRate(sampleRate),
39 m_resolution(resolution), 39 m_resolution(resolution),
53 EditableDenseThreeDimensionalModel::isOK() const 53 EditableDenseThreeDimensionalModel::isOK() const
54 { 54 {
55 return true; 55 return true;
56 } 56 }
57 57
58 size_t 58 int
59 EditableDenseThreeDimensionalModel::getSampleRate() const 59 EditableDenseThreeDimensionalModel::getSampleRate() const
60 { 60 {
61 return m_sampleRate; 61 return m_sampleRate;
62 } 62 }
63 63
64 size_t 64 int
65 EditableDenseThreeDimensionalModel::getStartFrame() const 65 EditableDenseThreeDimensionalModel::getStartFrame() const
66 { 66 {
67 return m_startFrame; 67 return m_startFrame;
68 } 68 }
69 69
70 void 70 void
71 EditableDenseThreeDimensionalModel::setStartFrame(size_t f) 71 EditableDenseThreeDimensionalModel::setStartFrame(int f)
72 { 72 {
73 m_startFrame = f; 73 m_startFrame = f;
74 } 74 }
75 75
76 size_t 76 int
77 EditableDenseThreeDimensionalModel::getEndFrame() const 77 EditableDenseThreeDimensionalModel::getEndFrame() const
78 { 78 {
79 return m_resolution * m_data.size() + (m_resolution - 1); 79 return m_resolution * m_data.size() + (m_resolution - 1);
80 } 80 }
81 81
90 90
91 model->m_minimum = m_minimum; 91 model->m_minimum = m_minimum;
92 model->m_maximum = m_maximum; 92 model->m_maximum = m_maximum;
93 model->m_haveExtents = m_haveExtents; 93 model->m_haveExtents = m_haveExtents;
94 94
95 for (size_t i = 0; i < m_data.size(); ++i) { 95 for (int i = 0; i < m_data.size(); ++i) {
96 model->setColumn(i, m_data.at(i)); 96 model->setColumn(i, m_data.at(i));
97 } 97 }
98 98
99 return model; 99 return model;
100 } 100 }
101 101
102 size_t 102 int
103 EditableDenseThreeDimensionalModel::getResolution() const 103 EditableDenseThreeDimensionalModel::getResolution() const
104 { 104 {
105 return m_resolution; 105 return m_resolution;
106 } 106 }
107 107
108 void 108 void
109 EditableDenseThreeDimensionalModel::setResolution(size_t sz) 109 EditableDenseThreeDimensionalModel::setResolution(int sz)
110 { 110 {
111 m_resolution = sz; 111 m_resolution = sz;
112 } 112 }
113 113
114 size_t 114 int
115 EditableDenseThreeDimensionalModel::getWidth() const 115 EditableDenseThreeDimensionalModel::getWidth() const
116 { 116 {
117 return m_data.size(); 117 return m_data.size();
118 } 118 }
119 119
120 size_t 120 int
121 EditableDenseThreeDimensionalModel::getHeight() const 121 EditableDenseThreeDimensionalModel::getHeight() const
122 { 122 {
123 return m_yBinCount; 123 return m_yBinCount;
124 } 124 }
125 125
126 void 126 void
127 EditableDenseThreeDimensionalModel::setHeight(size_t sz) 127 EditableDenseThreeDimensionalModel::setHeight(int sz)
128 { 128 {
129 m_yBinCount = sz; 129 m_yBinCount = sz;
130 } 130 }
131 131
132 float 132 float
152 { 152 {
153 m_maximum = level; 153 m_maximum = level;
154 } 154 }
155 155
156 EditableDenseThreeDimensionalModel::Column 156 EditableDenseThreeDimensionalModel::Column
157 EditableDenseThreeDimensionalModel::getColumn(size_t index) const 157 EditableDenseThreeDimensionalModel::getColumn(int index) const
158 { 158 {
159 QReadLocker locker(&m_lock); 159 QReadLocker locker(&m_lock);
160 if (index >= m_data.size()) return Column(); 160 if (int(index) >= m_data.size()) return Column();
161 return expandAndRetrieve(index); 161 return expandAndRetrieve(index);
162 } 162 }
163 163
164 float 164 float
165 EditableDenseThreeDimensionalModel::getValueAt(size_t index, size_t n) const 165 EditableDenseThreeDimensionalModel::getValueAt(int index, int n) const
166 { 166 {
167 Column c = getColumn(index); 167 Column c = getColumn(index);
168 if (n < c.size()) return c.at(n); 168 if (int(n) < c.size()) return c.at(n);
169 return m_minimum; 169 return m_minimum;
170 } 170 }
171 171
172 //static int given = 0, stored = 0; 172 //static int given = 0, stored = 0;
173 173
174 void 174 void
175 EditableDenseThreeDimensionalModel::truncateAndStore(size_t index, 175 EditableDenseThreeDimensionalModel::truncateAndStore(int index,
176 const Column &values) 176 const Column &values)
177 { 177 {
178 assert(index < m_data.size()); 178 assert(int(index) < m_data.size());
179 179
180 //cout << "truncateAndStore(" << index << ", " << values.size() << ")" << endl; 180 //cout << "truncateAndStore(" << index << ", " << values.size() << ")" << endl;
181 181
182 // The default case is to store the entire column at m_data[index] 182 // The default case is to store the entire column at m_data[index]
183 // and place 0 at m_trunc[index] to indicate that it has not been 183 // and place 0 at m_trunc[index] to indicate that it has not been
185 // tests works out. 185 // tests works out.
186 186
187 m_trunc[index] = 0; 187 m_trunc[index] = 0;
188 if (index == 0 || 188 if (index == 0 ||
189 m_compression == NoCompression || 189 m_compression == NoCompression ||
190 values.size() != m_yBinCount) { 190 values.size() != int(m_yBinCount)) {
191 // given += values.size(); 191 // given += values.size();
192 // stored += values.size(); 192 // stored += values.size();
193 m_data[index] = values; 193 m_data[index] = values;
194 return; 194 return;
195 } 195 }
281 m_data[index] = values; 281 m_data[index] = values;
282 return; 282 return;
283 } 283 }
284 284
285 EditableDenseThreeDimensionalModel::Column 285 EditableDenseThreeDimensionalModel::Column
286 EditableDenseThreeDimensionalModel::expandAndRetrieve(size_t index) const 286 EditableDenseThreeDimensionalModel::expandAndRetrieve(int index) const
287 { 287 {
288 // See comment above m_trunc declaration in header 288 // See comment above m_trunc declaration in header
289 289
290 assert(index < m_data.size()); 290 assert(int(index) < m_data.size());
291 Column c = m_data.at(index); 291 Column c = m_data.at(index);
292 if (index == 0) { 292 if (index == 0) {
293 return c; 293 return c;
294 } 294 }
295 int trunc = (int)m_trunc[index]; 295 int trunc = (int)m_trunc[index];
299 bool top = true; 299 bool top = true;
300 int tdist = trunc; 300 int tdist = trunc;
301 if (trunc < 0) { top = false; tdist = -trunc; } 301 if (trunc < 0) { top = false; tdist = -trunc; }
302 Column p = expandAndRetrieve(index - tdist); 302 Column p = expandAndRetrieve(index - tdist);
303 int psize = p.size(), csize = c.size(); 303 int psize = p.size(), csize = c.size();
304 if (psize != m_yBinCount) { 304 if (psize != int(m_yBinCount)) {
305 cerr << "WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl; 305 cerr << "WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl;
306 } 306 }
307 if (top) { 307 if (top) {
308 for (int i = csize; i < psize; ++i) { 308 for (int i = csize; i < psize; ++i) {
309 c.push_back(p.at(i)); 309 c.push_back(p.at(i));
324 } 324 }
325 return c; 325 return c;
326 } 326 }
327 327
328 void 328 void
329 EditableDenseThreeDimensionalModel::setColumn(size_t index, 329 EditableDenseThreeDimensionalModel::setColumn(int index,
330 const Column &values) 330 const Column &values)
331 { 331 {
332 QWriteLocker locker(&m_lock); 332 QWriteLocker locker(&m_lock);
333 333
334 while (index >= m_data.size()) { 334 while (int(index) >= m_data.size()) {
335 m_data.push_back(Column()); 335 m_data.push_back(Column());
336 m_trunc.push_back(0); 336 m_trunc.push_back(0);
337 } 337 }
338 338
339 bool allChange = false; 339 bool allChange = false;
340 340
341 // if (values.size() > m_yBinCount) m_yBinCount = values.size(); 341 // if (values.size() > m_yBinCount) m_yBinCount = values.size();
342 342
343 for (size_t i = 0; i < values.size(); ++i) { 343 for (int i = 0; i < values.size(); ++i) {
344 float value = values[i]; 344 float value = values[i];
345 if (ISNAN(value) || ISINF(value)) { 345 if (ISNAN(value) || ISINF(value)) {
346 continue; 346 continue;
347 } 347 }
348 if (!m_haveExtents || value < m_minimum) { 348 if (!m_haveExtents || value < m_minimum) {
386 } 386 }
387 } 387 }
388 } 388 }
389 389
390 QString 390 QString
391 EditableDenseThreeDimensionalModel::getBinName(size_t n) const 391 EditableDenseThreeDimensionalModel::getBinName(int n) const
392 { 392 {
393 if (m_binNames.size() > n) return m_binNames[n]; 393 if ((int)m_binNames.size() > n) return m_binNames[n];
394 else return ""; 394 else return "";
395 } 395 }
396 396
397 void 397 void
398 EditableDenseThreeDimensionalModel::setBinName(size_t n, QString name) 398 EditableDenseThreeDimensionalModel::setBinName(int n, QString name)
399 { 399 {
400 while (m_binNames.size() <= n) m_binNames.push_back(""); 400 while ((int)m_binNames.size() <= n) m_binNames.push_back("");
401 m_binNames[n] = name; 401 m_binNames[n] = name;
402 emit modelChanged(); 402 emit modelChanged();
403 } 403 }
404 404
405 void 405 void
414 { 414 {
415 return !m_binValues.empty(); 415 return !m_binValues.empty();
416 } 416 }
417 417
418 float 418 float
419 EditableDenseThreeDimensionalModel::getBinValue(size_t n) const 419 EditableDenseThreeDimensionalModel::getBinValue(int n) const
420 { 420 {
421 if (n < m_binValues.size()) return m_binValues[n]; 421 if (n < (int)m_binValues.size()) return m_binValues[n];
422 else return 0.f; 422 else return 0.f;
423 } 423 }
424 424
425 void 425 void
426 EditableDenseThreeDimensionalModel::setBinValues(std::vector<float> values) 426 EditableDenseThreeDimensionalModel::setBinValues(std::vector<float> values)
447 447
448 QVector<float> sample; 448 QVector<float> sample;
449 QVector<int> n; 449 QVector<int> n;
450 450
451 for (int i = 0; i < 10; ++i) { 451 for (int i = 0; i < 10; ++i) {
452 size_t index = i * 10; 452 int index = i * 10;
453 if (index < m_data.size()) { 453 if (index < m_data.size()) {
454 const Column &c = m_data.at(index); 454 const Column &c = m_data.at(index);
455 while (c.size() > sample.size()) { 455 while (c.size() > sample.size()) {
456 sample.push_back(0.f); 456 sample.push_back(0.f);
457 n.push_back(0); 457 n.push_back(0);
502 QString 502 QString
503 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const 503 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const
504 { 504 {
505 QReadLocker locker(&m_lock); 505 QReadLocker locker(&m_lock);
506 QString s; 506 QString s;
507 for (size_t i = 0; i < m_data.size(); ++i) { 507 for (int i = 0; i < m_data.size(); ++i) {
508 QStringList list; 508 QStringList list;
509 for (size_t j = 0; j < m_data.at(i).size(); ++j) { 509 for (int j = 0; j < m_data.at(i).size(); ++j) {
510 list << QString("%1").arg(m_data.at(i).at(j)); 510 list << QString("%1").arg(m_data.at(i).at(j));
511 } 511 }
512 s += list.join(delimiter) + "\n"; 512 s += list.join(delimiter) + "\n";
513 } 513 }
514 return s; 514 return s;
515 } 515 }
516 516
517 QString 517 QString
518 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter, size_t f0, size_t f1) const 518 EditableDenseThreeDimensionalModel::toDelimitedDataStringSubset(QString delimiter, int f0, int f1) const
519 { 519 {
520 QReadLocker locker(&m_lock); 520 QReadLocker locker(&m_lock);
521 QString s; 521 QString s;
522 for (size_t i = 0; i < m_data.size(); ++i) { 522 for (int i = 0; i < m_data.size(); ++i) {
523 size_t fr = m_startFrame + i * m_resolution; 523 int fr = m_startFrame + i * m_resolution;
524 if (fr >= f0 && fr < f1) { 524 if (fr >= int(f0) && fr < int(f1)) {
525 QStringList list; 525 QStringList list;
526 for (size_t j = 0; j < m_data.at(i).size(); ++j) { 526 for (int j = 0; j < m_data.at(i).size(); ++j) {
527 list << QString("%1").arg(m_data.at(i).at(j)); 527 list << QString("%1").arg(m_data.at(i).at(j));
528 } 528 }
529 s += list.join(delimiter) + "\n"; 529 s += list.join(delimiter) + "\n";
530 } 530 }
531 } 531 }
556 556
557 out << indent; 557 out << indent;
558 out << QString("<dataset id=\"%1\" dimensions=\"3\" separator=\" \">\n") 558 out << QString("<dataset id=\"%1\" dimensions=\"3\" separator=\" \">\n")
559 .arg(getObjectExportId(&m_data)); 559 .arg(getObjectExportId(&m_data));
560 560
561 for (size_t i = 0; i < m_binNames.size(); ++i) { 561 for (int i = 0; i < (int)m_binNames.size(); ++i) {
562 if (m_binNames[i] != "") { 562 if (m_binNames[i] != "") {
563 out << indent + " "; 563 out << indent + " ";
564 out << QString("<bin number=\"%1\" name=\"%2\"/>\n") 564 out << QString("<bin number=\"%1\" name=\"%2\"/>\n")
565 .arg(i).arg(m_binNames[i]); 565 .arg(i).arg(m_binNames[i]);
566 } 566 }
567 } 567 }
568 568
569 for (size_t i = 0; i < m_data.size(); ++i) { 569 for (int i = 0; i < (int)m_data.size(); ++i) {
570 out << indent + " "; 570 out << indent + " ";
571 out << QString("<row n=\"%1\">").arg(i); 571 out << QString("<row n=\"%1\">").arg(i);
572 for (size_t j = 0; j < m_data.at(i).size(); ++j) { 572 for (int j = 0; j < (int)m_data.at(i).size(); ++j) {
573 if (j > 0) out << " "; 573 if (j > 0) out << " ";
574 out << m_data.at(i).at(j); 574 out << m_data.at(i).at(j);
575 } 575 }
576 out << QString("</row>\n"); 576 out << QString("</row>\n");
577 out.flush(); 577 out.flush();