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