Mercurial > dive4elements > river
comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java @ 8915:d9dbf0b74bc2
Refaktoring of flow depth calculation, extracting tkh part. First implementation of tkh calculation.
author | gernotbelger |
---|---|
date | Wed, 28 Feb 2018 17:27:15 +0100 |
parents | a66f2a7c4f84 |
children | 82998242ba84 |
comparison
equal
deleted
inserted
replaced
8914:e3519c3e7a0a | 8915:d9dbf0b74bc2 |
---|---|
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.flowdepth; | 10 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
11 | 11 |
12 import java.io.Serializable; | |
13 import java.util.ArrayList; | |
14 import java.util.Collection; | 12 import java.util.Collection; |
15 import java.util.Collections; | |
16 import java.util.List; | |
17 | 13 |
14 import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResult; | |
18 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; | 15 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; |
19 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; | 16 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
20 | 17 |
21 import gnu.trove.TDoubleArrayList; | 18 import gnu.trove.TDoubleArrayList; |
22 | 19 |
23 /** | 20 /** |
24 * Contains the results of a {@link FlowDepthCalculation}. | 21 * Contains the results of a {@link FlowDepthCalculation}. |
25 * | 22 * |
26 * @author Gernot Belger | 23 * @author Gernot Belger |
27 */ | 24 */ |
28 class FlowDepthCalculationResult implements Serializable { | 25 final class FlowDepthCalculationResult extends AbstractSInfoCalculationResult<FlowDepthRow> { |
29 | 26 |
30 private static final long serialVersionUID = 1L; | 27 private static final long serialVersionUID = 1L; |
31 | 28 |
32 private final Collection<FlowDepthRow> rows = new ArrayList<>(); | |
33 | |
34 private final String label; | |
35 | |
36 private final BedHeightInfo sounding; | 29 private final BedHeightInfo sounding; |
37 | 30 |
38 private final WstInfo wst; | 31 public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final boolean hasTkh, |
32 final Collection<FlowDepthRow> rows) { | |
33 super(label, wst, hasTkh, rows); | |
39 | 34 |
40 public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding) { | |
41 this.label = label; | |
42 this.wst = wst; | |
43 this.sounding = sounding; | 35 this.sounding = sounding; |
44 } | |
45 | |
46 public void addRow(final double station, final double flowDepth, final double flowDepthWithTkh, final SoilKind tkhKind, final double tkh, | |
47 final double tkhUp, final double tkhDown, final double waterlevel, final double discharge, final String waterlevelLabel, final String gauge, | |
48 final double meanBedHeight, final String sondageLabel, final String location) { | |
49 this.rows.add(new FlowDepthRow(station, flowDepth, flowDepthWithTkh, tkhKind, tkh, tkhUp, tkhDown, waterlevel, discharge, waterlevelLabel, gauge, | |
50 meanBedHeight, sondageLabel, location)); | |
51 } | |
52 | |
53 public String getLabel() { | |
54 return this.label; | |
55 } | |
56 | |
57 public WstInfo getWst() { | |
58 return this.wst; | |
59 } | 36 } |
60 | 37 |
61 public BedHeightInfo getSounding() { | 38 public BedHeightInfo getSounding() { |
62 return this.sounding; | 39 return this.sounding; |
63 } | 40 } |
64 | 41 |
65 public Collection<FlowDepthRow> getRows() { | |
66 return Collections.unmodifiableCollection(this.rows); | |
67 } | |
68 | |
69 public double[][] getFlowDepthPoints() { | 42 public double[][] getFlowDepthPoints() { |
70 | 43 |
71 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | 44 final Collection<FlowDepthRow> rows = getRows(); |
72 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
73 | 45 |
74 for (final FlowDepthRow row : this.rows) { | 46 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); |
47 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); | |
48 | |
49 for (final FlowDepthRow row : rows) { | |
75 xPoints.add(row.getStation()); | 50 xPoints.add(row.getStation()); |
76 yPoints.add(row.getFlowDepth()); | 51 yPoints.add(row.getFlowDepth()); |
77 } | 52 } |
78 | 53 |
79 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | 54 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
80 } | 55 } |
81 | 56 |
82 public double[][] getFlowDepthTkhPoints() { | 57 public double[][] getFlowDepthTkhPoints() { |
83 | 58 |
84 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | 59 final Collection<FlowDepthRow> rows = getRows(); |
85 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
86 | 60 |
87 for (final FlowDepthRow row : this.rows) { | 61 final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); |
62 final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); | |
63 | |
64 for (final FlowDepthRow row : rows) { | |
88 xPoints.add(row.getStation()); | 65 xPoints.add(row.getStation()); |
89 yPoints.add(row.getFlowDepthWithTkh()); | 66 yPoints.add(row.getFlowDepthWithTkh()); |
90 } | 67 } |
91 | 68 |
92 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; | 69 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
93 } | 70 } |
94 | |
95 public double[][] getTkhUpPoints() { | |
96 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
97 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
98 final List<SoilKind> kinds = new ArrayList<>(this.rows.size()); | |
99 | |
100 for (final FlowDepthRow row : this.rows) { | |
101 xPoints.add(row.getStation()); | |
102 yPoints.add(row.getTkhUp()); | |
103 kinds.add(row.getTkhKind()); | |
104 } | |
105 | |
106 return adjustTkhVisualization(xPoints, yPoints, kinds); | |
107 } | |
108 | |
109 public double[][] getTkhDownPoints() { | |
110 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); | |
111 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); | |
112 final List<SoilKind> kinds = new ArrayList<>(this.rows.size()); | |
113 | |
114 for (final FlowDepthRow row : this.rows) { | |
115 xPoints.add(row.getStation()); | |
116 yPoints.add(row.getTkhDown()); | |
117 kinds.add(row.getTkhKind()); | |
118 } | |
119 | |
120 return adjustTkhVisualization(xPoints, yPoints, kinds); | |
121 } | |
122 | |
123 /** | |
124 * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß | |
125 * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case | |
126 */ | |
127 private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) { | |
128 | |
129 final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size()); | |
130 final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size()); | |
131 | |
132 adjustedX.add(xPoints.get(0)); | |
133 adjustedY.add(yPoints.get(0)); | |
134 | |
135 for (int i = 1; i < xPoints.size(); i++) { | |
136 | |
137 final SoilKind kind1 = kinds.get(i - 1); | |
138 final SoilKind kind2 = kinds.get(i); | |
139 | |
140 if (kind1 != kind2) { | |
141 /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */ | |
142 final double x1 = xPoints.get(i - 1); | |
143 final double y1 = yPoints.get(i - 1); | |
144 final double x2 = xPoints.get(i); | |
145 final double y2 = yPoints.get(i); | |
146 | |
147 final double middleX = (x1 + x2) / 2; | |
148 | |
149 // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly | |
150 adjustedX.add(middleX - 0.0001); | |
151 adjustedY.add(y1); | |
152 | |
153 adjustedX.add(middleX + 0.0001); | |
154 adjustedY.add(y2); | |
155 } | |
156 | |
157 /* always add the real point now */ | |
158 adjustedX.add(xPoints.get(i)); | |
159 adjustedY.add(yPoints.get(i)); | |
160 } | |
161 | |
162 | |
163 return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() }; | |
164 } | |
165 } | 71 } |