| 1 | /* CubeGrid.cpp |
| 2 | * |
| 3 | * Copyright (C) 2023 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. |
| 13 | * See the GNU 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 | #include "CubeGrid.h"cxx . . $ `<file>/gram/CubeGrid.h`/ |
| 20 | #include "Graphics.h"cxx . . $ `<file>/sys/Graphics.h`/ |
| 21 | |
| 22 | #include "oo_DESTROY.h"cxx . . $ `<file>/sys/oo_DESTROY.h`/ |
| 23 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 24 | #include "oo_COPY.h"cxx . . $ `<file>/sys/oo_COPY.h`/ |
| 25 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 26 | #include "oo_EQUAL.h"cxx . . $ `<file>/sys/oo_EQUAL.h`/ |
| 27 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 28 | #include "oo_CAN_WRITE_AS_ENCODING.h"cxx . . $ `<file>/sys/oo_CAN_WRITE_AS_ENCODING.h`/ |
| 29 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 30 | #include "oo_WRITE_TEXT.h"cxx . . $ `<file>/sys/oo_WRITE_TEXT.h`/ |
| 31 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 32 | #include "oo_READ_TEXT.h"cxx . . $ `<file>/sys/oo_READ_TEXT.h`/ |
| 33 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 34 | #include "oo_WRITE_BINARY.h"cxx . . $ `<file>/sys/oo_WRITE_BINARY.h`/ |
| 35 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 36 | #include "oo_READ_BINARY.h"cxx . . $ `<file>/sys/oo_READ_BINARY.h`/ |
| 37 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 38 | #include "oo_DESCRIPTION.h"cxx . . $ `<file>/sys/oo_DESCRIPTION.h`/ |
| 39 | #include "CubeGrid_def.h"cxx . . $ `<file>/gram/CubeGrid_def.h`/ |
| 40 | |
| 41 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (CubePoint, Function, 0); |
| 42 | |
| 43 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (CubeTier, Function, 0); |
| 44 | |
| 45 | Thing_implementcxx . . $ `sys/Thing.h:65:9`! (CubeGrid, Function, 0); |
| 46 | |
| 47 | autoCubePoint CubeGrid_averagecxx . . $ CubeGrid_average(f42ff99261c680e). (CubeGrid me, integercxx . . $ integer# tierNumber, double tmin, double tmax) { |
| 48 | try { |
| 49 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tierNumber >= 1, U"Tier number should be positive"); |
| 50 | Melder_requirecxx . . $ `melder/melder_require.h:21:9`! (tierNumber <= mycxx . . $ `melder/melder.h:44:9`! tiers.size, |
| 51 | U"Tier number (", tierNumber, U") should not be higher than the number of tiers (", mycxx . . $ `melder/melder.h:44:9`! tiers.size, U")."); |
| 52 | CubeTier tier = mycxx . . $ `melder/melder.h:44:9`! tiers.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).tierNumber]; |
| 53 | autoCubePoint you = Thing_newcxx . . $ `sys/Thing.h:514:9`! (CubePoint); |
| 54 | yourcxx . . $ `melder/melder.h:46:9`! red = 0.0; |
| 55 | yourcxx . . $ `melder/melder.h:46:9`! green = 0.0; |
| 56 | yourcxx . . $ `melder/melder.h:46:9`! blue = 0.0; |
| 57 | double numberOfSeconds = 0.0; |
| 58 | for (integercxx . . $ integer# ipoint = 1; ipoint <= tier -> points.sizecxx . . $ CollectionOf#size.; ipoint ++) { |
| 59 | CubePoint inpoint = tier -> points.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint]; |
| 60 | if (inpoint -> xmaxcxx . . $ structFunction#xmax. > tmin && inpoint -> xmincxx . . $ structFunction#xmin. < tmax) { |
| 61 | const double duration = inpoint -> xmaxcxx . . $ structFunction#xmax. - inpoint -> xmincxx . . $ structFunction#xmin.; |
| 62 | yourcxx . . $ `melder/melder.h:46:9`! red += inpoint -> red * duration; |
| 63 | yourcxx . . $ `melder/melder.h:46:9`! green += inpoint -> green * duration; |
| 64 | yourcxx . . $ `melder/melder.h:46:9`! blue += inpoint -> blue * duration; |
| 65 | numberOfSeconds += duration; |
| 66 | } |
| 67 | } |
| 68 | if (numberOfSeconds == 0.0) { |
| 69 | yourcxx . . $ `melder/melder.h:46:9`! red = undefinedcxx . . $ undefined.; |
| 70 | yourcxx . . $ `melder/melder.h:46:9`! green = undefinedcxx . . $ undefined.; |
| 71 | yourcxx . . $ `melder/melder.h:46:9`! blue = undefinedcxx . . $ undefined.; |
| 72 | } else { |
| 73 | yourcxx . . $ `melder/melder.h:46:9`! red /= numberOfSeconds; |
| 74 | yourcxx . . $ `melder/melder.h:46:9`! green /= numberOfSeconds; |
| 75 | yourcxx . . $ `melder/melder.h:46:9`! blue /= numberOfSeconds; |
| 76 | } |
| 77 | return youcxx . . $ autoSomeThing#autoSomeThing(b79141a71f7bc86f).; |
| 78 | } catch (MelderErrorcxx . . $ MelderError#) { |
| 79 | Melder_throwcxx . . $ `melder/melder_error.h:77:9`! (me, U": average not computed."); |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | autoVECcxx . . $ autoVEC# CubeGrid_getAveragescxx . . $ CubeGrid_getAverages(adf2cb2d84513c0b). (CubeGrid me, integercxx . . $ integer# tierNumber, double tmin, double tmax) { |
| 84 | autoCubePoint point = CubeGrid_averagecxx . . $ CubeGrid_average(f42ff99261c680e). (me, tierNumber, tmin, tmax); |
| 85 | autoVECcxx . . $ autoVEC# result = raw_VECcxx . . $ raw_VEC(e4395f764b859b1e). (3); |
| 86 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).1] = point ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). red; |
| 87 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).2] = point ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). green; |
| 88 | result [cxx . . $ autovector#`operator[]`(8a4599b8835d1ce1).3] = point ->cxx . . $ autoSomeThing#`operator->`(34d6acfd341ba7ab). blue; |
| 89 | return resultcxx . . $ autovector#autovector(d33c649a3aceae2f).; |
| 90 | } |
| 91 | |
| 92 | void CubeGrid_paintInsidecxx . . $ CubeGrid_paintInside(3e7cd0611f387639). (CubeGrid me, Graphicscxx . . $ Graphics# graphics, double tmin, double tmax) { |
| 93 | Function_unidirectionalAutowindowcxx . . $ Function_unidirectionalAutowindow(88b7840c59a57eaf). (me, & tmin, & tmax); |
| 94 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (graphics, Melder_WHITEcxx . . $ Melder_WHITE.); |
| 95 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (graphics, 0.0, 1.0, 0.0, 1.0); |
| 96 | Graphics_fillRectanglecxx . . $ Graphics_fillRectangle(72bdb7937dbb13da). (graphics, 0.0, 1.0, 0.0, 1.0); |
| 97 | Graphics_setWindowcxx . . $ Graphics_setWindow(72bdb7937dbb13da). (graphics, tmin, tmax, 0.0, mycxx . . $ `melder/melder.h:44:9`! tiers.sizecxx . . $ CollectionOf#size.); |
| 98 | for (integercxx . . $ integer# itier = 1; itier <= mycxx . . $ `melder/melder.h:44:9`! tiers.sizecxx . . $ CollectionOf#size.; itier ++) { |
| 99 | CubeTier tier = mycxx . . $ `melder/melder.h:44:9`! tiers.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).itier]; |
| 100 | const double ymin = mycxx . . $ `melder/melder.h:44:9`! tiers.sizecxx . . $ CollectionOf#size. - itier, ymax = ymin + 1.0; |
| 101 | for (integercxx . . $ integer# ipoint = 1; ipoint <= tier -> points.sizecxx . . $ CollectionOf#size.; ipoint ++) { |
| 102 | CubePoint point = tier -> points.atcxx . . $ CollectionOf#at. [cxx . . $ ArrayOf#`operator[]`(a7f36fee1ae21897).ipoint]; |
| 103 | if (point -> xmaxcxx . . $ structFunction#xmax. > tmin && point -> xmincxx . . $ structFunction#xmin. < tmax) { |
| 104 | const double xmin = Melder_clippedLeftcxx . . $ Melder_clippedLeft(f80f7d6260b3ee3a). (tmin, point -> xmincxx . . $ structFunction#xmin.); |
| 105 | const double xmax = Melder_clippedRightcxx . . $ Melder_clippedRight(f80f7d6260b3ee3a). (point -> xmaxcxx . . $ structFunction#xmax., tmax); |
| 106 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (graphics, MelderColourcxx . . $ MelderColour#MelderColour(98dd472ac7e5c3d4). (point -> red, point -> green, point -> blue)); |
| 107 | Graphics_fillRectanglecxx . . $ Graphics_fillRectangle(72bdb7937dbb13da). (graphics, xmin, xmax, ymin, ymax); |
| 108 | } |
| 109 | } |
| 110 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (graphics, Melder_BLACKcxx . . $ Melder_BLACK.); |
| 111 | if (itier > 1) { |
| 112 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (graphics, 1.0); |
| 113 | Graphics_linecxx . . $ Graphics_line(72bdb7937dbb13da). (graphics, tmin, ymax, tmax, ymax); |
| 114 | } |
| 115 | } |
| 116 | Graphics_setLineWidthcxx . . $ Graphics_setLineWidth(2514a1c07b6be5e2). (graphics, 1.0); |
| 117 | Graphics_setColourcxx . . $ Graphics_setColour(eb47b9513d3f4721). (graphics, Melder_BLACKcxx . . $ Melder_BLACK.); |
| 118 | } |
| 119 | |
| 120 | void CubeGrid_paintcxx . . $ CubeGrid_paint(50679656f0477d). (CubeGrid me, Graphicscxx . . $ Graphics# g, double tmin, double tmax, bool garnish) { |
| 121 | Graphics_setInnercxx . . $ Graphics_setInner(2d838ed765120c5d). (g); |
| 122 | CubeGrid_paintInsidecxx . . $ CubeGrid_paintInside(3e7cd0611f387639). (me, g, tmin, tmax); |
| 123 | Graphics_unsetInnercxx . . $ Graphics_unsetInner(2d838ed765120c5d). (g); |
| 124 | if (garnish) { |
| 125 | Graphics_drawInnerBoxcxx . . $ Graphics_drawInnerBox(2d838ed765120c5d). (g); |
| 126 | Graphics_textBottomcxx . . $ Graphics_textBottom(48cf1f690ec61203). (g, true, U"Time (s)"); |
| 127 | Graphics_marksBottomcxx . . $ Graphics_marksBottom(c3a11a8a55b243ff). (g, 2, true, true, false); |
| 128 | } |
| 129 | } |
| 130 | |
| 131 | /* End of file CubeGrid.cpp */ |
| 132 |