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