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