comparison src/Finder.cpp @ 147:3673e2dae6a7 structure

Factor out getBestEdgeCost
author Chris Cannam
date Thu, 22 Jan 2015 12:04:44 +0000
parents cfba9aec7569
children 4159f6b71942
comparison
equal deleted inserted replaced
146:214b72d55796 147:3673e2dae6a7
45 #endif 45 #endif
46 m_duration1 = d1; 46 m_duration1 = d1;
47 m_duration2 = d2; 47 m_duration2 = d2;
48 } 48 }
49 49
50 Matcher::Advance 50 void
51 Finder::getExpandDirection(int row, int col) 51 Finder::getBestEdgeCost(int row, int col,
52 { 52 int &bestRow, int &bestCol,
53 double min = m_m->getPathCost(row, col); 53 double &min)
54 54 {
55 int bestRow = row; 55 min = m_m->getPathCost(row, col);
56 int bestCol = col; 56
57 bestRow = row;
58 bestCol = col;
57 59
58 pair<int, int> rowRange = m_m->getRowRange(col); 60 pair<int, int> rowRange = m_m->getRowRange(col);
59 if (rowRange.second > row+1) { 61 if (rowRange.second > row+1) {
60 rowRange.second = row+1; // don't cheat by looking at future :) 62 rowRange.second = row+1; // don't cheat by looking at future :)
61 } 63 }
77 min = tmp; 79 min = tmp;
78 bestCol = index; 80 bestCol = index;
79 bestRow = row; 81 bestRow = row;
80 } 82 }
81 } 83 }
82 84 }
83 // cerr << "at [" << row << "," << col << "] (cost " << m_m->getPathCost(row, col) << ") blocksize = " << m_m->getBlockSize() << " best is [" << bestRow << "," << bestCol << "] (cost " << min << ")" << endl; 85
86 Matcher::Advance
87 Finder::getExpandDirection(int row, int col)
88 {
89 // To determine which direction to expand the search area in, we
90 // look at the path costs along the leading edges of the search
91 // area (the final row and column within the area). We find the
92 // lowest path cost within the final row, and the lowest within
93 // the final column, and we compare them. If the row is cheaper
94 // then we expand by adding another row next to it; if the column
95 // is cheaper then we expand by adding another column next to
96 // it. (The overall lowest path cost across the row and column
97 // represents the best alignment we have within the entire search
98 // area given the data available and the assumption that the piece
99 // is not ending yet.)
100
101 int bestRow = row;
102 int bestCol = col;
103 double bestCost = -1;
104
105 getBestEdgeCost(row, col, bestRow, bestCol, bestCost);
106
107 // cerr << "at [" << row << "," << col << "] (cost " << m_m->getPathCost(row, col) << ") blocksize = " << m_m->getBlockSize() << " best is [" << bestRow << "," << bestCol << "] (cost " << bestCost << ")" << endl;
84 108
85 if (bestRow == row) { 109 if (bestRow == row) {
86 if (bestCol == col) { 110 if (bestCol == col) {
87 return Matcher::AdvanceBoth; 111 return Matcher::AdvanceBoth;
88 } else { 112 } else {