annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2679:22c8a9b4de31

Minimal doc, TODO. flys-artifacts/trunk@4377 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Thu, 10 May 2012 09:28:01 +0000
parents 2be59d5b342c
children b94b367d8b4d
rev   line source
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
1 package de.intevation.flys.geom;
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
3 import java.util.ArrayList;
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import java.util.List;
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
5 import java.util.Iterator;
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7 import java.awt.geom.Point2D;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
8 import java.awt.geom.Line2D;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
9
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
10 import de.intevation.flys.artifacts.math.Linear;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
11
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
12 import org.apache.log4j.Logger;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
13
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
14 import gnu.trove.TDoubleArrayList;
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
15
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
16 /**
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
17 * Utility to create lines (intersect water with cross-section etc).
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
18 */
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 public class Lines
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
21 private static Logger log = Logger.getLogger(Lines.class);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
22
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 public static final double EPSILON = 1e-4;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25 public static enum Mode { UNDEF, WET, DRY };
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27 protected Lines() {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
30
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
31 /**
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
32 * Calculate area of polygon with four vertices.
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
33 * @return area of polygon with four vertices.
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
34 */
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
35 public static double area(Point2D p1, Point2D p2, Point2D p3, Point2D p4) {
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
36 double[] x = new double[] {p1.getX(), p2.getX(), p3.getX(), p4.getX() };
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
37 double[] y = new double[] {p1.getY(), p2.getY(), p3.getY(), p4.getY() };
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
38 double area = 0d;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
39 int j = 3;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
40 for (int i=0; i <4; i++) {
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
41 area += (x[j] + x[i]) * (y[j] - y[i]);
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
42 j = i;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
43 }
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
44 return area * 0.5d;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
45 }
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
46
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
47
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
48 /**
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
49 * Calculate the 'length' of the given lines.
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
50 */
2650
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
51 public static double length(List<Line2D> lines) {
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
52 double sum = 0d;
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
53 for (Line2D line: lines) {
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
54 double xDiff = line.getX1() - line.getX2();
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
55 double yDiff = line.getY1() - line.getY2();
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
56 sum += Math.sqrt(xDiff*xDiff + yDiff*yDiff);
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
57 }
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
58 return sum;
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
59 }
a6fa128e4654 Add method to calculate length of water lines.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 1651
diff changeset
60
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
61
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
62 /** List of lines and a double-precision area. */
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
63 private static class ListWithArea {
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
64 public List<Line2D> lines;
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
65 public double area;
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
66 public ListWithArea(List<Line2D> lines, double area) {
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
67 this.lines = lines;
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
68 this.area = area;
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
69 }
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
70 }
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
71
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
72
2679
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
73 /**
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
74 * For a cross section given as points and a waterlevel (in meters),
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
75 * create a set of lines that represent the water surface, assuming it
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
76 * is distributed horizontally equally.
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
77 * @param points the points describing the river bed.
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
78 * @param waterLevel the height of the horizontal water line.
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
79 * @return A list of Lines representing the water surface and the
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
80 * calculated area between water surface and river bed.
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
81 */
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
82 public static ListWithArea fillWater(List<Point2D> points, double waterLevel) {
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
84 boolean debug = log.isDebugEnabled();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
85
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
86 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
87 log.debug("fillWater");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
88 log.debug("----------------------------");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 List<Line2D> result = new ArrayList();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93 int N = points.size();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 if (N == 0) {
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
96 return new ListWithArea(result, 0d);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
98
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
99 if (N == 1) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 Point2D p = points.get(0);
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
101 // Only generate point if over profile
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 if (waterLevel > p.getY()) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 result.add(new Line2D.Double(
934
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
104 p.getX(), waterLevel,
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
105 p.getX(), waterLevel));
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 }
2679
22c8a9b4de31 Minimal doc, TODO.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2674
diff changeset
107 // TODO continue calculating area.
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
108 return new ListWithArea(result, 0d);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 double minX = Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 double minY = Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 double maxX = -Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 double maxY = -Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 // To ensure for sequences of equals x's that
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117 // the original index order is preserved.
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
118 for (Point2D p: points) {
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 double x = p.getX(), y = p.getY();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120 if (x < minX) minX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 if (x > maxX) maxX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 if (y < minY) minY = y;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 if (y > maxY) maxY = y;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 if (minY > waterLevel) { // profile completely over water level
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
127 log.debug("complete over water");
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
128 return new ListWithArea(result, 0d);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 if (waterLevel > maxY) { // water floods profile
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
132 log.debug("complete under water");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 result.add(new Line2D.Double(minX, waterLevel, maxX, waterLevel));
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
134 return new ListWithArea(result, 0d);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
137 // Water is sometimes above, sometimes under profile.
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 Mode mode = Mode.UNDEF;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
140 double startX = minX;
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
142 double area = 0d;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
143 // Walking along the profile.
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 for (int i = 1; i < N; ++i) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
145 Point2D p1 = points.get(i-1);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
146 Point2D p2 = points.get(i);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
148 if (p1.getY() < waterLevel && p2.getY() < waterLevel) {
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 // completely under water
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
150 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
151 log.debug("under water: " + p1 + " " + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
152 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
153 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
154 startX = p1.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
155 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
156 }
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
157 area += area(p1, p2,
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
158 new Point2D.Double(p2.getX(), waterLevel),
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
159 new Point2D.Double(p1.getX(), waterLevel));
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
163 // TODO trigger area calculation
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
164 if (p1.getY() > waterLevel && p2.getY() > waterLevel) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
165 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
166 log.debug("over water: " + p1 + " " + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
167 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 // completely over water
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169 if (mode == Mode.WET) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
170 log.debug("over/wet");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 p1.getX(), waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
174 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
175 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
176 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
179 // TODO trigger area calculation
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 if (Math.abs(p1.getX() - p2.getX()) < EPSILON) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
181 // vertical line
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 switch (mode) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 case WET:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
184 log.debug("vertical/wet");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
186 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 p1.getX(), waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 case DRY:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
191 log.debug("vertical/dry");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 startX = p2.getX();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 default: // UNDEF
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
196 log.debug("vertical/undef");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197 if (p2.getY() < waterLevel) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
198 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
199 startX = p2.getX();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
200 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
201 else {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
202 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
203 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
204 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
205 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
206 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
207
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
208 // check if waterlevel directly hits the vertices;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
209
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
210 boolean p1W = Math.abs(waterLevel - p1.getY()) < EPSILON;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
211 boolean p2W = Math.abs(waterLevel - p2.getY()) < EPSILON;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
212
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
213 // TODO trigger area calculation
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
214 if (p1W || p2W) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
215 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
216 log.debug("water hits vertex: " + p1 + " " + p2 + " " + mode);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
217 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
218 if (p1W && p2W) { // parallel to water -> dry
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
219 log.debug("water hits both vertices");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
220 if (mode == Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
221 result.add(new Line2D.Double(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
222 startX, waterLevel,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
223 p1.getX(), waterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
224 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
225 mode = Mode.DRY;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
226 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
227 else if (p1W) { // p1 == waterlevel
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
228 log.debug("water hits first vertex");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
229 if (p2.getY() > waterLevel) { // --> dry
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
230 if (mode == Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
231 result.add(new Line2D.Double(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
232 startX, waterLevel,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
233 p1.getX(), waterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
234 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
235 mode = Mode.DRY;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
236 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
237 else { // --> wet
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
238 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
239 startX = p1.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
240 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
241 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
242 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
243 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
244 else { // p2 == waterlevel
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
245 log.debug("water hits second vertex");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
246 if (p1.getY() > waterLevel) { // --> wet
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
247 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
248 startX = p2.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
249 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
250 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
251 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
252 else { // --> dry
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
253 if (mode == Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
254 result.add(new Line2D.Double(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
255 startX, waterLevel,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
256 p2.getX(), waterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
257 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
258 mode = Mode.DRY;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
259 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
260 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
261 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
262 log.debug("mode is now: " + mode);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
263 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
264 continue;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
265 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
266
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
267 // TODO trigger area calculation
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
268 // intersection case
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
269 double x = Linear.linear(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270 waterLevel,
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
271 p1.getY(), p2.getY(),
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
272 p1.getX(), p2.getX());
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
273
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
274 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
275 log.debug("intersection p1:" + p1);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
276 log.debug("intersection p2:" + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
277 log.debug("intersection at x: " + x);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
278 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
279
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
280 switch (mode) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
281 case WET:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
282 log.debug("intersect/wet");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
283 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
284 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
286 x, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
287 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
288
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
289 case DRY:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
290 log.debug("intersect/dry");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 startX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 default: // UNDEF
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
296 log.debug("intersect/undef");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297 if (p2.getY() > waterLevel) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
298 log.debug("intersect/undef/over");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
299 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
300 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301 p1.getX(), waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
302 x, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
303 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
304 else {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
305 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306 startX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
307 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
308 } // switch mode
934
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
309 } // for all points p[i] and p[i-1]
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
310
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
311 if (mode == Mode.WET) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
312 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
313 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
314 maxX, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
315 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
316
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
317 return new ListWithArea(result, area);
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
318 }
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
319
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
320
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
321 /**
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
322 * Class holding points that form lines and the calculated length.
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
323 */
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
324 public static class LineData {
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
325 public double [][] points;
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
326 public double width;
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
327 public double area;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
328 public LineData(double[][] points, double width, double area) {
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
329 this.points = points;
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
330 this.width = width;
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
331 this.area = area;
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
332 }
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
333 }
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
334
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
335
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
336 public static LineData createWaterLines(
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
337 List<Point2D> points,
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
338 double waterlevel
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
339 ) {
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
340 ListWithArea listAndArea = fillWater(points, waterlevel);
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
341 List<Line2D> lines = listAndArea.lines;
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
342
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
343 TDoubleArrayList lxs = new TDoubleArrayList();
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
344 TDoubleArrayList lys = new TDoubleArrayList();
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
345 double linesLength = 0.0f;
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
346
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
347 for (Iterator<Line2D> iter = lines.iterator(); iter.hasNext();) {
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
348 Line2D line = iter.next();
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
349 Point2D p1 = line.getP1();
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
350 Point2D p2 = line.getP2();
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
351 lxs.add(p1.getX());
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
352 lys.add(p1.getY());
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
353 lxs.add(p2.getX());
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
354 lys.add(p2.getY());
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
355
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
356 // Length calculation.
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
357 double xDiff = line.getX1() - line.getX2();
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
358 double yDiff = line.getY1() - line.getY2();
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
359 linesLength += Math.sqrt(xDiff*xDiff + yDiff*yDiff);
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
360
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
361 if (iter.hasNext()) {
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
362 lxs.add(Double.NaN);
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
363 lys.add(Double.NaN);
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
364 }
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
365 }
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
366
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
367 return new LineData(
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
368 new double [][] { lxs.toNativeArray(), lys.toNativeArray() },
2674
2be59d5b342c Added and respect theme prop whether or not to display (not yet calculated) middle height.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2673
diff changeset
369 linesLength, listAndArea.area
2652
9d2a06c3a134 Added DataType for lines that also stores width, use it. Added HasLabel interface for some series.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2650
diff changeset
370 );
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
371 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
372 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
373 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org