Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java @ 657:af3f56758f59
merged gnv-artifacts/0.5
author | Thomas Arendsen Hein <thomas@intevation.de> |
---|---|
date | Fri, 28 Sep 2012 12:13:53 +0200 |
parents | 1bf058f1a2d1 |
children | b1f5f2a8840f |
comparison
equal
deleted
inserted
replaced
590:5f5f273c8566 | 657:af3f56758f59 |
---|---|
1 package de.intevation.gnv.raster; | |
2 | |
3 import java.util.ArrayList; | |
4 import java.util.Collection; | |
5 | |
6 import org.apache.log4j.Logger; | |
7 | |
8 import gnu.trove.TIntObjectHashMap; | |
9 import gnu.trove.TDoubleArrayList; | |
10 | |
11 import de.intevation.gnv.raster.Vectorizer.Edge; | |
12 | |
13 import de.intevation.gnv.math.IJKey; | |
14 | |
15 import de.intevation.gnv.jfreechart.PolygonSeries; | |
16 import de.intevation.gnv.jfreechart.CompactXYItems; | |
17 | |
18 /** | |
19 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) | |
20 */ | |
21 public class IsoPolygonSeriesProducer | |
22 extends IsoProducer | |
23 { | |
24 private static Logger log = Logger.getLogger( | |
25 IsoPolygonSeriesProducer.class); | |
26 | |
27 public static final Float LINE_WIDTH = Float.valueOf(0.1f); | |
28 | |
29 public IsoPolygonSeriesProducer( | |
30 double minX, double minY, | |
31 double maxX, double maxY | |
32 ) { | |
33 super(minX, minY, maxX, maxY); | |
34 } | |
35 | |
36 public Collection<PolygonSeries> getSeries() { | |
37 return getSeries(null); | |
38 } | |
39 | |
40 public Collection<PolygonSeries> getSeries( | |
41 AttributeGenerator attributeGenerator | |
42 ) { | |
43 ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); | |
44 | |
45 double b1 = minX; | |
46 double m1 = width != 1 | |
47 ? (maxX - minX)/(width-1) | |
48 : 0d; | |
49 | |
50 double b2 = minY; | |
51 double m2 = height != 1 | |
52 ? (maxY - minY)/(height-1) | |
53 : 0d; | |
54 | |
55 TDoubleArrayList vertices = new TDoubleArrayList(); | |
56 | |
57 for (IJKey key: joinPairs()) { | |
58 PolygonSeries ps = new PolygonSeries(); | |
59 | |
60 // process complete | |
61 ArrayList<Edge> completeList = complete.get(key); | |
62 if (completeList != null) { | |
63 for (Edge head: completeList) { | |
64 Edge current = head; | |
65 do { | |
66 vertices.add(m1*(current.a % width) + b1); | |
67 vertices.add(m2*(current.a / width) + b2); | |
68 } | |
69 while ((current = current.next) != head); | |
70 // add head again to close shape | |
71 vertices.add(m1*(head.a % width) + b1); | |
72 vertices.add(m2*(head.a / width) + b2); | |
73 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | |
74 vertices.reset(); | |
75 } | |
76 } | |
77 | |
78 // process open | |
79 TIntObjectHashMap map = commonOpen.get(key); | |
80 | |
81 if (map != null) { | |
82 for (Edge head: headList(map)) { | |
83 | |
84 head = Vectorizer.simplify(head, width); | |
85 Edge current = head, last = head; | |
86 do { | |
87 vertices.add(m1*(current.a % width) + b1); | |
88 vertices.add(m2*(current.a / width) + b2); | |
89 last = current; | |
90 } | |
91 while ((current = current.next) != null); | |
92 // add b from tail | |
93 vertices.add(m1*(last.b % width) + b1); | |
94 vertices.add(m2*(last.b / width) + b2); | |
95 ps.addRing(new CompactXYItems(vertices.toNativeArray())); | |
96 vertices.reset(); | |
97 } // for all in common open | |
98 } // if map defined for key | |
99 | |
100 if (ps.getItemCount() > 0) { | |
101 series.add(ps); | |
102 if (attributeGenerator != null) { | |
103 Object attribute = attributeGenerator | |
104 .generateAttribute(key.i, key.j); | |
105 | |
106 if (attribute != null) { | |
107 ps.setAttribute("label", attribute); | |
108 } | |
109 } | |
110 ps.setAttribute("line.width", LINE_WIDTH); | |
111 } | |
112 } // for all pairs | |
113 | |
114 return series; | |
115 } | |
116 } | |
117 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: |