gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / test / java / org / gvsig / raster / cache / buffer / impl / stripecache / horizontal / TestGetBufferWithOneBand.java @ 1023
History | View | Annotate | Download (3.74 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal; |
---|---|
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.Buffer; |
9 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
10 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
11 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
12 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
13 |
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite; |
14 |
|
15 |
/**
|
16 |
* This test gets bands from a raster with the method getBufferWithOneBand() and compare
|
17 |
* each band from original source with obtained bands
|
18 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
19 |
*/
|
20 |
public class TestGetBufferWithOneBand extends TestCase { |
21 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
22 |
private String rasterOut1 = "/tmp/out-b1.tif"; |
23 |
private String rasterOut2 = "/tmp/out-b2.tif"; |
24 |
private String rasterOut3 = "/tmp/out-b3.tif"; |
25 |
|
26 |
public void start() { |
27 |
this.setUp();
|
28 |
this.testStack();
|
29 |
} |
30 |
|
31 |
public void setUp() { |
32 |
System.err.println("StripeCache TestGetBufferWithOneBand running..."); |
33 |
} |
34 |
|
35 |
public void testStack() { |
36 |
long t1 = System.currentTimeMillis(); |
37 |
GdalRead input = null;
|
38 |
try {
|
39 |
//Reducimos el tama?o de la cache para una prueba con menos datos
|
40 |
BufferCacheManagerImpl.cacheSize = 2;
|
41 |
BufferCacheManagerImpl.pageSize = 0.2;
|
42 |
|
43 |
//Read input data
|
44 |
input = new GdalRead(rasterIn);
|
45 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
46 |
|
47 |
//Create Buffer
|
48 |
Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
49 |
input.getWidth(), |
50 |
input.getHeight(), |
51 |
input.getBandCount()); |
52 |
|
53 |
//Set data to buffer
|
54 |
setLines(dataIn, buf); |
55 |
|
56 |
Buffer b0 = buf.getBufferWithOneBand(0); |
57 |
Buffer b1 = buf.getBufferWithOneBand(1); |
58 |
Buffer b2 = buf.getBufferWithOneBand(2); |
59 |
|
60 |
//Write output file
|
61 |
GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
62 |
out1.writeBands(b0.getBands()); |
63 |
out1.close(); |
64 |
|
65 |
GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
66 |
out2.writeBands(b1.getBands()); |
67 |
out2.close(); |
68 |
|
69 |
GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY); |
70 |
out3.writeBands(b2.getBands()); |
71 |
out3.close(); |
72 |
|
73 |
for (int row = 0; row < buf.getHeight(); row++) { |
74 |
for (int col = 0; col < buf.getWidth(); col++) { |
75 |
byte b_0 = buf.getElemByte(row, col, 0); |
76 |
byte b_1 = buf.getElemByte(row, col, 1); |
77 |
byte b_2 = buf.getElemByte(row, col, 2); |
78 |
assertEquals(b_0, b0.getElemByte(row, col, 0));
|
79 |
assertEquals(b_1, b1.getElemByte(row, col, 0));
|
80 |
assertEquals(b_2, b2.getElemByte(row, col, 0));
|
81 |
} |
82 |
} |
83 |
|
84 |
b0.free(); |
85 |
b1.free(); |
86 |
b2.free(); |
87 |
buf.free(); |
88 |
|
89 |
} catch (GdalException e) {
|
90 |
e.printStackTrace(); |
91 |
} catch (IOException e) { |
92 |
e.printStackTrace(); |
93 |
} catch (ProcessInterruptedException e) {
|
94 |
e.printStackTrace(); |
95 |
} catch (OperationNotSupportedException e) { |
96 |
e.printStackTrace(); |
97 |
} |
98 |
long t2 = System.currentTimeMillis(); |
99 |
System.out.println("Tiempo StripeCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos"); |
100 |
} |
101 |
|
102 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
103 |
if(dataIn instanceof byte[][][]) { |
104 |
byte[][][] d = (byte[][][])dataIn; |
105 |
for (int iBand = 0; iBand < d.length; iBand++) { |
106 |
for (int row = 0; row < d[iBand].length; row++) { |
107 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
108 |
} |
109 |
} |
110 |
} |
111 |
} |
112 |
|
113 |
} |