gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / rocache / TestWindow.java @ 1965
History | View | Annotate | Download (3.27 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.rocache; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
|
5 |
import junit.framework.TestCase; |
6 |
|
7 |
import org.gvsig.jgdal.GdalException; |
8 |
import org.gvsig.raster.cache.buffer.Band; |
9 |
import org.gvsig.raster.cache.buffer.Buffer; |
10 |
import org.gvsig.raster.cache.buffer.BufferDataSource; |
11 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
12 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
13 |
import org.gvsig.raster.cache.buffer.impl.PxTileImpl; |
14 |
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl; |
15 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
16 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
17 |
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer; |
18 |
|
19 |
/**
|
20 |
*
|
21 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
22 |
*/
|
23 |
public class TestWindow extends TestCase { |
24 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
25 |
private String rasterOut = "/tmp/window.tif"; |
26 |
private String compare = "./src/test/resources/image/clip_test_robufer.tif"; |
27 |
|
28 |
public void start() { |
29 |
this.setUp();
|
30 |
this.testStack();
|
31 |
} |
32 |
|
33 |
public void setUp() { |
34 |
System.err.println("ROCache TestWindow running..."); |
35 |
} |
36 |
|
37 |
public void testStack() { |
38 |
long t1 = System.currentTimeMillis(); |
39 |
GdalWrite output = null;
|
40 |
try {
|
41 |
|
42 |
BufferDataSource ds = null;
|
43 |
try {
|
44 |
ds = new BufferDataSourceImpl(rasterIn, new PxTileImpl(100, 100, 500, 400)); |
45 |
} catch (IOException e) { |
46 |
e.printStackTrace(); |
47 |
} |
48 |
Buffer buf = new RasterReadOnlyBuffer(ds); |
49 |
|
50 |
GdalRead input1 = new GdalRead(compare);
|
51 |
output = new GdalWrite(rasterOut, 3, input1.getGdalTypeFromRasterBufType(ds.getDataType()), ds.getWidth(), ds.getHeight(), GdalWrite.COLOR_INTERP_RGB); |
52 |
output.writeBands(buf.getBands()); |
53 |
output.close(); |
54 |
|
55 |
//Read input data
|
56 |
|
57 |
Object dataIn = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight()); |
58 |
|
59 |
//Create Buffer
|
60 |
Buffer buf1 = new RasterMemoryBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), |
61 |
input1.getWidth(), |
62 |
input1.getHeight(), |
63 |
input1.getBandCount(), |
64 |
true);
|
65 |
|
66 |
//Set data to buffer
|
67 |
setLines(dataIn, buf1); |
68 |
for (int i = 0; i < buf.getBandCount(); i++) |
69 |
compareBands(buf.getBand(i), buf.getBand(i)); |
70 |
|
71 |
buf.free(); |
72 |
buf1.free(); |
73 |
} catch (GdalException e) {
|
74 |
e.printStackTrace(); |
75 |
} catch (IOException e) { |
76 |
e.printStackTrace(); |
77 |
} catch (ProcessInterruptedException e) {
|
78 |
e.printStackTrace(); |
79 |
} catch (OperationNotSupportedException e) { |
80 |
e.printStackTrace(); |
81 |
} |
82 |
long t2 = System.currentTimeMillis(); |
83 |
System.out.println("Tiempo ROCache TestWindow: " + (t2 - t1) + " milisegundos"); |
84 |
} |
85 |
|
86 |
|
87 |
public void compareBands(Band band1, Band band2) { |
88 |
for (int i = 0; i < band1.getHeight(); i++) { |
89 |
for (int j = 0; j < band1.getWidth(); j++) { |
90 |
byte b1 = band1.getElemByte(i, j);
|
91 |
byte b2 = band2.getElemByte(i, j);
|
92 |
assertEquals(b1, b2); |
93 |
} |
94 |
} |
95 |
} |
96 |
|
97 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
98 |
if(dataIn instanceof byte[][][]) { |
99 |
byte[][][] d = (byte[][][])dataIn; |
100 |
for (int iBand = 0; iBand < d.length; iBand++) { |
101 |
for (int row = 0; row < d[iBand].length; row++) { |
102 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
103 |
} |
104 |
} |
105 |
} |
106 |
} |
107 |
} |