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 / TestAddBand.java @ 1965

History | View | Annotate | Download (3.04 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 add a band in a raster of 3 bands. As a result of this test a raster
18
 * of four bands is created and saved in the hard disk. The value of additional band
19
 * is zero in all its elements. Finally it gets the band added and compare each values 
20
 * with 0. 
21
 *  
22
 * @author Nacho Brodin (nachobrodin@gmail.com)
23
 */
24
public class TestAddBand extends TestCase {
25
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
26
        private String rasterOut = "/tmp/out-4bands.tif";
27
        
28
        public void start() {
29
                this.setUp();
30
                this.testStack();
31
        }
32

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