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

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

    
15
/**
16
 * This test gets bands from a raster with the method getBufferWithOneBand() and compare
17
 * each band from original source with obtained bands 
18
 * @author Nacho Brodin (nachobrodin@gmail.com)
19
 */
20
public class TestGetBufferWithOneBand extends TestCase {
21
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
22
        private String rasterOut1 = "/tmp/out-b1.tif";
23
        private String rasterOut2 = "/tmp/out-b2.tif";
24
        private String rasterOut3 = "/tmp/out-b3.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("StripeCache TestGetBufferWithOneBand running...");
33
        }
34
        
35
        public void testStack() {
36
                long t1 = System.currentTimeMillis();
37
                GdalRead input = 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 buf = new RasterVertCacheBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
49
                                                                                                                input.getWidth(), 
50
                                                                                                                input.getHeight(),
51
                                                                                                                input.getBandCount());
52
                        
53
                        //Set data to buffer
54
                        setBytes(dataIn, buf);
55
                        
56
                        Buffer b0 = buf.getBufferWithOneBand(0);
57
                        Buffer b1 = buf.getBufferWithOneBand(1);
58
                        Buffer b2 = buf.getBufferWithOneBand(2);
59
                        
60
                        //Write output file 
61
                        GdalWrite out1 = new GdalWrite(rasterOut1, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
62
                        out1.writeBands(b0.getBands());
63
                        out1.close();
64
                        
65
                        GdalWrite out2 = new GdalWrite(rasterOut2, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
66
                        out2.writeBands(b1.getBands());
67
                        out2.close();
68
                        
69
                        GdalWrite out3 = new GdalWrite(rasterOut3, 1, input.getDataType(), input.getWidth(), input.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
70
                        
71
                        //TODO: se ha comentarizado pq se para al cerrar las librer?as. Cuando se
72
                        //retome esta cach? deber?a ponerse en marcha
73
                        
74
                        /*out3.writeBands(b2.getBands());
75
                        out3.close();
76
                                
77
                        
78
                        for (int col = 0; col < buf.getWidth(); col++) {
79
                                for (int row = 0; row < buf.getHeight(); row++) {
80
                                        byte b_0 = buf.getElemByte(row, col, 0);
81
                                        byte b_1 = buf.getElemByte(row, col, 1);
82
                                        byte b_2 = buf.getElemByte(row, col, 2);
83
                                        assertEquals(b_0, b0.getElemByte(row, col, 0));
84
                                        assertEquals(b_1, b1.getElemByte(row, col, 0));
85
                                        assertEquals(b_2, b2.getElemByte(row, col, 0));
86
                                }
87
                        }
88
                        */
89
                        b0.free();
90
                        b1.free();
91
                        b2.free();
92
                        buf.free();
93
                                
94
                } catch (GdalException e) {
95
                        e.printStackTrace();
96
                } catch (IOException e) {
97
                        e.printStackTrace();
98
                } catch (ProcessInterruptedException e) {
99
                        e.printStackTrace();
100
                } catch (OperationNotSupportedException e) {
101
                        e.printStackTrace();
102
                }
103
                long t2 = System.currentTimeMillis();
104
                System.out.println("Tiempo StripeCache TestGetBufferWithOneBand: " + (t2 - t1) + " milisegundos");
105
        }
106
        
107
        private void setBytes(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 col = 0; col < d[iBand][0].length; col++) {
112
                                    for (int row = 0; row < d[iBand].length; row++) {
113
                                                buf.setElem(row, col, iBand, d[iBand][row][col]);
114
                                        }
115
                                }
116
                        }
117
            }
118
        }
119
//        
120
//        private void setlines(object datain, buffer buf) throws operationnotsupportedexception {
121
//                if(datain instanceof byte[][][]) {
122
//                    byte[][][] d = (byte[][][])datain;
123
//                    for (int iband = 0; iband < d.length; iband++) {
124
//                                for (int row = 0; row < d[iband].length; row++) {
125
//                                        buf.setlineinbandbyte(d[iband][row], row, iband);
126
//                                }
127
//                        }
128
//            }
129
//        }
130
        
131
}