sascha@436: package de.intevation.gnv.raster; sascha@436: sascha@436: import java.util.List; sascha@436: import java.util.HashMap; sascha@436: sascha@436: import gnu.trove.TDoubleArrayList; sascha@436: sascha@436: import de.intevation.gnv.raster.Vectorizer.Edge; sascha@436: sascha@436: import de.intevation.gnv.jfreechart.PolygonSeries; sascha@436: import de.intevation.gnv.jfreechart.PolygonDataset; sascha@436: import de.intevation.gnv.jfreechart.CompactXYItems; sascha@436: sascha@437: /** sascha@437: * @author Sascha L. Teichmann (sascha.teichmann@intevation.de) sascha@437: */ sascha@436: public class PolygonDatasetProducer sascha@465: extends AbstractProducer sascha@436: { sascha@436: protected HashMap polygonSeries; sascha@436: sascha@436: protected PolygonDatasetProducer() { sascha@436: } sascha@436: sascha@436: public PolygonDatasetProducer( sascha@436: double minX, double minY, sascha@436: double maxX, double maxY sascha@436: sascha@436: ) { sascha@465: super(minX, minY, maxX, maxY); sascha@436: polygonSeries = new HashMap(); sascha@436: } sascha@436: sascha@436: public void handleRings( sascha@436: List rings, sascha@436: int value, sascha@436: int width, sascha@436: int height sascha@436: ) { sascha@436: if (value == -1) { sascha@436: return; sascha@436: } sascha@436: sascha@436: Integer v = Integer.valueOf(value); sascha@436: sascha@465: PolygonSeries ps = polygonSeries.get(v); sascha@436: sascha@436: if (ps == null) { sascha@436: polygonSeries.put(v, ps = new PolygonSeries()); sascha@436: ps.setAttribute("fill", v); sascha@436: } sascha@436: sascha@436: TDoubleArrayList vertices = new TDoubleArrayList(); sascha@436: sascha@436: /* minX = 0*m1 + b1 <=> b1 = minX sascha@436: * maxX = (width-1)*m1 + b1 sascha@436: * m1 = (maxX - minX)/(width-1) sascha@436: */ sascha@436: sascha@437: double b1 = minX; sascha@437: double m1 = width != 1 sascha@437: ? (maxX - minX)/(width-1) sascha@437: : 0d; sascha@436: sascha@437: double b2 = minY; sascha@437: double m2 = height != 1 sascha@437: ? (maxY - minY)/(height-1) sascha@437: : 0d; sascha@436: sascha@436: for (Edge head: rings) { sascha@436: Edge current = head; sascha@436: do { sascha@437: vertices.add(m1*(current.a % width) + b1); sascha@437: vertices.add(m2*(current.a / width) + b2); sascha@436: } sascha@437: while ((current = current.next) != head); sascha@436: ps.addRing(new CompactXYItems(vertices.toNativeArray())); sascha@436: vertices.clear(); sascha@436: } sascha@436: } sascha@436: sascha@436: public PolygonDataset getPolygonDataset() { sascha@436: return new PolygonDataset(polygonSeries.values()); sascha@436: } sascha@436: } sascha@436: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: