Statistics
| Revision:

root / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / rmf / TestRmfWrite.java @ 21576

History | View | Annotate | Download (6.56 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.Point2D;
22
import java.io.File;
23
import java.io.FileNotFoundException;
24
import java.io.IOException;
25

    
26
import junit.framework.TestCase;
27

    
28
import org.gvsig.raster.RasterLibrary;
29
import org.gvsig.raster.buffer.BufferFactory;
30
import org.gvsig.raster.dataset.FileNotOpenException;
31
import org.gvsig.raster.dataset.NotSupportedExtensionException;
32
import org.gvsig.raster.dataset.RasterDataset;
33
import org.gvsig.raster.dataset.io.RasterDriverException;
34
import org.gvsig.raster.dataset.properties.DatasetColorInterpretation;
35
import org.gvsig.raster.dataset.properties.DatasetStatistics;
36
import org.gvsig.raster.dataset.serializer.ColorInterpretationRmfSerializer;
37
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer;
38
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer;
39
import org.gvsig.raster.dataset.serializer.StatisticsRmfSerializer;
40
import org.gvsig.raster.datastruct.ColorTable;
41
import org.gvsig.raster.datastruct.Extent;
42
import org.gvsig.raster.datastruct.GeoPoint;
43
import org.gvsig.raster.datastruct.Histogram;
44
import org.gvsig.raster.datastruct.ViewPortData;
45
import org.gvsig.raster.datastruct.serializer.ColorTableRmfSerializer;
46
import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer;
47
import org.gvsig.raster.datastruct.serializer.NoDataRmfSerializer;
48
/**
49
 * Test de escritura de ficheros rmf.
50
 * Escribe un fichero rmf con distintos bloques y a continuaci?n le pasa un
51
 * test de lectura para comprobar que se ha generado bien.
52
 *
53
 * @author Nacho Brodin (nachobrodin@gmail.com)
54
 */
55
public class TestRmfWrite extends TestCase {
56
        private RmfBlocksManager manager    = null;
57
        private String           baseDir    = "." + File.separator + "test-images" + File.separator;
58
        private String           path       = baseDir + "miniRaster25x24.tif";
59
        private String           pathGif    = baseDir + "gifTransparente.gif";
60
        private String           pathJpg    = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
61
        private Histogram        histogram  = null;
62
        private ColorTable       colorTable = null;
63
        private RasterDataset    f          = null;
64
        private RasterDataset    f2         = null;
65

    
66
        static {
67
                RasterLibrary.wakeUp();
68
        }
69

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

    
75
        public void setUp() {
76
                System.err.println("TestRmfWrite running...");
77

    
78
                RasterDataset f1 = null;
79
                try {
80
                        f = RasterDataset.open(null, path);
81
                        f1 = RasterDataset.open(null, pathGif);
82
                        f2 = RasterDataset.open(null, pathJpg);
83
                } catch (NotSupportedExtensionException e) {
84
                        return;
85
                } catch (RasterDriverException e) {
86
                        return;
87
                }
88
                BufferFactory ds = new BufferFactory(f);
89
                try {
90
                        ds.setAreaOfInterest();
91
                } catch (InterruptedException e1) {
92
                        e1.printStackTrace();
93
                } catch (RasterDriverException e) {
94
                        e.printStackTrace();
95
                }
96

    
97
                try {
98
                        histogram = f.getHistogram().getHistogram();
99
                        colorTable = f1.getColorTable();
100
                        f.getStatistics().calcFullStatistics();
101
                } catch (FileNotOpenException e) {
102
                        e.printStackTrace();
103
                } catch (RasterDriverException e) {
104
                        e.printStackTrace();
105
                } catch (InterruptedException e) {
106
                        e.printStackTrace();
107
                }
108
        }
109

    
110
        public void testStack() {
111
                manager = new RmfBlocksManager(baseDir + "writetest.rmf");
112

    
113
                // Histograma
114
                HistogramRmfSerializer ser = new HistogramRmfSerializer(histogram);
115
                manager.addClient(ser);
116

    
117
                // Tabla de color
118
                // colorTable.setName("Prueba Tabla de Color");
119
                ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer(colorTable);
120
                manager.addClient(ser1);
121

    
122
                // Estadisticas
123
                DatasetStatistics stat = f.getStatistics();
124
                stat.setTailTrimValue(3.0, new Double(10.0));
125
                stat.setTailTrimValue(4.0, new Double(16.0));
126
                StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer(stat);
127
                manager.addClient(ser2);
128

    
129
                // Georreferenciaci?n
130
                GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f2);
131
                manager.addClient(ser3);
132

    
133
                // Puntos de control
134
                GeoPoint p1 = new GeoPoint();
135
                p1.pixelPoint = new Point2D.Double(10, 10);
136
                p1.mapPoint = new Point2D.Double(34223.3, 2344.2);
137
                p1.leftViewPort = new ViewPortData();
138
                p1.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
139
                p1.rightViewPort = new ViewPortData();
140
                p1.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
141
                p1.leftCenterPoint = new Point2D.Double(24223.3, 3244.2);
142
                p1.rightCenterPoint = new Point2D.Double(2433.3, 6244.2);
143
                GeoPoint p2 = new GeoPoint();
144
                p2.pixelPoint = new Point2D.Double(10, 10);
145
                p2.mapPoint = new Point2D.Double(34223.3, 2344.2);
146
                p2.leftViewPort = new ViewPortData();
147
                p2.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
148
                p2.rightViewPort = new ViewPortData();
149
                p2.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
150
                p2.leftCenterPoint = new Point2D.Double(24223.3, 3244.2);
151
                p2.rightCenterPoint = new Point2D.Double(2433.3, 6244.2);
152

    
153
                p1.leftViewPort.pxSize = new Point2D.Double(32, 34);
154
                GeoPointRmfSerializer ser4 = new GeoPointRmfSerializer(new GeoPoint[] { p1, p2 }, p1.leftViewPort);
155
                manager.addClient(ser4);
156

    
157
                // Valor NoData
158
                NoDataRmfSerializer ser5 = new NoDataRmfSerializer(5450.0, 2);
159
                manager.addClient(ser5);
160

    
161
                // Interpretaci?n de color
162
                DatasetColorInterpretation ci = f.getColorInterpretation();
163
                ci.setColorInterpValue(0, DatasetColorInterpretation.BLUE_BAND);
164
                ci.setColorInterpValue(2, DatasetColorInterpretation.RED_BAND);
165
                ColorInterpretationRmfSerializer ser6 = new ColorInterpretationRmfSerializer(f.getColorInterpretation());
166
                manager.addClient(ser6);
167

    
168
                try {
169
                        manager.write();
170
                } catch (FileNotFoundException e) {
171
                        e.printStackTrace();
172
                } catch (IOException e) {
173
                        e.printStackTrace();
174
                }
175

    
176
                // Pasamos el test de lectura para comprobar que se ha generado bien
177
                TestRmfRead t = new TestRmfRead();
178
                t.file = "writetest.rmf";
179
                t.start();
180
        }
181
}