Mercurial > dive4elements > gnv-client
diff 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 |
line wrap: on
line diff
--- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoPolygonSeriesProducer.java Fri Sep 28 12:14:00 2012 +0200 @@ -0,0 +1,152 @@ +/* + * Copyright (c) 2010 by Intevation GmbH + * + * This program is free software under the LGPL (>=v2.1) + * Read the file LGPL.txt coming with the software for details + * or visit http://www.gnu.org/licenses/ if it does not exist. + */ + +package de.intevation.gnv.raster; + +import de.intevation.gnv.jfreechart.CompactXYItems; +import de.intevation.gnv.jfreechart.PolygonSeries; + +import de.intevation.gnv.math.IJKey; + +import de.intevation.gnv.raster.Vectorizer.Edge; + +import gnu.trove.TDoubleArrayList; +import gnu.trove.TIntObjectHashMap; + +import java.util.ArrayList; +import java.util.Collection; + +import org.apache.log4j.Logger; + +/** + * Vectorizer backend to generate iso lines which are able to be visualized + * via {@link de.intevation.gnv.jfreechart.PolygonPlot} as line strings + * and custom labels on the chart. + * + * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> + */ +public class IsoPolygonSeriesProducer +extends IsoProducer +{ + private static Logger log = Logger.getLogger( + IsoPolygonSeriesProducer.class); + + /** + * The line width of the line string used in the chart. + */ + public static final Float LINE_WIDTH = Float.valueOf(0.1f); + + /** + * Constructor to create an IsoPolygonSeriesProducer with a + * given world bounding box. + * @param minX Min x coord of the world. + * @param minY Min y coord of the world. + * @param maxX Max x coord of the world. + * @param maxY Max y coord of the world. + */ + public IsoPolygonSeriesProducer( + double minX, double minY, + double maxX, double maxY + ) { + super(minX, minY, maxX, maxY); + } + + /** + * Returns a collection of series with line strings + * with no AttributeGenerator. + * @return The collection with line strings. + */ + public Collection<PolygonSeries> getSeries() { + return getSeries(null); + } + + /** + * Returns a collection of series with line strings. + * The label attributes are generated with a given generator. + * @param attributeGenerator The attribute generator. Maybe null + * if no attributes should be generated. + * @return The collection with the line strings. + */ + public Collection<PolygonSeries> getSeries( + AttributeGenerator attributeGenerator + ) { + ArrayList<PolygonSeries> series = new ArrayList<PolygonSeries>(); + + double b1 = minX; + double m1 = width != 1 + ? (maxX - minX)/(width-1) + : 0d; + + double b2 = minY; + double m2 = height != 1 + ? (maxY - minY)/(height-1) + : 0d; + + TDoubleArrayList vertices = new TDoubleArrayList(); + + for (IJKey key: joinPairs()) { + PolygonSeries ps = new PolygonSeries(); + + // process complete + ArrayList<Edge> completeList = complete.get(key); + if (completeList != null) { + for (Edge head: completeList) { + Edge current = head; + do { + vertices.add(m1*(current.a % width) + b1); + vertices.add(m2*(current.a / width) + b2); + } + while ((current = current.next) != head); + // add head again to close shape + vertices.add(m1*(head.a % width) + b1); + vertices.add(m2*(head.a / width) + b2); + ps.addRing(new CompactXYItems(vertices.toNativeArray())); + vertices.reset(); + } + } + + // process open + TIntObjectHashMap map = commonOpen.get(key); + + if (map != null) { + for (Edge head: headList(map)) { + + head = Vectorizer.simplify(head, width); + Edge current = head, last = head; + do { + vertices.add(m1*(current.a % width) + b1); + vertices.add(m2*(current.a / width) + b2); + last = current; + } + while ((current = current.next) != null); + // add b from tail + vertices.add(m1*(last.b % width) + b1); + vertices.add(m2*(last.b / width) + b2); + ps.addRing(new CompactXYItems(vertices.toNativeArray())); + vertices.reset(); + } // for all in common open + } // if map defined for key + + if (ps.getItemCount() > 0) { + series.add(ps); + if (attributeGenerator != null) { + Object attribute = attributeGenerator + .generateAttribute(key.i, key.j); + + if (attribute != null) { + ps.setAttribute("label", attribute); + } + } + ps.setAttribute("line.width", LINE_WIDTH); + } + } // for all pairs + + return series; + } +} +// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :