Mercurial > hg > match-vamp
comparison src/Matcher.cpp @ 212:827176d3b6ec
Naming
author | Chris Cannam |
---|---|
date | Fri, 27 Feb 2015 14:14:42 +0000 |
parents | 6373d14deace |
children | 97cc0b9135e7 |
comparison
equal
deleted
inserted
replaced
211:6373d14deace | 212:827176d3b6ec |
---|---|
79 bool | 79 bool |
80 Matcher::isAvailable(int i, int j) | 80 Matcher::isAvailable(int i, int j) |
81 { | 81 { |
82 if (m_firstPM) { | 82 if (m_firstPM) { |
83 if (isInRange(i, j)) { | 83 if (isInRange(i, j)) { |
84 return (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost); | 84 return (m_bestPathCost[i][j - m_first[i]] != INVALID_PATHCOST); |
85 } else { | 85 } else { |
86 return false; | 86 return false; |
87 } | 87 } |
88 } else { | 88 } else { |
89 return m_otherMatcher->isAvailable(j, i); | 89 return m_otherMatcher->isAvailable(j, i); |
95 { | 95 { |
96 if (m_firstPM) { | 96 if (m_firstPM) { |
97 | 97 |
98 if (i < 0 || i >= int(m_first.size())) return false; | 98 if (i < 0 || i >= int(m_first.size())) return false; |
99 for (auto c: m_bestPathCost[i]) { | 99 for (auto c: m_bestPathCost[i]) { |
100 if (c != InvalidPathCost) return true; | 100 if (c != INVALID_PATHCOST) return true; |
101 } | 101 } |
102 return false; | 102 return false; |
103 | 103 |
104 } else { | 104 } else { |
105 return m_otherMatcher->isColAvailable(i); | 105 return m_otherMatcher->isColAvailable(i); |
110 Matcher::isColAvailable(int j) | 110 Matcher::isColAvailable(int j) |
111 { | 111 { |
112 if (m_firstPM) { | 112 if (m_firstPM) { |
113 for (int i = 0; i < int(m_first.size()); ++i) { | 113 for (int i = 0; i < int(m_first.size()); ++i) { |
114 if (j >= m_first[i] && j < m_last[i]) { | 114 if (j >= m_first[i] && j < m_last[i]) { |
115 if (m_bestPathCost[i][j - m_first[i]] != InvalidPathCost) { | 115 if (m_bestPathCost[i][j - m_first[i]] != INVALID_PATHCOST) { |
116 return true; | 116 return true; |
117 } | 117 } |
118 } | 118 } |
119 } | 119 } |
120 return false; | 120 return false; |
182 throw "Distance not available"; | 182 throw "Distance not available"; |
183 } | 183 } |
184 #endif | 184 #endif |
185 distance_t dist = m_distance[i][j - m_first[i]]; | 185 distance_t dist = m_distance[i][j - m_first[i]]; |
186 #ifdef PERFORM_ERROR_CHECKS | 186 #ifdef PERFORM_ERROR_CHECKS |
187 if (dist == InvalidDistance) { | 187 if (dist == INVALID_DISTANCE) { |
188 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " | 188 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " |
189 << "Location is in range, but distance (" | 189 << "Location is in range, but distance (" |
190 << distance_print_t(dist) | 190 << distance_print_t(dist) |
191 << ") is invalid or has not been set" << endl; | 191 << ") is invalid or has not been set" << endl; |
192 throw "Distance not available"; | 192 throw "Distance not available"; |
277 m_first.resize(m_distXSize, 0); | 277 m_first.resize(m_distXSize, 0); |
278 m_last.resize(m_distXSize, 0); | 278 m_last.resize(m_distXSize, 0); |
279 | 279 |
280 if (m_firstPM) { | 280 if (m_firstPM) { |
281 int distSize = (m_params.maxRunCount + 1) * m_blockSize; | 281 int distSize = (m_params.maxRunCount + 1) * m_blockSize; |
282 m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, InvalidPathCost)); | 282 m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, INVALID_PATHCOST)); |
283 m_distance.resize(m_distXSize, distancevec_t(distSize, InvalidDistance)); | 283 m_distance.resize(m_distXSize, distancevec_t(distSize, INVALID_DISTANCE)); |
284 m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone)); | 284 m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone)); |
285 } | 285 } |
286 } | 286 } |
287 | 287 |
288 void | 288 void |
295 } | 295 } |
296 | 296 |
297 pathcost_t | 297 pathcost_t |
298 Matcher::addToCost(pathcost_t cost, pathcost_t increment) | 298 Matcher::addToCost(pathcost_t cost, pathcost_t increment) |
299 { | 299 { |
300 if (MaxPathCost - increment < cost) { | 300 if (PATHCOST_MAX - increment < cost) { |
301 return MaxPathCost; | 301 return PATHCOST_MAX; |
302 } else { | 302 } else { |
303 return cost + pathcost_t(increment); | 303 return cost + pathcost_t(increment); |
304 } | 304 } |
305 } | 305 } |
306 | 306 |
446 if (dir == AdvanceBoth) { | 446 if (dir == AdvanceBoth) { |
447 increment = pathcost_t(increment * m_params.diagonalWeight); | 447 increment = pathcost_t(increment * m_params.diagonalWeight); |
448 } | 448 } |
449 | 449 |
450 pathcost_t newValue = addToCost(value, increment); | 450 pathcost_t newValue = addToCost(value, increment); |
451 if (newValue == MaxPathCost) { | 451 if (newValue == PATHCOST_MAX) { |
452 cerr << "ERROR: Path cost overflow at i=" << i << ", j=" << j << ": " | 452 cerr << "ERROR: Path cost overflow at i=" << i << ", j=" << j << ": " |
453 << value << " + " << increment << " >= " << MaxPathCost << endl; | 453 << value << " + " << increment << " >= " << PATHCOST_MAX << endl; |
454 newValue = MaxPathCost; | 454 newValue = PATHCOST_MAX; |
455 } | 455 } |
456 | 456 |
457 if (m_firstPM) { | 457 if (m_firstPM) { |
458 | 458 |
459 setDistance(i, j, distance); | 459 setDistance(i, j, distance); |
469 if (idx < 0 || size_t(idx) == m_otherMatcher->m_distance[j].size()) { | 469 if (idx < 0 || size_t(idx) == m_otherMatcher->m_distance[j].size()) { |
470 // This should never happen, but if we allow arbitrary | 470 // This should never happen, but if we allow arbitrary |
471 // pauses in either direction, and arbitrary lengths at | 471 // pauses in either direction, and arbitrary lengths at |
472 // end, it is better than a segmentation fault. | 472 // end, it is better than a segmentation fault. |
473 cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl; | 473 cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl; |
474 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, InvalidPathCost); | 474 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, INVALID_PATHCOST); |
475 m_otherMatcher->m_distance[j].resize(idx * 2, InvalidDistance); | 475 m_otherMatcher->m_distance[j].resize(idx * 2, INVALID_DISTANCE); |
476 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); | 476 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); |
477 } | 477 } |
478 | 478 |
479 m_otherMatcher->setDistance(j, i, distance); | 479 m_otherMatcher->setDistance(j, i, distance); |
480 m_otherMatcher->setPathCost(j, i, dir, newValue); | 480 m_otherMatcher->setPathCost(j, i, dir, newValue); |