annotate flys-artifacts/src/main/java/de/intevation/flys/artifacts/geom/Lines.java @ 2674:2be59d5b342c

Added and respect theme prop whether or not to display (not yet calculated) middle height. flys-artifacts/trunk@4368 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Felix Wolfsteller <felix.wolfsteller@intevation.de>
date Wed, 09 May 2012 20:05:46 +0000
parents 0143b44631cc
children 22c8a9b4de31
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
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
73 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
74
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
75 boolean debug = log.isDebugEnabled();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
76
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
77 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
78 log.debug("fillWater");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
79 log.debug("----------------------------");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
80 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
81
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
82 List<Line2D> result = new ArrayList();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
83
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
84 int N = points.size();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
85
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
86 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
87 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
88 }
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 if (N == 1) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 Point2D p = points.get(0);
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
92 // 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
93 if (waterLevel > p.getY()) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 result.add(new Line2D.Double(
934
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
95 p.getX(), waterLevel,
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
96 p.getX(), waterLevel));
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
97 }
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
98 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
99 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 double minX = Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
102 double minY = Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
103 double maxX = -Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 double maxY = -Double.MAX_VALUE;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 // 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
107 // the original index order is preserved.
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
108 for (Point2D p: points) {
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 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
110 if (x < minX) minX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
111 if (x > maxX) maxX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 if (y < minY) minY = y;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 if (y > maxY) maxY = y;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114 }
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 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
117 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
118 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
119 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 if (waterLevel > maxY) { // water floods profile
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
122 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
123 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
124 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
125 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
127 // 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
128 Mode mode = Mode.UNDEF;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
130 double startX = minX;
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
132 double area = 0d;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
133 // Walking along the profile.
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 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
135 Point2D p1 = points.get(i-1);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
136 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
137
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
138 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
139 // completely under water
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
140 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
141 log.debug("under water: " + p1 + " " + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
142 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
143 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
144 startX = p1.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
145 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
146 }
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
147 area += area(p1, p2,
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
148 new Point2D.Double(p2.getX(), waterLevel),
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
149 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
150 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
153 // TODO trigger area calculation
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
154 if (p1.getY() > waterLevel && p2.getY() > waterLevel) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
155 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
156 log.debug("over water: " + p1 + " " + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
157 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 // completely over water
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 if (mode == Mode.WET) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
160 log.debug("over/wet");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 p1.getX(), waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
169 // TODO trigger area calculation
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 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
171 // vertical line
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 switch (mode) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 case WET:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
174 log.debug("vertical/wet");
933
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 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
177 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
178 p1.getX(), waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
179 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
180 case DRY:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
181 log.debug("vertical/dry");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
182 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
183 startX = p2.getX();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
184 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
185 default: // UNDEF
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
186 log.debug("vertical/undef");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
187 if (p2.getY() < waterLevel) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
188 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
189 startX = p2.getX();
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
190 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
191 else {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
192 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
193 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
194 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
195 continue;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
196 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
197
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
198 // check if waterlevel directly hits the vertices;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
199
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
200 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
201 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
202
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
203 // TODO trigger area calculation
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
204 if (p1W || p2W) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
205 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
206 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
207 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
208 if (p1W && p2W) { // parallel to water -> dry
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
209 log.debug("water hits both vertices");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
210 if (mode == Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
211 result.add(new Line2D.Double(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
212 startX, waterLevel,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
213 p1.getX(), waterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
214 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
215 mode = Mode.DRY;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
216 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
217 else if (p1W) { // p1 == waterlevel
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
218 log.debug("water hits first vertex");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
219 if (p2.getY() > waterLevel) { // --> dry
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 { // --> wet
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
228 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
229 startX = p1.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
230 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
231 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
232 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
233 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
234 else { // p2 == waterlevel
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
235 log.debug("water hits second vertex");
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
236 if (p1.getY() > waterLevel) { // --> wet
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
237 if (mode != Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
238 startX = p2.getX();
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
239 mode = Mode.WET;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
240 }
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 else { // --> dry
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
243 if (mode == Mode.WET) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
244 result.add(new Line2D.Double(
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
245 startX, waterLevel,
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
246 p2.getX(), waterLevel));
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
247 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
248 mode = Mode.DRY;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
249 }
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 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
252 log.debug("mode is now: " + mode);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
253 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
254 continue;
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
255 }
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
256
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
257 // TODO trigger area calculation
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
258 // intersection case
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
259 double x = Linear.linear(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
260 waterLevel,
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
261 p1.getY(), p2.getY(),
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
262 p1.getX(), p2.getX());
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 if (debug) {
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
265 log.debug("intersection p1:" + p1);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
266 log.debug("intersection p2:" + p2);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
267 log.debug("intersection at x: " + x);
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
268 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
269
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
270 switch (mode) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
271 case WET:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
272 log.debug("intersect/wet");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
273 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
274 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
275 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
276 x, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
277 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
278
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
279 case DRY:
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
280 log.debug("intersect/dry");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
281 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
282 startX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
283 break;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
284
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
285 default: // UNDEF
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
286 log.debug("intersect/undef");
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
287 if (p2.getY() > waterLevel) {
938
bd3683453928 Debugged the water fill algorithm.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 934
diff changeset
288 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
289 mode = Mode.DRY;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
290 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
291 p1.getX(), waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
292 x, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
293 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
294 else {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
295 mode = Mode.WET;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
296 startX = x;
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
297 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
298 } // switch mode
934
d0f3fea20f01 Fixed corner case.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 933
diff changeset
299 } // 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
300
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
301 if (mode == Mode.WET) {
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
302 result.add(new Line2D.Double(
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
303 startX, waterLevel,
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
304 maxX, waterLevel));
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
305 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
306
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
307 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
308 }
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
309
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
310
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
311 /**
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
312 * 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
313 */
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
314 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
315 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
316 public double width;
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
317 public double area;
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
318 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
319 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
320 this.width = width;
2673
0143b44631cc Beginnings of mittlere hoehe calculation.
Felix Wolfsteller <felix.wolfsteller@intevation.de>
parents: 2652
diff changeset
321 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
322 }
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
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
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 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
327 List<Point2D> points,
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
328 double waterlevel
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
329 ) {
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
330 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
331 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
332
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
333 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
334 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
335 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
336
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
337 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
338 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
339 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
340 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
341 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
342 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
343 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
344 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
345
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
346 // 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
347 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
348 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
349 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
350
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
351 if (iter.hasNext()) {
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
352 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
353 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
354 }
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
355 }
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
356
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
357 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
358 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
359 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
360 );
1651
a7def20539fb flys/issue317: Removed dependency from cross section demo app.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 938
diff changeset
361 }
933
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
362 }
34136924661b Generate water level lines for given cross section.
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
363 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org