Mercurial > hg > match-vamp
changeset 81:c603d77b00ac refactors
Toward cost checks
author | Chris Cannam |
---|---|
date | Thu, 27 Nov 2014 08:13:29 +0000 |
parents | e48e27db6765 |
children | 3616d541d69e |
files | src/Finder.cpp src/Finder.h |
diffstat | 2 files changed, 99 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Finder.cpp Thu Nov 20 16:44:06 2014 +0000 +++ b/src/Finder.cpp Thu Nov 27 08:13:29 2014 +0000 @@ -148,6 +148,91 @@ } } +Finder::ErrorPosition +Finder::checkPathCostMatrix() +{ + ErrorPosition err; + + int r1 = 0; + int c1 = 0; + int r2 = m_m->getFrameCount() - 1; + int c2 = m_m->getOtherFrameCount() - 1; + + if (r2 < r1 || c2 < c1) { + return err; + } + + int prevRowStart = 0, prevRowStop = 0; + + for (int r = r1; r <= r2; r++) { + + pair<int, int> colRange = m_m->getColRange(r); + + int rowStart = max(c1, colRange.first); + int rowStop = min(c2 + 1, colRange.second); + + for (int c = rowStart; c < rowStop; c++) { + + float newCost = m_m->getDistance(r, c); + double updateTo = -1.0; + Matcher::Advance dir = Matcher::AdvanceNone; + + if (r > r1) { // not first row + double min = -1; + if ((c > prevRowStart) && (c <= prevRowStop)) { + // diagonal from (r-1,c-1) + min = m_m->getPathCost(r-1, c-1) + newCost * 2; + err.prevCost = m_m->getPathCost(r-1, c-1); + err.distance = newCost * 2; + dir = Matcher::AdvanceBoth; + } + if ((c >= prevRowStart) && (c < prevRowStop)) { + // vertical from (r-1,c) + double cost = m_m->getPathCost(r-1, c) + newCost; + if ((min < 0) || (cost < min)) { + min = cost; + err.prevCost = m_m->getPathCost(r-1, c); + err.distance = newCost; + dir = Matcher::AdvanceThis; + } + } + if (c > rowStart) { + // horizontal from (r,c-1) + double cost = m_m->getPathCost(r, c-1) + newCost; + if ((min < 0) || (cost < min)) { + min = cost; + err.prevCost = m_m->getPathCost(r, c-1); + err.distance = newCost; + dir = Matcher::AdvanceOther; + } + } + + updateTo = min; + + } else if (c > rowStart) { // first row + // horizontal from (r,c-1) + dir = Matcher::AdvanceOther; + updateTo = m_m->getPathCost(r, c-1) + newCost; + } + + if (m_m->getPathCost(r, c) != updateTo) { + err.type = ErrorPosition::CostError; + err.r = r; + err.c = c; + err.advance = dir; + err.costWas = m_m->getPathCost(r, c); + err.costShouldBe = updateTo; + return err; + } + } + + prevRowStart = rowStart; + prevRowStop = rowStop; + } + + return err; +} + int Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy) {
--- a/src/Finder.h Thu Nov 20 16:44:06 2014 +0000 +++ b/src/Finder.h Thu Nov 27 08:13:29 2014 +0000 @@ -67,6 +67,20 @@ int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy); protected: + struct ErrorPosition { + enum Type { NoError = 0, CostError }; + ErrorPosition() : type(NoError) { } + Type type; + int r; + int c; + double prevCost; + float distance; + Matcher::Advance advance; + double costWas; + double costShouldBe; + }; + ErrorPosition checkPathCostMatrix(); + Matcher *m_m; int m_duration1; int m_duration2;