Statistics
| Revision:

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

History | View | Annotate | Download (3.03 KB)

1
package org.gvsig.raster.cache.buffer.impl.rocache;
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.BufferDataSource;
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.io.BufferDataSourceImpl;
13
import org.gvsig.raster.cache.buffer.impl.io.GdalRead;
14
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
15

    
16
/**
17
 * This test read a RGB image and remove one band from the read buffer. Then compare 
18
 * the bands that have not been removed with the source bands. As a result of this test a raster
19
 * of two bands is created and saved in the hard disk
20
 * 
21
 * @author Nacho Brodin (nachobrodin@gmail.com)
22
 */
23
public class TestRemoveBand 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("ROCache TestRemoveBand running...");
33
        }
34
        
35
        public void testStack() {
36
                long t1 = System.currentTimeMillis();
37
                GdalRead input = null;
38
                try {
39
                        //Read input data
40
                        input = new GdalRead(rasterIn);
41
                        Object dataIn = input.readBlock(0, 0, input.getWidth(), input.getHeight());
42

    
43
                        //Create Buffer
44
                        Buffer buf1 = new RasterMemoryBuffer(input.getRasterBufTypeFromGdalType(input.getDataType()), 
45
                                        input.getWidth(), 
46
                                        input.getHeight(),
47
                                        input.getBandCount(),
48
                                        true);
49

    
50
                        //Set data to buffer
51
                        setLines(dataIn, buf1);
52

    
53
                        BufferDataSource ds = null;
54
                        try {
55
                                ds = new BufferDataSourceImpl(rasterIn);
56
                        } catch (IOException e) {
57
                                e.printStackTrace();
58
                        }
59
                        Buffer buf2 = new RasterReadOnlyBuffer(ds);
60

    
61
                        //Remove bands
62
                        buf2.removeBand(1);
63
                        buf1.removeBand(1);
64
                        compareIRasterBuffer(buf1, buf2);
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 ROCache TestRemoveBand: " + (t2 - t1) + " milisegundos");
76
        }
77
        
78
        private void setLines(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 row = 0; row < d[iBand].length; row++) {
83
                                        buf.setLineInBandByte(d[iBand][row], row, iBand);
84
                                }
85
                        }
86
            }
87
        }
88
        
89
        public void compareIRasterBuffer(Buffer b1, Buffer b2) {
90
                for (int iBand = 0; iBand < b1.getBandCount(); iBand++) {
91
                        
92
                for (int i = 0; i < b1.getHeight(); i++) {
93
                        for (int j = 0; j < b1.getWidth(); j++) {
94
                                byte b = b1.getElemByte(i, j, iBand);
95
                                byte c = b2.getElemByte(i, j, iBand);
96
                                if(b != c)
97
                                        System.out.println("B:" + iBand + "" + i + " " + j);
98
                                assertEquals(c, b);
99
                        }
100
                }
101
                
102
                }
103
        }
104
        
105
}