svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / TestHistogramSerializer.java @ 12522
History | View | Annotate | Download (2.96 KB)
1 | 12276 | nacho | /* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|---|---|
2 | 11326 | nacho | *
|
3 | * Copyright (C) 2004 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; |
||
20 | |||
21 | import junit.framework.TestCase; |
||
22 | |||
23 | import org.gvsig.raster.RasterLibrary; |
||
24 | 11329 | nacho | import org.gvsig.raster.dataset.io.rmf.ParsingException; |
25 | 11326 | nacho | import org.gvsig.raster.dataset.properties.DatasetHistogram; |
26 | 12383 | nacho | import org.gvsig.raster.datastruct.Histogram; |
27 | import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer; |
||
28 | 11326 | nacho | |
29 | /**
|
||
30 | 11332 | nacho | * Test para comprobar la construcci?n de un histograma desde un XML. Este test calcula el histograma
|
31 | * de un raster y lo convierte a XML. Despu?s crear? un objeto Histogram a partir del XML. Finalmente
|
||
32 | * se comparar? el Histograma original con el final.
|
||
33 | 11326 | nacho | *
|
34 | * @author Nacho Brodin (nachobrodin@gmail.com)
|
||
35 | */
|
||
36 | public class TestHistogramSerializer extends TestCase { |
||
37 | |||
38 | private String baseDir = "./test-images/"; |
||
39 | private String path = baseDir + "miniraster30x30.jp2"; |
||
40 | private RasterDataset f = null; |
||
41 | |||
42 | static {
|
||
43 | RasterLibrary.wakeUp(); |
||
44 | } |
||
45 | |||
46 | public void start() { |
||
47 | this.setUp();
|
||
48 | this.testStack();
|
||
49 | } |
||
50 | |||
51 | public void setUp() { |
||
52 | System.err.println("TestHistogramSerializer running..."); |
||
53 | int[] drawableBands = {0, 1, 2}; |
||
54 | try {
|
||
55 | f = RasterDataset.open(null, path);
|
||
56 | } catch (NotSupportedExtensionException e) {
|
||
57 | e.printStackTrace(); |
||
58 | return;
|
||
59 | } catch (RasterDriverException e) {
|
||
60 | e.printStackTrace(); |
||
61 | return;
|
||
62 | } |
||
63 | |||
64 | } |
||
65 | |||
66 | public void testStack() { |
||
67 | DatasetHistogram dsh = f.getHistogram(); |
||
68 | 11332 | nacho | Histogram hist1 = null;
|
69 | 11326 | nacho | try {
|
70 | 11332 | nacho | hist1 = dsh.getHistogram(); |
71 | 11326 | nacho | } catch (FileNotOpenException e) {
|
72 | e.printStackTrace(); |
||
73 | } catch (RasterDriverException e) {
|
||
74 | e.printStackTrace(); |
||
75 | } |
||
76 | 11332 | nacho | HistogramRmfSerializer serial1 = new HistogramRmfSerializer(hist1);
|
77 | String s = serial1.write();
|
||
78 | 11336 | nacho | //System.out.println(s);
|
79 | 11332 | nacho | |
80 | HistogramRmfSerializer serial2 = new HistogramRmfSerializer();
|
||
81 | 11329 | nacho | try {
|
82 | 11332 | nacho | serial2.read(s); |
83 | 11329 | nacho | } catch (ParsingException e) {
|
84 | e.printStackTrace(); |
||
85 | } |
||
86 | 11336 | nacho | Histogram hist2 = (Histogram)serial2.getResult(); |
87 | 11329 | nacho | |
88 | 11332 | nacho | assertEquals(hist1.getNumBands(), hist2.getNumBands()); |
89 | for (int iBand = 0; iBand < hist1.getNumBands(); iBand++) { |
||
90 | for(int i = 0; i < hist1.getNumValues(); i++) |
||
91 | assertEquals((long)hist1.getHistogramValue(iBand, i), (long)hist2.getHistogramValue(iBand, i)); |
||
92 | } |
||
93 | |||
94 | 11326 | nacho | } |
95 | 11329 | nacho | |
96 | 11326 | nacho | } |