svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / rmf / TestRmfRead.java @ 17651
History | View | Annotate | Download (9.24 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.dataset.io.rmf; |
20 |
|
21 |
import java.awt.geom.AffineTransform; |
22 |
|
23 |
import junit.framework.TestCase; |
24 |
|
25 |
import org.gvsig.raster.RasterLibrary; |
26 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
27 |
import org.gvsig.raster.dataset.RasterDataset; |
28 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
29 |
import org.gvsig.raster.dataset.properties.DatasetStatistics; |
30 |
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer; |
31 |
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer; |
32 |
import org.gvsig.raster.dataset.serializer.StatisticsRmfSerializer; |
33 |
import org.gvsig.raster.datastruct.ColorTable; |
34 |
import org.gvsig.raster.datastruct.GeoPoint; |
35 |
import org.gvsig.raster.datastruct.Histogram; |
36 |
import org.gvsig.raster.datastruct.HistogramClass; |
37 |
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer; |
38 |
import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer; |
39 |
import org.gvsig.raster.datastruct.serializer.NoDataRmfSerializer; |
40 |
|
41 |
/**
|
42 |
* Test de lectura para ficheros rmf.
|
43 |
* Obtiene distintos tipos de bloques y comprueba que el objeto que han
|
44 |
* de generar es correcto.
|
45 |
*
|
46 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
47 |
*
|
48 |
*/
|
49 |
public class TestRmfRead extends TestCase { |
50 |
|
51 |
private String baseDir = "./test-images/"; |
52 |
private RmfBlocksManager manager = null; |
53 |
public String file = "readtest.rmf"; |
54 |
private RasterDataset f1 = null; |
55 |
private String path1 = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg"; |
56 |
|
57 |
static {
|
58 |
RasterLibrary.wakeUp(); |
59 |
} |
60 |
|
61 |
public void start() { |
62 |
this.setUp();
|
63 |
this.testStack();
|
64 |
} |
65 |
|
66 |
public void setUp() { |
67 |
System.err.println("TestRmfRead running..."); |
68 |
try {
|
69 |
f1 = RasterDataset.open(null, path1);
|
70 |
} catch (NotSupportedExtensionException e1) {
|
71 |
e1.printStackTrace(); |
72 |
} catch (RasterDriverException e1) {
|
73 |
e1.printStackTrace(); |
74 |
} |
75 |
} |
76 |
|
77 |
public void testStack(){ |
78 |
manager = new RmfBlocksManager(baseDir + file);
|
79 |
if(!manager.checkRmf())
|
80 |
assertEquals(0, 1); |
81 |
HistogramRmfSerializer ser = new HistogramRmfSerializer();
|
82 |
ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer();
|
83 |
StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer();
|
84 |
GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f1);
|
85 |
GeoPointRmfSerializer ser4 = new GeoPointRmfSerializer();
|
86 |
NoDataRmfSerializer ser5 = new NoDataRmfSerializer();
|
87 |
|
88 |
manager.addClient(ser); |
89 |
manager.addClient(ser1); |
90 |
manager.addClient(ser2); |
91 |
manager.addClient(ser3); |
92 |
manager.addClient(ser4); |
93 |
manager.addClient(ser5); |
94 |
|
95 |
try {
|
96 |
manager.read(null);
|
97 |
for (int i = 0; i < manager.getClientsCount(); i++) { |
98 |
IRmfBlock client = manager.getClient(i); |
99 |
if (client instanceof HistogramRmfSerializer) |
100 |
testHistogram((Histogram) client.getResult()); |
101 |
if (client instanceof ColorTableRmfSerializer) { |
102 |
ColorTable colorTable = (ColorTable) client.getResult(); |
103 |
colorTable.setInterpolated(false);
|
104 |
testColorTable(colorTable); |
105 |
} |
106 |
if (client instanceof StatisticsRmfSerializer) |
107 |
testStatistics((DatasetStatistics) client.getResult()); |
108 |
if (client instanceof NoDataRmfSerializer) |
109 |
testNoData((Double) client.getResult());
|
110 |
// if (client instanceof GeoInfoRmfSerializer)
|
111 |
// testGeoInfo((RasterDataset) client.getResult());
|
112 |
if (client instanceof GeoPointRmfSerializer) |
113 |
testGeoPoints((GeoPoint[]) client.getResult());
|
114 |
} |
115 |
|
116 |
} catch (ParsingException e) {
|
117 |
e.printStackTrace(); |
118 |
} |
119 |
|
120 |
} |
121 |
|
122 |
public void testHistogram(Histogram h) { |
123 |
HistogramClass[][] classes = h.getHistogram(); |
124 |
for (int iBand = 0; iBand < classes.length; iBand++) { |
125 |
for (int iValue = 0; iValue < classes[iBand].length; iValue++) { |
126 |
assertEquals((int)classes[iBand][iValue].getMin(), iValue);
|
127 |
assertEquals((int)classes[iBand][iValue].getMax(), iValue + 1); |
128 |
} |
129 |
} |
130 |
|
131 |
assertEquals((int)classes[0][0].getValue(), 16); |
132 |
assertEquals((int)classes[0][1].getValue(), 4); |
133 |
assertEquals((int)classes[0][23].getValue(), 6); |
134 |
assertEquals((int)classes[0][48].getValue(), 4); |
135 |
|
136 |
assertEquals((int)classes[1][0].getValue(), 2); |
137 |
assertEquals((int)classes[1][4].getValue(), 1); |
138 |
assertEquals((int)classes[1][7].getValue(), 8); |
139 |
assertEquals((int)classes[1][20].getValue(), 4); |
140 |
|
141 |
assertEquals((int)classes[2][0].getValue(), 25); |
142 |
assertEquals((int)classes[2][2].getValue(), 1); |
143 |
assertEquals((int)classes[2][13].getValue(), 4); |
144 |
assertEquals((int)classes[2][21].getValue(), 2); |
145 |
} |
146 |
|
147 |
public void testColorTable(ColorTable ct) { |
148 |
|
149 |
byte[][] color = ct.getColorTableByBand(); |
150 |
|
151 |
// assertEquals(ct.getName(), "Prueba Tabla de Color");
|
152 |
|
153 |
assertEquals(ct.getRGBAByBand(15)[0] & 0xff, 95); |
154 |
assertEquals(ct.getRGBAByBand(15)[1] & 0xff, 95); |
155 |
assertEquals(ct.getRGBAByBand(15)[2] & 0xff, 95); |
156 |
|
157 |
assertEquals(ct.getRGBAByBand(22)[0] & 0xff, 0); |
158 |
assertEquals(ct.getRGBAByBand(22)[1] & 0xff, 0); |
159 |
assertEquals(ct.getRGBAByBand(22)[2] & 0xff, 0); |
160 |
|
161 |
assertEquals(ct.getRGBAByBand(24)[0] & 0xff, 0); |
162 |
assertEquals(ct.getRGBAByBand(24)[1] & 0xff, 0); |
163 |
assertEquals(ct.getRGBAByBand(24)[2] & 0xff, 0); |
164 |
|
165 |
assertEquals(ct.getRGBAByBand(28)[0] & 0xff, 0); |
166 |
assertEquals(ct.getRGBAByBand(28)[1] & 0xff, 0); |
167 |
assertEquals(ct.getRGBAByBand(28)[2] & 0xff, 0); |
168 |
|
169 |
assertEquals(ct.getRGBAByBand(0)[0] & 0xff, 255); |
170 |
assertEquals(ct.getRGBAByBand(0)[1] & 0xff, 255); |
171 |
assertEquals(ct.getRGBAByBand(0)[2] & 0xff, 255); |
172 |
|
173 |
assertEquals(ct.getRGBAByBand(1)[0] & 0xff, 0); |
174 |
assertEquals(ct.getRGBAByBand(1)[1] & 0xff, 0); |
175 |
assertEquals(ct.getRGBAByBand(1)[2] & 0xff, 0); |
176 |
|
177 |
assertEquals(ct.getRGBAByBand(2)[0] & 0xff, 0); |
178 |
assertEquals(ct.getRGBAByBand(2)[1] & 0xff, 102); |
179 |
assertEquals(ct.getRGBAByBand(2)[2] & 0xff, 255); |
180 |
|
181 |
System.out.println(ct.getName());
|
182 |
|
183 |
for (int i = 0; i < color.length; i++) { |
184 |
System.out.println((color[i][0] & 0xff) + " " + (color[i][1] & 0xff) + " " + (color[i][2] & 0xff)); |
185 |
} |
186 |
} |
187 |
|
188 |
public void testNoData(Double noData) { |
189 |
assertEquals((int) noData.doubleValue(), 5450); |
190 |
} |
191 |
|
192 |
public void testStatistics(DatasetStatistics ds) { |
193 |
int bandCount = ds.getBandCount();
|
194 |
double[] max = ds.getMax(); |
195 |
double[] min = ds.getMin(); |
196 |
double[] secondMax = ds.getSecondMax(); |
197 |
double[] secondMin = ds.getSecondMin(); |
198 |
double[] mean = ds.getMean(); |
199 |
double[] variance = ds.getVariance(); |
200 |
|
201 |
assertEquals(bandCount, 3);
|
202 |
for (int i = 0; i < bandCount; i++) { |
203 |
switch(i) {
|
204 |
case 0: |
205 |
assertEquals((int)max[i], 250); |
206 |
assertEquals((int)min[i], 0); |
207 |
assertEquals((int)secondMax[i], 248); |
208 |
assertEquals((int)secondMin[i], 1); |
209 |
assertEquals((int)mean[i], 95); |
210 |
assertEquals((int)variance[i], 3050); |
211 |
break;
|
212 |
case 1: |
213 |
assertEquals((int)max[i], 255); |
214 |
assertEquals((int)min[i], 0); |
215 |
assertEquals((int)secondMax[i], 254); |
216 |
assertEquals((int)secondMin[i], 3); |
217 |
assertEquals((int)mean[i], 105); |
218 |
assertEquals((int)variance[i], 2689); |
219 |
break;
|
220 |
case 2: |
221 |
assertEquals((int)max[i], 254); |
222 |
assertEquals((int)min[i], 0); |
223 |
assertEquals((int)secondMax[i], 250); |
224 |
assertEquals((int)secondMin[i], 1); |
225 |
assertEquals((int)mean[i], 85); |
226 |
assertEquals((int)variance[i], 3218); |
227 |
break;
|
228 |
} |
229 |
} |
230 |
|
231 |
//System.out.println(ct.getName());
|
232 |
//System.out.println(ct.getType());
|
233 |
|
234 |
/*for (int i = 0; i < color.length; i++) {
|
235 |
System.out.print(range[i] + ": ");
|
236 |
System.out.println(color[i][0] + " " + color[i][1] + " " + color[i][2]);
|
237 |
}*/
|
238 |
} |
239 |
|
240 |
public void testGeoInfo(RasterDataset dataset) { |
241 |
//String proj = "";
|
242 |
//TODO: TEST: Terminar test de acceso a la georreferenciaci?n.
|
243 |
//if(dataset.getProjection() != null)
|
244 |
//proj = dataset.getProjection().getAbrev();
|
245 |
AffineTransform at = dataset.getAffineTransform();
|
246 |
|
247 |
assertEquals((int)at.getTranslateX(), 5000); |
248 |
assertEquals((int)at.getTranslateY(), 5000); |
249 |
assertEquals((int)at.getScaleX(), 2); |
250 |
assertEquals((int)at.getScaleY(), -2); |
251 |
} |
252 |
|
253 |
public void testGeoPoints(GeoPoint[] gpList) { |
254 |
GeoPoint p = gpList[0];
|
255 |
|
256 |
assertEquals((int)p.pixelPoint.getX(), 10); |
257 |
assertEquals((int)p.pixelPoint.getY(), 10); |
258 |
assertEquals((int)p.mapPoint.getX(), 34223); |
259 |
assertEquals((int)p.mapPoint.getY(), 2344); |
260 |
|
261 |
assertEquals(p.active, true);
|
262 |
|
263 |
assertEquals((int)p.leftCenterPoint.getX(), 24223); |
264 |
assertEquals((int)p.leftCenterPoint.getY(), 3244); |
265 |
assertEquals((int)p.rightCenterPoint.getX(), 2433); |
266 |
assertEquals((int)p.rightCenterPoint.getY(), 6244); |
267 |
|
268 |
assertEquals((int)p.leftViewPort.getExtent().minX(), 30032); |
269 |
assertEquals((int)p.leftViewPort.getExtent().maxY(), 2103); |
270 |
|
271 |
assertEquals((int)p.rightViewPort.getExtent().minX(), 30032); |
272 |
assertEquals((int)p.rightViewPort.getExtent().maxY(), 2103); |
273 |
|
274 |
assertEquals((int)p.zoomLeft, 1); |
275 |
assertEquals((int)p.zoomRight, 1); |
276 |
|
277 |
} |
278 |
|
279 |
} |