Mercurial > dive4elements > gnv-client
view gnv-artifacts/src/main/java/de/intevation/gnv/state/profile/verticalcrosssection/OutputHelper.java @ 1074:649f564a5184
Implemented a new output state and chart type for horizontal profiles using vector data.
gnv-artifacts/trunk@1174 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Ingo Weinzierl <ingo.weinzierl@intevation.de> |
---|---|
date | Tue, 08 Jun 2010 13:00:58 +0000 |
parents | 9058c08eac3a |
children | f953c9a559d8 |
line wrap: on
line source
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 <a href="mailto:sascha.teichmann@intevation.de">Sascha L. Teichmann</a> */ public class OutputHelper { private static Logger log = Logger.getLogger(OutputHelper.class); public static final double EPS = 1e-5d; private OutputHelper() { } /** * Creates a PolygonSeries representing the seabed used to be displayed in a * 2D-chart. * * @param interpolation The interpolation which supports information about * the max depth, the cell width and height. * @param fill The fill color as integer. * @return a PolygonSeries representing the seabed. */ 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 :