Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/XYColumn.java @ 445:f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
gnv-artifacts/trunk@493 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 30 Dec 2009 23:02:10 +0000 |
parents | eb2ac62e853a |
children | 3cb2bea50456 |
comparison
equal
deleted
inserted
replaced
444:85f48e287fb3 | 445:f42ed4f10b79 |
---|---|
63 return Double.NaN; | 63 return Double.NaN; |
64 } | 64 } |
65 | 65 |
66 public boolean prepare(XYDepth xyDepth) { | 66 public boolean prepare(XYDepth xyDepth) { |
67 int N = values.size(); | 67 int N = values.size(); |
68 if (curve == null && N > 0) { | 68 if (curve == null) { |
69 if (N == 0) { | |
70 log.error("no points for interpolation"); | |
71 return false; | |
72 } | |
73 | |
69 if (N == 1) { | 74 if (N == 1) { |
70 // only one value -> constant function | 75 // only one value -> constant function |
71 curve = new ConstantFunction(values.get(0).v); | 76 curve = new ConstantFunction(values.get(0).v); |
72 } | 77 } |
73 else { // more than on value | 78 else { // more than on value |
76 | 81 |
77 // if there is no value at 0 repeat first value | 82 // if there is no value at 0 repeat first value |
78 HeightValue first = values.get(0); | 83 HeightValue first = values.get(0); |
79 if (first.z < 0d) { | 84 if (first.z < 0d) { |
80 values.add(0, new HeightValue(0d, first.z, first.k-1)); | 85 values.add(0, new HeightValue(0d, first.z, first.k-1)); |
86 ++N; | |
81 } | 87 } |
82 | 88 |
83 // if there is no value at depth repeat last value | 89 // if there is no value at depth repeat last value |
84 HeightValue last = values.get(N-1); | 90 HeightValue last = values.get(N-1); |
85 if (last.z > depth) { | 91 if (last.z > depth) { |
86 values.add(new HeightValue(depth, last.z, last.k+1)); | 92 values.add(new HeightValue(depth, last.z, last.k+1)); |
93 ++N; | |
87 } | 94 } |
88 N = values.size(); | 95 N = values.size(); |
89 if (N < 3) { // interpolate linear | 96 if (N < 3) { // interpolate linear |
90 first = values.get(0); | 97 first = values.get(0); |
91 last = values.get(N-1); | 98 last = values.get(N-1); |
95 } | 102 } |
96 else { // higher degree interpolation | 103 else { // higher degree interpolation |
97 double [] z = new double[N]; | 104 double [] z = new double[N]; |
98 double [] v = new double[N]; | 105 double [] v = new double[N]; |
99 for (int i = 0; i < N; ++i) { | 106 for (int i = 0; i < N; ++i) { |
100 HeightValue h = values.get(i); | 107 HeightValue h = values.get(N-1-i); |
101 z[i] = h.z; | 108 z[i] = h.z; |
102 v[i] = h.v; | 109 v[i] = h.v; |
103 } | 110 } |
104 try { | 111 try { |
105 curve = getInterpolator().interpolate(z, v); | 112 curve = getInterpolator().interpolate(z, v); |
109 return false; | 116 return false; |
110 } | 117 } |
111 } | 118 } |
112 } | 119 } |
113 } | 120 } |
114 else { | |
115 log.error("no points for interpolation"); | |
116 return false; | |
117 } | |
118 return true; | 121 return true; |
119 } | 122 } |
120 | 123 |
121 protected UnivariateRealInterpolator getInterpolator() { | 124 protected UnivariateRealInterpolator getInterpolator() { |
122 return new SplineInterpolator(); | 125 return new SplineInterpolator(); |