view artifacts/src/main/java/org/dive4elements/river/artifacts/sinfo/common/AbstractTkhCalculationResult.java @ 9585:aa6ee96071b7

Punkt 6.2.1 Sprünge auf vollen HM
author gernotbelger
date Wed, 09 Jan 2019 18:07:51 +0100
parents 392745cccede
children 1d4262a68f1f
line wrap: on
line source
/** Copyright (C) 2017 by Bundesanstalt für Gewässerkunde
 * Software engineering by
 *  Björnsen Beratende Ingenieure GmbH
 *  Dr. Schumacher Ingenieurbüro für Wasser und Umwelt
 *
 * This file is Free Software under the GNU AGPL (>=v3)
 * and comes with ABSOLUTELY NO WARRANTY! Check out the
 * documentation coming with Dive4Elements River for details.
 */
package org.dive4elements.river.artifacts.sinfo.common;

import java.util.Collection;
import java.util.List;

import org.apache.commons.collections.PredicateUtils;
import org.dive4elements.river.artifacts.common.AbstractCalculationExportableResult;
import org.dive4elements.river.artifacts.common.ResultRow;
import org.dive4elements.river.artifacts.sinfo.tkhcalculation.SoilKind;
import org.dive4elements.river.artifacts.sinfo.util.WstInfo;

import gnu.trove.TDoubleArrayList;

/**
 * @author Gernot Belger
 */

public abstract class AbstractTkhCalculationResult extends AbstractCalculationExportableResult {

    private static final long serialVersionUID = 1L;

    private final boolean hasTkh;
    private final WstInfo wst;

    public AbstractTkhCalculationResult(final String label, final WstInfo wst, final boolean hasTkh, final Collection<ResultRow> rows) {
        super(label, rows);
        this.wst = wst;
        this.hasTkh = hasTkh;
    }

    public final boolean hasTkh() {
        return this.hasTkh;
    }

    public boolean isShowRefGauges() {
        return this.wst.isShowRefGauges();
    }

    public final double[][] getTkhUpPoints() {

        final double[][] points = getStationPoints(SInfoResultType.tkhup);
        final List<SoilKind> kinds = getValues(SInfoResultType.soilkind, PredicateUtils.truePredicate());

        final double[] xPoints = points[0];
        final double[] yPoints = points[1];

        return adjustTkhVisualization(xPoints, yPoints, kinds);
    }

    public final double[][] getTkhDownPoints() {

        final double[][] points = getStationPoints(SInfoResultType.tkhdown);
        final List<SoilKind> kinds = getValues(SInfoResultType.soilkind, PredicateUtils.truePredicate());

        final double[] xPoints = points[0];
        final double[] yPoints = points[1];

        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 double[] xPoints, final double[] yPoints, final List<SoilKind> kinds) {

        final TDoubleArrayList adjustedX = new TDoubleArrayList(xPoints.length);
        final TDoubleArrayList adjustedY = new TDoubleArrayList(yPoints.length);

        adjustedX.add(xPoints[0]);
        adjustedY.add(yPoints[0]);

        for (int i = 1; i < xPoints.length; 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[i - 1];
                final double y1 = yPoints[i - 1];
                final double x2 = xPoints[i];
                final double y2 = yPoints[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[i]);
            adjustedY.add(yPoints[i]);
        }

        return new double[][] { adjustedX.toNativeArray(), adjustedY.toNativeArray() };
    }

    public final WstInfo getWst() {
        return this.wst; // TODO: Meta-Data export hier hin
    }
}

http://dive4elements.wald.intevation.org