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

History | View | Annotate | Download (3.53 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.BandNotCompatibleException;
11
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
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
 * Copy the band 0 from a buffer over the band 2 in the same buffer using the
18
 * method getBandCopy.  
19
 * @author Nacho Brodin (nachobrodin@gmail.com)
20
 */
21
public class TestCopyBand extends TestCase {
22
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
23
        private String rasterOut = "/tmp/out-copyFirstBand.tif";
24
        
25
        public void start() {
26
                this.setUp();
27
                this.testStack();
28
        }
29

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