8854
|
1 /* Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
8877
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
8854
|
4 * Dr. Schumacher Ingenieurbüro für Wasser und Umwelt |
|
5 * |
|
6 * This file is Free Software under the GNU AGPL (>=v3) |
|
7 * and comes with ABSOLUTELY NO WARRANTY! Check out the |
|
8 * documentation coming with Dive4Elements River for details. |
|
9 */ |
|
10 package org.dive4elements.river.artifacts.sinfo.flowdepth; |
|
11 |
|
12 import java.io.Serializable; |
|
13 import java.util.ArrayList; |
|
14 import java.util.Collection; |
|
15 import java.util.Collections; |
8886
|
16 import java.util.List; |
8854
|
17 |
8894
|
18 import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; |
|
19 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
|
20 |
8854
|
21 import gnu.trove.TDoubleArrayList; |
|
22 |
|
23 /** |
|
24 * Contains the results of a {@link FlowDepthCalculation}. |
|
25 * |
|
26 * @author Gernot Belger |
|
27 */ |
8886
|
28 class FlowDepthCalculationResult implements Serializable { |
8854
|
29 |
8877
|
30 private static final long serialVersionUID = 1L; |
8854
|
31 |
8877
|
32 private final Collection<FlowDepthRow> rows = new ArrayList<>(); |
8854
|
33 |
8877
|
34 private final String label; |
|
35 |
|
36 private final BedHeightInfo sounding; |
|
37 |
|
38 private final WstInfo wst; |
|
39 |
|
40 public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding) { |
|
41 this.label = label; |
|
42 this.wst = wst; |
|
43 this.sounding = sounding; |
|
44 } |
|
45 |
8886
|
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)); |
8877
|
51 } |
|
52 |
|
53 public String getLabel() { |
|
54 return this.label; |
|
55 } |
|
56 |
|
57 public WstInfo getWst() { |
|
58 return this.wst; |
|
59 } |
|
60 |
|
61 public BedHeightInfo getSounding() { |
|
62 return this.sounding; |
|
63 } |
|
64 |
|
65 public Collection<FlowDepthRow> getRows() { |
8886
|
66 return Collections.unmodifiableCollection(this.rows); |
8877
|
67 } |
|
68 |
8854
|
69 public double[][] getFlowDepthPoints() { |
|
70 |
8877
|
71 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); |
|
72 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); |
|
73 |
|
74 for (final FlowDepthRow row : this.rows) { |
|
75 xPoints.add(row.getStation()); |
|
76 yPoints.add(row.getFlowDepth()); |
|
77 } |
|
78 |
8854
|
79 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
|
80 } |
8884
|
81 |
|
82 public double[][] getFlowDepthTkhPoints() { |
|
83 |
|
84 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); |
|
85 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); |
|
86 |
|
87 for (final FlowDepthRow row : this.rows) { |
|
88 xPoints.add(row.getStation()); |
|
89 yPoints.add(row.getFlowDepthWithTkh()); |
|
90 } |
|
91 |
|
92 return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; |
|
93 } |
|
94 |
8886
|
95 public double[][] getTkhUpPoints() { |
8884
|
96 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); |
|
97 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); |
8886
|
98 final List<SoilKind> kinds = new ArrayList<>(this.rows.size()); |
8884
|
99 |
|
100 for (final FlowDepthRow row : this.rows) { |
|
101 xPoints.add(row.getStation()); |
8886
|
102 yPoints.add(row.getTkhUp()); |
|
103 kinds.add(row.getTkhKind()); |
8884
|
104 } |
|
105 |
8886
|
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() }; |
8884
|
164 } |
8854
|
165 } |