Statistics
| Revision:

gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.main / src / test / java / org / gvsig / fmap / dal / coverage / dataset / io / rmf / TestRmfRead.java @ 2443

History | View | Annotate | Download (11.5 KB)

1
/* gvSIG. Geographic Information System of the Valencian Government
2
 *
3
 * Copyright (C) 2007-2008 Infrastructures and Transports Department
4
 * of the Valencian Government (CIT)
5
 *
6
 * This program is free software; you can redistribute it and/or
7
 * modify it under the terms of the GNU General Public License
8
 * as published by the Free Software Foundation; either version 2
9
 * of the License, or (at your option) any later version.
10
 *
11
 * This program is distributed in the hope that it will be useful,
12
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14
 * GNU General Public License for more details.
15
 *
16
 * You should have received a copy of the GNU General Public License
17
 * along with this program; if not, write to the Free Software
18
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
19
 * MA  02110-1301, USA.
20
 *
21
 */
22
package org.gvsig.fmap.dal.coverage.dataset.io.rmf;
23

    
24
import java.awt.geom.AffineTransform;
25
import java.io.File;
26

    
27
import org.gvsig.fmap.dal.DALLocator;
28
import org.gvsig.fmap.dal.DataManager;
29
import org.gvsig.fmap.dal.coverage.BaseTestCase;
30
import org.gvsig.fmap.dal.coverage.dataset.Buffer;
31
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram;
32
import org.gvsig.fmap.dal.coverage.datastruct.HistogramClass;
33
import org.gvsig.fmap.dal.coverage.exception.ParsingException;
34
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
35
import org.gvsig.fmap.dal.coverage.store.props.ColorTable;
36
import org.gvsig.fmap.dal.serverexplorer.filesystem.FilesystemStoreParameters;
37
import org.gvsig.fmap.dal.spi.DataStoreProviderServices;
38
import org.gvsig.raster.impl.datastruct.BufferHistogramImpl;
39
import org.gvsig.raster.impl.datastruct.DefaultNoData;
40
import org.gvsig.raster.impl.datastruct.GeoPoint;
41
import org.gvsig.raster.impl.datastruct.GeoPointList;
42
import org.gvsig.raster.impl.datastruct.serializer.ColorTableRmfSerializer;
43
import org.gvsig.raster.impl.datastruct.serializer.HistogramRmfSerializer;
44
import org.gvsig.raster.impl.datastruct.serializer.NoDataRmfSerializer;
45
import org.gvsig.raster.impl.provider.DefaultRasterProvider;
46
import org.gvsig.raster.impl.store.DefaultMultiRasterStore;
47
import org.gvsig.raster.impl.store.properties.DataStoreColorInterpretation;
48
import org.gvsig.raster.impl.store.properties.DataStoreStatistics;
49
import org.gvsig.raster.impl.store.rmf.IRmfBlock;
50
import org.gvsig.raster.impl.store.rmf.RmfBlocksManager;
51
import org.gvsig.raster.impl.store.serializer.ColorInterpretationRmfSerializer;
52
import org.gvsig.raster.impl.store.serializer.GeoInfoRmfSerializer;
53
import org.gvsig.raster.impl.store.serializer.GeoPointListRmfSerializer;
54
import org.gvsig.raster.impl.store.serializer.StatisticsRmfSerializer;
55
import org.gvsig.raster.lizardtech.io.LizardTechProvider;
56
/**
57
 * Test de lectura para ficheros rmf. Obtiene distintos tipos de bloques y
58
 * comprueba que el objeto que han de generar es correcto.
59
 *
60
 * @author Nacho Brodin (nachobrodin@gmail.com)
61
 */
