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; rrenkert@4668: teichmann@5831: import org.dive4elements.artifactdatabase.state.Facet; rrenkert@4668: teichmann@5831: import org.dive4elements.artifacts.Artifact; teichmann@5831: import org.dive4elements.artifacts.CallContext; rrenkert@4668: teichmann@5867: import org.dive4elements.river.artifacts.D4EArtifact; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.access.RiverAccess; teichmann@5866: import org.dive4elements.river.artifacts.context.RiverContext; teichmann@5831: teichmann@5831: import org.dive4elements.river.artifacts.math.MovingAverage; teichmann@5831: import org.dive4elements.river.artifacts.states.DefaultState.ComputeType; rrenkert@4668: rrenkert@4668: import org.apache.log4j.Logger; rrenkert@4668: rrenkert@4668: /** rrenkert@4668: * Facet of a FlowVelocity curve. rrenkert@4668: */ rrenkert@4668: public class FlowVelocityFilterFacet extends DataFacet { rrenkert@4668: rrenkert@4668: private static Logger logger = Logger.getLogger(FlowVelocityFilterFacet.class); rrenkert@4668: rrenkert@4668: public FlowVelocityFilterFacet() { rrenkert@4668: // required for clone operation deepCopy() rrenkert@4668: } rrenkert@4668: rrenkert@4668: rrenkert@4668: public FlowVelocityFilterFacet( rrenkert@4668: int idx, rrenkert@4668: String name, rrenkert@4668: String description, rrenkert@4668: ComputeType type, rrenkert@4668: String stateId, rrenkert@4668: String hash rrenkert@4668: ) { rrenkert@4668: super(idx, name, description, type, hash, stateId); rrenkert@4668: } rrenkert@4668: rrenkert@4668: rrenkert@4668: public Object getData(Artifact artifact, CallContext context) { rrenkert@4668: logger.debug("Get data for flow velocity at index: " + index); rrenkert@4668: rrenkert@4668: Double start = (Double)context.getContextValue("startkm"); rrenkert@4668: Double end = (Double)context.getContextValue("endkm"); teichmann@5867: D4EArtifact flys = (D4EArtifact) artifact; rrenkert@4668: rrenkert@4668: CalculationResult res = (CalculationResult) rrenkert@4668: flys.compute(context, hash, stateId, type, false); rrenkert@4668: rrenkert@4668: FlowVelocityData[] data = (FlowVelocityData[]) res.getData(); rrenkert@4668: if(start != null && end != null) { teichmann@5866: RiverContext fc = (RiverContext)context.globalContext(); rrenkert@4668: ZoomScale scales = (ZoomScale)fc.get("zoomscale"); teichmann@5867: RiverAccess access = new RiverAccess((D4EArtifact)artifact); felix@7261: String river = access.getRiverName(); rrenkert@4668: rrenkert@4668: double radius = scales.getRadius(river, start, end); rrenkert@4668: FlowVelocityData oldData = data[index]; rrenkert@4668: FlowVelocityData newData = new FlowVelocityData(); rrenkert@4668: double[][] q = oldData.getQPoints(); rrenkert@4668: double[][] totalV = MovingAverage.weighted(oldData.getTotalChannelPoints(), radius); rrenkert@4668: double[][] mainV = MovingAverage.weighted(oldData.getMainChannelPoints(), radius); rrenkert@4668: double[][] tau = MovingAverage.weighted(oldData.getTauPoints(), radius); rrenkert@4668: for(int j = 0; j < q[0].length; j++) { rrenkert@4668: newData.addKM(q[0][j]); rrenkert@4668: newData.addQ(q[1][j]); rrenkert@4668: newData.addTauMain(tau[1][j]); rrenkert@4668: newData.addVMain(mainV[1][j]); rrenkert@4668: newData.addVTotal(totalV[1][j]); rrenkert@4668: } rrenkert@4668: return newData; rrenkert@4668: } rrenkert@4668: return data[index]; rrenkert@4668: } rrenkert@4668: rrenkert@4668: rrenkert@4668: /** Copy deeply. */ rrenkert@4668: @Override rrenkert@4668: public Facet deepCopy() { rrenkert@4668: FlowVelocityFilterFacet copy = new FlowVelocityFilterFacet(); rrenkert@4668: copy.set(this); rrenkert@4668: copy.type = type; rrenkert@4668: copy.hash = hash; rrenkert@4668: copy.stateId = stateId; rrenkert@4668: return copy; rrenkert@4668: } rrenkert@4668: } rrenkert@4668: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :