Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/PolygonDatasetProducer.java @ 875:5e9efdda6894
merged gnv-artifacts/1.0
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:56 +0200 |
parents | feae2f9d6c6f |
children | f953c9a559d8 |
comparison
equal
deleted
inserted
replaced
722:bb3ffe7d719e | 875:5e9efdda6894 |
---|---|
1 package de.intevation.gnv.raster; | |
2 | |
3 import de.intevation.gnv.jfreechart.CompactXYItems; | |
4 import de.intevation.gnv.jfreechart.PolygonDataset; | |
5 import de.intevation.gnv.jfreechart.PolygonSeries; | |
6 | |
7 import de.intevation.gnv.raster.Vectorizer.Edge; | |
8 | |
9 import gnu.trove.TDoubleArrayList; | |
10 | |
11 import java.util.HashMap; | |
12 import java.util.List; | |
13 | |
14 /** | |
15 * Vectorizer backend to produce polygon datasets suitable to being | |
16 * displayed with {@link de.intevation.gnv.jfreechart.PolygonPlot}. | |
17 * | |
18 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
19 */ | |
20 public class PolygonDatasetProducer | |
21 extends AbstractProducer | |
22 { | |
23 /** | |
24 * Maps value integers to series of polygons to group | |
25 * them by value. | |
26 */ | |
27 protected HashMap<Integer, PolygonSeries> polygonSeries; | |
28 | |
29 /** | |
30 * Default constructor. | |
31 */ | |
32 protected PolygonDatasetProducer() { | |
33 } | |
34 | |
35 /** | |
36 * Constructor to create a PolygonDatasetProducer with | |
37 * a given world bound box. | |
38 * @param minX Min x coord of the world. | |
39 * @param minY Min y coord of the world. | |
40 * @param maxX Max x coord of the world. | |
41 * @param maxY Max y coord of the world. | |
42 */ | |
43 public PolygonDatasetProducer( | |
44 double minX, double minY, | |
45 double maxX, double maxY | |
46 | |
47 ) { | |
48 super(minX, minY, maxX, maxY); | |
49 polygonSeries = new HashMap<Integer, PolygonSeries>(); | |
50 } | |
51 | |
52 public void handleRings( | |
53 List<Edge> rings, | |
54 int value, | |
55 int width, | |
56 int height | |
57 ) { | |
58 if (value == -1) { | |
59 return; | |
60 } | |
61 | |
62 Integer v = Integer.valueOf(value); | |
63 | |
64 PolygonSeries ps = polygonSeries.get(v); | |
65 | |
66 if (ps == null) { | |
67 polygonSeries.put(v, ps = new PolygonSeries()); | |
68 ps.setAttribute("fill", v); | |
69 } | |
70 | |
71 TDoubleArrayList vertices = new TDoubleArrayList(); | |
72 | |
73 /* minX = 0*m1 + b1 <=> b1 = minX | |
74 * maxX = (width-1)*m1 + b1 | |
75 * m1 = (maxX - minX)/(width-1) | |
76 */ | |
77 | |
78 double b1 = minX; | |
79 double m1 = width != 1 | |
80 ? (maxX - minX)/(width-1) | |
81 : 0d; | |
82 | |
83 double b2 = minY; | |
84 double m2 = height != 1 | |
85 ? (maxY - minY)/(height-1) | |
86 : 0d; | |
87 | |
88 for (Edge head: rings) { | |
89 Edge current = head; | |
90 do { | |
91 vertices.add(m1*(current.a % width) + b1); | |
92 vertices.add(m2*(current.a / width) + b2); | |
93 } | |
94 while ((current = current.next) != head); | |
95 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | |
96 vertices.reset(); | |
97 } | |
98 } | |
99 | |
100 /** | |
101 * Creates a new PolygonDataset from the polygons build by this | |
102 * backend. | |
103 * @return the new PolygonDataset | |
104 */ | |
105 public PolygonDataset getPolygonDataset() { | |
106 return new PolygonDataset(polygonSeries.values()); | |
107 } | |
108 } | |
109 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |