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