Mercurial > hg > match-vamp
changeset 182:a67663dc698d types
Start using properly-named types
author | Chris Cannam |
---|---|
date | Thu, 19 Feb 2015 16:57:19 +0000 |
parents | 8e7f96432570 |
children | 24ddab06aace |
files | Makefile.inc src/Finder.cpp src/Finder.h src/Matcher.cpp src/Matcher.h src/Types.h |
diffstat | 6 files changed, 104 insertions(+), 96 deletions(-) [+] |
line wrap: on
line diff
--- a/Makefile.inc Thu Feb 19 16:45:42 2015 +0000 +++ b/Makefile.inc Thu Feb 19 16:57:19 2015 +0000 @@ -37,27 +37,32 @@ # DO NOT DELETE src/DistanceMetric.o: src/DistanceMetric.h +src/Path.o: src/Path.h src/FeatureConditioner.o: src/FeatureConditioner.h -src/Path.o: src/Path.h src/MatchFeatureFeeder.o: src/MatchFeatureFeeder.h src/Matcher.h -src/MatchFeatureFeeder.o: src/DistanceMetric.h src/Finder.h +src/MatchFeatureFeeder.o: src/DistanceMetric.h src/Types.h src/Finder.h src/FeatureExtractor.o: src/FeatureExtractor.h -src/Finder.o: src/Finder.h src/Matcher.h src/DistanceMetric.h src/Path.h -src/Matcher.o: src/Matcher.h src/DistanceMetric.h +src/Finder.o: src/Finder.h src/Matcher.h src/DistanceMetric.h src/Types.h +src/Finder.o: src/Path.h +src/Matcher.o: src/Matcher.h src/DistanceMetric.h src/Types.h src/MatchPipeline.o: src/MatchPipeline.h src/Matcher.h src/DistanceMetric.h +src/MatchPipeline.o: src/Types.h src/Finder.h src/FeatureExtractor.h +src/MatchPipeline.o: src/FeatureConditioner.h src/MatchFeatureFeeder.h +src/MatchVampPlugin.o: src/MatchVampPlugin.h src/MatchPipeline.h +src/MatchVampPlugin.o: src/Matcher.h src/DistanceMetric.h src/Types.h +src/MatchVampPlugin.o: src/Finder.h src/FeatureExtractor.h +src/MatchVampPlugin.o: src/FeatureConditioner.h src/MatchFeatureFeeder.h +src/MatchVampPlugin.o: src/Path.h +src/MatchFeatureFeeder.o: src/Matcher.h src/DistanceMetric.h src/Types.h +src/MatchFeatureFeeder.o: src/Finder.h +src/Finder.o: src/Matcher.h src/DistanceMetric.h src/Types.h +src/Matcher.o: src/DistanceMetric.h src/Types.h +src/MatchPipeline.o: src/Matcher.h src/DistanceMetric.h src/Types.h src/MatchPipeline.o: src/Finder.h src/FeatureExtractor.h src/MatchPipeline.o: src/FeatureConditioner.h src/MatchFeatureFeeder.h -src/MatchVampPlugin.o: src/MatchVampPlugin.h src/MatchPipeline.h -src/MatchVampPlugin.o: src/Matcher.h src/DistanceMetric.h src/Finder.h -src/MatchVampPlugin.o: src/FeatureExtractor.h src/FeatureConditioner.h -src/MatchVampPlugin.o: src/MatchFeatureFeeder.h src/Path.h -src/MatchFeatureFeeder.o: src/Matcher.h src/DistanceMetric.h src/Finder.h -src/Finder.o: src/Matcher.h src/DistanceMetric.h -src/Matcher.o: src/DistanceMetric.h -src/MatchPipeline.o: src/Matcher.h src/DistanceMetric.h src/Finder.h -src/MatchPipeline.o: src/FeatureExtractor.h src/FeatureConditioner.h -src/MatchPipeline.o: src/MatchFeatureFeeder.h src/MatchVampPlugin.o: src/MatchPipeline.h src/Matcher.h src/DistanceMetric.h -src/MatchVampPlugin.o: src/Finder.h src/FeatureExtractor.h +src/MatchVampPlugin.o: src/Types.h src/Finder.h src/FeatureExtractor.h src/MatchVampPlugin.o: src/FeatureConditioner.h src/MatchFeatureFeeder.h +test/TestFeatureConditioner.o: src/FeatureConditioner.h +test/TestDistanceMetric.o: src/DistanceMetric.h test/TestFeatureExtractor.o: src/FeatureExtractor.h
--- a/src/Finder.cpp Thu Feb 19 16:45:42 2015 +0000 +++ b/src/Finder.cpp Thu Feb 19 16:57:19 2015 +0000 @@ -55,13 +55,13 @@ } bool -Finder::getBestRowCost(int row, int &bestCol, double &min) +Finder::getBestRowCost(int row, int &bestCol, pathcost_t &min) { if (!m_m->isRowAvailable(row)) return false; pair<int, int> colRange = m_m->getColRange(row); if (colRange.first >= colRange.second) return false; for (int index = colRange.first; index < colRange.second; index++) { - double tmp = m_m->getNormalisedPathCost(row, index); + pathcost_t tmp = m_m->getNormalisedPathCost(row, index); if (index == colRange.first || tmp < min) { min = tmp; bestCol = index; @@ -71,13 +71,13 @@ } bool -Finder::getBestColCost(int col, int &bestRow, double &min) +Finder::getBestColCost(int col, int &bestRow, pathcost_t &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); + pathcost_t tmp = m_m->getNormalisedPathCost(index, col); if (index == rowRange.first || tmp < min) { min = tmp; bestRow = index; @@ -89,7 +89,7 @@ void Finder::getBestEdgeCost(int row, int col, int &bestRow, int &bestCol, - double &min) + pathcost_t &min) { min = m_m->getPathCost(row, col); @@ -101,7 +101,7 @@ rowRange.second = row+1; // don't cheat by looking at future :) } for (int index = rowRange.first; index < rowRange.second; index++) { - double tmp = m_m->getNormalisedPathCost(index, col); + pathcost_t tmp = m_m->getNormalisedPathCost(index, col); if (tmp < min) { min = tmp; bestRow = index; @@ -113,7 +113,7 @@ colRange.second = col+1; // don't cheat by looking at future :) } for (int index = colRange.first; index < colRange.second; index++) { - double tmp = m_m->getNormalisedPathCost(row, index); + pathcost_t tmp = m_m->getNormalisedPathCost(row, index); if (tmp < min) { min = tmp; bestCol = index; @@ -146,7 +146,7 @@ int bestRow = row; int bestCol = col; - double bestCost = -1; + pathcost_t bestCost = -1; // cerr << "Finder " << this << "::getExpandDirection: "; @@ -183,19 +183,19 @@ for (int c = rowStart; c < rowStop; c++) { - float newCost = m_m->getDistance(r, c); + distance_t newStep = m_m->getDistance(r, c); advance_t dir = AdvanceNone; if (r > r1) { // not first row - double min = -1; + pathcost_t min = -1; if ((c > prevRowStart) && (c <= prevRowStop)) { // diagonal from (r-1,c-1) - min = m_m->getPathCost(r-1, c-1) + newCost * diagonalWeight; + min = m_m->getPathCost(r-1, c-1) + newStep * diagonalWeight; dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) { // vertical from (r-1,c) - double cost = m_m->getPathCost(r-1, c) + newCost; + pathcost_t cost = m_m->getPathCost(r-1, c) + newStep; if ((min < 0) || (cost < min)) { min = cost; dir = AdvanceThis; @@ -203,7 +203,7 @@ } if (c > rowStart) { // horizontal from (r,c-1) - double cost = m_m->getPathCost(r, c-1) + newCost; + pathcost_t cost = m_m->getPathCost(r, c-1) + newStep; if ((min < 0) || (cost < min)) { min = cost; dir = AdvanceOther; @@ -215,7 +215,7 @@ } else if (c > rowStart) { // first row // horizontal from (r,c-1) m_m->setPathCost(r, c, AdvanceOther, - m_m->getPathCost(r, c-1) + newCost); + m_m->getPathCost(r, c-1) + newStep); } } @@ -252,36 +252,36 @@ for (int c = rowStart; c < rowStop; c++) { - float newCost = m_m->getDistance(r, c); - double updateTo = -1.0; + distance_t newStep = m_m->getDistance(r, c); + pathcost_t updateTo = -1.0; advance_t dir = AdvanceNone; if (r > r1) { // not first row - double min = -1; + pathcost_t min = -1; if ((c > prevRowStart) && (c <= prevRowStop)) { // diagonal from (r-1,c-1) - min = m_m->getPathCost(r-1, c-1) + newCost * diagonalWeight; + min = m_m->getPathCost(r-1, c-1) + newStep * diagonalWeight; err.prevCost = m_m->getPathCost(r-1, c-1); - err.distance = newCost * diagonalWeight; + err.distance = newStep * diagonalWeight; dir = AdvanceBoth; } if ((c >= prevRowStart) && (c < prevRowStop)) { // vertical from (r-1,c) - double cost = m_m->getPathCost(r-1, c) + newCost; + pathcost_t cost = m_m->getPathCost(r-1, c) + newStep; if ((min < 0) || (cost < min)) { min = cost; err.prevCost = m_m->getPathCost(r-1, c); - err.distance = newCost; + err.distance = newStep; dir = AdvanceThis; } } if (c > rowStart) { // horizontal from (r,c-1) - double cost = m_m->getPathCost(r, c-1) + newCost; + pathcost_t cost = m_m->getPathCost(r, c-1) + newStep; if ((min < 0) || (cost < min)) { min = cost; err.prevCost = m_m->getPathCost(r, c-1); - err.distance = newCost; + err.distance = newStep; dir = AdvanceOther; } } @@ -292,9 +292,9 @@ if (c > rowStart) { // horizontal from (r,c-1) - updateTo = m_m->getPathCost(r, c-1) + newCost; + updateTo = m_m->getPathCost(r, c-1) + newStep; err.prevCost = m_m->getPathCost(r, c-1); - err.distance = newCost; + err.distance = newStep; dir = AdvanceOther; } } @@ -407,7 +407,7 @@ } #endif -double +pathcost_t Finder::getOverallCost() { int ex = m_m->getOtherFrameCount() - 1;
--- a/src/Finder.h Thu Feb 19 16:45:42 2015 +0000 +++ b/src/Finder.h Thu Feb 19 16:57:19 2015 +0000 @@ -47,7 +47,7 @@ * 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); + bool getBestRowCost(int row, int &bestCol, pathcost_t &bestCost); /** * Find the location and cost of the row with the cheapest path @@ -55,7 +55,7 @@ * return false and leave the bestRow and bestCost variables * unchanged. */ - bool getBestColCost(int col, int &bestRow, double &bestCost); + bool getBestColCost(int col, int &bestRow, pathcost_t &bestCost); /** * Find the location and cost of the cheapest path cost within the @@ -67,7 +67,7 @@ */ void getBestEdgeCost(int row, int col, int &bestRow, int &bestCol, - double &bestCost); + pathcost_t &bestCost); /** * Calculate which direction to expand the search area in, given @@ -110,7 +110,7 @@ * Get the path cost for the overall path to the end of both * sources. */ - double getOverallCost(); + pathcost_t getOverallCost(); protected: #ifdef PERFORM_ERROR_CHECKS @@ -120,10 +120,10 @@ Type type; int r; int c; - double prevCost; - float distance; - double costWas; - double costShouldBe; + pathcost_t prevCost; + distance_t distance; + pathcost_t costWas; + pathcost_t costShouldBe; advance_t advanceWas; advance_t advanceShouldBe; };
--- a/src/Matcher.cpp Thu Feb 19 16:45:42 2015 +0000 +++ b/src/Matcher.cpp Thu Feb 19 16:57:19 2015 +0000 @@ -63,7 +63,7 @@ { if (m_initialised) return; - m_frames = vector<vector<double> >(m_blockSize); + m_features = featureseq_t(m_blockSize); m_distXSize = m_blockSize * 2; @@ -140,7 +140,7 @@ return m_otherMatcher->getColRange(i); } -float +distance_t Matcher::getDistance(int i, int j) { if (m_firstPM) { @@ -149,7 +149,7 @@ << "Location is not in range" << endl; throw "Distance not available"; } - float dist = m_distance[i][j - m_first[i]]; + distance_t dist = m_distance[i][j - m_first[i]]; if (dist < 0) { cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " << "Location is in range, but distance (" @@ -163,7 +163,7 @@ } void -Matcher::setDistance(int i, int j, float distance) +Matcher::setDistance(int i, int j, distance_t distance) { if (m_firstPM) { if (!isInRange(i, j)) { @@ -177,14 +177,14 @@ } } -double +pathcost_t Matcher::getNormalisedPathCost(int i, int j) { // normalised for path length. 1+ prevents division by zero here return getPathCost(i, j) / (1 + i + j); } -double +pathcost_t Matcher::getPathCost(int i, int j) { if (m_firstPM) { @@ -207,7 +207,7 @@ } void -Matcher::setPathCost(int i, int j, advance_t dir, double pathCost) +Matcher::setPathCost(int i, int j, advance_t dir, pathcost_t pathCost) { if (m_firstPM) { if (!isInRange(i, j)) { @@ -233,19 +233,19 @@ Matcher::size() { int distSize = (m_params.maxRunCount + 1) * m_blockSize; - m_bestPathCost.resize(m_distXSize, vector<double>(distSize, -1)); - m_distance.resize(m_distXSize, vector<float>(distSize, -1)); - m_advance.resize(m_distXSize, vector<advance_t>(distSize, AdvanceNone)); + m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, -1)); + m_distance.resize(m_distXSize, distancevec_t(distSize, -1)); + m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone)); m_first.resize(m_distXSize, 0); m_last.resize(m_distXSize, 0); } void -Matcher::consumeFeatureVector(vector<double> feature) +Matcher::consumeFeatureVector(const feature_t &feature) { if (!m_initialised) init(); int frameIndex = m_frameCount % m_blockSize; - m_frames[frameIndex] = feature; + m_features[frameIndex] = feature; calcAdvance(); } @@ -269,14 +269,14 @@ // distance[m_frameCount-m_blockSize] to its first len elements. // Same for bestPathCost. - vector<float> dOld = m_distance[m_frameCount - m_blockSize]; - vector<float> dNew(len, -1.f); + distancevec_t dOld(m_distance[m_frameCount - m_blockSize]); + distancevec_t dNew(len, -1.f); - vector<double> bpcOld = m_bestPathCost[m_frameCount - m_blockSize]; - vector<double> bpcNew(len, -1.0); + pathcostvec_t bpcOld(m_bestPathCost[m_frameCount - m_blockSize]); + pathcostvec_t bpcNew(len, -1.0); - vector<advance_t> adOld = m_advance[m_frameCount - m_blockSize]; - vector<advance_t> adNew(len, AdvanceNone); + advancevec_t adOld(m_advance[m_frameCount - m_blockSize]); + advancevec_t adNew(len, AdvanceNone); for (int i = 0; i < len; ++i) { dNew[i] = dOld[i]; @@ -303,11 +303,11 @@ for ( ; index < stop; index++) { - float distance = (float) m_metric.calcDistance - (m_frames[frameIndex], - m_otherMatcher->m_frames[index % m_blockSize]); + distance_t distance = (distance_t) m_metric.calcDistance + (m_features[frameIndex], + m_otherMatcher->m_features[index % m_blockSize]); - float diagDistance = distance * m_params.diagonalWeight; + distance_t diagDistance = distance * m_params.diagonalWeight; if ((m_frameCount == 0) && (index == 0)) { // first element @@ -333,7 +333,7 @@ // - no previous value in current row (resp. column) // - no diagonal value if prev. dir. == curr. dirn - double min2 = getPathCost(m_frameCount - 1, index); + pathcost_t min2 = getPathCost(m_frameCount - 1, index); // cerr << "NOTE: missing value at i = " << m_frameCount << ", j = " // << index << " (first = " << m_firstPM << ")" << endl; @@ -347,7 +347,7 @@ } else { - double min1 = getPathCost(m_frameCount - 1, index - 1); + pathcost_t min1 = getPathCost(m_frameCount - 1, index - 1); if (min1 + diagDistance <= min2 + distance) { updateValue(m_frameCount, index, AdvanceBoth, min1, distance); @@ -359,13 +359,13 @@ } else { - double min1 = getPathCost(m_frameCount, index - 1); - double min2 = getPathCost(m_frameCount - 1, index); - double min3 = getPathCost(m_frameCount - 1, index - 1); + pathcost_t min1 = getPathCost(m_frameCount, index - 1); + pathcost_t min2 = getPathCost(m_frameCount - 1, index); + pathcost_t min3 = getPathCost(m_frameCount - 1, index - 1); - double cost1 = min1 + distance; - double cost2 = min2 + distance; - double cost3 = min3 + diagDistance; + pathcost_t cost1 = min1 + distance; + pathcost_t cost2 = min2 + distance; + pathcost_t cost3 = min3 + diagDistance; // Choosing is easy if there is a strict cheapest of the // three. If two or more share the lowest cost, we choose @@ -406,9 +406,9 @@ } void -Matcher::updateValue(int i, int j, advance_t dir, double value, float distance) +Matcher::updateValue(int i, int j, advance_t dir, pathcost_t value, distance_t distance) { - float weighted = distance; + distance_t weighted = distance; if (dir == AdvanceBoth) { weighted *= m_params.diagonalWeight; }
--- a/src/Matcher.h Thu Feb 19 16:45:42 2015 +0000 +++ b/src/Matcher.h Thu Feb 19 16:57:19 2015 +0000 @@ -148,7 +148,7 @@ * The supplied features must always be of the same size (within * any pair of Matcher objects). */ - void consumeFeatureVector(std::vector<double> feature); + void consumeFeatureVector(const feature_t &feature); /** Tests whether a location is in range in the minimum cost matrix. * @@ -202,7 +202,7 @@ * @param j the frame number of the other Matcher * @return the distance metric at this location */ - float getDistance(int i, int j); + distance_t getDistance(int i, int j); /** Sets a value to the distance matrix. * @@ -210,7 +210,7 @@ * @param j the frame number of the other Matcher * @param value the distance metric to set for this location */ - void setDistance(int i, int j, float distance); + void setDistance(int i, int j, distance_t distance); /** Retrieves a value from the minimum cost matrix. * @@ -218,7 +218,7 @@ * @param j the frame number of the other Matcher * @return the cost of the minimum cost path to this location */ - double getPathCost(int i, int j); + pathcost_t getPathCost(int i, int j); /** Sets a value and an advance direction to the minimum cost matrix. * @@ -228,7 +228,7 @@ * minimum cost * @param value the cost of the minimum cost path to set for this location */ - void setPathCost(int i, int j, advance_t dir, double value); + void setPathCost(int i, int j, advance_t dir, pathcost_t value); /** Retrieves a value from the minimum cost matrix, normalised for * path length. @@ -238,7 +238,7 @@ * @return the cost of the minimum cost path to this location, * normalised by the Manhattan distance from 0,0 to i,j */ - double getNormalisedPathCost(int i, int j); + pathcost_t getNormalisedPathCost(int i, int j); /** Retrieves an advance direction from the matrix. * @@ -265,7 +265,7 @@ * @param value the cost of the minimum path except the current step * @param dMN the distance cost between the two frames */ - void updateValue(int i, int j, advance_t dir, double value, float dMN); + void updateValue(int i, int j, advance_t dir, pathcost_t value, distance_t dMN); void calcAdvance(); @@ -301,16 +301,16 @@ * structure for calculation of the distance matrix as the new * frames are received. One can think of the structure of the * array as a circular buffer of vectors. */ - vector<vector<double> > m_frames; + featureseq_t m_features; /** The best path cost matrix. */ - vector<vector<double> > m_bestPathCost; + pathcostmat_t m_bestPathCost; /** The distance matrix. */ - vector<vector<float> > m_distance; + distancemat_t m_distance; /** The advance direction matrix. */ - vector<vector<advance_t> > m_advance; + advancemat_t m_advance; /** The bounds of each row of data in the distance, path cost, and * advance direction matrices.*/
--- a/src/Types.h Thu Feb 19 16:45:42 2015 +0000 +++ b/src/Types.h Thu Feb 19 16:57:19 2015 +0000 @@ -24,23 +24,26 @@ /// A feature vector typedef std::vector<featurebin_t> feature_t; +/// A sequence of feature vectors +typedef std::vector<feature_t> featureseq_t; + /// The distance between two feature vectors typedef float distance_t; /// A distance vector -typedef std::vector<distance_t> distvec_t; +typedef std::vector<distance_t> distancevec_t; /// A distance matrix -typedef std::vector<distvec_t> distmat_t; +typedef std::vector<distancevec_t> distancemat_t; /// The integrated distance (path cost) from the origin to a given point typedef double pathcost_t; /// A vector of path costs -typedef std::vector<pathcost_t> pathvec_t; +typedef std::vector<pathcost_t> pathcostvec_t; /// A matrix of path costs -typedef std::vector<pathcost_t> pathmat_t; +typedef std::vector<pathcostvec_t> pathcostmat_t; /// A direction advance instruction or state enum advance_t {