Mercurial > hg > match-vamp
changeset 154:4159f6b71942 structure
More cost query methods
author | Chris Cannam |
---|---|
date | Fri, 23 Jan 2015 14:55:19 +0000 |
parents | fcf0dd0166b1 |
children | 2b61e0cb6847 |
files | src/Finder.cpp src/Finder.h src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h src/Matcher.cpp src/Matcher.h |
diffstat | 6 files changed, 106 insertions(+), 4 deletions(-) [+] |
line wrap: on
line diff
--- a/src/Finder.cpp Fri Jan 23 11:46:14 2015 +0000 +++ b/src/Finder.cpp Fri Jan 23 14:55:19 2015 +0000 @@ -38,6 +38,12 @@ } void +Finder::setMatcher(Matcher *pm) +{ + m_m = pm; +} + +void Finder::setDurations(int d1, int d2) { #ifdef DEBUG_FINDER @@ -47,6 +53,45 @@ m_duration2 = d2; } +bool +Finder::getBestRowCost(int row, int &bestCol, double &min) +{ + if (!m_m->isRowAvailable(row)) { + cerr << "row not available: " << row << endl; + return false; + } + pair<int, int> colRange = m_m->getColRange(row); + if (colRange.first >= colRange.second) { + cerr << "row " << row << " has invalid col range " << colRange.first + << " -> " << colRange.second << endl; + return false; + } + for (int index = colRange.first; index < colRange.second; index++) { + double tmp = m_m->getNormalisedPathCost(row, index); + if (index == colRange.first || tmp < min) { + min = tmp; + bestCol = index; + } + } + return true; +} + +bool +Finder::getBestColCost(int col, int &bestRow, double &min) +{ + if (!m_m->isColAvailable(col)) return false; + pair<int, int> rowRange = m_m->getRowRange(col); + if (rowRange.first >= rowRange.second) return false; + for (int index = rowRange.first; index < rowRange.second; index++) { + double tmp = m_m->getNormalisedPathCost(index, col); + if (index == rowRange.first || tmp < min) { + min = tmp; + bestRow = index; + } + } + return true; +} + void Finder::getBestEdgeCost(int row, int col, int &bestRow, int &bestCol,
--- a/src/Finder.h Fri Jan 23 11:46:14 2015 +0000 +++ b/src/Finder.h Fri Jan 23 14:55:19 2015 +0000 @@ -29,6 +29,8 @@ ~Finder(); + void setMatcher(Matcher *pm); + /** * Tell the finder that one or both files ends sooner than it * thought, i.e. that some of the trailing features are silence or @@ -39,6 +41,21 @@ void setDurations(int d1, int d2); /** + * Find the location and cost of the column with the cheapest path + * cost within the given row. If the row is out of range, return + * false and leave the bestCol and bestCost variables unchanged. + */ + bool getBestRowCost(int row, int &bestCol, double &bestCost); + + /** + * Find the location and cost of the row with the cheapest path + * cost within the given column. If the column is out of range, + * return false and leave the bestRow and bestCost variables + * unchanged. + */ + bool getBestColCost(int col, int &bestRow, double &bestCost); + + /** * Find the location and cost of the cheapest path cost within the * final row and column of the search area, given that the area * extends as far as the point at (row, col). This is used by
--- a/src/MatchFeatureFeeder.cpp Fri Jan 23 11:46:14 2015 +0000 +++ b/src/MatchFeatureFeeder.cpp Fri Jan 23 14:55:19 2015 +0000 @@ -30,6 +30,14 @@ } void +MatchFeatureFeeder::setMatchers(Matcher *m1, Matcher *m2) +{ + m_pm1 = m1; + m_pm2 = m2; + m_finder->setMatcher(m_pm1); +} + +void MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2) { // We maintain two FIFO queues of feature vectors, one per input
--- a/src/MatchFeatureFeeder.h Fri Jan 23 11:46:14 2015 +0000 +++ b/src/MatchFeatureFeeder.h Fri Jan 23 14:55:19 2015 +0000 @@ -28,6 +28,8 @@ MatchFeatureFeeder(Matcher *m1, Matcher *m2); ~MatchFeatureFeeder(); + void setMatchers(Matcher *m1, Matcher *m2); + /** * Feed the two supplied feature vectors to feeders 1 and 2 * respectively (depending on their advance status). Matchers must
--- a/src/Matcher.cpp Fri Jan 23 11:46:14 2015 +0000 +++ b/src/Matcher.cpp Fri Jan 23 14:55:19 2015 +0000 @@ -76,6 +76,26 @@ } bool +Matcher::isRowAvailable(int i) +{ + if (i < 0 || i >= int(m_first.size())) return false; + + for (int j = m_first[i]; j < int(m_first[i] + m_bestPathCost[i].size()); ++j) { + if (isAvailable(i, j)) { + return true; + } + } + + return false; +} + +bool +Matcher::isColAvailable(int i) +{ + return m_otherMatcher->isRowAvailable(i); +} + +bool Matcher::isInRange(int i, int j) { if (m_firstPM) {
--- a/src/Matcher.h Fri Jan 23 11:46:14 2015 +0000 +++ b/src/Matcher.h Fri Jan 23 14:55:19 2015 +0000 @@ -158,6 +158,14 @@ * @return true if the location is in range */ bool isInRange(int i, int j); + + /** Tests whether any locations in the given row are available. + */ + bool isRowAvailable(int i); + + /** Tests whether any locations in the given column are available. + */ + bool isColAvailable(int i); /** Tests whether a location is available in the minimum cost matrix. * @@ -167,8 +175,9 @@ */ bool isAvailable(int i, int j); - /** Returns the valid range of frames in the other Matcher for the - * given frame in this Matcher's minimum cost matrix. + /** Returns the valid range of columns for the given row, that is, + * the range of frames in the other Matcher for the given frame + * in this Matcher's minimum cost matrix. * * @param i the frame number of this Matcher * @return the first, last pair of frame numbers for the other @@ -177,8 +186,9 @@ */ std::pair<int, int> getColRange(int i); - /** Returns the valid range of frames in this Matcher for the - * given frame in the other Matcher's minimum cost matrix. + /** Returns the valid range of rows for the given column, that is, + * the range of frames in this Matcher for the given frame in the + * other Matcher's minimum cost matrix. * * @param i the frame number of the other Matcher * @return the first, last pair of frame numbers for this