Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java @ 448:3cb2bea50456
Generate iso line classes according gnv-issues/issue108
gnv-artifacts/trunk@496 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sun, 03 Jan 2010 12:16:55 +0000 |
parents | 92b7ccbf6163 |
children | f7038820df2e |
comparison
equal
deleted
inserted
replaced
447:92b7ccbf6163 | 448:3cb2bea50456 |
---|---|
25 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | 25 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) |
26 */ | 26 */ |
27 public class IsoPolygonSeriesProducer | 27 public class IsoPolygonSeriesProducer |
28 implements RingsHandler | 28 implements RingsHandler |
29 { | 29 { |
30 private static Logger log = Logger.getLogger( | 30 private static Logger log = Logger.getLogger( |
31 IsoPolygonSeriesProducer.class); | 31 IsoPolygonSeriesProducer.class); |
32 | 32 |
33 public static final Float LINE_WIDTH = Float.valueOf(0.1f); | 33 public static final Float LINE_WIDTH = Float.valueOf(0.1f); |
34 | 34 |
35 public interface LabelGenerator { | 35 public interface AttributeGenerator { |
36 | 36 |
37 String generateLabel(int neighbor1, int neighbor2); | 37 Object generateAttribute(int neighbor1, int neighbor2); |
38 | 38 |
39 } // interface LabelGenerator | 39 } // interface AttributeGenerator |
40 | 40 |
41 protected HashMap<Edge, Integer> open; | 41 protected HashMap<Edge, Integer> open; |
42 protected HashMap<IJKey, TIntObjectHashMap> commonOpen; | 42 protected HashMap<IJKey, TIntObjectHashMap> commonOpen; |
43 protected HashMap<IJKey, ArrayList<Edge>> complete; | 43 protected HashMap<IJKey, ArrayList<Edge>> complete; |
44 | 44 |
135 | 135 |
136 public Collection<PolygonSeries> getSeries() { | 136 public Collection<PolygonSeries> getSeries() { |
137 return getSeries(null); | 137 return getSeries(null); |
138 } | 138 } |
139 | 139 |
140 public Collection<PolygonSeries> getSeries(LabelGenerator labelGenerator) { | 140 public Collection<PolygonSeries> getSeries( |
141 | 141 AttributeGenerator attributeGenerator |
142 ) { | |
142 ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); | 143 ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); |
143 | 144 |
144 double b1 = minX; | 145 double b1 = minX; |
145 double m1 = width != 1 | 146 double m1 = width != 1 |
146 ? (maxX - minX)/(width-1) | 147 ? (maxX - minX)/(width-1) |
185 | 186 |
186 // process open | 187 // process open |
187 TIntObjectHashMap map = commonOpen.get(key); | 188 TIntObjectHashMap map = commonOpen.get(key); |
188 | 189 |
189 if (map != null) { | 190 if (map != null) { |
190 final ArrayList<Edge> headList = new ArrayList<Edge>(); | 191 final ArrayList<Edge> headList = new ArrayList<Edge>(); |
191 map.forEachValue(new TObjectProcedure() { | 192 map.forEachValue(new TObjectProcedure() { |
192 TIntHashSet headSet = new TIntHashSet(); | 193 TIntHashSet headSet = new TIntHashSet(); |
193 public boolean execute(Object value) { | 194 public boolean execute(Object value) { |
194 Edge head = ((Edge)value).head(); | 195 Edge head = ((Edge)value).head(); |
195 if (headSet.add(head.a)) { | 196 if (headSet.add(head.a)) { |
196 headList.add(head); | 197 headList.add(head); |
197 } | 198 } |
198 return true; | 199 return true; |
199 } | 200 } |
200 }); | 201 }); |
201 | 202 |
202 for (Edge head: headList) { | 203 for (Edge head: headList) { |
203 | 204 |
204 head = Vectorizer.simplify(head, width); | 205 head = Vectorizer.simplify(head, width); |
205 Edge current = head, last = head; | 206 Edge current = head, last = head; |
215 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | 216 ps.addRing(new CompactXYItems(vertices.toNativeArray())); |
216 vertices.clear(); | 217 vertices.clear(); |
217 } // for all in common open | 218 } // for all in common open |
218 } // if map defined for key | 219 } // if map defined for key |
219 | 220 |
220 int itemCount = ps.getItemCount(); | 221 if (ps.getItemCount() > 0) { |
221 | |
222 if (itemCount > 0) { | |
223 series.add(ps); | 222 series.add(ps); |
224 if (labelGenerator != null) { | 223 if (attributeGenerator != null) { |
225 ps.setAttribute( | 224 Object attribute = attributeGenerator |
226 "label", | 225 .generateAttribute(key.i, key.j); |
227 labelGenerator.generateLabel(key.i, key.j)); | 226 |
227 if (attribute != null) { | |
228 ps.setAttribute("label", attribute); | |
229 } | |
228 } | 230 } |
229 ps.setAttribute("line.width", LINE_WIDTH); | 231 ps.setAttribute("line.width", LINE_WIDTH); |
230 } | 232 } |
231 } // for all pairs | 233 } // for all pairs |
232 | 234 |
233 return series; | 235 return series; |
234 } | 236 } |
237 | |
238 public void clear() { | |
239 open.clear(); | |
240 complete.clear(); | |
241 commonOpen.clear(); | |
242 } | |
235 } | 243 } |
236 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: | 244 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |