diff gnv-artifacts/src/main/java/de/intevation/gnv/raster/Vectorizer.java @ 436:6642ab6c583c

Added vectorizer rings callback which generates polygon datasets suitable for polygon plots. gnv-artifacts/trunk@484 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sat, 26 Dec 2009 15:32:08 +0000
parents 21fbd254db71
children b624879d2902
line wrap: on
line diff
--- a/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Vectorizer.java	Fri Dec 25 12:00:14 2009 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/Vectorizer.java	Sat Dec 26 15:32:08 2009 +0000
@@ -14,7 +14,11 @@
 {
     public interface RingsHandler {
 
-        void handleRings(List rings, int value, int width);
+        void handleRings(
+            List<Edge> rings,
+            int        value, 
+            int        width,
+            int        height);
 
     } // interface RingsHandler
 
@@ -69,6 +73,15 @@
             do { ++length; } while ((current = current.next) != this);
             return length;
         }
+
+        public int hashCode() {
+            return (a << 16) | b;
+        }
+
+        public boolean equals(Object other) {
+            Edge e = (Edge)other;
+            return a == e.a && b == e.b;
+        }
     } // class Edge
 
     protected static Edge simplify(Edge edge, int width) {
@@ -113,11 +126,17 @@
     protected int []            raster;
     protected int               width;
     protected TIntObjectHashMap openEdges;
-    protected ArrayList         rings;
+    protected List<Edge>        rings;
+    protected boolean           simplify;
 
     public Vectorizer() {
-        openEdges = new TIntObjectHashMap();
-        rings     = new ArrayList();
+        this(true);
+    }
+
+    public Vectorizer(boolean simplify) {
+        openEdges     = new TIntObjectHashMap();
+        rings         = new ArrayList<Edge>();
+        this.simplify = simplify;
     }
 
     public Vectorizer(int [] raster, int width) {
@@ -163,7 +182,7 @@
         }
 
         if (edge.isComplete()) {
-            rings.add(simplify(edge, width + 1));
+            rings.add(simplify ? simplify(edge, width + 1) : edge);
         }
         else {
             if (otherA == null) {
@@ -183,6 +202,7 @@
 
         int regions = 0;
 
+        int height = raster.length / width;
 
         for (int i = 0; i < raster.length; ++i) {
             if (visited.get(i)) {
@@ -278,7 +298,11 @@
                 current = stack.pop();
             }
 
-            handler.handleRings(rings, currentValue, width + 1);
+            handler.handleRings(
+                rings, 
+                currentValue, 
+                width + 1,
+                height + 1);
 
             resetRegion();
         }

http://dive4elements.wald.intevation.org