Debian Codegraph @

dwtools/PatternList.cpp

raw symbols SCIP
1 /* PatternList.cpp
2 *
3 * Copyright (C) 1993-2019 David Weenink
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 * along with this work. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19 /*
20 djmw 20020813 GPL header
21 djmw 20041203 Added _PatternList_checkElements.
22 djmw 20071017 Melder_error<p>
23 djmw 20110304 Thing_new
24 */
25
26 #include "PatternList.h"cxx . . $ `<file>/dwtools/PatternList.h`/
27
28 Thing_implementcxx . . $ `sys/Thing.h:65:9`! (PatternList, Matrix, 2);
29
30 bool _PatternList_checkElementscxx . . $ _PatternList_checkElements(b9281b447a2bfde7). (PatternListcxx . . $ PatternList# me) {
31 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) {
32 for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++)
33 if (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] < 0 || mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] > 1)
34 return false;
35 }
36 return true;
37 }
38
39 autoPatternListcxx . . $ autoPatternList# PatternList_createcxx . . $ PatternList_create(aadf1a410a0e0153). (integercxx . . $ integer# ny, integercxx . . $ integer# nx) {
40 try {
41 autoPatternListcxx . . $ autoPatternList# me = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PatternList);
42 Matrix_initcxx . . $ Matrix_init(9dd6c49f9830a091). (me.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).(), 1, nx, nx, 1, 1, 1, ny, ny, 1, 1);
43 return mecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
44 } catch (MelderErrorcxx . . $ MelderError#) {
45 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (U"PatternList not created.");
46 }
47 }
48
49 void PatternList_normalizecxx . . $ PatternList_normalize(ff69e583c72d238e). (PatternListcxx . . $ PatternList# me, int choice, double pmin, double pmax) {
50 if (pmin == pmax)
51 (void) Matrix_getWindowExtremacxx . . $ Matrix_getWindowExtrema(d50591dd897af896). (me, 1, mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx., 1, mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny., & pmin, & pmax);
52 if (pmin == pmax)
53 return;
54
55 if (choice == 1) {
56 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++)
57 for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++)
58 mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] = (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] - pmin) / (pmax - pmin);
59 } else { /* default choice */
60 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) {
61 double sum = 0;
62 for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++)
63 sum += (mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] -= pmin);
64 for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++)
65 mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j] *= 1.0 / sum;
66 }
67 }
68 }
69
70 void PatternList_drawcxx . . $ PatternList_draw(d59034c5cf38739f). (PatternListcxx . . $ PatternList# me, Graphicscxx . . $ Graphics# g, integercxx . . $ integer# pattern, double xmin, double xmax, double ymin, double ymax, bool garnish) {
71 Matrix_drawRowscxx . . $ Matrix_drawRows(13c691ba74eecb49). (me, g, xmin, xmax, pattern - 0.5, pattern + 0.5, ymin, ymax);
72 if (garnish) {
73 Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g);
74 Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false);
75 Graphics_marksLeftcxx . . $ Graphics_marksLeft(c3a11a8a55b243ff). (g, 2, true, true, false);
76 }
77 }
78
79 autoPatternListcxx . . $ autoPatternList# Matrix_to_PatternListcxx . . $ Matrix_to_PatternList(bd2df9bfaa9a0213). (Matrixcxx . . $ Matrix# me, integercxx . . $ integer# join) {
80 try {
81 if (join < 1) join = 1;
82 Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (mycxx . . $ `melder/melder.h:44:9`! ny % join == 0,
83 U"Number of rows should be a multiple of join factor.");
84 autoPatternListcxx . . $ autoPatternList# thee = PatternList_createcxx . . $ PatternList_create(aadf1a410a0e0153). (mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny. / join, join * mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.);
85
86 integercxx . . $ integer# r = 0, c = 1;
87 for (integercxx . . $ integer# i = 1; i <= mycxx . . $ `melder/melder.h:44:9`! nycxx . . $ structSampledXY#ny.; i ++) {
88 if ( (i - 1) % join == 0) {
89 r ++;
90 c = 1;
91 }
92 for (integercxx . . $ integer# j = 1; j <= mycxx . . $ `melder/melder.h:44:9`! nxcxx . . $ structSampled#nx.; j ++)
93 thycxx . . $ `melder/melder.h:45:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).r] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).c ++] = mycxx . . $ `melder/melder.h:44:9`! zcxx . . $ structMatrix#z. [cxx . . $ automatrix#`operator[]`(2d545b3cb3f8e666).i] [cxx . . $ vector#`operator[]`(8a4599b8835d1ce1).j];
94 }
95 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
96 } catch (MelderErrorcxx . . $ MelderError#) {
97 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to PatternList.");
98 }
99 }
100
101 autoMatrixcxx . . $ autoMatrix# PatternList_to_Matrixcxx . . $ PatternList_to_Matrix(c735e8ce7204ea9e). (PatternListcxx . . $ PatternList# me) {
102 try {
103 autoMatrixcxx . . $ autoMatrix# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (Matrix);
104 mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
105 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
106 } catch (MelderErrorcxx . . $ MelderError#) {
107 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to Matrix.");
108 }
109 }
110
111 autoPatternListcxx . . $ autoPatternList# ActivationList_to_PatternListcxx . . $ ActivationList_to_PatternList(cb1420ece586cd9a). (ActivationListcxx . . $ ActivationList# me) {
112 try {
113 autoPatternListcxx . . $ autoPatternList# thee = Thing_newcxx . . $ `sys/Thing.h:514:9`! (PatternList);
114 mycxx . . $ `melder/melder.h:44:9`! structMatrixcxx . . $ structMatrix# :: v1_copycxx . . $ structMatrix#v1_copy(42659c2335f2eda7). (thee.getcxx . . $ autoSomeThing#get(34d6acfd341ba7ab).());
115 return theecxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).;
116 } catch (MelderErrorcxx . . $ MelderError#) {
117 Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": not converted to PatternList.");
118 }
119 }
120
121 /* End of file PatternList.cpp */