Mercurial > dive4elements > river
diff flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java @ 1651:a7def20539fb
flys/issue317: Removed dependency from cross section demo app.
flys-artifacts/trunk@2840 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Tue, 27 Sep 2011 13:45:13 +0000 |
parents | 111794adf285 |
children | 595c404523a6 |
line wrap: on
line diff
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java Tue Sep 27 12:40:42 2011 +0000 +++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/charts/CrossSectionApp.java Tue Sep 27 13:45:13 2011 +0000 @@ -18,13 +18,8 @@ import java.awt.event.ActionEvent; import java.awt.geom.Point2D; -import java.awt.geom.Line2D; -import java.util.ArrayList; import java.util.List; -import java.util.Comparator; -import java.util.Collections; -import java.util.Iterator; import java.io.File; import java.io.IOException; @@ -59,8 +54,6 @@ import org.hibernate.Session; import org.hibernate.Query; -import gnu.trove.TDoubleArrayList; - public class CrossSectionApp extends ApplicationFrame { @@ -68,30 +61,6 @@ public static final double EPSILON = 1e-4; - public static final double TOO_SMALL = 0.2; - public static final double TOO_BIG = 500; - - public static final Comparator<CrossSectionPoint> COL_POS_CMP = - new Comparator<CrossSectionPoint>() { - @Override - public int compare(CrossSectionPoint a, CrossSectionPoint b) { - // TODO evaluate: isnt it enough to - // return (|d| > |EPS|) ? d : diff - double xa = a.getX().doubleValue(); - double xb = b.getX().doubleValue(); - double d = xa - xb; - if (d < -EPSILON) return -1; - if (d > +EPSILON) return +1; - int diff = a.getColPos() - b.getColPos(); - return diff < 0 ? -1 : diff > 0 ? +1 : 0; - } - }; - - public static final boolean isValid(double x) { - x = Math.abs(x); - return x > TOO_SMALL && x < TOO_BIG; - } - protected Session session; protected JComboBox crossSectionsCB; @@ -320,48 +289,14 @@ ) { DefaultXYDataset dataset = new DefaultXYDataset(); - List<CrossSectionPoint> ps = line.getPoints(); - - if (ps.isEmpty()) { - return dataset; - } - - Collections.sort(ps, COL_POS_CMP); - - List<Point2D> points = new ArrayList<Point2D>(ps.size()); - - for (CrossSectionPoint p: ps) { - double x = p.getX().doubleValue(); - double y = p.getY().doubleValue(); - if (isValid(x) && isValid(y)) { - points.add(new Point2D.Double(x, y)); - } - } + List<Point2D> points = line.fetchCrossSectionLinesPoints(); if (points.isEmpty()) { return dataset; } - double [] xs = new double[points.size()]; - double [] ys = new double[xs.length]; - - xs[0] = points.get(0).getX(); - ys[0] = points.get(0).getY(); - - for (int i = 1; i < xs.length; ++i) { - Point2D p = points.get(i); - double x = p.getX(); - double y = p.getY(); - - if (x <= xs[i-1]) { - x = xs[i-1] + EPSILON; - } - xs[i] = x; - ys[i] = y; - } - if (waterlevel != null) { - double [][] data = createWaterLines(points, waterlevel); + double [][] data = Lines.createWaterLines(points, waterlevel); dataset.addSeries(String.valueOf(waterlevel), data); } @@ -370,37 +305,13 @@ String legend = (cs != null ? cs.getDescription() : "???") + " " + Math.round(line.getKm().doubleValue() * 1000d)/1000d; - dataset.addSeries(legend, new double [][] { xs, ys }); + double [][] values = CrossSectionLine.fetchCrossSectionProfile(points); + + dataset.addSeries(legend, values); return dataset; } - public static double [][] createWaterLines( - List<Point2D> points, - double waterlevel - ) { - List<Line2D> lines = Lines.fillWater(points, waterlevel); - - TDoubleArrayList lxs = new TDoubleArrayList(); - TDoubleArrayList lys = new TDoubleArrayList(); - - for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) { - Line2D l = iter.next(); - Point2D p1 = l.getP1(); - Point2D p2 = l.getP2(); - lxs.add(p1.getX()); - lys.add(p1.getY()); - lxs.add(p2.getX()); - lys.add(p2.getY()); - if (iter.hasNext()) { - lxs.add(Double.NaN); - lys.add(Double.NaN); - } - } - - return new double [][] { lxs.toNativeArray(), lys.toNativeArray() }; - } - protected void updateCrossSection(CrossSection crossSection) { Object [] cslis = createCrossSectionLineItems(crossSection); DefaultComboBoxModel dcbm = new DefaultComboBoxModel(cslis);