Statistics
| Revision:

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

History | View | Annotate | Download (3.73 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.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 RasterVertCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
50
                                                                                                                input.getWidth(), 
51
                                                                                                                input.getHeight(),
52
                                                                                                                input.getBandCount());
53
                        
54
                        //Set data to buffer
55
                        setBytes(dataIn, buf1);
56
                        
57
                        //TODO: se ha comentado pq se para al cerrar las librer?as. Cuando se
58
                        //retome esta cach? deber?a ponerse en marcha
59
                        /*Band rb = buf1.getBandCopy(0);
60
                        
61
                        try {
62
                                buf1.copyBand(2, rb);
63
                        } catch (BandNotCompatibleException e) {
64
                                e.printStackTrace();
65
                        }
66
                        
67
                        //Write output file 
68
                        out = new GdalWrite(rasterOut, 3, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_RGB);
69
                        out.writeBands(buf1.getBands());
70
                        out.close();        
71
                        
72
                        Band band1 = buf1.getBand(0);
73
                        Band band2 = buf1.getBand(2);
74
                        for (int j = 0; j < band1.getWidth(); j++) {
75
                                for (int i = 0; i < band1.getHeight(); i++) {
76
                                        byte b1 = band1.getElemByte(i, j);
77
                                        byte b2 = band2.getElemByte(i, j);
78
                                        assertEquals(b1, b2);
79
                                }
80
                        }
81
                        
82
                        buf1.free();*/
83
                } catch (GdalException e) {
84
                        e.printStackTrace();
85
                } catch (IOException e) {
86
                        e.printStackTrace();
87
                } catch (ProcessInterruptedException e) {
88
                        e.printStackTrace();
89
                } catch (OperationNotSupportedException e) {
90
                        e.printStackTrace();
91
                }
92
                long t2 = System.currentTimeMillis();
93
                System.out.println("Tiempo StripeCache TestCopyBand: " + (t2 - t1) + " milisegundos");
94
        }
95
        
96
        private void setBytes(Object dataIn, Buffer buf) throws OperationNotSupportedException {
97
                if(dataIn instanceof byte[][][]) {
98
                    byte[][][] d = (byte[][][])dataIn;
99
                    for (int iBand = 0; iBand < d.length; iBand++) {
100
                            for (int col = 0; col < d[iBand][0].length; col++) {
101
                                    for (int row = 0; row < d[iBand].length; row++) {
102
                                                buf.setElem(row, col, iBand, d[iBand][row][col]);
103
                                        }
104
                                }
105
                        }
106
            }
107
        }
108
        
109
//        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
110
//                if(dataIn instanceof byte[][][]) {
111
//                    byte[][][] d = (byte[][][])dataIn;
112
//                    for (int iBand = 0; iBand < d.length; iBand++) {
113
//                                for (int row = 0; row < d[iBand].length; row++) {
114
//                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
115
//                                }
116
//                        }
117
//            }
118
//        }
119
        
120
}