changeset 2673:0143b44631cc

Beginnings of mittlere hoehe calculation. flys-artifacts/trunk@4367 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 09 May 2012 19:03:54 +0000
parents 5afccab9aac1
children 2be59d5b342c
files flys-artifacts/ChangeLog flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java
diffstat 4 files changed, 47 insertions(+), 5 deletions(-) [+]
line wrap: on
line diff
--- a/flys-artifacts/ChangeLog	Tue May 08 13:55:59 2012 +0000
+++ b/flys-artifacts/ChangeLog	Wed May 09 19:03:54 2012 +0000
@@ -1,3 +1,15 @@
+2012-05-08  Felix Wolfsteller <felix.wolfsteller@intevation.de>
+
+	Beginning of calculation of Mittlere Hoehe: area calculation.
+
+	* src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java,
+	  src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java:
+	  Adjusted to LineData constructor.
+
+	* src/main/java/de/intevation/flys/artifacts/geom/Lines.java
+	  (area): New, calculate area of a polygon.
+	  Added todos where area calculation code paths are missing.
+
 2012-05-08  Ingo Weinzierl <ingo@intevation.de>
 
 	* doc/conf/meta-data.xml: Moved the hws layers out to an own node.
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Tue May 08 13:55:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/StaticWKmsArtifact.java	Wed May 09 19:03:54 2012 +0000
@@ -271,7 +271,7 @@
         double wAtKm = getWAtKm(wkms, km);
         if (wAtKm == -1) {
             logger.warn("Waterlevel at km " + km + " unknown.");
-            return new Lines.LineData(new double[][] {{}}, 0d);
+            return new Lines.LineData(new double[][] {{}}, 0d, 0d);
         }
 
         return Lines.createWaterLines(points, wAtKm);
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Tue May 08 13:55:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java	Wed May 09 19:03:54 2012 +0000
@@ -27,6 +27,24 @@
     protected Lines() {
     }
 
+
+    /**
+     * Calculate area of polygon with four vertices.
+     * @return area of polygon with four vertices.
+     */
+    public static double area(Point2D p1, Point2D p2, Point2D p3, Point2D p4) {
+        double[] x = new double[] {p1.getX(), p2.getX(), p3.getX(), p4.getX() };
+        double[] y = new double[] {p1.getY(), p2.getY(), p3.getY(), p4.getY() };
+        double area = 0d;
+        int j = 3;
+        for (int i=0; i <4; i++) {
+            area += (x[j] + x[i]) * (y[j] - y[i]);
+            j = i;
+        }
+        return area * 0.5d;
+    }
+
+
     /**
      * Calculate the 'length' of the given lines.
      */
@@ -59,7 +77,7 @@
 
         if (N == 1) {
             Point2D p = points.get(0);
-            // Only generate point if over water
+            // Only generate point if over profile
             if (waterLevel > p.getY()) {
                 result.add(new Line2D.Double(
                     p.getX(), waterLevel,
@@ -94,10 +112,13 @@
             return result;
         }
 
+        // Water is sometimes above, sometimes under profile.
         Mode mode = Mode.UNDEF;
 
         double startX = minX;
 
+        double area = 0d;
+        // Walking along the profile.
         for (int i = 1; i < N; ++i) {
             Point2D p1 = points.get(i-1);
             Point2D p2 = points.get(i);
@@ -111,9 +132,13 @@
                     startX = p1.getX();
                     mode = Mode.WET;
                 }
+                area += area(p1, p2,
+                    new Point2D.Double(p2.getX(), waterLevel),
+                    new Point2D.Double(p1.getX(), waterLevel));
                 continue;
             }
 
+            // TODO trigger area calculation
             if (p1.getY() > waterLevel && p2.getY() > waterLevel) {
                 if (debug) {
                     log.debug("over water: " + p1 + " " + p2);
@@ -129,6 +154,7 @@
                 continue;
             }
 
+            // TODO trigger area calculation
             if (Math.abs(p1.getX() - p2.getX()) < EPSILON) {
                 // vertical line
                 switch (mode) {
@@ -162,6 +188,7 @@
             boolean p1W = Math.abs(waterLevel - p1.getY()) < EPSILON;
             boolean p2W = Math.abs(waterLevel - p2.getY()) < EPSILON;
 
+            // TODO trigger area calculation
             if (p1W || p2W) {
                 if (debug) {
                     log.debug("water hits vertex: " + p1 + " " + p2 + " " + mode);
@@ -215,6 +242,7 @@
                 continue;
             }
 
+            // TODO trigger area calculation
             // intersection case
             double x = Linear.linear(
                 waterLevel,
@@ -274,9 +302,11 @@
     public static class LineData {
         public double [][] points;
         public double width;
-        public LineData(double[][] points, double width) {
+        public double area;
+        public LineData(double[][] points, double width, double area) {
             this.points = points;
             this.width = width;
+            this.area = area;
         }
     }
 
@@ -313,7 +343,7 @@
 
         return new LineData(
             new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
-            linesLength
+            linesLength, 0d
             );
     }
 }
--- a/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Tue May 08 13:55:59 2012 +0000
+++ b/flys-artifacts/src/main/java/de/intevation/flys/artifacts/model/CrossSectionWaterLineFacet.java	Wed May 09 19:03:54 2012 +0000
@@ -42,7 +42,7 @@
             getDataProvider(CrossSectionFacet.BLACKBOARD_CS_MASTER_DATA);
         if (providers.size() < 1) {
             logger.warn("Could not find Cross-Section data provider.");
-            return new Lines.LineData(new double[][] {}, 0d);
+            return new Lines.LineData(new double[][] {}, 0d, 0d);
         }
         
         Object crossSection = providers.get(0)

http://dive4elements.wald.intevation.org