| 1 | /* DTW.cpp |
| 2 | * |
| 3 | * Copyright (C) 1993-2023 David Weenink, 2017 Paul Boersma |
| 4 | * |
| 5 | * This code is free software; you can redistribute it and/or modify |
| 6 | * it under the terms of the GNU General Public License as published by |
| 7 | * the Free Software Foundation; either version 2 of the License, or (at |
| 8 | * your option) any later version. |
| 9 | * |
| 10 | * This code is distributed in the hope that it will be useful, but |
| 11 | * WITHOUT ANY WARRANTY; without even the implied warranty of |
| 12 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU |
| 13 | * General Public License for more details. |
| 14 | * |
| 15 | * You should have received a copy of the GNU General Public License |
| 16 | * ilong with this work. If not, see <http://www.gnu.org/licenses/>. |
| 17 | */ |
| 18 | |
| 19 | /* |
| 20 | djmw 20020813 GPL header |
| 21 | djmw 20050302 Path finder modified with sakoe-chiba band |
| 22 | djmw 20050305 DTW_to_Polygon |
| 23 | djmw 20050306 DTW_swapAxes |
| 24 | djmw 20050530 Added Matrices_to_DTW |
| 25 | djmw 20060909 DTW_getPathY linear behaviour outside domains. |
| 26 | djmw 20061205 Pitches_to_DTW |
| 27 | djmw 20061214 Changed info to Melder_writeLine<x> format. |
| 28 | djmw 20071012 Added: o_CAN_WRITE_AS_ENCODING.h |
| 29 | djmw 20071016 To Melder_error<n> |
| 30 | djmw 20071022 Extra comments + possible bug correction in DTW_Path_recode. |
| 31 | djmw 20071201 Melder_warning<n>. |
| 32 | djmw 20071204 DTW_and_Sounds_draw. |
| 33 | djmw 20080122 float -> double |
| 34 | djmw 20081123 DTW_and_Sounds_checkDomains did not swap sounds correctly. |
| 35 | djmw 20091009 Removed a bug in DTW_Path_recode that could cause two identical x and y times in succession at the end. |
| 36 | djmw 20100504 extra check in DTW_Path_makeIndex |
| 37 | djmw 20110304 Thing_new |
| 38 | */ |
| 39 | |
| 40 | #include "DTW.h"cxx . . $ `<file>/dwtools/DTW.h`/ |
| 41 | #include "Sound_extensions.h"cxx . . $ `<file>/dwtools/Sound_extensions.h`/ |
| 42 | #include "NUM2.h"cxx . . $ `<file>/dwsys/NUM2.h`/ |
| 43 | #include "NUMmachar.h"cxx . . $ `<file>/dwsys/NUMmachar.h`/ |
| 44 | |
| 45 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 46 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 47 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 48 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 49 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 50 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 51 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 52 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 53 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 54 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 55 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 56 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 57 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 58 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 59 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 60 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 61 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 62 | #include "DTW_def.h"cxx . . $ `<file>/dwtools/DTW_def.h`/ |
| 63 | |
| 64 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (DTW, Matrix, 2); |
| 65 | |
| 66 | #define DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`! 1e308 |
| 67 | |
| 68 | void structDTWcxx . . $ structDTW# :: v1_infocxx . . $ structDTW#v1_info(49f6e7a06ebc5aa8). () { |
| 69 | structDaatacxx . . $ structDaata# :: v1_infocxx . . $ structThing#v1_info(49f6e7a06ebc5aa8). (); |
| 70 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Domain of prototype: ", ymincxx . . $ structSampledXY#ymin., U" to ", ymaxcxx . . $ structSampledXY#ymax., U" (s)."); // ppgb: Wat is een domain prototype? |
| 71 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Domain of candidate: ", xmincxx . . $ structFunction#xmin., U" to ", xmaxcxx . . $ structFunction#xmax., U" (s)."); // ppgb: Wat is een domain candidate? |
| 72 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frames in prototype: ", nycxx . . $ structSampledXY#ny.); |
| 73 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Number of frames in candidate: ", nxcxx . . $ structSampled#nx.); |
| 74 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Path length (frames): ", pathLengthcxx . . $ structDTW#pathLength.); |
| 75 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Global warped distance: ", weightedDistancecxx . . $ structDTW#weightedDistance.); |
| 76 | if (nxcxx . . $ structSampled#nx. == nycxx . . $ structSampledXY#ny.) { |
| 77 | double dd = 0; |
| 78 | for (integercxx . . $ integer# i = 1; i <= nxcxx . . $ structSampled#nx.; i ++) { |
| 79 | dd += zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 80 | } |
| 81 | MelderInfo_writeLinecxx . . $ MelderInfo_writeLine(3eb398314feba58b). (U"Distance along diagonal: ", dd / nxcxx . . $ structSampled#nx.); |
| 82 | } |
| 83 | } |
| 84 | |
| 85 | static void DTW_drawPath_rawcxx . . $ DTW_drawPath_raw(e4aa7edb19c14841). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, bool garnish, bool inset); |
| 86 | static void DTW_paintDistances_rawcxx . . $ DTW_paintDistances_raw(f6bf7b8b1c7306af). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish, bool inset); |
| 87 | static double _DTW_Sounds_getPartYcxx . . $ _DTW_Sounds_getPartY(f042c24bcd87f07e). (Graphicscxx . . $ Graphics# g, double dtw_part_x); |
| 88 | static void DTW_findPath_specialcxx . . $ DTW_findPath_special(e5f77fcf08ecb8f7). (DTWcxx . . $ DTW# me, bool matchStart, bool matchEnd, int slope, autoMatrixcxx . . $ autoMatrix# *cumulativeDists); |
| 89 | /* |
| 90 | Two 'slope lines, lh and ll, start in the lower left corner, the upper/lower has the maximum/minimum allowed slope. |
| 91 | Two other lines, ru and rl, end in the upper-right corner. The upper/lower line have minimum/maximum slope. |
| 92 | 1. the four lines with the two intersections determine a diamond |
| 93 | For vertical line at x we return the upper and lower y of the two intersections |
| 94 | 1. When we don't have a diamond, we return an error and the vertical distance between the slopelines in ylow. |
| 95 | */ |
| 96 | |
| 97 | |
| 98 | /* |
| 99 | The actual path will be interpolated as follows: |
| 100 | The distance matrix has cells of dimensions dx by dy. |
| 101 | The optimal path connects these cells with one another in the following way: |
| 102 | |
| 103 | In a diagonal ''path'' segment, i.e. when cells have no side in common, |
| 104 | the interpolated path runs from the lowerleft corner to the upperright corner. |
| 105 | If a path segment is horizontal or vertical the path also runs from lowerleft to upperright. |
| 106 | It is only when a horizontal and a vertical segment have a cell in common that we have to make |
| 107 | some adjustments to the path in the common cell. |
| 108 | This will be done as follows: |
| 109 | Let nx and ny be the number of horizontal and vertical cells in this path segment. |
| 110 | The path will always start at the lowerleft of the leftmost block and end |
| 111 | at the upperright of the rightmost block. |
| 112 | In the common cell we have to introduce an extra point in the path at (x1,y1) |
| 113 | where the line from the horizontal segment and the line from the vertical segment intersect. |
| 114 | Let the lowerleft and upperright point of the common cell be (0,0) and (dx,dy), |
| 115 | then the coordinates (x,y) of the intersection can be calculated as follows: |
| 116 | If we have two lines y = a1*x+b1 and y = a2*x+b2 they intersect at |
| 117 | (x,y) = (b2-b1, a1*b2-a2*b1)/(a1-a2) |
| 118 | For horizontal-vertical (hv) cells: |
| 119 | a1 = dy/(nx*dx), a2 = ny*dy/dx |
| 120 | b1 = dy*(nx-1)/nx, b2 = 0 |
| 121 | Then: |
| 122 | (x,y) = (dx, dy*ny ) * (nx-1)/(nx*ny-1) |
| 123 | |
| 124 | For vertical-horizontal (vh) cells: |
| 125 | a1 = ny*dy/dx, a2 = dy/(nx*dx) |
| 126 | b1 = -(ny-1)*dy b2 = 0 |
| 127 | Then: |
| 128 | (x,y) = (nx*dx, dy) * (ny-1)/(nx*ny-1) |
| 129 | */ |
| 130 | |
| 131 | /* DTW_getXTime (DTW me, (DTW_getYTime (DTW me, double tx)) == tx */ |
| 132 | double DTW_getYTimeFromXTimecxx . . $ DTW_getYTimeFromXTime(17d996b58e1db56). (DTWcxx . . $ DTW# me, double tx) { |
| 133 | double time = tx; // Catch cases where tier would give constant extrapolation |
| 134 | /* |
| 135 | If `eps` were zero, then the condition would rely on floating-point equality, |
| 136 | which is a bad idea (e.g. the result would be platform-dependent). |
| 137 | (fix ppgb 20240420, after this crashed on Windows only) |
| 138 | (rewind 20240501, because of retries in SpeechSynthesizer & Sound & TextGrid alignment) |
| 139 | */ |
| 140 | const double eps = 0.0 * (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.); |
| 141 | if (tx > mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + eps && tx < mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - eps) { |
| 142 | DTW_Path_Querycxx . . $ DTW_Path_Query# thee = & mycxx . . $ `melder/melder.h:44:9`! pathQuerycxx . . $ structDTW#pathQuery.; |
| 143 | time = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tx); |
| 144 | } else { |
| 145 | //TRACE |
| 146 | tracecxx . . $ `melder/melder_debug.h:60:10`! (U"Time set to ", tx, U" instead of between ", mycxx . . $ `melder/melder.h:44:9`! xmin, U" and ", mycxx . . $ `melder/melder.h:44:9`! xmax, U"."); |
| 147 | } |
| 148 | return time; |
| 149 | } |
| 150 | |
| 151 | double DTW_getXTimeFromYTimecxx . . $ DTW_getXTimeFromYTime(17d996b58e1db56). (DTWcxx . . $ DTW# me, double ty) { |
| 152 | double time = ty; // Catch cases where tier would give constant extrapolation |
| 153 | /* |
| 154 | If `eps` were zero, then the condition would rely on floating-point equality, |
| 155 | which is a bad idea (e.g. the result would be platform-dependent). |
| 156 | (fix ppgb 20240420, after this crashed on Windows only) |
| 157 | (rewind 20240501, because of retries in SpeechSynthesizer & Sound & TextGrid alignment) |
| 158 | */ |
| 159 | const double eps = 0.0 * (mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.); |
| 160 | if (ty > mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. + eps && ty < mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - eps) { |
| 161 | DTW_Path_Querycxx . . $ DTW_Path_Query# thee = & mycxx . . $ `melder/melder.h:44:9`! pathQuerycxx . . $ structDTW#pathQuery.; |
| 162 | time = RealTier_getValueAtTimecxx . . $ RealTier_getValueAtTime(22f4103126fb5be4). (thycxx . . $ `melder/melder.h:45:9`! xfromycxx . . $ structDTW_Path_Query#xfromy..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), ty); |
| 163 | } |
| 164 | return time; |
| 165 | } |
| 166 | |
| 167 | void DTW_Path_Query_initcxx . . $ DTW_Path_Query_init(32599237e6804113). (DTW_Path_Querycxx . . $ DTW_Path_Query# me, integercxx . . $ integer# ny, integercxx . . $ integer# nx) { |
| 168 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (ny > 0 && nx > 0); |
| 169 | mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structDTW_Path_Query#ny. = ny; |
| 170 | mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structDTW_Path_Query#nx. = nx; |
| 171 | mycxx . . $ `melder/melder.h:44:9`! nxycxx . . $ structDTW_Path_Query#nxy. = 2 * stdcxx . . $ std/::maxcxx . . $ std/max(2a338fce5842aa6a). (ny, nx) + 2; // maximum number of points |
| 172 | mycxx . . $ `melder/melder.h:44:9`! xfromycxx . . $ structDTW_Path_Query#xfromy. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Thing_newcxx . . $ `sys/Thing.h:514:9`! (RealTier); |
| 173 | mycxx . . $ `melder/melder.h:44:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). Thing_newcxx . . $ `sys/Thing.h:514:9`! (RealTier); |
| 174 | } |
| 175 | |
| 176 | /* Recode the path from a chain of cells to a piecewise linear path. */ |
| 177 | void DTW_Path_recodecxx . . $ DTW_Path_recode(1effd30d7a74ffbf). (DTWcxx . . $ DTW# me) { |
| 178 | try { |
| 179 | DTW_Path_Querycxx . . $ DTW_Path_Query# thee = & mycxx . . $ `melder/melder.h:44:9`! pathQuerycxx . . $ structDTW#pathQuery.; |
| 180 | integercxx . . $ integer# nxy; // current number of elements in recoded path |
| 181 | integercxx . . $ integer# nsc_x = 1; // current number of successive horizontal cells in the cells chain |
| 182 | integercxx . . $ integer# nsc_y = 1; // current number of successive vertical cells in the cells chain |
| 183 | integercxx . . $ integer# nd = 0; // current number of successive diagonal cells in the cells chain |
| 184 | bool yDirection = false; // previous segment in the original path was vertical |
| 185 | bool xDirection = false; // previous segment in the original path was horizontal |
| 186 | integercxx . . $ integer# ixp = 0, iyp = 0; // previous cell |
| 187 | struct structPointcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint# { |
| 188 | double xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x.,ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y.; |
| 189 | }; |
| 190 | |
| 191 | // 1. Starting point always at origin |
| 192 | |
| 193 | const integercxx . . $ integer# nxymax = thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structDTW_Path_Query#nx. + thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structDTW_Path_Query#ny. + 2; |
| 194 | autovectorcxx . . $ autovector# <structPointcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#> xytimes = newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structPointcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#> (nxymax); |
| 195 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 196 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 197 | |
| 198 | // 2. next point lower left of first cell |
| 199 | |
| 200 | nsc_x = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. xcxx . . $ structDTW_Path#x.; |
| 201 | ixp = nsc_x - 1; |
| 202 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (nsc_x - 1 - 0.5) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 203 | nsc_y = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. ycxx . . $ structDTW_Path#y.; |
| 204 | iyp = nsc_y - 1; |
| 205 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (nsc_y - 1 - 0.5) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; |
| 206 | |
| 207 | // 3. follow all cells. implicit: my x1 - 0.5 * my dx > my xmin && my y1 - 0.5 * my dy > my ymin */ |
| 208 | |
| 209 | nxy = 2; |
| 210 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; j ++) { |
| 211 | const integercxx . . $ integer# ix = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. xcxx . . $ structDTW_Path#x., iy = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. ycxx . . $ structDTW_Path#y.; |
| 212 | const double xright = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (ix - 1 + 0.5) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 213 | const double ytop = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (iy - 1 + 0.5) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; |
| 214 | double x, y, f; |
| 215 | integercxx . . $ integer# index; // where are we in the new path? |
| 216 | |
| 217 | if (iy == iyp) { // horizontal path? |
| 218 | xDirection = true; |
| 219 | if (yDirection) { |
| 220 | // We came from a vertical direction so this is the second horizontal cell in a row. |
| 221 | // The statement after this "if" updates nsc_x to 2. |
| 222 | nsc_x = 1; |
| 223 | yDirection = false; |
| 224 | } |
| 225 | nsc_x ++; |
| 226 | |
| 227 | if (nsc_y > 1 || nd > 1) { |
| 228 | // Previous segment was diagonal or vertical: modify intersection |
| 229 | // The vh intersection (x,y) = (nsc_x*dx, dy) * (nsc_y-1)/(nsc_x*nsc_y-1) |
| 230 | // A diagonal segment has nsc_y = 1. |
| 231 | f = (nsc_y - 1.0) / (nsc_x * nsc_y - 1); |
| 232 | x = xright - nsc_x * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. + nsc_x * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * f; |
| 233 | y = ytop - mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. + mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. * f; |
| 234 | index = nxy - 1; |
| 235 | if (nsc_x == 2) |
| 236 | index = nxy ++; |
| 237 | |
| 238 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = x; |
| 239 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = y; |
| 240 | } |
| 241 | nd = 0; |
| 242 | } else if (ix == ixp) { // vertical |
| 243 | yDirection = true; |
| 244 | if (xDirection) { |
| 245 | nsc_y = 1; |
| 246 | xDirection = false; |
| 247 | } |
| 248 | nsc_y ++; |
| 249 | |
| 250 | if (nsc_x > 1 || nd > 1) { |
| 251 | // The hv intersection (x,y) = (dx, dy*nsc_y ) * (nsc_x-1)/(nsc_x*nsc_y-1) |
| 252 | f = (nsc_x - 1.0) / (nsc_x * nsc_y - 1); |
| 253 | x = xright - mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. * f; |
| 254 | y = ytop - nsc_y * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. + nsc_y * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. * f; |
| 255 | index = nxy - 1; |
| 256 | if (nsc_y == 2) |
| 257 | index = nxy ++; |
| 258 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = x; |
| 259 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).index]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = y; |
| 260 | } |
| 261 | nd = 0; |
| 262 | } else if (ix == ixp + 1 && iy == iyp + 1) { // diagonal |
| 263 | nd ++; |
| 264 | if (nd == 1) |
| 265 | nxy ++; |
| 266 | nsc_x = nsc_y = 1; |
| 267 | } else { |
| 268 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"The path goes back in time."); |
| 269 | } |
| 270 | // update |
| 271 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nxy]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = xright; |
| 272 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nxy]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = ytop; |
| 273 | ixp = ix; |
| 274 | iyp = iy; |
| 275 | } |
| 276 | |
| 277 | if (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. > xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nxy].xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. || mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. > xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nxy].ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y.) { |
| 278 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ nxy]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x. = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 279 | xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).nxy]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y. = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 280 | } |
| 281 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (nxy <= 2 * std::max (mycxx . . $ `melder/melder.h:44:9`! ny, mycxx . . $ `melder/melder.h:44:9`! nx) + 2); |
| 282 | |
| 283 | thycxx . . $ `melder/melder.h:45:9`! nxycxx . . $ structDTW_Path_Query#nxy. = nxy; |
| 284 | thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 285 | thycxx . . $ `melder/melder.h:45:9`! xfromycxx . . $ structDTW_Path_Query#xfromy. =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). RealTier_createcxx . . $ RealTier_create(8e3ec305798a9b8e). (mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.); |
| 286 | for (integercxx . . $ integer# i = 1; i <= nxy; i ++) { |
| 287 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x., xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y.); |
| 288 | RealTier_addPointcxx . . $ RealTier_addPoint(d84c0874d617a544). (thycxx . . $ `melder/melder.h:45:9`! xfromycxx . . $ structDTW_Path_Query#xfromy..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#y., xytimes [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ DTW_Path_recode(1effd30d7a74ffbf).structPoint#x.); |
| 289 | } |
| 290 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 291 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not recoded."); |
| 292 | } |
| 293 | } |
| 294 | |
| 295 | void DTW_pathRemoveRedundantNodescxx . . $ DTW_pathRemoveRedundantNodes(1effd30d7a74ffbf). (DTWcxx . . $ DTW# me) { |
| 296 | integercxx . . $ integer# i = 1, skip = 0; |
| 297 | |
| 298 | for (integercxx . . $ integer# j = 2; j <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; j ++) { |
| 299 | if (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. ycxx . . $ structDTW_Path#y. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y. || mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. xcxx . . $ structDTW_Path#x. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x.) |
| 300 | skip ++; |
| 301 | else { |
| 302 | /* if (j-1)^th was the last of a series: store it */ |
| 303 | if (skip > 0) |
| 304 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ i] =cxx . . $ structDTW_Path#`operator=`(79e7d195d0f1460b). mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j - 1]; |
| 305 | /* same check again */ |
| 306 | skip = 0; |
| 307 | if (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. ycxx . . $ structDTW_Path#y. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y. || mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]. xcxx . . $ structDTW_Path#x. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x.) |
| 308 | skip ++; |
| 309 | else |
| 310 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ i] =cxx . . $ structDTW_Path#`operator=`(79e7d195d0f1460b). mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]; |
| 311 | } |
| 312 | } |
| 313 | if (skip > 0) |
| 314 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).++ i] =cxx . . $ structDTW_Path#`operator=`(79e7d195d0f1460b). mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.]; |
| 315 | mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. = i; |
| 316 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path..resizecxx . . $ autovector#resize(d91e89fbd57cd1). (mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.); // maintain invariant |
| 317 | } |
| 318 | |
| 319 | /* Prototype must be on y-axis and test on x-axis */ |
| 320 | |
| 321 | autoDTWcxx . . $ autoDTW# DTW_createcxx . . $ DTW_create(266b4c6b39481820). (double tminp, double tmaxp, integercxx . . $ integer# ntp, double dtp, double t1p, double tminc, double tmaxc, integercxx . . $ integer# ntc, double dtc, double t1c) { |
| 322 | try { |
| 323 | autoDTWcxx . . $ autoDTW# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (DTW); |
| 324 | Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), tminc, tmaxc, ntc, dtc, t1c, tminp, tmaxp, ntp, dtp, t1p); |
| 325 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. =cxx . . $ autovector#`operator=`(f4f0443dbfdd1e40). newvectorzerocxx . . $ newvectorzero(d6d5973469733409). <structDTW_Pathcxx . . $ structDTW_Path#> (ntc + ntp - 1); |
| 326 | DTW_Path_Query_initcxx . . $ DTW_Path_Query_init(32599237e6804113). (& mycxx . . $ `melder/melder.h:44:9`! pathQuerycxx . . $ structDTW#pathQuery., ntp, ntc); |
| 327 | mycxx . . $ `melder/melder.h:44:9`! wxcxx . . $ structDTW#wx. = 1; |
| 328 | mycxx . . $ `melder/melder.h:44:9`! wycxx . . $ structDTW#wy. = 1; |
| 329 | mycxx . . $ `melder/melder.h:44:9`! wdcxx . . $ structDTW#wd. = 2; |
| 330 | return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 331 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 332 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"DTW not created."); |
| 333 | } |
| 334 | } |
| 335 | |
| 336 | void DTW_setWeightscxx . . $ DTW_setWeights(c9c8af126407f471). (DTWcxx . . $ DTW# me, double wx, double wy, double wd) { |
| 337 | mycxx . . $ `melder/melder.h:44:9`! wxcxx . . $ structDTW#wx. = wx; |
| 338 | mycxx . . $ `melder/melder.h:44:9`! wycxx . . $ structDTW#wy. = wy; |
| 339 | mycxx . . $ `melder/melder.h:44:9`! wdcxx . . $ structDTW#wd. = wd; |
| 340 | } |
| 341 | |
| 342 | autoDTWcxx . . $ autoDTW# DTW_swapAxescxx . . $ DTW_swapAxes(6bfe1dff7e6574dc). (DTWcxx . . $ DTW# me) { |
| 343 | try { |
| 344 | autoDTWcxx . . $ autoDTW# thee = DTW_createcxx . . $ DTW_create(266b4c6b39481820). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy., mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1.); |
| 345 | |
| 346 | transpose_MAT_outcxx . . $ transpose_MAT_out(a7d93ba40fe22fe0). (thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).(), mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).()); |
| 347 | |
| 348 | thycxx . . $ `melder/melder.h:45:9`! pathLengthcxx . . $ structDTW#pathLength. = mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; |
| 349 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; i ++) { |
| 350 | thycxx . . $ `melder/melder.h:45:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x. = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y.; |
| 351 | thycxx . . $ `melder/melder.h:45:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y. = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x.; |
| 352 | } |
| 353 | thycxx . . $ `melder/melder.h:45:9`! pathcxx . . $ structDTW#path..resizecxx . . $ autovector#resize(d91e89fbd57cd1). (thycxx . . $ `melder/melder.h:45:9`! pathLengthcxx . . $ structDTW#pathLength.); // maintain invariant |
| 354 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 355 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 356 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": axes not swapped."); |
| 357 | } |
| 358 | } |
| 359 | |
| 360 | double DTW_getPathYcxx . . $ DTW_getPathY(17d996b58e1db56). (DTWcxx . . $ DTW# me, double tx) { |
| 361 | // Assume linear behaviour outside domains |
| 362 | // Other option: scale with x_domain/y_domain |
| 363 | |
| 364 | if (tx < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 365 | return mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. - (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. - tx); |
| 366 | if (tx > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 367 | return mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. + (tx - mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.); |
| 368 | |
| 369 | |
| 370 | // Find column in DTW matrix |
| 371 | |
| 372 | integercxx . . $ integer# ix = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! ((tx - mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1.) / mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.) + 1; |
| 373 | if (ix < 1) |
| 374 | ix = 1; |
| 375 | if (ix > mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) |
| 376 | ix = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 377 | |
| 378 | // Find index in the path and the row number (iy) |
| 379 | |
| 380 | integercxx . . $ integer# i = ix + mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1]. xcxx . . $ structDTW_Path#x. - 1; |
| 381 | while (i <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x. != ix) |
| 382 | i ++; |
| 383 | |
| 384 | if (i > mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.) |
| 385 | return undefinedcxx . . $ undefined.; |
| 386 | |
| 387 | const integercxx . . $ integer# iy = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y.; /* row */ |
| 388 | |
| 389 | /* |
| 390 | We like to have a "continuous" interpretation of time for the quantized x and y times. |
| 391 | A time block is specified by lower left (x,y) and upper right (x+dx,y+dy). |
| 392 | The path is interpreted as piecewise linear. |
| 393 | Two special cases: |
| 394 | 1. the local path is horizontal, i.e. two or more path elements with the same path.y value. |
| 395 | We calculate the y-time from the line that connects the lower-left position of the leftmost |
| 396 | horizontal time block to the upper-right position of the rightmost time horizontal block. |
| 397 | (lowest column number to highest column number) |
| 398 | For the first column and the last column we need to do something special if |
| 399 | 2. the local path is vertical, i.e. two or path elements with the same path.x value. |
| 400 | We calculate the y-time from the line that connects the lower-left position of the bottommost |
| 401 | vertical time block to the upper-right position of the topmost time horizontal block. |
| 402 | (lowest row number to highest row number) |
| 403 | */ |
| 404 | |
| 405 | // Horizontal path? Find left and right positions. |
| 406 | |
| 407 | integercxx . . $ integer# ileft = i - 1; |
| 408 | while (ileft >= 1 && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ileft]. ycxx . . $ structDTW_Path#y. == iy) |
| 409 | ileft --; |
| 410 | |
| 411 | ileft ++; |
| 412 | if (ileft == 1 && ix > 1 && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ileft]. ycxx . . $ structDTW_Path#y. > 1) |
| 413 | ileft ++; |
| 414 | |
| 415 | integercxx . . $ integer# iright = i + 1; |
| 416 | while (iright <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iright]. ycxx . . $ structDTW_Path#y. == iy) |
| 417 | iright ++; |
| 418 | |
| 419 | iright --; |
| 420 | if (iright == mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. && ix < mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).iright]. ycxx . . $ structDTW_Path#y. < mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) |
| 421 | iright --; |
| 422 | |
| 423 | integercxx . . $ integer# nxx = iright - ileft + 1; |
| 424 | |
| 425 | // Vertical path? Only if not already horizontal. |
| 426 | |
| 427 | integercxx . . $ integer# ibottom = i, itop = i; |
| 428 | |
| 429 | if (nxx == 1) { |
| 430 | ibottom --; |
| 431 | while (ibottom >= 1 && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ibottom]. xcxx . . $ structDTW_Path#x. == ix) |
| 432 | ibottom --; |
| 433 | |
| 434 | ibottom ++; |
| 435 | |
| 436 | itop ++; |
| 437 | while (itop <= 1 && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).itop]. xcxx . . $ structDTW_Path#x. == ix) |
| 438 | itop --; |
| 439 | |
| 440 | itop ++; |
| 441 | } |
| 442 | |
| 443 | const integercxx . . $ integer# nyy = itop - ibottom + 1; |
| 444 | double boxx = nxx * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 445 | double boxy = nyy * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; |
| 446 | double ty; |
| 447 | |
| 448 | // Corrections at extreme left and right if path [1].x=1 && path [1].y>1 |
| 449 | |
| 450 | if (ix == mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.) { |
| 451 | boxx = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - (mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (ix - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. - mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / 2.0); |
| 452 | boxy = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - (mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (iy - 1) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. - mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. / 2.0); |
| 453 | ty = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - (boxy - (boxx - (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - tx)) * boxy / boxx); |
| 454 | } else if (ix == 1) { |
| 455 | boxx = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / 2.0 - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 456 | boxy = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (itop - 1) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. + mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. / 2.0 - mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 457 | ty = (tx - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) * boxy / boxx + mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 458 | } else { |
| 459 | // Diagonal interpolation in a box with lower left (0,0) and upper right (nxx*dx, nyy*dy). |
| 460 | const double ty0 = (tx - (mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ileft]. xcxx . . $ structDTW_Path#x. - 1.0) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. - mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / 2.0)) * boxy / boxx; |
| 461 | ty = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ibottom]. ycxx . . $ structDTW_Path#y. - 1.0) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. - mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy. / 2.0 + ty0; |
| 462 | } |
| 463 | return ty; |
| 464 | } |
| 465 | |
| 466 | integercxx . . $ integer# DTW_getMaximumConsecutiveStepscxx . . $ DTW_getMaximumConsecutiveSteps(34de04e3b517b2cc). (DTWcxx . . $ DTW# me, int direction) { |
| 467 | integercxx . . $ integer# nglobal = 1, nlocal = 1; |
| 468 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; i ++) { |
| 469 | int localdirection; |
| 470 | if (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1]. ycxx . . $ structDTW_Path#y.) |
| 471 | localdirection = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 472 | else if (mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. xcxx . . $ structDTW_Path#x. == mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - 1]. xcxx . . $ structDTW_Path#x.) |
| 473 | localdirection = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 474 | else |
| 475 | localdirection = DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`!; |
| 476 | if (localdirection == direction) |
| 477 | nlocal += 1; |
| 478 | if (direction != localdirection || i == mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.) { |
| 479 | if (nlocal > nglobal) |
| 480 | nglobal = nlocal; |
| 481 | nlocal = 1; |
| 482 | } |
| 483 | } |
| 484 | return nglobal; |
| 485 | } |
| 486 | |
| 487 | static void DTW_paintDistances_rawcxx . . $ DTW_paintDistances_raw(f6bf7b8b1c7306af). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish, bool inset) { |
| 488 | integercxx . . $ integer# ixmin, ixmax, iymin, iymax; |
| 489 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & xmin, & xmax); |
| 490 | SampledXY_unidirectionalAutowindowYcxx . . $ SampledXY_unidirectionalAutowindowY(b6a531eed30bf40e). (me, & ymin, & ymax); |
| 491 | (void) Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (me, xmin - 0.49999 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., xmax + 0.49999 * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., & ixmin, & ixmax); |
| 492 | (void) Matrix_getWindowSamplesYcxx . . $ Matrix_getWindowSamplesY(c738979be11bd51a). (me, ymin - 0.49999 * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy., ymax + 0.49999 * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy., & iymin, & iymax); |
| 493 | if (maximum <= minimum) |
| 494 | (void) Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (me, ixmin, ixmax, iymin, iymax, & minimum, & maximum); |
| 495 | |
| 496 | if (maximum <= minimum) { |
| 497 | minimum -= 1.0; |
| 498 | maximum += 1.0; |
| 499 | } |
| 500 | if (xmin >= xmax || ymin >= ymax) |
| 501 | return; |
| 502 | if (inset) |
| 503 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 504 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 505 | Graphics_cellArraycxx . . $ Graphics_cellArray(a5d48eb8683d0521). (g, mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..partcxx . . $ automatrix#part(5c23e73480cfacfb). (iymin, iymax, ixmin, ixmax), |
| 506 | Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmin - 0.5), Matrix_columnToXcxx . . $ Matrix_columnToX(89d6d8659270b8b7). (me, ixmax + 0.5), |
| 507 | Matrix_rowToYcxx . . $ Matrix_rowToY(89d6d8659270b8b7). (me, iymin - 0.5), Matrix_rowToYcxx . . $ Matrix_rowToY(89d6d8659270b8b7). (me, iymax + 0.5), |
| 508 | minimum, maximum); |
| 509 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 510 | if (inset) |
| 511 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 512 | if (garnish) { |
| 513 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 514 | Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 515 | } |
| 516 | } |
| 517 | |
| 518 | void DTW_paintDistancescxx . . $ DTW_paintDistances(24885978ad4cd331). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double minimum, double maximum, bool garnish) { |
| 519 | DTW_paintDistances_rawcxx . . $ DTW_paintDistances_raw(f6bf7b8b1c7306af). (me, g, xmin, xmax, ymin, ymax, minimum, maximum, garnish, true); |
| 520 | } |
| 521 | |
| 522 | static double RealTier_getXAtIndexcxx . . $ RealTier_getXAtIndex(6672734ab0fefeb0). (RealTiercxx . . $ RealTier# me, integercxx . . $ integer# ipoint) { |
| 523 | return ( ipoint > 0 && ipoint <= mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size. ? mycxx . . $ `melder/melder.h:44:9`! pointscxx . . $ structRealTier#points..atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint] -> numbercxx . . $ structSimpleDouble#number. : undefinedcxx . . $ undefined. ); |
| 524 | } |
| 525 | |
| 526 | static void DTW_drawPath_rawcxx . . $ DTW_drawPath_raw(e4aa7edb19c14841). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, bool garnish, bool inset) { |
| 527 | DTW_Path_Querycxx . . $ DTW_Path_Query# thee = & mycxx . . $ `melder/melder.h:44:9`! pathQuerycxx . . $ structDTW#pathQuery.; |
| 528 | |
| 529 | if (xmin >= xmax) { |
| 530 | xmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 531 | xmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 532 | } |
| 533 | if (ymin >= ymax) { |
| 534 | ymin = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 535 | ymax = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 536 | } |
| 537 | |
| 538 | if (inset) |
| 539 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 540 | |
| 541 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 542 | double x1 = RealTier_getXAtIndexcxx . . $ RealTier_getXAtIndex(6672734ab0fefeb0). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1); |
| 543 | double y1 = RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1); |
| 544 | for (integercxx . . $ integer# i = 2; i <= thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx. ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). pointscxx . . $ structRealTier#points..sizecxx . . $ CollectionOf#size.; i ++) { |
| 545 | const double x2 = RealTier_getXAtIndexcxx . . $ RealTier_getXAtIndex(6672734ab0fefeb0). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i); |
| 546 | const double y2 = RealTier_getValueAtIndexcxx . . $ RealTier_getValueAtIndex(ed98425824ac647a). (thycxx . . $ `melder/melder.h:45:9`! yfromxcxx . . $ structDTW_Path_Query#yfromx..getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), i); |
| 547 | double xc1, yc1, xc2, yc2; |
| 548 | if (NUMclipLineWithinRectanglecxx . . $ NUMclipLineWithinRectangle(dbd26f6c64c2fbf9). (x1, y1, x2, y2, xmin, ymin, xmax, ymax, & xc1, & yc1, & xc2, & yc2)) |
| 549 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, xc1, yc1, xc2, yc2); |
| 550 | |
| 551 | x1 = x2; |
| 552 | y1 = y2; |
| 553 | } |
| 554 | |
| 555 | if (inset) |
| 556 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 557 | |
| 558 | if (garnish) { |
| 559 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 560 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 561 | Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 562 | } |
| 563 | } |
| 564 | |
| 565 | void DTW_drawPathcxx . . $ DTW_drawPath(5f4953c8558cdc27). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, bool garnish) { |
| 566 | DTW_drawPath_rawcxx . . $ DTW_drawPath_raw(e4aa7edb19c14841). (me, g, xmin, xmax, ymin, ymax, garnish, true); |
| 567 | } |
| 568 | |
| 569 | static void DTW_drawWarp_rawcxx . . $ DTW_drawWarp_raw(18eef65c072f4354). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double t, bool garnish, bool inset, bool warpX) { |
| 570 | const double tx = ( warpX ? t : DTW_getXTimeFromYTimecxx . . $ DTW_getXTimeFromYTime(17d996b58e1db56). (me, t) ); |
| 571 | const double ty = ( warpX ? DTW_getYTimeFromXTimecxx . . $ DTW_getYTimeFromXTime(17d996b58e1db56). (me, t) : t ); |
| 572 | const int lineType = Graphics_inqLineTypecxx . . $ Graphics_inqLineType(d4bbe1b9daaaf11b). (g); |
| 573 | |
| 574 | if (xmin >= xmax) { |
| 575 | xmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 576 | xmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 577 | } |
| 578 | if (ymin >= ymax) { |
| 579 | ymin = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 580 | ymax = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 581 | } |
| 582 | |
| 583 | if (inset) |
| 584 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 585 | |
| 586 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 587 | |
| 588 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`!); |
| 589 | if (ty <= ymax) { |
| 590 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tx, ymin, tx, ty); |
| 591 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tx, ty, xmin, ty); |
| 592 | } else { |
| 593 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tx, ymin, tx, ymax); |
| 594 | } |
| 595 | |
| 596 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, lineType); |
| 597 | |
| 598 | if (inset) |
| 599 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 600 | |
| 601 | if (garnish) { |
| 602 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, tx, true, true, false, nullptr); |
| 603 | if (ty <= ymax) |
| 604 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, ty, true, true, false, nullptr); |
| 605 | } |
| 606 | } |
| 607 | |
| 608 | void DTW_drawWarpXcxx . . $ DTW_drawWarpX(d33eabef8cb26635). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double tx, bool garnish) { |
| 609 | DTW_drawWarp_rawcxx . . $ DTW_drawWarp_raw(18eef65c072f4354). (me, g, xmin, xmax, ymin, ymax, tx, garnish, true, true); |
| 610 | } |
| 611 | |
| 612 | void DTW_drawWarpYcxx . . $ DTW_drawWarpY(d33eabef8cb26635). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double ty, bool garnish) { |
| 613 | DTW_drawWarp_rawcxx . . $ DTW_drawWarp_raw(18eef65c072f4354). (me, g, xmin, xmax, ymin, ymax, ty, garnish, true, false); |
| 614 | } |
| 615 | |
| 616 | static void DTW_Sounds_checkDomainscxx . . $ DTW_Sounds_checkDomains(29295714b45dfbac). (DTWcxx . . $ DTW# me, Soundcxx . . $ Sound# *y, Soundcxx . . $ Sound# *x, double *xmin, double *xmax, double *ymin, double *ymax) { |
| 617 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! ((mycxx . . $ `melder/melder.h:44:9`! ymin == (*y) -> xmin && mycxx . . $ `melder/melder.h:44:9`! ymax == (*y) -> xmax && |
| 618 | mycxx . . $ `melder/melder.h:44:9`! xmin == (*x) -> xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == (*x) -> xmax) || |
| 619 | (mycxx . . $ `melder/melder.h:44:9`! ymin == (*x) -> xmin && mycxx . . $ `melder/melder.h:44:9`! ymax == (*x) -> xmax && |
| 620 | mycxx . . $ `melder/melder.h:44:9`! xmin == (*y) -> xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == (*y) -> xmax), |
| 621 | U"The domains of the DTW and the sound(s) should be equal."); |
| 622 | |
| 623 | if (*xmin >= *xmax) { |
| 624 | *xmin = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 625 | *xmax = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 626 | } |
| 627 | if (*ymin >= *ymax) { |
| 628 | *ymin = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 629 | *ymax = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 630 | } |
| 631 | } |
| 632 | |
| 633 | static void drawBoxcxx . . $ drawBox(2d838ed765120c5d). (Graphicscxx . . $ Graphics# g) { |
| 634 | double x1WC, x2WC, y1WC, y2WC; |
| 635 | const double lineWidth = Graphics_inqLineWidthcxx . . $ Graphics_inqLineWidth(f906975acce41a59). (g); |
| 636 | Graphics_inqWindowcxx . . $ Graphics_inqWindow(962850f2031ce0d0). (g, & x1WC, & x2WC, & y1WC, & y2WC); |
| 637 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, 2.0 * lineWidth); |
| 638 | Graphics_rectanglecxx . . $ Graphics_rectangle(72bdb7937dbb13da). (g, x1WC, x2WC, y1WC, y2WC); |
| 639 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (g, lineWidth); |
| 640 | } |
| 641 | |
| 642 | /* |
| 643 | In a picture with a DTW and a left and bottom Sound, we want "width" of the vertical sound |
| 644 | and the "height" of the horizontal Sound to be equal. |
| 645 | Given the horizontal fraction of the DTW-part, this routine returns the vertical part. |
| 646 | */ |
| 647 | static double _DTW_Sounds_getPartYcxx . . $ _DTW_Sounds_getPartY(f042c24bcd87f07e). (Graphicscxx . . $ Graphics# g, double dtw_part_x) { |
| 648 | double x1NDC, x2NDC, y1NDC, y2NDC; |
| 649 | Graphics_inqViewportcxx . . $ Graphics_inqViewport(962850f2031ce0d0). (g, & x1NDC, & x2NDC, & y1NDC, & y2NDC); |
| 650 | return 1.0 - (1.0 - dtw_part_x) * (x2NDC - x1NDC) / (y2NDC - y1NDC); |
| 651 | } |
| 652 | |
| 653 | void DTW_Sounds_drawcxx . . $ DTW_Sounds_draw(97171f0d49a5d1e1). (DTWcxx . . $ DTW# me, Soundcxx . . $ Sound# y, Soundcxx . . $ Sound# x, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, bool garnish) { |
| 654 | DTW_Sounds_checkDomainscxx . . $ DTW_Sounds_checkDomains(29295714b45dfbac). (me, & y, & x, & xmin, & xmax, & ymin, & ymax); |
| 655 | |
| 656 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 657 | Graphics_Viewportcxx . . $ Graphics_Viewport# ovp = g -> outerViewportcxx . . $ structGraphics#outerViewport.; // save for unsetInner |
| 658 | |
| 659 | const double dtw_part_x = 0.85; |
| 660 | const double dtw_part_y = _DTW_Sounds_getPartYcxx . . $ _DTW_Sounds_getPartY(f042c24bcd87f07e). (g, dtw_part_x); |
| 661 | |
| 662 | // DTW |
| 663 | |
| 664 | Graphics_Viewportcxx . . $ Graphics_Viewport# vp = Graphics_insetViewportcxx . . $ Graphics_insetViewport(b48873d7bfae0d92). (g, 1.0 - dtw_part_x, 1.0, 1.0 - dtw_part_y, 1.0); |
| 665 | DTW_paintDistances_rawcxx . . $ DTW_paintDistances_raw(f6bf7b8b1c7306af). (me, g, xmin, xmax, ymin, ymax, 0.0, 0.0, false, false); |
| 666 | DTW_drawPath_rawcxx . . $ DTW_drawPath_raw(e4aa7edb19c14841). (me, g, xmin, xmax, ymin, ymax, false, false); |
| 667 | drawBoxcxx . . $ drawBox(2d838ed765120c5d). (g); |
| 668 | Graphics_resetViewportcxx . . $ Graphics_resetViewport(620f27fff4cd4a03). (g, vp); |
| 669 | |
| 670 | // Sound y |
| 671 | |
| 672 | vp =cxx . . $ $anonymous_type_5b6ec70e96eeadfb_0#`operator=`(6a528276102e99b). Graphics_insetViewportcxx . . $ Graphics_insetViewport(b48873d7bfae0d92). (g, 0.0, 1.0 - dtw_part_x, 1.0 - dtw_part_y, 1.0); |
| 673 | Sound_draw_btlrcxx . . $ Sound_draw_btlr(795e12f324b9f7ba). (y, g, ymin, ymax, -1.0, 1.0, kSoundDrawingDirectioncxx . . $ kSoundDrawingDirection#::BOTTOM_TO_TOPcxx . . $ kSoundDrawingDirection#BOTTOM_TO_TOP., false); |
| 674 | if (garnish) |
| 675 | drawBoxcxx . . $ drawBox(2d838ed765120c5d). (g); |
| 676 | Graphics_resetViewportcxx . . $ Graphics_resetViewport(620f27fff4cd4a03). (g, vp); |
| 677 | |
| 678 | // Sound x |
| 679 | |
| 680 | vp =cxx . . $ $anonymous_type_5b6ec70e96eeadfb_0#`operator=`(6a528276102e99b). Graphics_insetViewportcxx . . $ Graphics_insetViewport(b48873d7bfae0d92). (g, 1 - dtw_part_x, 1, 0, 1 - dtw_part_y); |
| 681 | Sound_draw_btlrcxx . . $ Sound_draw_btlr(795e12f324b9f7ba). (x, g, xmin, xmax, -1.0, 1.0, kSoundDrawingDirectioncxx . . $ kSoundDrawingDirection#::LEFT_TO_RIGHTcxx . . $ kSoundDrawingDirection#LEFT_TO_RIGHT., false); |
| 682 | if (garnish) |
| 683 | drawBoxcxx . . $ drawBox(2d838ed765120c5d). (g); |
| 684 | Graphics_resetViewportcxx . . $ Graphics_resetViewport(620f27fff4cd4a03). (g, vp); |
| 685 | |
| 686 | |
| 687 | // Set window coordinates so that margins will work, i.e. extend time domains |
| 688 | |
| 689 | const double xmin3 = xmax - (xmax - xmin) / dtw_part_x; |
| 690 | const double ymin3 = ymax - (ymax - ymin) / dtw_part_y; |
| 691 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin3, xmax, ymin3, ymax); |
| 692 | |
| 693 | g -> outerViewportcxx . . $ structGraphics#outerViewport. =cxx . . $ $anonymous_type_5b6ec70e96eeadfb_0#`operator=`(89cb37edafb745f1). ovp; // restore from _setInner |
| 694 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 695 | |
| 696 | if (garnish) { |
| 697 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, ymin, true, true, false, nullptr); |
| 698 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, ymax, true, true, false, nullptr); |
| 699 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, xmin, true, true, false, nullptr); |
| 700 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, xmax, true, true, false, nullptr); |
| 701 | } |
| 702 | } |
| 703 | |
| 704 | void DTW_Sounds_drawWarpXcxx . . $ DTW_Sounds_drawWarpX(e4c95a0d2ec92c03). (DTWcxx . . $ DTW# me, Soundcxx . . $ Sound# yy, Soundcxx . . $ Sound# xx, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double ymin, double ymax, double tx, bool garnish) |
| 705 | { |
| 706 | Soundcxx . . $ Sound# y = yy, x = xx; |
| 707 | const int lineType = Graphics_inqLineTypecxx . . $ Graphics_inqLineType(d4bbe1b9daaaf11b). (g); |
| 708 | |
| 709 | DTW_Sounds_checkDomainscxx . . $ DTW_Sounds_checkDomains(29295714b45dfbac). (me, & y, & x, & xmin, & xmax, & ymin, & ymax); |
| 710 | |
| 711 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 712 | const double dtw_part_x = 0.85; |
| 713 | const double dtw_part_y = _DTW_Sounds_getPartYcxx . . $ _DTW_Sounds_getPartY(f042c24bcd87f07e). (g, dtw_part_x); |
| 714 | |
| 715 | xmin = xmax - (xmax - xmin) / dtw_part_x; |
| 716 | ymin = ymax - (ymax - ymin) / dtw_part_y; |
| 717 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, ymin, ymax); |
| 718 | |
| 719 | const double ty = DTW_getYTimeFromXTimecxx . . $ DTW_getYTimeFromXTime(17d996b58e1db56). (me, tx); |
| 720 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, Graphics_DOTTEDcxx . . $ `sys/Graphics.h:288:9`!); |
| 721 | |
| 722 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tx, ymin, tx, ty); |
| 723 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (g, tx, ty, xmin, ty); |
| 724 | |
| 725 | Graphics_setLineTypecxx . . $ Graphics_setLineType(9abe41586e87648d). (g, lineType); |
| 726 | |
| 727 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 728 | |
| 729 | if (garnish) { |
| 730 | Graphics_markBottomcxx . . $ Graphics_markBottom(e82cc8dc402e8bd7). (g, tx, true, true, false, nullptr); |
| 731 | Graphics_markLeftcxx . . $ Graphics_markLeft(e82cc8dc402e8bd7). (g, ty, true, true, false, nullptr); |
| 732 | } |
| 733 | } |
| 734 | |
| 735 | autoMatrixcxx . . $ autoMatrix# DTW_to_Matrix_distancescxx . . $ DTW_to_Matrix_distances(1f5473e394883f73). (DTWcxx . . $ DTW# me) { |
| 736 | try { |
| 737 | autoMatrixcxx . . $ autoMatrix# thee = Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy., mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1.); |
| 738 | thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).(); |
| 739 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 740 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 741 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": distances not converted to Matrix."); |
| 742 | } |
| 743 | } |
| 744 | |
| 745 | /* nog aanpassen, dl = sqrt (dx^2 + dy^2) */ |
| 746 | void DTW_drawDistancesAlongPathcxx . . $ DTW_drawDistancesAlongPath(5f4953c8558cdc27). (DTWcxx . . $ DTW# me, Graphicscxx . . $ Graphics# g, double xmin, double xmax, double dmin, double dmax, bool garnish) { |
| 747 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & xmin, & xmax); |
| 748 | integercxx . . $ integer# ixmax, ixmin; |
| 749 | if (Matrix_getWindowSamplesXcxx . . $ Matrix_getWindowSamplesX(c738979be11bd51a). (me, xmin, xmax, & ixmin, & ixmax) == 0) |
| 750 | return; |
| 751 | |
| 752 | integercxx . . $ integer# ii = 1; |
| 753 | while (ii < mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ii]. xcxx . . $ structDTW_Path#x. < ixmin) |
| 754 | ii ++; |
| 755 | ixmin = ii; |
| 756 | |
| 757 | while (ii <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. && mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).ii]. xcxx . . $ structDTW_Path#x. < ixmax) |
| 758 | ii ++; |
| 759 | ixmax = ii; |
| 760 | |
| 761 | const integercxx . . $ integer# numberOfSelected = ixmax - ixmin + 1; |
| 762 | autoVECcxx . . $ autoVEC# d = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (numberOfSelected); |
| 763 | |
| 764 | for (integercxx . . $ integer# i = ixmin; i <= ixmax; i ++) |
| 765 | d [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i - ixmin + 1] = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).i]. ycxx . . $ structDTW_Path#y.] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i]; |
| 766 | |
| 767 | if (dmin >= dmax) { |
| 768 | NUMextrema_ucxx . . $ NUMextrema_u(9aff78012e48d2eb). (dcxx . . $ constvectorview#constvectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), & dmin, & dmax); |
| 769 | if (isundefcxx . . $ isundef(f8197d536af80c96). (dmin) || isundefcxx . . $ isundef(f8197d536af80c96). (dmax)) |
| 770 | return; |
| 771 | } else |
| 772 | VECclip_inplacecxx . . $ VECclip_inplace(c22bf7a6e3d33143). (dmin, dcxx . . $ vectorview#vectorview(eac9d6ec4c4bfecd)..getcxx . . $ autovector#get(e8d1da7fe68a6585).(), dmax); |
| 773 | |
| 774 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 775 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (g, xmin, xmax, dmin, dmax); |
| 776 | Graphics_functioncxx . . $ Graphics_function(1c6279e2c8b8beb1). (g, d.asArgumentToFunctionThatExpectsOneBasedArraycxx . . $ autovector#asArgumentToFunctionThatExpectsOneBasedArray(5a2a78a048fb49a8).(), 1, numberOfSelected, xmin, xmax); |
| 777 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 778 | |
| 779 | if (garnish) { |
| 780 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 781 | Graphics_textLeftcxx . . $ Graphics_textLeft(48cf1f690ec61203). (g, true, U"distance"); |
| 782 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 783 | Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 784 | } |
| 785 | } |
| 786 | |
| 787 | /* |
| 788 | metric = 1...n (sum (a_i^n))^(1/n) |
| 789 | */ |
| 790 | autoDTWcxx . . $ autoDTW# Matrices_to_DTWcxx . . $ Matrices_to_DTW(f5b87c2dcdd95520). (Matrixcxx . . $ Matrix# me, Matrixcxx . . $ Matrix# thee, bool matchStart, bool matchEnd, int slope, double metric) { |
| 791 | try { |
| 792 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (thycxx . . $ `melder/melder.h:45:9`! ny == mycxx . . $ `melder/melder.h:44:9`! ny, |
| 793 | U"Column sizes should be equal."); |
| 794 | |
| 795 | autoDTWcxx . . $ autoDTW# him = DTW_createcxx . . $ DTW_create(266b4c6b39481820). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax., thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx., thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx., thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1.); |
| 796 | autoMelderProgresscxx . . $ autoMelderProgress# progesscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"Matrices to DTW: Calculate distances..."); |
| 797 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 798 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) { |
| 799 | /* |
| 800 | First divide distance by maximum to prevent overflow when metric |
| 801 | is a large number. |
| 802 | d = (x^n)^(1/n) may overflow if x>1 & n >>1 even if d would not overflow! |
| 803 | */ |
| 804 | double dmax = 0.0, d = 0.0; |
| 805 | for (integercxx . . $ integer# k = 1; k <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; k ++) { |
| 806 | const double dtmp = fabscxx . . $ fabs(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] - thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]); |
| 807 | if (dtmp > dmax) |
| 808 | dmax = dtmp; |
| 809 | } |
| 810 | if (dmax > 0) { |
| 811 | for (integercxx . . $ integer# k = 1; k <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; k ++) { |
| 812 | const double dtmp = fabscxx . . $ fabs(fee4f1d22bc8e617). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).i] - thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) / dmax; |
| 813 | d += powcxx . . $ pow(b71928d39fde4295). (dtmp, metric); |
| 814 | } |
| 815 | } |
| 816 | d = dmax * powcxx . . $ pow(b71928d39fde4295). (d, 1.0 / metric); |
| 817 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = d / mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; // == d * dy / ymax |
| 818 | } |
| 819 | if ((i % 10) == 1) { |
| 820 | Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.999 * i / mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., U"Calculate distances: column ", i, U" from ", mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., U"."); |
| 821 | } |
| 822 | } |
| 823 | DTW_findPathcxx . . $ DTW_findPath(7c4c07b8524d5375). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), matchStart, matchEnd, slope); |
| 824 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 825 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 826 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"DTW not created from matrices."); |
| 827 | } |
| 828 | } |
| 829 | |
| 830 | autoDTWcxx . . $ autoDTW# Spectrograms_to_DTWcxx . . $ Spectrograms_to_DTW(c41ee0357e90fdaa). (Spectrogramcxx . . $ Spectrogram# me, Spectrogramcxx . . $ Spectrogram# thee, bool matchStart, bool matchEnd, int slope, double metric) { |
| 831 | try { |
| 832 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! ymax == thycxx . . $ `melder/melder.h:45:9`! ymax && mycxx . . $ `melder/melder.h:44:9`! ny == thycxx . . $ `melder/melder.h:45:9`! ny, |
| 833 | U"The number of frequencies and/or frequency ranges should be equal."); |
| 834 | |
| 835 | autoMatrixcxx . . $ autoMatrix# m1 = Spectrogram_to_Matrixcxx . . $ Spectrogram_to_Matrix(9f47dc33fb88330d). (me); |
| 836 | autoMatrixcxx . . $ autoMatrix# m2 = Spectrogram_to_Matrixcxx . . $ Spectrogram_to_Matrix(9f47dc33fb88330d). (thee); |
| 837 | |
| 838 | /* |
| 839 | Take log10 for dB's (4e-10 scaling not necessary) |
| 840 | */ |
| 841 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) { |
| 842 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++) |
| 843 | m1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (m1 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]); |
| 844 | } |
| 845 | for (integercxx . . $ integer# i = 1; i <= thycxx . . $ `melder/melder.h:45:9`! nycxx . . $ structSampledXY#ny.; i ++) { |
| 846 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) |
| 847 | m2 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = 10.0 * log10cxx . . $ log10(fee4f1d22bc8e617). (m2 ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]); |
| 848 | } |
| 849 | |
| 850 | autoDTWcxx . . $ autoDTW# him = Matrices_to_DTWcxx . . $ Matrices_to_DTW(f5b87c2dcdd95520). (m1.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), m2.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), matchStart, matchEnd, slope, metric); |
| 851 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 852 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 853 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"DTW not created from Spectrograms."); |
| 854 | } |
| 855 | } |
| 856 | |
| 857 | static int Pitch_findFirstAndLastVoicedFramecxx . . $ Pitch_findFirstAndLastVoicedFrame(5897c7d7bd1ec2c6). (Pitchcxx . . $ Pitch# me, integercxx . . $ integer# *first, integercxx . . $ integer# *last) { |
| 858 | *first = 1; |
| 859 | while (*first <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. && ! Pitch_isVoiced_icxx . . $ Pitch_isVoiced_i(fd5b671aa7b53262). (me, *first)) |
| 860 | (*first) ++; |
| 861 | |
| 862 | *last = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 863 | while (*last >= *first && ! Pitch_isVoiced_icxx . . $ Pitch_isVoiced_i(fd5b671aa7b53262). (me, *last)) |
| 864 | (*last) --; |
| 865 | |
| 866 | return *first <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. && *last >= 1; |
| 867 | } |
| 868 | |
| 869 | autoDTWcxx . . $ autoDTW# Pitches_to_DTW_sgccxx . . $ Pitches_to_DTW_sgc(ec88775ba582cd9c). (Pitchcxx . . $ Pitch# me, Pitchcxx . . $ Pitch# thee, double vuv_costs, double time_weight, bool matchStart, bool matchEnd, int slope); |
| 870 | autoDTWcxx . . $ autoDTW# Pitches_to_DTW_sgccxx . . $ Pitches_to_DTW_sgc(ec88775ba582cd9c). (Pitchcxx . . $ Pitch# me, Pitchcxx . . $ Pitch# thee, double vuv_costs, double time_weight, bool matchStart, bool matchEnd, int slope) { // vuv_costs=24, time_weight=10 ? |
| 871 | try { |
| 872 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vuv_costs >= 0.0, |
| 873 | U"Voiced-unvoiced costs should not be negative."); |
| 874 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (time_weight >= 0.0, |
| 875 | U"Time costs weight should not be negative."); |
| 876 | |
| 877 | integercxx . . $ integer# myfirst, mylast, thyfirst, thylast; |
| 878 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (Pitch_findFirstAndLastVoicedFrame (me, & myfirst, & mylast) && Pitch_findFirstAndLastVoicedFrame (thee, & thyfirst, & thylast), |
| 879 | U"No voiced frames."); |
| 880 | |
| 881 | /* |
| 882 | We do not want the silences before the first voiced frame and after the last voiced frame |
| 883 | to determine the distances. |
| 884 | We create paths from (1,1)...(thyfirst,myfirst) and (thylast,mylast)...(thy nx,my nx) |
| 885 | by making the other cell's distances very large. |
| 886 | */ |
| 887 | autoDTWcxx . . $ autoDTW# him = DTW_createcxx . . $ DTW_create(266b4c6b39481820). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax., thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx., thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx., thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1.); |
| 888 | autoVECcxx . . $ autoVEC# pitchx = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.); |
| 889 | kPitch_unitcxx . . $ kPitch_unit# unit = kPitch_unitcxx . . $ kPitch_unit#::SEMITONES_100cxx . . $ kPitch_unit#SEMITONES_100.; |
| 890 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) |
| 891 | pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] = Sampled_getValueAtSamplecxx . . $ Sampled_getValueAtSample(5092633e80007c54). (thee, j, Pitch_LEVEL_FREQUENCYcxx . . $ `fon/Pitch.h:85:9`!, (int) unit); |
| 892 | |
| 893 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 894 | const double pitchy = Sampled_getValueAtSamplecxx . . $ Sampled_getValueAtSample(5092633e80007c54). (me, i, Pitch_LEVEL_FREQUENCYcxx . . $ `fon/Pitch.h:85:9`!, (int) unit); |
| 895 | const double t1 = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 896 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) { |
| 897 | const double t2 = thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. + (j - 1) * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.; |
| 898 | const double dist_t = fabscxx . . $ fabs(fee4f1d22bc8e617). (t1 - t2); |
| 899 | double dist_f = 0.0; // based on pitch difference |
| 900 | if (isundefcxx . . $ isundef(f8197d536af80c96). (pitchy)) { |
| 901 | if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j])) |
| 902 | dist_f = vuv_costs; |
| 903 | } else if (isundefcxx . . $ isundef(f8197d536af80c96). (pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j])) { |
| 904 | dist_f = vuv_costs; |
| 905 | } else { |
| 906 | dist_f = fabscxx . . $ fabs(fee4f1d22bc8e617). (pitchy - pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]); |
| 907 | } |
| 908 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (dist_f * dist_f + time_weight * dist_t * dist_t); |
| 909 | } |
| 910 | } |
| 911 | DTW_findPathcxx . . $ DTW_findPath(7c4c07b8524d5375). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), matchStart, matchEnd, slope); |
| 912 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 913 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 914 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"DTW not created from Pitches."); |
| 915 | } |
| 916 | } |
| 917 | |
| 918 | autoDTWcxx . . $ autoDTW# Pitches_to_DTWcxx . . $ Pitches_to_DTW(ec88775ba582cd9c). (Pitchcxx . . $ Pitch# me, Pitchcxx . . $ Pitch# thee, double vuv_costs, double time_weight, bool matchStart, bool matchEnd, int slope) { // vuv_costs=24, time_weight=10 ? |
| 919 | try { |
| 920 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (vuv_costs >= 0.0, |
| 921 | U"Voiced-unvoiced costs should not be negative."); |
| 922 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (time_weight >= 0.0, |
| 923 | U"Time costs weight should not be negative."); |
| 924 | |
| 925 | autoDTWcxx . . $ autoDTW# him = DTW_createcxx . . $ DTW_create(266b4c6b39481820). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., thycxx . . $ `melder/melder.h:45:9`! xmincxx . . $ structFunction#xmin., thycxx . . $ `melder/melder.h:45:9`! xmaxcxx . . $ structFunction#xmax., thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx., thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx., thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1.); |
| 926 | autoVECcxx . . $ autoVEC# pitchx = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.); |
| 927 | kPitch_unitcxx . . $ kPitch_unit# unit = kPitch_unitcxx . . $ kPitch_unit#::SEMITONES_100cxx . . $ kPitch_unit#SEMITONES_100.; |
| 928 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) |
| 929 | pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] = Sampled_getValueAtSamplecxx . . $ Sampled_getValueAtSample(5092633e80007c54). (thee, j, Pitch_LEVEL_FREQUENCYcxx . . $ `fon/Pitch.h:85:9`!, (int) unit); |
| 930 | |
| 931 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; i ++) { |
| 932 | const double pitchy = Sampled_getValueAtSamplecxx . . $ Sampled_getValueAtSample(5092633e80007c54). (me, i, Pitch_LEVEL_FREQUENCYcxx . . $ `fon/Pitch.h:85:9`!, (int) unit); |
| 933 | const double t1 = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (i - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 934 | for (integercxx . . $ integer# j = 1; j <= thycxx . . $ `melder/melder.h:45:9`! nxcxx . . $ structSampled#nx.; j ++) { |
| 935 | const double t2 = thycxx . . $ `melder/melder.h:45:9`! x1cxx . . $ structSampled#x1. + (j - 1) * thycxx . . $ `melder/melder.h:45:9`! dxcxx . . $ structSampled#dx.; |
| 936 | const double dist_t = fabscxx . . $ fabs(fee4f1d22bc8e617). (t1 - t2); |
| 937 | double dist_f = 0; // based on pitch difference |
| 938 | if (isundefcxx . . $ isundef(f8197d536af80c96). (pitchy)) { |
| 939 | if (isdefinedcxx . . $ isdefined(f8197d536af80c96). (pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j])) |
| 940 | dist_f = vuv_costs; |
| 941 | } else if (isundefcxx . . $ isundef(f8197d536af80c96). (pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j])) { |
| 942 | dist_f = vuv_costs; |
| 943 | } else { |
| 944 | dist_f = fabscxx . . $ fabs(fee4f1d22bc8e617). (pitchy - pitchx [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j]); |
| 945 | } |
| 946 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = sqrtcxx . . $ sqrt(fee4f1d22bc8e617). (dist_f * dist_f + time_weight * dist_t * dist_t); |
| 947 | } |
| 948 | } |
| 949 | |
| 950 | DTW_findPathcxx . . $ DTW_findPath(7c4c07b8524d5375). (him.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), matchStart, matchEnd, slope); |
| 951 | return himcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 952 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 953 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"DTW not created from Pitches."); |
| 954 | } |
| 955 | } |
| 956 | |
| 957 | autoDurationTiercxx . . $ autoDurationTier# DTW_to_DurationTiercxx . . $ DTW_to_DurationTier(c4384e6c9200962d). (DTWcxx . . $ DTW# /* me */) { |
| 958 | return autoDurationTiercxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).(); |
| 959 | } |
| 960 | |
| 961 | void DTW_Matrix_replacecxx . . $ DTW_Matrix_replace(460a9e47324bd9e1). (DTWcxx . . $ DTW# me, Matrixcxx . . $ Matrix# thee) { |
| 962 | try { |
| 963 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! xmin == thycxx . . $ `melder/melder.h:45:9`! xmin && mycxx . . $ `melder/melder.h:44:9`! xmax == thycxx . . $ `melder/melder.h:45:9`! xmax && mycxx . . $ `melder/melder.h:44:9`! ymin == thycxx . . $ `melder/melder.h:45:9`! ymin && mycxx . . $ `melder/melder.h:44:9`! ymax == thycxx . . $ `melder/melder.h:45:9`! ymax, |
| 964 | U"The X and Y domains of the matrix and the DTW must be equal."); |
| 965 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! nx == thycxx . . $ `melder/melder.h:45:9`! nx && mycxx . . $ `melder/melder.h:44:9`! dx == thycxx . . $ `melder/melder.h:45:9`! dx && mycxx . . $ `melder/melder.h:44:9`! ny == thycxx . . $ `melder/melder.h:45:9`! ny && mycxx . . $ `melder/melder.h:44:9`! dy == thycxx . . $ `melder/melder.h:45:9`! dy, |
| 966 | U"The sampling of the matrix and the DTW should be equal."); |
| 967 | double minimum, maximum; |
| 968 | Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (me, 0, 0, 0, 0, & minimum, & maximum); |
| 969 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (minimum >= 0.0, |
| 970 | U"Distances should not be negative."); |
| 971 | mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).(); |
| 972 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 973 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": distances not replaced."); |
| 974 | } |
| 975 | } |
| 976 | |
| 977 | /****************** new implementation ********/ |
| 978 | |
| 979 | void DTW_findPathcxx . . $ DTW_findPath(7c4c07b8524d5375). (DTWcxx . . $ DTW# me, bool matchStart, bool matchEnd, int slope) { |
| 980 | DTW_findPath_specialcxx . . $ DTW_findPath_special(e5f77fcf08ecb8f7). (me, matchStart, matchEnd, slope, nullptr); |
| 981 | } |
| 982 | |
| 983 | autoMatrixcxx . . $ autoMatrix# DTW_to_Matrix_cumulativeDistancescxx . . $ DTW_to_Matrix_cumulativeDistances(2fdd3ebacda56566). (DTWcxx . . $ DTW# me, double sakoeChibaBand, int slope) { |
| 984 | try { |
| 985 | autoMatrixcxx . . $ autoMatrix# cumulativeDistancescxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 986 | DTW_findPath_bandAndSlopecxx . . $ DTW_findPath_bandAndSlope(c86b42c214827506). (me, sakoeChibaBand, slope, & cumulativeDistances); |
| 987 | return cumulativeDistancescxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 988 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 989 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cumulative costs matrix not created."); |
| 990 | } |
| 991 | } |
| 992 | |
| 993 | static void DTW_relaxConstraintscxx . . $ DTW_relaxConstraints(fad80edc8ff7600a). (DTWcxx . . $ DTW# me, double band, int /* slope */, double *relaxedBand, int *relaxedSlope) { |
| 994 | |
| 995 | //double dtw_slope = (my ymax - my ymin - band) / (my xmax - my xmin - band); |
| 996 | //dtw_slope = dtw_slope+1.0; // fake instruction to avoid compiler warning |
| 997 | *relaxedBand = 0.0; |
| 998 | *relaxedSlope = 1; |
| 999 | } |
| 1000 | |
| 1001 | static void DTW_checkSlopeConstraintscxx . . $ DTW_checkSlopeConstraints(fee1a9416624a494). (DTWcxx . . $ DTW# me, double band, int slope) { |
| 1002 | try { |
| 1003 | const double slopes [5] = { DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, 3.0, 2.0, 1.5 } ; |
| 1004 | double dtw_slope = (mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. - band) / (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. - band); |
| 1005 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (slope > 0 && slope < 5, |
| 1006 | U"Invalid slope constraint."); |
| 1007 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (! (dtw_slope == 0.0 && slope != 1), |
| 1008 | U"Band too wide."); |
| 1009 | |
| 1010 | if (dtw_slope < 1.0) |
| 1011 | dtw_slope = 1.0 / dtw_slope; |
| 1012 | |
| 1013 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (dtw_slope <= slopes [slope], |
| 1014 | U"There is a conflict between the chosen slope constraint and the relative duration. " |
| 1015 | U"The duration ratio of the longest and the shortest object is ", dtw_slope, |
| 1016 | U". This implies that the largest slope in the constraint must have a value greater than or equal to this ratio." |
| 1017 | ); |
| 1018 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1019 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"Slope constraints cannot be met."); |
| 1020 | } |
| 1021 | } |
| 1022 | |
| 1023 | static void DTW_Polygon_setUnreachablePartscxx . . $ DTW_Polygon_setUnreachableParts(96486ebe11fc87a6). (DTWcxx . . $ DTW# me, Polygoncxx . . $ Polygon# thee, INTMATcxx . . $ INTMAT# const& psi) { |
| 1024 | try { |
| 1025 | const double eps = mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / 100.0; // safe enough |
| 1026 | const double dtw_slope = (mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.) / (mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.); |
| 1027 | |
| 1028 | double xmin, xmax, ymin, ymax; |
| 1029 | Polygon_getExtremacxx . . $ Polygon_getExtrema(7bc564fe6c79180b). (thee, & xmin, & xmax, & ymin, & ymax); |
| 1030 | // if the Polygon and the DTW don't overlap everything is unreachable! |
| 1031 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (! (xmax <= mycxx . . $ `melder/melder.h:44:9`! xmin || xmin >= mycxx . . $ `melder/melder.h:44:9`! xmax || ymax <= mycxx . . $ `melder/melder.h:44:9`! ymin || ymin >= mycxx . . $ `melder/melder.h:44:9`! ymax), |
| 1032 | U"DTW and Polygon don't overlap."); |
| 1033 | |
| 1034 | // find border "above" polygon |
| 1035 | for (integercxx . . $ integer# ix = 1; ix <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ix ++) { |
| 1036 | const double x = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (ix - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 1037 | const integercxx . . $ integer# iystart = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (dtw_slope * ix * (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.)) + 1; |
| 1038 | for (integercxx . . $ integer# iy = iystart + 1; iy <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; iy ++) { |
| 1039 | const double y = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (iy - 1) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; |
| 1040 | if (Polygon_getLocationOfPointcxx . . $ Polygon_getLocationOfPoint(7c887ac351245d3b). (thee, x, y, eps) == Polygon_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.h:33:9`!) { |
| 1041 | for (integercxx . . $ integer# k = iy; k <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; k ++) |
| 1042 | psi [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] = DTW_UNREACHABLEcxx . . $ `dwtools/DTW.h:37:9`!; |
| 1043 | break; |
| 1044 | } |
| 1045 | } |
| 1046 | } |
| 1047 | // find border "below" polygon |
| 1048 | for (integercxx . . $ integer# ix = 2; ix <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; ix ++) { |
| 1049 | const double x = mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1. + (ix - 1) * mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx.; |
| 1050 | integercxx . . $ integer# iystart = Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (dtw_slope * ix * (mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx. / mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.)); // start 1 lower |
| 1051 | if (iystart > mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) |
| 1052 | iystart = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; |
| 1053 | for (integercxx . . $ integer# iy = iystart - 1; iy >= 1; iy --) { |
| 1054 | const double y = mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1. + (iy - 1) * mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy.; |
| 1055 | if (Polygon_getLocationOfPointcxx . . $ Polygon_getLocationOfPoint(7c887ac351245d3b). (thee, x, y, eps) == Polygon_OUTSIDEcxx . . $ `dwtools/Polygon_extensions.h:33:9`!) { |
| 1056 | for (integercxx . . $ integer# k = iy; k >= 1; k --) |
| 1057 | psi [cxx . . $ matrix#`operator[]`(2d545b3cb3f8e666).k] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] = DTW_UNREACHABLEcxx . . $ `dwtools/DTW.h:37:9`!; |
| 1058 | break; |
| 1059 | } |
| 1060 | } |
| 1061 | } |
| 1062 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1063 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" cannot set unreachable parts."); |
| 1064 | } |
| 1065 | } |
| 1066 | |
| 1067 | #define DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`!(y,x) ((psi [y] [x] != DTW_UNREACHABLEcxx . . $ `dwtools/DTW.h:37:9`!) && (psi [y] [x] != DTW_FORBIDDENcxx . . $ `dwtools/DTW.h:38:9`!)) |
| 1068 | static void DTW_findPath_specialcxx . . $ DTW_findPath_special(e5f77fcf08ecb8f7). (DTWcxx . . $ DTW# me, bool /* matchStart */, bool /* matchEnd */, int slope, autoMatrixcxx . . $ autoMatrix# *cumulativeDists) { |
| 1069 | try { |
| 1070 | autoPolygoncxx . . $ autoPolygon# thee = DTW_to_Polygoncxx . . $ DTW_to_Polygon(57d3a1deeef0f568). (me, 0.0, slope); |
| 1071 | DTW_Polygon_findPathInsidecxx . . $ DTW_Polygon_findPathInside(df18308236acd980). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), slope, cumulativeDists); |
| 1072 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1073 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot find path."); |
| 1074 | } |
| 1075 | } |
| 1076 | |
| 1077 | /* |
| 1078 | Intersection of two straight lines y = a [i]*x+b [i], where a [2] = 1 / a [1]. Point (x1,y1) is on first line, |
| 1079 | point (x2,y2) is on second line. |
| 1080 | */ |
| 1081 | static void getIntersectionPointcxx . . $ getIntersectionPoint(5d9ba02e38dab810). (double x1, double y1, double x2, double y2, double a, double *x3, double *y3) { |
| 1082 | *x3 = (y2 - y1 + a * x1 - x2 / a) / (a - 1.0 / a); |
| 1083 | *y3 = a * *x3 + y1 - a * x1; |
| 1084 | } |
| 1085 | |
| 1086 | autoPolygoncxx . . $ autoPolygon# DTW_to_Polygoncxx . . $ DTW_to_Polygon(57d3a1deeef0f568). (DTWcxx . . $ DTW# me, double band, int slope) { |
| 1087 | try { |
| 1088 | try { |
| 1089 | DTW_checkSlopeConstraintscxx . . $ DTW_checkSlopeConstraints(fee1a9416624a494). (me, band, slope); |
| 1090 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1091 | DTW_relaxConstraintscxx . . $ DTW_relaxConstraints(fad80edc8ff7600a). (me, band, slope, & band, & slope); |
| 1092 | Melder_flushErrorcxx . . $ Melder_flushError(49f6e7a06ebc5aa8). (); |
| 1093 | } |
| 1094 | |
| 1095 | double slopes [5] = { DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, 3.0, 2.0, 1.5 } ; |
| 1096 | if (band <= 0) { |
| 1097 | if (slope == 1) { |
| 1098 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (4); |
| 1099 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1100 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1101 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1102 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1103 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1104 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1105 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1106 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1107 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1108 | } else { |
| 1109 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (4); |
| 1110 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1111 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1112 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1113 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1114 | double x, y; |
| 1115 | getIntersectionPointcxx . . $ getIntersectionPoint(5d9ba02e38dab810). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., slopes [slope], & x, & y); |
| 1116 | if (x < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 1117 | x = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1118 | if (x > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 1119 | x = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1120 | if (y < mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.) |
| 1121 | y = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1122 | if (y > mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.) |
| 1123 | y = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1124 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = x; |
| 1125 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = y; |
| 1126 | getIntersectionPointcxx . . $ getIntersectionPoint(5d9ba02e38dab810). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., 1.0 / slopes [slope], & x, & y); |
| 1127 | if (x < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 1128 | x = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1129 | if (x > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 1130 | x = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1131 | if (y < mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.) |
| 1132 | y = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1133 | if (y > mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.) |
| 1134 | y = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1135 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = x; |
| 1136 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = y; |
| 1137 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1138 | } |
| 1139 | } else { |
| 1140 | if (slope == 1) { |
| 1141 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (6); |
| 1142 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1143 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1144 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1145 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. + band; |
| 1146 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - band; |
| 1147 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1148 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1149 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1150 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1151 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - band; |
| 1152 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + band; |
| 1153 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1154 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1155 | } else { |
| 1156 | autoPolygoncxx . . $ autoPolygon# thee = Polygon_createcxx . . $ Polygon_create(2216cf3dda2361cc). (8); |
| 1157 | double x, y; |
| 1158 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1159 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1160 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1161 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. + band; |
| 1162 | getIntersectionPointcxx . . $ getIntersectionPoint(5d9ba02e38dab810). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin. + band, mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - band, mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., slopes [slope], & x, & y); |
| 1163 | if (x < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 1164 | x = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1165 | if (x > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 1166 | x = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1167 | if (y < mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.) |
| 1168 | y = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1169 | if (y > mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.) |
| 1170 | y = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1171 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = x; |
| 1172 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = y; |
| 1173 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax. - band; |
| 1174 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).4] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1175 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1176 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).5]= mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1177 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6] = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1178 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).6] = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - band; |
| 1179 | getIntersectionPointcxx . . $ getIntersectionPoint(5d9ba02e38dab810). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + band, mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax. - band, 1.0 / slopes [slope], & x, & y); |
| 1180 | if (x < mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.) |
| 1181 | x = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin.; |
| 1182 | if (x > mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.) |
| 1183 | x = mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax.; |
| 1184 | if (y < mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.) |
| 1185 | y = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1186 | if (y > mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.) |
| 1187 | y = mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax.; |
| 1188 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).7] = x; |
| 1189 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).7] = y; |
| 1190 | thycxx . . $ `melder/melder.h:45:9`! xcxx . . $ structPolygon#x. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).8] = mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin. + band; |
| 1191 | thycxx . . $ `melder/melder.h:45:9`! ycxx . . $ structPolygon#y. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).8] = mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin.; |
| 1192 | return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1193 | } |
| 1194 | } |
| 1195 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1196 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" no Polygon created."); |
| 1197 | } |
| 1198 | } |
| 1199 | |
| 1200 | autoMatrixcxx . . $ autoMatrix# DTW_Polygon_to_Matrix_cumulativeDistancescxx . . $ DTW_Polygon_to_Matrix_cumulativeDistances(9b7d95787d770d89). (DTWcxx . . $ DTW# me, Polygoncxx . . $ Polygon# thee, int localSlope) { |
| 1201 | try { |
| 1202 | autoMatrixcxx . . $ autoMatrix# cumulativeDistancescxx . . $ autoSomeThing#autoSomeThing(49f6e7a06ebc5aa8).; |
| 1203 | DTW_Polygon_findPathInsidecxx . . $ DTW_Polygon_findPathInside(df18308236acd980). (me, thee, localSlope, & cumulativeDistances); |
| 1204 | return cumulativeDistancescxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 1205 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1206 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cumulative costs matrix not created from DTW and Polygon."); |
| 1207 | } |
| 1208 | } |
| 1209 | |
| 1210 | void DTW_findPath_bandAndSlopecxx . . $ DTW_findPath_bandAndSlope(c86b42c214827506). (DTWcxx . . $ DTW# me, double sakoeChibaBand, int localSlope, autoMatrixcxx . . $ autoMatrix# *cumulativeDists) { |
| 1211 | try { |
| 1212 | autoPolygoncxx . . $ autoPolygon# thee = DTW_to_Polygoncxx . . $ DTW_to_Polygon(57d3a1deeef0f568). (me, sakoeChibaBand, localSlope); |
| 1213 | DTW_Polygon_findPathInsidecxx . . $ DTW_Polygon_findPathInside(df18308236acd980). (me, thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), localSlope, cumulativeDists); |
| 1214 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1215 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U" cannot determine the path."); |
| 1216 | } |
| 1217 | } |
| 1218 | |
| 1219 | void DTW_Polygon_findPathInsidecxx . . $ DTW_Polygon_findPathInside(df18308236acd980). (DTWcxx . . $ DTW# me, Polygoncxx . . $ Polygon# thee, int localSlope, autoMatrixcxx . . $ autoMatrix# *cumulativeDists) { |
| 1220 | try { |
| 1221 | const double slopes [5] = { DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!, 3.0, 2.0, 1.5 }; |
| 1222 | // if localSlope == 1 start of path is within 10% of minimum duration. Starts farther away |
| 1223 | integercxx . . $ integer# delta_xy = stdcxx . . $ std/::mincxx . . $ std/min(2a338fce5842aa6a). (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.) / 10; // if localSlope == 1 start within 10% of |
| 1224 | |
| 1225 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (localSlope > 0 && localSlope < 5, |
| 1226 | U"Local slope parameter ", localSlope, U" not supported."); |
| 1227 | |
| 1228 | autoMATcxx . . $ autoMAT# delta = copy_MATcxx . . $ copy_MAT(a392b09ce3fc3972). (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z..getcxx . . $ automatrix#get(b2b81450b5bdda66).()); |
| 1229 | autoINTMATcxx . . $ autoINTMAT# psi = zero_INTMATcxx . . $ zero_INTMAT(4cdd710bd00a100c). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.); |
| 1230 | /* |
| 1231 | Start by making the outside unreachable. |
| 1232 | */ |
| 1233 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++) |
| 1234 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = DTW_UNREACHABLEcxx . . $ `dwtools/DTW.h:37:9`!; |
| 1235 | for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) |
| 1236 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = DTW_UNREACHABLEcxx . . $ `dwtools/DTW.h:37:9`!; |
| 1237 | |
| 1238 | /* |
| 1239 | Make begin part of first column reachable. |
| 1240 | */ |
| 1241 | const integercxx . . $ integer# rowto = ( localSlope != 1 ? Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (slopes [localSlope]) + 1 : delta_xy ); |
| 1242 | for (integercxx . . $ integer# iy = 2; iy <= rowto; iy ++) { |
| 1243 | if (localSlope != 1) { |
| 1244 | delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1]; |
| 1245 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1246 | } else { |
| 1247 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).1] = DTW_STARTcxx . . $ `dwtools/DTW.h:39:9`!; // will be adapted by DTW_Polygon_setUnreachableParts |
| 1248 | } |
| 1249 | } |
| 1250 | /* |
| 1251 | Make begin part of first row reachable. |
| 1252 | */ |
| 1253 | const integercxx . . $ integer# colto = ( localSlope != 1 ? Melder_ifloorcxx . . $ `melder/melder_ftoi.h:33:9`! (slopes [localSlope]) + 1 : delta_xy ); |
| 1254 | for (integercxx . . $ integer# ix = 2; ix <= colto; ix ++) { |
| 1255 | if (localSlope != 1) { |
| 1256 | delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix -1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix]; |
| 1257 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1258 | } else { |
| 1259 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] = DTW_STARTcxx . . $ `dwtools/DTW.h:39:9`!; // will be adapted by DTW_Polygon_setUnreachableParts |
| 1260 | } |
| 1261 | } |
| 1262 | |
| 1263 | /* |
| 1264 | Now we can set the unreachable parts from the Polygon. |
| 1265 | */ |
| 1266 | DTW_Polygon_setUnreachablePartscxx . . $ DTW_Polygon_setUnreachableParts(96486ebe11fc87a6). (me, thee, psi.getcxx . . $ automatrix#get(b2b81450b5bdda66).()); |
| 1267 | |
| 1268 | /* |
| 1269 | Forward pass. |
| 1270 | */ |
| 1271 | integercxx . . $ integer# numberOfIsolatedPoints = 0; |
| 1272 | autoMelderProgresscxx . . $ autoMelderProgress# progresscxx . . $ autoMelderProgress#autoMelderProgress(ff00d524ab0355ec). (U"DTW & Polygon: Find path..."); |
| 1273 | for (integercxx . . $ integer# j = 2; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++) { |
| 1274 | for (integercxx . . $ integer# i = 2; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) { |
| 1275 | if (! DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i, j)) |
| 1276 | continue; |
| 1277 | double g, gmin = DTW_BIGcxx . . $ `dwtools/DTW.cpp:66:9`!; |
| 1278 | integercxx . . $ integer# direction = 0; |
| 1279 | if (DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j - 1)) { |
| 1280 | gmin = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]; |
| 1281 | direction = DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`!; |
| 1282 | } else if (DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i, j - 1)) { |
| 1283 | gmin = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]; |
| 1284 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1285 | } else if (DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j)) { |
| 1286 | gmin = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]; |
| 1287 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1288 | } else { |
| 1289 | numberOfIsolatedPoints ++; |
| 1290 | continue; |
| 1291 | } |
| 1292 | |
| 1293 | switch (localSlope) { |
| 1294 | case 1: { // no restriction |
| 1295 | if (DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i, j - 1) && ((g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin)) { |
| 1296 | gmin = g; |
| 1297 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1298 | } |
| 1299 | if (DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j) && ((g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin)) { |
| 1300 | gmin = g; |
| 1301 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1302 | } |
| 1303 | } |
| 1304 | break; |
| 1305 | |
| 1306 | /* |
| 1307 | Sakoe & Chiba (1978) define the slope constraint measure as P = n / m, |
| 1308 | where n is the number of steps in the diagonal and |
| 1309 | m the number of steps in one of the other directions. |
| 1310 | |
| 1311 | P = 1/2 |
| 1312 | */ |
| 1313 | case 2: { // P = 1/2 |
| 1314 | if (j >= 4 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j - 3) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] == DTW_Xcxx . . $ `dwtools/DTW.h:41:9`! && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 2] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1315 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-3] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-2] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) { |
| 1316 | gmin = g; |
| 1317 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1318 | } |
| 1319 | if (j >= 3 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j - 2) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1320 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 2] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) { |
| 1321 | gmin = g; |
| 1322 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1323 | } |
| 1324 | if (i >= 3 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 2, j - 1) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1325 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) { |
| 1326 | gmin = g; |
| 1327 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1328 | } |
| 1329 | if (i >= 4 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 3, j - 1) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] == DTW_Ycxx . . $ `dwtools/DTW.h:42:9`! && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1330 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-1] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) { |
| 1331 | gmin = g; |
| 1332 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1333 | } |
| 1334 | } |
| 1335 | break; |
| 1336 | |
| 1337 | // P = 1 |
| 1338 | |
| 1339 | case 3: { |
| 1340 | if (j >= 3 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 1, j - 2) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1341 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 2] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) |
| 1342 | { |
| 1343 | gmin = g; |
| 1344 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1345 | } |
| 1346 | if (i >= 3 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 2, j - 1) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1347 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) |
| 1348 | { |
| 1349 | gmin = g; |
| 1350 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1351 | } |
| 1352 | } |
| 1353 | break; |
| 1354 | |
| 1355 | // P = 2 |
| 1356 | |
| 1357 | case 4: { |
| 1358 | if (i >= 3 && j >= 4 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 2, j - 3) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 2] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1359 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-3] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-2] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-1] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) |
| 1360 | { |
| 1361 | gmin = g; |
| 1362 | direction = DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!; |
| 1363 | } |
| 1364 | if (i >= 4 && j >= 3 && DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i - 3, j - 2) && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i - 2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j - 1] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`! && |
| 1365 | (g = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-3] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-2] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-2] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j-1] + 2.0 * mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i-1] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] + mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j]) < gmin) |
| 1366 | { |
| 1367 | gmin = g; |
| 1368 | direction = DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!; |
| 1369 | } |
| 1370 | } |
| 1371 | break; |
| 1372 | default: |
| 1373 | break; |
| 1374 | } |
| 1375 | Melder_assertcxx . . $ `melder/melder_assert.h:39:10`! (direction != 0); |
| 1376 | psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = direction; |
| 1377 | delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = gmin; |
| 1378 | } |
| 1379 | if (j % 10 == 2) |
| 1380 | Melder_progresscxx . . $ Melder_progress(3af686d0d3721642). (0.999 * j / mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., U"Calculate time warp: frame ", j, U" from ", mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., U"."); |
| 1381 | } |
| 1382 | |
| 1383 | /* |
| 1384 | Find minimum at end of path and trace back. |
| 1385 | */ |
| 1386 | integercxx . . $ integer# iy = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; |
| 1387 | double minimum = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.]; |
| 1388 | for (integercxx . . $ integer# i = mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - 1; i > 0; i --) { |
| 1389 | if (! DTW_ISREACHABLEcxx . . $ `dwtools/DTW.cpp:1067:9`! (i, mycxx . . $ `melder/melder.h:44:9`! nx)) { |
| 1390 | break; // we're in unreachable places |
| 1391 | } else if (delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.] < minimum) { |
| 1392 | minimum = delta [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy = i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.]; |
| 1393 | } |
| 1394 | } |
| 1395 | |
| 1396 | integercxx . . $ integer# pathIndex = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - 1; // maximum path length |
| 1397 | mycxx . . $ `melder/melder.h:44:9`! weightedDistancecxx . . $ structDTW#weightedDistance. = minimum / (mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.); |
| 1398 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).pathIndex]. ycxx . . $ structDTW_Path#y. = iy; |
| 1399 | integercxx . . $ integer# ix = mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).pathIndex]. xcxx . . $ structDTW_Path#x. = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; |
| 1400 | |
| 1401 | /* |
| 1402 | Fill path backwards. |
| 1403 | */ |
| 1404 | while (ix > 1) { |
| 1405 | if (psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] == DTW_XANDYcxx . . $ `dwtools/DTW.h:40:9`!) { |
| 1406 | ix --; |
| 1407 | iy --; |
| 1408 | } else if (psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] == DTW_Xcxx . . $ `dwtools/DTW.h:41:9`!) { |
| 1409 | ix --; |
| 1410 | } else if (psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] == DTW_Ycxx . . $ `dwtools/DTW.h:42:9`!) { |
| 1411 | iy --; |
| 1412 | } else if (psi [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).iy] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).ix] == DTW_STARTcxx . . $ `dwtools/DTW.h:39:9`!) { |
| 1413 | break; |
| 1414 | } |
| 1415 | if (pathIndex < 2 || iy < 1) |
| 1416 | break; |
| 1417 | //Melder_assert (pathIndex > 1 && iy > 0); |
| 1418 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).-- pathIndex]. xcxx . . $ structDTW_Path#x. = ix; |
| 1419 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).pathIndex]. ycxx . . $ structDTW_Path#y. = iy; |
| 1420 | } |
| 1421 | |
| 1422 | mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength. = mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx. + mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. - 1 - pathIndex + 1; |
| 1423 | if (pathIndex > 1) |
| 1424 | for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.; j ++) |
| 1425 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).j] =cxx . . $ structDTW_Path#`operator=`(79e7d195d0f1460b). mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path. [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).pathIndex ++]; |
| 1426 | mycxx . . $ `melder/melder.h:44:9`! pathcxx . . $ structDTW#path..resizecxx . . $ autovector#resize(d91e89fbd57cd1). (mycxx . . $ `melder/melder.h:44:9`! pathLengthcxx . . $ structDTW#pathLength.); // maintain invariant |
| 1427 | DTW_Path_recodecxx . . $ DTW_Path_recode(1effd30d7a74ffbf). (me); |
| 1428 | if (cumulativeDists) { |
| 1429 | autoMatrixcxx . . $ autoMatrix# him = Matrix_createcxx . . $ Matrix_create(494a3ae9ff7e3b60). (mycxx . . $ `melder/melder.h:44:9`! xmincxx . . $ structFunction#xmin., mycxx . . $ `melder/melder.h:44:9`! xmaxcxx . . $ structFunction#xmax., mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., mycxx . . $ `melder/melder.h:44:9`! dxcxx . . $ structSampled#dx., mycxx . . $ `melder/melder.h:44:9`! x1cxx . . $ structSampled#x1., |
| 1430 | mycxx . . $ `melder/melder.h:44:9`! ymincxx . . $ structSampledXY#ymin., mycxx . . $ `melder/melder.h:44:9`! ymaxcxx . . $ structSampledXY#ymax., mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., mycxx . . $ `melder/melder.h:44:9`! dycxx . . $ structSampledXY#dy., mycxx . . $ `melder/melder.h:44:9`! y1cxx . . $ structSampledXY#y1.); |
| 1431 | hiscxx . . $ `melder/melder.h:47:9`! zcxx . . $ structMatrix#z..allcxx . . $ automatrix#all(2114117ba8ed4224).() <<=cxx . . $ `operator<<=`(a7d93ba40fe22fe0). deltacxx . . $ constmatrixview#constmatrixview(c98a2930b9469e58)..allcxx . . $ automatrix#all(2114117ba8ed4224).(); |
| 1432 | *cumulativeDists =cxx . . $ autoSomeThing#`operator=`(80cc59814f7161e8). him.movecxx . . $ autoSomeThing#move(25acc3554b7d1642).(); |
| 1433 | } |
| 1434 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 1435 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": cannot find path."); |
| 1436 | } |
| 1437 | } |
| 1438 | |
| 1439 | /* End of file DTW.cpp */ |