changeset 4797:43e69af28b3c

A naive algorithm to figure out the "Umhuellende" of a set of WQKms.
author Sascha L. Teichmann <teichmann@intevation.de>
date Sun, 13 Jan 2013 14:18:04 +0100
parents 729a5edb0313
children 39885bdfc6fc
files flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java
diffstat 2 files changed, 53 insertions(+), 1 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Sat Jan 12 11:30:46 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/QRangeTree.java	Sun Jan 13 14:18:04 2013 +0100
@@ -101,8 +101,52 @@
                 return current.q;
             }
         }
+
+        public Node findNode(double pos) {
+            Node current = this;
+            while (current != null) {
+                if (pos < current.a) {
+                    current = current.left;
+                }
+                else if (pos > current.b) {
+                    current = current.right;
+                }
+                return current;
+            }
+            return null;
+        }
+
+        public boolean contains(double c) {
+            return c >= a && c <= b;
+        }
     } // class Node
 
+    /** Class to cache the last found tree leaf in a search for Q.
+     *  Its likely that a neighbored pos search
+     *  results in using the same leaf node. So
+     *  caching this leaf will minimize expensive
+     *  tree traversals.
+     *  Modeled as inner class because the QRangeTree
+     *  itself is a shared data structure.
+     *  Using this class omits interpolation between
+     *  leaves.
+     */
+    public final class QuickQFinder {
+
+        private Node last;
+
+        public QuickQFinder() {
+        }
+
+        public double findQ(double pos) {
+            if (last != null && last.contains(pos)) {
+                return last.q;
+            }
+            last = QRangeTree.this.findNode(pos);
+            return last != null ? last.q : Double.NaN;
+        }
+    } // class QuickQFinder
+
     protected Node root;
 
     public QRangeTree() {
@@ -212,6 +256,10 @@
         return root != null ? root.findQ(pos) : Double.NaN;
     }
 
+    public Node findNode(double pos) {
+        return root != null ? root.findNode(pos) : null;
+    }
+
     protected Node head() {
         Node head = root;
         while (head.left != null) {
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sat Jan 12 11:30:46 2013 +0100
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/WstValueTable.java	Sun Jan 13 14:18:04 2013 +0100
@@ -59,7 +59,7 @@
             this.name = name;
         }
 
-    public QRangeTree getQRangeTree() {
+        public QRangeTree getQRangeTree() {
             return qRangeTree;
         }
 
@@ -540,6 +540,10 @@
         this.rows    = rows;
     }
 
+    public Column [] getColumns() {
+        return columns;
+    }
+
     /** Sort rows (by km). */
     public void sortRows() {
         Collections.sort(rows);

http://dive4elements.wald.intevation.org