ingo@1115: /* ingo@1115: * Copyright (c) 2010 by Intevation GmbH ingo@1115: * ingo@1115: * This program is free software under the LGPL (>=v2.1) ingo@1115: * Read the file LGPL.txt coming with the software for details ingo@1115: * or visit http://www.gnu.org/licenses/ if it does not exist. ingo@1115: */ ingo@1115: sascha@521: package de.intevation.gnv.state.profile.verticalcrosssection; sascha@521: sascha@521: import de.intevation.gnv.jfreechart.CompactXYItems; sascha@521: import de.intevation.gnv.jfreechart.PolygonSeries; sascha@521: sascha@521: import de.intevation.gnv.math.Interpolation3D; sascha@521: sascha@521: import gnu.trove.TDoubleArrayList; sascha@521: sascha@521: import org.apache.log4j.Logger; sascha@521: sascha@521: /** sascha@780: * @author Sascha L. Teichmann sascha@521: */ sascha@521: public class OutputHelper sascha@521: { sascha@521: private static Logger log = Logger.getLogger(OutputHelper.class); sascha@521: sascha@521: public static final double EPS = 1e-5d; sascha@521: sascha@521: private OutputHelper() { sascha@521: } sascha@521: ingo@804: ingo@804: /** ingo@804: * Creates a PolygonSeries representing the seabed used to be displayed in a ingo@804: * 2D-chart. ingo@804: * ingo@804: * @param interpolation The interpolation which supports information about ingo@804: * the max depth, the cell width and height. ingo@804: * @param fill The fill color as integer. ingo@804: * @return a PolygonSeries representing the seabed. ingo@804: */ sascha@521: public static PolygonSeries createSeabedPolygon( sascha@521: Interpolation3D interpolation, sascha@521: Integer fill sascha@521: ) { sascha@521: double maxDepth = interpolation.getMaxDepth(); sascha@521: double cellWidth = interpolation.getCellWidth(); sascha@521: double cellHeight = interpolation.getCellHeight(); sascha@521: sascha@521: double [] depths = interpolation.getDepths(); sascha@521: sascha@521: double x = 0d; sascha@521: sascha@521: TDoubleArrayList vertices = new TDoubleArrayList(); sascha@521: sascha@521: PolygonSeries ps = new PolygonSeries(); sascha@521: sascha@521: for (int i = 0; i < depths.length; ++i, x += cellWidth) { sascha@521: double depth = depths[i]; sascha@521: sascha@521: if (vertices.isEmpty()) { sascha@521: if (Double.isNaN(depth) || depth == maxDepth) { sascha@521: continue; sascha@521: } sascha@521: if (depth > 0d) depth = 0d; sascha@521: vertices.add(x); vertices.add(maxDepth); sascha@521: vertices.add(x); vertices.add(depth); sascha@521: vertices.add(x+cellWidth); vertices.add(depth); sascha@521: } sascha@521: else { // in polygon sascha@521: if (Double.isNaN(depth) || depth == maxDepth) { sascha@521: vertices.add(x); vertices.add(maxDepth); sascha@521: ps.addRing(new CompactXYItems(vertices.toNativeArray())); sascha@521: vertices.reset(); sascha@521: } sascha@521: else { sascha@521: if (depth > 0d) depth = 0d; sascha@521: int N = vertices.size(); sascha@521: if (N > 2 && Math.abs(depth - vertices.get(N-1)) < EPS) { sascha@521: vertices.set(N-2, x+cellWidth); sascha@521: } sascha@521: else { sascha@521: vertices.add(vertices.get(N-2)); vertices.add(depth); sascha@521: vertices.add(x+cellWidth); vertices.add(depth); sascha@521: } sascha@521: } sascha@521: } sascha@521: } // for all depths sascha@521: sascha@521: if (!vertices.isEmpty()) { sascha@521: vertices.add(vertices.get(vertices.size()-2)); sascha@521: vertices.add(maxDepth); sascha@521: ps.addRing(new CompactXYItems(vertices.toNativeArray())); sascha@521: } sascha@521: sascha@521: if (ps.getItemCount() == 0) { sascha@521: return null; sascha@521: } sascha@521: sascha@521: ps.setAttribute("fill", fill); sascha@521: sascha@521: return ps; sascha@521: } sascha@521: } sascha@521: // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :