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

History | View | Annotate | Download (4.08 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
 *  
19
 * @author Nacho Brodin (nachobrodin@gmail.com)
20
 */
21
public class TestAssignBand extends TestCase {
22
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
23
        private String rasterOut = "/tmp/out-4bands.tif";
24
        
25
        public void start() {
26
                this.setUp();
27
                this.testStack();
28
        }
29

    
30
        public void setUp() {
31
                System.err.println("StripeCache TestAssignBand running...");
32
        }
33
        
34
        public void testStack() {
35
                long t1 = System.currentTimeMillis();
36
                GdalRead input1 = null;
37
                GdalRead input2 = 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
                        input1 = new GdalRead(rasterIn);
46
                        Object dataIn1 = input1.readBlock(0, 0, input1.getWidth(), input1.getHeight());
47
                        input2 = new GdalRead(rasterIn);
48
                        Object dataIn2 = input1.readBlock(0, 0, input2.getWidth(), input2.getHeight());
49
                        
50
                        //Create Buffer
51
                        Buffer buf1 = new RasterVertCacheBuffer(input1.getRasterBufTypeFromGdalType(input1.getDataType()), 
52
                                                                                                                input1.getWidth(), 
53
                                                                                                                input1.getHeight(),
54
                                                                                                                input1.getBandCount());
55
                        
56
                        //Set data to buffer
57
                        setBytes(dataIn1, buf1);
58
                        //Create Buffer
59
                        Buffer buf2 = new RasterVertCacheBuffer(input2.getRasterBufTypeFromGdalType(input2.getDataType()), 
60
                                                                                                                input2.getWidth(), 
61
                                                                                                                input2.getHeight(),
62
                                                                                                                input2.getBandCount());
63
                        
64
                        //Set data to buffer
65
                        setBytes(dataIn2, buf2);
66
                        
67
                        Band rb = buf2.getBand(2);
68
                        try {
69
                                buf1.assignBand(1, rb);
70
                        } catch (BandNotCompatibleException e) {
71
                                e.printStackTrace();
72
                        }
73
                        
74
                        //Write output file 
75
                        out = new GdalWrite(rasterOut, 4, input1.getDataType(), input1.getWidth(), input1.getHeight(), GdalWrite.COLOR_INTERP_GRAY);
76
                        
77
                        //TODO: se ha comentarizado pq se para al cerrar las librer?as. Cuando se
78
                        //retome esta cach? deber?a ponerse en marcha
79
                        
80
                        /*out.writeBands(buf1.getBands());
81
                        out.close();        
82
                        
83
                        Band band1 = buf1.getBand(1);
84
                        Band band2 = buf1.getBand(3);
85
                        for (int j = 0; j < band1.getWidth(); j++) {
86
                                for (int i = 0; i < band1.getHeight(); i++) {
87
                                        byte b1 = band1.getElemByte(i, j);
88
                                        byte b2 = band2.getElemByte(i, j);
89
                                        assertEquals(b1, b2);
90
                                }
91
                        }
92
                        
93
                        buf1.free();
94
                        buf2.free();*/
95
                } catch (GdalException e) {
96
                        e.printStackTrace();
97
                } catch (IOException e) {
98
                        e.printStackTrace();
99
                } catch (ProcessInterruptedException e) {
100
                        e.printStackTrace();
101
                } catch (OperationNotSupportedException e) {
102
                        e.printStackTrace();
103
                }
104
                long t2 = System.currentTimeMillis();
105
                System.out.println("Tiempo StripeCache TestAssignBand: " + (t2 - t1) + " milisegundos");
106
        }
107
        
108
        private void setBytes(Object dataIn, Buffer buf) throws OperationNotSupportedException {
109
                if(dataIn instanceof byte[][][]) {
110
                    byte[][][] d = (byte[][][])dataIn;
111
                    for (int iBand = 0; iBand < d.length; iBand++) {
112
                            for (int col = 0; col < d[iBand][0].length; col++) {
113
                                    for (int row = 0; row < d[iBand].length; row++) {
114
                                                buf.setElem(row, col, iBand, d[iBand][row][col]);
115
                                        }
116
                                }
117
                        }
118
            }
119
        }
120
        
121
        /*private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
122
                if(dataIn instanceof byte[][][]) {
123
                    byte[][][] d = (byte[][][])dataIn;
124
                    for (int iBand = 0; iBand < d.length; iBand++) {
125
                                for (int row = 0; row < d[iBand].length; row++) {
126
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
127
                                }
128
                        }
129
            }
130
        }*/
131
        
132
}