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

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

    
17
/**
18
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
19
 * method getBandCopy.  
20
 * @author Nacho Brodin (nachobrodin@gmail.com)
21
 */
22
public class TestCopyBand extends TestCase {
23
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
24
        private String rasterOut = "/tmp/out-copyFirstBand.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

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