62
public class TestRmfRead extends BaseTestCase {
63
        private RmfBlocksManager blocksManager = null;
64
        public String            file    = "readtest.rmf";
65
        private DefaultRasterProvider      f2       = null;        
66
        protected Buffer           raster  = null;
67
        private String           path1   = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
68

    
69
        public void start() throws Exception {
70
                this.setUp();
71
                this.testStack();
72
        }
73

    
74
        protected void doSetUp() throws Exception {
75
                try {
76
                        super.doSetUp();
77
                } catch (Exception e) {
78
                        e.printStackTrace();
79
                }
80
                System.err.println("TestRmfRead running...");
81
                
82
                deleteRMF(path1);
83
                DefaultMultiRasterStore grmf = new DefaultMultiRasterStore();
84

    
85
                DataManager dm = DALLocator.getDataManager();
86
                FilesystemStoreParameters p = (FilesystemStoreParameters)dm.createStoreParameters(LizardTechProvider.NAME);
87
                p.setFile(new File(path1));
88
                f2 = (DefaultRasterProvider)loadProvider(p, (DataStoreProviderServices)grmf);
89
        }
90

    
91
        public void testStack(){
92
                blocksManager = new RmfBlocksManager(baseDir + file);
93
                if (!blocksManager.checkRmf())
94
                        assertEquals(0, 1);
95
                HistogramRmfSerializer ser = new HistogramRmfSerializer();
96
                ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer();
97
                StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer();
98
                GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f2);
99
                GeoPointListRmfSerializer ser4 = new GeoPointListRmfSerializer();
100
                NoDataRmfSerializer ser5 = new NoDataRmfSerializer();
101
                ColorInterpretationRmfSerializer ser6 = new ColorInterpretationRmfSerializer((DataStoreColorInterpretation)f2.getColorInterpretation());
102

    
103
                blocksManager.addClient(ser);
104
                blocksManager.addClient(ser1);
105
                blocksManager.addClient(ser2);
106
                blocksManager.addClient(ser3);
107
                blocksManager.addClient(ser4);
108
                blocksManager.addClient(ser5);
109
                blocksManager.addClient(ser6);
110

    
111
                try {
112
                        blocksManager.read(null);
113
                        for (int i = 0; i < blocksManager.getClientsCount(); i++) {
114
                                IRmfBlock client = blocksManager.getClient(i);
115
                                if (client instanceof HistogramRmfSerializer)
116
                                        testHistogram((BufferHistogram) client.getResult());
117
                                if (client instanceof ColorTableRmfSerializer) {
118
                                        ColorTable colorTable = (ColorTable) client.getResult();
119
                                        colorTable.setInterpolated(false);
120
                                        testColorTable(colorTable);
121
                                }
122
                                if (client instanceof StatisticsRmfSerializer)
123
                                        testStatistics((DataStoreStatistics) client.getResult());
124
                                if (client instanceof NoDataRmfSerializer)
125
                                        testNoData((DefaultNoData) client.getResult());
126
//                                if (client instanceof GeoInfoRmfSerializer)
127
//                                        testGeoInfo((RasterDataset) client.getResult());
128
                                if (client instanceof GeoPointListRmfSerializer)
129
                                        testGeoPoints((GeoPointList) client.getResult());
130
                                if (client instanceof ColorInterpretationRmfSerializer) {
131
                                        DataStoreColorInterpretation ci = (DataStoreColorInterpretation) client.getResult();
132
                                        testColorInterpretation(ci);
133
                                }
134
                        }
135

    
136
                } catch (ParsingException e) {
137
                        e.printStackTrace();
138
                }
139

    
140
        }
141

    
142
        public void testColorInterpretation(DataStoreColorInterpretation ci) {
143
                for (int j = 0; j < ci.length(); j++) {
144
                        String value = ci.get(j);
145
//                        System.out.println(value);
146
                        if (j == 0)
147
                                assertEquals(value, "Red");
148
                        if (j == 1)
149
                                assertEquals(value, "Green");
150
                        if (j == 2)
151
                                assertEquals(value, "Blue");
152
                }
153
        }
