comparison src/Matcher.cpp @ 183:24ddab06aace re-minimise

Toward allowing types to be small again. Doesn't currently build
author Chris Cannam
date Thu, 19 Feb 2015 17:17:20 +0000
parents a67663dc698d
children 487261a22b18
comparison
equal deleted inserted replaced
182:a67663dc698d 183:24ddab06aace
148 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " 148 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
149 << "Location is not in range" << endl; 149 << "Location is not in range" << endl;
150 throw "Distance not available"; 150 throw "Distance not available";
151 } 151 }
152 distance_t dist = m_distance[i][j - m_first[i]]; 152 distance_t dist = m_distance[i][j - m_first[i]];
153 if (dist < 0) { 153 if (dist == InvalidDistance) {
154 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): " 154 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
155 << "Location is in range, but distance (" 155 << "Location is in range, but distance ("
156 << dist << ") is invalid or has not been set" << endl; 156 << dist << ") is invalid or has not been set" << endl;
157 throw "Distance not available"; 157 throw "Distance not available";
158 } 158 }
231 231
232 void 232 void
233 Matcher::size() 233 Matcher::size()
234 { 234 {
235 int distSize = (m_params.maxRunCount + 1) * m_blockSize; 235 int distSize = (m_params.maxRunCount + 1) * m_blockSize;
236 m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, -1)); 236 m_bestPathCost.resize(m_distXSize, pathcostvec_t(distSize, InvalidPathCost));
237 m_distance.resize(m_distXSize, distancevec_t(distSize, -1)); 237 m_distance.resize(m_distXSize, distancevec_t(distSize, InvalidDistance));
238 m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone)); 238 m_advance.resize(m_distXSize, advancevec_t(distSize, AdvanceNone));
239 m_first.resize(m_distXSize, 0); 239 m_first.resize(m_distXSize, 0);
240 m_last.resize(m_distXSize, 0); 240 m_last.resize(m_distXSize, 0);
241 } 241 }
242 242
268 // distance[m_frameCount], and then truncate 268 // distance[m_frameCount], and then truncate
269 // distance[m_frameCount-m_blockSize] to its first len elements. 269 // distance[m_frameCount-m_blockSize] to its first len elements.
270 // Same for bestPathCost. 270 // Same for bestPathCost.
271 271
272 distancevec_t dOld(m_distance[m_frameCount - m_blockSize]); 272 distancevec_t dOld(m_distance[m_frameCount - m_blockSize]);
273 distancevec_t dNew(len, -1.f); 273 distancevec_t dNew(len, InvalidDistance);
274 274
275 pathcostvec_t bpcOld(m_bestPathCost[m_frameCount - m_blockSize]); 275 pathcostvec_t bpcOld(m_bestPathCost[m_frameCount - m_blockSize]);
276 pathcostvec_t bpcNew(len, -1.0); 276 pathcostvec_t bpcNew(len, InvalidPathCost);
277 277
278 advancevec_t adOld(m_advance[m_frameCount - m_blockSize]); 278 advancevec_t adOld(m_advance[m_frameCount - m_blockSize]);
279 advancevec_t adNew(len, AdvanceNone); 279 advancevec_t adNew(len, AdvanceNone);
280 280
281 for (int i = 0; i < len; ++i) { 281 for (int i = 0; i < len; ++i) {
305 305
306 distance_t distance = (distance_t) m_metric.calcDistance 306 distance_t distance = (distance_t) m_metric.calcDistance
307 (m_features[frameIndex], 307 (m_features[frameIndex],
308 m_otherMatcher->m_features[index % m_blockSize]); 308 m_otherMatcher->m_features[index % m_blockSize]);
309 309
310 distance_t diagDistance = distance * m_params.diagonalWeight; 310 distance_t diagDistance = distance_t(distance * m_params.diagonalWeight);
311 311
312 if ((m_frameCount == 0) && (index == 0)) { // first element 312 if ((m_frameCount == 0) && (index == 0)) { // first element
313 313
314 updateValue(0, 0, AdvanceNone, 314 updateValue(0, 0, AdvanceNone,
315 0, 315 0,
408 void 408 void
409 Matcher::updateValue(int i, int j, advance_t dir, pathcost_t value, distance_t distance) 409 Matcher::updateValue(int i, int j, advance_t dir, pathcost_t value, distance_t distance)
410 { 410 {
411 distance_t weighted = distance; 411 distance_t weighted = distance;
412 if (dir == AdvanceBoth) { 412 if (dir == AdvanceBoth) {
413 weighted *= m_params.diagonalWeight; 413 weighted = distance_t(weighted * m_params.diagonalWeight);
414 } 414 }
415 415
416 if (m_firstPM) { 416 if (m_firstPM) {
417 417
418 setDistance(i, j, distance); 418 setDistance(i, j, distance);
428 if (idx == (int)m_otherMatcher->m_distance[j].size()) { 428 if (idx == (int)m_otherMatcher->m_distance[j].size()) {
429 // This should never happen, but if we allow arbitrary 429 // This should never happen, but if we allow arbitrary
430 // pauses in either direction, and arbitrary lengths at 430 // pauses in either direction, and arbitrary lengths at
431 // end, it is better than a segmentation fault. 431 // end, it is better than a segmentation fault.
432 cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl; 432 cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl;
433 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, -1); 433 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, InvalidPathCost);
434 m_otherMatcher->m_distance[j].resize(idx * 2, -1); 434 m_otherMatcher->m_distance[j].resize(idx * 2, InvalidDistance);
435 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); 435 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone);
436 } 436 }
437 437
438 m_otherMatcher->setDistance(j, i, distance); 438 m_otherMatcher->setDistance(j, i, distance);
439 m_otherMatcher->setPathCost(j, i, dir, value + weighted); 439 m_otherMatcher->setPathCost(j, i, dir, value + weighted);