Statistics
| Revision:

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

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

    
15
/**
16
 * This test add a band in a raster of 3 bands. As a result of this test a raster
17
 * of four bands is created and saved in the hard disk. The value of additional band
18
 * is zero in all its elements. Finally it gets the band added and compare each values 
19
 * with 0. 
20
 *  
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestCreateBand extends TestCase {
24
        private String rasterIn = "./src/test/resources/image/001m09_1_0.tif";
25
        
26
        public void start() {
27
                this.setUp();
28
                this.testStack();
29
        }
30

    
31
        public void setUp() {
32
                System.err.println("StripeCache TestCreateBand 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
                        Band rb = buf.createBand((byte)100);
56

    
57
                        for (int j = 0; j < rb.getWidth(); j++) {
58
                                for (int i = 0; i < rb.getHeight(); i++) {
59
                                        byte b = rb.getElemByte(i, j);
60
                                        assertEquals((byte)100, b);
61
                                }
62
                        }
63
                        
64
                        buf.free();
65
                } catch (GdalException e) {
66
                        e.printStackTrace();
67
                } catch (IOException e) {
68
                        e.printStackTrace();
69
                } catch (ProcessInterruptedException e) {
70
                        e.printStackTrace();
71
                } catch (OperationNotSupportedException e) {
72
                        e.printStackTrace();
73
                }
74
                long t2 = System.currentTimeMillis();
75
                System.out.println("Tiempo StripeCache TestCreateBand: " + (t2 - t1) + " milisegundos");
76
        }
77
        
78
        private void setBytes(Object dataIn, Buffer buf) throws OperationNotSupportedException {
79
                if(dataIn instanceof byte[][][]) {
80
                    byte[][][] d = (byte[][][])dataIn;
81
                    for (int iBand = 0; iBand < d.length; iBand++) {
82
                            for (int col = 0; col < d[iBand][0].length; col++) {
83
                                    for (int row = 0; row < d[iBand].length; row++) {
84
                                                buf.setElem(row, col, iBand, d[iBand][row][col]);
85
                                        }
86
                                }
87
                        }
88
            }
89
        }
90
        
91
//        private void setLines(Object dataIn, Buffer buf) throws OperationNotSupportedException {
92
//                if(dataIn instanceof byte[][][]) {
93
//                    byte[][][] d = (byte[][][])dataIn;
94
//                    for (int iBand = 0; iBand < d.length; iBand++) {
95
//                                for (int row = 0; row < d[iBand].length; row++) {
96
//                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
97
//                                }
98
//                        }
99
//            }
100
//        }
101
        
102
}