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