comparison flys-artifacts/src/main/java/org/dive4elements/river/artifacts/model/InfoldingColumns.java @ 5831:bd047b71ab37

Repaired internal references
author Sascha L. Teichmann <teichmann@intevation.de>
date Thu, 25 Apr 2013 12:06:39 +0200
parents flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java@243f1eb02b95
children
comparison
equal deleted inserted replaced
5830:160f53ee0870 5831:bd047b71ab37
1 package org.dive4elements.river.artifacts.model;
2
3 /** A pretty naive pointwise algorithm to find out the columns
4 * of a WSTValueTable which imfold ("umhuellen") a set of WQKMs
5 * in terms of Q.
6 * A better implemention would exploit the fact that the
7 * Qs normally are constant for a while along km. This would
8 * reduce the runtime complexity to only a few Q spans instead
9 * of the pointwise evaluation.
10 */
11 public class InfoldingColumns
12 {
13 private QRangeTree.QuickQFinder [] qFinders;
14
15 private boolean [] infoldingColumns;
16
17 public InfoldingColumns() {
18 }
19
20 public InfoldingColumns(WstValueTable.Column [] columns) {
21
22 qFinders = new QRangeTree.QuickQFinder[columns.length];
23 for (int i = 0; i < qFinders.length; ++i) {
24 qFinders[i] = columns[i].getQRangeTree().new QuickQFinder();
25 }
26
27 infoldingColumns = new boolean[columns.length];
28 }
29
30 public boolean [] getInfoldingColumns() {
31 return infoldingColumns;
32 }
33
34 public void markInfoldingColumns(QKms [] qkms) {
35 for (QKms qk: qkms) {
36 markInfoldingColumns(qk);
37 }
38 }
39
40 public void markInfoldingColumns(QKms qkms) {
41 int N = qkms.size();
42 int C = qFinders.length-1;
43 for (int i = 0; i < N; ++i) {
44 double km = qkms.getKm(i);
45 double q = qkms.getQ(i);
46 double above = Double.MAX_VALUE;
47 double below = -Double.MAX_VALUE;
48 int aboveIdx = -1;
49 int belowIdx = -1;
50
51 for (int j = C; j >= 0; --j) {
52 double qc = qFinders[j].findQ(km);
53 if (Double.isNaN(qc)) {
54 continue;
55 }
56 if (qc <= q) {
57 if (qc > below) {
58 below = qc;
59 belowIdx = j;
60 }
61 }
62 else if (qc < above) { // qc > q
63 above = qc;
64 aboveIdx = j;
65 }
66 }
67
68 if (aboveIdx != -1) {
69 infoldingColumns[aboveIdx] = true;
70 }
71
72 if (belowIdx != -1) {
73 infoldingColumns[belowIdx] = true;
74 }
75 }
76 }
77 }
78 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org