comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoCalculationResult.java @ 8946:5d5d482da3e9

Implementing SINFO - FlowDepthMinMax calculation
author gernotbelger
date Tue, 13 Mar 2018 18:49:33 +0100
parents 82998242ba84
children a4f1ac81f26d
comparison
equal deleted inserted replaced
8945:4a6b6a3c279c 8946:5d5d482da3e9
11 11
12 import java.io.Serializable; 12 import java.io.Serializable;
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.Collection; 14 import java.util.Collection;
15 import java.util.Collections; 15 import java.util.Collections;
16 import java.util.List;
17 16
18 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKind;
19 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; 17 import org.dive4elements.river.artifacts.sinfo.util.WstInfo;
20
21 import gnu.trove.TDoubleArrayList;
22 18
23 /** 19 /**
24 * @author Gernot Belger 20 * @author Gernot Belger
25 */ 21 */
26 public abstract class AbstractSInfoCalculationResult<ROW extends AbstractSInfoResultRow> implements Serializable { 22 public abstract class AbstractSInfoCalculationResult<ROW extends AbstractSInfoResultRow> implements Serializable {
29 25
30 private final Collection<ROW> rows; 26 private final Collection<ROW> rows;
31 27
32 private final String label; 28 private final String label;
33 29
34 private final boolean hasTkh;
35
36 private final WstInfo wst; 30 private final WstInfo wst;
37 31
38 public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ROW> rows) { 32 public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final Collection<ROW> rows) {
39 this.label = label; 33 this.label = label;
40 this.wst = wst; 34 this.wst = wst;
41 this.hasTkh = hasTkh;
42 this.rows = new ArrayList<>(rows); 35 this.rows = new ArrayList<>(rows);
43 } 36 }
44 37
45 public final String getLabel() { 38 public final String getLabel() {
46 return this.label; 39 return this.label;
47 }
48
49 public final boolean hasTkh() {
50 return this.hasTkh;
51 } 40 }
52 41
53 public final WstInfo getWst() { 42 public final WstInfo getWst() {
54 return this.wst; 43 return this.wst;
55 } 44 }
59 } 48 }
60 49
61 public final Collection<ROW> getRows() { 50 public final Collection<ROW> getRows() {
62 return Collections.unmodifiableCollection(this.rows); 51 return Collections.unmodifiableCollection(this.rows);
63 } 52 }
64
65 public double[][] getFlowDepthPoints() {
66
67 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
68 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
69
70 for (final ROW row : this.rows) {
71 xPoints.add(row.getStation());
72 yPoints.add(row.getFlowDepth());
73 }
74
75 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
76 }
77
78 public double[][] getFlowDepthTkhPoints() {
79
80 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
81 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
82
83 for (final ROW row : this.rows) {
84 xPoints.add(row.getStation());
85 yPoints.add(row.getFlowDepthWithTkh());
86 }
87
88 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
89 }
90
91 public final double[][] getTkhUpPoints() {
92 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
93 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
94 final List<SoilKind> kinds = new ArrayList<>(this.rows.size());
95
96 for (final ROW row : this.rows) {
97 xPoints.add(row.getStation());
98 yPoints.add(row.getTkhUp());
99 kinds.add(row.getTkhKind());
100 }
101
102 return adjustTkhVisualization(xPoints, yPoints, kinds);
103 }
104
105 public final double[][] getTkhDownPoints() {
106 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
107 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
108 final List<SoilKind> kinds = new ArrayList<>(this.rows.size());
109
110 for (final ROW row : this.rows) {
111 xPoints.add(row.getStation());
112 yPoints.add(row.getTkhDown());
113 kinds.add(row.getTkhKind());
114 }
115
116 return adjustTkhVisualization(xPoints, yPoints, kinds);
117 }
118
119 public double[][] getVelocityPoints() {
120
121 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
122 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
123
124 for (final ROW row : this.rows) {
125 xPoints.add(row.getStation());
126 yPoints.add(row.getVelocity());
127 }
128
129 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
130 }
131
132 public double[][] getD50Points() {
133
134 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
135 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
136
137 for (final ROW row : this.rows) {
138 xPoints.add(row.getStation());
139 yPoints.add(row.getD50());
140 }
141
142 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
143 }
144
145 public double[][] getTauPoints() {
146
147 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
148 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
149
150 for (final ROW row : this.rows) {
151 xPoints.add(row.getStation());
152 yPoints.add(row.getTau());
153 }
154
155 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() };
156 }
157
158 /**
159 * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß
160 * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case
161 */
162 private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) {
163
164 final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size());
165 final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size());
166
167 adjustedX.add(xPoints.get(0));
168 adjustedY.add(yPoints.get(0));
169
170 for (int i = 1; i < xPoints.size(); i++) {
171
172 final SoilKind kind1 = kinds.get(i - 1);
173 final SoilKind kind2 = kinds.get(i);
174
175 if (kind1 != kind2) {
176 /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */
177 final double x1 = xPoints.get(i - 1);
178 final double y1 = yPoints.get(i - 1);
179 final double x2 = xPoints.get(i);
180 final double y2 = yPoints.get(i);
181
182 final double middleX = (x1 + x2) / 2;
183
184 // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly
185 adjustedX.add(middleX - 0.0001);
186 adjustedY.add(y1);
187
188 adjustedX.add(middleX + 0.0001);
189 adjustedY.add(y2);
190 }
191
192 /* always add the real point now */
193 adjustedX.add(xPoints.get(i));
194 adjustedY.add(yPoints.get(i));
195 }
196
197 return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() };
198 }
199 } 53 }

http://dive4elements.wald.intevation.org