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 / stripecache / vertical / TestReplicateBand.java @ 991

History | View | Annotate | Download (3.5 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.Band;
9
import org.gvsig.raster.cache.buffer.Buffer;
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.io.GdalRead;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
14

    
15
/** 
16
 * This test insert one band at the end of the layer. The data of this new band is a copy 
17
 * of the band in position zero. Finally data of band zero and band three are compared
18
 * checking if both have the same values. 
19
 *  
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestReplicateBand extends TestCase {
23
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
        private String rasterOut = "/tmp/out-replicateBands.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("StripeCache TestReplicateBand running...");
33
        }
34
        
35
        public void testStack() {
36
                long t1 = System.currentTimeMillis();
37
                GdalRead input1 = null;
38
                GdalWrite out = null;
39
                try {
40
                        //Reducimos el tama?o de la cache para una prueba con menos datos
41
                        BufferCacheManagerImpl.cacheSize = 2;
42
                        BufferCacheManagerImpl.pageSize = 0.2;
43
                        
44
                        //Read input data
45
                        input1 = new GdalRead(rasterIn);
46
                        Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
47
                        
48
                        //Create Buffer
49
                        Buffer buf1 = new RasterVertCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
50
                                                                                                                input1.getWidth(), 
51
                                                                                                                input1.getHeight(),
52
                                                                                                                input1.getBandCount());
53
                        
54
                        //Set data to buffer
55
                        setBytes(dataIn1, buf1);
56
                                                
57
                        buf1.replicateBand(0, 3);
58
                        
59
                        //Write output file 
60
                        out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
61
                        out.writeBands(buf1.getBands());
62
                        out.close();        
63
                        
64
                        Band band1 = buf1.getBand(0);
65
                        Band band2 = buf1.getBand(3);
66
                        for (int j = 0; j < band1.getWidth(); j++) {
67
                                for (int i = 0; i < band1.getHeight(); i++) {
68
                                        byte b1 = band1.getElemByte(i, j);
69
                                        byte b2 = band2.getElemByte(i, j);
70
                                        assertEquals(b1, b2);
71
                                }
72
                        }
73
                        
74
                        buf1.free();
75
                } catch (GdalException e) {
76
                        e.printStackTrace();
77
                } catch (IOException e) {
78
                        e.printStackTrace();
79
                } catch (InterruptedException e) {
80
                        e.printStackTrace();
81
                } catch (OperationNotSupportedException e) {
82
                        e.printStackTrace();
83
                }
84
                long t2 = System.currentTimeMillis();
85
                System.out.println("Tiempo StripeCache TestReplicateBand: " + (t2 - t1) + " milisegundos");
86
        }
87
        
88
        private void setBytes(Object dataIn, Buffer buf) throws OperationNotSupportedException {
89
                if(dataIn instanceof byte[][][]) {
90
                    byte[][][] d = (byte[][][])dataIn;
91
                    for (int iBand = 0; iBand < d.length; iBand++) {
92
                            for (int col = 0; col < d[iBand][0].length; col++) {
93
                                    for (int row = 0; row < d[iBand].length; row++) {
94
                                                buf.setElem(row, col, iBand, d[iBand][row][col]);
95
                                        }
96
                                }
97
                        }
98
            }
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
}