gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / stripecache / horizontal / TestRWTiffAndCompareData.java @ 1965
History | View | Annotate | Download (3.49 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 reads a Tiff from disk with the class TIFFRead and load data in
|
17 |
* a cache buffer. Then it saves those bytes in a new out file in the same format.
|
18 |
* Finally it compares the input data with the output data to test if there are some
|
19 |
* differences.
|
20 |
*
|
21 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
22 |
*/
|
23 |
public class TestRWTiffAndCompareData extends TestCase { |
24 |
private String rasterIn = "./src/test/resources/image/001m09_1_0.tif"; |
25 |
private String rasterOut = "/tmp/out.tif"; |
26 |
|
27 |
public void start() { |
28 |
this.setUp();
|
29 |
this.testStack();
|
30 |
} |
31 |
|
32 |
public void setUp() { |
33 |
System.err.println("StripeCache TestRWTiffAndCompareData running..."); |
34 |
} |
35 |
|
36 |
public void testStack() { |
37 |
long t1 = System.currentTimeMillis(); |
38 |
GdalRead input = null;
|
39 |
GdalWrite out = null;
|
40 |
try {
|
41 |
//Reducimos el tama?o de la cache para una prueba con menos datos
|
42 |
BufferCacheManagerImpl.cacheSize = 2;
|
43 |
BufferCacheManagerImpl.pageSize = 0.2;
|
44 |
|
45 |
//Read input data
|
46 |
input = new GdalRead(rasterIn);
|
47 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
48 |
|
49 |
//Create Buffer
|
50 |
Buffer buf = new RasterCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), |
51 |
input.getWidth(), |
52 |
input.getHeight(), |
53 |
input.getBandCount()); |
54 |
|
55 |
//Set data to buffer
|
56 |
setLines(dataIn, buf); |
57 |
|
58 |
//Write output file
|
59 |
out = new GdalWrite(rasterOut, input.getBandCount(), input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
|
60 |
out.writeBands(buf.getBands()); |
61 |
buf.free(); |
62 |
out.close(); |
63 |
|
64 |
//Open output file and compare
|
65 |
GdalRead newFile = new GdalRead(rasterOut);
|
66 |
Object dataOut = newFile.readBlock(0, 0, input.getWidth(), input.getHeight()); |
67 |
|
68 |
byte[][][] d1 = (byte[][][])dataIn; |
69 |
byte[][][] d2 = (byte[][][])dataOut; |
70 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
71 |
for (int row = 0; row < buf.getHeight(); row++) { |
72 |
for (int col = 0; col < buf.getWidth(); col++) { |
73 |
if(d1[iBand][row][col] != d2[iBand][row][col])
|
74 |
System.out.println("BAND:" + iBand +" ROW:" + row + " COL:" + col + " " + d1[iBand][row][col] + " " + d2[iBand][row][col]); |
75 |
assertEquals(d1[iBand][row][col], d2[iBand][row][col]); |
76 |
} |
77 |
} |
78 |
} |
79 |
|
80 |
} catch (GdalException e) {
|
81 |
e.printStackTrace(); |
82 |
} catch (IOException e) { |
83 |
e.printStackTrace(); |
84 |
} catch (ProcessInterruptedException e) {
|
85 |
e.printStackTrace(); |
86 |
} catch (OperationNotSupportedException e) { |
87 |
e.printStackTrace(); |
88 |
} |
89 |
long t2 = System.currentTimeMillis(); |
90 |
System.out.println("Tiempo StripeCache TestRWTiffAndCompareData: " + (t2 - t1) + " milisegundos"); |
91 |
} |
92 |
|
93 |
private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException { |
94 |
if(dataIn instanceof byte[][][]) { |
95 |
byte[][][] d = (byte[][][])dataIn; |
96 |
for (int iBand = 0; iBand < d.length; iBand++) { |
97 |
for (int row = 0; row < d[iBand].length; row++) { |
98 |
buf.setLineInBandByte(d[iBand][row], row, iBand); |
99 |
} |
100 |
} |
101 |
} |
102 |
} |
103 |
|
104 |
} |