svn-gvsig-desktop / trunk / libraries / libRaster / src-test / org / gvsig / raster / buffer / TestBufferInterpolation.java @ 11652
History | View | Annotate | Download (7.55 KB)
1 |
/*
|
---|---|
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.buffer; |
26 |
|
27 |
import java.io.File; |
28 |
import java.io.IOException; |
29 |
|
30 |
import junit.framework.TestCase; |
31 |
|
32 |
import org.gvsig.raster.RasterLibrary; |
33 |
import org.gvsig.raster.buffer.cache.WriterBufferServer; |
34 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
35 |
import org.gvsig.raster.dataset.IBuffer; |
36 |
import org.gvsig.raster.dataset.IDataWriter; |
37 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
38 |
import org.gvsig.raster.dataset.Params; |
39 |
import org.gvsig.raster.dataset.RasterDataset; |
40 |
import org.gvsig.raster.dataset.RasterDriverException; |
41 |
import org.gvsig.raster.shared.Extent; |
42 |
|
43 |
/**
|
44 |
* Test para probar las interpolaciones de un buffer de datos completo. El test crear? un
|
45 |
* buffer a partir de una imagen de 870x870 y aplicar? una reducci?n usando los m?todos
|
46 |
* de interpolaci?n implementados. Despu?s comparar? el resultado con imagenes ya generadas
|
47 |
* y correctas que se encuentran en el directorio de test-images.
|
48 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
49 |
*
|
50 |
*/
|
51 |
public class TestBufferInterpolation extends TestCase { |
52 |
private String baseDir = "./test-images/"; |
53 |
private String path = baseDir + "03AUG23153350-M2AS-000000122423_01_P001-BROWSE.jpg"; |
54 |
private RasterDataset f = null; |
55 |
private BufferFactory ds = null; |
56 |
private int size = 50; |
57 |
|
58 |
private String fileNeighbour1 = baseDir + "neighbour50x50.tif"; |
59 |
private String fileBilinear1 = baseDir + "bilinear50x50.tif"; |
60 |
private String fileInverseDistance1 = baseDir + "inverseDistance50x50.tif"; |
61 |
private String fileBSpline1 = baseDir + "bspline50x50.tif"; |
62 |
private String fileBicubicSpline1 = baseDir + "bicubicspline50x50.tif"; |
63 |
|
64 |
private String fileNeighbour = "/tmp/neighbour.tif"; |
65 |
private String fileBilinear = "/tmp/bilinear.tif"; |
66 |
private String fileInverseDistance = "/tmp/invdistance.tif"; |
67 |
private String fileBSpline = "/tmp/bspline.tif"; |
68 |
private String fileBicubicSpline = "/tmp/bicubicspline.tif"; |
69 |
|
70 |
static {
|
71 |
RasterLibrary.wakeUp(); |
72 |
} |
73 |
|
74 |
public void start() { |
75 |
this.setUp();
|
76 |
this.testStack();
|
77 |
} |
78 |
|
79 |
public void setUp() { |
80 |
System.err.println("TestBufferInterpolation running..."); |
81 |
int[] drawableBands = {0, 1, 2}; |
82 |
try {
|
83 |
f = RasterDataset.open(null, path);
|
84 |
} catch (NotSupportedExtensionException e) {
|
85 |
e.printStackTrace(); |
86 |
return;
|
87 |
} catch (RasterDriverException e) {
|
88 |
e.printStackTrace(); |
89 |
return;
|
90 |
} |
91 |
ds = new BufferFactory(f);
|
92 |
ds.addDrawableBands(drawableBands); |
93 |
ds.setAreaOfInterest(0, 0, f.getWidth(), f.getHeight()); |
94 |
RasterBuffer buf = (RasterBuffer)ds.getRasterBuf(); |
95 |
|
96 |
try {
|
97 |
IBuffer b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_NearestNeighbour); |
98 |
convertBufferToTif(fileNeighbour, f.getExtent(), b1); |
99 |
b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_Bilinear); |
100 |
convertBufferToTif(fileBilinear, f.getExtent(), b1); |
101 |
b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_InverseDistance); |
102 |
convertBufferToTif(fileInverseDistance, f.getExtent(), b1); |
103 |
b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BSpline); |
104 |
convertBufferToTif(fileBSpline, f.getExtent(), b1); |
105 |
b1 = buf.getAdjustedWindow(size, size, BufferInterpolation.INTERPOLATION_BicubicSpline); |
106 |
convertBufferToTif(fileBicubicSpline, f.getExtent(), b1); |
107 |
} catch (IOException e) { |
108 |
e.printStackTrace(); |
109 |
} |
110 |
} |
111 |
|
112 |
public void testStack(){ |
113 |
compareResult(fileNeighbour, fileNeighbour1); |
114 |
compareResult(fileBilinear, fileBilinear1); |
115 |
compareResult(fileInverseDistance, fileInverseDistance1); |
116 |
compareResult(fileBSpline, fileBSpline1); |
117 |
//compareResult(fileBicubicSpline, fileBicubicSpline1);
|
118 |
File file1 = new File(fileNeighbour); |
119 |
File file2 = new File(fileBilinear); |
120 |
File file3 = new File(fileInverseDistance); |
121 |
File file4 = new File(fileBSpline); |
122 |
//File file5 = new File(fileBicubicSpline);
|
123 |
if(file1.exists())
|
124 |
file1.delete(); |
125 |
if(file2.exists())
|
126 |
file2.delete(); |
127 |
if(file3.exists())
|
128 |
file3.delete(); |
129 |
if(file4.exists())
|
130 |
file4.delete(); |
131 |
//if(file5.exists())
|
132 |
// file5.delete();
|
133 |
} |
134 |
|
135 |
/**
|
136 |
* Compara dos ficheros raster
|
137 |
* @param f1
|
138 |
* @param f2
|
139 |
*/
|
140 |
private void compareResult(String f1, String f2) { |
141 |
int[] drawableBands = {0, 1, 2}; |
142 |
RasterDataset d1 = null;
|
143 |
RasterDataset d2 = null;
|
144 |
try {
|
145 |
d1 = RasterDataset.open(null, f1);
|
146 |
d2 = RasterDataset.open(null, f2);
|
147 |
} catch (NotSupportedExtensionException e) {
|
148 |
e.printStackTrace(); |
149 |
return;
|
150 |
} catch (RasterDriverException e) {
|
151 |
e.printStackTrace(); |
152 |
return;
|
153 |
} |
154 |
BufferFactory ds = new BufferFactory(d1);
|
155 |
ds.addDrawableBands(drawableBands); |
156 |
ds.setAreaOfInterest(0, 0, d1.getWidth(), d1.getHeight()); |
157 |
IBuffer b1 = ds.getRasterBuf(); |
158 |
|
159 |
ds = new BufferFactory(d2);
|
160 |
ds.addDrawableBands(drawableBands); |
161 |
ds.setAreaOfInterest(0, 0, d1.getWidth(), d1.getHeight()); |
162 |
IBuffer b2 = ds.getRasterBuf(); |
163 |
|
164 |
for (int k = 0; k < b1.getBandCount(); k++) { |
165 |
for (int i = 0; i < b1.getHeight(); i++) { |
166 |
for (int j = 0; j < b1.getWidth(); j++) { |
167 |
switch(b1.getDataType()) {
|
168 |
case IBuffer.TYPE_BYTE:
|
169 |
assertEquals(b1.getElemByte(i, j, k), b2.getElemByte(i, j, k)); |
170 |
break;
|
171 |
case IBuffer.TYPE_SHORT:
|
172 |
assertEquals(b1.getElemShort(i, j, k), b2.getElemShort(i, j, k)); |
173 |
break;
|
174 |
|
175 |
case IBuffer.TYPE_INT:
|
176 |
assertEquals(b1.getElemInt(i, j, k), b2.getElemInt(i, j, k)); |
177 |
break;
|
178 |
|
179 |
case IBuffer.TYPE_FLOAT:
|
180 |
assertEquals((int)b1.getElemFloat(i, j, k), (int)b2.getElemFloat(i, j, k)); |
181 |
break;
|
182 |
|
183 |
case IBuffer.TYPE_DOUBLE:
|
184 |
assertEquals((int)b1.getElemDouble(i, j, k), (int)b2.getElemDouble(i, j, k)); |
185 |
break;
|
186 |
} |
187 |
} |
188 |
} |
189 |
} |
190 |
} |
191 |
|
192 |
/**
|
193 |
* Funci?n para pruebas.
|
194 |
* Convierte los ficheros generados por la funci?n cachear en ficheros tif para comprobar que est?n
|
195 |
* bien generados.
|
196 |
* @param grf
|
197 |
* @param pageBuffer
|
198 |
* @param pageLines
|
199 |
* @throws IOException
|
200 |
*/
|
201 |
private void convertBufferToTif(String fileName, Extent ext, IBuffer buffer)throws IOException { |
202 |
IDataWriter dataWriter1 = new WriterBufferServer(buffer);
|
203 |
GeoRasterWriter grw = null;
|
204 |
try {
|
205 |
Params params = GeoRasterWriter.getWriter(fileName).getParams(); |
206 |
params.changeParamValue("blocksize", "512"); |
207 |
params.changeParamValue("tfw", "false"); |
208 |
params.changeParamValue("interleave", "PIXEL"); |
209 |
grw = GeoRasterWriter.getWriter(dataWriter1, |
210 |
fileName, |
211 |
buffer.getBandCount(), |
212 |
ext, |
213 |
buffer.getWidth(), |
214 |
buffer.getHeight(), |
215 |
buffer.getDataType(), |
216 |
params); |
217 |
|
218 |
} catch (NotSupportedExtensionException e) {
|
219 |
e.printStackTrace(); |
220 |
} catch (RasterDriverException e) {
|
221 |
e.printStackTrace(); |
222 |
} |
223 |
grw.dataWrite(); |
224 |
grw.writeClose(); |
225 |
} |
226 |
|
227 |
} |