Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation2D.java @ 528:44415ae01ddb
Fixed issue gnv/issue159
gnv-artifacts/trunk@624 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Mon, 25 Jan 2010 18:25:19 +0000 |
parents | 4e347624ee7c |
children | 9a828e5a2390 |
comparison
equal
deleted
inserted
replaced
527:f598702b2a10 | 528:44415ae01ddb |
---|---|
26 } // interface Consumer | 26 } // interface Consumer |
27 | 27 |
28 private Interpolation2D() { | 28 private Interpolation2D() { |
29 } | 29 } |
30 | 30 |
31 public static Envelope pathBoundingBox( | 31 public static final Envelope relevantArea( |
32 List<? extends Coordinate> path, | 32 List<? extends Coordinate> path, |
33 double extra | 33 List<? extends Coordinate> points |
34 ) { | |
35 return relevantArea(path, points, CULL_POINT_THRESHOLD); | |
36 } | |
37 | |
38 public static final Envelope relevantArea( | |
39 Envelope pathBBox, | |
40 List<? extends Coordinate> points | |
41 ) { | |
42 return relevantArea(pathBBox, points, CULL_POINT_THRESHOLD); | |
43 } | |
44 | |
45 public static final Envelope relevantArea( | |
46 Envelope pathBBox, | |
47 List<? extends Coordinate> points, | |
48 int threshold | |
49 ) { | |
50 return points.size() < threshold | |
51 ? null | |
52 : relevantArea( | |
53 pathBBox, | |
54 pointsBoundingBox(points)); | |
55 } | |
56 | |
57 public static final Envelope relevantArea( | |
58 List<? extends Coordinate> path, | |
59 List<? extends Coordinate> points, | |
60 int threshold | |
61 ) { | |
62 return points.size() < threshold || path.isEmpty() | |
63 ? null | |
64 : relevantArea( | |
65 pointsBoundingBox(path), | |
66 pointsBoundingBox(points)); | |
67 } | |
68 | |
69 public static final Envelope relevantArea( | |
70 Envelope pathBBox, | |
71 Envelope pointsBBox | |
72 ) { | |
73 double pathArea = pathBBox.getWidth()*pathBBox.getHeight(); | |
74 double pointsArea = pointsBBox.getWidth()*pointsBBox.getHeight(); | |
75 | |
76 if (pathArea > 0.8d*pointsArea) { return null; } | |
77 | |
78 double nArea = 1.44d * pathArea; | |
79 if (nArea < 0.1d*pointsArea) nArea = 0.1d*pointsArea; | |
80 double w = pathBBox.getWidth(); | |
81 double h = pathBBox.getHeight(); | |
82 double [] d = solveQuadratic(1d, w+h, pathArea - nArea); | |
83 | |
84 if (d == null) { return null; } | |
85 | |
86 double extra = pos(d); | |
87 | |
88 pathBBox.expandBy(extra); | |
89 | |
90 return pathBBox; | |
91 } | |
92 | |
93 public static final double [] solveQuadratic( | |
94 double a, double b, double c | |
95 ) { | |
96 double d = b*b - 4d*a*c; | |
97 if (d < 0d) { return null; } | |
98 | |
99 d = Math.sqrt(d); | |
100 a = 1d/(2d*a); | |
101 b = -b; | |
102 | |
103 return new double [] { a*(b + d), a*(b - d) }; | |
104 } | |
105 | |
106 public static final double pos(double [] x) { | |
107 return x[0] >= 0 ? x[0] : x[1]; | |
108 } | |
109 | |
110 | |
111 public static Envelope pointsBoundingBox( | |
112 List<? extends Coordinate> path | |
34 ) { | 113 ) { |
35 int N = path.size(); | 114 int N = path.size(); |
36 Envelope area = new Envelope(path.get(N-1)); | 115 Envelope area = new Envelope(path.get(N-1)); |
37 | 116 |
38 for (int i = N-2; i >= 0; --i) { | 117 for (int i = N-2; i >= 0; --i) { |
39 area.expandToInclude(path.get(i)); | 118 area.expandToInclude(path.get(i)); |
40 } | 119 } |
41 | |
42 area.expandBy( | |
43 extra*area.getWidth(), | |
44 extra*area.getHeight()); | |
45 | 120 |
46 return area; | 121 return area; |
47 } | 122 } |
48 | 123 |
49 public static void interpolate( | 124 public static void interpolate( |
67 | 142 |
68 if (M < 1 || N < 2) { // nothing to do | 143 if (M < 1 || N < 2) { // nothing to do |
69 return; | 144 return; |
70 } | 145 } |
71 | 146 |
72 Envelope relevantArea = M > CULL_POINT_THRESHOLD | |
73 ? pathBoundingBox(path, 0.05d) | |
74 : null; | |
75 | |
76 List<GridCell> cells = GridCell.pointsToGridCells( | 147 List<GridCell> cells = GridCell.pointsToGridCells( |
77 points, relevantArea); | 148 points, relevantArea(path, points)); |
78 | 149 |
79 if (cells.isEmpty()) { | 150 if (cells.isEmpty()) { |
80 log.warn("no cells found"); | 151 log.warn("no cells found"); |
81 return; | 152 return; |
82 } | 153 } |