Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TDSDoubleAdjustToExtentBufferEcw.java @ 22936

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

    
46
        public void start() {
47
                this.setUp();
48
                this.testStack();
49
        }
50

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

    
55
        static {
56
                RasterLibrary.wakeUp();
57
        }
58

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

    
98
        private void dataTest1(IBuffer raster) {
99
                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 };
100
                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 };
101
                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 };
102
                compareRaster(raster, band0, band1, band2);
103
        }
104

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

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

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