Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.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 | a66f2a7c4f84 |
children | 82998242ba84 |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java Tue Feb 27 18:06:52 2018 +0100 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/flowdepth/FlowDepthCalculationResult.java Wed Feb 28 17:27:15 2018 +0100 @@ -9,12 +9,9 @@ */ package org.dive4elements.river.artifacts.sinfo.flowdepth; -import java.io.Serializable; -import java.util.ArrayList; import java.util.Collection; -import java.util.Collections; -import java.util.List; +import org.dive4elements.river.artifacts.sinfo.common.AbstractSInfoCalculationResult; import org.dive4elements.river.artifacts.sinfo.util.BedHeightInfo; import org.dive4elements.river.artifacts.sinfo.util.WstInfo; @@ -25,53 +22,31 @@ * * @author Gernot Belger */ -class FlowDepthCalculationResult implements Serializable { +final class FlowDepthCalculationResult extends AbstractSInfoCalculationResult<FlowDepthRow> { private static final long serialVersionUID = 1L; - private final Collection<FlowDepthRow> rows = new ArrayList<>(); - - private final String label; - private final BedHeightInfo sounding; - private final WstInfo wst; - - public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding) { - this.label = label; - this.wst = wst; - this.sounding = sounding; - } + public FlowDepthCalculationResult(final String label, final WstInfo wst, final BedHeightInfo sounding, final boolean hasTkh, + final Collection<FlowDepthRow> rows) { + super(label, wst, hasTkh, rows); - public void addRow(final double station, final double flowDepth, final double flowDepthWithTkh, final SoilKind tkhKind, final double tkh, - final double tkhUp, final double tkhDown, final double waterlevel, final double discharge, final String waterlevelLabel, final String gauge, - final double meanBedHeight, final String sondageLabel, final String location) { - this.rows.add(new FlowDepthRow(station, flowDepth, flowDepthWithTkh, tkhKind, tkh, tkhUp, tkhDown, waterlevel, discharge, waterlevelLabel, gauge, - meanBedHeight, sondageLabel, location)); - } - - public String getLabel() { - return this.label; - } - - public WstInfo getWst() { - return this.wst; + this.sounding = sounding; } public BedHeightInfo getSounding() { return this.sounding; } - public Collection<FlowDepthRow> getRows() { - return Collections.unmodifiableCollection(this.rows); - } - public double[][] getFlowDepthPoints() { - final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); + final Collection<FlowDepthRow> rows = getRows(); - for (final FlowDepthRow row : this.rows) { + final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); + final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); + + for (final FlowDepthRow row : rows) { xPoints.add(row.getStation()); yPoints.add(row.getFlowDepth()); } @@ -81,85 +56,16 @@ public double[][] getFlowDepthTkhPoints() { - final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); + final Collection<FlowDepthRow> rows = getRows(); - for (final FlowDepthRow row : this.rows) { + final TDoubleArrayList xPoints = new TDoubleArrayList(rows.size()); + final TDoubleArrayList yPoints = new TDoubleArrayList(rows.size()); + + for (final FlowDepthRow row : rows) { xPoints.add(row.getStation()); yPoints.add(row.getFlowDepthWithTkh()); } return new double[][] { xPoints.toNativeArray(), yPoints.toNativeArray() }; } - - public double[][] getTkhUpPoints() { - final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); - final List<SoilKind> kinds = new ArrayList<>(this.rows.size()); - - for (final FlowDepthRow row : this.rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getTkhUp()); - kinds.add(row.getTkhKind()); - } - - return adjustTkhVisualization(xPoints, yPoints, kinds); - } - - public double[][] getTkhDownPoints() { - final TDoubleArrayList xPoints = new TDoubleArrayList(this.rows.size()); - final TDoubleArrayList yPoints = new TDoubleArrayList(this.rows.size()); - final List<SoilKind> kinds = new ArrayList<>(this.rows.size()); - - for (final FlowDepthRow row : this.rows) { - xPoints.add(row.getStation()); - yPoints.add(row.getTkhDown()); - kinds.add(row.getTkhKind()); - } - - return adjustTkhVisualization(xPoints, yPoints, kinds); - } - - /** - * the up and down points must be further adjusted for visualization, see Mail Hr. Reiß - * basically we need to introduce extra points when the kind changes, so we get vertical lines in that case - */ - private double[][] adjustTkhVisualization(final TDoubleArrayList xPoints, final TDoubleArrayList yPoints, final List<SoilKind> kinds) { - - final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.size()); - final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.size()); - - adjustedX.add(xPoints.get(0)); - adjustedY.add(yPoints.get(0)); - - for (int i = 1; i < xPoints.size(); i++) { - - final SoilKind kind1 = kinds.get(i - 1); - final SoilKind kind2 = kinds.get(i); - - if (kind1 != kind2) { - /* introduce two extra points in order to create a vertical line in the middle of the two adjacent points */ - final double x1 = xPoints.get(i - 1); - final double y1 = yPoints.get(i - 1); - final double x2 = xPoints.get(i); - final double y2 = yPoints.get(i); - - final double middleX = (x1 + x2) / 2; - - // REMARK: we can't produce a 100% vertical line, as the area-renderer will not work correctly - adjustedX.add(middleX - 0.0001); - adjustedY.add(y1); - - adjustedX.add(middleX + 0.0001); - adjustedY.add(y2); - } - - /* always add the real point now */ - adjustedX.add(xPoints.get(i)); - adjustedY.add(yPoints.get(i)); - } - - - return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() }; - } } \ No newline at end of file