comparison 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
comparison
equal deleted inserted replaced
435:67091b17462d 436:6642ab6c583c
12 */ 12 */
13 public class Vectorizer 13 public class Vectorizer
14 { 14 {
15 public interface RingsHandler { 15 public interface RingsHandler {
16 16
17 void handleRings(List rings, int value, int width); 17 void handleRings(
18 List<Edge> rings,
19 int value,
20 int width,
21 int height);
18 22
19 } // interface RingsHandler 23 } // interface RingsHandler
20 24
21 public static final class Edge { 25 public static final class Edge {
22 26
66 public int length() { 70 public int length() {
67 int length = 0; 71 int length = 0;
68 Edge current = this; 72 Edge current = this;
69 do { ++length; } while ((current = current.next) != this); 73 do { ++length; } while ((current = current.next) != this);
70 return length; 74 return length;
75 }
76
77 public int hashCode() {
78 return (a << 16) | b;
79 }
80
81 public boolean equals(Object other) {
82 Edge e = (Edge)other;
83 return a == e.a && b == e.b;
71 } 84 }
72 } // class Edge 85 } // class Edge
73 86
74 protected static Edge simplify(Edge edge, int width) { 87 protected static Edge simplify(Edge edge, int width) {
75 88
111 } 124 }
112 125
113 protected int [] raster; 126 protected int [] raster;
114 protected int width; 127 protected int width;
115 protected TIntObjectHashMap openEdges; 128 protected TIntObjectHashMap openEdges;
116 protected ArrayList rings; 129 protected List<Edge> rings;
130 protected boolean simplify;
117 131
118 public Vectorizer() { 132 public Vectorizer() {
119 openEdges = new TIntObjectHashMap(); 133 this(true);
120 rings = new ArrayList(); 134 }
135
136 public Vectorizer(boolean simplify) {
137 openEdges = new TIntObjectHashMap();
138 rings = new ArrayList<Edge>();
139 this.simplify = simplify;
121 } 140 }
122 141
123 public Vectorizer(int [] raster, int width) { 142 public Vectorizer(int [] raster, int width) {
124 this(); 143 this();
125 this.raster = raster; 144 this.raster = raster;
161 if (otherB != null) { 180 if (otherB != null) {
162 otherB.chain(edge, edge.b); 181 otherB.chain(edge, edge.b);
163 } 182 }
164 183
165 if (edge.isComplete()) { 184 if (edge.isComplete()) {
166 rings.add(simplify(edge, width + 1)); 185 rings.add(simplify ? simplify(edge, width + 1) : edge);
167 } 186 }
168 else { 187 else {
169 if (otherA == null) { 188 if (otherA == null) {
170 openEdges.put(edge.a, edge); 189 openEdges.put(edge.a, edge);
171 } 190 }
181 200
182 TIntStack stack = new TIntStack(); 201 TIntStack stack = new TIntStack();
183 202
184 int regions = 0; 203 int regions = 0;
185 204
205 int height = raster.length / width;
186 206
187 for (int i = 0; i < raster.length; ++i) { 207 for (int i = 0; i < raster.length; ++i) {
188 if (visited.get(i)) { 208 if (visited.get(i)) {
189 continue; 209 continue;
190 } 210 }
276 } 296 }
277 297
278 current = stack.pop(); 298 current = stack.pop();
279 } 299 }
280 300
281 handler.handleRings(rings, currentValue, width + 1); 301 handler.handleRings(
302 rings,
303 currentValue,
304 width + 1,
305 height + 1);
282 306
283 resetRegion(); 307 resetRegion();
284 } 308 }
285 309
286 return regions; 310 return regions;

http://dive4elements.wald.intevation.org