Mercurial > dive4elements > river
changeset 406:663aa18bee7f
Back jump correction should work now for both flow directions.
flys-artifacts/trunk@1848 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 07 May 2011 21:34:02 +0000 |
parents | 55c2b0d9999e |
children | 9eb5f0c8fe7f |
files | flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java |
diffstat | 2 files changed, 46 insertions(+), 0 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog Fri May 06 16:49:31 2011 +0000 +++ b/flys-artifacts/ChangeLog Sat May 07 21:34:02 2011 +0000 @@ -1,3 +1,9 @@ +2011-05-07 Sascha L. Teichmann <sascha.teichmann@intevation.de> + + * src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java: + Added code to make back jump correction work with both + potential flow directions. + 2011-05-06 Sascha L. Teichmann <sascha.teichmann@intevation.de> * src/main/resources/metadata/template.xml:
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Fri May 06 16:49:31 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/math/BackJumpCorrector.java Sat May 07 21:34:02 2011 +0000 @@ -38,7 +38,47 @@ return corrected; } + private static final boolean isIncreasing(double [] ws) { + int inc = 0; + int dec = 0; + int sweet = (ws.length-1)/2; + for (int i = 1; i < ws.length; ++i) { + if (ws[i] > ws[i-1]) { + if (++inc > sweet) { + return true; + } + } + else if (++dec > sweet) { + return false; + } + } + return inc > sweet; + } + public boolean doCorrection(double [] km, double [] ws) { + boolean isIncreasing = isIncreasing(ws); + + if (isIncreasing) { + // mirror along x axis to simulate decreasing values + ws = (double [])ws.clone(); + for (int i = 0; i < ws.length; ++i) { + ws[i] = -ws[i]; + } + } + + boolean hasBackJumps = doCorrectionClean(km, ws); + + if (hasBackJumps && isIncreasing) { + // mirror back + for (int i = 0; i < corrected.length; ++i) { + corrected[i] = -corrected[i]; + } + } + + return hasBackJumps; + } + + protected boolean doCorrectionClean(double [] km, double [] ws) { int N = km.length; if (N != ws.length) {