Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / rocache / TestReadWindowAndCompareData.java @ 1965

History | View | Annotate | Download (3.08 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.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
13
import org.gvsig.raster.cache.buffer.impl.BufferParamImpl;
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 TestReadWindowAndCompareData extends TestCase {
22
        private String in = "./src/test/resources/image/001m09_1_0.tif";
23
        private int    initX  = 200;
24
        private int    initY  = 200;
25
        private int    w      = 400;
26
        private int    h      = 400;
27
        
28
        public void start() {
29
                this.setUp();
30
                this.testStack();
31
        }
32

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

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

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

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