Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / test / impl / stripecache / horizontal / TestReplicateBand.java @ 1965

History | View | Annotate | Download (3.14 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.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.exception.ProcessInterruptedException;
12
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.io.GdalWrite;
15

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

    
32
        public void setUp() {
33
                System.err.println("StripeCache TestReplicateBand running...");
34
        }
35
        
36
        public void testStack() {
37
                long t1 = System.currentTimeMillis();
38
                GdalRead input1 = 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
                        input1 = new GdalRead(rasterIn);
47
                        Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
48
                        
49
                        //Create Buffer
50
                        Buffer buf1 = new RasterCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
51
                                                                                                                input1.getWidth(), 
52
                                                                                                                input1.getHeight(),
53
                                                                                                                input1.getBandCount());
54
                        
55
                        //Set data to buffer
56
                        setLines(dataIn1, buf1);
57
                                                
58
                        buf1.replicateBand(0, 3);
59
                        
60
                        //Write output file 
61
                        out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
                        out.writeBands(buf1.getBands());
63
                        out.close();        
64
                        
65
                        Band band1 = buf1.getBand(0);
66
                        Band band2 = buf1.getBand(3);
67
                        for (int i = 0; i < band1.getHeight(); i++) {
68
                                for (int j = 0; j < band1.getWidth(); j++) {
69
                                        byte b1 = band1.getElemByte(i, j);
70
                                        byte b2 = band2.getElemByte(i, j);
71
                                        assertEquals(b1, b2);
72
                                }
73
                        }
74
                        
75
                        buf1.free();
76
                } catch (GdalException e) {
77
                        e.printStackTrace();
78
                } catch (IOException e) {
79
                        e.printStackTrace();
80
                } catch (ProcessInterruptedException e) {
81
                        e.printStackTrace();
82
                } catch (OperationNotSupportedException e) {
83
                        e.printStackTrace();
84
                }
85
                long t2 = System.currentTimeMillis();
86
                System.out.println("Tiempo StripeCache TestReplicateBand: " + (t2 - t1) + " milisegundos");
87
        }
88
        
89
        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {  
90
                if(dataIn instanceof byte[][][]) {
91
                    byte[][][] d = (byte[][][])dataIn;
92
                    for (int iBand = 0; iBand < d.length; iBand++) {
93
                                for (int row = 0; row < d[iBand].length; row++) {
94
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
95
                                }
96
                        }
97
            }
98
        }
99
        
100
}