154

    
155
        public void testHistogram(BufferHistogram h) {
156
                BufferHistogram h2 = BufferHistogramImpl.convertHistogramToRGB(h);
157

    
158
                HistogramClass[][] classes = h2.getHistogram();
159
                for (int iBand = 0; iBand < classes.length; iBand++)
160
                        for (int iValue = 0; iValue < classes[iBand].length; iValue++) {
161
                                assertEquals((int) classes[iBand][iValue].getMin(), iValue);
162
                                assertEquals((int) classes[iBand][iValue].getMax(), iValue + 1);
163
                        }
164

    
165
                assertEquals((int) h.getHistogramValue(0, 0), 16);
166
                assertEquals((int) h.getHistogramValue(0, 1), 4);
167
                assertEquals((int) h.getHistogramValue(0, 23), 6);
168
                assertEquals((int) h.getHistogramValue(0, 48), 4);
169

    
170
                assertEquals((int) h.getHistogramValue(1, 0), 2);
171
                assertEquals((int) h.getHistogramValue(1, 4), 1);
172
                assertEquals((int) h.getHistogramValue(1, 7), 8);
173
                assertEquals((int) h.getHistogramValue(1, 20), 4);
174

    
175
                assertEquals((int) h.getHistogramValue(2, 0), 25);
176
                assertEquals((int) h.getHistogramValue(2, 2), 1);
177
                assertEquals((int) h.getHistogramValue(2, 13), 4);
178
                assertEquals((int) h.getHistogramValue(2, 21), 2);
179
        }
180

    
181
        public void testColorTable(ColorTable ct) {
182

    
183
//                byte[][] color = ct.getColorTableByBand();
184

    
185
//                assertEquals(ct.getName(), "Prueba Tabla de Color");
186

    
187
                assertEquals(ct.getRGBAByBand(15)[0] & 0xff, 95);
188
                assertEquals(ct.getRGBAByBand(15)[1] & 0xff, 95);
189
                assertEquals(ct.getRGBAByBand(15)[2] & 0xff, 95);
190

    
191
                assertEquals(ct.getRGBAByBand(22)[0] & 0xff, 0);
192
                assertEquals(ct.getRGBAByBand(22)[1] & 0xff, 0);
193
                assertEquals(ct.getRGBAByBand(22)[2] & 0xff, 0);
194

    
195
                assertEquals(ct.getRGBAByBand(24)[0] & 0xff, 0);
196
                assertEquals(ct.getRGBAByBand(24)[1] & 0xff, 0);
197
                assertEquals(ct.getRGBAByBand(24)[2] & 0xff, 0);
198

    
199
                assertEquals(ct.getRGBAByBand(28)[0] & 0xff, 0);
200
                assertEquals(ct.getRGBAByBand(28)[1] & 0xff, 0);
201
                assertEquals(ct.getRGBAByBand(28)[2] & 0xff, 0);
202

    
203
                assertEquals(ct.getRGBAByBand(0)[0] & 0xff, 255);
204
                assertEquals(ct.getRGBAByBand(0)[1] & 0xff, 255);
205
                assertEquals(ct.getRGBAByBand(0)[2] & 0xff, 255);
206

    
207
                assertEquals(ct.getRGBAByBand(1)[0] & 0xff, 0);
208
                assertEquals(ct.getRGBAByBand(1)[1] & 0xff, 0);
209
                assertEquals(ct.getRGBAByBand(1)[2] & 0xff, 0);
210

    
211
                assertEquals(ct.getRGBAByBand(2)[0] & 0xff, 0);
212
                assertEquals(ct.getRGBAByBand(2)[1] & 0xff, 102);
213
                assertEquals(ct.getRGBAByBand(2)[2] & 0xff, 255);
214

    
215
//                System.out.println(ct.getName());
216
//                for (int i = 0; i < color.length; i++) {
217
//                        System.out.println((color[i][0] & 0xff) + " " + (color[i][1] & 0xff) + " " + (color[i][2] & 0xff));
218
//                }
219
        }
220

    
221
        public void testNoData(DefaultNoData noData) {
222
                assertEquals((int) noData.getValue(), 5450);
223
                assertEquals(noData.getType(), 2);
224
        }
