Statistics
| Revision:

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 / rocache / TestReadWindowAndCompareData.java @ 999

History | View | Annotate | Download (3 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.BufferParam;
10
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
11
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
12
import org.gvsig.raster.cache.buffer.impl.BufferParamImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
15

    
16
/**
17
 * Read a number from cache
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestReadWindowAndCompareData extends TestCase {
21
        private String in = "./src/test/resources/image/001m09_1_0.tif";
22
        private int    initX  = 200;
23
        private int    initY  = 200;
24
        private int    w      = 400;
25
        private int    h      = 400;
26
        
27
        public void start() {
28
                this.setUp();
29
                this.testStack();
30
        }
31

    
32
        public void setUp() {
33
                System.err.println("ROCache TestReadTiffAndCompareData running...");
34
        }
35
        
36
        public void testStack() {
37
                long t1 = System.currentTimeMillis();
38
                GdalRead input = null;
39
                
40
                BufferCacheManagerImpl.cacheSize = 1;
41
                BufferCacheManagerImpl.pageSize = 0.2;
42
                
43
                Buffer buf1 = null;
44
                try {
45
                        input = new GdalRead(in);
46

    
47
                        Object dataIn = input.readBlock(initX, initY, w, h);
48

    
49
                        //Create Buffer
50
                        buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
51
                                                                                        w, 
52
                                                                                        h,
53
                                                                                        input.getBandCount(),
54
                                                                                        true);
55

    
56
                        //Set data to buffer
57
                        setLines(dataIn, buf1);
58
                } catch (GdalException e1) {
59
                        e1.printStackTrace();
60
                } catch (IOException e1) {
61
                        e1.printStackTrace();
62
                } catch (InterruptedException e1) {
63
                        e1.printStackTrace();
64
                } catch (OperationNotSupportedException e1) {
65
                        e1.printStackTrace();
66
                }
67
                
68
                RasterReadOnlyBuffer buf = null;
69
                try {
70
                        BufferParam p = new BufferParamImpl(in, initX, initY, w, h, new int[]{0, 1, 2});
71
                        buf = new RasterReadOnlyBuffer(p);
72
                } catch (IOException e) {
73
                        e.printStackTrace();
74
                }
75
                
76
                                
77
                for (int iBand = 0; iBand < buf.getBandCount(); iBand++) {
78
                        for (int row = 0; row < buf.getHeight(); row++) {
79
                                for (int col = 0; col < buf.getWidth(); col++) {
80
                                        byte n = buf.getElemByte(row, col, iBand);
81
                                        byte m = buf1.getElemByte(row, col, iBand);
82
                                        if(n != m)
83
                                                System.out.println(row + " " + col);
84
                                        assertEquals(n, m);
85
                                }
86
                        }
87
                }
88
                
89
                try {
90
                        buf.free();
91
                } catch (IOException e) {
92
                        // TODO Auto-generated catch block
93
                        e.printStackTrace();
94
                }
95
                
96
                long t2 = System.currentTimeMillis();
97
                System.out.println("Tiempo ROCache TestRWOneValue: " + (t2 - t1) + " milisegundos");
98
        }
99
        
100
        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
101
                if(dataIn instanceof byte[][][]) {
102
                    byte[][][] d = (byte[][][])dataIn;
103
                    for (int iBand = 0; iBand < d.length; iBand++) {
104
                                for (int row = 0; row < d[iBand].length; row++) {
105
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
106
                                }
107
                        }
108
            }
109
        }
110
        
111
}