Mercurial > hg > match-vamp
comparison src/Finder.cpp @ 92:c665173b3a33 refactors
Improve error reporting
author | Chris Cannam |
---|---|
date | Thu, 27 Nov 2014 15:29:43 +0000 |
parents | 7bb586054b16 |
children | bc3b60d65a5f |
comparison
equal
deleted
inserted
replaced
91:35e50f28720f | 92:c665173b3a33 |
---|---|
17 #include "Finder.h" | 17 #include "Finder.h" |
18 | 18 |
19 #include "Path.h" | 19 #include "Path.h" |
20 | 20 |
21 #include <algorithm> | 21 #include <algorithm> |
22 #include <iomanip> | |
22 | 23 |
23 using namespace std; | 24 using namespace std; |
24 | 25 |
25 Finder::Finder(Matcher *pm) | 26 Finder::Finder(Matcher *pm) |
26 { | 27 { |
146 | 147 |
147 #ifdef PERFORM_ERROR_CHECKS | 148 #ifdef PERFORM_ERROR_CHECKS |
148 Finder::ErrorPosition | 149 Finder::ErrorPosition |
149 Finder::checkPathCostMatrix() | 150 Finder::checkPathCostMatrix() |
150 { | 151 { |
151 cerr << "Finder: Checking path-cost matrix..." << endl; | |
152 | |
153 ErrorPosition err; | 152 ErrorPosition err; |
154 | 153 |
155 int r1 = 0; | 154 int r1 = 0; |
156 int c1 = 0; | 155 int c1 = 0; |
157 int r2 = m_m->getFrameCount() - 1; | 156 int r2 = m_m->getFrameCount() - 1; |
221 } | 220 } |
222 } | 221 } |
223 | 222 |
224 if (dir != Matcher::AdvanceNone) { | 223 if (dir != Matcher::AdvanceNone) { |
225 if (m_m->getAdvance(r, c) != dir) { | 224 if (m_m->getAdvance(r, c) != dir) { |
226 cerr << "WrongAdvance found" << endl; | |
227 err.type = ErrorPosition::WrongAdvance; | 225 err.type = ErrorPosition::WrongAdvance; |
228 err.r = r; | 226 err.r = r; |
229 err.c = c; | 227 err.c = c; |
230 err.costWas = m_m->getPathCost(r, c); | 228 err.costWas = m_m->getPathCost(r, c); |
231 err.costShouldBe = updateTo; | 229 err.costShouldBe = updateTo; |
232 err.advanceWas = m_m->getAdvance(r, c); | 230 err.advanceWas = m_m->getAdvance(r, c); |
233 err.advanceShouldBe = dir; | 231 err.advanceShouldBe = dir; |
234 return err; | 232 return err; |
235 } | 233 } |
236 if (m_m->getPathCost(r, c) != updateTo) { | 234 if (m_m->getPathCost(r, c) != updateTo) { |
237 cerr << "WrongCost found" << endl; | |
238 err.type = ErrorPosition::WrongCost; | 235 err.type = ErrorPosition::WrongCost; |
239 err.r = r; | 236 err.r = r; |
240 err.c = c; | 237 err.c = c; |
241 err.costWas = m_m->getPathCost(r, c); | 238 err.costWas = m_m->getPathCost(r, c); |
242 err.costShouldBe = updateTo; | 239 err.costShouldBe = updateTo; |
245 return err; | 242 return err; |
246 } | 243 } |
247 } else { | 244 } else { |
248 // AdvanceNone should occur only at r = r1, c = c1 | 245 // AdvanceNone should occur only at r = r1, c = c1 |
249 if (r != r1 || c != c1) { | 246 if (r != r1 || c != c1) { |
250 cerr << "AdvanceNone error found" << endl; | |
251 err.type = ErrorPosition::NoAdvance; | 247 err.type = ErrorPosition::NoAdvance; |
252 err.r = r; | 248 err.r = r; |
253 err.c = c; | 249 err.c = c; |
254 err.costWas = m_m->getPathCost(r, c); | 250 err.costWas = m_m->getPathCost(r, c); |
255 err.costShouldBe = updateTo; | 251 err.costShouldBe = updateTo; |
262 | 258 |
263 prevRowStart = rowStart; | 259 prevRowStart = rowStart; |
264 prevRowStop = rowStop; | 260 prevRowStop = rowStop; |
265 } | 261 } |
266 | 262 |
267 cerr << "No errors found" << endl; | |
268 return err; | 263 return err; |
269 } | 264 } |
270 #endif | 265 |
271 | 266 void |
272 int | 267 Finder::checkAndReport() |
273 Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy) | 268 { |
274 { | 269 cerr << "Finder: Checking path-cost matrix..." << endl; |
275 pathx.clear(); | |
276 pathy.clear(); | |
277 | |
278 #ifdef PERFORM_ERROR_CHECKS | |
279 ErrorPosition err = checkPathCostMatrix(); | 270 ErrorPosition err = checkPathCostMatrix(); |
280 if (err.type != ErrorPosition::NoError) { | 271 if (err.type == ErrorPosition::NoError) { |
272 cerr << "No errors found" << endl; | |
273 } else { | |
281 cerr << "\nWARNING: Checking path-cost matrix returned mismatch:" << endl; | 274 cerr << "\nWARNING: Checking path-cost matrix returned mismatch:" << endl; |
282 cerr << "Type: " << err.type << endl; | 275 cerr << "Type: " << err.type << ": "; |
276 switch (err.type) { | |
277 case ErrorPosition::NoError: break; | |
278 case ErrorPosition::WrongCost: cerr << "WrongCost"; break; | |
279 case ErrorPosition::WrongAdvance: cerr << "WrongAdvance"; break; | |
280 case ErrorPosition::NoAdvance: cerr << "NoAdvance"; break; | |
281 } | |
282 cerr << endl; | |
283 cerr << "At row " << err.r << ", column " << err.c | 283 cerr << "At row " << err.r << ", column " << err.c |
284 << "\nShould be advancing " | 284 << "\nShould be advancing " |
285 << Matcher::advanceToString(err.advanceShouldBe) | 285 << Matcher::advanceToString(err.advanceShouldBe) |
286 << ", advance in matrix is " | 286 << ", advance in matrix is " |
287 << Matcher::advanceToString(err.advanceWas) | 287 << Matcher::advanceToString(err.advanceWas) |
289 << " plus distance " << err.distance << " gives " | 289 << " plus distance " << err.distance << " gives " |
290 << err.costShouldBe << ", matrix contains " << err.costWas | 290 << err.costShouldBe << ", matrix contains " << err.costWas |
291 << endl; | 291 << endl; |
292 cerr << "Note: diagonal weight = " << m_m->getDiagonalWeight() << endl; | 292 cerr << "Note: diagonal weight = " << m_m->getDiagonalWeight() << endl; |
293 cerr << endl; | 293 cerr << endl; |
294 } | 294 |
295 int w(10); | |
296 | |
297 cerr << "Distance matrix leading up to this point:" << endl; | |
298 cerr << setw(w) << ""; | |
299 for (int i = -4; i <= 0; ++i) { | |
300 cerr << setw(w) << i; | |
301 } | |
302 cerr << endl; | |
303 for (int j = -4; j <= 0; ++j) { | |
304 cerr << setw(w) << j; | |
305 for (int i = -4; i <= 0; ++i) { | |
306 cerr << setw(w) << m_m->getDistance(err.r + j, err.c + i); | |
307 } | |
308 cerr << endl; | |
309 } | |
310 cerr << endl; | |
311 | |
312 cerr << "Cost matrix leading up to this point:" << endl; | |
313 cerr << setw(w) << ""; | |
314 for (int i = -4; i <= 0; ++i) { | |
315 cerr << setw(w) << i; | |
316 } | |
317 cerr << endl; | |
318 for (int j = -4; j <= 0; ++j) { | |
319 cerr << setw(w) << j; | |
320 for (int i = -4; i <= 0; ++i) { | |
321 cerr << setw(w) << m_m->getPathCost(err.r + j, err.c + i); | |
322 } | |
323 cerr << endl; | |
324 } | |
325 cerr << endl; | |
326 } | |
327 } | |
328 #endif | |
329 | |
330 int | |
331 Finder::retrievePath(bool smooth, vector<int> &pathx, vector<int> &pathy) | |
332 { | |
333 pathx.clear(); | |
334 pathy.clear(); | |
335 | |
336 #ifdef PERFORM_ERROR_CHECKS | |
337 checkAndReport(); | |
295 #endif | 338 #endif |
296 | 339 |
297 int ex = m_m->getOtherFrameCount() - 1; | 340 int ex = m_m->getOtherFrameCount() - 1; |
298 int ey = m_m->getFrameCount() - 1; | 341 int ey = m_m->getFrameCount() - 1; |
299 | 342 |