comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/extreme/Curve.java @ 3737:976be312a84c

Simplified code for extreme curves. flys-artifacts/trunk@5412 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 09 Sep 2012 17:19:50 +0000
parents 893b2477208f
children 467efea19d15
comparison
equal deleted inserted replaced
3736:da1969b05292 3737:976be312a84c
3 import de.intevation.flys.artifacts.math.Function; 3 import de.intevation.flys.artifacts.math.Function;
4 import de.intevation.flys.artifacts.math.NaNFunction; 4 import de.intevation.flys.artifacts.math.NaNFunction;
5 import de.intevation.flys.artifacts.math.UnivariateRealFunctionFunction; 5 import de.intevation.flys.artifacts.math.UnivariateRealFunctionFunction;
6 6
7 import de.intevation.flys.artifacts.math.fitting.FunctionFactory; 7 import de.intevation.flys.artifacts.math.fitting.FunctionFactory;
8
9 import de.intevation.flys.artifacts.model.QW;
10 8
11 import java.io.Serializable; 9 import java.io.Serializable;
12 10
13 import java.lang.ref.SoftReference; 11 import java.lang.ref.SoftReference;
14 12
21 public class Curve 19 public class Curve
22 implements Serializable, Function 20 implements Serializable, Function
23 { 21 {
24 private static Logger log = Logger.getLogger(Curve.class); 22 private static Logger log = Logger.getLogger(Curve.class);
25 23
26 protected QW [] qws; 24 protected double [] qs;
25 protected double [] ws;
27 protected String function; 26 protected String function;
28 protected double [] coeffs; 27 protected double [] coeffs;
29 28
30 // The spline is pretty heavy weight so cache it with a soft ref only. 29 // The spline is pretty heavy weight so cache it with a soft ref only.
31 protected transient SoftReference<Function> spline; 30 protected transient SoftReference<Function> spline;
32 protected transient Function extrapolation; 31 protected transient Function extrapolation;
33 32
34 public Curve() { 33 public Curve() {
35 } 34 }
36 35
37 public Curve(QW [] qws, String function, double [] coeffs) { 36 public Curve(
38 this.qws = qws; 37 double [] qs,
38 double [] ws,
39 String function,
40 double [] coeffs
41 ) {
42 this.qs = qs;
43 this.ws = ws;
39 this.function = function; 44 this.function = function;
40 this.coeffs = coeffs; 45 this.coeffs = coeffs;
41 } 46 }
42 47
43 public QW [] getQWs() { 48 public double [] getQs() {
44 return qws; 49 return qs;
50 }
51
52 public double [] getWs() {
53 return ws;
45 } 54 }
46 55
47 public String getFunction() { 56 public String getFunction() {
48 return function; 57 return function;
49 } 58 }
52 return coeffs; 61 return coeffs;
53 } 62 }
54 63
55 @Override 64 @Override
56 public double value(double x) { 65 public double value(double x) {
57 if (x < qws[0].getQ()) return Double.NaN; 66 if (x < qs[0]) return Double.NaN;
58 return (x <= qws[qws.length-1].getQ() 67 return (x <= qs[qs.length-1]
59 ? getSpline() 68 ? getSpline()
60 : getExtrapolation()).value(x); 69 : getExtrapolation()).value(x);
61 } 70 }
62 71
63 protected synchronized Function getExtrapolation() { 72 protected synchronized Function getExtrapolation() {
83 return sp; 92 return sp;
84 } 93 }
85 94
86 protected Function createSpline() { 95 protected Function createSpline() {
87 SplineInterpolator interpolator = new SplineInterpolator(); 96 SplineInterpolator interpolator = new SplineInterpolator();
88 double [] qs = new double[qws.length];
89 double [] ws = new double[qws.length];
90 for (int i = 0; i < qws.length; ++i) {
91 QW qw = qws[i];
92 qs[i] = qw.getQ();
93 ws[i] = qw.getW();
94 }
95 try { 97 try {
96 return new UnivariateRealFunctionFunction( 98 return new UnivariateRealFunctionFunction(
97 interpolator.interpolate(qs, ws)); 99 interpolator.interpolate(qs, ws));
98 } 100 }
99 catch (MathIllegalArgumentException miae) { 101 catch (MathIllegalArgumentException miae) {

http://dive4elements.wald.intevation.org