Mercurial > dive4elements > gnv-client
annotate gnv-artifacts/src/main/java/de/intevation/gnv/raster/Vectorizer.java @ 808:2e951160c43d
Finished the javadoc of the math package.
gnv-artifacts/trunk@890 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Thu, 08 Apr 2010 16:35:02 +0000 |
parents | d766fe2d917a |
children | f953c9a559d8 |
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 |
779
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
3 import gnu.trove.TIntObjectHashMap; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
4 import gnu.trove.TIntStack; |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
5 |
b1f5f2a8840f
Ordered imports. Removed needless imports. Removed empty headers.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
778
diff
changeset
|
6 import java.util.ArrayList; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
7 import java.util.BitSet; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
8 import java.util.List; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
9 |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
10 import org.apache.log4j.Logger; |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
11 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
12 /** |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
13 * Instances of this class are able to vectorize 2D integer arrays |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
14 * with a kind of flood filling regions detection mechanism to |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
15 * a set of line strings and polygons. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
16 * |
780
c4156275c1e1
Bring @author javadoc tags in form '@author <a href="john.doe@example.com">John Doe</a>'
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
779
diff
changeset
|
17 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> |
424
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 public class Vectorizer |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
20 { |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
21 private static Logger log = Logger.getLogger(Vectorizer.class); |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
22 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
23 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
24 * Callback to process the found line strings and polygons. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
25 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
26 public interface RingsHandler { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
27 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
28 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
29 * Called from {@link #process(de.intevation.gnv.raster.Vectorizer.RingsHandler) } |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
30 * to give the found features to the postprocessing backend. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
31 * @param rings The found line strings and polygons. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
32 * @param value The integer value of the raster surrounded by |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
33 * the features. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
34 * @param width The width of the index space of the vectorized data. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
35 * @param height The height of the index space of the vectorized data. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
36 */ |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
37 void handleRings( |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
38 List<Edge> rings, |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
39 int value, |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
40 int width, |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
41 int height); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
42 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
43 } // interface RingsHandler |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
44 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
45 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
46 * Doubly link list representing a line string or a polygon. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
47 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
48 public static final class Edge { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
49 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
50 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
51 * The predecessor. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
52 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
53 public Edge prev; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
54 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
55 * The successor. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
56 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
57 public Edge next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
58 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
59 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
60 * Index of first vertex. To separate x and y values |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
61 * you have to divide the value by the width of the |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
62 * index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
63 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
64 public int a; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
65 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
66 * Index of second vertex. To separate x and y values |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
67 * you have to divide the value by the width of the |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
68 * index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
69 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
70 public int b; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
71 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
72 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
73 * Default constructor. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
74 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
75 public Edge() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
76 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
77 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
78 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
79 * Constructor to create Edge with two vertices. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
80 * @param a The first vertex. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
81 * @param b The second vertex. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
82 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
83 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
|
84 this.a = a; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
85 this.b = b; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
86 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
87 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
88 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
89 * Copy constructor |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
90 * @param other The edge to clone. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
91 */ |
437
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
92 public Edge(Edge other) { |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
93 a = other.a; |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
94 b = other.b; |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
95 } |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
96 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
97 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
98 * Chain a given edge segment to this segment. The |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
99 * side of the chaining is determined by a given |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
100 * parameter. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
101 * @param other The segment to chain. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
102 * @param found The side to chain. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
103 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
104 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
|
105 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
106 if (found == a) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
107 other.next = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
108 prev = other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
109 return; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
110 } |
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 if (found == b) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
113 next = other; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
114 other.prev = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
115 return; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
116 } |
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 throw new IllegalStateException("cannot chain"); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
119 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
120 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
121 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
122 * Tells if the list is complete which means that this |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
123 * edge list is a closed polygon. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
124 * @return true if edge list is closed else false. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
125 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
126 public boolean isComplete() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
127 Edge current = this; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
128 do { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
129 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
|
130 return false; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
131 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
132 current = current.next; |
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 while (current != this); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
135 return true; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
136 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
137 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
138 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
139 * Returns the length of this edge list in next direction. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
140 * Segments in prev direction are ignored. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
141 * @return The length of this edge list. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
142 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
143 public int length() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
144 int length = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
145 Edge current = this; |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
146 do { ++length; } |
437
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
147 while ((current = current.next) != null && current != this); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
148 return length; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
149 } |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
150 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
151 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
152 * Returns the head node of this edge list. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
153 * @return The head node. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
154 */ |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
155 public Edge head() { |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
156 Edge current = this; |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
157 while (current.prev != null) { |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
158 current = current.prev; |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
159 } |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
160 return current; |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
161 } |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
162 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
163 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
164 * Hashes the two vertex indices to a common value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
165 * @return The hash value. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
166 */ |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
167 @Override |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
168 public int hashCode() { |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
169 return (a << 16) | b; |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
170 } |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
171 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
172 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
173 * Two edges are considered equal if they have the same |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
174 * a and b vertices. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
175 * @param other The other edge. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
176 * @return true if the edges are equal else false. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
177 */ |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
178 @Override |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
179 public boolean equals(Object other) { |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
180 Edge e = (Edge)other; |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
181 return a == e.a && b == e.b; |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
182 } |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
183 } // class Edge |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
184 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
185 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
186 * Simplifies a given edge list by removing collinear vertices. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
187 * Attention: The original list is modified. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
188 * @param edge The edge list to simplify. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
189 * @param width The width of the vertex index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
190 * @return The simplified list. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
191 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
192 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
|
193 |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
194 Edge e1 = edge, start = edge; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
195 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
196 int length = edge.length(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
197 |
437
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
198 if (length < 2) { |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
199 return e1; |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
200 } |
b624879d2902
Added vectorizer rings callback to generate iso lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
436
diff
changeset
|
201 |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
202 Edge e2 = edge.next; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
203 |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
204 int count = 0; |
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 do { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
207 int e1x = e1.a % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
208 int e1y = e1.a / width; |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
209 int e2x = e1.b % width; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
210 int e2y = e1.b / width; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
211 int e3x = e2.b % width; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
212 int e3y = e2.b / width; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
213 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
214 if ((e1x == e2x && e2x == e3x && e1x == e3x) |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
215 || (e1y == e2y && e2y == e3y && e1y == e3y)) { |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
216 e1.b = e2.b; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
217 Edge removed = e1.next; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
218 e1.next = e2.next; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
219 if (e1.next != null) { |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
220 e1.next.prev = e1; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
221 } |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
222 e2 = e1.next; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
223 count = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
224 --length; |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
225 if (removed == start) { |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
226 start = e1; |
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
227 } |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
228 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
229 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
230 e1 = e1.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
231 e2 = e2.next; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
232 ++count; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
233 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
234 } |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
235 while (length > 1 && e2 != null && count < length + 2); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
236 |
447
92b7ccbf6163
Improved generation of iso lines in vertical cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
445
diff
changeset
|
237 return start; |
424
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 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
240 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
241 * The raster to be traced. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
242 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
243 protected int [] raster; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
244 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
245 * The width of the raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
246 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
247 protected int width; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
248 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
249 * Map of the currently open edges. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
250 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
251 protected TIntObjectHashMap openEdges; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
252 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
253 * List of rings already found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
254 */ |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
255 protected List<Edge> rings; |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
256 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
257 * Flag to signal if a simplification should be performed |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
258 * after a ring is completed. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
259 */ |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
260 protected boolean simplify; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
261 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
262 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
263 * Default constructor. Simplification is turned on. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
264 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
265 public Vectorizer() { |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
266 this(true); |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
267 } |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
268 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
269 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
270 * Constructor to create a vectorized with an explicit |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
271 * simplification policy. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
272 * @param simplify Indicates if simplification should be |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
273 * used on ring completion. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
274 */ |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
275 public Vectorizer(boolean simplify) { |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
276 openEdges = new TIntObjectHashMap(); |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
277 rings = new ArrayList<Edge>(); |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
278 this.simplify = simplify; |
424
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 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
281 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
282 * Constructor to create a vectorizer with a given raster and width. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
283 * Simplification is turn on. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
284 * @param raster The raster to be vectorized. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
285 * @param width The width of the raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
286 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
287 public Vectorizer(int [] raster, int width) { |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
288 this(true, raster, width); |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
289 } |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
290 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
291 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
292 * Constructor to create a vectorizer with a given raster, width |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
293 * and an explicit simplification policy. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
294 * @param simplify Indicates if simplification should be |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
295 * used on ring completion. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
296 * @param raster The raster to be vectorized. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
297 * @param width The width of the raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
298 */ |
445
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
299 public Vectorizer(boolean simplify, int [] raster, int width) { |
f42ed4f10b79
Fixed some bugs and create "Profilschnitt" polygons via configuration.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
437
diff
changeset
|
300 this(simplify); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
301 this.raster = raster; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
302 this.width = width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
303 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
304 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
305 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
306 * Returns (x, y+1) for given vertex in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
307 * @param i vertex in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
308 * @param w width of raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
309 * @return (x, y+1) in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
310 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
311 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
|
312 int x = i % w; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
313 int y = i / w; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
314 return x + (w + 1)*y; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
315 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
316 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
317 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
318 * Returns tl(i, w) + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
319 * @param i vertex in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
320 * @param w width of raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
321 * @return tl(i, w) + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
322 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
323 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
|
324 return tl(i, w) + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
325 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
326 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
327 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
328 * Returns tl(i, w) + w + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
329 * @param i vertex in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
330 * @param w width of raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
331 * @return tl(i, w) + w + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
332 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
333 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
|
334 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
|
335 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
336 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
337 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
338 * Returns bl(i, w) + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
339 * @param i vertex in index space. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
340 * @param w width of raster. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
341 * @return bl(i, w) + 1. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
342 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
343 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
|
344 return bl(i, w) + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
345 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
346 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
347 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
348 * Resets open resources after a set of features were found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
349 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
350 protected void resetRegion() { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
351 openEdges.clear(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
352 rings.clear(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
353 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
354 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
355 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
356 * Adds an edge to the map of open edges, joins it |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
357 * with its direct neighbors of if complete add the |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
358 * list to the complete features. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
359 * @param edge |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
360 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
361 protected void emit(Edge edge) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
362 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
363 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
|
364 if (otherA != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
365 otherA.chain(edge, edge.a); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
366 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
367 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
368 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
|
369 if (otherB != null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
370 otherB.chain(edge, edge.b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
371 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
372 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
373 if (edge.isComplete()) { |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
374 rings.add(simplify ? simplify(edge, width + 1) : edge); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
375 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
376 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
377 if (otherA == null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
378 openEdges.put(edge.a, edge); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
379 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
380 if (otherB == null) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
381 openEdges.put(edge.b, edge); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
382 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
383 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
384 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
385 |
801
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
386 /** |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
387 * Vectorize the raster. The found features are fed into |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
388 * the given ring handler. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
389 * @param handler The RingHandler to postprocess the found features. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
390 * @return The number of regions found. |
d766fe2d917a
More javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
798
diff
changeset
|
391 */ |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
392 public int process(RingsHandler handler) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
393 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
394 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
|
395 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
396 TIntStack stack = new TIntStack(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
397 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
398 int regions = 0; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
399 |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
400 int height = raster.length / width; |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
401 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
402 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
|
403 if (visited.get(i)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
404 continue; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
405 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
406 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
407 ++regions; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
408 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
409 int currentValue = raster[i]; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
410 visited.set(i); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
411 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
412 int current = i; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
413 visited.set(current); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
414 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
415 for (;;) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
416 int tl = tl(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
417 int tr = tr(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
418 int bl = bl(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
419 int br = br(current, width); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
420 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
421 int t = current - width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
422 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
423 if (t < 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
424 emit(new Edge(tr, tl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
425 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
426 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
427 if (raster[t] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
428 emit(new Edge(tr, tl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
429 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
430 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
431 if (!visited.get(t)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
432 visited.set(t); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
433 stack.push(t); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
434 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
435 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
436 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
437 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
438 int b = current + width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
439 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
440 if (b >= raster.length) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
441 emit(new Edge(bl, br)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
442 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
443 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
444 if (raster[b] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
445 emit(new Edge(bl, br)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
446 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
447 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
448 if (!visited.get(b)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
449 visited.set(b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
450 stack.push(b); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
451 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
452 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
453 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
454 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
455 int x = current % width; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
456 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
457 if (x == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
458 emit(new Edge(tl, bl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
459 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
460 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
461 int l = current - 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
462 if (raster[l] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
463 emit(new Edge(tl, bl)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
464 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
465 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
466 if (!visited.get(l)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
467 visited.set(l); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
468 stack.push(l); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
469 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
470 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
471 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
472 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
473 if (x == width - 1) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
474 emit(new Edge(br, tr)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
475 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
476 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
477 int r = current + 1; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
478 if (raster[r] != currentValue) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
479 emit(new Edge(br, tr)); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
480 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
481 else { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
482 if (!visited.get(r)) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
483 visited.set(r); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
484 stack.push(r); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
485 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
486 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
487 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
488 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
489 if (stack.size() == 0) { |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
490 break; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
491 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
492 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
493 current = stack.pop(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
494 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
495 |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
496 handler.handleRings( |
778
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
497 rings, |
9a828e5a2390
Removed trailing whitespace
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
447
diff
changeset
|
498 currentValue, |
436
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
499 width + 1, |
6642ab6c583c
Added vectorizer rings callback which generates polygon datasets suitable
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
424
diff
changeset
|
500 height + 1); |
424
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
501 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
502 resetRegion(); |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
503 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
504 |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
505 return regions; |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
506 } |
21fbd254db71
Added support for converting 2D rasters into polygons.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff
changeset
|
507 } |
798
6cff63d0c434
Fixed vim modeline. Added some Javadoc.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
780
diff
changeset
|
508 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |