Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/Parameters.java @ 3059:4f7171ac6153
Parameters: Linear interpolation of parameters.
flys-artifacts/trunk@4638 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 11 Jun 2012 14:51:21 +0000 |
parents | febc39e77672 |
children | 49baebb39305 |
comparison
equal
deleted
inserted
replaced
3058:df4d6b286af8 | 3059:4f7171ac6153 |
---|---|
1 package de.intevation.flys.artifacts.model; | 1 package de.intevation.flys.artifacts.model; |
2 | |
3 import de.intevation.flys.artifacts.math.Linear; | |
2 | 4 |
3 import gnu.trove.TDoubleArrayList; | 5 import gnu.trove.TDoubleArrayList; |
4 | 6 |
5 import java.io.Serializable; | 7 import java.io.Serializable; |
6 | 8 |
8 | 10 |
9 public class Parameters | 11 public class Parameters |
10 implements Serializable | 12 implements Serializable |
11 { | 13 { |
12 private static Logger log = Logger.getLogger(Parameters.class); | 14 private static Logger log = Logger.getLogger(Parameters.class); |
15 | |
16 public static final double EPSILON = 1e-4; | |
13 | 17 |
14 protected String [] columnNames; | 18 protected String [] columnNames; |
15 protected TDoubleArrayList [] columns; | 19 protected TDoubleArrayList [] columns; |
16 | 20 |
17 public Parameters() { | 21 public Parameters() { |
151 if (v < vl) hi = mid - 1; | 155 if (v < vl) hi = mid - 1; |
152 else if (v > vh) lo = mid + 1; | 156 else if (v > vh) lo = mid + 1; |
153 else return mid; | 157 else return mid; |
154 } | 158 } |
155 | 159 |
156 return -1; | 160 return -(lo + 1); |
161 } | |
162 | |
163 public double [] interpolate(int columnIndex, double key) { | |
164 return interpolate(columnIndex, key, new double[columns.length]); | |
165 } | |
166 | |
167 public double [] interpolate(String columnName, double key) { | |
168 return interpolate( | |
169 columnIndex(columnName), key, new double[columns.length]); | |
170 } | |
171 | |
172 public double [] interpolate( | |
173 String columnName, | |
174 double key, | |
175 double [] values | |
176 ) { | |
177 return interpolate(columnIndex(columnName), key, values); | |
178 } | |
179 | |
180 public double [] interpolate(int columnIndex, double key, double [] values) { | |
181 | |
182 int row = binarySearch(columnIndex, key, EPSILON); | |
183 | |
184 if (row >= 0) { | |
185 for (int i = 0; i < values.length; ++i) { | |
186 values[i] = columns[i].getQuick(row); | |
187 } | |
188 } | |
189 else { | |
190 row = -row - 1; | |
191 if (row < 1 || row >= size()) { | |
192 return null; | |
193 } | |
194 double v1 = columns[columnIndex].getQuick(row-1); | |
195 double v2 = columns[columnIndex].getQuick(row); | |
196 double factor = Linear.factor(key, v1, v2); | |
197 for (int i = 0; i < values.length; ++i) { | |
198 values[i] = Linear.weight( | |
199 factor, | |
200 columns[i].getQuick(row-1), | |
201 columns[i].getQuick(row)); | |
202 } | |
203 } | |
204 return values; | |
157 } | 205 } |
158 | 206 |
159 public boolean isSorted(String columnName) { | 207 public boolean isSorted(String columnName) { |
160 return isSorted(columnIndex(columnName)); | 208 return isSorted(columnIndex(columnName)); |
161 } | 209 } |