Mercurial > hg > match-vamp
changeset 82:3616d541d69e refactors
Error-checking code optional
author | Chris Cannam |
---|---|
date | Thu, 27 Nov 2014 10:14:07 +0000 |
parents | c603d77b00ac |
children | 10e76188c846 |
files | src/Finder.cpp src/Finder.h |
diffstat | 2 files changed, 53 insertions(+), 22 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Finder.cpp Thu Nov 27 08:13:29 2014 +0000 +++ b/src/Finder.cpp Thu Nov 27 10:14:07 2014 +0000 @@ -43,12 +43,6 @@ Matcher::Advance Finder::getExpandDirection(int row, int col) { - return getExpandDirection(row, col, false); -} // getExpandDirection() - -Matcher::Advance -Finder::getExpandDirection(int row, int col, bool check) -{ double min = m_m->getPathCost(row, col); int bestRow = row; @@ -148,9 +142,12 @@ } } +#ifdef PERFORM_ERROR_CHECKS Finder::ErrorPosition Finder::checkPathCostMatrix() { + cerr << "Finder: Checking path-cost matrix..." << endl; + ErrorPosition err; int r1 = 0; @@ -209,20 +206,38 @@ updateTo = min; - } else if (c > rowStart) { // first row - // horizontal from (r,c-1) - dir = Matcher::AdvanceOther; - updateTo = m_m->getPathCost(r, c-1) + newCost; + } else { // first row + + if (c > rowStart) { + // 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; + if (dir != Matcher::AdvanceNone) { + if (m_m->getPathCost(r, c) != updateTo) { + cerr << "CostError found" << endl; + 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; + } + } else { + // AdvanceNone should occur only at r = r1, c = c1 + if (r != r1 || c != c1) { + cerr << "AdvanceNone error found" << endl; + err.type = ErrorPosition::NoAdvance; + err.r = r; + err.c = c; + err.advance = dir; + err.costWas = m_m->getPathCost(r, c); + err.costShouldBe = updateTo; + return err; + } } } @@ -230,8 +245,10 @@ prevRowStop = rowStop; } + cerr << "No errors found" << endl; return err; -} +} +#endif int Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy) @@ -239,6 +256,19 @@ pathx.clear(); pathy.clear(); +#ifdef PERFORM_ERROR_CHECKS + ErrorPosition err = checkPathCostMatrix(); + if (err.type != ErrorPosition::NoError) { + cerr << "\nWARNING: Checking path-cost matrix returned mismatch:" << endl; + cerr << "Type: " << err.type << endl; + cerr << "At row " << err.r << ", column " << err.c << " advancing " + << err.advance << "\nPrev cost " << err.prevCost + << " plus distance " << err.distance << " gives " + << err.costShouldBe << ", but matrix contains " << err.costWas + << "\n" << endl; + } +#endif + int ex = m_m->getOtherFrameCount() - 1; int ey = m_m->getFrameCount() - 1;
--- a/src/Finder.h Thu Nov 27 08:13:29 2014 +0000 +++ b/src/Finder.h Thu Nov 27 10:14:07 2014 +0000 @@ -39,7 +39,6 @@ void setDurations(int d1, int d2); Matcher::Advance getExpandDirection(int row, int col); - Matcher::Advance getExpandDirection(int row, int col, bool check); /** Calculates a rectangle of the path cost matrix so that the * minimum cost path between the bottom left and top right @@ -67,8 +66,9 @@ int retrievePath(bool smooth, std::vector<int> &pathx, std::vector<int> &pathy); protected: +#ifdef PERFORM_ERROR_CHECKS struct ErrorPosition { - enum Type { NoError = 0, CostError }; + enum Type { NoError = 0, CostError, NoAdvance }; ErrorPosition() : type(NoError) { } Type type; int r; @@ -80,7 +80,8 @@ double costShouldBe; }; ErrorPosition checkPathCostMatrix(); - +#endif + Matcher *m_m; int m_duration1; int m_duration2;