sascha@437: package de.intevation.gnv.raster;
sascha@437:
sascha@779: import de.intevation.gnv.jfreechart.CompactXYItems;
sascha@779: import de.intevation.gnv.jfreechart.PolygonSeries;
sascha@779:
sascha@779: import de.intevation.gnv.math.IJKey;
sascha@779:
sascha@779: import de.intevation.gnv.raster.Vectorizer.Edge;
sascha@779:
sascha@779: import gnu.trove.TDoubleArrayList;
sascha@779: import gnu.trove.TIntObjectHashMap;
sascha@779:
sascha@437: import java.util.ArrayList;
sascha@437: import java.util.Collection;
sascha@437:
sascha@447: import org.apache.log4j.Logger;
sascha@447:
sascha@437: /**
sascha@780: * @author Sascha L. Teichmann
sascha@437: */
sascha@437: public class IsoPolygonSeriesProducer
sascha@465: extends IsoProducer
sascha@437: {
sascha@448: private static Logger log = Logger.getLogger(
sascha@448: IsoPolygonSeriesProducer.class);
sascha@447:
sascha@447: public static final Float LINE_WIDTH = Float.valueOf(0.1f);
sascha@447:
sascha@437: public IsoPolygonSeriesProducer(
sascha@437: double minX, double minY,
sascha@437: double maxX, double maxY
sascha@437: ) {
sascha@465: super(minX, minY, maxX, maxY);
sascha@437: }
sascha@437:
sascha@437: public Collection getSeries() {
sascha@437: return getSeries(null);
sascha@437: }
sascha@437:
sascha@448: public Collection getSeries(
sascha@448: AttributeGenerator attributeGenerator
sascha@448: ) {
sascha@437: ArrayList series = new ArrayList();
sascha@447:
sascha@437: double b1 = minX;
sascha@437: double m1 = width != 1
sascha@437: ? (maxX - minX)/(width-1)
sascha@437: : 0d;
sascha@437:
sascha@437: double b2 = minY;
sascha@437: double m2 = height != 1
sascha@437: ? (maxY - minY)/(height-1)
sascha@437: : 0d;
sascha@437:
sascha@437: TDoubleArrayList vertices = new TDoubleArrayList();
sascha@437:
sascha@465: for (IJKey key: joinPairs()) {
sascha@437: PolygonSeries ps = new PolygonSeries();
sascha@437:
sascha@437: // process complete
sascha@437: ArrayList completeList = complete.get(key);
sascha@437: if (completeList != null) {
sascha@437: for (Edge head: completeList) {
sascha@437: Edge current = head;
sascha@437: do {
sascha@437: vertices.add(m1*(current.a % width) + b1);
sascha@437: vertices.add(m2*(current.a / width) + b2);
sascha@437: }
sascha@437: while ((current = current.next) != head);
sascha@447: // add head again to close shape
sascha@447: vertices.add(m1*(head.a % width) + b1);
sascha@447: vertices.add(m2*(head.a / width) + b2);
sascha@437: ps.addRing(new CompactXYItems(vertices.toNativeArray()));
sascha@521: vertices.reset();
sascha@437: }
sascha@437: }
sascha@437:
sascha@437: // process open
sascha@437: TIntObjectHashMap map = commonOpen.get(key);
sascha@447:
sascha@437: if (map != null) {
sascha@465: for (Edge head: headList(map)) {
sascha@447:
sascha@437: head = Vectorizer.simplify(head, width);
sascha@437: Edge current = head, last = head;
sascha@437: do {
sascha@437: vertices.add(m1*(current.a % width) + b1);
sascha@437: vertices.add(m2*(current.a / width) + b2);
sascha@437: last = current;
sascha@437: }
sascha@437: while ((current = current.next) != null);
sascha@437: // add b from tail
sascha@437: vertices.add(m1*(last.b % width) + b1);
sascha@437: vertices.add(m2*(last.b / width) + b2);
sascha@437: ps.addRing(new CompactXYItems(vertices.toNativeArray()));
sascha@521: vertices.reset();
sascha@437: } // for all in common open
sascha@437: } // if map defined for key
sascha@447:
sascha@448: if (ps.getItemCount() > 0) {
sascha@447: series.add(ps);
sascha@448: if (attributeGenerator != null) {
sascha@448: Object attribute = attributeGenerator
sascha@448: .generateAttribute(key.i, key.j);
sascha@448:
sascha@448: if (attribute != null) {
sascha@448: ps.setAttribute("label", attribute);
sascha@448: }
sascha@447: }
sascha@447: ps.setAttribute("line.width", LINE_WIDTH);
sascha@447: }
sascha@437: } // for all pairs
sascha@437:
sascha@437: return series;
sascha@437: }
sascha@437: }
sascha@437: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8: