Mercurial > hg > match-vamp
comparison src/Matcher.cpp @ 46:b0ebc3e2c016 refactors
Some fixes: int -> float
author | Chris Cannam |
---|---|
date | Thu, 13 Nov 2014 15:09:04 +0000 |
parents | a1b7df871496 |
children | 8cbc15519d2c |
comparison
equal
deleted
inserted
replaced
45:a1b7df871496 | 46:b0ebc3e2c016 |
---|---|
163 | 163 |
164 m_bestPathCost[m_frameCount] = m_bestPathCost[m_frameCount - m_blockSize]; | 164 m_bestPathCost[m_frameCount] = m_bestPathCost[m_frameCount - m_blockSize]; |
165 m_bestPathCost[m_frameCount - m_blockSize].resize(len, 0); | 165 m_bestPathCost[m_frameCount - m_blockSize].resize(len, 0); |
166 | 166 |
167 m_advance[m_frameCount] = m_advance[m_frameCount - m_blockSize]; | 167 m_advance[m_frameCount] = m_advance[m_frameCount - m_blockSize]; |
168 m_advance[m_frameCount - m_blockSize].resize(len); | 168 m_advance[m_frameCount - m_blockSize].resize(len, AdvanceNone); |
169 | 169 |
170 m_distYSizes[m_frameCount] = m_distYSizes[m_frameCount - m_blockSize]; | 170 m_distYSizes[m_frameCount] = m_distYSizes[m_frameCount - m_blockSize]; |
171 m_distYSizes[m_frameCount - m_blockSize] = len; | 171 m_distYSizes[m_frameCount - m_blockSize] = len; |
172 } | 172 } |
173 | 173 |
176 if (index < 0) | 176 if (index < 0) |
177 index = 0; | 177 index = 0; |
178 m_first[m_frameCount] = index; | 178 m_first[m_frameCount] = index; |
179 m_last[m_frameCount] = stop; | 179 m_last[m_frameCount] = stop; |
180 | 180 |
181 bool overflow = false; | 181 float mn= -1; |
182 int mn= -1; | 182 float mx= -1; |
183 int mx= -1; | |
184 for ( ; index < stop; index++) { | 183 for ( ; index < stop; index++) { |
185 | 184 |
186 float dMN = m_metric.calcDistance | 185 float dMN = m_metric.calcDistance |
187 (m_frames[frameIndex], | 186 (m_frames[frameIndex], |
188 m_otherMatcher->m_frames[index % m_blockSize]); | 187 m_otherMatcher->m_frames[index % m_blockSize]); |
191 mx = mn = dMN; | 190 mx = mn = dMN; |
192 else if (dMN > mx) | 191 else if (dMN > mx) |
193 mx = dMN; | 192 mx = dMN; |
194 else if (dMN < mn) | 193 else if (dMN < mn) |
195 mn = dMN; | 194 mn = dMN; |
196 if (dMN >= 255) { | |
197 overflow = true; | |
198 dMN = 255; | |
199 } | |
200 | 195 |
201 if ((m_frameCount == 0) && (index == 0)) // first element | 196 if ((m_frameCount == 0) && (index == 0)) // first element |
202 setValue(0, 0, AdvanceNone, 0, dMN); | 197 setValue(0, 0, AdvanceNone, 0, dMN); |
203 else if (m_frameCount == 0) // first row | 198 else if (m_frameCount == 0) // first row |
204 setValue(0, index, AdvanceOther, | 199 setValue(0, index, AdvanceOther, |
208 getValue(m_frameCount - 1, 0, true), dMN); | 203 getValue(m_frameCount - 1, 0, true), dMN); |
209 else if (index == m_otherMatcher->m_frameCount - m_blockSize) { | 204 else if (index == m_otherMatcher->m_frameCount - m_blockSize) { |
210 // missing value(s) due to cutoff | 205 // missing value(s) due to cutoff |
211 // - no previous value in current row (resp. column) | 206 // - no previous value in current row (resp. column) |
212 // - no diagonal value if prev. dir. == curr. dirn | 207 // - no diagonal value if prev. dir. == curr. dirn |
213 int min2 = getValue(m_frameCount - 1, index, true); | 208 float min2 = getValue(m_frameCount - 1, index, true); |
214 // if ((m_firstPM && (first[m_frameCount - 1] == index)) || | 209 // if ((m_firstPM && (first[m_frameCount - 1] == index)) || |
215 // (!m_firstPM && (m_last[index-1] < m_frameCount))) | 210 // (!m_firstPM && (m_last[index-1] < m_frameCount))) |
216 if (m_first[m_frameCount - 1] == index) | 211 if (m_first[m_frameCount - 1] == index) |
217 setValue(m_frameCount, index, AdvanceThis, min2, dMN); | 212 setValue(m_frameCount, index, AdvanceThis, min2, dMN); |
218 else { | 213 else { |
219 int min1 = getValue(m_frameCount - 1, index - 1, true); | 214 float min1 = getValue(m_frameCount - 1, index - 1, true); |
220 if (min1 + dMN <= min2) | 215 if (min1 + dMN <= min2) |
221 setValue(m_frameCount, index, AdvanceBoth, min1,dMN); | 216 setValue(m_frameCount, index, AdvanceBoth, min1,dMN); |
222 else | 217 else |
223 setValue(m_frameCount, index, AdvanceThis, min2,dMN); | 218 setValue(m_frameCount, index, AdvanceThis, min2,dMN); |
224 } | 219 } |
225 } else { | 220 } else { |
226 int min1 = getValue(m_frameCount, index-1, true); | 221 float min1 = getValue(m_frameCount, index-1, true); |
227 int min2 = getValue(m_frameCount - 1, index, true); | 222 float min2 = getValue(m_frameCount - 1, index, true); |
228 int min3 = getValue(m_frameCount - 1, index-1, true); | 223 float min3 = getValue(m_frameCount - 1, index-1, true); |
229 if (min1 <= min2) { | 224 if (min1 <= min2) { |
230 if (min3 + dMN <= min1) | 225 if (min3 + dMN <= min1) |
231 setValue(m_frameCount, index, AdvanceBoth, min3,dMN); | 226 setValue(m_frameCount, index, AdvanceBoth, min3,dMN); |
232 else | 227 else |
233 setValue(m_frameCount, index, AdvanceOther,min1,dMN); | 228 setValue(m_frameCount, index, AdvanceOther,min1,dMN); |
243 | 238 |
244 m_frameCount++; | 239 m_frameCount++; |
245 m_runCount++; | 240 m_runCount++; |
246 | 241 |
247 m_otherMatcher->m_runCount = 0; | 242 m_otherMatcher->m_runCount = 0; |
248 | 243 } |
249 if (overflow) { | 244 |
250 cerr << "WARNING: overflow in distance metric: " | 245 float |
251 << "frame " << m_frameCount << ", val = " << mx << endl; | |
252 } | |
253 } | |
254 | |
255 int | |
256 Matcher::getValue(int i, int j, bool firstAttempt) | 246 Matcher::getValue(int i, int j, bool firstAttempt) |
257 { | 247 { |
258 if (m_firstPM) | 248 if (m_firstPM) |
259 return m_bestPathCost[i][j - m_first[i]]; | 249 return m_bestPathCost[i][j - m_first[i]]; |
260 else | 250 else |
288 // end, it is better than a segmentation fault. | 278 // end, it is better than a segmentation fault. |
289 std::cerr << "Emergency resize: " << idx << " -> " << idx * 2 << std::endl; | 279 std::cerr << "Emergency resize: " << idx << " -> " << idx * 2 << std::endl; |
290 m_otherMatcher->m_distYSizes[j] = idx * 2; | 280 m_otherMatcher->m_distYSizes[j] = idx * 2; |
291 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, 0); | 281 m_otherMatcher->m_bestPathCost[j].resize(idx * 2, 0); |
292 m_otherMatcher->m_distance[j].resize(idx * 2, 0); | 282 m_otherMatcher->m_distance[j].resize(idx * 2, 0); |
283 m_otherMatcher->m_advance[j].resize(idx * 2, AdvanceNone); | |
293 } | 284 } |
294 | 285 |
295 m_otherMatcher->m_distance[j][idx] = dMN; | 286 m_otherMatcher->m_distance[j][idx] = dMN; |
296 m_otherMatcher->m_advance[j][idx] = dir; | 287 m_otherMatcher->m_advance[j][idx] = dir; |
297 m_otherMatcher->m_bestPathCost[j][idx] = | 288 m_otherMatcher->m_bestPathCost[j][idx] = |