gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / rocache / TestReadTiffAndCompareData.java @ 1965
History | View | Annotate | Download (2.99 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.Buffer; |
9 |
import org.gvsig.raster.cache.buffer.BufferDataSource; |
10 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
11 |
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException; |
12 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
13 |
import org.gvsig.raster.cache.buffer.impl.io.BufferDataSourceImpl; |
14 |
import org.gvsig.raster.cache.buffer.impl.io.GdalRead; |
15 |
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer; |
16 |
|
17 |
/**
|
18 |
* Read a number from cache
|
19 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
20 |
*/
|
21 |
public class TestReadTiffAndCompareData extends TestCase { |
22 |
private String in = "./src/test/resources/image/001m09_1_0.tif"; |
23 |
|
24 |
public void start() { |
25 |
this.setUp();
|
26 |
this.testStack();
|
27 |
} |
28 |
|
29 |
public void setUp() { |
30 |
System.err.println("ROCache TestReadTiffAndCompareData running..."); |
31 |
} |
32 |
|
33 |
public void testStack() { |
34 |
long t1 = System.currentTimeMillis(); |
35 |
GdalRead input = null;
|
36 |
|
37 |
BufferCacheManagerImpl.cacheSize = 1;
|
38 |
BufferCacheManagerImpl.pageSize = 0.2;
|
39 |
|
40 |
Buffer buf1 = null; |
41 |
try {
|
42 |
input = new GdalRead(in);
|
43 |
|
44 |
Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight()); |
45 |
|
46 |
//Create Buffer
|
47 |
buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()),
|
48 |
input.getWidth(), |
49 |
input.getHeight(), |
50 |
input.getBandCount(), |
51 |
true);
|
52 |
|
53 |
//Set data to buffer
|
54 |
setLines(dataIn, buf1); |
55 |
} catch (GdalException e1) {
|
56 |
e1.printStackTrace(); |
57 |
} catch (IOException e1) { |
58 |
e1.printStackTrace(); |
59 |
} catch (ProcessInterruptedException e1) {
|
60 |
e1.printStackTrace(); |
61 |
} catch (OperationNotSupportedException e1) { |
62 |
e1.printStackTrace(); |
63 |
} |
64 |
|
65 |
|
66 |
BufferDataSource ds = null;
|
67 |
try {
|
68 |
ds = new BufferDataSourceImpl(in);
|
69 |
} catch (IOException e) { |
70 |
e.printStackTrace(); |
71 |
} |
72 |
RasterReadOnlyBuffer buf = new RasterReadOnlyBuffer(ds);
|
73 |
|
74 |
for (int iBand = 0; iBand < buf.getBandCount(); iBand++) { |
75 |
for (int row = 0; row < buf.getHeight(); row++) { |
76 |
for (int col = 0; col < buf.getWidth(); col++) { |
77 |
byte n = buf.getElemByte(row, col, iBand);
|
78 |
byte m = buf1.getElemByte(row, col, iBand);
|
79 |
if(n != m)
|
80 |
System.out.println(row + " " + col); |
81 |
assertEquals(n, m); |
82 |
} |
83 |
} |
84 |
} |
85 |
|
86 |
try {
|
87 |
buf.free(); |
88 |
} catch (IOException e) { |
89 |
// TODO Auto-generated catch block
|
90 |
e.printStackTrace(); |
91 |
} |
92 |
|
93 |
long t2 = System.currentTimeMillis(); |
94 |
System.out.println("Tiempo ROCache TestRWOneValue: " + (t2 - t1) + " milisegundos"); |
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 |
|
108 |
} |