225

    
226
        public void testStatistics(DataStoreStatistics ds) {
227
                int bandCount = ds.getBandCount();
228
                double[] max = ds.getMaxByteUnsigned();
229
                double[] min = ds.getMinByteUnsigned();
230
                double[] secondMax = ds.getSecondMaxByteUnsigned();
231
                double[] secondMin = ds.getSecondMinByteUnsigned();
232
                double[] mean = ds.getMean();
233
                double[] variance = ds.getVariance();
234

    
235
                assertEquals(bandCount, 3);
236
                for (int i = 0; i < bandCount; i++)
237
                        switch (i) {
238
                                case 0:
239
                                        assertEquals((int) max[i], 250);
240
                                        assertEquals((int) min[i], 0);
241
                                        assertEquals((int) secondMax[i], 248);
242
                                        assertEquals((int) secondMin[i], 1);
243
                                        assertEquals((int) mean[i], 95);
244
                                        assertEquals((int) variance[i], 3050);
245
                                        break;
246
                                case 1:
247
                                        assertEquals((int) max[i], 255);
248
                                        assertEquals((int) min[i], 0);
249
                                        assertEquals((int) secondMax[i], 254);
250
                                        assertEquals((int) secondMin[i], 3);
251
                                        assertEquals((int) mean[i], 105);
252
                                        assertEquals((int) variance[i], 2689);
253
                                        break;
254
                                case 2:
255
                                        assertEquals((int) max[i], 254);
256
                                        assertEquals((int) min[i], 0);
257
                                        assertEquals((int) secondMax[i], 250);
258
                                        assertEquals((int) secondMin[i], 1);
259
                                        assertEquals((int) mean[i], 85);
260
                                        assertEquals((int) variance[i], 3218);
261
                                        break;
262
                        }
263

    
264
//                System.out.println(ct.getName());
265
//                System.out.println(ct.getType());
266
//                for (int i = 0; i < color.length; i++) {
267
//                        System.out.print(range[i] + ": ");
268
//                        System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]);
269
//                }
270
        }
271

    
272
        public void testGeoInfo(RasterDataStore dataset) {
273
        //TODO: TEST: Terminar test de acceso a la georreferenciaci?n.
274
//                String proj = "";
275
//                if(dataset.getProjection() != null)
276
//                        proj = dataset.getProjection().getAbrev();
277
                AffineTransform at = dataset.getAffineTransform();
278

    
279
                assertEquals((int) at.getTranslateX(), 5000);
280
                assertEquals((int) at.getTranslateY(), 5000);
281
                assertEquals((int) at.getScaleX(), 2);
282
                assertEquals((int) at.getScaleY(), -2);
283
        }
284

    
285
        public void testGeoPoints(GeoPointList gpList) {
286
                GeoPoint p = gpList.get(0);
287

    
288
                assertEquals((int) p.pixelPoint.getX(), 10);
289
                assertEquals((int) p.pixelPoint.getY(), 10);
290
                assertEquals((int) p.mapPoint.getX(), 34223);
291
                assertEquals((int) p.mapPoint.getY(), 2344);
292

    
293
                assertEquals(p.active, true);
294

    
295
//                assertEquals((int) p.leftCenterPoint.getX(), 24223);
296
//                assertEquals((int) p.leftCenterPoint.getY(), 3244);
297
//                assertEquals((int) p.rightCenterPoint.getX(), 2433);
298
//                assertEquals((int) p.rightCenterPoint.getY(), 6244);
299
//
300
//                assertEquals((int) p.leftViewPort.getExtent().minX(), 30032);
301
//                assertEquals((int) p.leftViewPort.getExtent().maxY(), 2103);
302
//
303
//                assertEquals((int) p.rightViewPort.getExtent().minX(), 30032);
304
//                assertEquals((int) p.rightViewPort.getExtent().maxY(), 2103);
305

    
306
                assertEquals((int) p.zoomLeft, 1);
307
                assertEquals((int) p.zoomRight, 1);
308
        }
309
}