comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/PolygonDatasetProducer.java @ 540:80630520e25a

merged gnv-artifacts/0.4
author Thomas Arendsen Hein <thomas@intevation.de>
date Fri, 28 Sep 2012 12:13:49 +0200
parents 1bf058f1a2d1
children 9a828e5a2390
comparison
equal deleted inserted replaced
415:9f4a0b990d27 540:80630520e25a
1 package de.intevation.gnv.raster;
2
3 import java.util.List;
4 import java.util.HashMap;
5
6 import gnu.trove.TDoubleArrayList;
7
8 import de.intevation.gnv.raster.Vectorizer.Edge;
9
10 import de.intevation.gnv.jfreechart.PolygonSeries;
11 import de.intevation.gnv.jfreechart.PolygonDataset;
12 import de.intevation.gnv.jfreechart.CompactXYItems;
13
14 /**
15 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
16 */
17 public class PolygonDatasetProducer
18 extends AbstractProducer
19 {
20 protected HashMap<Integer, PolygonSeries> polygonSeries;
21
22 protected PolygonDatasetProducer() {
23 }
24
25 public PolygonDatasetProducer(
26 double minX, double minY,
27 double maxX, double maxY
28
29 ) {
30 super(minX, minY, maxX, maxY);
31 polygonSeries = new HashMap<Integer, PolygonSeries>();
32 }
33
34 public void handleRings(
35 List<Edge> rings,
36 int value,
37 int width,
38 int height
39 ) {
40 if (value == -1) {
41 return;
42 }
43
44 Integer v = Integer.valueOf(value);
45
46 PolygonSeries ps = polygonSeries.get(v);
47
48 if (ps == null) {
49 polygonSeries.put(v, ps = new PolygonSeries());
50 ps.setAttribute("fill", v);
51 }
52
53 TDoubleArrayList vertices = new TDoubleArrayList();
54
55 /* minX = 0*m1 + b1 <=> b1 = minX
56 * maxX = (width-1)*m1 + b1
57 * m1 = (maxX - minX)/(width-1)
58 */
59
60 double b1 = minX;
61 double m1 = width != 1
62 ? (maxX - minX)/(width-1)
63 : 0d;
64
65 double b2 = minY;
66 double m2 = height != 1
67 ? (maxY - minY)/(height-1)
68 : 0d;
69
70 for (Edge head: rings) {
71 Edge current = head;
72 do {
73 vertices.add(m1*(current.a % width) + b1);
74 vertices.add(m2*(current.a / width) + b2);
75 }
76 while ((current = current.next) != head);
77 ps.addRing(new CompactXYItems(vertices.toNativeArray()));
78 vertices.reset();
79 }
80 }
81
82 public PolygonDataset getPolygonDataset() {
83 return new PolygonDataset(polygonSeries.values());
84 }
85 }
86 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8:

http://dive4elements.wald.intevation.org