teichmann@5863: /* Copyright (C) 2011, 2012, 2013 by Bundesanstalt für Gewässerkunde teichmann@5863: * Software engineering by Intevation GmbH teichmann@5863: * teichmann@5994: * This file is Free Software under the GNU AGPL (>=v3) teichmann@5863: * and comes with ABSOLUTELY NO WARRANTY! Check out the teichmann@5994: * documentation coming with Dive4Elements River for details. teichmann@5863: */ teichmann@5863: teichmann@5831: package org.dive4elements.river.artifacts.model.minfo; ingo@3784: andre@8581: import org.dive4elements.river.utils.DoubleUtil; andre@8581: ingo@3784: import gnu.trove.TDoubleArrayList; ingo@3784: andre@8581: import org.apache.commons.math.analysis.polynomials.PolynomialSplineFunction; andre@8581: andre@8581: import org.apache.commons.math.ArgumentOutsideDomainException; ingo@3784: ingo@3784: public class BedDiameterResult ingo@3784: extends BedQualityDiameterResult ingo@3784: { ingo@3784: protected TDoubleArrayList diameterCap; ingo@3784: protected TDoubleArrayList diameterSub; ingo@3784: andre@8581: protected PolynomialSplineFunction interpolSub; andre@8581: protected PolynomialSplineFunction interpolCap; andre@8581: protected boolean nonInterpolSub; andre@8581: protected boolean nonInterpolCap; andre@8581: ingo@3784: public BedDiameterResult ( ingo@3784: String type, ingo@3784: TDoubleArrayList diameterCap, ingo@3784: TDoubleArrayList diameterSub, ingo@3784: TDoubleArrayList km ingo@3784: ) { ingo@3784: super(type, km); ingo@3784: this.diameterCap = diameterCap; ingo@3784: this.diameterSub = diameterSub; andre@8581: interpolSub = null; andre@8581: nonInterpolSub = false; andre@8581: interpolCap = null; andre@8581: nonInterpolCap = false; ingo@3784: } ingo@3784: ingo@3784: public double getDiameterCap(int ndx) { ingo@3784: if (diameterCap != null) { ingo@3784: return this.diameterCap.get(ndx); ingo@3784: } ingo@3784: return Double.NaN; ingo@3784: } ingo@3784: ingo@3784: public double getDiameterSub(int ndx) { ingo@3784: if (diameterSub != null) { ingo@3784: return this.diameterSub.get(ndx); ingo@3784: } ingo@3784: return Double.NaN; ingo@3784: } ingo@3784: ingo@3785: public double getDiameterCap(double km) { ingo@3785: if (kms.indexOf(km) >= 0) { ingo@3785: return diameterCap.get(kms.indexOf(km)); ingo@3785: } ingo@3785: return Double.NaN; ingo@3785: } ingo@3785: andre@8581: public double getDiameterCapInterpol(double km) { andre@8581: if (nonInterpolCap) { andre@8581: return Double.NaN; andre@8581: } andre@8581: if (interpolCap == null) { andre@8581: interpolCap = DoubleUtil.getLinearInterpolator(kms, diameterCap); andre@8581: if (interpolCap == null) { andre@8581: nonInterpolCap = true; andre@8581: return Double.NaN; andre@8581: } andre@8581: } andre@8581: try { andre@8581: return interpolCap.value(km); andre@8581: } catch (ArgumentOutsideDomainException e) { andre@8581: /* This is expected for many results. */ andre@8581: return Double.NaN; andre@8581: } andre@8581: } andre@8581: ingo@3785: public double getDiameterSub(double km) { ingo@3785: if (kms.indexOf(km) >= 0) { ingo@3785: return diameterSub.get(kms.indexOf(km)); ingo@3785: } ingo@3785: return Double.NaN; ingo@3785: } ingo@3785: andre@8581: public double getDiameterSubInterpol(double km) { andre@8581: if (nonInterpolSub) { andre@8581: return Double.NaN; andre@8581: } andre@8581: if (interpolSub == null) { andre@8581: interpolSub = DoubleUtil.getLinearInterpolator(kms, diameterSub); andre@8581: if (interpolSub == null) { andre@8581: nonInterpolSub = true; andre@8581: return Double.NaN; andre@8581: } andre@8581: } andre@8581: try { andre@8581: return interpolSub.value(km); andre@8581: } catch (ArgumentOutsideDomainException e) { andre@8581: /* This is expected for many results. */ andre@8581: return Double.NaN; andre@8581: } andre@8581: } andre@8581: ingo@3784: public double[][] getDiameterCapData() { ingo@3784: return new double[][] { ingo@3784: kms.toNativeArray(), ingo@3784: diameterCap.toNativeArray() ingo@3784: }; ingo@3784: } ingo@3784: ingo@3784: public double[][] getDiameterSubData() { ingo@3784: return new double[][] { ingo@3784: kms.toNativeArray(), ingo@3784: diameterSub.toNativeArray() ingo@3784: }; ingo@3784: } ingo@3784: }