Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / rmf / TestRmfRead.java @ 12522

History | View | Annotate | Download (8.62 KB)

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

    
27
import junit.framework.TestCase;
28

    
29
import org.gvsig.raster.RasterLibrary;
30
import org.gvsig.raster.dataset.NotSupportedExtensionException;
31
import org.gvsig.raster.dataset.RasterDataset;
32
import org.gvsig.raster.dataset.RasterDriverException;
33
import org.gvsig.raster.dataset.properties.DatasetStatistics;
34
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer;
35
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer;
36
import org.gvsig.raster.dataset.serializer.StatisticsRmfSerializer;
37
import org.gvsig.raster.datastruct.ColorTable;
38
import org.gvsig.raster.datastruct.GeoPoint;
39
import org.gvsig.raster.datastruct.Histogram;
40
import org.gvsig.raster.datastruct.HistogramClass;
41
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer;
42
import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer;
43

    
44
/**
45
 * Test de lectura para ficheros rmf.
46
 * Obtiene distintos tipos de bloques y comprueba que el objeto que han
47
 * de generar es correcto.
48
 *
49
 * @author Nacho Brodin (nachobrodin@gmail.com)
50
 *
51
 */
52
public class TestRmfRead extends TestCase {
53

    
54
        private String baseDir = "./test-images/";
55
        private RmfBlocksManager manager = null;
56
        public String file = "readtest.rmf";
57
        private RasterDataset f1 = null;
58
        private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
59

    
60
        static {
61
                RasterLibrary.wakeUp();
62
        }
63

    
64
        public void start() {
65
                this.setUp();
66
                this.testStack();
67
        }
68

    
69
        public void setUp() {
70
                System.err.println("TestRmfRead running...");
71
                try {
72
                        f1 = RasterDataset.open(null, path1);
73
                } catch (NotSupportedExtensionException e1) {
74
                        e1.printStackTrace();
75
                } catch (RasterDriverException e1) {
76
                        e1.printStackTrace();
77
                }
78
        }
79

    
80
        public void testStack(){
81
                manager = new RmfBlocksManager(baseDir + file);
82
                if(!manager.checkRmf())
83
                        assertEquals(0, 1);
84
                HistogramRmfSerializer ser = new HistogramRmfSerializer();
85
                ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer();
86
                StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer();
87
                GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f1);
88
                GeoPointRmfSerializer ser4 = new GeoPointRmfSerializer();
89
                
90
                manager.addClient(ser);
91
                manager.addClient(ser1);
92
                manager.addClient(ser2);
93
                manager.addClient(ser3);
94
                manager.addClient(ser4);
95

    
96
                try {
97
                        manager.read(null);
98
                        for (int i = 0; i < manager.getClientsCount(); i++) {
99
                                IRmfBlock client = manager.getClient(i);
100
                                if(client instanceof HistogramRmfSerializer)
101
                                        testHistogram((Histogram)manager.getClient(i).getResult());
102
                                if(client instanceof ColorTableRmfSerializer)
103
                                        testColorTable((ColorTable)manager.getClient(i).getResult());
104
                                if(client instanceof StatisticsRmfSerializer)
105
                                        testStatistics((DatasetStatistics)manager.getClient(i).getResult());
106
                                if(client instanceof GeoInfoRmfSerializer)
107
                                        testGeoInfo((RasterDataset)manager.getClient(i).getResult());
108
                                if(client instanceof GeoPointRmfSerializer)
109
                                        testGeoPoints((GeoPoint[])manager.getClient(i).getResult());
110
                        }
111

    
112
                } catch (ParsingException e) {
113
                        e.printStackTrace();
114
                }
115

    
116
        }
117

    
118
        public void testHistogram(Histogram h) {
119
                HistogramClass[][] classes = h.getHistogram();
120
                for (int iBand = 0; iBand < classes.length; iBand++) {
121
                        for (int iValue = 0; iValue < classes[iBand].length; iValue++) {
122
                                assertEquals((int)classes[iBand][iValue].getMin(), iValue);
123
                                assertEquals((int)classes[iBand][iValue].getMax(), iValue + 1);
124
                        }
125
                }
126

    
127
                assertEquals((int)classes[0][0].getValue(), 16);
128
                assertEquals((int)classes[0][1].getValue(), 4);
129
                assertEquals((int)classes[0][23].getValue(), 6);
130
                assertEquals((int)classes[0][48].getValue(), 4);
131

    
132
                assertEquals((int)classes[1][0].getValue(), 2);
133
                assertEquals((int)classes[1][4].getValue(), 1);
134
                assertEquals((int)classes[1][7].getValue(), 8);
135
                assertEquals((int)classes[1][20].getValue(), 4);
136

    
137
                assertEquals((int)classes[2][0].getValue(), 25);
138
                assertEquals((int)classes[2][2].getValue(), 1);
139
                assertEquals((int)classes[2][13].getValue(), 4);
140
                assertEquals((int)classes[2][21].getValue(), 2);
141
        }
