Revision 2236 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
DefaultRasterQuery.java | ||
---|---|---|
34 | 34 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
35 | 35 |
*/ |
36 | 36 |
public class DefaultRasterQuery implements RasterQuery, SpiRasterQuery { |
37 |
public static final int TYPE_UNDEFINED = -1; |
|
37 | 38 |
public static final int TYPE_ENTIRE = 0; |
38 | 39 |
public static final int TYPE_WCOORDS = 1; |
39 | 40 |
public static final int TYPE_WCOORDS_RESCALED = 2; |
... | ... | |
65 | 66 |
*/ |
66 | 67 |
private Extent adjustedBoundingBox = null; |
67 | 68 |
|
68 |
private int widthForResampling = 0;
|
|
69 |
private int heightForResampling = 0;
|
|
69 |
private int widthForResampling = -1;
|
|
70 |
private int heightForResampling = -1;
|
|
70 | 71 |
/* |
71 | 72 |
* If the request is adjusted to the input source this width is the same to widthForResampling else |
72 | 73 |
* the provider has to receive the right buffer size for the request, so this adjustedWidth will |
... | ... | |
93 | 94 |
private boolean storeLastBuffer = false; |
94 | 95 |
private Time time = null; |
95 | 96 |
|
97 |
|
|
98 |
private boolean supersamplingLoadingBuffer = false; |
|
96 | 99 |
/** |
97 |
* Activa o desactiva el supersampleo en la carga del buffer. |
|
98 |
*/ |
|
99 |
private boolean supersamplingLoadingBuffer = true; |
|
100 |
/** |
|
101 | 100 |
* Valor NoData con el que se rellenan las celdas cuando adjustToExtent es false |
102 | 101 |
*/ |
103 | 102 |
private NoData noDataValueToFill = null; |
... | ... | |
110 | 109 |
//Parameters only for providers |
111 | 110 |
private BandList bandList = null; |
112 | 111 |
private Buffer bufferForProviders = null; |
113 |
private Buffer bufferWithoutAdjust = null; |
|
112 |
//private Buffer bufferWithoutAdjust = null;
|
|
114 | 113 |
|
115 | 114 |
|
116 | 115 |
//**************************************************** |
... | ... | |
123 | 122 |
|
124 | 123 |
public void setAreaOfInterest(Rectangle pixelWindow) { |
125 | 124 |
this.pixelWindow = pixelWindow; |
126 |
if(adjustToSrcExtent) |
|
127 |
this.type = TYPE_PX; |
|
128 |
else |
|
129 |
this.type = TYPE_PX_SHIFT; |
|
125 |
this.type = TYPE_PX; |
|
130 | 126 |
} |
131 | 127 |
|
132 | 128 |
public void setAreaOfInterest(Rectangle pixelWindow, int bufWidth, int bufHeight) { |
133 | 129 |
this.pixelWindow = pixelWindow; |
134 | 130 |
this.widthForResampling = bufWidth; |
135 | 131 |
this.heightForResampling = bufHeight; |
136 |
if(adjustToSrcExtent) |
|
137 |
this.type = TYPE_PX_RESCALED; |
|
138 |
else |
|
139 |
this.type = TYPE_PX_RESCALED_SHIFT; |
|
132 |
this.type = TYPE_PX; |
|
140 | 133 |
} |
141 | 134 |
|
142 | 135 |
public void setAreaOfInterest(Extent requestBoundingBox, int bufWidth, int bufHeight) { |
143 | 136 |
this.widthForResampling = bufWidth; |
144 | 137 |
this.heightForResampling = bufHeight; |
145 | 138 |
this.requestBoundingBox = requestBoundingBox; |
146 |
if(adjustToSrcExtent) { |
|
147 |
this.type = TYPE_WCOORDS_RESCALED; |
|
148 |
} else { |
|
149 |
this.type = TYPE_WCOORDS_SHIFT; |
|
150 |
} |
|
139 |
this.type = TYPE_WCOORDS; |
|
151 | 140 |
} |
152 | 141 |
|
153 | 142 |
public void setAreaOfInterest(Extent boundingBox) { |
... | ... | |
233 | 222 |
case TYPE_WCOORDS: |
234 | 223 |
case TYPE_WCOORDS_RESCALED: |
235 | 224 |
case TYPE_WCOORDS_SHIFT: |
225 |
case TYPE_TILED: |
|
236 | 226 |
return true; |
237 | 227 |
} |
238 | 228 |
return false; |
... | ... | |
250 | 240 |
} |
251 | 241 |
|
252 | 242 |
/** |
253 |
* Returns true if the request is trying of supersampler, that is, the size of the result is
|
|
243 |
* Returns true if the request is trying apply supersampling, that is, the size of the result is
|
|
254 | 244 |
* bigger that the window of maximum resolution of this source |
255 | 245 |
* @return |
256 | 246 |
*/ |
257 |
private boolean isSupersamplingTheRequest() {
|
|
247 |
public boolean isSupersamplingTheRequest() {
|
|
258 | 248 |
if(!requestHasShift()) { |
259 | 249 |
return (getBufWidth() > getAdjustedWidth() || getBufHeight() > getAdjustedHeight()); |
260 | 250 |
} |
... | ... | |
486 | 476 |
*/ |
487 | 477 |
public BandList buildDrawableBandList(BandList storeBandList) { |
488 | 478 |
bandList = (BandList)storeBandList.clone(); |
489 |
bandList.setDrawableBands(drawableBands); |
|
479 |
//If drawableBands is null then the bandList is the same that the source band list |
|
480 |
if(drawableBands != null) |
|
481 |
bandList.setDrawableBands(drawableBands); |
|
490 | 482 |
return bandList; |
491 | 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 |
} |
|
492 | 541 |
|
493 | 542 |
/** |
494 | 543 |
* Calculates the parameters using the base request. That is, bounding boxes, data windows, |
495 |
* output size, steps and parameters for supersampling, band lists and buffers. |
|
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 |
|
496 | 548 |
* @param store |
497 | 549 |
* @throws QueryException |
498 | 550 |
*/ |
499 | 551 |
public void calculateParameters(RasterDataStore store) throws QueryException { |
500 |
if(type == TYPE_ENTIRE) { //This is the only type that does not have coordinates assigned |
|
501 |
pixelWindow = new Rectangle(0, 0, (int)store.getWidth(), (int)store.getHeight()); |
|
502 |
} |
|
552 |
calculateRequestType(store); |
|
503 | 553 |
|
504 | 554 |
//Parameters for requests in pixels |
505 | 555 |
if(requestIsPixelCoordinates()) { |
... | ... | |
508 | 558 |
} |
509 | 559 |
|
510 | 560 |
//Parameters for requests in world coordinates |
511 |
if(requestIsInWorldCoordinates() || type == TYPE_TILED) {
|
|
561 |
if(requestIsInWorldCoordinates()) { |
|
512 | 562 |
calculateAdjustedWCWindowFromWCWindow(store.getAffineTransform(), (int)store.getWidth(), (int)store.getHeight()); |
513 | 563 |
calculatePxWindowsFromBoundingBoxes(store); |
514 | 564 |
} |
... | ... | |
564 | 614 |
//**************************************************** |
565 | 615 |
//**************Getters and Setters******************* |
566 | 616 |
//**************************************************** |
567 |
|
|
617 |
|
|
568 | 618 |
public int getType() { |
569 | 619 |
return type; |
570 | 620 |
} |
571 | 621 |
|
572 |
public void setType(int type) { |
|
573 |
this.type = type; |
|
574 |
} |
|
575 |
|
|
576 | 622 |
public void storeLastBuffer(boolean store) { |
577 | 623 |
this.storeLastBuffer = store; |
578 | 624 |
} |
... | ... | |
609 | 655 |
this.readOnly = readOnly; |
610 | 656 |
} |
611 | 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 |
*/ |
|
612 | 664 |
public boolean isSupersamplingOptionActive() { |
613 | 665 |
return supersamplingLoadingBuffer; |
614 | 666 |
} |
615 | 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 |
*/ |
|
616 | 673 |
public void setSupersamplingOption(boolean supersamplingLoadingBuffer) { |
617 | 674 |
this.supersamplingLoadingBuffer = supersamplingLoadingBuffer; |
618 | 675 |
} |
... | ... | |
645 | 702 |
public NoData getNoDataValueToFill() { |
646 | 703 |
return this.noDataValueToFill; |
647 | 704 |
} |
705 |
|
|
706 |
public void setRequestPixelWindow(Rectangle pixelWindow) { |
|
707 |
this.pixelWindow = pixelWindow; |
|
708 |
} |
|
648 | 709 |
|
649 | 710 |
public int getX() { |
650 | 711 |
return (int)pixelWindow.getX(); |
... | ... | |
846 | 907 |
return bufferForProviders; |
847 | 908 |
} |
848 | 909 |
|
849 |
/** |
|
850 |
* Buffer loaded by the provider and created by the store |
|
851 |
* @return |
|
852 |
*/ |
|
853 |
public void setBufferForProviders(Buffer buffer) { |
|
910 |
public void setBufferForProviders(Buffer buffer) throws QueryException { |
|
911 |
if(buffer.getWidth() != getAdjustedBufWidth() || buffer.getHeight() != getAdjustedBufHeight()) |
|
912 |
throw new QueryException("Error in buffer size"); |
|
854 | 913 |
this.bufferForProviders = buffer; |
855 | 914 |
} |
856 | 915 |
|
... | ... | |
860 | 919 |
* values |
861 | 920 |
* @return |
862 | 921 |
*/ |
863 |
public Buffer getBufferWithoutAdjust() { |
|
922 |
/*public Buffer getBufferWithoutAdjust() {
|
|
864 | 923 |
return bufferWithoutAdjust; |
865 |
} |
|
924 |
}*/
|
|
866 | 925 |
|
867 | 926 |
/** |
868 | 927 |
* Buffer without adjust to the source limits. This is useful for |
869 | 928 |
* request with shift. Normally the result will have frames with nodata |
870 | 929 |
* values |
871 | 930 |
*/ |
872 |
public void setBufferWithoutAdjust(Buffer buffer) { |
|
931 |
/*public void setBufferWithoutAdjust(Buffer buffer) {
|
|
873 | 932 |
this.bufferWithoutAdjust = buffer; |
874 |
} |
|
933 |
}*/
|
|
875 | 934 |
|
876 | 935 |
public double[] getStep() { |
877 | 936 |
return step; |
Also available in: Unified diff