comparison data/model/EditableDenseThreeDimensionalModel.cpp @ 1154:aa588c391d1a 3.0-integration

Convert 3d model column type from QVector to std::vector; replace another user of ResizeableBitset
author Chris Cannam
date Fri, 22 Jan 2016 13:39:45 +0000
parents 1517d4c60e88
children 2ff5e411151d
comparison
equal deleted inserted replaced
1153:ece369c5bb68 1154:aa588c391d1a
94 } 94 }
95 95
96 int 96 int
97 EditableDenseThreeDimensionalModel::getWidth() const 97 EditableDenseThreeDimensionalModel::getWidth() const
98 { 98 {
99 return m_data.size(); 99 return int(m_data.size());
100 } 100 }
101 101
102 int 102 int
103 EditableDenseThreeDimensionalModel::getHeight() const 103 EditableDenseThreeDimensionalModel::getHeight() const
104 { 104 {
137 137
138 EditableDenseThreeDimensionalModel::Column 138 EditableDenseThreeDimensionalModel::Column
139 EditableDenseThreeDimensionalModel::getColumn(int index) const 139 EditableDenseThreeDimensionalModel::getColumn(int index) const
140 { 140 {
141 QReadLocker locker(&m_lock); 141 QReadLocker locker(&m_lock);
142 if (index < 0 || index >= m_data.size()) return Column(); 142 if (in_range_for(m_data, index)) return expandAndRetrieve(index);
143 return expandAndRetrieve(index); 143 else return Column();
144 } 144 }
145 145
146 float 146 float
147 EditableDenseThreeDimensionalModel::getValueAt(int index, int n) const 147 EditableDenseThreeDimensionalModel::getValueAt(int index, int n) const
148 { 148 {
149 Column c = getColumn(index); 149 Column c = getColumn(index);
150 if (int(n) < c.size()) return c.at(n); 150 if (in_range_for(c, n)) return c.at(n);
151 return m_minimum; 151 return m_minimum;
152 } 152 }
153 153
154 //static int given = 0, stored = 0; 154 //static int given = 0, stored = 0;
155 155
156 void 156 void
157 EditableDenseThreeDimensionalModel::truncateAndStore(int index, 157 EditableDenseThreeDimensionalModel::truncateAndStore(int index,
158 const Column &values) 158 const Column &values)
159 { 159 {
160 assert(int(index) < m_data.size()); 160 assert(in_range_for(m_data, index));
161 161
162 //cout << "truncateAndStore(" << index << ", " << values.size() << ")" << endl; 162 //cout << "truncateAndStore(" << index << ", " << values.size() << ")" << endl;
163 163
164 // The default case is to store the entire column at m_data[index] 164 // The default case is to store the entire column at m_data[index]
165 // and place 0 at m_trunc[index] to indicate that it has not been 165 // and place 0 at m_trunc[index] to indicate that it has not been
167 // tests works out. 167 // tests works out.
168 168
169 m_trunc[index] = 0; 169 m_trunc[index] = 0;
170 if (index == 0 || 170 if (index == 0 ||
171 m_compression == NoCompression || 171 m_compression == NoCompression ||
172 values.size() != int(m_yBinCount)) { 172 int(values.size()) != m_yBinCount) {
173 // given += values.size(); 173 // given += values.size();
174 // stored += values.size(); 174 // stored += values.size();
175 m_data[index] = values; 175 m_data[index] = values;
176 return; 176 return;
177 } 177 }
204 } 204 }
205 205
206 Column p = expandAndRetrieve(index - tdist); 206 Column p = expandAndRetrieve(index - tdist);
207 int h = m_yBinCount; 207 int h = m_yBinCount;
208 208
209 if (p.size() == h && tdist <= maxdist) { 209 if (int(p.size()) == h && tdist <= maxdist) {
210 210
211 int bcount = 0, tcount = 0; 211 int bcount = 0, tcount = 0;
212 if (!known || !top) { 212 if (!known || !top) {
213 // count how many identical values there are at the bottom 213 // count how many identical values there are at the bottom
214 for (int i = 0; i < h; ++i) { 214 for (int i = 0; i < h; ++i) {
280 } 280 }
281 bool top = true; 281 bool top = true;
282 int tdist = trunc; 282 int tdist = trunc;
283 if (trunc < 0) { top = false; tdist = -trunc; } 283 if (trunc < 0) { top = false; tdist = -trunc; }
284 Column p = expandAndRetrieve(index - tdist); 284 Column p = expandAndRetrieve(index - tdist);
285 int psize = p.size(), csize = c.size(); 285 int psize = int(p.size()), csize = int(c.size());
286 if (psize != m_yBinCount) { 286 if (psize != m_yBinCount) {
287 cerr << "WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl; 287 cerr << "WARNING: EditableDenseThreeDimensionalModel::expandAndRetrieve: Trying to expand from incorrectly sized column" << endl;
288 } 288 }
289 if (top) { 289 if (top) {
290 for (int i = csize; i < psize; ++i) { 290 for (int i = csize; i < psize; ++i) {
291 c.push_back(p.at(i)); 291 c.push_back(p.at(i));
292 } 292 }
293 } else { 293 } else {
294 // push_front is very slow on QVector -- but not enough to
295 // make it desirable to choose a different container, since
296 // QVector has all the other advantages for us. easier to
297 // write the whole array out to a new vector
298 Column cc(psize); 294 Column cc(psize);
299 for (int i = 0; i < psize - csize; ++i) { 295 for (int i = 0; i < psize - csize; ++i) {
300 cc[i] = p.at(i); 296 cc[i] = p.at(i);
301 } 297 }
302 for (int i = 0; i < csize; ++i) { 298 for (int i = 0; i < csize; ++i) {
311 EditableDenseThreeDimensionalModel::setColumn(int index, 307 EditableDenseThreeDimensionalModel::setColumn(int index,
312 const Column &values) 308 const Column &values)
313 { 309 {
314 QWriteLocker locker(&m_lock); 310 QWriteLocker locker(&m_lock);
315 311
316 while (int(index) >= m_data.size()) { 312 while (index >= int(m_data.size())) {
317 m_data.push_back(Column()); 313 m_data.push_back(Column());
318 m_trunc.push_back(0); 314 m_trunc.push_back(0);
319 } 315 }
320 316
321 bool allChange = false; 317 bool allChange = false;
322 318
323 // if (values.size() > m_yBinCount) m_yBinCount = values.size(); 319 // if (values.size() > m_yBinCount) m_yBinCount = values.size();
324 320
325 for (int i = 0; i < values.size(); ++i) { 321 for (int i = 0; in_range_for(values, i); ++i) {
326 float value = values[i]; 322 float value = values[i];
327 if (ISNAN(value) || ISINF(value)) { 323 if (ISNAN(value) || ISINF(value)) {
328 continue; 324 continue;
329 } 325 }
330 if (!m_haveExtents || value < m_minimum) { 326 if (!m_haveExtents || value < m_minimum) {
430 vector<double> sample; 426 vector<double> sample;
431 vector<int> n; 427 vector<int> n;
432 428
433 for (int i = 0; i < 10; ++i) { 429 for (int i = 0; i < 10; ++i) {
434 int index = i * 10; 430 int index = i * 10;
435 if (index < m_data.size()) { 431 if (in_range_for(m_data, index)) {
436 const Column &c = m_data.at(index); 432 const Column &c = m_data.at(index);
437 while (c.size() > int(sample.size())) { 433 while (c.size() > sample.size()) {
438 sample.push_back(0.0); 434 sample.push_back(0.0);
439 n.push_back(0); 435 n.push_back(0);
440 } 436 }
441 for (int j = 0; j < c.size(); ++j) { 437 for (int j = 0; in_range_for(c, j); ++j) {
442 sample[j] += c.at(j); 438 sample[j] += c.at(j);
443 ++n[j]; 439 ++n[j];
444 } 440 }
445 } 441 }
446 } 442 }
484 QString 480 QString
485 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const 481 EditableDenseThreeDimensionalModel::toDelimitedDataString(QString delimiter) const
486 { 482 {
487 QReadLocker locker(&m_lock); 483 QReadLocker locker(&m_lock);
488 QString s; 484 QString s;
489 for (int i = 0; i < m_data.size(); ++i) { 485 for (int i = 0; in_range_for(m_data, i); ++i) {
490 QStringList list; 486 QStringList list;
491 for (int j = 0; j < m_data.at(i).size(); ++j) { 487 for (int j = 0; in_range_for(m_data.at(i), j); ++j) {
492 list << QString("%1").arg(m_data.at(i).at(j)); 488 list << QString("%1").arg(m_data.at(i).at(j));
493 } 489 }
494 s += list.join(delimiter) + "\n"; 490 s += list.join(delimiter) + "\n";
495 } 491 }
496 return s; 492 return s;
499 QString 495 QString
500 EditableDenseThreeDimensionalModel::toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const 496 EditableDenseThreeDimensionalModel::toDelimitedDataStringSubset(QString delimiter, sv_frame_t f0, sv_frame_t f1) const
501 { 497 {
502 QReadLocker locker(&m_lock); 498 QReadLocker locker(&m_lock);
503 QString s; 499 QString s;
504 for (int i = 0; i < m_data.size(); ++i) { 500 for (int i = 0; in_range_for(m_data, i); ++i) {
505 sv_frame_t fr = m_startFrame + i * m_resolution; 501 sv_frame_t fr = m_startFrame + i * m_resolution;
506 if (fr >= f0 && fr < f1) { 502 if (fr >= f0 && fr < f1) {
507 QStringList list; 503 QStringList list;
508 for (int j = 0; j < m_data.at(i).size(); ++j) { 504 for (int j = 0; in_range_for(m_data.at(i), j); ++j) {
509 list << QString("%1").arg(m_data.at(i).at(j)); 505 list << QString("%1").arg(m_data.at(i).at(j));
510 } 506 }
511 s += list.join(delimiter) + "\n"; 507 s += list.join(delimiter) + "\n";
512 } 508 }
513 } 509 }