Revision 13359
trunk/libraries/libRaster/src-test/org/gvsig/raster/buffer/TestAdjustToExtent.java | ||
---|---|---|
1 |
/* gvSIG. Sistema de Informaci�n Geogr�fica de la Generalitat Valenciana |
|
2 |
* |
|
3 |
* Copyright (C) 2007 IVER T.I. and Generalitat Valenciana. |
|
4 |
* |
|
5 |
* This program is free software; you can redistribute it and/or |
|
6 |
* modify it under the terms of the GNU General Public License |
|
7 |
* as published by the Free Software Foundation; either version 2 |
|
8 |
* of the License, or (at your option) any later version. |
|
9 |
* |
|
10 |
* This program is distributed in the hope that it will be useful, |
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
13 |
* GNU General Public License for more details. |
|
14 |
* |
|
15 |
* You should have received a copy of the GNU General Public License |
|
16 |
* along with this program; if not, write to the Free Software |
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
18 |
*/ |
|
19 |
package org.gvsig.raster.buffer; |
|
20 |
|
|
21 |
import junit.framework.TestCase; |
|
22 |
|
|
23 |
import org.gvsig.raster.RasterLibrary; |
|
24 |
import org.gvsig.raster.dataset.IBuffer; |
|
25 |
import org.gvsig.raster.dataset.InvalidSetViewException; |
|
26 |
import org.gvsig.raster.dataset.MultiRasterDataset; |
|
27 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
28 |
import org.gvsig.raster.dataset.RasterDriverException; |
|
29 |
|
|
30 |
/** |
|
31 |
* Prueba del acceso a datos usando el flag setAdjustToExtent a true. Esto consigue que |
|
32 |
* no se ajuste la petici?n a los margenes del raster sino que se dibuje dentro y el resto |
|
33 |
* se rellene con valores NoData. |
|
34 |
* |
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com) |
|
36 |
* |
|
37 |
*/ |
|
38 |
public class TestAdjustToExtent extends TestCase{ |
|
39 |
|
|
40 |
private String baseDir = "./test-images/"; |
|
41 |
private String path = baseDir + "miniRaster25x24.tif"; |
|
42 |
private MultiRasterDataset f = null; |
|
43 |
private BufferFactory ds = null; |
|
44 |
|
|
45 |
public void start(){ |
|
46 |
this.setUp(); |
|
47 |
this.testStack(); |
|
48 |
} |
|
49 |
|
|
50 |
public void setUp() { |
|
51 |
System.err.println("TestAdjustToExtent running..."); |
|
52 |
} |
|
53 |
|
|
54 |
static{ |
|
55 |
RasterLibrary.wakeUp(); |
|
56 |
} |
|
57 |
|
|
58 |
public void testStack(){ |
|
59 |
int[] drawableBands = {0, 1, 2}; |
|
60 |
try { |
|
61 |
f = MultiRasterDataset.open(null, path); |
|
62 |
} catch (NotSupportedExtensionException e) { |
|
63 |
e.printStackTrace(); |
|
64 |
return; |
|
65 |
} catch (RasterDriverException e) { |
|
66 |
e.printStackTrace(); |
|
67 |
return; |
|
68 |
} |
|
69 |
ds = new BufferFactory(f); |
|
70 |
ds.setDrawableBands(drawableBands); |
|
71 |
try { |
|
72 |
ds.setAdjustToExtent(false); |
|
73 |
ds.setAreaOfInterest(645800.0, 4923870.0, 645830.0, 4923820, 10, 10); //Inferior derecha |
|
74 |
//ds.setAreaOfInterest(645830.0, 4923870.0, 645880.0, 4923820, 10, 10); //Inferior izquierda |
|
75 |
|
|
76 |
} catch (InvalidSetViewException e) { |
|
77 |
e.printStackTrace(); |
|
78 |
} |
|
79 |
//print(); |
|
80 |
dataTest1(); |
|
81 |
|
|
82 |
} |
|
83 |
|
|
84 |
private void dataTest1(){ |
|
85 |
IBuffer raster = ds.getRasterBuf(); |
|
86 |
//Upper Left |
|
87 |
assertEquals((int)(raster.getElemByte(4, 7, 0) & 0xff), 97); |
|
88 |
assertEquals((int)(raster.getElemByte(4, 7, 1) & 0xff), 101); |
|
89 |
assertEquals((int)(raster.getElemByte(4, 7, 2) & 0xff), 68); |
|
90 |
} |
|
91 |
|
|
92 |
/** |
|
93 |
* Imprime todos los pixels de la fuente de datos en RGB |
|
94 |
*/ |
|
95 |
/*private void print(){ |
|
96 |
IBuffer raster = ds.getRasterBuf(); |
|
97 |
for(int line = 0; line < raster.getHeight(); line++){ |
|
98 |
for(int col = 0; col < raster.getWidth(); col++) |
|
99 |
System.out.print("(" + (int)(raster.getElemByte(line, col, 0) & 0xff) + " " + (int)(raster.getElemByte(line, col, 1) & 0xff) + " " + (int)(raster.getElemByte(line, col, 2) & 0xff) + ")"); |
|
100 |
System.out.println(); |
|
101 |
} |
|
102 |
}*/ |
|
103 |
|
|
104 |
} |
|
0 | 105 |
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/BufferFactory.java | ||
---|---|---|
297 | 297 |
Extent adjustedDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, mDataset.getAffineTransform(), new Dimension((int)mDataset.getWidth()[0], (int)mDataset.getHeight()[0])); |
298 | 298 |
|
299 | 299 |
//Caso 3D: La petici?n no se ajusta al ?rea y se rellena el exterior con NoData |
300 |
if(!adjustToExtent && RasterUtilities.isOutside(dataExtent, mDataset.getExtent()))
|
|
300 |
if(!adjustToExtent && !RasterUtilities.isInside(dataExtent, mDataset.getExtent()))
|
|
301 | 301 |
return requestFillingWithNoData(dataExtent, adjustedDataExtent, bufWidth, bufHeight); |
302 | 302 |
|
303 | 303 |
//Esta secci?n es para que no supersamplee el driver y pueda hacerse en el cliente |
... | ... | |
359 | 359 |
rasterBuf = mDataset.getWindowRaster(wcXInit, wcYEnd, wcXEnd, wcYInit, copyX, copyY, true); |
360 | 360 |
IBuffer buf = RasterBuffer.getBuffer(mDataset.getDataType()[0], bufWidth, bufHeight, rasterBuf.getBandCount(), true); |
361 | 361 |
buf.setNoDataValue(noDataValue); |
362 |
for(int i = 0; i < buf.getBandCount(); i++) { |
|
363 |
switch(buf.getDataType()) { |
|
364 |
case IBuffer.TYPE_BYTE:buf.assign(i, rasterBuf.getByteNoDataValue());break; |
|
365 |
case IBuffer.TYPE_SHORT:buf.assign(i, rasterBuf.getShortNoDataValue());break; |
|
366 |
case IBuffer.TYPE_INT:buf.assign(i, rasterBuf.getIntNoDataValue());break; |
|
367 |
case IBuffer.TYPE_FLOAT:buf.assign(i, rasterBuf.getFloatNoDataValue());break; |
|
368 |
case IBuffer.TYPE_DOUBLE:buf.assign(i, rasterBuf.getNoDataValue());break; |
|
369 |
} |
|
370 |
} |
|
362 | 371 |
|
363 | 372 |
switch(rasterBuf.getDataType()) { |
364 | 373 |
case IBuffer.TYPE_BYTE: |
... | ... | |
449 | 458 |
* @throws ArrayIndexOutOfBoundsException |
450 | 459 |
*/ |
451 | 460 |
public void setAreaOfInterest(int x, int y, int w, int h) throws InvalidSetViewException { |
461 |
if(x > getWidth() || y > getHeight()) |
|
462 |
throw new InvalidSetViewException("Par?metros incorrectos en setAreaOfInterest"); |
|
452 | 463 |
x = (x < 0) ? 0 : x; |
453 | 464 |
y = (y < 0) ? 0 : y; |
454 | 465 |
w = (w > getWidth()) ? getWidth() : w; |
... | ... | |
487 | 498 |
*/ |
488 | 499 |
public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth, int bufHeight) |
489 | 500 |
throws InvalidSetViewException { |
490 |
//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada |
|
501 |
if(x > getWidth() || y > getHeight()) |
|
502 |
throw new InvalidSetViewException("Par?metros incorrectos en setAreaOfInterest"); |
|
503 |
|
|
491 | 504 |
x = (x < 0) ? 0 : x; |
492 | 505 |
y = (y < 0) ? 0 : y; |
493 | 506 |
w = (w > getWidth()) ? getWidth() : w; |
trunk/libraries/libRaster/src/org/gvsig/raster/util/RasterUtilities.java | ||
---|---|---|
406 | 406 |
} |
407 | 407 |
|
408 | 408 |
/** |
409 |
* Comprueba si alguna parte de un extent est? fuera del extent que tenemos como referencia.
|
|
409 |
* Comprueba si un extent est? fuera de otro extent que tenemos como referencia.
|
|
410 | 410 |
* @param e1 Extent a comprobar si est? fuera |
411 | 411 |
* @param ref Extent de referencia |
412 |
* @return Devuelve true si alguna parte de e1 cae fuera de ref y false si no tiene ninguna fuera.
|
|
412 |
* @return Devuelve true si todo el extent cae fuera de ref y false si no est? fuera.
|
|
413 | 413 |
*/ |
414 | 414 |
public static boolean isOutside(Extent e1, Extent ref){ |
415 | 415 |
return ((e1.getMin().getX() > ref.getMax().getX()) || (e1.getMin().getY() > ref.getMax().getY()) || |
Also available in: Unified diff