comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java @ 8948:a4f1ac81f26d

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

http://dive4elements.wald.intevation.org