Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TDSDoubleAdjustToExtentBufferEcw.java @ 21615

History | View | Annotate | Download (5.88 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.raster.buffer;
20

    
21
import junit.framework.TestCase;
22

    
23
import org.gvsig.raster.RasterLibrary;
24
import org.gvsig.raster.dataset.IBuffer;
25
import org.gvsig.raster.dataset.InvalidSetViewException;
26
import org.gvsig.raster.dataset.NotSupportedExtensionException;
27
import org.gvsig.raster.dataset.RasterDataset;
28
import org.gvsig.raster.dataset.io.RasterDriverException;
29
/**
30
 * Este test prueba el acceso a datos a traves de un DataSource sin resampleo
31
 * para un ECW con coordenadas reales. 
32
 * 
33
 * Lee el raster completo y comprueba que los datos leidos sean correctos 
34
 * comparando los valores de las cuatro esquinas y algunos valores dentro de la imagen.
35
 * Se lee un ?rea m?s grande que el extent completo del raster para comprobar que el ajuste
36
 * al extent lo hace correctamente.
37
 * 
38
 * Despu?s hace selecciona un ?rea dentro de la imagen de 2x2 y compara que los valores
39
 * leidos sean correctos.
40
 * 
41
 * @author Nacho Brodin (nachobrodin@gmail.com)
42
 *
43
 */
44
public class TDSDoubleAdjustToExtentBufferEcw extends TestCase {
45
        private String        baseDir = "./test-images/";
46
        private String        path    = baseDir + "miniraster30x30.jp2";
47

    
48
        public void start() {
49
                this.setUp();
50
                this.testStack();
51
        }
52

    
53
        public void setUp() {
54
                System.err.println("TDSDoubleAdjustToExtentBufferEcw running...");
55
        }
56

    
57
        static {
58
                RasterLibrary.wakeUp();
59
        }
60

    
61
        public void testStack() {
62
                RasterDataset f;
63
                int[] drawableBands = { 0, 1, 2 };
64
                try {
65
                        f = RasterDataset.open(null, path);
66
                } catch (RasterDriverException e) {
67
                        return;
68
                } catch (NotSupportedExtensionException e) {
69
                        return;
70
                }
71
                BufferFactory ds = new BufferFactory(f);
72
                ds.setDrawableBands(drawableBands);
73
                //Se selecciona un ?rea mayor que el extent para probar que lo ajusta a este 
74
                try {
75
                        ds.setAreaOfInterest(645860.0, 4923870.0, 645986.0, 4923744.0, 10, 10);
76
                } catch (RasterDriverException e) {
77
                        e.printStackTrace();
78
                } catch (InvalidSetViewException e) {
79
                        e.printStackTrace();
80
                } catch (InterruptedException e) {
81
                        e.printStackTrace();
82
                }
83
//                print(ds.getRasterBuf());
84
                dataTest1(ds.getRasterBuf());
85
                                
86
                try {
87
                        ds.setAreaOfInterest(645860.0, 4923870.0, 645986.0, 4923744.0, 2, 2);
88
                } catch (RasterDriverException e) {
89
                        e.printStackTrace();
90
                } catch (InvalidSetViewException e) {
91
                        e.printStackTrace();
92
                } catch (InterruptedException e) {
93
                        e.printStackTrace();
94
                }
95
//                print(ds.getRasterBuf());
96
                dataTest2(ds.getRasterBuf());
97
        }
98

    
99
        private void dataTest1(IBuffer raster) {
100
                int band0[] = { 43, 14, 87, 166, 174, 109, 90, 93, 190, 143, 85, 93, 103, 112, 138, 94, 138, 192, 180, 196, 99, 209, 41, 98, 168, 170, 89, 141, 158, 199, 108, 71, 67, 92, 131, 176, 243, 98, 163, 141, 157, 170, 94, 159, 233, 114, 144, 62, 147, 173, 159, 173, 184, 94, 56, 18, 69, 78, 83, 115, 95, 37, 80, 57, 68, 68, 55, 59, 58, 101, 69, 44, 24, 58, 115, 40, 58, 56, 68, 111, 84, 117, 55, 88, 170, 135, 169, 99, 74, 42, 114, 223, 171, 67, 216, 104, 167, 83, 66, 45 };
101
                int band1[] = { 53, 15, 109, 154, 164, 111, 109, 93, 189, 151, 89, 102, 107, 111, 142, 100, 143, 195, 178, 190, 100, 192, 61, 108, 154, 172, 99, 149, 160, 206, 122, 74, 81, 94, 136, 195, 248, 105, 173, 141, 158, 162, 98, 158, 226, 114, 132, 66, 150, 176, 168, 172, 175, 105, 82, 39, 85, 89, 73, 104, 92, 51, 80, 71, 88, 84, 71, 74, 68, 106, 82, 62, 37, 74, 129, 49, 78, 67, 89, 126, 100, 132, 71, 107, 164, 145, 154, 108, 85, 48, 130, 210, 164, 66, 209, 115, 160, 85, 90, 61 };
102
                int band2[] = { 26, 11, 82, 145, 165, 97, 86, 71, 191, 135, 74, 75, 85, 110, 117, 82, 115, 186, 179, 183, 91, 181, 43, 85, 139, 178, 78, 133, 152, 206, 98, 61, 71, 109, 118, 181, 244, 82, 144, 117, 144, 159, 83, 155, 231, 98, 108, 60, 136, 163, 146, 170, 162, 111, 102, 41, 62, 60, 64, 68, 97, 26, 74, 50, 64, 70, 47, 48, 56, 70, 54, 35, 19, 50, 91, 35, 48, 52, 62, 101, 73, 91, 35, 80, 140, 119, 140, 91, 58, 36, 112, 202, 146, 66, 192, 81, 131, 71, 63, 37 };
103
                compareRaster(raster, band0, band1, band2);
104
        }
105

    
106
        private void dataTest2(IBuffer raster) {
107
                int band0[] = { 43, 109, 160, 18 };
108
                int band1[] = { 53, 111, 168, 39 };
109
                int band2[] = { 26, 97, 146, 41 };
110
                compareRaster(raster, band0, band1, band2);
111
        }
112

    
113
        public void compareRaster(IBuffer raster, int band0[], int band1[], int band2[]) {
114
                int cont = 0;
115
                for (int line = 0; line < raster.getHeight(); line++) {
116
                        for (int col = 0; col < raster.getWidth(); col++) {
117
                                assertEquals((int) (raster.getElemByte(line, col, 0) & 0xff), band0[cont]);
118
                                assertEquals((int) (raster.getElemByte(line, col, 1) & 0xff), band1[cont]);
119
                                assertEquals((int) (raster.getElemByte(line, col, 2) & 0xff), band2[cont]);
120
                                cont++;
121
                        }
122
                }
123
        }
124

    
125
        /**
126
         * Imprime todos los pixels de la fuente de datos en RGB
127
         */
128
        public void print(IBuffer raster) {
129
                System.out.println("");
130
                for (int band = 0; band < 3; band++) {
131
                        System.out.print("int band" + band + "[] = { ");
132
                        int cont = 0;
133
                        for (int line = 0; line < raster.getHeight(); line++) {
134
                                for (int col = 0; col < raster.getWidth(); col++) {
135
                                        if (cont != 0)
136
                                                System.out.print(", ");
137
                                        System.out.print(((int) (raster.getElemByte(line, col, band) & 0xff)));
138
                                        cont++;
139
                                }
140
                        }
141
                        System.out.println("};");
142
                }
143
        }
144
}