Mercurial > dive4elements > river
comparison flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/InfoldingColumns.java @ 4800:c6814695c82c
Added missing InfoldingColumns.java
author | Sascha L. Teichmann <teichmann@intevation.de> |
---|---|
date | Sun, 13 Jan 2013 17:00:37 +0100 |
parents | |
children | 243f1eb02b95 |
comparison
equal
deleted
inserted
replaced
4799:e3532c7850b9 | 4800:c6814695c82c |
---|---|
1 package de.intevation.flys.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(WQKms [] wqkms) { | |
35 for (WQKms wqk: wqkms) { | |
36 markInfoldingColumns(wqk); | |
37 } | |
38 } | |
39 | |
40 public void markInfoldingColumns(WQKms wqkms) { | |
41 int N = wqkms.size(); | |
42 int C = qFinders.length-1; | |
43 for (int i = 0; i < N; ++i) { | |
44 double km = wqkms.getKm(i); | |
45 double q = wqkms.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 : |