Mercurial > hg > match-vamp
comparison src/Matcher.cpp @ 211:6373d14deace
Clip cost when adding increment in direction comparison as well as when updating
author | Chris Cannam |
---|---|
date | Fri, 27 Feb 2015 14:10:50 +0000 |
parents | d46be43c0738 |
children | 827176d3b6ec |
comparison
equal
deleted
inserted
replaced
210:96dc6a59e1ed | 211:6373d14deace |
---|---|
292 int frameIndex = m_frameCount % m_blockSize; | 292 int frameIndex = m_frameCount % m_blockSize; |
293 m_features[frameIndex] = feature; | 293 m_features[frameIndex] = feature; |
294 calcAdvance(); | 294 calcAdvance(); |
295 } | 295 } |
296 | 296 |
297 pathcost_t | |
298 Matcher::addToCost(pathcost_t cost, pathcost_t increment) | |
299 { | |
300 if (MaxPathCost - increment < cost) { | |
301 return MaxPathCost; | |
302 } else { | |
303 return cost + pathcost_t(increment); | |
304 } | |
305 } | |
306 | |
297 void | 307 void |
298 Matcher::calcAdvance() | 308 Matcher::calcAdvance() |
299 { | 309 { |
300 int frameIndex = m_frameCount % m_blockSize; | 310 int frameIndex = m_frameCount % m_blockSize; |
301 | 311 |
302 if (m_frameCount >= m_distXSize) { | 312 if (m_frameCount >= m_distXSize) { |
303 m_distXSize *= 1.2; | 313 m_distXSize = int(m_distXSize * 1.2); |
304 size(); | 314 size(); |
305 } | 315 } |
306 | 316 |
307 if (m_firstPM && (m_frameCount >= m_blockSize)) { | 317 if (m_firstPM && (m_frameCount >= m_blockSize)) { |
308 // Memory reduction for old rows | 318 // Memory reduction for old rows |
369 min2, distance); | 379 min2, distance); |
370 | 380 |
371 } else { | 381 } else { |
372 | 382 |
373 pathcost_t min1 = getPathCost(m_frameCount - 1, index - 1); | 383 pathcost_t min1 = getPathCost(m_frameCount - 1, index - 1); |
374 if (min1 + diagIncrement <= min2 + straightIncrement) { | 384 if (addToCost(min1, diagIncrement) <= |
385 addToCost(min2, straightIncrement)) { | |
375 updateValue(m_frameCount, index, AdvanceBoth, | 386 updateValue(m_frameCount, index, AdvanceBoth, |
376 min1, distance); | 387 min1, distance); |
377 } else { | 388 } else { |
378 updateValue(m_frameCount, index, AdvanceThis, | 389 updateValue(m_frameCount, index, AdvanceThis, |
379 min2, distance); | 390 min2, distance); |
384 | 395 |
385 pathcost_t min1 = getPathCost(m_frameCount, index - 1); | 396 pathcost_t min1 = getPathCost(m_frameCount, index - 1); |
386 pathcost_t min2 = getPathCost(m_frameCount - 1, index); | 397 pathcost_t min2 = getPathCost(m_frameCount - 1, index); |
387 pathcost_t min3 = getPathCost(m_frameCount - 1, index - 1); | 398 pathcost_t min3 = getPathCost(m_frameCount - 1, index - 1); |
388 | 399 |
389 pathcost_t cost1 = min1 + straightIncrement; | 400 pathcost_t cost1 = addToCost(min1, straightIncrement); |
390 pathcost_t cost2 = min2 + straightIncrement; | 401 pathcost_t cost2 = addToCost(min2, straightIncrement); |
391 pathcost_t cost3 = min3 + diagIncrement; | 402 pathcost_t cost3 = addToCost(min3, diagIncrement); |
392 | 403 |
393 // Choosing is easy if there is a strict cheapest of the | 404 // Choosing is easy if there is a strict cheapest of the |
394 // three. If two or more share the lowest cost, we choose | 405 // three. If two or more share the lowest cost, we choose |
395 // in order of preference: cost3 (AdvanceBoth), cost2 | 406 // in order of preference: cost3 (AdvanceBoth), cost2 |
396 // (AdvanceThis), cost1 (AdvanceOther) if we are the first | 407 // (AdvanceThis), cost1 (AdvanceOther) if we are the first |
434 pathcost_t increment = distance; | 445 pathcost_t increment = distance; |
435 if (dir == AdvanceBoth) { | 446 if (dir == AdvanceBoth) { |
436 increment = pathcost_t(increment * m_params.diagonalWeight); | 447 increment = pathcost_t(increment * m_params.diagonalWeight); |
437 } | 448 } |
438 | 449 |
439 pathcost_t newValue = value + increment; | 450 pathcost_t newValue = addToCost(value, increment); |
440 if (MaxPathCost - increment < value) { | 451 if (newValue == MaxPathCost) { |
441 cerr << "ERROR: Path cost overflow at i=" << i << ", j=" << j << ": " | 452 cerr << "ERROR: Path cost overflow at i=" << i << ", j=" << j << ": " |
442 << value << " + " << increment << " > " << MaxPathCost << endl; | 453 << value << " + " << increment << " >= " << MaxPathCost << endl; |
443 newValue = MaxPathCost; | 454 newValue = MaxPathCost; |
444 } | 455 } |
445 | 456 |
446 if (m_firstPM) { | 457 if (m_firstPM) { |
447 | 458 |