changeset 167:28c73e5db2eb structure

Allow querying the best-estimate reference frame for the current feed point; don't heap-allocate finder
author Chris Cannam
date Thu, 05 Feb 2015 14:06:57 +0000
parents d6cdbd814c8c
children 70636e3c5a46
files src/Finder.h src/MatchFeatureFeeder.cpp src/MatchFeatureFeeder.h
diffstat 3 files changed, 36 insertions(+), 13 deletions(-) [+]
line wrap: on
line diff
--- a/src/Finder.h	Thu Jan 29 13:29:48 2015 +0000
+++ b/src/Finder.h	Thu Feb 05 14:06:57 2015 +0000
@@ -27,6 +27,8 @@
 public:
     Finder(Matcher *pm);
 
+    // default copy ctor and operator= are fine
+
     ~Finder();
 
     void setMatcher(Matcher *pm);
@@ -116,7 +118,7 @@
     ErrorPosition checkPathCostMatrix();
     void checkAndReport();
 #endif
-    
+
     Matcher *m_m;   // I do not own this
     
     int m_duration1;
--- a/src/MatchFeatureFeeder.cpp	Thu Jan 29 13:29:48 2015 +0000
+++ b/src/MatchFeatureFeeder.cpp	Thu Feb 05 14:06:57 2015 +0000
@@ -19,21 +19,21 @@
 using std::vector;
 
 MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) :
-    m_pm1(m1), m_pm2(m2)
+    m_pm1(m1),
+    m_pm2(m2),
+    m_finder(m_pm1)
 {
-    m_finder = new Finder(m1);
 }
 
 MatchFeatureFeeder::~MatchFeatureFeeder()
 {
-    delete m_finder;
 }
 
 MatchFeatureFeeder::MatchFeatureFeeder(const MatchFeatureFeeder &other) :
-    m_pm1(other.m_pm1), m_pm2(other.m_pm2)
+    m_pm1(other.m_pm1),
+    m_pm2(other.m_pm2),
+    m_finder(m_pm1)
 {
-    //!!! This is gross. Finder should probably not be heap allocated at all
-    m_finder = new Finder(*other.m_finder);
 }
 
 MatchFeatureFeeder &
@@ -41,7 +41,7 @@
 {
     m_pm1 = other.m_pm1;
     m_pm2 = other.m_pm2;
-    m_finder = new Finder(*other.m_finder);
+    m_finder = Finder(m_pm1);
     return *this;
 }
 
@@ -50,7 +50,7 @@
 {
     m_pm1 = m1;
     m_pm2 = m2;
-    m_finder->setMatcher(m_pm1);
+    m_finder.setMatcher(m_pm1);
 }
 
 void
@@ -75,6 +75,21 @@
     }
 }
 
+int
+MatchFeatureFeeder::getEstimatedReferenceFrame()
+{
+    if (m_pm1->getFrameCount() == 0 || m_pm2->getFrameCount() == 0) {
+        return 0;
+    }
+    int bestRow = 0;
+    double bestCost = 0;
+    if (!m_finder.getBestColCost(m_pm2->getFrameCount()-1, bestRow, bestCost)) {
+        return -1;
+    } else {
+        return bestRow;
+    }
+}
+
 void
 MatchFeatureFeeder::finish()
 {
@@ -98,7 +113,7 @@
     } else if (m_pm2->isOverrunning()) {
         feed1();
     } else {
-        switch (m_finder->getExpandDirection
+        switch (m_finder.getExpandDirection
                 (m_pm1->getFrameCount()-1, m_pm2->getFrameCount()-1)) {
         case Matcher::AdvanceThis:
             feed1();
--- a/src/MatchFeatureFeeder.h	Thu Jan 29 13:29:48 2015 +0000
+++ b/src/MatchFeatureFeeder.h	Thu Feb 05 14:06:57 2015 +0000
@@ -49,6 +49,12 @@
     void feed(std::vector<double> f1, std::vector<double> f2);
 
     /**
+     * Get the best estimate for the frame in the reference (f1)
+     * corresponding to the latest frame in the other input (f2).
+     */
+    int getEstimatedReferenceFrame();
+    
+    /**
      * Indicate that both inputs have come to an end.
      */
     void finish();
@@ -65,18 +71,18 @@
         pathy = m_fpy;
     }
 
-    Finder *getFinder() { return m_finder; }
+    Finder *getFinder() { return &m_finder; }
 
 protected:
     void feedBlock();
     void feed1();
     void feed2();
 
-    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
 
+    Finder m_finder; // I own this, and it refers to m_pm1
+    
     std::queue<std::vector<double> > m_q1;
     std::queue<std::vector<double> > m_q2;