diff gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/OutputHelper.java @ 521:1bf058f1a2d1

Generate seabed polygon to "Profilschnitte". gnv-artifacts/trunk@615 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Sascha L. Teichmann <sascha.teichmann@intevation.de>
date Sun, 24 Jan 2010 20:24:03 +0000
parents
children c4156275c1e1
line wrap: on
line diff
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/OutputHelper.java	Sun Jan 24 20:24:03 2010 +0000
@@ -0,0 +1,87 @@
+package de.intevation.gnv.state.profile.verticalcrosssection;
+
+import de.intevation.gnv.jfreechart.CompactXYItems;
+import de.intevation.gnv.jfreechart.PolygonSeries;
+
+import de.intevation.gnv.math.Interpolation3D;
+
+import gnu.trove.TDoubleArrayList;
+
+import org.apache.log4j.Logger;
+
+/**
+ * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
+ */
+public class OutputHelper
+{
+    private static Logger log = Logger.getLogger(OutputHelper.class);
+
+    public static final double EPS = 1e-5d;
+
+    private OutputHelper() {
+    }
+
+    public static PolygonSeries createSeabedPolygon(
+        Interpolation3D interpolation,
+        Integer         fill
+    ) {
+        double maxDepth   = interpolation.getMaxDepth();
+        double cellWidth  = interpolation.getCellWidth();
+        double cellHeight = interpolation.getCellHeight();
+
+        double [] depths = interpolation.getDepths();
+
+        double x = 0d;
+
+        TDoubleArrayList vertices = new TDoubleArrayList();
+
+        PolygonSeries ps = new PolygonSeries();
+
+        for (int i = 0; i < depths.length; ++i, x += cellWidth) {
+            double depth = depths[i];
+
+            if (vertices.isEmpty()) {
+                if (Double.isNaN(depth) || depth == maxDepth) {
+                    continue;
+                }
+                if (depth > 0d) depth = 0d;
+                vertices.add(x); vertices.add(maxDepth);
+                vertices.add(x); vertices.add(depth);
+                vertices.add(x+cellWidth); vertices.add(depth);
+            }
+            else { // in polygon
+                if (Double.isNaN(depth) || depth == maxDepth) {
+                    vertices.add(x); vertices.add(maxDepth);
+                    ps.addRing(new CompactXYItems(vertices.toNativeArray()));
+                    vertices.reset();
+                }
+                else {
+                    if (depth > 0d) depth = 0d;
+                    int N = vertices.size();
+                    if (N > 2 && Math.abs(depth - vertices.get(N-1)) < EPS) {
+                        vertices.set(N-2, x+cellWidth);
+                    }
+                    else {
+                        vertices.add(vertices.get(N-2)); vertices.add(depth);
+                        vertices.add(x+cellWidth); vertices.add(depth);
+                    }
+                }
+            }
+        } // for all depths
+
+        if (!vertices.isEmpty()) {
+            vertices.add(vertices.get(vertices.size()-2));
+            vertices.add(maxDepth);
+            ps.addRing(new CompactXYItems(vertices.toNativeArray()));
+        }
+
+        if (ps.getItemCount() == 0) {
+            return null;
+        }
+
+        ps.setAttribute("fill", fill);
+
+        return ps;
+    }
+}
+// vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org