annotate gnv-artifacts/src/main/java/de/intevation/gnv/math/AreaInterpolation.java @ 492:79e80c289018

Added labels and titles to 'Profilschnitt' charts. gnv-artifacts/trunk@569 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author Ingo Weinzierl <ingo.weinzierl@intevation.de>
date Tue, 19 Jan 2010 10:06:03 +0000
parents 64e65daa65e9
children 6e8364e766fa
rev   line source
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
1 package de.intevation.gnv.math;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
2
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
3 import com.vividsolutions.jts.geom.Coordinate;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
4 import com.vividsolutions.jts.geom.Envelope;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
5
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
6 import com.vividsolutions.jts.index.quadtree.Quadtree;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
7
479
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
8 import java.awt.Dimension;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
9
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
10 import java.io.Serializable;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
11
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
12 import java.util.Arrays;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
13 import java.util.Collections;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
14 import java.util.List;
d47b478e662b Cleaned up imports
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 474
diff changeset
15
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
16 import org.apache.log4j.Logger;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
17
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
18 /**
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
19 * @author Sascha L. Teichmann (sascha.teichmann@intevation.de)
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
20 */
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
21 public class AreaInterpolation
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
22 implements Serializable
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
23 {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
24 private static Logger log = Logger.getLogger(AreaInterpolation.class);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
25
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
26 protected double [] raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
27
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
28 protected int width;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
29 protected int height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
30
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
31 public AreaInterpolation() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
32 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
33
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
34 public int getWidth() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
35 return width;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
36 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
37
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
38 public int getHeight() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
39 return height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
40 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
41
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
42 public double [] getRaster() {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
43 return raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
44 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
45
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
46 public boolean interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
47 List<? extends Point2d> points,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
48 Envelope boundingBox,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
49 Dimension samples,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
50 XYDepth depth
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
51 ) {
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
52 boolean debug = log.isDebugEnabled();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
53
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
54 if (points == null || points.isEmpty()) {
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
55 if (debug) {
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
56 log.debug("no points to interpolate");
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
57 }
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
58 return false;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
59 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
60
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
61 double [] buffer = Interpolation2D.calculateBuffer(points);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
62 double dxMax = buffer[0];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
63 double dyMax = buffer[1];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
64
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
65 Quadtree spatialIndex = new Quadtree();
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
66
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
67 for (int i = points.size()-1; i >= 0; --i) {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
68 Point2d p = points.get(i);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
69 spatialIndex.insert(p.envelope(), p);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
70 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
71
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
72 int W = samples.width;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
73 int H = samples.height;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
74
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
75 double cellWidth = boundingBox.getWidth() / W;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
76 double cellHeight = boundingBox.getHeight() / H;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
77
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
78 if (debug) {
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
79 log.debug("width: " + boundingBox.getWidth());
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
80 log.debug("height: " + boundingBox.getHeight());
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
81 log.debug("sample width: " + W);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
82 log.debug("sample height: " + H);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
83 log.debug("cell width: " + cellWidth);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
84 log.debug("cell height: " + cellHeight);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
85 log.debug("buffer x: " + dxMax);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
86 log.debug("buffer y: " + dyMax);
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
87 }
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
88
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
89 Envelope queryBuffer = new Envelope();
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
90 Point2d [] neighbors = new Point2d[4];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
91 Coordinate center = new Coordinate();
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
92 L1Comparator invL1 = new L1Comparator(center);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
93
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
94 double [] raster = new double[W*H];
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
95 Arrays.fill(raster, Double.NaN);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
96
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
97 double minX = boundingBox.getMinX();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
98 double minY = boundingBox.getMinY();
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
99
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
100 int row = 0;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
101 for (int j = 0; j < H; ++j, row += W) {
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
102 double y = j*cellHeight + 0.5d*cellHeight + minY;
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
103 double x = 0.5d*cellWidth + minX;
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
104 for (int i = 0; i < W; ++i, x += cellWidth) {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
105 queryBuffer.init(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
106 x - dxMax, x + dxMax,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
107 y - dyMax, y + dyMax);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
108
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
109 List potential = spatialIndex.query(queryBuffer);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
110
482
64e65daa65e9 Fixed some bugs with calculating "Horizontalschnitte".
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents: 479
diff changeset
111 if (potential.size() < 4) {
474
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
112 continue;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
113 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
114
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
115 center.x = x; center.y = y;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
116 Collections.sort(potential, invL1);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
117
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
118 neighbors[0] = neighbors[1] =
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
119 neighbors[2] = neighbors[3] = null;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
120
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
121 int mask = 0;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
122 // reversed order is essential here!
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
123 for (int k = potential.size()-1; k >= 0; --k) {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
124 Point2d n = (Point2d)potential.get(k);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
125 int code = n.x > center.x ? 1 : 0;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
126 if (n.y > center.y) code |= 2;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
127 neighbors[code] = n;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
128 mask |= 1 << code;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
129 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
130
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
131 int numNeighbors = Integer.bitCount(mask);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
132
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
133 // only interpolate if we have all four neighbors
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
134 // we do not have any gaps and we are below surface.
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
135 if (numNeighbors == 4
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
136 && !neighbors[0].hasIGap(neighbors[1])
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
137 && !neighbors[1].hasJGap(neighbors[3])
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
138 && !neighbors[3].hasIGap(neighbors[2])
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
139 && !neighbors[2].hasJGap(neighbors[0])
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
140 && depth.depth(center) <= 0d
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
141 ) {
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
142 double z1 = Interpolation2D.interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
143 neighbors[0].x, neighbors[0].z,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
144 neighbors[1].x, neighbors[1].z,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
145 center.x);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
146 double z2 = Interpolation2D.interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
147 neighbors[2].x, neighbors[2].z,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
148 neighbors[3].x, neighbors[3].z,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
149 center.x);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
150 double y1 = Interpolation2D.interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
151 neighbors[0].x, neighbors[0].y,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
152 neighbors[1].x, neighbors[1].y,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
153 center.x);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
154 double y2 = Interpolation2D.interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
155 neighbors[2].x, neighbors[2].y,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
156 neighbors[3].x, neighbors[3].y,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
157 center.x);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
158 raster[row+i] = Interpolation2D.interpolate(
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
159 y1, z1,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
160 y2, z2,
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
161 center.y);
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
162 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
163 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
164 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
165
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
166 this.raster = raster;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
167 this.width = W;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
168 this.height = H;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
169
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
170 return true;
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
171 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
172 }
ab29e4ff2fda Added area interpolation needed for "Horizontalschnitt"
Sascha L. Teichmann <sascha.teichmann@intevation.de>
parents:
diff changeset
173 // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 :

http://dive4elements.wald.intevation.org