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