comparison src/MatchFeatureFeeder.cpp @ 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 2b61e0cb6847
children 70636e3c5a46
comparison
equal deleted inserted replaced
158:d6cdbd814c8c 167:28c73e5db2eb
17 #include "MatchFeatureFeeder.h" 17 #include "MatchFeatureFeeder.h"
18 18
19 using std::vector; 19 using std::vector;
20 20
21 MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) : 21 MatchFeatureFeeder::MatchFeatureFeeder(Matcher *m1, Matcher *m2) :
22 m_pm1(m1), m_pm2(m2) 22 m_pm1(m1),
23 m_pm2(m2),
24 m_finder(m_pm1)
23 { 25 {
24 m_finder = new Finder(m1);
25 } 26 }
26 27
27 MatchFeatureFeeder::~MatchFeatureFeeder() 28 MatchFeatureFeeder::~MatchFeatureFeeder()
28 { 29 {
29 delete m_finder;
30 } 30 }
31 31
32 MatchFeatureFeeder::MatchFeatureFeeder(const MatchFeatureFeeder &other) : 32 MatchFeatureFeeder::MatchFeatureFeeder(const MatchFeatureFeeder &other) :
33 m_pm1(other.m_pm1), m_pm2(other.m_pm2) 33 m_pm1(other.m_pm1),
34 m_pm2(other.m_pm2),
35 m_finder(m_pm1)
34 { 36 {
35 //!!! This is gross. Finder should probably not be heap allocated at all
36 m_finder = new Finder(*other.m_finder);
37 } 37 }
38 38
39 MatchFeatureFeeder & 39 MatchFeatureFeeder &
40 MatchFeatureFeeder::operator=(const MatchFeatureFeeder &other) 40 MatchFeatureFeeder::operator=(const MatchFeatureFeeder &other)
41 { 41 {
42 m_pm1 = other.m_pm1; 42 m_pm1 = other.m_pm1;
43 m_pm2 = other.m_pm2; 43 m_pm2 = other.m_pm2;
44 m_finder = new Finder(*other.m_finder); 44 m_finder = Finder(m_pm1);
45 return *this; 45 return *this;
46 } 46 }
47 47
48 void 48 void
49 MatchFeatureFeeder::setMatchers(Matcher *m1, Matcher *m2) 49 MatchFeatureFeeder::setMatchers(Matcher *m1, Matcher *m2)
50 { 50 {
51 m_pm1 = m1; 51 m_pm1 = m1;
52 m_pm2 = m2; 52 m_pm2 = m2;
53 m_finder->setMatcher(m_pm1); 53 m_finder.setMatcher(m_pm1);
54 } 54 }
55 55
56 void 56 void
57 MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2) 57 MatchFeatureFeeder::feed(vector<double> f1, vector<double> f2)
58 { 58 {
70 m_q2.push(f2); 70 m_q2.push(f2);
71 } 71 }
72 72
73 while (!m_q1.empty() && !m_q2.empty()) { 73 while (!m_q1.empty() && !m_q2.empty()) {
74 feedBlock(); 74 feedBlock();
75 }
76 }
77
78 int
79 MatchFeatureFeeder::getEstimatedReferenceFrame()
80 {
81 if (m_pm1->getFrameCount() == 0 || m_pm2->getFrameCount() == 0) {
82 return 0;
83 }
84 int bestRow = 0;
85 double bestCost = 0;
86 if (!m_finder.getBestColCost(m_pm2->getFrameCount()-1, bestRow, bestCost)) {
87 return -1;
88 } else {
89 return bestRow;
75 } 90 }
76 } 91 }
77 92
78 void 93 void
79 MatchFeatureFeeder::finish() 94 MatchFeatureFeeder::finish()
96 } else if (m_pm1->isOverrunning()) { // slope constraints 111 } else if (m_pm1->isOverrunning()) { // slope constraints
97 feed2(); 112 feed2();
98 } else if (m_pm2->isOverrunning()) { 113 } else if (m_pm2->isOverrunning()) {
99 feed1(); 114 feed1();
100 } else { 115 } else {
101 switch (m_finder->getExpandDirection 116 switch (m_finder.getExpandDirection
102 (m_pm1->getFrameCount()-1, m_pm2->getFrameCount()-1)) { 117 (m_pm1->getFrameCount()-1, m_pm2->getFrameCount()-1)) {
103 case Matcher::AdvanceThis: 118 case Matcher::AdvanceThis:
104 feed1(); 119 feed1();
105 break; 120 break;
106 case Matcher::AdvanceOther: 121 case Matcher::AdvanceOther: