8946
|
1 /** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde |
|
2 * Software engineering by |
|
3 * Björnsen Beratende Ingenieure GmbH |
|
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.common; |
|
11 |
|
12 import java.util.Collection; |
|
13 import java.util.List; |
|
14 |
9170
|
15 import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult; |
|
16 import org.dive4elements.river.artifacts.common.AbstractCalculationResults; |
9000
|
17 import org.dive4elements.river.artifacts.common.ResultRow; |
8946
|
18 import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKind; |
|
19 import org.dive4elements.river.artifacts.sinfo.util.WstInfo; |
|
20 |
|
21 import gnu.trove.TDoubleArrayList; |
|
22 |
|
23 /** |
|
24 * @author Gernot Belger |
|
25 */ |
9170
|
26 |
|
27 public abstract class AbstractTkhCalculationResult<RESULTS extends AbstractCalculationResults<?>> extends AbstractCalculationExportableResult<RESULTS> { |
8946
|
28 |
|
29 private static final long serialVersionUID = 1L; |
|
30 |
|
31 private final boolean hasTkh; |
9170
|
32 private final WstInfo wst; |
8946
|
33 |
9000
|
34 public AbstractTkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ResultRow> rows) { |
9170
|
35 super(label, rows); |
|
36 this.wst = wst; |
8946
|
37 this.hasTkh = hasTkh; |
|
38 } |
|
39 |
|
40 public final boolean hasTkh() { |
|
41 return this.hasTkh; |
|
42 } |
|
43 |
|
44 public final double[][] getTkhUpPoints() { |
|
45 |
8948
|
46 final double[][] points = getStationPoints(SInfoResultType.tkhup); |
|
47 final List<SoilKind> kinds = getValues(SInfoResultType.soilkind); |
8946
|
48 |
8948
|
49 final double[] xPoints = points[0]; |
|
50 final double[] yPoints = points[1]; |
8946
|
51 |
|
52 return adjustTkhVisualization(xPoints, yPoints, kinds); |
|
53 } |
|
54 |
|
55 public final double[][] getTkhDownPoints() { |
|
56 |
8948
|
57 final double[][] points = getStationPoints(SInfoResultType.tkhdown); |
|
58 final List<SoilKind> kinds = getValues(SInfoResultType.soilkind); |
8946
|
59 |
8948
|
60 final double[] xPoints = points[0]; |
|
61 final double[] yPoints = points[1]; |
8946
|
62 |
|
63 return adjustTkhVisualization(xPoints, yPoints, kinds); |
|
64 } |
|
65 |
|
66 /** |
|
67 * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß |
|
68 * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case |
|
69 */ |
8948
|
70 private double[][] adjustTkhVisualization(final double[] xPoints, final double[] yPoints, final List<SoilKind> kinds) { |
8946
|
71 |
8948
|
72 final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.length); |
|
73 final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.length); |
8946
|
74 |
8948
|
75 adjustedX.add(xPoints[0]); |
|
76 adjustedY.add(yPoints[0]); |
8946
|
77 |
8948
|
78 for (int i = 1; i < xPoints.length; i++) { |
8946
|
79 |
|
80 final SoilKind kind1 = kinds.get(i - 1); |
|
81 final SoilKind kind2 = kinds.get(i); |
|
82 |
|
83 if (kind1 != kind2) { |
|
84 /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */ |
8948
|
85 final double x1 = xPoints[i - 1]; |
|
86 final double y1 = yPoints[i - 1]; |
|
87 final double x2 = xPoints[i]; |
|
88 final double y2 = yPoints[i]; |
8946
|
89 |
|
90 final double middleX = (x1 + x2) / 2; |
|
91 |
|
92 // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly |
|
93 adjustedX.add(middleX - 0.0001); |
|
94 adjustedY.add(y1); |
|
95 |
|
96 adjustedX.add(middleX + 0.0001); |
|
97 adjustedY.add(y2); |
|
98 } |
|
99 |
|
100 /* always add the real point now */ |
8948
|
101 adjustedX.add(xPoints[i]); |
|
102 adjustedY.add(yPoints[i]); |
8946
|
103 } |
|
104 |
|
105 return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() }; |
|
106 } |
9170
|
107 |
|
108 public final WstInfo getWst() { |
|
109 return this.wst; // TODO: Meta-Data export hier hin |
|
110 } |
8946
|
111 } |