Revision 4578
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/SharpeningImageFilter.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.cresques.io.raster; |
|
25 |
|
|
26 |
import java.awt.Dimension; |
|
27 |
import java.awt.Graphics2D; |
|
28 |
import java.awt.Image; |
|
29 |
import java.awt.image.BufferedImage; |
|
30 |
import java.awt.image.PixelGrabber; |
|
31 |
|
|
32 |
import org.cresques.geo.ViewPortData; |
|
33 |
import org.cresques.io.GeoRasterFile; |
|
34 |
import org.cresques.px.PxRaster; |
|
35 |
|
|
36 |
|
|
37 |
/** |
|
38 |
* Filtro de sharpening que se aplica sobre la vista. Tiene como entradas el objeto Image |
|
39 |
* con las bandas del raster visualizadas en la Vista y la banda pancrom?tica. A partir de |
|
40 |
* estas entradas genera un Image de salida como la que hay pero de resoluci?n igual a la |
|
41 |
* de la pancrom?tica. |
|
42 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
43 |
* |
|
44 |
*/ |
|
45 |
public class SharpeningImageFilter extends SharpeningFilter { |
|
46 |
|
|
47 |
//Variable que dice para cada pixel de la imagen de entrada cuantos de salida hay. |
|
48 |
private int nOutputPixelsPerInputPixel; |
|
49 |
//Vector con los desplazamientos de los pixeles de salida dentro del vector |
|
50 |
private int[] outKernel; |
|
51 |
//Kernel aplicado a la pancromatica |
|
52 |
private Kernel kernel = null; |
|
53 |
private PixelGrabber pgAct = null, pgPrev = null, pgNext = null; |
|
54 |
int[] bufferPrev = null, bufferAct = null, bufferNext = null; |
|
55 |
|
|
56 |
/** |
|
57 |
* Constructor |
|
58 |
* |
|
59 |
*/ |
|
60 |
public SharpeningImageFilter() { |
|
61 |
super(); |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Validamos que haya alguna otra banda adem?s de la pancrom?tica y que la pancrom?tica |
|
66 |
* sea de mayor resoluci?n que las dem?s. |
|
67 |
*/ |
|
68 |
private void checkInput(){ |
|
69 |
exec = true; |
|
70 |
if(heightMultiespec >= heightPancr || widthMultiespec >= widthPancr || heightMultiespec == 0 || widthMultiespec == 0) |
|
71 |
exec = false; |
|
72 |
for(int i=0;i<files.length;i++){ |
|
73 |
if(i != posPancromatica){ |
|
74 |
if(files[i].getHeight() != heightMultiespec || files[i].getWidth() != widthMultiespec){ |
|
75 |
exec = false; |
|
76 |
break; |
|
77 |
} |
|
78 |
} |
|
79 |
} |
|
80 |
} |
|
81 |
|
|
82 |
/** |
|
83 |
* Carga los par?metros pasados al filtro en las variables de |
|
84 |
* instancia que corresponde, |
|
85 |
*/ |
|
86 |
private void loadParam(){ |
|
87 |
//Carga de parametros |
|
88 |
this.image = (Image) params.get("raster"); |
|
89 |
posPancromatica = ((Integer) params.get("pancromatica")).intValue(); |
|
90 |
files = (GeoRasterFile[]) params.get("files"); |
|
91 |
bandOrder = (int[]) params.get("order"); |
|
92 |
alpha = ((Integer) params.get("alpha")).intValue(); |
|
93 |
method = (String) params.get("method"); |
|
94 |
coef = ((Double) params.get("coef")).doubleValue(); |
|
95 |
coefBrovey = ((Integer) params.get("coefBrovey")).intValue(); |
|
96 |
|
|
97 |
//Asignamos el nombre de la banda pancrom?tica como par?metro para que cuando |
|
98 |
//volvamos a abrir el dialogo pueda recuperarse y seleccionarse en el cuadro |
|
99 |
pancrName = files[posPancromatica].getName().substring( |
|
100 |
files[posPancromatica].getName().lastIndexOf("/")+1, |
|
101 |
files[posPancromatica].getName().length()); |
|
102 |
this.addParam("pancrName", pancrName); |
|
103 |
|
|
104 |
height = image.getHeight(null); |
|
105 |
width = image.getWidth(null); |
|
106 |
heightPancr = files[posPancromatica].getHeight(); |
|
107 |
widthPancr = files[posPancromatica].getWidth(); |
|
108 |
for(int i=0;i<files.length;i++){ |
|
109 |
if(i != posPancromatica){ |
|
110 |
heightMultiespec = files[i].getHeight(); |
|
111 |
widthMultiespec = files[i].getWidth(); |
|
112 |
} |
|
113 |
} |
|
114 |
|
|
115 |
relX = (int)widthPancr/widthMultiespec; |
|
116 |
relY = (int)heightPancr/heightMultiespec; |
|
117 |
} |
|
118 |
|
|
119 |
/* (non-Javadoc) |
|
120 |
* @see org.cresques.io.raster.IRasterFilter#pre() |
|
121 |
*/ |
|
122 |
public void pre() { |
|
123 |
|
|
124 |
loadParam(); |
|
125 |
checkInput(); |
|
126 |
|
|
127 |
//Creamos el buffer donde se pinta la pancromatica |
|
128 |
|
|
129 |
imagePancr = new BufferedImage(width, height, BufferedImage.TYPE_INT_ARGB); |
|
130 |
Graphics2D graphicsPancr = (Graphics2D)imagePancr.getGraphics(); |
|
131 |
PxRaster rasterPancr = new PxRaster(files[posPancromatica], null, files[posPancromatica].getView()); |
|
132 |
|
|
133 |
rasterPancr.setBand(GeoRasterFile.RED_BAND, 0); |
|
134 |
rasterPancr.setBand(GeoRasterFile.GREEN_BAND, 1); |
|
135 |
rasterPancr.setBand(GeoRasterFile.BLUE_BAND, 2); |
|
136 |
|
|
137 |
ViewPortData vp = (ViewPortData)viewPortData.clone(); |
|
138 |
vp.zoom(extent); |
|
139 |
rasterPancr.draw(graphicsPancr, vp); |
|
140 |
rasterPancr = null; |
|
141 |
|
|
142 |
//Creamos el buffer donde se pinta la imagen de entrada |
|
143 |
|
|
144 |
imageMultiespec = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB); |
|
145 |
Graphics2D graphicsMultiespec = (Graphics2D)imageMultiespec.getGraphics(); |
|
146 |
PxRaster rasterMultiespec = null; |
|
147 |
boolean first = true; |
|
148 |
for(int i = 0;i<files.length;i++){ |
|
149 |
if(first){ |
|
150 |
rasterMultiespec = new PxRaster(files[i], null, files[posPancromatica].getView()); |
|
151 |
first = false; |
|
152 |
}else |
|
153 |
rasterMultiespec.addFile(files[i].getName()); |
|
154 |
} |
|
155 |
|
|
156 |
rasterMultiespec.setBand(GeoRasterFile.RED_BAND, bandOrder[0]); |
|
157 |
rasterMultiespec.setBand(GeoRasterFile.GREEN_BAND, bandOrder[1]); |
|
158 |
rasterMultiespec.setBand(GeoRasterFile.BLUE_BAND, bandOrder[2]); |
|
159 |
|
|
160 |
rasterMultiespec.draw(graphicsMultiespec, vp); |
|
161 |
rasterMultiespec = null; |
|
162 |
|
|
163 |
super.pre(); |
|
164 |
} |
|
165 |
|
|
166 |
/** |
|
167 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene |
|
168 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica. |
|
169 |
* @param bufferInput Buffer rgb |
|
170 |
* @param length longitud del buffer de la pancromatica utilizado |
|
171 |
* @param iLine l?nea leida de la imagen multiespectral |
|
172 |
* @return buffer con el resultado de la operaci?n |
|
173 |
*/ |
|
174 |
private int[] processBrovey(int[] bufferInput, int iLine){ |
|
175 |
double[] hsl; |
|
176 |
int[] rgb; |
|
177 |
PixelGrabber pg = null; |
|
178 |
|
|
179 |
//Longitud del buffer de salida |
|
180 |
int widthDst = width * relX; |
|
181 |
//Buffer de salida |
|
182 |
int[] bufferPancr = new int[width]; |
|
183 |
|
|
184 |
pg = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferPancr , 0, width); |
|
185 |
|
|
186 |
|
|
187 |
try { |
|
188 |
pg.grabPixels(); |
|
189 |
} catch (InterruptedException e) { |
|
190 |
e.printStackTrace(); |
|
191 |
} |
|
192 |
|
|
193 |
for(int iElem=0; iElem<width; iElem++){ |
|
194 |
int r = ((bufferInput[iElem] >> 16) & 0xff); |
|
195 |
int g = ((bufferInput[iElem] >> 8) & 0xff); |
|
196 |
int b = (bufferInput[iElem] & 0xff); |
|
197 |
byte i = (byte)((bufferPancr[iElem] >> 16) & 0xff); |
|
198 |
double scale = (3.0*(i+coefBrovey))/(r+g+b+1.0); |
|
199 |
r *= scale;g *= scale;b *= scale; |
|
200 |
bufferPancr[iElem] = ((alpha << 24) & 0xff000000) | |
|
201 |
((r << 16) & 0x00ff0000)| |
|
202 |
((g << 8) & 0x0000ff00) | |
|
203 |
(b & 0x000000ff); |
|
204 |
} |
|
205 |
return bufferPancr; |
|
206 |
|
|
207 |
} |
|
208 |
|
|
209 |
/** |
|
210 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene |
|
211 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica. |
|
212 |
* @param bufferInput Buffer rgb |
|
213 |
* @param length longitud del buffer de la pancromatica utilizado |
|
214 |
* @param iLine l?nea leida de la imagen multiespectral |
|
215 |
* @return buffer con el resultado de la operaci?n |
|
216 |
*/ |
|
217 |
private int[] processKernel(int[] bufferInput, int iLine){ |
|
218 |
int[] bufferDst = new int[width]; |
|
219 |
|
|
220 |
if(iLine != 0){ |
|
221 |
bufferPrev = bufferAct; |
|
222 |
bufferAct = bufferNext; |
|
223 |
}else{ |
|
224 |
bufferPrev = null; |
|
225 |
bufferAct = new int[width]; |
|
226 |
pgAct = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferAct , 0, width); |
|
227 |
try { |
|
228 |
pgAct.grabPixels(); |
|
229 |
} catch (InterruptedException e) {e.printStackTrace();} |
|
230 |
} |
|
231 |
|
|
232 |
if(iLine != (height - 1)){ |
|
233 |
bufferNext = new int[width]; |
|
234 |
pgNext = new PixelGrabber(imagePancr, 0, iLine + 1, width, 1, bufferNext , 0, width); |
|
235 |
try { |
|
236 |
pgNext.grabPixels(); |
|
237 |
} catch (InterruptedException e) {e.printStackTrace();} |
|
238 |
}else |
|
239 |
bufferNext = null; |
|
240 |
|
|
241 |
|
|
242 |
for(int iElem=0; iElem<width; iElem++){ |
|
243 |
int a = ((bufferInput[iElem] >> 24) & 0xff); |
|
244 |
int r = ((bufferInput[iElem] >> 16) & 0xff); |
|
245 |
int g = ((bufferInput[iElem] >> 8) & 0xff); |
|
246 |
int b = (bufferInput[iElem] & 0xff); |
|
247 |
|
|
248 |
float[][] op = new float[3][3]; |
|
249 |
if(bufferPrev != null){ |
|
250 |
if(iElem != 0)op[0][0] = (bufferPrev[iElem - 1] & 0x000000ff); |
|
251 |
op[0][1] = (bufferPrev[iElem] & 0x000000ff); |
|
252 |
if(iElem != (width -1))op[0][2] = (bufferPrev[iElem + 1] & 0x000000ff); |
|
253 |
} |
|
254 |
if(iElem != 0)op[1][0] = (bufferAct[iElem - 1] & 0x000000ff); |
|
255 |
op[1][1] = (bufferAct[iElem] & 0x000000ff); |
|
256 |
if(iElem != (width -1))op[1][2] = (bufferAct[iElem + 1] & 0x000000ff); |
|
257 |
if(bufferNext != null){ |
|
258 |
if(iElem != 0)op[2][0] = (bufferNext[iElem - 1] & 0x000000ff); |
|
259 |
op[2][1] = (bufferNext[iElem] & 0x000000ff); |
|
260 |
if(iElem != (width -1))op[2][2] = (bufferNext[iElem + 1] & 0x000000ff); |
|
261 |
} |
|
262 |
Kernel operando = new Kernel(op); |
|
263 |
double i = kernel.kernelOperation(operando) * 0.15; |
|
264 |
r += i; |
|
265 |
g += i; |
|
266 |
b += i; |
|
267 |
bufferDst[iElem] = ((a << 24) & 0xff000000) | |
|
268 |
((r << 16) & 0x00ff0000)| |
|
269 |
((g << 8) & 0x0000ff00) | |
|
270 |
(b & 0x000000ff); |
|
271 |
} |
|
272 |
return bufferDst; |
|
273 |
|
|
274 |
} |
|
275 |
|
|
276 |
/** |
|
277 |
* Aplica la operaci?n de refinamiento sobre el buffer Multiespectral que contiene |
|
278 |
* el RGB que es pasado por par?metro utilizando la pancrom?tica. |
|
279 |
* @param bufferInput Buffer rgb |
|
280 |
* @param length longitud del buffer de la pancromatica utilizado |
|
281 |
* @param iLine l?nea leida de la imagen multiespectral |
|
282 |
* @return buffer con el resultado de la operaci?n |
|
283 |
*/ |
|
284 |
private int[] processIHS(int[] bufferInput, int iLine){ |
|
285 |
double[] hsl; |
|
286 |
int[] rgb; |
|
287 |
PixelGrabber pg = null; |
|
288 |
|
|
289 |
//Buffer de salida |
|
290 |
int[] bufferPancr = new int[width]; |
|
291 |
|
|
292 |
pg = new PixelGrabber(imagePancr, 0, iLine, width, 1, bufferPancr , 0, width); |
|
293 |
|
|
294 |
try { |
|
295 |
pg.grabPixels(); |
|
296 |
} catch (InterruptedException e) { |
|
297 |
e.printStackTrace(); |
|
298 |
} |
|
299 |
|
|
300 |
int[] uvw , tmp = new int[3]; |
|
301 |
double[] xyz; |
|
302 |
for(int iElem=0; iElem<width; iElem++){ |
|
303 |
xyz = ColorSpaceConversion.RGBtoHSL( (bufferInput[iElem] >> 16) & 0x000000ff, |
|
304 |
(bufferInput[iElem] >> 8) & 0x000000ff, |
|
305 |
bufferInput[iElem] & 0x000000ff); |
|
306 |
|
|
307 |
xyz[2] = ((bufferPancr[iElem] & 0x000000ff)/255.0) + coef; |
|
308 |
|
|
309 |
tmp[0] = (int)(255.0 * xyz[0] / 360.0 + 0.5); |
|
310 |
tmp[2] = (int) (xyz[2]*255. + 0.5); |
|
311 |
tmp[1] = (int) (xyz[1]*255. + 0.5); |
|
312 |
|
|
313 |
uvw = ColorSpaceConversion.HSLtoRGB(tmp[ColorSpaceConversion.H], |
|
314 |
tmp[ColorSpaceConversion.S], |
|
315 |
tmp[ColorSpaceConversion.L]); |
|
316 |
bufferPancr[iElem] = ((alpha << 24) & 0xff000000) | |
|
317 |
((uvw[0] << 16) & 0x00ff0000)| |
|
318 |
((uvw[1] << 8) & 0x0000ff00) | |
|
319 |
(uvw[2] & 0x000000ff); |
|
320 |
} |
|
321 |
return bufferPancr; |
|
322 |
|
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
326 |
* Aplica el filtro sobre el raster pasado pixel a pixel |
|
327 |
*/ |
|
328 |
public void execute() { |
|
329 |
pre(); |
|
330 |
if (exec) { |
|
331 |
int[] pRGBArrayMultiesp = new int[width]; |
|
332 |
int[] pRGBArrayPancr = null; |
|
333 |
PixelGrabber pg = null; |
|
334 |
int widthDst = width * relX; |
|
335 |
|
|
336 |
//Para cada linea leemos los valores RGB del image. Aplicamos el algoritmo |
|
337 |
//y escribimos el resultado. |
|
338 |
|
|
339 |
if(method.equals("hsl")){ |
|
340 |
float[][] k = {{-1F, -1F, -1F},{-1F, 8F, -1F},{-1F, -1F, -1F}}; |
|
341 |
kernel = new Kernel(k); |
|
342 |
for(int iLine=0;iLine<height ;iLine++){ |
|
343 |
pg = new PixelGrabber(imageMultiespec, 0, iLine, width, 1, pRGBArrayMultiesp, 0, width); |
|
344 |
try { |
|
345 |
pg.grabPixels(); |
|
346 |
} catch (InterruptedException e) {e.printStackTrace();} |
|
347 |
pRGBArrayPancr = processIHS(pRGBArrayMultiesp, iLine); |
|
348 |
((BufferedImage)imagePancr).setRGB(0, iLine, width, 1, pRGBArrayPancr, 0, width); |
|
349 |
} |
|
350 |
}else{ |
|
351 |
for(int iLine=0;iLine<height ;iLine++){ |
|
352 |
pg = new PixelGrabber(imageMultiespec, 0, iLine, width, 1, pRGBArrayMultiesp, 0, width); |
|
353 |
try { |
|
354 |
pg.grabPixels(); |
|
355 |
} catch (InterruptedException e) {e.printStackTrace();} |
|
356 |
pRGBArrayPancr = processBrovey(pRGBArrayMultiesp, iLine); |
|
357 |
((BufferedImage)imagePancr).setRGB(0, iLine, width, 1, pRGBArrayPancr, 0, width); |
|
358 |
} |
|
359 |
} |
|
360 |
} |
|
361 |
|
|
362 |
post(); |
|
363 |
} |
|
364 |
|
|
365 |
/* (non-Javadoc) |
|
366 |
* @see org.cresques.io.raster.IRasterFilter#process(int, int) |
|
367 |
*/ |
|
368 |
public void process(int x, int y) { |
|
369 |
|
|
370 |
} |
|
371 |
|
|
372 |
/* (non-Javadoc) |
|
373 |
* @see org.cresques.io.raster.IRasterFilter#getInRasterDataType() |
|
374 |
*/ |
|
375 |
public int getInRasterDataType() { |
|
376 |
return RasterBuf.TYPE_IMAGE; |
|
377 |
} |
|
378 |
|
|
379 |
/* (non-Javadoc) |
|
380 |
* @see org.cresques.io.raster.IRasterFilter#getOutRasterDataType() |
|
381 |
*/ |
|
382 |
public int getOutRasterDataType() { |
|
383 |
return RasterBuf.TYPE_IMAGE; |
|
384 |
} |
|
385 |
|
|
386 |
/* (non-Javadoc) |
|
387 |
* @see org.cresques.io.raster.IRasterFilter#getResult(java.lang.String) |
|
388 |
*/ |
|
389 |
public Object getResult(String name) { |
|
390 |
if (name.equals("raster")) { |
|
391 |
return (Object) this.imagePancr; |
|
392 |
} else { |
|
393 |
return null; |
|
394 |
} |
|
395 |
} |
|
396 |
|
|
397 |
/* (non-Javadoc) |
|
398 |
* @see org.cresques.io.raster.RasterFilter#processLine(int) |
|
399 |
*/ |
|
400 |
public void processLine(int y) { |
|
401 |
} |
|
402 |
|
|
403 |
/* (non-Javadoc) |
|
404 |
* @see org.cresques.io.raster.IRasterFilter#post() |
|
405 |
*/ |
|
406 |
public void post() { |
|
407 |
} |
|
408 |
} |
|
409 |
|
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/SharpeningFilter.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.cresques.io.raster; |
|
25 |
|
|
26 |
import java.awt.Image; |
|
27 |
|
|
28 |
import org.cresques.io.GeoRasterFile; |
|
29 |
|
|
30 |
|
|
31 |
/** |
|
32 |
* Clase base para los filtros de sharpening en sus diferentes tipos |
|
33 |
* de datos. |
|
34 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
35 |
* |
|
36 |
*/ |
|
37 |
public abstract class SharpeningFilter extends RasterFilter { |
|
38 |
|
|
39 |
/** |
|
40 |
* Posici?n en la lista de GeoRasterFiles de la imagen de refinado. |
|
41 |
*/ |
|
42 |
public int posPancromatica = 0; |
|
43 |
|
|
44 |
/** |
|
45 |
* Lista de GeoRasterFiles que componen los datos de entrada |
|
46 |
*/ |
|
47 |
public GeoRasterFile[] files = null; |
|
48 |
|
|
49 |
/** |
|
50 |
* Alto de la imagen pancrom?tica |
|
51 |
*/ |
|
52 |
protected int heightPancr = 0; |
|
53 |
|
|
54 |
/** |
|
55 |
* Ancho de la imagen pancrom?tica |
|
56 |
*/ |
|
57 |
protected int widthPancr = 0; |
|
58 |
|
|
59 |
/** |
|
60 |
* Alto de las bandas multiespectrales |
|
61 |
*/ |
|
62 |
protected int heightMultiespec = 0; |
|
63 |
|
|
64 |
/** |
|
65 |
* Ancho de las bandas multiespectrales |
|
66 |
*/ |
|
67 |
protected int widthMultiespec = 0; |
|
68 |
|
|
69 |
/** |
|
70 |
* Image que corresponde a la imagen de refinado |
|
71 |
*/ |
|
72 |
protected Image imagePancr = null; |
|
73 |
|
|
74 |
/** |
|
75 |
* Image que corresponde a la imagen de entrada |
|
76 |
*/ |
|
77 |
protected Image imageMultiespec = null; |
|
78 |
|
|
79 |
/** |
|
80 |
* N?mero de bandas de la operaci?n incluido la de refinado |
|
81 |
*/ |
|
82 |
protected int nBands = 0; |
|
83 |
|
|
84 |
/** |
|
85 |
* Relaci?n entre la pancromatica y la multiespectral en X |
|
86 |
*/ |
|
87 |
protected int relX = 0; |
|
88 |
|
|
89 |
/** |
|
90 |
* Relaci?n entre la pancromatica y la multiespectral en Y |
|
91 |
*/ |
|
92 |
protected int relY = 0; |
|
93 |
|
|
94 |
/** |
|
95 |
* Vector de 3 elementos que corresponden a R, G y B respectivamente. El valor contenido |
|
96 |
* en cada uno de ellos corresponde al n?mero de banda de fichero que se visualiza en R, G y B. |
|
97 |
*/ |
|
98 |
public int[] bandOrder = null; |
|
99 |
|
|
100 |
/** |
|
101 |
* Valor de alpha aplicado a toda la imagen |
|
102 |
*/ |
|
103 |
public int alpha = 0; |
|
104 |
|
|
105 |
/** |
|
106 |
* M?todo de calculo del refinado |
|
107 |
*/ |
|
108 |
public String method = "ihs"; |
|
109 |
|
|
110 |
/** |
|
111 |
* Coeficiente |
|
112 |
*/ |
|
113 |
public double coef = 0.20; |
|
114 |
|
|
115 |
/** |
|
116 |
* Coeficiente Brovey |
|
117 |
*/ |
|
118 |
public int coefBrovey = 0; |
|
119 |
|
|
120 |
/** |
|
121 |
* Nombre de la banda pancrom?tica |
|
122 |
*/ |
|
123 |
protected String pancrName = null; |
|
124 |
|
|
125 |
/** |
|
126 |
* Constructor |
|
127 |
* |
|
128 |
*/ |
|
129 |
public SharpeningFilter() { |
|
130 |
super(); |
|
131 |
} |
|
132 |
|
|
133 |
/** |
|
134 |
* |
|
135 |
*/ |
|
136 |
public void pre() { |
|
137 |
|
|
138 |
} |
|
139 |
|
|
140 |
} |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilterStackManager.java | ||
---|---|---|
61 | 61 |
typeFilters.put("computeminmax", new Integer(2)); |
62 | 62 |
typeFilters.put("tail", new Integer(3)); |
63 | 63 |
typeFilters.put("removebands", new Integer(4)); |
64 |
typeFilters.put("sharpening", new Integer(5)); |
|
65 | 64 |
init(); |
66 | 65 |
this.filterStack.setOrder(order); |
67 | 66 |
} |
... | ... | |
70 | 69 |
* Registra un manager del sistema |
71 | 70 |
* @param manager |
72 | 71 |
*/ |
73 |
protected void register(IStackManager manager) {
|
|
72 |
public void register(IStackManager manager) {
|
|
74 | 73 |
managers.add(manager); |
75 | 74 |
} |
76 | 75 |
|
... | ... | |
80 | 79 |
*/ |
81 | 80 |
protected void init() { |
82 | 81 |
order = new int[typeFilters.size()]; |
83 |
order[0] = ((Integer) typeFilters.get("sharpening")).intValue(); |
|
84 |
order[1] = ((Integer) typeFilters.get("computeminmax")).intValue();
|
|
85 |
order[2] = ((Integer) typeFilters.get("tail")).intValue();
|
|
86 |
order[3] = ((Integer) typeFilters.get("enhanced")).intValue();
|
|
87 |
order[4] = ((Integer) typeFilters.get("transparency")).intValue();
|
|
88 |
order[5] = ((Integer) typeFilters.get("removebands")).intValue();
|
|
82 |
//order[0] = ((Integer) typeFilters.get("sharpening")).intValue();
|
|
83 |
order[0] = ((Integer) typeFilters.get("computeminmax")).intValue();
|
|
84 |
order[1] = ((Integer) typeFilters.get("tail")).intValue();
|
|
85 |
order[2] = ((Integer) typeFilters.get("enhanced")).intValue();
|
|
86 |
order[3] = ((Integer) typeFilters.get("transparency")).intValue();
|
|
87 |
order[4] = ((Integer) typeFilters.get("removebands")).intValue();
|
|
89 | 88 |
} |
90 | 89 |
|
91 | 90 |
/** |
... | ... | |
93 | 92 |
* @param key Nombre del filtro |
94 | 93 |
* @param type Constante entera asignada a ese tipo |
95 | 94 |
*/ |
96 |
protected void addTypeFilter(String key, int type, int position) {
|
|
95 |
public void addTypeFilter(String key, int type, int position) {
|
|
97 | 96 |
typeFilters.put(key, new Integer(type)); |
98 | 97 |
|
99 | 98 |
int[] newOrder = new int[order.length + 1]; |
... | ... | |
116 | 115 |
* @return Tipo de filtro |
117 | 116 |
*/ |
118 | 117 |
public int getTypeFilter(String key) { |
119 |
return ((Integer) typeFilters.get(key)).intValue(); |
|
118 |
Integer value = ((Integer) typeFilters.get(key)); |
|
119 |
if(value != null) |
|
120 |
return value.intValue(); |
|
121 |
else |
|
122 |
return -1; |
|
120 | 123 |
} |
121 | 124 |
|
122 | 125 |
/** |
... | ... | |
346 | 349 |
|
347 | 350 |
this.controlTypes(); |
348 | 351 |
} |
349 |
|
|
350 |
/** |
|
351 |
* A?ade un filtro ComputeMinMax |
|
352 |
* @param files Ficheros que componen la imagen |
|
353 |
* @param i Posici?n de la imagen de refinado dentro de la lista de GeoRasterFile |
|
354 |
* @param order Orden de visualizado de las bandas RGB |
|
355 |
* @param alpha Alpha aplicado a toda la imagen |
|
356 |
* @param method M?todo de calculo del refinado |
|
357 |
* @param coef Coeficiente |
|
358 |
*/ |
|
359 |
public void addSharpeningFilter(GeoRasterFile[] files, int i, int[] order, int alpha, String method, double coef, int coefBrovey) { |
|
360 |
//Si ya hay un filtro de sharpening nos lo cargamos |
|
361 |
if (filterStack.isActive(((Integer) typeFilters.get("sharpening")).intValue())) { |
|
362 |
filterStack.removeFilter(((Integer) typeFilters.get("sharpening")).intValue()); |
|
363 |
} |
|
364 |
|
|
365 |
RasterFilter filtro = null; |
|
366 |
|
|
367 |
switch (filterStack.getDataTypeInFilter(((Integer) typeFilters.get("sharpening")).intValue())) { |
|
368 |
case RasterBuf.TYPE_IMAGE: |
|
369 |
filtro = new SharpeningImageFilter(); |
|
370 |
break; |
|
371 |
case RasterBuf.TYPE_SHORT: |
|
372 |
case RasterBuf.TYPE_USHORT: |
|
373 |
case RasterBuf.TYPE_INT: |
|
374 |
//filtro = new SharpeningShortFilter(); |
|
375 |
break; |
|
376 |
} |
|
377 |
|
|
378 |
if(filtro != null){ |
|
379 |
filtro.addParam("stats", filterStack.getStats()); |
|
380 |
filtro.addParam("pancromatica", new Integer(i)); |
|
381 |
filtro.addParam("files", files); |
|
382 |
filtro.addParam("order", order); |
|
383 |
filtro.addParam("alpha", new Integer(alpha)); |
|
384 |
filtro.addParam("method", method); |
|
385 |
filtro.addParam("coef", new Double(coef)); |
|
386 |
filtro.addParam("coefBrovey", new Integer(coefBrovey)); |
|
387 |
filterStack.addFilter(((Integer) typeFilters.get("sharpening")).intValue(),filtro); |
|
388 |
|
|
389 |
this.controlTypes(); |
|
390 |
} |
|
391 |
} |
|
392 | 352 |
|
393 | 353 |
/** |
394 | 354 |
* Obtiene de la pila el primer filtro del tipo solicitado si existe sino devuelve null |
... | ... | |
406 | 366 |
* @param rasterFilter Objeto RasterFilter del cual se quiere saber que tipo de filtro contiene |
407 | 367 |
* @return Tipo de filtro seg?n las constantes contenidas en RasterFilterStackManager |
408 | 368 |
*/ |
409 |
protected int getType(RasterFilter rasterFilter) { |
|
410 |
if (rasterFilter instanceof TransparencyFilter) { |
|
411 |
return 0; |
|
412 |
} |
|
369 |
public int getType(RasterFilter rasterFilter) { |
|
370 |
if (rasterFilter instanceof TransparencyFilter) |
|
371 |
return ((Integer)typeFilters.get("transparency")).intValue(); |
|
372 |
|
|
373 |
if (rasterFilter instanceof LinearEnhancementFilter) |
|
374 |
return ((Integer)typeFilters.get("enhanced")).intValue(); |
|
375 |
|
|
376 |
if (rasterFilter instanceof ComputeMinMaxFilter) |
|
377 |
return ((Integer)typeFilters.get("computeminmax")).intValue(); |
|
378 |
|
|
379 |
if (rasterFilter instanceof PercentTailTrimFilter) |
|
380 |
return ((Integer)typeFilters.get("tail")).intValue(); |
|
381 |
|
|
382 |
if (rasterFilter instanceof RemoveBandsFilter) |
|
383 |
return ((Integer)typeFilters.get("removebands")).intValue(); |
|
413 | 384 |
|
414 |
if (rasterFilter instanceof LinearEnhancementFilter) { |
|
415 |
return 1; |
|
416 |
} |
|
417 |
|
|
418 |
if (rasterFilter instanceof ComputeMinMaxFilter) { |
|
419 |
return 2; |
|
420 |
} |
|
421 |
|
|
422 |
if (rasterFilter instanceof PercentTailTrimFilter) { |
|
423 |
return 3; |
|
424 |
} |
|
425 |
|
|
426 | 385 |
return -1; |
427 | 386 |
} |
428 | 387 |
|
... | ... | |
433 | 392 |
* en el no coincidente. Esto es necesario ya que en la eliminaci?n de filtros puede |
434 | 393 |
* quedarse en inconsistencia de tipos. |
435 | 394 |
*/ |
436 |
protected void controlTypes() {
|
|
395 |
public void controlTypes() {
|
|
437 | 396 |
if (debug) { |
438 | 397 |
filterStack.show(); |
439 | 398 |
} |
... | ... | |
558 | 517 |
*/ |
559 | 518 |
public ArrayList getStringsFromStack() { |
560 | 519 |
filterList = new ArrayList(); |
561 |
|
|
562 | 520 |
for (int i = 0; i < filterStack.lenght(); i++) { |
563 | 521 |
RasterFilter rf = filterStack.get(i); |
564 | 522 |
|
... | ... | |
584 | 542 |
filterList.add("filter.removebands.active=true"); |
585 | 543 |
filterList.add("filter.removebands.bands=" + |
586 | 544 |
((RemoveBandsFilter) rf).bands); |
587 |
} else if (rf instanceof SharpeningFilter) { |
|
588 |
SharpeningFilter sharp = ((SharpeningFilter) rf); |
|
589 |
filterList.add("filter.pansharpening.active=true"); |
|
590 |
filterList.add("filter.pansharpening.posPancromatica="+sharp.posPancromatica); |
|
591 |
filterList.add("filter.pansharpening.bandOrder="+sharp.bandOrder[0]+","+sharp.bandOrder[1]+","+sharp.bandOrder[2]); |
|
592 |
for(int file=0;file<sharp.files.length;file++) |
|
593 |
filterList.add("filter.pansharpening.file"+file+"="+sharp.files[file].getName()); |
|
594 |
filterList.add("filter.pansharpening.method="+sharp.method); |
|
595 |
filterList.add("filter.pansharpening.coefHSL="+sharp.coef); |
|
596 |
filterList.add("filter.pansharpening.coefBrovey="+sharp.coefBrovey); |
|
597 |
filterList.add("filter.pansharpening.alpha="+sharp.alpha); |
|
598 | 545 |
} else { //Se recorren todos los managers registrados comprobando si corresponde a la clase del filtro |
599 |
|
|
600 |
for (int j = 0; j < managers.size(); j++) |
|
601 |
((IStackManager) managers.get(j)).getStringsFromStack(); |
|
546 |
System.out.println("...Manager registrado "+rf.getClass().getName()+" - "+managers.size()); |
|
547 |
for (int j = 0; j < managers.size(); j++){ |
|
548 |
filterList = ((IStackManager) managers.get(j)).getStringsFromStack(filterList, rf); |
|
549 |
} |
|
602 | 550 |
} |
603 | 551 |
} |
604 | 552 |
|
605 | 553 |
return filterList; |
606 | 554 |
} |
607 | 555 |
|
556 |
/* (non-Javadoc) |
|
557 |
* @see org.cresques.io.raster.StackManager#getStringsFromStack() |
|
558 |
*/ |
|
559 |
public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf){ |
|
560 |
return null; |
|
561 |
} |
|
562 |
|
|
563 |
public int createStackFromStrings(String fil, ArrayList filters, int filteri){ |
|
564 |
return 0; |
|
565 |
} |
|
566 |
|
|
608 | 567 |
/** |
609 | 568 |
* Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe |
610 | 569 |
* tener la forma elemento=valor. |
... | ... | |
640 | 599 |
if (fil.startsWith("filter.transparency.active") && |
641 | 600 |
getValue(fil).equals("true")) { |
642 | 601 |
filters.remove(filteri); |
643 |
|
|
644 |
int[][] r = null; |
|
645 |
int[][] g = null; |
|
646 |
int[][] b = null; |
|
647 | 602 |
|
648 | 603 |
ArrayList list = new ArrayList(); |
649 | 604 |
for (int propFilter = 0;propFilter < filters.size();propFilter++) { |
... | ... | |
745 | 700 |
} |
746 | 701 |
filteri = -1; |
747 | 702 |
} |
748 |
|
|
749 |
if (fil.startsWith("filter.pansharpening.active") && |
|
750 |
getValue(fil).equals("true")) { |
|
751 |
filters.remove(filteri); |
|
752 |
|
|
753 |
int posPancromatica = 0; |
|
754 |
int[] bandOrder = {0, 1, 2}; |
|
755 |
ArrayList files = new ArrayList(); |
|
756 |
int alpha = 0; |
|
757 |
String method = ""; |
|
758 |
double coef = 0D; |
|
759 |
int coefBrovey = 0; |
|
760 |
|
|
761 |
for (int propFilter = 0;propFilter < filters.size();propFilter++) { |
|
762 |
String elem = (String) filters.get(propFilter); |
|
763 |
|
|
764 |
if (elem.startsWith("filter.pansharpening.posPancromatica")) { |
|
765 |
posPancromatica = Integer.parseInt(getValue(elem)); |
|
766 |
filters.remove(propFilter); |
|
767 |
propFilter--; |
|
768 |
} |
|
769 |
if (elem.startsWith("filter.pansharpening.bandOrder")) { |
|
770 |
String rango = getValue(elem); |
|
771 |
bandOrder[0] = Integer.parseInt(rango.substring(0, rango.indexOf(","))); |
|
772 |
bandOrder[1] = Integer.parseInt(rango.substring(rango.indexOf(",") + 1, rango.lastIndexOf(","))); |
|
773 |
bandOrder[2] = Integer.parseInt(rango.substring(rango.lastIndexOf(",") + 1, rango.length())); |
|
774 |
filters.remove(propFilter); |
|
775 |
propFilter--; |
|
776 |
} |
|
777 |
if (elem.startsWith("filter.pansharpening.file")) { |
|
778 |
files.add(getValue(elem)); |
|
779 |
filters.remove(propFilter); |
|
780 |
propFilter--; |
|
781 |
} |
|
782 |
if (elem.startsWith("filter.pansharpening.alpha")) { |
|
783 |
alpha = Integer.parseInt(getValue(elem)); |
|
784 |
filters.remove(propFilter); |
|
785 |
propFilter--; |
|
786 |
} |
|
787 |
if (elem.startsWith("filter.pansharpening.method")) { |
|
788 |
method = getValue(elem); |
|
789 |
filters.remove(propFilter); |
|
790 |
propFilter--; |
|
791 |
} |
|
792 |
if (elem.startsWith("filter.pansharpening.coefHSL")) { |
|
793 |
coef = Double.parseDouble(getValue(elem)); |
|
794 |
filters.remove(propFilter); |
|
795 |
propFilter--; |
|
796 |
} |
|
797 |
if (elem.startsWith("filter.pansharpening.coefBrovey")) { |
|
798 |
coefBrovey = Integer.parseInt(getValue(elem)); |
|
799 |
//filters.remove(propFilter); |
|
800 |
//propFilter--; |
|
801 |
} |
|
802 |
} |
|
803 |
|
|
804 |
addSharpeningFilter(this.grfList, posPancromatica, bandOrder, alpha, method, coef, coefBrovey); |
|
805 |
filteri = -1; |
|
806 |
} |
|
807 | 703 |
|
808 | 704 |
for (int j = 0; j < managers.size(); j++) |
809 |
((IStackManager) managers.get(j)).createStackFromStrings(filters, new Integer(filteri));
|
|
705 |
filteri = ((IStackManager) managers.get(j)).createStackFromStrings(fil, filters, filteri);
|
|
810 | 706 |
|
811 | 707 |
filteri++; |
812 | 708 |
} |
... | ... | |
817 | 713 |
* @param cadena |
818 | 714 |
* @return |
819 | 715 |
*/ |
820 |
public String getElem(String cadena) { |
|
716 |
public static String getElem(String cadena) {
|
|
821 | 717 |
if (cadena != null) { |
822 | 718 |
return cadena.substring(0, cadena.indexOf("=")); |
823 | 719 |
} else { |
... | ... | |
830 | 726 |
* @param cadena |
831 | 727 |
* @return |
832 | 728 |
*/ |
833 |
public String getValue(String cadena) { |
|
729 |
public static String getValue(String cadena) {
|
|
834 | 730 |
if (cadena != null) { |
835 | 731 |
return cadena.substring(cadena.indexOf("=") + 1, cadena.length()); |
836 | 732 |
} else { |
... | ... | |
894 | 790 |
return null; |
895 | 791 |
} |
896 | 792 |
} |
793 |
|
|
794 |
/** |
|
795 |
* Obtiene la pila de filtros |
|
796 |
* @return RasterFilterStack |
|
797 |
*/ |
|
798 |
public RasterFilterStack getFilterStack() { |
|
799 |
return filterStack; |
|
800 |
} |
|
801 |
|
|
802 |
/** |
|
803 |
* Obtiene la Hashable que contiene los tipos de filtros registrados |
|
804 |
* @return Hashtable |
|
805 |
*/ |
|
806 |
public Hashtable getTypeFilters() { |
|
807 |
return typeFilters; |
|
808 |
} |
|
809 |
|
|
897 | 810 |
} |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/IRasterOperationsRegistrablePanels.java | ||
---|---|---|
1 |
/* |
|
2 |
* Created on 23-mar-2006 |
|
3 |
* |
|
4 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana |
|
5 |
* |
|
6 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana. |
|
7 |
* |
|
8 |
* This program is free software; you can redistribute it and/or |
|
9 |
* modify it under the terms of the GNU General Public License |
|
10 |
* as published by the Free Software Foundation; either version 2 |
|
11 |
* of the License, or (at your option) any later version. |
|
12 |
* |
|
13 |
* This program is distributed in the hope that it will be useful, |
|
14 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
15 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
16 |
* GNU General Public License for more details. |
|
17 |
* |
|
18 |
* You should have received a copy of the GNU General Public License |
|
19 |
* along with this program; if not, write to the Free Software |
|
20 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
21 |
* |
|
22 |
*/ |
|
23 |
package org.cresques.io.raster; |
|
24 |
|
|
25 |
import org.cresques.io.GeoRasterFile; |
|
26 |
|
|
27 |
|
|
28 |
/** |
|
29 |
* Este interface lo implementaran las clases que se registran en propiedades |
|
30 |
* de raster. Representa a las operaciones que pueden realizar y que deben ser |
|
31 |
* invocadas desde la libreria de cresques. Cuando las propiedades del raster |
|
32 |
* ejecutan alguna de estas operaciones recorreran todas las clases que han sido |
|
33 |
* registradas y ejecutaran para cada una la operaci?n. Si la clase registrada no |
|
34 |
* necesita hacer nada con esa operaci?n simplemente no la implementar?. |
|
35 |
* |
|
36 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
37 |
* |
|
38 |
*/ |
|
39 |
public interface IRasterOperationsRegistrablePanels{ |
|
40 |
|
|
41 |
/** |
|
42 |
* Operaci?n de a?adir ficheros. El dialogo para a?adir bandas se encuentra |
|
43 |
* en cresques. Es corriente que haya paneles que necesiten ser informados |
|
44 |
* cuando se a?aden nuevas bandas. Si es as? addFiles deber?a ser implementado. |
|
45 |
* @param files |
|
46 |
*/ |
|
47 |
public void addFiles(GeoRasterFile[] files); |
|
48 |
|
|
49 |
/** |
|
50 |
* Operaci?n de eliminar ficheros. El dialogo para eliminar bandas se encuentra |
|
51 |
* en cresques. Es corriente que haya paneles que necesiten ser informados |
|
52 |
* cuando se eliminan bandas. Si es as? removeFile deber?a ser implementado. |
|
53 |
* @param files |
|
54 |
*/ |
|
55 |
public void removeFile(String file); |
|
56 |
} |
|
0 | 57 |
trunk/libraries/libCq CMS for java.old/src/org/cresques/io/raster/IStackManager.java | ||
---|---|---|
38 | 38 |
* @return ArrayList donde cada elemento es una cadena |
39 | 39 |
*/ |
40 | 40 |
public ArrayList getStringsFromStack(); |
41 |
|
|
42 |
/** |
|
43 |
* Convierte cada filtro o elemento de un filtro de la pila en un String de la forma |
|
44 |
* elemento=valor. Esta versi?n la implementan las extensiones que registren filtros |
|
45 |
* de forma externa para que pueda ser ejecutado por el RasterFilterStackManager. |
|
46 |
* @return ArrayList donde cada elemento es una cadena |
|
47 |
*/ |
|
48 |
public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf); |
|
41 | 49 |
|
42 | 50 |
/** |
43 | 51 |
* Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe |
... | ... | |
45 | 53 |
* @param filters |
46 | 54 |
*/ |
47 | 55 |
public void createStackFromStrings(ArrayList f, Integer pos); |
56 |
|
|
57 |
/** |
|
58 |
* Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe |
|
59 |
* tener la forma elemento=valor. Esta versi?n la implementan las extensiones que registren filtros |
|
60 |
* de forma externa para que pueda ser ejecutado por el RasterFilterStackManager. |
|
61 |
* @param fil Cadena que representa el identificador del elemento |
|
62 |
* @param filters Lista de filtros |
|
63 |
* @param filteri N?mero de filtro de la lista analizado |
|
64 |
* @return filteri modificado |
|
65 |
*/ |
|
66 |
public int createStackFromStrings(String fil, ArrayList filters, int filteri); |
|
48 | 67 |
} |
trunk/libraries/libCq CMS for java.old/src/org/cresques/ui/DefaultTabPanel.java | ||
---|---|---|
65 | 65 |
* @param title T?tulo del tab |
66 | 66 |
* @param panel Panel del nuevo tab |
67 | 67 |
*/ |
68 |
protected void addTab(String title, JPanel panel) {
|
|
68 |
public void addTab(String title, JPanel panel) {
|
|
69 | 69 |
tabbedPane.add(title, panel); |
70 | 70 |
} |
71 | 71 |
|
trunk/libraries/libCq CMS for java.old/src/org/cresques/ui/raster/SharpeningPanel.java | ||
---|---|---|
1 |
/* |
|
2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
|
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 |
* This program is free software; you can redistribute it and/or |
|
7 |
* modify it under the terms of the GNU General Public License |
|
8 |
* as published by the Free Software Foundation; either version 2 |
|
9 |
* of the License, or (at your option) any later version. |
|
10 |
* |
|
11 |
* This program is distributed in the hope that it will be useful, |
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of |
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|
14 |
* GNU General Public License for more details. |
|
15 |
* |
|
16 |
* You should have received a copy of the GNU General Public License |
|
17 |
* along with this program; if not, write to the Free Software |
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
|
19 |
* |
|
20 |
* For more information, contact: |
|
21 |
* |
|
22 |
* cresques@gmail.com |
|
23 |
*/ |
|
24 |
package org.cresques.ui.raster; |
|
25 |
|
|
26 |
import java.awt.Component; |
|
27 |
import java.awt.Dimension; |
|
28 |
import java.awt.FlowLayout; |
|
29 |
import java.awt.GridBagConstraints; |
|
30 |
import java.awt.GridBagLayout; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.awt.event.KeyEvent; |
|
34 |
import java.awt.event.KeyListener; |
|
35 |
import java.awt.image.DataBuffer; |
|
36 |
import java.io.File; |
|
37 |
import java.util.Vector; |
|
38 |
|
|
39 |
import javax.swing.AbstractCellEditor; |
|
40 |
import javax.swing.ButtonGroup; |
|
41 |
import javax.swing.JCheckBox; |
|
42 |
import javax.swing.JPanel; |
|
43 |
import javax.swing.JRadioButton; |
|
44 |
import javax.swing.JScrollPane; |
|
45 |
import javax.swing.JSlider; |
|
46 |
import javax.swing.JTable; |
|
47 |
import javax.swing.JTextField; |
|
48 |
import javax.swing.SwingConstants; |
|
49 |
import javax.swing.SwingUtilities; |
|
50 |
import javax.swing.event.ChangeEvent; |
|
51 |
import javax.swing.event.ChangeListener; |
|
52 |
import javax.swing.event.TableModelEvent; |
|
53 |
import javax.swing.event.TableModelListener; |
|
54 |
import javax.swing.table.DefaultTableModel; |
|
55 |
import javax.swing.table.TableCellEditor; |
|
56 |
import javax.swing.table.TableCellRenderer; |
|
57 |
import javax.swing.table.TableColumn; |
|
58 |
|
|
59 |
import org.cresques.io.GeoRasterFile; |
|
60 |
/** |
|
61 |
* Selecciona las bandas visibles en un raster. Contiene una tabla con una fila por cada |
|
62 |
* banda de la imagen. Por medio de checkbox se selecciona para cada RGB que banda de la |
|
63 |
* imagen ser? visualizada. |
|
64 |
* @author Luis W. Sevilla (sevilla_lui@gva.es) |
|
65 |
* @author Nacho Brodin (brodin_ign@gva.es) |
|
66 |
*/ |
|
67 |
public class SharpeningPanel extends JPanel implements TableModelListener, |
|
68 |
KeyListener, ChangeListener, |
|
69 |
ActionListener { |
|
70 |
final private static long serialVersionUID = -3370601314380922368L; |
|
71 |
|
|
72 |
private final static String[] columnNames = { " ", "Band" }; |
|
73 |
|
|
74 |
/** |
|
75 |
* Nombre del panel |
|
76 |
*/ |
|
77 |
private String nom = "Pansharpening"; |
|
78 |
private JTable rgbTable = null; |
|
79 |
private JScrollPane rgbBandAssignPane = null; |
|
80 |
RGBBandAsignTableModel tableModel = null; |
|
81 |
private int sizeX = 445; |
|
82 |
private int sizeY = 174; |
|
83 |
private JPanel activationPanel = null; |
|
84 |
|
|
85 |
private JCheckBox cbActiveSharpening = null; |
|
86 |
private JPanel pSharpNorth = null; |
|
87 |
private JPanel pSharpSouth = null; |
|
88 |
private JRadioButton rbBrovey = null; |
|
89 |
private JRadioButton rbHSL = null; |
|
90 |
private JPanel pHSL = null; |
|
91 |
private JSlider jSlider = null; |
|
92 |
private JTextField jTextField = null; |
|
93 |
|
|
94 |
private JPanel pBrovey = null; |
|
95 |
|
|
96 |
private JSlider slBrovey = null; |
|
97 |
|
|
98 |
private JTextField jTextField1 = null; |
|
99 |
/** |
|
100 |
* This method initializes |
|
101 |
* |
|
102 |
*/ |
|
103 |
public SharpeningPanel() { |
|
104 |
super(); |
|
105 |
initialize(); |
|
106 |
} |
|
107 |
|
|
108 |
/** |
|
109 |
* This method initializes this |
|
110 |
* |
|
111 |
* @return void |
|
112 |
*/ |
|
113 |
void initialize() { |
|
114 |
this.setPreferredSize(new Dimension(sizeX, sizeY)); |
|
115 |
this.setLayout(new FlowLayout()); |
|
116 |
this.setLocation(0, 0); |
|
117 |
this.setSize(445, 239); |
|
118 |
this.add(getPSharpNorth(), null); |
|
119 |
this.setTableEnabled(false); |
|
120 |
} |
|
121 |
|
|
122 |
/** |
|
123 |
* Obtiene el nombre del panel |
|
124 |
* @return Cadena con el nombre del panel |
|
125 |
*/ |
|
126 |
public String getName(){ |
|
127 |
return this.nom; |
|
128 |
} |
|
129 |
|
|
130 |
/** |
|
131 |
* Activa o desactiva la tabla de selecci?n de banda de refinado |
|
132 |
* @param enable |
|
133 |
*/ |
|
134 |
public void setTableEnabled(boolean enabled){ |
|
135 |
this.getRGBBandAssignPane().setEnabled(enabled); |
|
136 |
this.getRGBTable().setEnabled(enabled); |
|
137 |
this.getJSlider().setEnabled(enabled); |
|
138 |
this.getJSlider1().setEnabled(enabled); |
|
139 |
this.getJTextField().setEnabled(enabled); |
|
140 |
this.getJTextField1().setEnabled(enabled); |
|
141 |
this.getRbBrovey().setEnabled(enabled); |
|
142 |
this.getRbHSL().setEnabled(enabled); |
|
143 |
} |
|
144 |
|
|
145 |
/** |
|
146 |
* A?ade la lista de georasterfiles a la tabla |
|
147 |
* @param files |
|
148 |
*/ |
|
149 |
public void addFiles(GeoRasterFile[] files) { |
|
150 |
for (int i = 0; i < files.length; i++) { |
|
151 |
String fName = files[i].getName(); |
|
152 |
|
|
153 |
String bandName = new File(fName).getName(); |
|
154 |
String bandType = ""; |
|
155 |
|
|
156 |
switch (files[i].getDataType()) { |
|
157 |
case DataBuffer.TYPE_BYTE: |
|
158 |
bandType = "8U"; |
|
159 |
break; |
|
160 |
case DataBuffer.TYPE_INT: |
|
161 |
bandType = "32"; |
|
162 |
break; |
|
163 |
case DataBuffer.TYPE_DOUBLE: |
|
164 |
bandType = "64"; |
|
165 |
break; |
|
166 |
case DataBuffer.TYPE_FLOAT: |
|
167 |
bandType = "32"; |
|
168 |
break; |
|
169 |
case DataBuffer.TYPE_SHORT: |
|
170 |
bandType = "16"; |
|
171 |
break; |
|
172 |
case DataBuffer.TYPE_USHORT: |
|
173 |
bandType = "16U"; |
|
174 |
break; |
|
175 |
case DataBuffer.TYPE_UNDEFINED: |
|
176 |
bandType = "??"; |
|
177 |
break; |
|
178 |
} |
|
179 |
|
|
180 |
if (files[i].getBandCount() > 1) { |
|
181 |
for (int b = 0; b < files[i].getBandCount(); b++) |
|
182 |
addBand((b + 1) + " [" + bandType + "] " + bandName); |
|
183 |
} else { |
|
184 |
addBand("1 [" + bandType + "] " + bandName); |
|
185 |
} |
|
186 |
} |
|
187 |
} |
|
188 |
|
|
189 |
/** |
|
190 |
* Elimina un fichero de la lista |
|
191 |
* @param file Nombre del fichero a eliminar |
|
192 |
*/ |
|
193 |
public void removeFile(String file) { |
|
194 |
for (int i = 0; i < ((DefaultTableModel) rgbTable.getModel()).getRowCount(); i++) { |
|
195 |
if (((String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 1)).endsWith(file)) { |
|
196 |
((DefaultTableModel) rgbTable.getModel()).removeRow(i); |
|
197 |
i--; //Ojo! que hemos eliminado una fila |
|
198 |
} |
|
199 |
} |
|
200 |
} |
|
201 |
|
|
202 |
/** |
|
203 |
* This method initializes jTable |
|
204 |
* |
|
205 |
* @return javax.swing.JTable |
|
206 |
*/ |
|
207 |
private JScrollPane getRGBBandAssignPane() { |
|
208 |
if (rgbBandAssignPane == null) { |
|
209 |
rgbBandAssignPane = new JScrollPane(getRGBTable()); |
|
210 |
rgbBandAssignPane.setPreferredSize(new java.awt.Dimension(400,60)); |
|
211 |
rgbBandAssignPane.setEnabled(true); |
|
212 |
TableColumn column = null; |
|
213 |
|
|
214 |
for (int i = 0; i < 1; i++) { |
|
215 |
column = rgbTable.getColumnModel().getColumn(i); |
|
216 |
column.setCellRenderer(new RadioColumnRenderer()); |
|
217 |
column.setCellEditor(new RadioColumnEditor()); |
|
218 |
column.setMaxWidth(22); |
|
219 |
column.setMinWidth(22); |
|
220 |
} |
|
221 |
} |
|
222 |
return rgbBandAssignPane; |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* Obtiene la Tabla |
|
227 |
* @return Tabla de bandas de la imagen |
|
228 |
*/ |
|
229 |
public JTable getRGBTable() { |
|
230 |
if (rgbTable == null) { |
|
231 |
tableModel = new RGBBandAsignTableModel(); |
|
232 |
tableModel.addTableModelListener(this); |
|
233 |
rgbTable = new JTable(tableModel); |
|
234 |
rgbTable.setPreferredScrollableViewportSize(new Dimension(300, 60)); |
|
235 |
} |
|
236 |
return rgbTable; |
|
237 |
} |
|
238 |
|
|
239 |
|
|
240 |
/** |
|
241 |
* A?ade una banda a la tabla bandas de la imagen asignandole un |
|
242 |
* nombre y valor a los checkbox |
|
243 |
* @param bandName Nombre de la banda |
|
244 |
*/ |
|
245 |
private void addBand(String bandName) { |
|
246 |
Vector v = new Vector(); |
|
247 |
v.add(new Boolean(false)); |
|
248 |
v.add(bandName); |
|
249 |
((DefaultTableModel) rgbTable.getModel()).addRow(v); |
|
250 |
} |
|
251 |
|
|
252 |
/** |
|
253 |
* Obtiene el n?mero de bandas de la lista |
|
254 |
* @return |
|
255 |
*/ |
|
256 |
public int getNBands() { |
|
257 |
return ((DefaultTableModel) rgbTable.getModel()).getRowCount(); |
|
258 |
} |
|
259 |
|
|
260 |
/** |
|
261 |
* Obtiene el nombre de la banda de la posici?n i de la tabla |
|
262 |
* @param i |
|
263 |
* @return |
|
264 |
*/ |
|
265 |
public String getBandName(int i) { |
|
266 |
String s = (String) ((DefaultTableModel) rgbTable.getModel()).getValueAt(i, 1); |
|
267 |
return s.substring(s.lastIndexOf("[8U]") + 5, s.length()); |
|
268 |
} |
|
269 |
|
|
270 |
/** |
|
271 |
* Selecciona una banda de la tabla. |
|
272 |
* @param i |
|
273 |
*/ |
|
274 |
public void selectRow(int i){ |
|
275 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(true),i,0); |
|
276 |
} |
|
277 |
|
|
278 |
/** |
|
279 |
* Elimina todas las filas seleccionadas |
|
280 |
*/ |
|
281 |
public void removeSelections(){ |
|
282 |
for(int i=0;i<((DefaultTableModel) rgbTable.getModel()).getRowCount();i++){ |
|
283 |
((DefaultTableModel) rgbTable.getModel()).setValueAt(new Boolean(false),i,0); |
|
284 |
} |
|
285 |
} |
|
286 |
|
|
287 |
/* (non-Javadoc) |
|
288 |
* @see javax.swing.event.TableModelListener#tableChanged(javax.swing.event.TableModelEvent) |
|
289 |
*/ |
|
290 |
public void tableChanged(TableModelEvent e) { |
|
291 |
rgbTable.revalidate(); |
|
292 |
rgbBandAssignPane.revalidate(); |
|
293 |
revalidate(); |
|
294 |
} |
|
295 |
|
|
296 |
/* (non-Javadoc) |
|
297 |
* @see java.awt.event.KeyListener#keyPressed(java.awt.event.KeyEvent) |
|
298 |
*/ |
|
299 |
public void keyPressed(KeyEvent arg0) { |
|
300 |
// TODO Auto-generated method stub |
|
301 |
} |
|
302 |
|
|
303 |
/* (non-Javadoc) |
|
304 |
* @see java.awt.event.KeyListener#keyReleased(java.awt.event.KeyEvent) |
|
305 |
*/ |
|
306 |
public void keyReleased(KeyEvent arg0) { |
|
307 |
// TODO Auto-generated method stub |
|
308 |
} |
|
309 |
|
|
310 |
/* (non-Javadoc) |
|
311 |
* @see java.awt.event.KeyListener#keyTyped(java.awt.event.KeyEvent) |
|
312 |
*/ |
|
313 |
public void keyTyped(KeyEvent arg0) { |
|
314 |
// TODO Auto-generated method stub |
|
315 |
} |
|
316 |
|
|
317 |
/** |
|
318 |
* |
|
319 |
*/ |
|
320 |
public void actionPerformed(ActionEvent e) { |
|
321 |
if(e.getSource() == this.cbActiveSharpening){ |
|
322 |
if(this.cbActiveSharpening.isSelected()){ |
|
323 |
this.setTableEnabled(true); |
|
324 |
}else{ |
|
325 |
this.setTableEnabled(false); |
|
326 |
} |
|
327 |
} |
|
328 |
} |
|
329 |
|
|
330 |
class RadioColumnEditor extends AbstractCellEditor |
|
331 |
implements TableCellEditor { |
|
332 |
final private static long serialVersionUID = -3370601314380922368L; |
|
333 |
public JRadioButton theRadioButton; |
|
334 |
|
|
335 |
public RadioColumnEditor() { |
|
336 |
super(); |
|
337 |
theRadioButton = new JRadioButton(); |
|
338 |
theRadioButton.addActionListener(new ActionListener() { |
|
339 |
public void actionPerformed(ActionEvent event) { |
|
340 |
fireEditingStopped(); |
|
341 |
} |
|
342 |
}); |
|
343 |
} |
|
344 |
|
|
345 |
public Component getTableCellEditorComponent(JTable table, Object obj, |
|
346 |
boolean isSelected, |
|
347 |
int row, int col) { |
|
348 |
theRadioButton.setHorizontalAlignment(SwingUtilities.CENTER); |
|
349 |
|
|
350 |
Boolean lValueAsBoolean = (Boolean) obj; |
|
351 |
theRadioButton.setSelected(lValueAsBoolean.booleanValue()); |
|
352 |
|
|
353 |
return theRadioButton; |
|
354 |
} |
|
355 |
|
|
356 |
public Object getCellEditorValue() { |
|
357 |
return new Boolean(theRadioButton.isSelected()); |
|
358 |
} |
|
359 |
} |
|
360 |
|
|
361 |
class RadioColumnRenderer extends JRadioButton implements TableCellRenderer { |
|
362 |
final private static long serialVersionUID = -3370601314380922368L; |
|
363 |
|
|
364 |
public Component getTableCellRendererComponent(JTable table, |
|
365 |
Object value, |
|
366 |
boolean isSelected, |
|
367 |
boolean hasFocus, |
|
368 |
int row, int column) { |
|
369 |
if (value == null) { |
|
370 |
this.setSelected(false); |
|
371 |
} |
|
372 |
|
|
373 |
Boolean ValueAsBoolean = (Boolean) value; |
|
374 |
this.setSelected(ValueAsBoolean.booleanValue()); |
|
375 |
this.setHorizontalAlignment(SwingConstants.CENTER); |
|
376 |
|
|
377 |
return this; |
|
378 |
} |
|
379 |
} |
|
380 |
|
|
381 |
class RGBBandAsignTableModel extends DefaultTableModel { |
|
382 |
final private static long serialVersionUID = -3370601314380922368L; |
|
383 |
|
|
384 |
public RGBBandAsignTableModel() { |
|
385 |
super(new Object[0][2], columnNames); |
|
386 |
} |
|
387 |
|
|
388 |
public Class getColumnClass(int c) { |
|
389 |
if (c < 1) { |
|
390 |
return Boolean.class; |
|
391 |
} |
|
392 |
|
|
393 |
return String.class; |
|
394 |
} |
|
395 |
|
|
396 |
public void setValueAt(Object value, int row, int col) { |
|
397 |
if ((col < 1) && ((Boolean) value).booleanValue()) { |
|
398 |
for (int i = 0; i < getRowCount(); i++) { |
|
399 |
if (i != row) { |
|
400 |
setValueAt(new Boolean(false), i, col); |
|
401 |
} |
|
402 |
} |
|
403 |
} |
|
404 |
|
|
405 |
super.setValueAt(value, row, col); |
|
406 |
} |
|
407 |
|
|
408 |
public void addNew() { |
|
409 |
super.addRow(new Object[] { |
|
410 |
new Boolean(false), "" |
|
411 |
}); |
|
412 |
} |
|
413 |
} |
|
414 |
/** |
|
415 |
* This method initializes jPanel |
|
416 |
* |
|
417 |
* @return javax.swing.JPanel |
|
418 |
*/ |
|
419 |
private JPanel getActivationPanel() { |
|
420 |
if (activationPanel == null) { |
|
421 |
FlowLayout flowLayout = new FlowLayout(); |
|
422 |
flowLayout.setAlignment(java.awt.FlowLayout.LEFT); |
|
423 |
flowLayout.setVgap(0); |
|
424 |
flowLayout.setHgap(0); |
|
425 |
activationPanel = new JPanel(); |
|
426 |
activationPanel.setLayout(flowLayout); |
|
427 |
activationPanel.setPreferredSize(new java.awt.Dimension(340,30)); |
|
428 |
activationPanel.add(getCbActiveSharpening(), null); |
|
429 |
} |
|
430 |
return activationPanel; |
|
431 |
} |
|
432 |
/** |
|
433 |
* This method initializes jCheckBox |
|
434 |
* |
|
435 |
* @return javax.swing.JCheckBox |
|
436 |
*/ |
|
437 |
public JCheckBox getCbActiveSharpening() { |
|
438 |
if (cbActiveSharpening == null) { |
|
439 |
cbActiveSharpening = new JCheckBox(); |
|
440 |
cbActiveSharpening.setText("Activar Pansharpening"); |
|
441 |
cbActiveSharpening.setPreferredSize(new java.awt.Dimension(150,23)); |
|
442 |
cbActiveSharpening.setHorizontalAlignment(javax.swing.SwingConstants.LEFT); |
|
443 |
cbActiveSharpening.addActionListener(this); |
|
444 |
} |
|
445 |
return cbActiveSharpening; |
|
446 |
} |
|
447 |
/** |
|
448 |
* This method initializes jPanel |
|
449 |
* |
|
450 |
* @return javax.swing.JPanel |
|
451 |
*/ |
|
452 |
public JPanel getPSharpNorth() { |
|
453 |
if (pSharpNorth == null) { |
|
454 |
GridBagConstraints gridBagConstraints10 = new GridBagConstraints(); |
|
455 |
gridBagConstraints10.gridx = 0; |
|
456 |
gridBagConstraints10.gridy = 1; |
|
457 |
GridBagConstraints gridBagConstraints3 = new GridBagConstraints(); |
|
458 |
GridBagConstraints gridBagConstraints2 = new GridBagConstraints(); |
|
459 |
pSharpNorth = new JPanel(); |
|
460 |
pSharpNorth.setLayout(new GridBagLayout()); |
|
461 |
pSharpNorth.setPreferredSize(new java.awt.Dimension(440,225)); |
|
462 |
pSharpNorth.setBorder(javax.swing.BorderFactory.createTitledBorder(null, "Selector de banda de refinado", javax.swing.border.TitledBorder.DEFAULT_JUSTIFICATION, javax.swing.border.TitledBorder.DEFAULT_POSITION, null, null)); |
|
463 |
gridBagConstraints2.gridx = 0; |
|
464 |
gridBagConstraints2.gridy = 0; |
|
465 |
gridBagConstraints2.anchor = java.awt.GridBagConstraints.WEST; |
|
466 |
gridBagConstraints2.gridwidth = 0; |
|
467 |
gridBagConstraints2.gridheight = 1; |
|
468 |
gridBagConstraints3.gridx = 0; |
|
469 |
gridBagConstraints3.gridy = 2; |
|
470 |
gridBagConstraints3.weightx = 0.0D; |
|
471 |
gridBagConstraints3.weighty = 0.0D; |
|
472 |
gridBagConstraints3.fill = java.awt.GridBagConstraints.NONE; |
|
473 |
gridBagConstraints3.ipadx = 0; |
|
474 |
gridBagConstraints3.ipady = 0; |
|
475 |
gridBagConstraints3.insets = new java.awt.Insets(0,0,0,0); |
|
476 |
gridBagConstraints3.gridheight = 0; |
|
477 |
gridBagConstraints3.gridwidth = 0; |
|
478 |
pSharpNorth.add(getActivationPanel(), gridBagConstraints2); |
|
479 |
pSharpNorth.add(getRGBBandAssignPane(), gridBagConstraints3); |
|
480 |
pSharpNorth.add(getPSharpSouth(), gridBagConstraints10); |
|
481 |
} |
|
482 |
return pSharpNorth; |
|
483 |
} |
Also available in: Unified diff