gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / buffer / DefaultRasterQuery.java @ 2236
History | View | Annotate | Download (29.1 KB)
1 |
package org.gvsig.raster.impl.buffer; |
---|---|
2 |
|
3 |
import java.awt.Rectangle; |
4 |
import java.awt.geom.AffineTransform; |
5 |
import java.awt.geom.Point2D; |
6 |
|
7 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
8 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
9 |
import org.gvsig.fmap.dal.coverage.datastruct.BandList; |
10 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
11 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
12 |
import org.gvsig.fmap.dal.coverage.exception.FileNotExistsException; |
13 |
import org.gvsig.fmap.dal.coverage.exception.InvalidSetViewException; |
14 |
import org.gvsig.fmap.dal.coverage.exception.NotSupportedExtensionException; |
15 |
import org.gvsig.fmap.dal.coverage.exception.QueryException; |
16 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
17 |
import org.gvsig.fmap.dal.coverage.store.RasterQuery; |
18 |
import org.gvsig.fmap.dal.coverage.util.RasterUtils; |
19 |
import org.gvsig.raster.cache.tile.TileCacheLibrary; |
20 |
import org.gvsig.raster.cache.tile.provider.CacheStruct; |
21 |
import org.gvsig.raster.cache.tile.provider.TileListener; |
22 |
import org.gvsig.raster.impl.DefaultRasterManager; |
23 |
import org.gvsig.raster.impl.buffer.cache.RasterReadOnlyBuffer; |
24 |
import org.gvsig.raster.impl.datastruct.ExtentImpl; |
25 |
import org.gvsig.raster.impl.store.QueryableRaster; |
26 |
import org.gvsig.timesupport.Time; |
27 |
import org.gvsig.tools.persistence.PersistentState; |
28 |
import org.gvsig.tools.persistence.exception.PersistenceException; |
29 |
import org.gvsig.tools.task.TaskStatus; |
30 |
|
31 |
/**
|
32 |
* Default implementation for RasterQuery
|
33 |
*
|
34 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
35 |
*/
|
36 |
public class DefaultRasterQuery implements RasterQuery, SpiRasterQuery { |
37 |
public static final int TYPE_UNDEFINED = -1; |
38 |
public static final int TYPE_ENTIRE = 0; |
39 |
public static final int TYPE_WCOORDS = 1; |
40 |
public static final int TYPE_WCOORDS_RESCALED = 2; |
41 |
public static final int TYPE_WCOORDS_SHIFT = 3; |
42 |
public static final int TYPE_PX = 4; |
43 |
public static final int TYPE_PX_RESCALED = 5; |
44 |
public static final int TYPE_PX_SHIFT = 6; |
45 |
public static final int TYPE_PX_RESCALED_SHIFT = 7; |
46 |
public static final int TYPE_TILED = 8; |
47 |
public static final int TYPE_ONE_TILE = 9; |
48 |
|
49 |
private int type = -1; |
50 |
/*
|
51 |
* Request in pixels
|
52 |
*/
|
53 |
private Rectangle pixelWindow = null; |
54 |
/*
|
55 |
* Request in pixels adjusted to the source. The provider will use this parameter. If the type is with
|
56 |
* shift then adjustedPixelWindow will be the same to the pixelWindow
|
57 |
*/
|
58 |
private Rectangle adjustedPixelWindow = null; |
59 |
/*
|
60 |
* Request in world coordinates
|
61 |
*/
|
62 |
private Extent requestBoundingBox = null; |
63 |
/*
|
64 |
* Request in world coordinates adjusted to the source. The provider will use this parameter. If the type is with
|
65 |
* shift then adjustedBoundingBox will be the same to the requestBoundingBox
|
66 |
*/
|
67 |
private Extent adjustedBoundingBox = null; |
68 |
|
69 |
private int widthForResampling = -1; |
70 |
private int heightForResampling = -1; |
71 |
/*
|
72 |
* If the request is adjusted to the input source this width is the same to widthForResampling else
|
73 |
* the provider has to receive the right buffer size for the request, so this adjustedWidth will
|
74 |
* contain a smaller buffer without frames.
|
75 |
*/
|
76 |
private int adjustedBufferWidth = 0; |
77 |
/*
|
78 |
* If the request is adjusted to the input source this height is the same to heightForResampling else
|
79 |
* the provider has to receive the right buffer size for the request, so this adjustedHeight will
|
80 |
* contain a smaller buffer without frames.
|
81 |
*/
|
82 |
private int adjustedBufferHeight = 0; |
83 |
|
84 |
private double[] step = null; |
85 |
|
86 |
private int tileRow = 0; |
87 |
private int tileCol = 0; |
88 |
private int resolutionLevel = -1; |
89 |
private boolean adjustToSrcExtent = true; |
90 |
|
91 |
private int[] drawableBands = new int[]{0}; |
92 |
private boolean readOnly = false; |
93 |
private boolean memoryBuffer = false; |
94 |
private boolean storeLastBuffer = false; |
95 |
private Time time = null; |
96 |
|
97 |
|
98 |
private boolean supersamplingLoadingBuffer = false; |
99 |
/**
|
100 |
* Valor NoData con el que se rellenan las celdas cuando adjustToExtent es false
|
101 |
*/
|
102 |
private NoData noDataValueToFill = null; |
103 |
|
104 |
private TileListener listener = null; |
105 |
private int alphaBandNumber = -1; |
106 |
private CacheStruct cacheStruct = null; |
107 |
private TaskStatus taskStatus = null; |
108 |
|
109 |
//Parameters only for providers
|
110 |
private BandList bandList = null; |
111 |
private Buffer bufferForProviders = null; |
112 |
//private Buffer bufferWithoutAdjust = null;
|
113 |
|
114 |
|
115 |
//****************************************************
|
116 |
//*************Request of data windows****************
|
117 |
//****************************************************
|
118 |
|
119 |
public void setAreaOfInterest() { |
120 |
this.type = TYPE_ENTIRE;
|
121 |
} |
122 |
|
123 |
public void setAreaOfInterest(Rectangle pixelWindow) { |
124 |
this.pixelWindow = pixelWindow;
|
125 |
this.type = TYPE_PX;
|
126 |
} |
127 |
|
128 |
public void setAreaOfInterest(Rectangle pixelWindow, int bufWidth, int bufHeight) { |
129 |
this.pixelWindow = pixelWindow;
|
130 |
this.widthForResampling = bufWidth;
|
131 |
this.heightForResampling = bufHeight;
|
132 |
this.type = TYPE_PX;
|
133 |
} |
134 |
|
135 |
public void setAreaOfInterest(Extent requestBoundingBox, int bufWidth, int bufHeight) { |
136 |
this.widthForResampling = bufWidth;
|
137 |
this.heightForResampling = bufHeight;
|
138 |
this.requestBoundingBox = requestBoundingBox;
|
139 |
this.type = TYPE_WCOORDS;
|
140 |
} |
141 |
|
142 |
public void setAreaOfInterest(Extent boundingBox) { |
143 |
this.requestBoundingBox = boundingBox;
|
144 |
this.type = TYPE_WCOORDS;
|
145 |
} |
146 |
|
147 |
public void setAreaOfInterest(Extent requestBoundingBox, |
148 |
int bufWidth, int bufHeight, TileListener listener) { |
149 |
this.requestBoundingBox = requestBoundingBox;
|
150 |
this.widthForResampling = bufWidth;
|
151 |
this.heightForResampling = bufHeight;
|
152 |
this.type = TYPE_TILED;
|
153 |
this.listener = listener;
|
154 |
} |
155 |
|
156 |
public void setTileParameters(int level, int tileCol, int tileRow) { |
157 |
this.type = TYPE_ONE_TILE;
|
158 |
this.resolutionLevel = level;
|
159 |
this.tileRow = tileRow;
|
160 |
this.tileCol = tileCol;
|
161 |
} |
162 |
|
163 |
/**
|
164 |
* @deprecated Use setTileParameters(int level, int tileCol, int tileRow)
|
165 |
*/
|
166 |
public void setTileParameters(int level, int tileCol, int tileRow, Extent bbox, CacheStruct cacheStruct) { |
167 |
this.type = TYPE_ONE_TILE;
|
168 |
this.requestBoundingBox = bbox;
|
169 |
this.resolutionLevel = level;
|
170 |
this.tileRow = tileRow;
|
171 |
this.tileCol = tileCol;
|
172 |
int[] size = null; |
173 |
if(cacheStruct != null) { |
174 |
this.cacheStruct = cacheStruct;
|
175 |
size = cacheStruct.getTileSizeByLevel(level); |
176 |
} else {
|
177 |
size = new int[]{TileCacheLibrary.DEFAULT_TILEWIDTH, TileCacheLibrary.DEFAULT_TILEHEIGHT}; |
178 |
} |
179 |
this.widthForResampling = size[0]; |
180 |
this.heightForResampling = size[1]; |
181 |
} |
182 |
|
183 |
|
184 |
|
185 |
//****************************************************
|
186 |
//****************Internal Services*******************
|
187 |
//****************************************************
|
188 |
|
189 |
public boolean requestIsTiled() { |
190 |
switch (type) {
|
191 |
case TYPE_TILED:
|
192 |
case TYPE_ONE_TILE:
|
193 |
return true; |
194 |
} |
195 |
return false; |
196 |
} |
197 |
|
198 |
public boolean requestHasShift() { |
199 |
switch (type) {
|
200 |
case TYPE_PX_RESCALED_SHIFT:
|
201 |
case TYPE_PX_SHIFT:
|
202 |
case TYPE_WCOORDS_SHIFT:
|
203 |
return true; |
204 |
} |
205 |
return false; |
206 |
} |
207 |
|
208 |
public boolean requestIsPixelCoordinates() { |
209 |
switch (type) {
|
210 |
case TYPE_PX:
|
211 |
case TYPE_PX_SHIFT:
|
212 |
case TYPE_PX_RESCALED:
|
213 |
case TYPE_PX_RESCALED_SHIFT:
|
214 |
case TYPE_ENTIRE:
|
215 |
return true; |
216 |
} |
217 |
return false; |
218 |
} |
219 |
|
220 |
public boolean requestIsInWorldCoordinates() { |
221 |
switch (type) {
|
222 |
case TYPE_WCOORDS:
|
223 |
case TYPE_WCOORDS_RESCALED:
|
224 |
case TYPE_WCOORDS_SHIFT:
|
225 |
case TYPE_TILED:
|
226 |
return true; |
227 |
} |
228 |
return false; |
229 |
} |
230 |
|
231 |
public boolean requestIsRescaled() { |
232 |
switch (type) {
|
233 |
case TYPE_PX_RESCALED:
|
234 |
case TYPE_PX_RESCALED_SHIFT:
|
235 |
case TYPE_WCOORDS_RESCALED:
|
236 |
case TYPE_TILED:
|
237 |
return true; |
238 |
} |
239 |
return false; |
240 |
} |
241 |
|
242 |
/**
|
243 |
* Returns true if the request is trying apply supersampling, that is, the size of the result is
|
244 |
* bigger that the window of maximum resolution of this source
|
245 |
* @return
|
246 |
*/
|
247 |
public boolean isSupersamplingTheRequest() { |
248 |
if(!requestHasShift()) {
|
249 |
return (getBufWidth() > getAdjustedWidth() || getBufHeight() > getAdjustedHeight());
|
250 |
} |
251 |
return (getAdjustedBufWidth() > getAdjustedWidth() || getAdjustedBufHeight() > getAdjustedHeight());
|
252 |
} |
253 |
|
254 |
|
255 |
public RasterQuery clone() {
|
256 |
DefaultRasterQuery q = new DefaultRasterQuery();
|
257 |
q.type = type; |
258 |
q.pixelWindow = (Rectangle)pixelWindow.clone();
|
259 |
q.adjustToSrcExtent = adjustToSrcExtent; |
260 |
q.widthForResampling = widthForResampling; |
261 |
q.heightForResampling = heightForResampling; |
262 |
q.requestBoundingBox = requestBoundingBox != null ? requestBoundingBox.clone() : null; |
263 |
q.tileCol = tileCol; |
264 |
q.tileRow = tileRow; |
265 |
q.resolutionLevel = resolutionLevel; |
266 |
q.readOnly = readOnly; |
267 |
q.memoryBuffer = memoryBuffer; |
268 |
q.storeLastBuffer = storeLastBuffer; |
269 |
q.drawableBands = new int[drawableBands.length]; |
270 |
for (int i = 0; i < q.drawableBands.length; i++) { |
271 |
q.drawableBands[i] = drawableBands[i]; |
272 |
} |
273 |
q.supersamplingLoadingBuffer = supersamplingLoadingBuffer; |
274 |
q.noDataValueToFill = noDataValueToFill != null ? (NoData)noDataValueToFill.clone() : null; |
275 |
q.listener = listener; |
276 |
q.alphaBandNumber = alphaBandNumber; |
277 |
q.bandList = bandList != null ? (BandList)bandList.clone() : null; |
278 |
q.bufferForProviders = bufferForProviders; |
279 |
return q;
|
280 |
} |
281 |
|
282 |
//****************************************************
|
283 |
//*************Parameters calculation*****************
|
284 |
//****************************************************
|
285 |
|
286 |
/**
|
287 |
* Adjust the request in world coordinates to the data size
|
288 |
* @param q
|
289 |
*/
|
290 |
private void calculateAdjustedWCWindowFromWCWindow(AffineTransform at, int w, int h) { |
291 |
if(requestHasShift()) {
|
292 |
setAdjustedRequestBoundingBox(getRequestBoundingBox().clone()); |
293 |
} |
294 |
RasterUtils util = RasterLocator.getManager().getRasterUtils(); |
295 |
Extent adjustedDataExtent = util.calculateAdjustedView(getRequestBoundingBox(), at, w, h); |
296 |
setAdjustedRequestBoundingBox(adjustedDataExtent); |
297 |
} |
298 |
|
299 |
/**
|
300 |
* Adjust the request in pixel coordinates to the data size
|
301 |
* @param q
|
302 |
*/
|
303 |
private void calculateAdjustedPxSizeFromPxSize(int sourceWidth, int sourceHeight) { |
304 |
adjustedPixelWindow = (Rectangle)pixelWindow.clone();
|
305 |
|
306 |
if(requestHasShift())
|
307 |
return;
|
308 |
|
309 |
if(getAdjustedX() < 0) |
310 |
setAdjustedX(0);
|
311 |
if(getAdjustedY() < 0) |
312 |
setAdjustedY(0);
|
313 |
if((getAdjustedX() + getAdjustedWidth()) > sourceWidth)
|
314 |
setAdjustedWidth(sourceWidth - getX()); |
315 |
if((getAdjustedY() + getAdjustedHeight()) > sourceHeight)
|
316 |
setAdjustedHeight(sourceHeight - getAdjustedY()); |
317 |
} |
318 |
|
319 |
|
320 |
private void calculateBoundingBoxesFromPxRequest(RasterDataStore store) { |
321 |
Extent extent = new ExtentImpl(
|
322 |
store.rasterToWorld(new Point2D.Double(getX(), getY())), |
323 |
store.rasterToWorld(new Point2D.Double(getX() + getWidth(), getY() + getHeight()))); |
324 |
setRequestBoundingBox(extent); |
325 |
|
326 |
Extent adjustedExtent = new ExtentImpl(
|
327 |
store.rasterToWorld(new Point2D.Double(getAdjustedX(), getAdjustedY())), |
328 |
store.rasterToWorld(new Point2D.Double(getAdjustedX() + getAdjustedWidth(), getAdjustedY() + getAdjustedHeight()))); |
329 |
setAdjustedRequestBoundingBox(adjustedExtent); |
330 |
} |
331 |
|
332 |
private double round(double value) { |
333 |
double a = (value - (int)value); |
334 |
return (a > 0.95 || a < 0.05) ? Math.round(value) : value; |
335 |
} |
336 |
|
337 |
private void calculateOutputSizeFromPxWindow(RasterDataStore store) { |
338 |
if(!requestIsRescaled()) {
|
339 |
setBufHeight(getHeight()); |
340 |
setBufWidth(getWidth()); |
341 |
setAdjustedBufWidth(getAdjustedWidth()); |
342 |
setAdjustedBufHeight(getAdjustedHeight()); |
343 |
} else {
|
344 |
double scaleWidth = (double)getWidth() / getBufWidth(); |
345 |
double scaleHeight = (double)getHeight() / getBufHeight(); |
346 |
setAdjustedBufWidth((int)Math.ceil(round(getAdjustedWidth() / scaleWidth))); |
347 |
setAdjustedBufHeight((int)Math.ceil(round(getAdjustedHeight() / scaleHeight))); |
348 |
} |
349 |
} |
350 |
|
351 |
private void calculatePxWindowsFromBoundingBoxes(RasterDataStore store) { |
352 |
Extent requestBBox = getRequestBoundingBox(); |
353 |
Point2D ul = store.worldToRaster(requestBBox.getUL());
|
354 |
Point2D lr = store.worldToRaster(requestBBox.getLR());
|
355 |
int w = (int)Math.ceil(Math.abs(ul.getX() - lr.getX())); |
356 |
int h = (int)Math.ceil(Math.abs(ul.getY() - lr.getY())); |
357 |
Rectangle r = new Rectangle((int)ul.getX(), (int)ul.getY(), w, h); |
358 |
pixelWindow = r; |
359 |
|
360 |
Extent adjustedBBox = getAdjustedRequestBoundingBox(); |
361 |
ul = store.worldToRaster(adjustedBBox.getUL()); |
362 |
lr = store.worldToRaster(adjustedBBox.getLR()); |
363 |
w = (int)Math.ceil(Math.abs(ul.getX() - lr.getX())); |
364 |
h = (int)Math.ceil(Math.abs(ul.getY() - lr.getY())); |
365 |
r = new Rectangle((int)ul.getX(), (int)ul.getY(), w, h); |
366 |
adjustedPixelWindow = r; |
367 |
} |
368 |
|
369 |
/**
|
370 |
* <p>
|
371 |
* If the request is being supersampled, then the buffer size will be bigger than the pixel window.
|
372 |
* In this case the provider will receive a buffer in 1:1 scale. The supersampling function will be
|
373 |
* in the client (supersampling deactivated) or in the store (supersampling activated).
|
374 |
* </p><p>
|
375 |
* The buffer will have one pixel more because the resampling cuts the first pixel by the beginning and
|
376 |
* shows the last pixel by the end.
|
377 |
* </p>
|
378 |
* @param store
|
379 |
*/
|
380 |
private void supersampledBuffers(RasterDataStore store) { |
381 |
//Si se est? pidiendo supersampleo el provider tiene que recibir un buffer de tama?o igual al n?mero real de
|
382 |
//pixels del ?rea, por ello habr? que cambiar el adjustedbufwidth y adjustedBufHeight. Adem?s habr? que variar
|
383 |
//el extent del provider y la ventana en pixeles para que todo cuadre. El objetivo es que cuando el cliente (Render)
|
384 |
//supersamplee no le queden huecos en blanco porque le falte el ?ltimo pixel.
|
385 |
if((getAdjustedX() + getAdjustedWidth()) < store.getWidth())
|
386 |
setAdjustedWidth(getAdjustedWidth() + 1);
|
387 |
if((getAdjustedY() + getAdjustedHeight()) < store.getHeight())
|
388 |
setAdjustedHeight(getAdjustedHeight() + 1);
|
389 |
setAdjustedBufWidth(getAdjustedWidth()); |
390 |
setAdjustedBufHeight(getAdjustedHeight()); |
391 |
Point2D ul = store.rasterToWorld(new Point2D.Double(adjustedPixelWindow.getX(), adjustedPixelWindow.getY())); |
392 |
Point2D lr = store.rasterToWorld(new Point2D.Double( |
393 |
adjustedPixelWindow.getX() + adjustedPixelWindow.getWidth(), |
394 |
adjustedPixelWindow.getY() + adjustedPixelWindow.getHeight())); |
395 |
setAdjustedRequestBoundingBox(new ExtentImpl(ul, lr));
|
396 |
} |
397 |
|
398 |
/**
|
399 |
* Giving a world coordinates, a buffer size and a original raster size. If the
|
400 |
* buffer is bigger than the window requested in the source raster (supersampling),
|
401 |
* then it means that each pixel of the raster will be written several times in
|
402 |
* the destination buffer.
|
403 |
*
|
404 |
* This function calculates the shift in pixels en X and Y coordinate that
|
405 |
* correspond to the first pixel, due to this pixel won't be drawn entirely.
|
406 |
*
|
407 |
* This operation is needed when the client wants to apply suppersampling on the
|
408 |
* result of a request.
|
409 |
*/
|
410 |
private void calculateStep(RasterDataStore store) { |
411 |
Point2D tl = store.worldToRaster(getAdjustedRequestBoundingBox().getUL());
|
412 |
Point2D br = store.worldToRaster(getAdjustedRequestBoundingBox().getLR());
|
413 |
|
414 |
//Se obtiene el tama?o de la petici?n original pero ajustada ya que adjustedBufferWidth y adjustedBufferHeight
|
415 |
//habr?n sido modificados para que no excedan el tama?o de la ventana, ya que el provider no debe supersamplear
|
416 |
double scaleWidth = (double)getWidth() / getBufWidth(); |
417 |
double scaleHeight = (double)getHeight() / getBufHeight(); |
418 |
int srcOriginalAdjustedWidth = (int)Math.ceil(round(getAdjustedWidth() / scaleWidth)); |
419 |
int srcOriginalAdjustedHeight = (int)Math.ceil(round(getAdjustedHeight() / scaleHeight)); |
420 |
|
421 |
double wPx = (srcOriginalAdjustedWidth / Math.abs(br.getX() - tl.getX())); |
422 |
double hPx = (srcOriginalAdjustedHeight / Math.abs(br.getY() - tl.getY())); |
423 |
|
424 |
int x = (int)((tl.getX() > br.getX()) ? Math.floor(br.getX()) : Math.floor(tl.getX())); |
425 |
int y = (int)((tl.getY() > br.getY()) ? Math.floor(br.getY()) : Math.floor(tl.getY())); |
426 |
|
427 |
double a = (tl.getX() > br.getX()) ? (Math.abs(br.getX() - x)) : (Math.abs(tl.getX() - x)); |
428 |
double b = (tl.getY() > br.getY()) ? (Math.abs(br.getY() - y)) : (Math.abs(tl.getY() - y)); |
429 |
|
430 |
double stpX = (int)((a * srcOriginalAdjustedWidth) / Math.abs(br.getX() - tl.getX())); |
431 |
double stpY = (int)((b * srcOriginalAdjustedHeight) / Math.abs(br.getY() - tl.getY())); |
432 |
|
433 |
step = new double[]{stpX, stpY, wPx, hPx}; |
434 |
} |
435 |
|
436 |
private Buffer createBuffer(RasterDataStore store) throws QueryException { |
437 |
if(isReadOnly()) {
|
438 |
bufferForProviders = DefaultRasterManager.getInstance().createReadOnlyBuffer( |
439 |
store.getDataType()[0], getAdjustedWidth(), getAdjustedHeight(), store.getBandCount());
|
440 |
try {
|
441 |
((RasterReadOnlyBuffer)bufferForProviders).setBufferParams((QueryableRaster)this,
|
442 |
getAdjustedX(), |
443 |
getAdjustedY(), |
444 |
getAdjustedX() + getAdjustedBufWidth() - 1,
|
445 |
getAdjustedY() + getAdjustedBufHeight() - 1,
|
446 |
bandList); |
447 |
} catch (FileNotExistsException e) {
|
448 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
449 |
} catch (NotSupportedExtensionException e) {
|
450 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
451 |
} catch (InvalidSetViewException e) {
|
452 |
throw new QueryException("Error setting buffer params in a RO buffer", e); |
453 |
} |
454 |
} else {
|
455 |
BandList bandList = buildDrawableBandList(store.getBands()); |
456 |
|
457 |
if(isMemoryBuffer())
|
458 |
bufferForProviders = DefaultRasterManager.getInstance().createMemoryBuffer( |
459 |
store.getDataType()[0], getAdjustedBufWidth(), getAdjustedBufHeight(), bandList.getDrawableBandsCount(), true); |
460 |
else
|
461 |
bufferForProviders = DefaultRasterManager.getInstance().createBuffer( |
462 |
store.getDataType()[0], getAdjustedBufWidth(), getAdjustedBufHeight(), bandList.getDrawableBandsCount(), true); |
463 |
} |
464 |
|
465 |
bufferForProviders.setDataExtent(getAdjustedRequestBoundingBox().toRectangle2D()); |
466 |
return bufferForProviders;
|
467 |
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* Builds a list o bands to draw from the store band list and
|
472 |
* the <code>drawablebands</code> asigned by the user
|
473 |
* @param drawableBands
|
474 |
* @param storeBandList
|
475 |
* @return
|
476 |
*/
|
477 |
public BandList buildDrawableBandList(BandList storeBandList) {
|
478 |
bandList = (BandList)storeBandList.clone(); |
479 |
//If drawableBands is null then the bandList is the same that the source band list
|
480 |
if(drawableBands != null) |
481 |
bandList.setDrawableBands(drawableBands); |
482 |
return bandList;
|
483 |
} |
484 |
|
485 |
private boolean isAdjustingPixelWindowToStore(RasterDataStore store) { |
486 |
return (pixelWindow.getX() >= 0 && |
487 |
pixelWindow.getY() >= 0 &&
|
488 |
pixelWindow.getWidth() <= store.getWidth() && |
489 |
pixelWindow.getHeight() <= store.getHeight()); |
490 |
} |
491 |
|
492 |
private boolean isBufferSizeDefined() { |
493 |
return (widthForResampling != -1 && heightForResampling != -1); |
494 |
} |
495 |
|
496 |
private boolean isAdjustingRequestBBoxToStore(RasterDataStore store) { |
497 |
Extent intersection = requestBoundingBox.intersection(store.getExtent()); |
498 |
return intersection.equals(store.getExtent());
|
499 |
} |
500 |
|
501 |
private void calculateRequestType(RasterDataStore store) { |
502 |
if(type == TYPE_ENTIRE) {
|
503 |
pixelWindow = new Rectangle(0, 0, (int)store.getWidth(), (int)store.getHeight()); |
504 |
return;
|
505 |
} |
506 |
|
507 |
if(!adjustToSrcExtent) {
|
508 |
if(type == TYPE_PX) {
|
509 |
if(isAdjustingPixelWindowToStore(store)) {
|
510 |
if(isBufferSizeDefined())
|
511 |
this.type = TYPE_PX_RESCALED;
|
512 |
else
|
513 |
this.type = TYPE_PX;
|
514 |
} else {
|
515 |
if(isBufferSizeDefined())
|
516 |
this.type = TYPE_PX_RESCALED_SHIFT;
|
517 |
else
|
518 |
this.type = TYPE_PX_SHIFT;
|
519 |
} |
520 |
} |
521 |
if(type == TYPE_WCOORDS) {
|
522 |
if(isBufferSizeDefined()) {
|
523 |
if(isAdjustingRequestBBoxToStore(store))
|
524 |
this.type = TYPE_WCOORDS_RESCALED;
|
525 |
else
|
526 |
this.type = TYPE_WCOORDS_SHIFT;
|
527 |
} //else TYPE_WCOORDS
|
528 |
} |
529 |
} else {
|
530 |
if(type == TYPE_PX) {
|
531 |
if(isBufferSizeDefined())
|
532 |
this.type = TYPE_PX_RESCALED;
|
533 |
} |
534 |
if(type == TYPE_WCOORDS) {
|
535 |
if(isBufferSizeDefined())
|
536 |
this.type = TYPE_WCOORDS_RESCALED;
|
537 |
//else TYPE_WCOORDS
|
538 |
} |
539 |
} |
540 |
} |
541 |
|
542 |
/**
|
543 |
* Calculates the parameters using the base request. That is, bounding boxes, data windows,
|
544 |
* output size, steps and parameters for supersampling, band lists and buffers. This parameters
|
545 |
* are calculated adjusting to the source limits. For this reason, the request parameters are
|
546 |
* saved in other variables, to allow calculate the displacement and resampling whether it was
|
547 |
* necessary
|
548 |
* @param store
|
549 |
* @throws QueryException
|
550 |
*/
|
551 |
public void calculateParameters(RasterDataStore store) throws QueryException { |
552 |
calculateRequestType(store); |
553 |
|
554 |
//Parameters for requests in pixels
|
555 |
if(requestIsPixelCoordinates()) {
|
556 |
calculateAdjustedPxSizeFromPxSize((int)store.getWidth(), (int)store.getHeight()); |
557 |
calculateBoundingBoxesFromPxRequest(store); |
558 |
} |
559 |
|
560 |
//Parameters for requests in world coordinates
|
561 |
if(requestIsInWorldCoordinates()) {
|
562 |
calculateAdjustedWCWindowFromWCWindow(store.getAffineTransform(), (int)store.getWidth(), (int)store.getHeight()); |
563 |
calculatePxWindowsFromBoundingBoxes(store); |
564 |
} |
565 |
|
566 |
//Output
|
567 |
calculateOutputSizeFromPxWindow(store); |
568 |
|
569 |
//Supersampling parameters
|
570 |
step = null;
|
571 |
if(isSupersamplingTheRequest()) {
|
572 |
calculateStep(store); |
573 |
supersampledBuffers(store); |
574 |
} |
575 |
|
576 |
//Bands and buffers
|
577 |
buildDrawableBandList(store.getBands()); |
578 |
createBuffer(store); |
579 |
} |
580 |
|
581 |
//****************************************************
|
582 |
//*********Implementing DataQuery methods*************
|
583 |
//****************************************************
|
584 |
|
585 |
public Object getQueryParameter(String name) { |
586 |
return null; |
587 |
} |
588 |
|
589 |
public double getScale() { |
590 |
return 0; |
591 |
} |
592 |
|
593 |
public void setQueryParameter(String name, Object value) { |
594 |
|
595 |
} |
596 |
|
597 |
public void setScale(double scale) { |
598 |
|
599 |
} |
600 |
|
601 |
//****************************************************
|
602 |
//*********Implementing Persistent methods************
|
603 |
//****************************************************
|
604 |
|
605 |
public void loadFromState(PersistentState state) |
606 |
throws PersistenceException {
|
607 |
|
608 |
} |
609 |
|
610 |
public void saveToState(PersistentState state) throws PersistenceException { |
611 |
|
612 |
} |
613 |
|
614 |
//****************************************************
|
615 |
//**************Getters and Setters*******************
|
616 |
//****************************************************
|
617 |
|
618 |
public int getType() { |
619 |
return type;
|
620 |
} |
621 |
|
622 |
public void storeLastBuffer(boolean store) { |
623 |
this.storeLastBuffer = store;
|
624 |
} |
625 |
|
626 |
/**
|
627 |
* The user can told if the buffer will be stored or not in the RasterDatasource.
|
628 |
* @return store
|
629 |
*/
|
630 |
public boolean isStoredLastBuffer() { |
631 |
return storeLastBuffer;
|
632 |
} |
633 |
|
634 |
public void setAdjustToExtent(boolean adjustToExtent) { |
635 |
this.adjustToSrcExtent = adjustToExtent;
|
636 |
} |
637 |
|
638 |
public boolean isAdjustToExtent() { |
639 |
return adjustToSrcExtent;
|
640 |
} |
641 |
|
642 |
public int[] getDrawableBands() { |
643 |
return drawableBands;
|
644 |
} |
645 |
|
646 |
public void setAllDrawableBands() { |
647 |
this.drawableBands = null; |
648 |
} |
649 |
|
650 |
public void setDrawableBands(int[] drawableBands) { |
651 |
this.drawableBands = drawableBands;
|
652 |
} |
653 |
|
654 |
public void setReadOnly(boolean readOnly) { |
655 |
this.readOnly = readOnly;
|
656 |
} |
657 |
|
658 |
/**
|
659 |
* Returns true if the supersampling is enable and false if it is disable
|
660 |
* Rendering from gvSIG, the resampling is always disable because if the request
|
661 |
* is greater than 1:1 scale the resampling will be done in the client <code>Render</code>.
|
662 |
* The default value is disable.
|
663 |
*/
|
664 |
public boolean isSupersamplingOptionActive() { |
665 |
return supersamplingLoadingBuffer;
|
666 |
} |
667 |
|
668 |
/**
|
669 |
* Enables or disables the supersampling loading the buffer. Rendering from gvSIG,
|
670 |
* the resampling is always disable because if the request is greater than 1:1 scale
|
671 |
* the resampling will be done in the client <code>Render</code>
|
672 |
*/
|
673 |
public void setSupersamplingOption(boolean supersamplingLoadingBuffer) { |
674 |
this.supersamplingLoadingBuffer = supersamplingLoadingBuffer;
|
675 |
} |
676 |
|
677 |
public void setMemoryBuffer(boolean memoryBuffer) { |
678 |
this.memoryBuffer = memoryBuffer;
|
679 |
} |
680 |
|
681 |
/**
|
682 |
* Obtiene el flag que dice si la carga del siguiente buffer es en memoria
|
683 |
* @return memory true si la siguiente carga de buffer se hace en memoria y false se deja decidir al dataset
|
684 |
* el tipo de buffer
|
685 |
*/
|
686 |
public boolean isMemoryBuffer() { |
687 |
return memoryBuffer;
|
688 |
} |
689 |
|
690 |
public void setNoDataToFill(NoData noData) { |
691 |
this.noDataValueToFill = noData;
|
692 |
} |
693 |
|
694 |
public void setAlphaBand(int bandNumber) { |
695 |
this.alphaBandNumber = bandNumber;
|
696 |
} |
697 |
|
698 |
public int getAlphaBandNumber() { |
699 |
return alphaBandNumber;
|
700 |
} |
701 |
|
702 |
public NoData getNoDataValueToFill() {
|
703 |
return this.noDataValueToFill; |
704 |
} |
705 |
|
706 |
public void setRequestPixelWindow(Rectangle pixelWindow) { |
707 |
this.pixelWindow = pixelWindow;
|
708 |
} |
709 |
|
710 |
public int getX() { |
711 |
return (int)pixelWindow.getX(); |
712 |
} |
713 |
|
714 |
public int getY() { |
715 |
return (int)pixelWindow.getY(); |
716 |
} |
717 |
|
718 |
public int getWidth() { |
719 |
return (int)pixelWindow.getWidth(); |
720 |
} |
721 |
|
722 |
public int getHeight() { |
723 |
return (int)pixelWindow.getHeight(); |
724 |
} |
725 |
|
726 |
public void setX(int x) { |
727 |
pixelWindow.setLocation(x, getY()); |
728 |
} |
729 |
|
730 |
public void setY(int y) { |
731 |
pixelWindow.setLocation(getX(), y); |
732 |
} |
733 |
|
734 |
public void setWidth(int w) { |
735 |
pixelWindow.setSize(w, getWidth()); |
736 |
} |
737 |
|
738 |
public void setHeight(int h) { |
739 |
pixelWindow.setSize(getHeight(), h); |
740 |
} |
741 |
|
742 |
public int getAdjustedX() { |
743 |
return (int)adjustedPixelWindow.getX(); |
744 |
} |
745 |
|
746 |
public int getAdjustedY() { |
747 |
return (int)adjustedPixelWindow.getY(); |
748 |
} |
749 |
|
750 |
public int getAdjustedWidth() { |
751 |
return (int)adjustedPixelWindow.getWidth(); |
752 |
} |
753 |
|
754 |
public int getAdjustedHeight() { |
755 |
return (int)adjustedPixelWindow.getHeight(); |
756 |
} |
757 |
|
758 |
public void setAdjustedX(int x) { |
759 |
adjustedPixelWindow.setLocation(x, getAdjustedY()); |
760 |
} |
761 |
|
762 |
public void setAdjustedY(int y) { |
763 |
adjustedPixelWindow.setLocation(getAdjustedX(), y); |
764 |
} |
765 |
|
766 |
public void setAdjustedWidth(int w) { |
767 |
adjustedPixelWindow.setSize(w, getAdjustedHeight()); |
768 |
} |
769 |
|
770 |
public void setAdjustedHeight(int h) { |
771 |
adjustedPixelWindow.setSize(getAdjustedWidth(), h); |
772 |
} |
773 |
|
774 |
/**
|
775 |
* Gets the window of the request in pixel coordinates
|
776 |
*/
|
777 |
public Rectangle getRequestPxWindow() { |
778 |
return pixelWindow;
|
779 |
} |
780 |
|
781 |
/**
|
782 |
* Gets the adjusted window of the request in pixel coordinates
|
783 |
*/
|
784 |
public Rectangle getAdjustedRequestPxWindow() { |
785 |
return adjustedPixelWindow;
|
786 |
} |
787 |
|
788 |
/**
|
789 |
* Gets a bounding box of a request in world coordinates.
|
790 |
*/
|
791 |
public Extent getRequestBoundingBox() {
|
792 |
return requestBoundingBox;
|
793 |
} |
794 |
|
795 |
/**
|
796 |
* Sets a bounding box of a request in world coordinates.
|
797 |
* @param requestBoundingBox
|
798 |
*/
|
799 |
public void setRequestBoundingBox(Extent requestBoundingBox) { |
800 |
this.requestBoundingBox = requestBoundingBox;
|
801 |
} |
802 |
|
803 |
/**
|
804 |
* Gets a bounding box of a request in world coordinates adjusted to the bounding box of the source.
|
805 |
*/
|
806 |
public Extent getAdjustedRequestBoundingBox() {
|
807 |
return adjustedBoundingBox;
|
808 |
} |
809 |
|
810 |
/**
|
811 |
* Sets a bounding box of a request in world coordinates adjusted to the bounding box of the source.
|
812 |
* @param requestBoundingBox
|
813 |
*/
|
814 |
public void setAdjustedRequestBoundingBox(Extent adjustedBoundingBox) { |
815 |
this.adjustedBoundingBox = adjustedBoundingBox;
|
816 |
} |
817 |
|
818 |
public int getBufWidth() { |
819 |
return widthForResampling;
|
820 |
} |
821 |
|
822 |
public int getBufHeight() { |
823 |
return heightForResampling;
|
824 |
} |
825 |
|
826 |
public void setBufHeight(int h) { |
827 |
widthForResampling = h; |
828 |
} |
829 |
|
830 |
public void setBufWidth(int w) { |
831 |
heightForResampling = w; |
832 |
} |
833 |
|
834 |
public int getAdjustedBufWidth() { |
835 |
return adjustedBufferWidth;
|
836 |
} |
837 |
|
838 |
public int getAdjustedBufHeight() { |
839 |
return adjustedBufferHeight;
|
840 |
} |
841 |
|
842 |
public void setAdjustedBufHeight(int h) { |
843 |
adjustedBufferHeight = h; |
844 |
} |
845 |
|
846 |
public void setAdjustedBufWidth(int w) { |
847 |
adjustedBufferWidth = w; |
848 |
} |
849 |
|
850 |
public boolean isReadOnly() { |
851 |
return readOnly;
|
852 |
} |
853 |
|
854 |
public TileListener getTileListener() {
|
855 |
return listener;
|
856 |
} |
857 |
|
858 |
public void setTileListener(TileListener listener) { |
859 |
this.listener = listener;
|
860 |
} |
861 |
|
862 |
public Time getTime() { |
863 |
return time;
|
864 |
} |
865 |
|
866 |
public void setTime(Time time) { |
867 |
this.time = time;
|
868 |
} |
869 |
|
870 |
public int getTileRow() { |
871 |
return tileRow;
|
872 |
} |
873 |
|
874 |
public int getTileCol() { |
875 |
return tileCol;
|
876 |
} |
877 |
|
878 |
public CacheStruct getCacheStruct() {
|
879 |
return cacheStruct;
|
880 |
} |
881 |
|
882 |
public void setCacheStruct(CacheStruct cacheStruct) { |
883 |
this.cacheStruct = cacheStruct;
|
884 |
} |
885 |
|
886 |
public int getResolutionLevel() { |
887 |
return resolutionLevel;
|
888 |
} |
889 |
|
890 |
public void setTaskStatus(TaskStatus taskStatus) { |
891 |
this.taskStatus = taskStatus;
|
892 |
} |
893 |
|
894 |
public BandList getBandList() {
|
895 |
return bandList;
|
896 |
} |
897 |
|
898 |
public void setBandList(BandList bandList) { |
899 |
this.bandList = bandList;
|
900 |
} |
901 |
|
902 |
/**
|
903 |
* Buffer loaded by the provider and created by the store
|
904 |
* @return
|
905 |
*/
|
906 |
public Buffer getBufferForProviders() { |
907 |
return bufferForProviders;
|
908 |
} |
909 |
|
910 |
public void setBufferForProviders(Buffer buffer) throws QueryException { |
911 |
if(buffer.getWidth() != getAdjustedBufWidth() || buffer.getHeight() != getAdjustedBufHeight())
|
912 |
throw new QueryException("Error in buffer size"); |
913 |
this.bufferForProviders = buffer;
|
914 |
} |
915 |
|
916 |
/**
|
917 |
* Buffer without adjust to the source limits. This is useful for
|
918 |
* request with shift. Normally the result will have frames with nodata
|
919 |
* values
|
920 |
* @return
|
921 |
*/
|
922 |
/*public Buffer getBufferWithoutAdjust() {
|
923 |
return bufferWithoutAdjust;
|
924 |
}*/
|
925 |
|
926 |
/**
|
927 |
* Buffer without adjust to the source limits. This is useful for
|
928 |
* request with shift. Normally the result will have frames with nodata
|
929 |
* values
|
930 |
*/
|
931 |
/*public void setBufferWithoutAdjust(Buffer buffer) {
|
932 |
this.bufferWithoutAdjust = buffer;
|
933 |
}*/
|
934 |
|
935 |
public double[] getStep() { |
936 |
return step;
|
937 |
} |
938 |
|
939 |
/**
|
940 |
* Gets the task status
|
941 |
*/
|
942 |
public TaskStatus getTaskStatus() {
|
943 |
return taskStatus;
|
944 |
} |
945 |
} |