142

    
143
        public void testColorTable(ColorTable ct) {
144
                /*
145
                int[] range = ct.getIntRange();
146
                byte[][] color = ct.getColorTableByBand();
147

148
                assertEquals(ct.getType(), 0);
149
                assertEquals(ct.getName(), "Prueba Tabla de Color");
150
                for (int i = 0; i < color.length; i++) {
151
                        assertEquals(range[i], (31 - i));
152
                        switch(i) {
153
                        case 15:
154
                                assertEquals(color[i][0], -65);
155
                                assertEquals(color[i][1], -65);
156
                                assertEquals(color[i][2], -65);
157
                                break;
158
                        case 22:
159
                                assertEquals(color[i][0], -65);
160
                                assertEquals(color[i][1], -14);
161
                                assertEquals(color[i][2], -1);
162
                                break;
163
                        case 24:
164
                                assertEquals(color[i][0], 0);
165
                                assertEquals(color[i][1], -52);
166
                                assertEquals(color[i][2], -1);
167
                                break;
168
                        case 28:
169
                                assertEquals(color[i][0], 0);
170
                                assertEquals(color[i][1], -103);
171
                                assertEquals(color[i][2], -1);
172
                                break;
173
                        }
174
                }
175
                */
176

    
177
                //System.out.println(ct.getName());
178
                //System.out.println(ct.getType());
179

    
180
                /*for (int i = 0; i < color.length; i++) {
181
                        System.out.print(range[i] + ": ");
182
                        System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]);
183
                }*/
184
        }
185

    
186
        public void testStatistics(DatasetStatistics ds) {
187
                int bandCount = ds.getBandCount();
188
                double[] max = ds.getMax();
189
                double[] min = ds.getMin();
190
                double[] secondMax = ds.getSecondMax();
191
                double[] secondMin = ds.getSecondMin();
192
                double[] mean = ds.getMean();
193
                double[] variance = ds.getVariance();
194

    
195
                assertEquals(bandCount, 3);
196
                for (int i = 0; i < bandCount; i++) {
197
                        switch(i) {
198
                        case 0:
199
                                assertEquals((int)max[i], 250);
200
                                assertEquals((int)min[i], 0);
201
                                assertEquals((int)secondMax[i], 248);
202
                                assertEquals((int)secondMin[i], 1);
203
                                assertEquals((int)mean[i], 95);
204
                                assertEquals((int)variance[i], 3050);
205
                                break;
206
                        case 1:
207
                                assertEquals((int)max[i], 255);
208
                                assertEquals((int)min[i], 0);
209
                                assertEquals((int)secondMax[i], 254);
210
                                assertEquals((int)secondMin[i], 3);
211
                                assertEquals((int)mean[i], 105);
212
                                assertEquals((int)variance[i], 2689);
213
                                break;
214
                        case 2:
215
                                assertEquals((int)max[i], 254);
216
                                assertEquals((int)min[i], 0);
217
                                assertEquals((int)secondMax[i], 250);
218
                                assertEquals((int)secondMin[i], 1);
219
                                assertEquals((int)mean[i], 85);
220
                                assertEquals((int)variance[i], 3218);
221
                                break;
222
                        }
223
                }
224

    
225
                //System.out.println(ct.getName());
226
                //System.out.println(ct.getType());
227

    
228
                /*for (int i = 0; i < color.length; i++) {
229
                        System.out.print(range[i] + ": ");
230
                        System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]);
231
                }*/
232
        }
233

    
234
        public void testGeoInfo(RasterDataset dataset) {
235
                //String proj = "";
236
                //TODO: TEST: Terminar test de acceso a la georreferenciaci?n.
237
                //if(dataset.getProjection() != null)
238
                        //proj = dataset.getProjection().getAbrev();
239
                double x = dataset.getExtent().getMin().getX();
240
                double y = dataset.getExtent().getMax().getY();
241

    
242
                assertEquals((int)x, 5000);
243
                assertEquals((int)y, 5000);
244
        }
245
        
246
        public void testGeoPoints(GeoPoint[] gpList) {
247
                GeoPoint p = gpList[0];
248
                
249
                assertEquals((int)p.pixelPoint.getX(), 10);
250
                assertEquals((int)p.pixelPoint.getY(), 10);
251
                assertEquals((int)p.mapPoint.getX(), 34223);
252
                assertEquals((int)p.mapPoint.getY(), 2344);
253
                
254
                assertEquals(p.active, true);
255
                
256
                assertEquals((int)p.leftCenterPoint.getX(), 24223);
257
                assertEquals((int)p.leftCenterPoint.getY(), 3244);
258
                assertEquals((int)p.rightCenterPoint.getX(), 2433);
259
                assertEquals((int)p.rightCenterPoint.getY(), 6244);
260
                
261
                assertEquals((int)p.leftViewPort.getExtent().minX(), 30032);
262
                assertEquals((int)p.leftViewPort.getExtent().maxY(), 2103);
263
                
264
                assertEquals((int)p.rightViewPort.getExtent().minX(), 30032);
265
                assertEquals((int)p.rightViewPort.getExtent().maxY(), 2103);
266
                
267
                assertEquals((int)p.zoomLeft, 1);
268
                assertEquals((int)p.zoomRight, 1);
269

    
270
        }
271

    
272
}