comparison artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractSInfoCalculationResult.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
children 82998242ba84
comparison
equal deleted inserted replaced
8914:e3519c3e7a0a 8915:d9dbf0b74bc2
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.io.Serializable;
13 import java.util.ArrayList;
14 import java.util.Collection;
15 import java.util.Collections;
16 import java.util.List;
17
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 */
26 public abstract class AbstractSInfoCalculationResult<ROW extends AbstractSInfoResultRow> implements Serializable {
27
28 private static final long serialVersionUID = 1L;
29
30 private final Collection<ROW> rows;
31
32 private final String label;
33
34 private final boolean hasTkh;
35
36 private final WstInfo wst;
37
38 public AbstractSInfoCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ROW> rows) {
39 this.label = label;
40 this.wst = wst;
41 this.hasTkh = hasTkh;
42 this.rows = new ArrayList<>(rows);
43 }
44
45 public final String getLabel() {
46 return this.label;
47 }
48
49 public final boolean hasTkh() {
50 return this.hasTkh;
51 }
52
53 public final WstInfo getWst() {
54 return this.wst;
55 }
56
57 public final void addRow(final ROW resultRow) {
58 this.rows.add(resultRow);
59 }
60
61 public final Collection<ROW> getRows() {
62 return Collections.unmodifiableCollection(this.rows);
63 }
64
65 public final double[][] getTkhUpPoints() {
66 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
67 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
68 final List<SoilKind> kinds = new ArrayList<>(this.rows.size());
69
70 for (final ROW row : this.rows) {
71 xPoints.add(row.getStation());
72 yPoints.add(row.getTkhUp());
73 kinds.add(row.getTkhKind());
74 }
75
76 return adjustTkhVisualization(xPoints, yPoints, kinds);
77 }
78
79 public final double[][] getTkhDownPoints() {
80 final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size());
81 final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size());
82 final List<SoilKind> kinds = new ArrayList<>(this.rows.size());
83
84 for (final ROW row : this.rows) {
85 xPoints.add(row.getStation());
86 yPoints.add(row.getTkhDown());
87 kinds.add(row.getTkhKind());
88 }
89
90 return adjustTkhVisualization(xPoints, yPoints, kinds);
91 }
92
93 /**
94 * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß
95 * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case
96 */
97 private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) {
98
99 final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size());
100 final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size());
101
102 adjustedX.add(xPoints.get(0));
103 adjustedY.add(yPoints.get(0));
104
105 for (int i = 1; i < xPoints.size(); i++) {
106
107 final SoilKind kind1 = kinds.get(i - 1);
108 final SoilKind kind2 = kinds.get(i);
109
110 if (kind1 != kind2) {
111 /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */
112 final double x1 = xPoints.get(i - 1);
113 final double y1 = yPoints.get(i - 1);
114 final double x2 = xPoints.get(i);
115 final double y2 = yPoints.get(i);
116
117 final double middleX = (x1 + x2) / 2;
118
119 // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly
120 adjustedX.add(middleX - 0.0001);
121 adjustedY.add(y1);
122
123 adjustedX.add(middleX + 0.0001);
124 adjustedY.add(y2);
125 }
126
127 /* always add the real point now */
128 adjustedX.add(xPoints.get(i));
129 adjustedY.add(yPoints.get(i));
130 }
131
132 return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() };
133 }
134 }

http://dive4elements.wald.intevation.org