Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/Vectorizer.java @ 430:23e9352df09b
Load salinity palette correctly.
gnv-artifacts/trunk@478 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 22 Dec 2009 20:45:45 +0000 |
parents | 21fbd254db71 |
children | 6642ab6c583c |
rev | line source |
---|---|
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
1 package de.intevation.gnv.raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
2 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
3 import java.util.BitSet; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
4 import java.util.List; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
5 import java.util.ArrayList; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
6 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import gnu.trove.TIntStack; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import gnu.trove.TIntObjectHashMap; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
10 /** |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
11 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 */ |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
13 public class Vectorizer |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
14 { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
15 public interface RingsHandler { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
16 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
17 void handleRings(List rings, int value, int width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
18 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
19 } // interface RingsHandler |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
21 public static final class Edge { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
22 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
23 public Edge prev; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
24 public Edge next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
25 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public int a; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 public int b; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
28 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
29 public Edge() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
30 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
31 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
32 public Edge(int a, int b) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
33 this.a = a; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
34 this.b = b; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
35 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
36 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
37 public void chain(Edge other, int found) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
38 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
39 if (found == a) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
40 other.next = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
41 prev = other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 return; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
45 if (found == b) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
46 next = other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
47 other.prev = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 return; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
50 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
51 throw new IllegalStateException("cannot chain"); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
52 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
54 public boolean isComplete() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
55 Edge current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
56 do { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 if (current.prev == null || current.next == null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 return false; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
59 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
60 current = current.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
61 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
62 while (current != this); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
63 return true; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
65 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
66 public int length() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
67 int length = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
68 Edge current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
69 do { ++length; } while ((current = current.next) != this); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 return length; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
72 } // class Edge |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
73 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
74 protected static Edge simplify(Edge edge, int width) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 Edge e1 = edge; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 Edge e2 = edge.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
78 Edge e3 = e2.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
79 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
80 int length = edge.length(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
81 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
82 int count = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
84 do { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 int e1x = e1.a % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 int e1y = e1.a / width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 int e2x = e2.a % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
88 int e2y = e2.a / width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
89 int e3x = e3.a % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
90 int e3y = e3.a / width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
91 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
92 if ((e1x == e2x && e2x == e3x && e1x == e3x) |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
93 || (e1y == e2y && e2y == e3y && e1y == e3y)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
94 e1.next = e3; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
95 e3.prev = e1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
96 e2 = e3; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
97 e3 = e2.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
98 count = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
99 --length; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
100 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
101 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
102 e1 = e1.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
103 e2 = e2.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 e3 = e3.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
105 ++count; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 while (count < length + 2); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 return e1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
111 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
112 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 protected int [] raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 protected int width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 protected TIntObjectHashMap openEdges; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 protected ArrayList rings; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
117 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
118 public Vectorizer() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 openEdges = new TIntObjectHashMap(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 rings = new ArrayList(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
121 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
122 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
123 public Vectorizer(int [] raster, int width) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
124 this(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
125 this.raster = raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 this.width = width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 public static final int tl(int i, int w) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
130 int x = i % w; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 int y = i / w; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 return x + (w + 1)*y; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
133 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
134 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 public static final int tr(int i, int w) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 return tl(i, w) + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
138 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
139 public static final int bl(int i, int w) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
140 return tl(i, w) + w + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
141 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
142 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 public static final int br(int i, int w) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 return bl(i, w) + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
146 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
147 protected void resetRegion() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 openEdges.clear(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 rings.clear(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
150 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
151 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
152 protected void emit(Edge edge) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
153 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
154 Edge otherA = (Edge)openEdges.remove(edge.a); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
155 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
156 if (otherA != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
157 otherA.chain(edge, edge.a); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
158 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
159 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
160 Edge otherB = (Edge)openEdges.remove(edge.b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
161 if (otherB != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
162 otherB.chain(edge, edge.b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
163 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
164 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
165 if (edge.isComplete()) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
166 rings.add(simplify(edge, width + 1)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
167 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
168 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
169 if (otherA == null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
170 openEdges.put(edge.a, edge); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
171 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
172 if (otherB == null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
173 openEdges.put(edge.b, edge); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
174 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
175 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
176 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
177 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
178 public int process(RingsHandler handler) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
179 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
180 BitSet visited = new BitSet(raster.length); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
181 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
182 TIntStack stack = new TIntStack(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 int regions = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
185 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
186 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
187 for (int i = 0; i < raster.length; ++i) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
188 if (visited.get(i)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
189 continue; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
190 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
191 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 ++regions; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
193 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
194 int currentValue = raster[i]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 visited.set(i); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 int current = i; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
198 visited.set(current); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
199 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
200 for (;;) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
201 int tl = tl(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
202 int tr = tr(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
203 int bl = bl(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 int br = br(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
205 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
206 int t = current - width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 if (t < 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
209 emit(new Edge(tr, tl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
210 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
211 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
212 if (raster[t] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 emit(new Edge(tr, tl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
215 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
216 if (!visited.get(t)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
217 visited.set(t); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
218 stack.push(t); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
219 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
220 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
221 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
222 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 int b = current + width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
225 if (b >= raster.length) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
226 emit(new Edge(bl, br)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
227 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 if (raster[b] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 emit(new Edge(bl, br)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 if (!visited.get(b)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 visited.set(b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
235 stack.push(b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
237 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
238 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
239 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
240 int x = current % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
241 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
242 if (x == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 emit(new Edge(tl, bl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
244 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
245 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
246 int l = current - 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 if (raster[l] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
248 emit(new Edge(tl, bl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
249 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
250 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 if (!visited.get(l)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
252 visited.set(l); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
253 stack.push(l); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
254 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
255 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
256 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
257 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
258 if (x == width - 1) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
259 emit(new Edge(br, tr)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
260 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
262 int r = current + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
263 if (raster[r] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
264 emit(new Edge(br, tr)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
266 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
267 if (!visited.get(r)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
268 visited.set(r); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
269 stack.push(r); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
270 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
271 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
272 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
273 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
274 if (stack.size() == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
275 break; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
276 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
277 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
278 current = stack.pop(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
279 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
280 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
281 handler.handleRings(rings, currentValue, width + 1); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
282 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
283 resetRegion(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
284 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
285 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
286 return regions; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
288 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
289 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |