Mercurial > dive4elements > gnv-client
comparison geo-backend/src/main/java/de/intevation/gnv/geobackend/sde/datasources/RasterObject.java @ 548:ccd976fc0f7b
Implemented bilinear interpolation on raster tiles.
geo-backend/trunk@520 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Sascha L. Teichmann <sascha.teichmann@intevation.de> |
---|---|
date | Sat, 09 Jan 2010 16:12:10 +0000 |
parents | 23d5cc37dd5b |
children | 0dcf068fb552 |
comparison
equal
deleted
inserted
replaced
547:23d5cc37dd5b | 548:ccd976fc0f7b |
---|---|
87 | 87 |
88 public double getValue(Coordinate coordinate) { | 88 public double getValue(Coordinate coordinate) { |
89 return getValue(coordinate, NEAREST_NEIGHBOR); | 89 return getValue(coordinate, NEAREST_NEIGHBOR); |
90 } | 90 } |
91 | 91 |
92 public final double interpolateBilinear(double px, double py) { | |
93 | |
94 if (px < 0.5d) { // left border | |
95 if (py < 0.5d) { // upper left edge | |
96 return rasterData[0]; | |
97 } | |
98 if (py > tileHeight-0.5d) { // lower left edge | |
99 return rasterData[rasterData.length-tileWidth]; | |
100 } | |
101 // center left | |
102 int i = (int)(py -= 0.5d); | |
103 double t = py - i; | |
104 i *= tileWidth; | |
105 return (1d-t)*rasterData[i] + t*rasterData[i+tileWidth]; | |
106 } | |
107 | |
108 if (px > tileWidth-0.5d) { // right border | |
109 if (py < 0.5d) { // upper right edge | |
110 return rasterData[tileWidth-1]; | |
111 } | |
112 if (py > tileHeight-0.5d) { // lower right edge | |
113 return rasterData[rasterData.length-1]; | |
114 } | |
115 // center right | |
116 int i = (int)(py -= 0.5d); | |
117 double t = py - i; | |
118 i = i*tileWidth + tileWidth-1; | |
119 return (1d-t)*rasterData[i] + t*rasterData[i+tileWidth]; | |
120 } | |
121 | |
122 if (py < 0.5d) { // top border | |
123 int i = (int)(px -= 0.5d); | |
124 double t = px - i; | |
125 return (1d-t)*rasterData[i] + t*rasterData[i+1]; | |
126 } | |
127 | |
128 if (py > tileHeight-0.5d) { // bottom border | |
129 int i = (int)(px -= 0.5d); | |
130 double t = px - i; | |
131 i += rasterData.length-tileWidth; | |
132 return (1d-t)*rasterData[i] + t*rasterData[i+1]; | |
133 } | |
134 | |
135 // center | |
136 int i = (int)(py -= 0.5d); | |
137 int j = (int)(px -= 0.5d); | |
138 double ti = py - i; | |
139 double tj = px - j; | |
140 | |
141 int idx = i*tileWidth + j; | |
142 | |
143 double v1j1 = rasterData[idx]; | |
144 double v2j1 = rasterData[idx+1]; | |
145 | |
146 idx += tileWidth; | |
147 | |
148 double v1j2 = rasterData[idx]; | |
149 double v2j2 = rasterData[idx+1]; | |
150 | |
151 double v1 = (1d-tj)*v1j1 + tj*v2j1; | |
152 double v2 = (1d-tj)*v1j2 + tj*v2j2; | |
153 | |
154 return (1d-ti)*v1 + ti*v2; | |
155 } | |
156 | |
92 public double getValue(Coordinate coordinate, int interpolationType) { | 157 public double getValue(Coordinate coordinate, int interpolationType) { |
93 | 158 |
94 double px = mx*coordinate.x + bx; | 159 double px = mx*coordinate.x + bx; |
95 double py = my*coordinate.y + by; | 160 double py = my*coordinate.y + by; |
96 | 161 |
97 if (px < 0d || py < 0d || px >= tileWidth || py >= tileHeight) { | 162 if (px < 0d || py < 0d || px >= tileWidth || py >= tileHeight) { |
98 return Double.NaN; | 163 return Double.NaN; |
99 } | 164 } |
100 | 165 |
101 /* | |
102 if (interpolationType == BILINEAR) { | 166 if (interpolationType == BILINEAR) { |
103 // TODO: implement me! | 167 return interpolateBilinear(px, py); |
104 } | 168 } |
105 */ | |
106 | 169 |
107 int posX = Math.min(tileWidth-1, (int)Math.round(px)); | 170 int posX = Math.min(tileWidth-1, (int)Math.round(px)); |
108 int posY = Math.min(tileHeight-1, (int)Math.round(py)); | 171 int posY = Math.min(tileHeight-1, (int)Math.round(py)); |
109 | 172 |
110 return get(posX, posY); | 173 return get(posX, posY); |