changeset 147:3673e2dae6a7 structure

Factor out getBestEdgeCost
author Chris Cannam
date Thu, 22 Jan 2015 12:04:44 +0000
parents 214b72d55796
children d307803083e6 4e7f8653c643
files src/Finder.cpp src/Finder.h src/MatchFeatureFeeder.h
diffstat 3 files changed, 54 insertions(+), 12 deletions(-) [+]
line wrap: on
line diff
--- a/src/Finder.cpp	Fri Jan 16 16:48:55 2015 +0000
+++ b/src/Finder.cpp	Thu Jan 22 12:04:44 2015 +0000
@@ -47,13 +47,15 @@
     m_duration2 = d2;
 }
 
-Matcher::Advance
-Finder::getExpandDirection(int row, int col)
+void
+Finder::getBestEdgeCost(int row, int col,
+                        int &bestRow, int &bestCol,
+                        double &min)
 {
-    double min = m_m->getPathCost(row, col);
+    min = m_m->getPathCost(row, col);
     
-    int bestRow = row;
-    int bestCol = col;
+    bestRow = row;
+    bestCol = col;
 
     pair<int, int> rowRange = m_m->getRowRange(col);
     if (rowRange.second > row+1) {
@@ -79,8 +81,30 @@
             bestRow = row;
         }
     }
+}
 
-//    cerr << "at [" << row << "," << col << "] (cost " << m_m->getPathCost(row, col) << ") blocksize = " << m_m->getBlockSize() << " best is [" << bestRow << "," << bestCol << "] (cost " << min << ")" << endl;
+Matcher::Advance
+Finder::getExpandDirection(int row, int col)
+{
+    // To determine which direction to expand the search area in, we
+    // look at the path costs along the leading edges of the search
+    // area (the final row and column within the area). We find the
+    // lowest path cost within the final row, and the lowest within
+    // the final column, and we compare them. If the row is cheaper
+    // then we expand by adding another row next to it; if the column
+    // is cheaper then we expand by adding another column next to
+    // it. (The overall lowest path cost across the row and column
+    // represents the best alignment we have within the entire search
+    // area given the data available and the assumption that the piece
+    // is not ending yet.)
+
+    int bestRow = row;
+    int bestCol = col;
+    double bestCost = -1;
+
+    getBestEdgeCost(row, col, bestRow, bestCol, bestCost);
+
+//    cerr << "at [" << row << "," << col << "] (cost " << m_m->getPathCost(row, col) << ") blocksize = " << m_m->getBlockSize() << " best is [" << bestRow << "," << bestCol << "] (cost " << bestCost << ")" << endl;
     
     if (bestRow == row) {
         if (bestCol == col) {
--- a/src/Finder.h	Fri Jan 16 16:48:55 2015 +0000
+++ b/src/Finder.h	Thu Jan 22 12:04:44 2015 +0000
@@ -37,7 +37,23 @@
      * duration of each input will be considered.
      */
     void setDurations(int d1, int d2);
-    
+
+    /**
+     * 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
+     * getExpandDirection and can also be used, for example, to
+     * determine the current best estimate alignment for a frame we
+     * have just reached.
+     */
+    void getBestEdgeCost(int row, int col,
+                         int &bestRow, int &bestCol,
+                         double &bestCost);
+
+    /**
+     * Calculate which direction to expand the search area in, given
+     * that so far it extends as far as the point at (row, col).
+     */
     Matcher::Advance getExpandDirection(int row, int col);
     
     /** Calculates a rectangle of the path cost matrix so that the
@@ -84,9 +100,10 @@
     void checkAndReport();
 #endif
     
-    Matcher *m_m;
+    Matcher *m_m;   // I do not own this
+    
     int m_duration1;
     int m_duration2;
-}; // class Finder
+};
 
 #endif
--- a/src/MatchFeatureFeeder.h	Fri Jan 16 16:48:55 2015 +0000
+++ b/src/MatchFeatureFeeder.h	Thu Jan 22 12:04:44 2015 +0000
@@ -67,9 +67,10 @@
     void feed1();
     void feed2();
 
-    Finder *m_finder;
-    Matcher *m_pm1;
-    Matcher *m_pm2;
+    Finder *m_finder; // I own this, and it refers to m_pm1 and m_pm2
+    
+    Matcher *m_pm1;   // I do not own this
+    Matcher *m_pm2;   // I do not own this
 
     std::queue<std::vector<double> > m_q1;
     std::queue<std::vector<double> > m_q2;