cannam@0
|
1 /* -*- c-basic-offset: 4 indent-tabs-mode: nil -*- vi:set ts=8 sts=4 sw=4: */
|
cannam@0
|
2
|
cannam@0
|
3 /*
|
cannam@0
|
4 Vamp feature extraction plugin using the MATCH audio alignment
|
cannam@0
|
5 algorithm.
|
cannam@0
|
6
|
cannam@0
|
7 Centre for Digital Music, Queen Mary, University of London.
|
cannam@0
|
8 This file copyright 2007 Simon Dixon, Chris Cannam and QMUL.
|
cannam@0
|
9
|
cannam@0
|
10 This program is free software; you can redistribute it and/or
|
cannam@0
|
11 modify it under the terms of the GNU General Public License as
|
cannam@0
|
12 published by the Free Software Foundation; either version 2 of the
|
cannam@0
|
13 License, or (at your option) any later version. See the file
|
cannam@0
|
14 COPYING included with this distribution for more information.
|
cannam@0
|
15 */
|
cannam@0
|
16
|
cannam@0
|
17 #include "Matcher.h"
|
cannam@0
|
18
|
cannam@0
|
19 #include <iostream>
|
cannam@0
|
20
|
cannam@4
|
21 #include <cstdlib>
|
Chris@16
|
22 #include <cassert>
|
cannam@4
|
23
|
Chris@72
|
24 using namespace std;
|
Chris@72
|
25
|
Chris@10
|
26 //#define DEBUG_MATCHER 1
|
Chris@10
|
27
|
Chris@143
|
28 Matcher::Matcher(Parameters parameters, DistanceMetric::Parameters dparams,
|
Chris@143
|
29 Matcher *p) :
|
Chris@43
|
30 m_params(parameters),
|
Chris@143
|
31 m_metric(dparams)
|
Chris@23
|
32 {
|
Chris@23
|
33 #ifdef DEBUG_MATCHER
|
Chris@143
|
34 cerr << "*** Matcher: hopTime = " << parameters.hopTime
|
Chris@140
|
35 << ", blockTime = " << parameters.blockTime
|
Chris@140
|
36 << ", maxRunCount = " << parameters.maxRunCount
|
Chris@140
|
37 << ", diagonalWeight = " << parameters.diagonalWeight << endl;
|
Chris@23
|
38 #endif
|
Chris@140
|
39
|
Chris@43
|
40 m_otherMatcher = p; // the first matcher will need this to be set later
|
Chris@43
|
41 m_firstPM = (!p);
|
Chris@43
|
42 m_frameCount = 0;
|
Chris@43
|
43 m_runCount = 0;
|
Chris@43
|
44 m_blockSize = 0;
|
cannam@0
|
45
|
Chris@43
|
46 m_blockSize = lrint(m_params.blockTime / m_params.hopTime);
|
Chris@15
|
47 #ifdef DEBUG_MATCHER
|
Chris@43
|
48 cerr << "Matcher: m_blockSize = " << m_blockSize << endl;
|
Chris@15
|
49 #endif
|
cannam@0
|
50
|
Chris@43
|
51 m_initialised = false;
|
Chris@23
|
52 }
|
cannam@0
|
53
|
cannam@0
|
54 Matcher::~Matcher()
|
cannam@0
|
55 {
|
Chris@10
|
56 #ifdef DEBUG_MATCHER
|
Chris@15
|
57 cerr << "Matcher(" << this << ")::~Matcher()" << endl;
|
Chris@10
|
58 #endif
|
cannam@0
|
59 }
|
cannam@0
|
60
|
cannam@0
|
61 void
|
cannam@0
|
62 Matcher::init()
|
cannam@0
|
63 {
|
Chris@43
|
64 if (m_initialised) return;
|
cannam@0
|
65
|
Chris@104
|
66 m_frames = vector<vector<double> >(m_blockSize);
|
cannam@0
|
67
|
Chris@43
|
68 m_distXSize = m_blockSize * 2;
|
Chris@45
|
69
|
Chris@41
|
70 size();
|
cannam@0
|
71
|
Chris@43
|
72 m_frameCount = 0;
|
Chris@43
|
73 m_runCount = 0;
|
Chris@38
|
74
|
Chris@43
|
75 m_initialised = true;
|
Chris@16
|
76 }
|
Chris@16
|
77
|
Chris@87
|
78 bool
|
Chris@154
|
79 Matcher::isRowAvailable(int i)
|
Chris@154
|
80 {
|
Chris@154
|
81 if (i < 0 || i >= int(m_first.size())) return false;
|
Chris@154
|
82
|
Chris@154
|
83 for (int j = m_first[i]; j < int(m_first[i] + m_bestPathCost[i].size()); ++j) {
|
Chris@154
|
84 if (isAvailable(i, j)) {
|
Chris@154
|
85 return true;
|
Chris@154
|
86 }
|
Chris@154
|
87 }
|
Chris@154
|
88
|
Chris@154
|
89 return false;
|
Chris@154
|
90 }
|
Chris@154
|
91
|
Chris@154
|
92 bool
|
Chris@154
|
93 Matcher::isColAvailable(int i)
|
Chris@154
|
94 {
|
Chris@154
|
95 return m_otherMatcher->isRowAvailable(i);
|
Chris@154
|
96 }
|
Chris@154
|
97
|
Chris@154
|
98 bool
|
Chris@87
|
99 Matcher::isInRange(int i, int j)
|
Chris@87
|
100 {
|
Chris@87
|
101 if (m_firstPM) {
|
Chris@87
|
102 return ((i >= 0) &&
|
Chris@87
|
103 (i < int(m_first.size())) &&
|
Chris@87
|
104 (j >= m_first[i]) &&
|
Chris@87
|
105 (j < int(m_first[i] + m_bestPathCost[i].size())));
|
Chris@87
|
106 } else {
|
Chris@87
|
107 return m_otherMatcher->isInRange(j, i);
|
Chris@87
|
108 }
|
Chris@87
|
109 }
|
Chris@87
|
110
|
Chris@87
|
111 bool
|
Chris@87
|
112 Matcher::isAvailable(int i, int j)
|
Chris@87
|
113 {
|
Chris@87
|
114 if (m_firstPM) {
|
Chris@87
|
115 if (isInRange(i, j)) {
|
Chris@87
|
116 return (m_bestPathCost[i][j - m_first[i]] >= 0);
|
Chris@87
|
117 } else {
|
Chris@87
|
118 return false;
|
Chris@87
|
119 }
|
Chris@87
|
120 } else {
|
Chris@87
|
121 return m_otherMatcher->isAvailable(j, i);
|
Chris@87
|
122 }
|
Chris@87
|
123 }
|
Chris@87
|
124
|
Chris@87
|
125 pair<int, int>
|
Chris@87
|
126 Matcher::getColRange(int i)
|
Chris@87
|
127 {
|
Chris@87
|
128 if (i < 0 || i >= int(m_first.size())) {
|
Chris@87
|
129 cerr << "ERROR: Matcher::getColRange(" << i << "): Index out of range"
|
Chris@87
|
130 << endl;
|
Chris@87
|
131 throw "Index out of range";
|
Chris@87
|
132 } else {
|
Chris@87
|
133 return pair<int, int>(m_first[i], m_last[i]);
|
Chris@87
|
134 }
|
Chris@87
|
135 }
|
Chris@87
|
136
|
Chris@87
|
137 pair<int, int>
|
Chris@87
|
138 Matcher::getRowRange(int i)
|
Chris@87
|
139 {
|
Chris@87
|
140 return m_otherMatcher->getColRange(i);
|
Chris@87
|
141 }
|
Chris@87
|
142
|
Chris@87
|
143 float
|
Chris@87
|
144 Matcher::getDistance(int i, int j)
|
Chris@87
|
145 {
|
Chris@87
|
146 if (m_firstPM) {
|
Chris@87
|
147 if (!isInRange(i, j)) {
|
Chris@87
|
148 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
|
Chris@87
|
149 << "Location is not in range" << endl;
|
Chris@87
|
150 throw "Distance not available";
|
Chris@87
|
151 }
|
Chris@87
|
152 float dist = m_distance[i][j - m_first[i]];
|
Chris@87
|
153 if (dist < 0) {
|
Chris@87
|
154 cerr << "ERROR: Matcher::getDistance(" << i << ", " << j << "): "
|
Chris@87
|
155 << "Location is in range, but distance ("
|
Chris@87
|
156 << dist << ") is invalid or has not been set" << endl;
|
Chris@87
|
157 throw "Distance not available";
|
Chris@87
|
158 }
|
Chris@87
|
159 return dist;
|
Chris@87
|
160 } else {
|
Chris@87
|
161 return m_otherMatcher->getDistance(j, i);
|
Chris@87
|
162 }
|
Chris@87
|
163 }
|
Chris@87
|
164
|
Chris@87
|
165 void
|
Chris@87
|
166 Matcher::setDistance(int i, int j, float distance)
|
Chris@87
|
167 {
|
Chris@87
|
168 if (m_firstPM) {
|
Chris@87
|
169 if (!isInRange(i, j)) {
|
Chris@87
|
170 cerr << "ERROR: Matcher::setDistance(" << i << ", " << j << ", "
|
Chris@87
|
171 << distance << "): Location is out of range" << endl;
|
Chris@87
|
172 throw "Indices out of range";
|
Chris@87
|
173 }
|
Chris@87
|
174 m_distance[i][j - m_first[i]] = distance;
|
Chris@87
|
175 } else {
|
Chris@87
|
176 m_otherMatcher->setDistance(j, i, distance);
|
Chris@87
|
177 }
|
Chris@87
|
178 }
|
Chris@87
|
179
|
Chris@87
|
180 double
|
Chris@135
|
181 Matcher::getNormalisedPathCost(int i, int j)
|
Chris@135
|
182 {
|
Chris@135
|
183 // normalised for path length. 1+ prevents division by zero here
|
Chris@135
|
184 return getPathCost(i, j) / (1 + i + j);
|
Chris@135
|
185 }
|
Chris@135
|
186
|
Chris@135
|
187 double
|
Chris@87
|
188 Matcher::getPathCost(int i, int j)
|
Chris@87
|
189 {
|
Chris@87
|
190 if (m_firstPM) {
|
Chris@87
|
191 if (!isAvailable(i, j)) {
|
Chris@87
|
192 if (!isInRange(i, j)) {
|
Chris@87
|
193 cerr << "ERROR: Matcher::getPathCost(" << i << ", " << j << "): "
|
Chris@87
|
194 << "Location is not in range" << endl;
|
Chris@87
|
195 } else {
|
Chris@87
|
196 cerr << "ERROR: Matcher::getPathCost(" << i << ", " << j << "): "
|
Chris@87
|
197 << "Location is in range, but pathCost ("
|
Chris@87
|
198 << m_bestPathCost[i][j - m_first[i]]
|
Chris@87
|
199 << ") is invalid or has not been set" << endl;
|
Chris@87
|
200 }
|
Chris@87
|
201 throw "Path cost not available";
|
Chris@87
|
202 }
|
Chris@87
|
203 return m_bestPathCost[i][j - m_first[i]];
|
Chris@87
|
204 } else {
|
Chris@87
|
205 return m_otherMatcher->getPathCost(j, i);
|
Chris@87
|
206 }
|
Chris@87
|
207 }
|
Chris@87
|
208
|
Chris@87
|
209 void
|
Chris@87
|
210 Matcher::setPathCost(int i, int j, Advance dir, double pathCost)
|
Chris@87
|
211 {
|
Chris@87
|
212 if (m_firstPM) {
|
Chris@87
|
213 if (!isInRange(i, j)) {
|
Chris@87
|
214 cerr << "ERROR: Matcher::setPathCost(" << i << ", " << j << ", "
|
Chris@87
|
215 << dir << ", " << pathCost
|
Chris@87
|
216 << "): Location is out of range" << endl;
|
Chris@87
|
217 throw "Indices out of range";
|
Chris@87
|
218 }
|
Chris@87
|
219 m_advance[i][j - m_first[i]] = dir;
|
Chris@87
|
220 m_bestPathCost[i][j - m_first[i]] = pathCost;
|
Chris@87
|
221 } else {
|
Chris@87
|
222 if (dir == AdvanceThis) {
|
Chris@87
|
223 dir = AdvanceOther;
|
Chris@87
|
224 } else if (dir == AdvanceOther) {
|
Chris@87
|
225 dir = AdvanceThis;
|
Chris@87
|
226 }
|
Chris@87
|
227 m_otherMatcher->setPathCost(j, i, dir, pathCost);
|
Chris@87
|
228 }
|
Chris@87
|
229
|
Chris@87
|
230 }
|
Chris@87
|
231
|
cannam@0
|
232 void
|
Chris@41
|
233 Matcher::size()
|
cannam@0
|
234 {
|
Chris@43
|
235 int distSize = (m_params.maxRunCount + 1) * m_blockSize;
|
Chris@71
|
236 m_bestPathCost.resize(m_distXSize, vector<double>(distSize, -1));
|
Chris@71
|
237 m_distance.resize(m_distXSize, vector<float>(distSize, -1));
|
Chris@45
|
238 m_advance.resize(m_distXSize, vector<Advance>(distSize, AdvanceNone));
|
Chris@43
|
239 m_first.resize(m_distXSize, 0);
|
Chris@43
|
240 m_last.resize(m_distXSize, 0);
|
Chris@38
|
241 }
|
cannam@0
|
242
|
Chris@23
|
243 void
|
Chris@72
|
244 Matcher::consumeFeatureVector(vector<double> feature)
|
Chris@23
|
245 {
|
Chris@43
|
246 if (!m_initialised) init();
|
Chris@43
|
247 int frameIndex = m_frameCount % m_blockSize;
|
Chris@43
|
248 m_frames[frameIndex] = feature;
|
Chris@23
|
249 calcAdvance();
|
Chris@21
|
250 }
|
Chris@21
|
251
|
Chris@21
|
252 void
|
Chris@21
|
253 Matcher::calcAdvance()
|
Chris@21
|
254 {
|
Chris@43
|
255 int frameIndex = m_frameCount % m_blockSize;
|
Chris@21
|
256
|
Chris@43
|
257 if (m_frameCount >= m_distXSize) {
|
Chris@43
|
258 m_distXSize *= 2;
|
Chris@41
|
259 size();
|
cannam@0
|
260 }
|
cannam@0
|
261
|
Chris@43
|
262 if (m_firstPM && (m_frameCount >= m_blockSize)) {
|
cannam@0
|
263
|
Chris@43
|
264 int len = m_last[m_frameCount - m_blockSize] -
|
Chris@43
|
265 m_first[m_frameCount - m_blockSize];
|
cannam@0
|
266
|
Chris@43
|
267 // We need to copy distance[m_frameCount-m_blockSize] to
|
Chris@43
|
268 // distance[m_frameCount], and then truncate
|
Chris@43
|
269 // distance[m_frameCount-m_blockSize] to its first len elements.
|
cannam@0
|
270 // Same for bestPathCost.
|
cannam@0
|
271
|
Chris@69
|
272 vector<float> dOld = m_distance[m_frameCount - m_blockSize];
|
Chris@71
|
273 vector<float> dNew(len, -1.f);
|
cannam@0
|
274
|
Chris@69
|
275 vector<double> bpcOld = m_bestPathCost[m_frameCount - m_blockSize];
|
Chris@71
|
276 vector<double> bpcNew(len, -1.0);
|
Chris@69
|
277
|
Chris@69
|
278 vector<Advance> adOld = m_advance[m_frameCount - m_blockSize];
|
Chris@69
|
279 vector<Advance> adNew(len, AdvanceNone);
|
Chris@69
|
280
|
Chris@69
|
281 for (int i = 0; i < len; ++i) {
|
Chris@69
|
282 dNew[i] = dOld[i];
|
Chris@69
|
283 bpcNew[i] = bpcOld[i];
|
Chris@69
|
284 adNew[i] = adOld[i];
|
Chris@69
|
285 }
|
Chris@45
|
286
|
Chris@69
|
287 m_distance[m_frameCount] = dOld;
|
Chris@69
|
288 m_distance[m_frameCount - m_blockSize] = dNew;
|
Chris@69
|
289
|
Chris@69
|
290 m_bestPathCost[m_frameCount] = bpcOld;
|
Chris@69
|
291 m_bestPathCost[m_frameCount - m_blockSize] = bpcNew;
|
Chris@69
|
292
|
Chris@69
|
293 m_advance[m_frameCount] = adOld;
|
Chris@69
|
294 m_advance[m_frameCount - m_blockSize] = adNew;
|
cannam@0
|
295 }
|
cannam@0
|
296
|
Chris@43
|
297 int stop = m_otherMatcher->m_frameCount;
|
Chris@43
|
298 int index = stop - m_blockSize;
|
Chris@86
|
299 if (index < 0) index = 0;
|
Chris@86
|
300
|
Chris@43
|
301 m_first[m_frameCount] = index;
|
Chris@43
|
302 m_last[m_frameCount] = stop;
|
cannam@0
|
303
|
cannam@0
|
304 for ( ; index < stop; index++) {
|
Chris@26
|
305
|
Chris@86
|
306 float distance = (float) m_metric.calcDistance
|
Chris@43
|
307 (m_frames[frameIndex],
|
Chris@45
|
308 m_otherMatcher->m_frames[index % m_blockSize]);
|
Chris@26
|
309
|
Chris@89
|
310 float diagDistance = distance * m_params.diagonalWeight;
|
Chris@89
|
311
|
Chris@86
|
312 if ((m_frameCount == 0) && (index == 0)) { // first element
|
Chris@86
|
313
|
Chris@86
|
314 updateValue(0, 0, AdvanceNone,
|
Chris@86
|
315 0,
|
Chris@86
|
316 distance);
|
Chris@86
|
317
|
Chris@86
|
318 } else if (m_frameCount == 0) { // first row
|
Chris@86
|
319
|
Chris@71
|
320 updateValue(0, index, AdvanceOther,
|
Chris@86
|
321 getPathCost(0, index-1),
|
Chris@86
|
322 distance);
|
Chris@86
|
323
|
Chris@86
|
324 } else if (index == 0) { // first column
|
Chris@86
|
325
|
Chris@71
|
326 updateValue(m_frameCount, index, AdvanceThis,
|
Chris@86
|
327 getPathCost(m_frameCount - 1, 0),
|
Chris@86
|
328 distance);
|
Chris@86
|
329
|
Chris@86
|
330 } else if (index == m_otherMatcher->m_frameCount - m_blockSize) {
|
Chris@86
|
331
|
cannam@0
|
332 // missing value(s) due to cutoff
|
cannam@0
|
333 // - no previous value in current row (resp. column)
|
cannam@0
|
334 // - no diagonal value if prev. dir. == curr. dirn
|
Chris@86
|
335
|
Chris@72
|
336 double min2 = getPathCost(m_frameCount - 1, index);
|
Chris@86
|
337
|
Chris@91
|
338 // cerr << "NOTE: missing value at i = " << m_frameCount << ", j = "
|
Chris@91
|
339 // << index << " (first = " << m_firstPM << ")" << endl;
|
Chris@86
|
340
|
Chris@43
|
341 // if ((m_firstPM && (first[m_frameCount - 1] == index)) ||
|
Chris@43
|
342 // (!m_firstPM && (m_last[index-1] < m_frameCount)))
|
Chris@86
|
343 if (m_first[m_frameCount - 1] == index) {
|
Chris@86
|
344
|
Chris@86
|
345 updateValue(m_frameCount, index, AdvanceThis,
|
Chris@86
|
346 min2, distance);
|
Chris@86
|
347
|
Chris@86
|
348 } else {
|
Chris@86
|
349
|
Chris@72
|
350 double min1 = getPathCost(m_frameCount - 1, index - 1);
|
Chris@89
|
351 if (min1 + diagDistance <= min2 + distance) {
|
Chris@86
|
352 updateValue(m_frameCount, index, AdvanceBoth,
|
Chris@86
|
353 min1, distance);
|
Chris@86
|
354 } else {
|
Chris@86
|
355 updateValue(m_frameCount, index, AdvanceThis,
|
Chris@86
|
356 min2, distance);
|
Chris@86
|
357 }
|
cannam@0
|
358 }
|
Chris@86
|
359
|
cannam@0
|
360 } else {
|
Chris@86
|
361
|
Chris@86
|
362 double min1 = getPathCost(m_frameCount, index - 1);
|
Chris@72
|
363 double min2 = getPathCost(m_frameCount - 1, index);
|
Chris@86
|
364 double min3 = getPathCost(m_frameCount - 1, index - 1);
|
Chris@87
|
365
|
Chris@89
|
366 double cost1 = min1 + distance;
|
Chris@89
|
367 double cost2 = min2 + distance;
|
Chris@89
|
368 double cost3 = min3 + diagDistance;
|
Chris@93
|
369
|
Chris@93
|
370 // Choosing is easy if there is a strict cheapest of the
|
Chris@93
|
371 // three. If two or more share the lowest cost, we choose
|
Chris@93
|
372 // in order of preference: cost3 (AdvanceBoth), cost2
|
Chris@94
|
373 // (AdvanceThis), cost1 (AdvanceOther) if we are the first
|
Chris@94
|
374 // matcher; and cost3 (AdvanceBoth), cost1 (AdvanceOther),
|
Chris@94
|
375 // cost2 (AdvanceThis) if we are the second matcher. That
|
Chris@94
|
376 // is, we always prioritise the diagonal followed by the
|
Chris@94
|
377 // first matcher.
|
Chris@94
|
378
|
Chris@94
|
379 if (( m_firstPM && (cost1 < cost2)) ||
|
Chris@94
|
380 (!m_firstPM && (cost1 <= cost2))) {
|
Chris@89
|
381 if (cost3 <= cost1) {
|
Chris@86
|
382 updateValue(m_frameCount, index, AdvanceBoth,
|
Chris@86
|
383 min3, distance);
|
Chris@86
|
384 } else {
|
Chris@86
|
385 updateValue(m_frameCount, index, AdvanceOther,
|
Chris@86
|
386 min1, distance);
|
Chris@86
|
387 }
|
cannam@0
|
388 } else {
|
Chris@89
|
389 if (cost3 <= cost2) {
|
Chris@86
|
390 updateValue(m_frameCount, index, AdvanceBoth,
|
Chris@86
|
391 min3, distance);
|
Chris@86
|
392 } else {
|
Chris@86
|
393 updateValue(m_frameCount, index, AdvanceThis,
|
Chris@86
|
394 min2, distance);
|
Chris@86
|
395 }
|
cannam@0
|
396 }
|
cannam@0
|
397 }
|
Chris@86
|
398
|
Chris@43
|
399 m_otherMatcher->m_last[index]++;
|
cannam@0
|
400 } // loop for row (resp. column)
|
cannam@0
|
401
|
Chris@43
|
402 m_frameCount++;
|
Chris@43
|
403 m_runCount++;
|
cannam@0
|
404
|
Chris@43
|
405 m_otherMatcher->m_runCount = 0;
|
Chris@21
|
406 }
|
cannam@0
|
407
|
cannam@0
|
408 void
|
Chris@96
|
409 Matcher::updateValue(int i, int j, Advance dir, double value, float distance)
|
cannam@0
|
410 {
|
Chris@96
|
411 float weighted = distance;
|
Chris@83
|
412 if (dir == AdvanceBoth) {
|
Chris@83
|
413 weighted *= m_params.diagonalWeight;
|
Chris@83
|
414 }
|
Chris@83
|
415
|
Chris@43
|
416 if (m_firstPM) {
|
Chris@45
|
417
|
Chris@96
|
418 setDistance(i, j, distance);
|
Chris@83
|
419 setPathCost(i, j, dir, value + weighted);
|
Chris@45
|
420
|
cannam@0
|
421 } else {
|
Chris@45
|
422
|
Chris@86
|
423 if (dir == AdvanceThis) dir = AdvanceOther;
|
Chris@86
|
424 else if (dir == AdvanceOther) dir = AdvanceThis;
|
Chris@84
|
425
|
Chris@43
|
426 int idx = i - m_otherMatcher->m_first[j];
|
Chris@45
|
427
|
Chris@69
|
428 if (idx == (int)m_otherMatcher->m_distance[j].size()) {
|
cannam@0
|
429 // This should never happen, but if we allow arbitrary
|
cannam@0
|
430 // pauses in either direction, and arbitrary lengths at
|
cannam@0
|
431 // end, it is better than a segmentation fault.
|
Chris@72
|
432 cerr << "Emergency resize: " << idx << " -> " << idx * 2 << endl;
|
Chris@71
|
433 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, -1);
|
Chris@71
|
434 m_otherMatcher->m_distance[j].resize(idx * 2, -1);
|
Chris@46
|
435 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone);
|
cannam@0
|
436 }
|
Chris@45
|
437
|
Chris@96
|
438 m_otherMatcher->setDistance(j, i, distance);
|
Chris@83
|
439 m_otherMatcher->setPathCost(j, i, dir, value + weighted);
|
cannam@0
|
440 }
|
Chris@71
|
441 }
|
cannam@0
|
442
|
Chris@72
|
443 Matcher::Advance
|
Chris@72
|
444 Matcher::getAdvance(int i, int j)
|
Chris@72
|
445 {
|
Chris@72
|
446 if (m_firstPM) {
|
Chris@72
|
447 if (!isInRange(i, j)) {
|
Chris@72
|
448 cerr << "ERROR: Matcher::getAdvance(" << i << ", " << j << "): "
|
Chris@72
|
449 << "Location is not in range" << endl;
|
Chris@72
|
450 throw "Advance not available";
|
Chris@72
|
451 }
|
Chris@72
|
452 return m_advance[i][j - m_first[i]];
|
Chris@72
|
453 } else {
|
Chris@72
|
454 return m_otherMatcher->getAdvance(j, i);
|
Chris@72
|
455 }
|
Chris@72
|
456 }
|