Mercurial > hg > svcore
comparison data/model/SparseModel.h @ 777:eea8049df526
Fix incorrect retrieval of point in model by row number if point frame values fell between model resolution boundaries
author | Chris Cannam |
---|---|
date | Wed, 27 Mar 2013 14:51:49 +0000 |
parents | e22b6e89a7f7 |
children | d373ced0e6e9 |
comparison
equal
deleted
inserted
replaced
766:2444ef08b7eb | 777:eea8049df526 |
---|---|
384 mutable std::vector<long> m_rows; // map from row number to frame | 384 mutable std::vector<long> m_rows; // map from row number to frame |
385 void rebuildRowVector() const | 385 void rebuildRowVector() const |
386 { | 386 { |
387 m_rows.clear(); | 387 m_rows.clear(); |
388 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { | 388 for (PointListConstIterator i = m_points.begin(); i != m_points.end(); ++i) { |
389 // std::cerr << "rebuildRowVector: row " << m_rows.size() << " -> " << i->frame << std::endl; | |
389 m_rows.push_back(i->frame); | 390 m_rows.push_back(i->frame); |
390 } | 391 } |
391 } | 392 } |
392 | 393 |
393 PointListIterator getPointListIteratorForRow(int row) | 394 PointListIterator getPointListIteratorForRow(int row) |
404 PointListIterator i0, i1; | 405 PointListIterator i0, i1; |
405 getPointIterators(frame, i0, i1); | 406 getPointIterators(frame, i0, i1); |
406 PointListIterator i = i0; | 407 PointListIterator i = i0; |
407 | 408 |
408 for (i = i0; i != i1; ++i) { | 409 for (i = i0; i != i1; ++i) { |
410 if (i->frame < frame) { continue; } | |
409 if (indexAtFrame > 0) { --indexAtFrame; continue; } | 411 if (indexAtFrame > 0) { --indexAtFrame; continue; } |
410 return i; | 412 return i; |
411 } | 413 } |
412 | 414 |
413 if (indexAtFrame > 0) { | 415 if (indexAtFrame > 0) { |
425 int indexAtFrame = 0; | 427 int indexAtFrame = 0; |
426 int ri = row; | 428 int ri = row; |
427 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } | 429 while (ri > 0 && m_rows[ri-1] == m_rows[row]) { --ri; ++indexAtFrame; } |
428 int initialIndexAtFrame = indexAtFrame; | 430 int initialIndexAtFrame = indexAtFrame; |
429 | 431 |
432 // std::cerr << "getPointListIteratorForRow " << row << ": initialIndexAtFrame = " << initialIndexAtFrame << std::endl; | |
433 | |
430 PointListConstIterator i0, i1; | 434 PointListConstIterator i0, i1; |
431 getPointIterators(frame, i0, i1); | 435 getPointIterators(frame, i0, i1); |
432 PointListConstIterator i = i0; | 436 PointListConstIterator i = i0; |
433 | 437 |
434 for (i = i0; i != i1; ++i) { | 438 for (i = i0; i != i1; ++i) { |
439 if (i->frame < frame) { continue; } | |
435 if (indexAtFrame > 0) { --indexAtFrame; continue; } | 440 if (indexAtFrame > 0) { --indexAtFrame; continue; } |
436 return i; | 441 return i; |
437 } | 442 } |
438 | 443 |
439 if (indexAtFrame > 0) { | 444 if (indexAtFrame > 0) { |
577 | 582 |
578 long start = (frame / m_resolution) * m_resolution; | 583 long start = (frame / m_resolution) * m_resolution; |
579 long end = start + m_resolution; | 584 long end = start + m_resolution; |
580 | 585 |
581 PointType startPoint(start), endPoint(end); | 586 PointType startPoint(start), endPoint(end); |
582 | 587 |
583 startItr = m_points.lower_bound(startPoint); | 588 startItr = m_points.lower_bound(startPoint); |
584 endItr = m_points.upper_bound(endPoint); | 589 endItr = m_points.upper_bound(endPoint); |
585 } | 590 } |
586 | 591 |
587 template <typename PointType> | 592 template <typename PointType> |
600 | 605 |
601 long start = (frame / m_resolution) * m_resolution; | 606 long start = (frame / m_resolution) * m_resolution; |
602 long end = start + m_resolution; | 607 long end = start + m_resolution; |
603 | 608 |
604 PointType startPoint(start), endPoint(end); | 609 PointType startPoint(start), endPoint(end); |
610 | |
611 // std::cerr << "getPointIterators: start frame " << start << ", end frame " << end << ", m_resolution " << m_resolution << std::endl; | |
605 | 612 |
606 startItr = m_points.lower_bound(startPoint); | 613 startItr = m_points.lower_bound(startPoint); |
607 endItr = m_points.upper_bound(endPoint); | 614 endItr = m_points.upper_bound(endPoint); |
608 } | 615 } |
609 | 616 |
773 void | 780 void |
774 SparseModel<PointType>::toXml(QTextStream &out, | 781 SparseModel<PointType>::toXml(QTextStream &out, |
775 QString indent, | 782 QString indent, |
776 QString extraAttributes) const | 783 QString extraAttributes) const |
777 { | 784 { |
778 std::cerr << "SparseModel::toXml: extraAttributes = \"" | 785 // std::cerr << "SparseModel::toXml: extraAttributes = \"" |
779 << extraAttributes.toStdString() << std::endl; | 786 // << extraAttributes.toStdString() << std::endl; |
780 | 787 |
781 QString type = getXmlOutputType(); | 788 QString type = getXmlOutputType(); |
782 | 789 |
783 Model::toXml | 790 Model::toXml |
784 (out, | 791 (out, |