Mercurial > dive4elements > gnv-client
comparison gnv-artifacts/src/main/java/de/intevation/gnv/math/Interpolation2D.java @ 431:422275fc9927
Refactored the XYColumn and Point2d code a bit to be more reusable in 3D.
gnv-artifacts/trunk@479 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Wed, 23 Dec 2009 06:53:46 +0000 |
parents | 04a242c67fe6 |
children | 0eed5749fd63 |
comparison
equal
deleted
inserted
replaced
430:23e9352df09b | 431:422275fc9927 |
---|---|
22 public interface Consumer { | 22 public interface Consumer { |
23 void interpolated(Coordinate point, boolean success); | 23 void interpolated(Coordinate point, boolean success); |
24 } // interface Consumer | 24 } // interface Consumer |
25 | 25 |
26 private Interpolation2D() { | 26 private Interpolation2D() { |
27 } | |
28 | |
29 public static final double [] calculateBuffer( | |
30 List <? extends Point2d> points | |
31 ) { | |
32 HashMap<Integer, ArrayList<Point2d>> iMap = | |
33 new HashMap<Integer, ArrayList<Point2d>>(); | |
34 | |
35 HashMap<Integer, ArrayList<Point2d>> jMap = | |
36 new HashMap<Integer, ArrayList<Point2d>>(); | |
37 | |
38 for (int k = points.size()-1; k >= 0; --k) { | |
39 Point2d p = points.get(k); | |
40 | |
41 ArrayList<Point2d> jList = jMap.get(p.j); | |
42 ArrayList<Point2d> iList = jMap.get(p.i); | |
43 | |
44 if (jList == null) { | |
45 iMap.put(p.j, jList = new ArrayList<Point2d>()); | |
46 } | |
47 jList.add(p); | |
48 | |
49 if (iList == null) { | |
50 jMap.put(p.i, iList = new ArrayList<Point2d>()); | |
51 } | |
52 iList.add(p); | |
53 } | |
54 | |
55 double dxMax = -Double.MAX_VALUE; | |
56 double dyMax = -Double.MAX_VALUE; | |
57 | |
58 for (ArrayList<Point2d> v: jMap.values()) { | |
59 Collections.sort(v, Point2d.Y_COMPARATOR); | |
60 for (int i = 1, L = v.size(); i < L; ++i) { | |
61 double dy = Math.abs(v.get(i).x - v.get(i-1).x); | |
62 if (dy > dyMax) { | |
63 dyMax = dy; | |
64 } | |
65 } | |
66 } | |
67 | |
68 dyMax += 1e-5d; | |
69 | |
70 for (ArrayList<Point2d> v: iMap.values()) { | |
71 Collections.sort(v, Point2d.X_COMPARATOR); | |
72 for (int i = 1, L = v.size(); i < L; ++i) { | |
73 double dx = Math.abs(v.get(i).x - v.get(i-1).x); | |
74 if (dx > dxMax) { | |
75 dxMax = dx; | |
76 } | |
77 } | |
78 } | |
79 | |
80 dxMax += 1e-5d; | |
81 | |
82 return new double [] { dxMax, dyMax }; | |
27 } | 83 } |
28 | 84 |
29 public static void interpolate( | 85 public static void interpolate( |
30 List<? extends Coordinate> path, | 86 List<? extends Coordinate> path, |
31 List<? extends Point2d> points, | 87 List<? extends Point2d> points, |
45 | 101 |
46 if (M < 1 || N < 2) { // nothing to do | 102 if (M < 1 || N < 2) { // nothing to do |
47 return; | 103 return; |
48 } | 104 } |
49 | 105 |
50 HashMap<Integer, ArrayList<Point2d>> map = new HashMap<Integer, ArrayList<Point2d>>(); | 106 double [] buffer = calculateBuffer(points); |
51 | 107 double dxMax = buffer[0]; |
52 for (int k = M-1; k >= 0; --k) { | 108 double dyMax = buffer[1]; |
53 Point2d p = points.get(k); | |
54 | |
55 ArrayList<Point2d> list = map.get(p.j); | |
56 | |
57 if (list == null) { | |
58 map.put(p.j, list = new ArrayList<Point2d>()); | |
59 } | |
60 list.add(p); | |
61 } | |
62 | |
63 double dxMax = -Double.MAX_VALUE; | |
64 | |
65 for (ArrayList<Point2d> v: map.values()) { | |
66 Collections.sort(v, Point2d.X_COMPARATOR); | |
67 for (int i = 1, L = v.size(); i < L; ++i) { | |
68 double dx = Math.abs(v.get(i).x - v.get(i-1).x); | |
69 if (dx > dxMax) { | |
70 dxMax = dx; | |
71 } | |
72 } | |
73 } | |
74 | |
75 dxMax += 1e-5d; | |
76 | |
77 map.clear(); | |
78 | |
79 for (int k = M-1; k >= 0; --k) { | |
80 Point2d p = points.get(k); | |
81 | |
82 ArrayList<Point2d> list = map.get(p.i); | |
83 | |
84 if (list == null) { | |
85 map.put(p.i, list = new ArrayList<Point2d>()); | |
86 } | |
87 list.add(p); | |
88 } | |
89 | |
90 double dyMax = -Double.MAX_VALUE; | |
91 | |
92 for (ArrayList<Point2d> v: map.values()) { | |
93 Collections.sort(v, Point2d.Y_COMPARATOR); | |
94 for (int i = 1, L = v.size(); i < L; ++i) { | |
95 double dy = Math.abs(v.get(i).y - v.get(i-1).y); | |
96 if (dy > dyMax) { | |
97 dyMax = dy; | |
98 } | |
99 } | |
100 } | |
101 | |
102 dyMax += 1e-5d; | |
103 | |
104 map = null; | |
105 | 109 |
106 if (log.isDebugEnabled()) { | 110 if (log.isDebugEnabled()) { |
107 log.debug("buffer size: " + dxMax + " / " + dyMax); | 111 log.debug("buffer size: " + dxMax + " / " + dyMax); |
108 } | 112 } |
109 | 113 |