Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / dataset / io / rmf / TestRmfWrite.java @ 12522

History | View | Annotate | Download (5.44 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.FileNotFoundException;
23
import java.io.IOException;
24

    
25
import junit.framework.TestCase;
26

    
27
import org.gvsig.raster.RasterLibrary;
28
import org.gvsig.raster.buffer.BufferFactory;
29
import org.gvsig.raster.dataset.FileNotOpenException;
30
import org.gvsig.raster.dataset.NotSupportedExtensionException;
31
import org.gvsig.raster.dataset.RasterDataset;
32
import org.gvsig.raster.dataset.RasterDriverException;
33
import org.gvsig.raster.dataset.properties.DatasetStatistics;
34
import org.gvsig.raster.dataset.serializer.GeoInfoRmfSerializer;
35
import org.gvsig.raster.dataset.serializer.GeoPointRmfSerializer;
36
import org.gvsig.raster.dataset.serializer.StatisticsRmfSerializer;
37
import org.gvsig.raster.datastruct.ColorTable;
38
import org.gvsig.raster.datastruct.Extent;
39
import org.gvsig.raster.datastruct.GeoPoint;
40
import org.gvsig.raster.datastruct.Histogram;
41
import org.gvsig.raster.datastruct.ViewPortData;
42
import org.gvsig.raster.datastruct.serializer.HistogramRmfSerializer;
43

    
44
/**
45
 * Test de escritura de ficheros rmf.
46
 * Escribe un fichero rmf con distintos bloques y a continuaci?n le pasa un 
47
 * test de lectura para comprobar que se ha generado bien.
48
 * 
49
 * @author Nacho Brodin (nachobrodin@gmail.com)
50
 *
51
 */
52
public class TestRmfWrite extends TestCase {
53
        
54
        private RmfBlocksManager manager = null;
55
        private String baseDir = "./test-images/";
56
        private String path = baseDir + "miniRaster25x24.tif";
57
        private String pathGif = baseDir + "gifTransparente.gif";
58
        private String pathJpg = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg";
59
        private Histogram histogram = null;
60
        private ColorTable colorTable = null;
61
        private RasterDataset f = null;
62
        private RasterDataset f2 = null;
63
        
64
        static {
65
                RasterLibrary.wakeUp();
66
        }
67
        
68
        public void start() {
69
                this.setUp();
70
                this.testStack();
71
        }
72
        
73
        public void setUp() {
74
                System.err.println("TestRmfWrite running...");
75
                
76
                RasterDataset f1 = null;        
77
                try {
78
                        f = RasterDataset.open(null, path);
79
                        f1 = RasterDataset.open(null, pathGif);
80
                        f2 = RasterDataset.open(null, pathJpg);
81
                } catch (NotSupportedExtensionException e) {
82
                        return;
83
                } catch (RasterDriverException e) {
84
                        return;
85
                }
86
                BufferFactory ds = new BufferFactory(f);
87
                ds.setAreaOfInterest();
88
                
89
                try {
90
                        histogram = f.getHistogram().getHistogram();
91
                        colorTable = f1.getColorTable();
92
                        f.getStatistics().calcFullStatistics();
93
                } catch (FileNotOpenException e) {
94
                        e.printStackTrace();
95
                } catch (RasterDriverException e) {
96
                        e.printStackTrace();
97
                }
98
                
99
        }
100
        
101
        public void testStack(){
102
                manager = new RmfBlocksManager(baseDir + "writetest.rmf");
103
                
104
                //Histograma
105
                HistogramRmfSerializer ser = new HistogramRmfSerializer(histogram);
106
                manager.addClient(ser);
107
                
108
                //Tabla de color
109
                colorTable.setName("Prueba Tabla de Color");
110
                //ColorTableRmfSerializer ser1 = new ColorTableRmfSerializer(colorTable);
111
                //manager.addClient(ser1);
112
                
113
                //Estadisticas
114
                DatasetStatistics stat = f.getStatistics();
115
                stat.setTailTrimValue(3.0, new Double(10.0));
116
                stat.setTailTrimValue(4.0, new Double(16.0));
117
                StatisticsRmfSerializer ser2 = new StatisticsRmfSerializer(stat);
118
                manager.addClient(ser2);
119
                
120
                //Georreferenciaci?n
121
                GeoInfoRmfSerializer ser3 = new GeoInfoRmfSerializer(f2);
122
                manager.addClient(ser3);
123
                
124
                //Puntos de control
125
                GeoPoint p1 = new GeoPoint();
126
                p1.pixelPoint = new Point2D.Double(10, 10);
127
                p1.mapPoint = new Point2D.Double(34223.3, 2344.2);
128
                p1.leftViewPort = new ViewPortData();
129
                p1.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
130
                p1.rightViewPort = new ViewPortData();
131
                p1.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
132
                p1.leftCenterPoint = new Point2D.Double(24223.3, 3244.2);
133
                p1.rightCenterPoint = new Point2D.Double(2433.3, 6244.2);
134
                GeoPoint p2 = new GeoPoint();
135
                p2.pixelPoint = new Point2D.Double(10, 10);
136
                p2.mapPoint = new Point2D.Double(34223.3, 2344.2);
137
                p2.leftViewPort = new ViewPortData();
138
                p2.leftViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
139
                p2.rightViewPort = new ViewPortData();
140
                p2.rightViewPort.setExtent(new Extent(30032.3, 2103.3, 50023.3, 1234.3));
141
                p2.leftCenterPoint = new Point2D.Double(24223.3, 3244.2);
142
                p2.rightCenterPoint = new Point2D.Double(2433.3, 6244.2);
143
                GeoPointRmfSerializer ser4 = new GeoPointRmfSerializer(new GeoPoint[]{p1, p2});
144
                manager.addClient(ser4);
145
                
146
                try {
147
                        manager.write();
148
                } catch (FileNotFoundException e) {
149
                        e.printStackTrace();
150
                } catch (IOException e) {
151
                        e.printStackTrace();
152
                }
153
                
154
                //Pasamos el test de lectura para comprobar que se ha generado bien
155
                TestRmfRead t = new TestRmfRead();
156
                t.file = "writetest.rmf";
157
                t.start();
158
        }
159

    
160
}