Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/raster/IsoProducer.java @ 788:e8a9e84a0328
Corrected JavaDoc errors in Chart Package.
gnv-artifacts/trunk@870 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Wed, 31 Mar 2010 08:01:56 +0000 |
parents | c4156275c1e1 |
children | d766fe2d917a |
line wrap: on
line source
package de.intevation.gnv.raster; import de.intevation.gnv.math.IJKey; import de.intevation.gnv.raster.Vectorizer.Edge; import gnu.trove.TIntHashSet; import gnu.trove.TIntObjectHashMap; import gnu.trove.TObjectProcedure; import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.List; /** * @author <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ public class IsoProducer extends AbstractProducer { public interface AttributeGenerator { Object generateAttribute(int neighbor1, int neighbor2); } // interface AttributeGenerator protected HashMap<Edge, Integer> open; protected HashMap<IJKey, TIntObjectHashMap> commonOpen; protected HashMap<IJKey, ArrayList<Edge>> complete; protected int width; protected int height; public IsoProducer( double minX, double minY, double maxX, double maxY ) { super(minX, minY, maxX, maxY); open = new HashMap<Edge, Integer>(); commonOpen = new HashMap<IJKey, TIntObjectHashMap>(); complete = new HashMap<IJKey, ArrayList<Edge>>(); } public void handleRings( List<Edge> rings, int value, int width, int height ) { if (value == -1) { return; } this.width = width; this.height = height; Integer v = Integer.valueOf(value); for (Edge head: rings) { Edge current = head; do { Integer neighbor = open.remove(current); if (neighbor != null) { IJKey pair = new IJKey(value, neighbor.intValue()); pair.sort(); TIntObjectHashMap co = commonOpen.get(pair); if (co == null) { commonOpen.put(pair, co = new TIntObjectHashMap()); } Edge edge = new Edge(current); Edge otherA = (Edge)co.remove(edge.a); if (otherA != null) { otherA.chain(edge, edge.a); } Edge otherB = (Edge)co.remove(edge.b); if (otherB != null) { otherB.chain(edge, edge.b); } if (edge.isComplete()) { ArrayList list = complete.get(pair); if (list == null) { complete.put(pair, list = new ArrayList()); } list.add(Vectorizer.simplify(edge, width)); } else { if (otherA == null) { co.put(edge.a, edge); } if (otherB == null) { co.put(edge.b, edge); } } } else { Edge edge = new Edge(current.b, current.a); open.put(edge, v); } current = current.next; } while (current != head); } // for all rings } // handleRings protected HashSet<IJKey> joinPairs() { HashSet<IJKey> pairs = new HashSet<IJKey>(); pairs.addAll(complete .keySet()); pairs.addAll(commonOpen.keySet()); return pairs; } protected static ArrayList<Edge> headList(TIntObjectHashMap map) { final ArrayList<Edge> headList = new ArrayList<Edge>(); map.forEachValue(new TObjectProcedure() { TIntHashSet headSet = new TIntHashSet(); public boolean execute(Object value) { Edge head = ((Edge)value).head(); if (headSet.add(head.a)) { headList.add(head); } return true; } }); return headList; } public void clear() { open.clear(); complete.clear(); commonOpen.clear(); } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :