Mercurial > hg > match-vamp
comparison src/Finder.cpp @ 59:fb6e4829c1af cheap_diagonals
Weight of sqrt(2) in both cases
author | Chris Cannam |
---|---|
date | Fri, 14 Nov 2014 12:35:36 +0000 |
parents | bbdcf79f3916 |
children | ad417dd05e0b |
comparison
equal
deleted
inserted
replaced
58:bbdcf79f3916 | 59:fb6e4829c1af |
---|---|
208 } // setPathCost() | 208 } // setPathCost() |
209 | 209 |
210 void | 210 void |
211 Finder::recalculatePathCostMatrix(int r1, int c1, int r2, int c2) | 211 Finder::recalculatePathCostMatrix(int r1, int c1, int r2, int c2) |
212 { | 212 { |
213 float diagonalWeight = sqrtf(2.f); | |
214 | |
213 if (!find(r1,c1)) { | 215 if (!find(r1,c1)) { |
214 std::cerr << "recalculatePathCostMatrix(" << r1 << "," << c1 << "): out of bounds" << std::endl; | 216 std::cerr << "recalculatePathCostMatrix(" << r1 << "," << c1 << "): out of bounds" << std::endl; |
215 throw "recalculatePathCostMatrix index out of bounds"; | 217 throw "recalculatePathCostMatrix index out of bounds"; |
216 } | 218 } |
217 int thisRowStart, c; | 219 int thisRowStart, c; |
228 if (r > r1) { // not first row | 230 if (r > r1) { // not first row |
229 double min = -1; | 231 double min = -1; |
230 if ((c > prevRowStart) && (c <= prevRowStop)) { | 232 if ((c > prevRowStart) && (c <= prevRowStop)) { |
231 // diagonal from (r-1,c-1) | 233 // diagonal from (r-1,c-1) |
232 min = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]-1] + | 234 min = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]-1] + |
233 newCost; | 235 newCost * diagonalWeight; |
234 dir = Matcher::AdvanceBoth; | 236 dir = Matcher::AdvanceBoth; |
235 } | 237 } |
236 if ((c >= prevRowStart) && (c < prevRowStop)) { | 238 if ((c >= prevRowStart) && (c < prevRowStop)) { |
237 // vertical from (r-1,c) | 239 // vertical from (r-1,c) |
238 double cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] + | 240 double cost = pm1->m_bestPathCost[r-1][c-pm1->m_first[r-1]] + |