gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / provider / MemoryMatrixBuffer.java @ 1810
History | View | Annotate | Download (18.4 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.provider; |
23 |
|
24 |
import java.awt.geom.AffineTransform; |
25 |
import java.awt.geom.Rectangle2D; |
26 |
import java.io.IOException; |
27 |
import java.util.ArrayList; |
28 |
import java.util.List; |
29 |
|
30 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
31 |
import org.gvsig.fmap.dal.coverage.RasterManager; |
32 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
33 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
34 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
35 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
36 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
37 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
38 |
import org.gvsig.fmap.dal.coverage.store.DataServerWriter; |
39 |
import org.gvsig.fmap.dal.coverage.store.RasterWriter; |
40 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
41 |
import org.gvsig.raster.cache.tile.Tile; |
42 |
import org.gvsig.raster.impl.DefaultRasterManager; |
43 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
44 |
|
45 |
/**
|
46 |
* Buffer composed by a list of tiles and its extents.
|
47 |
* It will expose a method getWindow to read a window of data from the tile list.
|
48 |
* The list of tiles have to make a square.
|
49 |
*
|
50 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
51 |
*/
|
52 |
public class MemoryMatrixBuffer { |
53 |
private Buffer[] bufferList = null; |
54 |
private Buffer[] transpList = null; |
55 |
private int nRows = 0; |
56 |
private int nCols = 0; |
57 |
@SuppressWarnings("unused") |
58 |
private Extent bbox = null; |
59 |
private List<Tile> tileList = null; |
60 |
|
61 |
/**
|
62 |
* Constructor using an array of tiles. It will compute the number
|
63 |
* of rows and columns and the complete bounding box
|
64 |
* @param tileList
|
65 |
*/
|
66 |
public MemoryMatrixBuffer(Tile[] tileList) { |
67 |
this.tileList = new ArrayList<Tile>(); |
68 |
bufferList = new Buffer[tileList.length]; |
69 |
if(tileList[0].getData().length > 1 && tileList[0].getData()[1] instanceof Buffer) |
70 |
transpList = new Buffer[tileList.length]; |
71 |
for (int i = 0; i < tileList.length; i++) { |
72 |
this.tileList.add(tileList[i]);
|
73 |
bufferList[i] = (Buffer)tileList[i].getData()[0]; |
74 |
if(tileList[i].getData().length > 1 && tileList[i].getData()[1] instanceof Buffer) |
75 |
transpList[i] = (Buffer)tileList[i].getData()[1]; |
76 |
//extentList[i] = tileList[i].getExtent();
|
77 |
//pxLayerList[i] = tileList[i].getCoordsPx();
|
78 |
} |
79 |
int minRow = Integer.MAX_VALUE; |
80 |
int maxRow = Integer.MIN_VALUE; |
81 |
int minCol = Integer.MAX_VALUE; |
82 |
int maxCol = Integer.MIN_VALUE; |
83 |
for (int i = 0; i < tileList.length; i++) { |
84 |
if(tileList[i].getRow() > maxRow)
|
85 |
maxRow = tileList[i].getRow(); |
86 |
if(tileList[i].getCol() > maxCol)
|
87 |
maxCol = tileList[i].getCol(); |
88 |
if(tileList[i].getRow() < minRow)
|
89 |
minRow = tileList[i].getRow(); |
90 |
if(tileList[i].getCol() < minCol)
|
91 |
minCol = tileList[i].getCol(); |
92 |
} |
93 |
nRows = maxRow - minRow + 1;
|
94 |
nCols = maxCol - minCol + 1;
|
95 |
bbox = calculateBBox(); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* Constructor using an ArrayList of tiles. It will compute the number
|
100 |
* of rows and columns and the complete bounding box
|
101 |
* @param tileList
|
102 |
*/
|
103 |
public MemoryMatrixBuffer(List<Tile> tileList) { |
104 |
this.tileList = tileList;
|
105 |
bufferList = new Buffer[tileList.size()]; |
106 |
if(tileList.get(0).getData().length > 1 && tileList.get(0).getData()[1] instanceof Buffer) |
107 |
transpList = new Buffer[tileList.size()]; |
108 |
for (int i = 0; i < tileList.size(); i++) { |
109 |
bufferList[i] = (Buffer)tileList.get(i).getData()[0]; |
110 |
if(tileList.get(i).getData().length > 1 && tileList.get(i).getData()[1] instanceof Buffer) |
111 |
transpList[i] = (Buffer)tileList.get(i).getData()[1]; |
112 |
} |
113 |
int minRow = Integer.MAX_VALUE; |
114 |
int maxRow = Integer.MIN_VALUE; |
115 |
int minCol = Integer.MAX_VALUE; |
116 |
int maxCol = Integer.MIN_VALUE; |
117 |
for (int i = 0; i < tileList.size(); i++) { |
118 |
if(tileList.get(i).getRow() > maxRow)
|
119 |
maxRow = tileList.get(i).getRow(); |
120 |
if(tileList.get(i).getCol() > maxCol)
|
121 |
maxCol = tileList.get(i).getCol(); |
122 |
if(tileList.get(i).getRow() < minRow)
|
123 |
minRow = tileList.get(i).getRow(); |
124 |
if(tileList.get(i).getCol() < minCol)
|
125 |
minCol = tileList.get(i).getCol(); |
126 |
} |
127 |
nRows = maxRow - minRow + 1;
|
128 |
nCols = maxCol - minCol + 1;
|
129 |
bbox = calculateBBox(); |
130 |
} |
131 |
|
132 |
/**
|
133 |
* Builds the complete bounding box of the tile list
|
134 |
* @return
|
135 |
*/
|
136 |
private Extent calculateBBox() {
|
137 |
double minX = Double.MAX_VALUE; |
138 |
double minY = Double.MAX_VALUE; |
139 |
double maxX = 0; |
140 |
double maxY = 0; |
141 |
for (int i = 0; i < tileList.size(); i++) { |
142 |
Rectangle2D e = tileList.get(i).getExtent();
|
143 |
if(e.getX() < minX)
|
144 |
minX = e.getX(); |
145 |
if((e.getY() - e.getHeight()) < minY)
|
146 |
minY = (e.getY() - e.getHeight()); |
147 |
if((e.getX() + e.getWidth()) > maxX)
|
148 |
maxX = (e.getX() + e.getWidth()); |
149 |
if(e.getY() > maxY)
|
150 |
maxY = e.getY(); |
151 |
} |
152 |
return new ExtentImpl(minX, minY, maxX, maxY); |
153 |
} |
154 |
|
155 |
/**
|
156 |
* Gets a window from tiles
|
157 |
* @param ext
|
158 |
* @param buf
|
159 |
* @return
|
160 |
*/
|
161 |
public Buffer getWindow(Rectangle2D r, Buffer buf) { |
162 |
int shiftRow = 0; |
163 |
int shiftCol = 0; |
164 |
int posRow = 0; |
165 |
int posCol = 0; |
166 |
Rectangle2D[] rTileShiftList = new Rectangle2D[bufferList.length]; |
167 |
Rectangle2D[] rBufferShiftList = new Rectangle2D[bufferList.length]; |
168 |
int[] colsWidth = new int[nCols]; |
169 |
int[] rowsHeight = new int[nRows]; |
170 |
for (int i = 0; i < bufferList.length; i++) { |
171 |
Rectangle2D pxLayer = tileList.get(i).getCoordsPx();
|
172 |
int initPxTileX = (int)Math.max(pxLayer.getMinX(), r.getMinX()) - (tileList.get(i).getCol() * tileList.get(i).getWidthPx()); |
173 |
int initPxTileY = (int)Math.max(pxLayer.getMinY(), r.getMinY()) - (tileList.get(i).getRow() * tileList.get(i).getHeightPx()); |
174 |
int widthPxTile = (int)Math.min(pxLayer.getMaxX(), r.getMaxX()) - (tileList.get(i).getCol() * tileList.get(i).getWidthPx()) - initPxTileX; |
175 |
int heightPxTile = (int)Math.min(pxLayer.getMaxY(), r.getMaxY()) - (tileList.get(i).getRow() * tileList.get(i).getHeightPx()) - initPxTileY; |
176 |
rTileShiftList[i] = new Rectangle2D.Double(initPxTileX, initPxTileY, widthPxTile, heightPxTile); |
177 |
if(i == 0) { |
178 |
shiftCol = tileList.get(i).getCol(); |
179 |
shiftRow = tileList.get(i).getRow(); |
180 |
} |
181 |
posCol = tileList.get(i).getCol() - shiftCol; |
182 |
posRow = tileList.get(i).getRow() - shiftRow; |
183 |
if(posCol == 0) |
184 |
colsWidth[posCol] = widthPxTile; |
185 |
else
|
186 |
colsWidth[posCol] = widthPxTile + colsWidth[posCol - 1];
|
187 |
|
188 |
if(posRow == 0) |
189 |
rowsHeight[posRow] = heightPxTile; |
190 |
else
|
191 |
rowsHeight[posRow] = heightPxTile + rowsHeight[posRow - 1];
|
192 |
|
193 |
|
194 |
//shiftX = initPxTileX < shiftX ? initPxTileX : shiftX;
|
195 |
//shiftY = initPxTileY < shiftY ? initPxTileY : shiftY;
|
196 |
} |
197 |
|
198 |
int initPxBufferX = 0; |
199 |
int initPxBufferY = 0; |
200 |
int widthPxBuffer = 0; |
201 |
int heightPxBuffer = 0; |
202 |
|
203 |
for (int i = 0; i < bufferList.length; i++) { |
204 |
posCol = tileList.get(i).getCol() - shiftCol; |
205 |
posRow = tileList.get(i).getRow() - shiftRow; |
206 |
if(posCol == 0) { |
207 |
initPxBufferX = 0;
|
208 |
widthPxBuffer = colsWidth[0];
|
209 |
} else {
|
210 |
initPxBufferX = colsWidth[posCol - 1];
|
211 |
widthPxBuffer = colsWidth[posCol] - initPxBufferX; |
212 |
} |
213 |
if(posRow == 0) { |
214 |
initPxBufferY = 0;
|
215 |
heightPxBuffer = rowsHeight[0];
|
216 |
} else {
|
217 |
initPxBufferY = rowsHeight[posRow - 1];
|
218 |
heightPxBuffer = rowsHeight[posRow] - initPxBufferY; |
219 |
} |
220 |
rBufferShiftList[i] = new Rectangle2D.Double(initPxBufferX, initPxBufferY, widthPxBuffer, heightPxBuffer); |
221 |
} |
222 |
|
223 |
for (int i = 0; i < bufferList.length; i++) { |
224 |
loadBuffer(buf, |
225 |
bufferList[i], |
226 |
rTileShiftList[i], |
227 |
(int)rBufferShiftList[i].getX(),
|
228 |
(int)rBufferShiftList[i].getY(),
|
229 |
false);
|
230 |
} |
231 |
return buf;
|
232 |
} |
233 |
|
234 |
/**
|
235 |
* Gets a window from tiles
|
236 |
* @param ext
|
237 |
* @param buf
|
238 |
* @return
|
239 |
*/
|
240 |
public Buffer getWindow(Extent ext, Buffer buf) { |
241 |
return getWindow(ext, buf, false); |
242 |
} |
243 |
|
244 |
/**
|
245 |
* Gets a window from tiles
|
246 |
* @param ext
|
247 |
* @param buf
|
248 |
* @return
|
249 |
*/
|
250 |
public Buffer getWindow(Extent ext, Buffer buf, boolean alpha) { |
251 |
if(tileList.size() <= 0) |
252 |
return null; |
253 |
|
254 |
Buffer sourceWithoutResampling = createBufferWithoutResampling(ext, buf, tileList.get(0).getExtent(), bufferList[0]); |
255 |
for (int i = 0; i < bufferList.length; i++) { |
256 |
//1-Calcular las coordenadas pixel del tile de entrada
|
257 |
int[] points = getClipPoints(tileList.get(i).getExtent(), bufferList[i], ext); |
258 |
|
259 |
//2-Ajustar peti?n al extent del tile
|
260 |
Extent adjustedRequestExtent = getAdjustedExtent(tileList.get(i).getExtent(), ext); |
261 |
|
262 |
if((points[0] == 0 && points[1] == 0) || (points[2] == 0 && points[3] == 0)) |
263 |
continue;
|
264 |
|
265 |
//3-Calcular coordenada pixel de inicio del buffer
|
266 |
double wcX1 = Math.abs(adjustedRequestExtent.getMin().getX() - ext.getMin().getX()); |
267 |
double wcY1 = Math.abs(ext.getMax().getY() - adjustedRequestExtent.getMax().getY()); |
268 |
int initXPxBuf = (int)Math.round((wcX1 * (sourceWithoutResampling.getWidth())) / ext.width()); |
269 |
int initYPxBuf = (int)Math.round((wcY1 * (sourceWithoutResampling.getHeight())) / ext.height()); |
270 |
|
271 |
//4-Copiar recorte al buffer
|
272 |
Rectangle2D rTile = new Rectangle2D.Double(points[0], points[2], (points[1] - points[0]) + 1, (points[3] - points[2]) + 1); |
273 |
if(alpha)
|
274 |
loadBuffer(sourceWithoutResampling, transpList[i], rTile, initXPxBuf, initYPxBuf, true);
|
275 |
else
|
276 |
loadBuffer(sourceWithoutResampling, bufferList[i], rTile, initXPxBuf, initYPxBuf, false);
|
277 |
} |
278 |
try {
|
279 |
save(sourceWithoutResampling, true, ext, null); |
280 |
} catch (NotSupportedExtensionException e) {
|
281 |
e.printStackTrace(); |
282 |
} catch (RasterDriverException e) {
|
283 |
e.printStackTrace(); |
284 |
} catch (ProcessInterruptedException e) {
|
285 |
e.printStackTrace(); |
286 |
} catch (IOException e) { |
287 |
e.printStackTrace(); |
288 |
} |
289 |
//Devuelve el buffer pero reescalandolo antes al tama?o en pixeles de la petici?n
|
290 |
try {
|
291 |
Buffer result = null; |
292 |
result = sourceWithoutResampling.getAdjustedWindow(buf.getWidth(), buf.getHeight(), Buffer.INTERPOLATION_NearestNeighbour);
|
293 |
if(result != sourceWithoutResampling)
|
294 |
sourceWithoutResampling.dispose(); |
295 |
return result;
|
296 |
} catch (ProcessInterruptedException e) {
|
297 |
} |
298 |
return buf;
|
299 |
} |
300 |
|
301 |
private void save(Buffer bufResult, |
302 |
boolean alphaBand,
|
303 |
Extent tileExtent, |
304 |
ColorInterpretation colorInterpretation) throws NotSupportedExtensionException, RasterDriverException, ProcessInterruptedException, IOException { |
305 |
//Escritura en disco del tile
|
306 |
RasterManager rManager = RasterLocator.getManager(); |
307 |
DataServerWriter dataWriter = RasterLocator.getManager().createDataServerWriter(); |
308 |
dataWriter.setBuffer(bufResult, -1);
|
309 |
Params params = rManager.createWriter("_.tif").getParams();
|
310 |
double pixelSize = (tileExtent.width() / bufResult.getWidth());
|
311 |
AffineTransform affineTransform = new AffineTransform(pixelSize, 0, 0, -pixelSize, |
312 |
tileExtent.getULX(), |
313 |
tileExtent.getULY()); |
314 |
RasterWriter rw = rManager.createWriter(dataWriter, "/tmp/prueba.tif",
|
315 |
bufResult.getBandCount(), affineTransform, bufResult.getWidth(), |
316 |
bufResult.getHeight(), bufResult.getDataType(), params, null);
|
317 |
|
318 |
if(colorInterpretation != null) { |
319 |
String[] values = colorInterpretation.getValues(); |
320 |
if(alphaBand) {
|
321 |
String[] newValues = values; |
322 |
boolean exists = false; |
323 |
for (int i = 0; i < values.length; i++) { |
324 |
if(values[i] != null && values[i].compareTo("Alpha") == 0) |
325 |
exists = true;
|
326 |
} |
327 |
if(!exists) {
|
328 |
newValues = new String[values.length + 1]; |
329 |
for (int i = 0; i < values.length; i++) { |
330 |
newValues[i] = values[i]; |
331 |
} |
332 |
newValues[newValues.length - 1] = "Alpha"; |
333 |
} |
334 |
rw.setColorBandsInterpretation(newValues); |
335 |
} |
336 |
|
337 |
} else {
|
338 |
if(alphaBand) {
|
339 |
String[] ci = new String[bufResult.getBandCount()]; |
340 |
if(bufResult.getBandCount() == 4) { |
341 |
ci[0] = "Red"; |
342 |
ci[1] = "Green"; |
343 |
ci[2] = "Blue"; |
344 |
ci[3] = "Alpha"; |
345 |
} else {
|
346 |
for (int i = 0; i < bufResult.getBandCount(); i++) { |
347 |
ci[i] = "Gray";
|
348 |
} |
349 |
} |
350 |
rw.setColorBandsInterpretation(ci); |
351 |
} |
352 |
} |
353 |
rw.dataWrite(); |
354 |
rw.writeClose(); |
355 |
} |
356 |
|
357 |
/**
|
358 |
* Builds a buffer in the same resolution as the list of tiles. When the operation
|
359 |
* ends this buffer should be resampled.
|
360 |
* @return
|
361 |
*/
|
362 |
private Buffer createBufferWithoutResampling(Extent extOrigin, |
363 |
Buffer bufOrigin,
|
364 |
Rectangle2D extTile,
|
365 |
Buffer bufTile) {
|
366 |
double psOrigin = extOrigin.width() / bufOrigin.getWidth();
|
367 |
double psTile = extTile.getWidth() / bufTile.getWidth();
|
368 |
double rel = psTile / psOrigin;
|
369 |
int w = (int)Math.round(bufOrigin.getWidth() / rel); |
370 |
int h = (int)Math.round(bufOrigin.getHeight() / rel); |
371 |
return DefaultRasterManager.getInstance().createBuffer(bufOrigin.getDataType(), w, h, bufOrigin.getBandCount(), true); |
372 |
} |
373 |
|
374 |
/**
|
375 |
* Gets the point list to clip the tile
|
376 |
* @param r Bounding box of the tile
|
377 |
* @param b Buffer of the tile
|
378 |
* @param extentRequest
|
379 |
* @return
|
380 |
*/
|
381 |
private int[] getClipPoints(Rectangle2D r, Buffer b, Extent extentRequest) { |
382 |
double widthWCTile = r.getWidth();
|
383 |
double widthPXTile = b.getWidth();
|
384 |
double heightWCTile = r.getHeight();
|
385 |
double heightPXTile = b.getHeight();
|
386 |
|
387 |
//1-Ajustar peti?n al extent del tile
|
388 |
Extent adjustedRequestExtent = getAdjustedExtent(r, extentRequest); |
389 |
|
390 |
//2-Obtener el punto inicial y final del recorte del tile en pixeles
|
391 |
double wcX1 = adjustedRequestExtent.getMin().getX() - r.getX();
|
392 |
double wcX2 = adjustedRequestExtent.getMax().getX() - r.getX();
|
393 |
double wcY1 = r.getY() - adjustedRequestExtent.getMax().getY();
|
394 |
double wcY2 = r.getY() - adjustedRequestExtent.getMin().getY();
|
395 |
int initXPxTile = (int)((wcX1 * widthPXTile) / widthWCTile); |
396 |
int endXPxTile = (int)(((wcX2 * widthPXTile) / widthWCTile) - 1); |
397 |
int initYPxTile = (int)((wcY1 * heightPXTile) / heightWCTile); |
398 |
int endYPxTile = (int)(((wcY2 * heightPXTile) / heightWCTile) - 1); |
399 |
return new int[]{initXPxTile, |
400 |
endXPxTile >= widthPXTile ? endXPxTile - 1 : endXPxTile,
|
401 |
initYPxTile, |
402 |
endYPxTile >= heightPXTile ? endYPxTile - 1 : endYPxTile};
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Adjust the request to the tile bounding box
|
407 |
* @param tileExtent
|
408 |
* @param extentRequest
|
409 |
* @return
|
410 |
*/
|
411 |
private Extent getAdjustedExtent(Rectangle2D tileExtent, Extent extentRequest) { |
412 |
double x1 = Math.max(extentRequest.getMin().getX(), tileExtent.getX()); |
413 |
double y1 = Math.min(extentRequest.getMax().getY(), tileExtent.getY()); |
414 |
double x2 = Math.min(extentRequest.getMax().getX(), (tileExtent.getX() + tileExtent.getWidth())); |
415 |
double y2 = Math.max(extentRequest.getMin().getY(), (tileExtent.getY() - tileExtent.getHeight())); |
416 |
return new ExtentImpl(x1, y1, x2, y2); |
417 |
} |
418 |
|
419 |
/**
|
420 |
* Write data in the source buffer taking into account the view shift
|
421 |
* @param sourceBuf
|
422 |
* @param tileBuf
|
423 |
* @param rTile
|
424 |
* @param initXPxBuf
|
425 |
* @param initYPxBuf
|
426 |
*/
|
427 |
private void loadBuffer(Buffer sourceBuf, Buffer tileBuf, Rectangle2D rTile, int initXPxBuf, int initYPxBuf, boolean alpha) { |
428 |
int r = initXPxBuf;
|
429 |
int c = initYPxBuf;
|
430 |
//if(!alpha) {
|
431 |
if(tileBuf.getDataType() == Buffer.TYPE_BYTE) { |
432 |
for (int band = 0; band < tileBuf.getBandCount(); band++) { |
433 |
r = initYPxBuf; |
434 |
for (int row = (int)rTile.getMinY(); (row < (int)rTile.getMaxY() && r < sourceBuf.getHeight()); row++) { |
435 |
c = initXPxBuf; |
436 |
for (int col = (int)rTile.getMinX(); (col < (int)rTile.getMaxX() && c < sourceBuf.getWidth()); col++) { |
437 |
sourceBuf.setElem(r, c, band, tileBuf.getElemByte(row, col, band)); |
438 |
c++; |
439 |
} |
440 |
r++; |
441 |
} |
442 |
} |
443 |
} |
444 |
/*} else {
|
445 |
if(tileBuf.getDataType() == Buffer.TYPE_BYTE) {
|
446 |
r = initYPxBuf;
|
447 |
for (int row = (int)rTile.getMinY(); row < (int)rTile.getMaxY(); row++) {
|
448 |
c = initXPxBuf;
|
449 |
for (int col = (int)rTile.getMinX(); col < (int)rTile.getMaxX(); col++) {
|
450 |
sourceBuf.setElem(r, c, 0, tileBuf.getElemByte(row, col, 0));
|
451 |
c++;
|
452 |
}
|
453 |
r++;
|
454 |
}
|
455 |
}
|
456 |
}*/
|
457 |
if(tileBuf.getDataType() == Buffer.TYPE_SHORT) { |
458 |
for (int band = 0; band < tileBuf.getBandCount(); band++) { |
459 |
r = initYPxBuf; |
460 |
for (int row = (int)rTile.getMinY(); (row < (int)rTile.getMaxY() && r < sourceBuf.getHeight()); row++) { |
461 |
c = initXPxBuf; |
462 |
for (int col = (int)rTile.getMinX(); (col < (int)rTile.getMaxX() && c < sourceBuf.getWidth()); col++) { |
463 |
sourceBuf.setElem(r, c, band, tileBuf.getElemShort(row, col, band)); |
464 |
c++; |
465 |
} |
466 |
r++; |
467 |
} |
468 |
} |
469 |
} |
470 |
if(tileBuf.getDataType() == Buffer.TYPE_INT) { |
471 |
for (int band = 0; band < tileBuf.getBandCount(); band++) { |
472 |
r = initYPxBuf; |
473 |
for (int row = (int)rTile.getMinY(); (row < (int)rTile.getMaxY() && r < sourceBuf.getHeight()); row++) { |
474 |
c = initXPxBuf; |
475 |
for (int col = (int)rTile.getMinX(); (col < (int)rTile.getMaxX() && c < sourceBuf.getWidth()); col++) { |
476 |
sourceBuf.setElem(r, c, band, tileBuf.getElemInt(row, col, band)); |
477 |
c++; |
478 |
} |
479 |
r++; |
480 |
} |
481 |
} |
482 |
} |
483 |
if(tileBuf.getDataType() == Buffer.TYPE_FLOAT) { |
484 |
for (int band = 0; band < tileBuf.getBandCount(); band++) { |
485 |
r = initYPxBuf; |
486 |
for (int row = (int)rTile.getMinY(); (row < (int)rTile.getMaxY() && r < sourceBuf.getHeight()); row++) { |
487 |
c = initXPxBuf; |
488 |
for (int col = (int)rTile.getMinX(); (col < (int)rTile.getMaxX() && c < sourceBuf.getWidth()); col++) { |
489 |
sourceBuf.setElem(r, c, band, tileBuf.getElemFloat(row, col, band)); |
490 |
c++; |
491 |
} |
492 |
r++; |
493 |
} |
494 |
} |
495 |
} |
496 |
if(tileBuf.getDataType() == Buffer.TYPE_DOUBLE) { |
497 |
for (int band = 0; band < tileBuf.getBandCount(); band++) { |
498 |
r = initYPxBuf; |
499 |
for (int row = (int)rTile.getMinY(); (row < (int)rTile.getMaxY() && r < sourceBuf.getHeight()); row++) { |
500 |
c = initXPxBuf; |
501 |
for (int col = (int)rTile.getMinX(); (col < (int)rTile.getMaxX() && c < sourceBuf.getWidth()); col++) { |
502 |
sourceBuf.setElem(r, c, band, tileBuf.getElemDouble(row, col, band)); |
503 |
c++; |
504 |
} |
505 |
r++; |
506 |
} |
507 |
} |
508 |
} |
509 |
} |
510 |
|
511 |
|
512 |
/*private double clip(double value) {
|
513 |
return math.clipDecimals(value, 5);
|
514 |
}
|
515 |
|
516 |
private double round(double value) {
|
517 |
double a = (value - (int)value);
|
518 |
return (a > 0.95 || a < 0.05) ? Math.round(value) : value;
|
519 |
}*/
|
520 |
|
521 |
} |