Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.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 | 4abe172be970 |
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.PolygonSeries; | |
5 | |
6 import de.intevation.gnv.math.IJKey; | |
7 | |
8 import de.intevation.gnv.raster.Vectorizer.Edge; | |
9 | |
10 import gnu.trove.TDoubleArrayList; | |
11 import gnu.trove.TIntObjectHashMap; | |
12 | |
13 import java.util.ArrayList; | |
14 import java.util.Collection; | |
15 | |
16 import org.apache.log4j.Logger; | |
17 | |
18 /** | |
19 * Vectorizer backend to generate iso lines which are able to be visualized | |
20 * via {@link de.intevation.gnv.jfreechart.PolygonPlot} as line strings | |
21 * and custom labels on the chart. | |
22 * | |
23 * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> | |
24 */ | |
25 public class IsoPolygonSeriesProducer | |
26 extends IsoProducer | |
27 { | |
28 private static Logger log = Logger.getLogger( | |
29 IsoPolygonSeriesProducer.class); | |
30 | |
31 /** | |
32 * The line width of the line string used in the chart. | |
33 */ | |
34 public static final Float LINE_WIDTH = Float.valueOf(0.1f); | |
35 | |
36 /** | |
37 * Constructor to create an IsoPolygonSeriesProducer with a | |
38 * given world bounding box. | |
39 * @param minX Min x coord of the world. | |
40 * @param minY Min y coord of the world. | |
41 * @param maxX Max x coord of the world. | |
42 * @param maxY Max y coord of the world. | |
43 */ | |
44 public IsoPolygonSeriesProducer( | |
45 double minX, double minY, | |
46 double maxX, double maxY | |
47 ) { | |
48 super(minX, minY, maxX, maxY); | |
49 } | |
50 | |
51 /** | |
52 * Returns a collection of series with line strings | |
53 * with no AttributeGenerator. | |
54 * @return The collection with line strings. | |
55 */ | |
56 public Collection<PolygonSeries> getSeries() { | |
57 return getSeries(null); | |
58 } | |
59 | |
60 /** | |
61 * Returns a collection of series with line strings. | |
62 * The label attributes are generated with a given generator. | |
63 * @param attributeGenerator The attribute generator. Maybe null | |
64 * if no attributes should be generated. | |
65 * @return The collection with the line strings. | |
66 */ | |
67 public Collection<PolygonSeries> getSeries( | |
68 AttributeGenerator attributeGenerator | |
69 ) { | |
70 ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); | |
71 | |
72 double b1 = minX; | |
73 double m1 = width != 1 | |
74 ? (maxX - minX)/(width-1) | |
75 : 0d; | |
76 | |
77 double b2 = minY; | |
78 double m2 = height != 1 | |
79 ? (maxY - minY)/(height-1) | |
80 : 0d; | |
81 | |
82 TDoubleArrayList vertices = new TDoubleArrayList(); | |
83 | |
84 for (IJKey key: joinPairs()) { | |
85 PolygonSeries ps = new PolygonSeries(); | |
86 | |
87 // process complete | |
88 ArrayList<Edge> completeList = complete.get(key); | |
89 if (completeList != null) { | |
90 for (Edge head: completeList) { | |
91 Edge current = head; | |
92 do { | |
93 vertices.add(m1*(current.a % width) + b1); | |
94 vertices.add(m2*(current.a / width) + b2); | |
95 } | |
96 while ((current = current.next) != head); | |
97 // add head again to close shape | |
98 vertices.add(m1*(head.a % width) + b1); | |
99 vertices.add(m2*(head.a / width) + b2); | |
100 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | |
101 vertices.reset(); | |
102 } | |
103 } | |
104 | |
105 // process open | |
106 TIntObjectHashMap map = commonOpen.get(key); | |
107 | |
108 if (map != null) { | |
109 for (Edge head: headList(map)) { | |
110 | |
111 head = Vectorizer.simplify(head, width); | |
112 Edge current = head, last = head; | |
113 do { | |
114 vertices.add(m1*(current.a % width) + b1); | |
115 vertices.add(m2*(current.a / width) + b2); | |
116 last = current; | |
117 } | |
118 while ((current = current.next) != null); | |
119 // add b from tail | |
120 vertices.add(m1*(last.b % width) + b1); | |
121 vertices.add(m2*(last.b / width) + b2); | |
122 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | |
123 vertices.reset(); | |
124 } // for all in common open | |
125 } // if map defined for key | |
126 | |
127 if (ps.getItemCount() > 0) { | |
128 series.add(ps); | |
129 if (attributeGenerator != null) { | |
130 Object attribute = attributeGenerator | |
131 .generateAttribute(key.i, key.j); | |
132 | |
133 if (attribute != null) { | |
134 ps.setAttribute("label", attribute); | |
135 } | |
136 } | |
137 ps.setAttribute("line.width", LINE_WIDTH); | |
138 } | |
139 } // for all pairs | |
140 | |
141 return series; | |
142 } | |
143 } | |
144 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : |