svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / px / PxRaster.java @ 5185
History | View | Annotate | Download (42.3 KB)
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.px; |
25 |
|
26 |
import java.awt.Color; |
27 |
import java.awt.Component; |
28 |
import java.awt.Graphics2D; |
29 |
import java.awt.Image; |
30 |
import java.awt.geom.GeneralPath; |
31 |
import java.awt.geom.Point2D; |
32 |
import java.awt.image.BufferedImage; |
33 |
import java.awt.image.DataBuffer; |
34 |
import java.awt.image.ImageObserver; |
35 |
import java.util.ArrayList; |
36 |
import java.util.Date; |
37 |
import java.util.Vector; |
38 |
|
39 |
import org.cresques.cts.ICoordTrans; |
40 |
import org.cresques.cts.IProjection; |
41 |
import org.cresques.geo.Projected; |
42 |
import org.cresques.geo.ViewPortData; |
43 |
import org.cresques.io.EcwFile; |
44 |
import org.cresques.io.GdalFile; |
45 |
import org.cresques.io.GeoRasterFile; |
46 |
import org.cresques.io.SupersamplingNotSupportedException; |
47 |
import org.cresques.io.raster.RasterBuf; |
48 |
import org.cresques.io.raster.RasterFilterStack; |
49 |
import org.cresques.io.raster.RasterFilterStackManager; |
50 |
import org.cresques.io.raster.RasterStats; |
51 |
import org.cresques.io.raster.RasterToImageFilter; |
52 |
|
53 |
|
54 |
/**
|
55 |
*
|
56 |
* @author Luis W. Sevilla (sevilla_lui@gva.es)
|
57 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
58 |
*
|
59 |
*/
|
60 |
public class PxRaster extends PxObj implements Projected { |
61 |
protected GeoRasterFile[] geoFile = null; |
62 |
protected ImageObserver component = null; |
63 |
Vector pts = null; |
64 |
|
65 |
// Soporte para n bandas, visibles de 3 en 3, en ficheros separados
|
66 |
//protected GeoRasterFile [] colorBand = null;
|
67 |
protected int rBand = 1; |
68 |
|
69 |
// Soporte para n bandas, visibles de 3 en 3, en ficheros separados
|
70 |
//protected GeoRasterFile [] colorBand = null;
|
71 |
protected int gBand = 2; |
72 |
|
73 |
// Soporte para n bandas, visibles de 3 en 3, en ficheros separados
|
74 |
//protected GeoRasterFile [] colorBand = null;
|
75 |
protected int bBand = 3; |
76 |
public RasterStats stats = new RasterStats(); |
77 |
int transparente = 0x10ffff80; |
78 |
String vName = null; |
79 |
protected boolean pintaMarco = false; //true; |
80 |
IProjection proj = null;
|
81 |
protected Extent extentOrig = null; |
82 |
ICoordTrans rp = null;
|
83 |
public RasterFilterStack filterStack = new RasterFilterStack(stats); |
84 |
private BandSwitch bandSwitch = new BandSwitch(); |
85 |
private boolean firstPxRaster = true; |
86 |
private final double percentFilterInit = 0.02; |
87 |
private RasterFilterStackManager stackManager = null; |
88 |
private Image geoImage = null; |
89 |
private ViewPortData lastViewPort = null; |
90 |
|
91 |
/*public boolean transparencyFilterEnabled = false;
|
92 |
public boolean enhancedFilterEnabled = false;
|
93 |
public boolean tailFilterEnabled = false;*/
|
94 |
|
95 |
/**
|
96 |
* Constructor.
|
97 |
* @param component
|
98 |
*/
|
99 |
public PxRaster(ImageObserver component) { |
100 |
this.component = component;
|
101 |
} |
102 |
|
103 |
/**
|
104 |
* Contructor para un solo fichero
|
105 |
* @param proj Proyeccci?n
|
106 |
* @param fname Nombre del fichero
|
107 |
* @param component
|
108 |
*/
|
109 |
public PxRaster(IProjection proj, String fname, ImageObserver component) { |
110 |
geoFile = new GeoRasterFile[1]; |
111 |
geoFile[0] = GeoRasterFile.openFile(proj, fname); //loadECW(fname); |
112 |
geoFile[0].setUpdatable((Component) component); |
113 |
this.proj = proj;
|
114 |
this.component = component;
|
115 |
setExtent(geoFile[0].getExtent());
|
116 |
geoFile[0].setView(geoFile[0].getExtent()); |
117 |
extentOrig = extent; |
118 |
bandSwitch.addFile(geoFile[0]);
|
119 |
|
120 |
if (geoFile[0].getBandCount() >= 3) { |
121 |
setBand(GeoRasterFile.RED_BAND, 0);
|
122 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
123 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
124 |
} else if (geoFile[0].getBandCount() == 2) { |
125 |
setBand(GeoRasterFile.RED_BAND, 0);
|
126 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
127 |
setBand(GeoRasterFile.BLUE_BAND, 1);
|
128 |
} else if (geoFile[0].getBandCount() == 1) { |
129 |
//setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
130 |
setBand(GeoRasterFile.RED_BAND, 0);
|
131 |
setBand(GeoRasterFile.GREEN_BAND, 0);
|
132 |
setBand(GeoRasterFile.BLUE_BAND, 0);
|
133 |
} |
134 |
} |
135 |
|
136 |
/**
|
137 |
* Constructor para multiples ficheros
|
138 |
*/
|
139 |
public PxRaster(IProjection proj, String[] fnames, ImageObserver component) { |
140 |
this.proj = proj;
|
141 |
this.component = component;
|
142 |
geoFile = new GeoRasterFile[fnames.length];
|
143 |
|
144 |
for (int i = 0; i < geoFile.length; i++) { |
145 |
geoFile[i] = GeoRasterFile.openFile(proj, fnames[i]); //loadECW(fname);
|
146 |
geoFile[i].setUpdatable((Component) component);
|
147 |
setExtent(geoFile[i].getExtent()); |
148 |
geoFile[i].setView(geoFile[i].getExtent()); |
149 |
bandSwitch.addFile(geoFile[i]); |
150 |
} |
151 |
|
152 |
//geoFile = geoFile[0];
|
153 |
extentOrig = extent; |
154 |
|
155 |
if ((fnames.length >= 3) || (geoFile[0].getBandCount() > 2)) { |
156 |
setBand(GeoRasterFile.RED_BAND, 0);
|
157 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
158 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
159 |
} else {
|
160 |
setBand(GeoRasterFile.RED_BAND | GeoRasterFile.GREEN_BAND | |
161 |
GeoRasterFile.BLUE_BAND, 0);
|
162 |
} |
163 |
} |
164 |
|
165 |
public PxRaster(GeoRasterFile eFile, ImageObserver component, Extent view) { |
166 |
geoFile = new GeoRasterFile[1]; |
167 |
geoFile[0] = eFile; //loadECW(fname); |
168 |
geoFile[0].setUpdatable((Component) component); |
169 |
setProjection(geoFile[0].getProjection());
|
170 |
this.component = component;
|
171 |
|
172 |
setExtent(geoFile[0].getExtent());
|
173 |
if(view != null){ |
174 |
geoFile[0].setView(view); //geoFile.getExtent()); |
175 |
extentOrig = extent; |
176 |
bandSwitch.addFile(eFile); |
177 |
|
178 |
if (geoFile[0].getBandCount() >= 3) { |
179 |
setBand(GeoRasterFile.RED_BAND, 0);
|
180 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
181 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
182 |
} else if (geoFile[0].getBandCount() == 2) { |
183 |
setBand(GeoRasterFile.RED_BAND, 0);
|
184 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
185 |
setBand(GeoRasterFile.BLUE_BAND, 1);
|
186 |
} else if (geoFile[0].getBandCount() == 1) { |
187 |
//setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
188 |
setBand(GeoRasterFile.RED_BAND, 0);
|
189 |
setBand(GeoRasterFile.GREEN_BAND, 0);
|
190 |
setBand(GeoRasterFile.BLUE_BAND, 0);
|
191 |
} |
192 |
} |
193 |
} |
194 |
|
195 |
/**
|
196 |
* A?ade un GeoRasterFile al PxRaster
|
197 |
* @param fileName Nombre del fichero
|
198 |
*/
|
199 |
public void addFile(String fileName) { |
200 |
if (geoFile != null) { |
201 |
GeoRasterFile[] listFiles = new GeoRasterFile[geoFile.length + 1]; |
202 |
|
203 |
for (int i = 0; i < geoFile.length; i++) |
204 |
listFiles[i] = geoFile[i]; |
205 |
|
206 |
listFiles[geoFile.length] = GeoRasterFile.openFile(proj, fileName); |
207 |
listFiles[geoFile.length].setUpdatable((Component) component);
|
208 |
setExtent(listFiles[geoFile.length].getExtent()); |
209 |
listFiles[geoFile.length].setView(listFiles[geoFile.length].getExtent()); |
210 |
bandSwitch.addFile(listFiles[geoFile.length]); |
211 |
geoFile = listFiles; |
212 |
} else {
|
213 |
System.err.println("PxRaster.addFile(): Imagen no cargada."); |
214 |
|
215 |
return;
|
216 |
} |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Devuelve el Extent de un fichero son necesidad de a?adirlo
|
221 |
* al PxRaster
|
222 |
* @param fileName
|
223 |
* @return
|
224 |
*/
|
225 |
public Extent testExtentFile(String fileName) { |
226 |
GeoRasterFile grf = GeoRasterFile.openFile(proj, fileName); |
227 |
|
228 |
return grf.getExtent();
|
229 |
} |
230 |
|
231 |
/**
|
232 |
* Obtiene el valor del pixel del Image en la posici?n wcx,wcy
|
233 |
* @param wcx Posici?n x
|
234 |
* @param wcx Posici?n y
|
235 |
* @return valor de pixel
|
236 |
*/
|
237 |
public int[] getPixel(double wcx, double wcy) { |
238 |
if (geoImage != null) { |
239 |
int ptox = 0; |
240 |
int ptoy = 0; |
241 |
|
242 |
try {
|
243 |
//Extent de la imagen completa
|
244 |
Extent extOrtofoto = geoFile[0].getExtent();
|
245 |
|
246 |
//Variables q definen el extent del objeto image
|
247 |
double minx = 0; |
248 |
|
249 |
//Variables q definen el extent del objeto image
|
250 |
double miny = 0; |
251 |
|
252 |
//Variables q definen el extent del objeto image
|
253 |
double maxx = 0; |
254 |
|
255 |
//Variables q definen el extent del objeto image
|
256 |
double maxy = 0; |
257 |
|
258 |
if (lastViewPort.getExtent().getMin().getX() < extOrtofoto.minX()) {
|
259 |
minx = extOrtofoto.minX(); |
260 |
} else {
|
261 |
minx = lastViewPort.getExtent().getMin().getX(); |
262 |
} |
263 |
|
264 |
if (lastViewPort.getExtent().getMax().getX() > extOrtofoto.maxX()) {
|
265 |
maxx = extOrtofoto.maxX(); |
266 |
} else {
|
267 |
maxx = lastViewPort.getExtent().getMax().getX(); |
268 |
} |
269 |
|
270 |
if (lastViewPort.getExtent().getMin().getY() < extOrtofoto.minY()) {
|
271 |
miny = extOrtofoto.minY(); |
272 |
} else {
|
273 |
miny = lastViewPort.getExtent().getMin().getY(); |
274 |
} |
275 |
|
276 |
if (lastViewPort.getExtent().getMax().getY() > extOrtofoto.maxY()) {
|
277 |
maxy = extOrtofoto.maxY(); |
278 |
} else {
|
279 |
maxy = lastViewPort.getExtent().getMax().getY(); |
280 |
} |
281 |
|
282 |
//Comprobamos que estemos dentro del extent del Image
|
283 |
if ((wcx < minx) || (wcx > maxx) || (wcy < miny) ||
|
284 |
(wcy > maxy)) { |
285 |
int[] res = { -1, -1, -1, -1 }; |
286 |
|
287 |
return res;
|
288 |
} |
289 |
|
290 |
//Pasamos a coordenadas del Image las coordenadas del mundo real
|
291 |
int w = ((BufferedImage) geoImage).getWidth(); |
292 |
int h = ((BufferedImage) geoImage).getHeight(); |
293 |
double wcw = maxx - minx;
|
294 |
double wch = maxy - miny;
|
295 |
ptox = (int) (((wcx - minx) * w) / wcw);
|
296 |
ptoy = (int) (((wcy - miny) * h) / wch);
|
297 |
|
298 |
//Obtenemos el pto seleccionado del Image y extraemos el RGB
|
299 |
int px = ((BufferedImage) geoImage).getRGB(ptox, h - ptoy); |
300 |
int[] values = new int[4]; |
301 |
values[0] = ((px & 0xff000000) >> 24); |
302 |
values[1] = ((px & 0x00ff0000) >> 16); |
303 |
values[2] = ((px & 0x0000ff00) >> 8); |
304 |
values[3] = (px & 0x000000ff); |
305 |
|
306 |
return values;
|
307 |
} catch (ArrayIndexOutOfBoundsException e) { |
308 |
e.printStackTrace(); |
309 |
} |
310 |
} |
311 |
|
312 |
return null; |
313 |
} |
314 |
|
315 |
/**
|
316 |
* Elimina un GeoRasterFile al PxRaster
|
317 |
* @param finaName Nombre del fichero
|
318 |
*/
|
319 |
public void delFile(String fileName) { |
320 |
if (geoFile != null) { |
321 |
Vector grfTemp = new Vector(); |
322 |
|
323 |
for (int i = 0; i < geoFile.length; i++) { |
324 |
if (!fileName.endsWith(geoFile[i].getName())) {
|
325 |
grfTemp.add(geoFile[i]); |
326 |
} |
327 |
} |
328 |
|
329 |
GeoRasterFile[] listFiles = new GeoRasterFile[grfTemp.size()]; |
330 |
|
331 |
for (int i = 0; i < listFiles.length; i++) |
332 |
listFiles[i] = (GeoRasterFile) grfTemp.get(i); |
333 |
|
334 |
//Lo eliminamos del bandSwitch
|
335 |
for (int i = 0; i < geoFile.length; i++) { |
336 |
if (fileName.endsWith(geoFile[i].getName())) {
|
337 |
bandSwitch.removeFile(geoFile[i]); |
338 |
} |
339 |
} |
340 |
|
341 |
geoFile = listFiles; |
342 |
|
343 |
/*if(geoFile!=null)
|
344 |
setExtent(geoFile[0].getExtent());*/
|
345 |
} else {
|
346 |
System.err.println("PxRaster.addFile(): Imagen no cargada."); |
347 |
|
348 |
return;
|
349 |
} |
350 |
} |
351 |
|
352 |
/**
|
353 |
* Obtiene el tama?o de bloque
|
354 |
* @return
|
355 |
*/
|
356 |
public int getBlockSize() { |
357 |
return geoFile[0].getBlockSize(); |
358 |
} |
359 |
|
360 |
/**
|
361 |
*
|
362 |
* @return
|
363 |
*/
|
364 |
public GeoRasterFile[] getGeoFiles() { |
365 |
return geoFile;
|
366 |
} |
367 |
|
368 |
public GeoRasterFile getGeoFile() {
|
369 |
return geoFile[0]; |
370 |
} |
371 |
|
372 |
/**
|
373 |
* Obtiene el n?mero de bandas del PxRaster. Si ls longitud de geoFile es 1 quiere
|
374 |
* decir que hay un solo fichero que contiene todas las bandas. Si hay m?s de un geoFile
|
375 |
* el n?mero de bandas ser? la suma de todas las bandas de las im?genes que forman
|
376 |
* el geoFile
|
377 |
* @return N?mero de bandas
|
378 |
*/
|
379 |
public int getBandCount() { |
380 |
return bandSwitch.getBandCount();
|
381 |
} |
382 |
|
383 |
/**
|
384 |
* Obtiene el tipo de dato del primer GeoRasterFile
|
385 |
* @return
|
386 |
*/
|
387 |
public int getDataType() { |
388 |
if (geoFile != null) { |
389 |
return geoFile[0].getDataType(); |
390 |
} else {
|
391 |
System.err.println("PxRaster.getDataType(): Imagen no cargada."); |
392 |
} |
393 |
|
394 |
return 0; |
395 |
} |
396 |
|
397 |
/**
|
398 |
* Obtiene el vector de GeoRasterFile que componen el PxRaster
|
399 |
* @return vector GeoRasterFile
|
400 |
*/
|
401 |
public GeoRasterFile[] getFiles() { |
402 |
return geoFile;
|
403 |
} |
404 |
|
405 |
/**
|
406 |
* Asocia un colorBand al rojo, verde o azul.
|
407 |
* @param flag cual (o cuales) de las bandas.
|
408 |
* @param nBand que colorBand
|
409 |
*/
|
410 |
public void setBand(int flag, int nBand) { |
411 |
bandSwitch.setBand(flag, nBand); |
412 |
} |
413 |
|
414 |
/**
|
415 |
* Obtiene la posici?n del fichero asignado a la banda
|
416 |
* que se le pasa por par?metro
|
417 |
* @return
|
418 |
*/
|
419 |
public int getPosFile(int flag) { |
420 |
if (flag == GeoRasterFile.RED_BAND) {
|
421 |
return bandSwitch.getBandR().getPos();
|
422 |
} else if (flag == GeoRasterFile.GREEN_BAND) { |
423 |
return bandSwitch.getBandG().getPos();
|
424 |
} else if (flag == GeoRasterFile.BLUE_BAND) { |
425 |
return bandSwitch.getBandB().getPos();
|
426 |
} else {
|
427 |
return -1; |
428 |
} |
429 |
} |
430 |
|
431 |
/**
|
432 |
* Devuelve el colorBand activo en la banda especificada.
|
433 |
* @param flag banda.
|
434 |
*/
|
435 |
public int getBand(int flag) { |
436 |
if (flag == GeoRasterFile.RED_BAND) {
|
437 |
return bandSwitch.getBandR().getBand();
|
438 |
} else if (flag == GeoRasterFile.GREEN_BAND) { |
439 |
return bandSwitch.getBandG().getBand();
|
440 |
} else if (flag == GeoRasterFile.BLUE_BAND) { |
441 |
return bandSwitch.getBandB().getBand();
|
442 |
} else {
|
443 |
return -1; |
444 |
} |
445 |
} |
446 |
|
447 |
/**
|
448 |
* @param pm
|
449 |
*/
|
450 |
public void setDrawBorder(boolean pm) { |
451 |
pintaMarco = pm; |
452 |
} |
453 |
|
454 |
/**
|
455 |
* Obtiene el nombre del fichero si solo hay uno
|
456 |
* @return Nombre del fichero
|
457 |
*/
|
458 |
public String getFName() { |
459 |
return geoFile[0].getName(); |
460 |
} |
461 |
|
462 |
/**
|
463 |
* Obtiene el nombre del fichero GeoRasterFile seleccionado
|
464 |
* @param i posici?n del GeoRasterFile
|
465 |
* @return Nombre del fichero
|
466 |
*/
|
467 |
public String getFName(int i) { |
468 |
if (geoFile != null) { |
469 |
if (i < geoFile.length) {
|
470 |
return geoFile[i].getName();
|
471 |
} else {
|
472 |
return null; |
473 |
} |
474 |
} else {
|
475 |
System.err.println("PxRaster.getFName(): Imagen no cargada."); |
476 |
|
477 |
return null; |
478 |
} |
479 |
} |
480 |
|
481 |
/**
|
482 |
* Obtiene una lista de Strings con los nombres de todos los ficheros
|
483 |
* que tiene el PxRaster
|
484 |
* @return Lista de nombres
|
485 |
*/
|
486 |
public String[] getLisName() { |
487 |
if (geoFile != null) { |
488 |
String[] list = new String[geoFile.length]; |
489 |
|
490 |
for (int i = 0; i < geoFile.length; i++) |
491 |
list[i] = geoFile[i].getName(); |
492 |
|
493 |
return list;
|
494 |
} else {
|
495 |
System.err.println("PxRaster.getListName(): Imagen no cargada."); |
496 |
|
497 |
return null; |
498 |
} |
499 |
} |
500 |
|
501 |
/**
|
502 |
* Devuelve la anchura total del fichero, en pixeles.
|
503 |
* @return ancho en pixeles
|
504 |
*/
|
505 |
public int getFWidth() { |
506 |
if (geoFile != null) { |
507 |
return geoFile[0].getWidth(); |
508 |
} else {
|
509 |
System.err.println("PxRaster.getFWidth(): Imagen no cargada."); |
510 |
|
511 |
return 0; |
512 |
} |
513 |
} |
514 |
|
515 |
/**
|
516 |
* Devuelve la anchura total del fichero, en pixeles.
|
517 |
* @return ancho en pixeles
|
518 |
*/
|
519 |
public int getFWidth(int i) { |
520 |
if (i < geoFile.length) {
|
521 |
return geoFile[i].getWidth();
|
522 |
} else {
|
523 |
System.err.println("PxRaster.getFWidth(): Imagen no cargada."); |
524 |
|
525 |
return 0; |
526 |
} |
527 |
} |
528 |
|
529 |
/**
|
530 |
* Devuelve la altura total del fichero, en pixeles.
|
531 |
* @return alto en pixeles
|
532 |
*/
|
533 |
public int getFHeight() { |
534 |
if (geoFile != null) { |
535 |
return geoFile[0].getHeight(); |
536 |
} else {
|
537 |
System.err.println("PxRaster.getFHeight(): Imagen no cargada."); |
538 |
|
539 |
return 0; |
540 |
} |
541 |
} |
542 |
|
543 |
/**
|
544 |
* Devuelve la altura total del fichero, en pixeles.
|
545 |
* @return alto en pixeles
|
546 |
*/
|
547 |
public int getFHeight(int i) { |
548 |
if (i < geoFile.length) {
|
549 |
return geoFile[i].getHeight();
|
550 |
} else {
|
551 |
System.err.println("PxRaster.getFHeight(): Imagen no cargada."); |
552 |
|
553 |
return 0; |
554 |
} |
555 |
} |
556 |
|
557 |
/**
|
558 |
* Devuelve el n?mero de ficheros que componen el PxRaster
|
559 |
* @return N?mero de ficheros
|
560 |
*/
|
561 |
public int nFiles() { |
562 |
if (geoFile != null) { |
563 |
return geoFile.length;
|
564 |
} else {
|
565 |
return 0; |
566 |
} |
567 |
} |
568 |
|
569 |
/**
|
570 |
* Activa o desactiva la transparencia de los ficheros que forman el PxRaster
|
571 |
* @param t true o false para activar o desactivar transparencia
|
572 |
*/
|
573 |
public void setTransparency(boolean t) { |
574 |
if (geoFile != null) { |
575 |
for (int i = 0; i < geoFile.length; i++) { |
576 |
geoFile[i].setTransparency(t); |
577 |
} |
578 |
} else {
|
579 |
System.err.println("PxRaster.setTransparency(): Imagen no cargada."); |
580 |
|
581 |
return;
|
582 |
} |
583 |
} |
584 |
|
585 |
/**
|
586 |
* Pone la transparencia de los ficheros de la imagen a un valor
|
587 |
* @param t Valor para la transparencia
|
588 |
*/
|
589 |
public void setTransparency(int t) { |
590 |
if (geoFile != null) { |
591 |
for (int i = 0; i < geoFile.length; i++) { |
592 |
geoFile[i].setTransparency(t); |
593 |
} |
594 |
} else {
|
595 |
System.err.println("PxRaster.setTransparency(): Imagen no cargada."); |
596 |
|
597 |
return;
|
598 |
} |
599 |
} |
600 |
|
601 |
/**
|
602 |
* Obtiene el alpha del primer fichero. Han de ser iguales en todos
|
603 |
* los ficheros de la imagen.
|
604 |
* @return alpha
|
605 |
*/
|
606 |
public int getAlpha() { |
607 |
if (geoFile != null) { |
608 |
return geoFile[0].getAlpha(); |
609 |
} else {
|
610 |
System.err.println("PxRaster.getAlpha(): Imagen no cargada."); |
611 |
|
612 |
return 0; |
613 |
} |
614 |
} |
615 |
|
616 |
/**
|
617 |
* Asigna el extent
|
618 |
* @param e extent
|
619 |
*/
|
620 |
public void setExtent(Extent e) { |
621 |
super.extent = e;
|
622 |
if(e != null){ |
623 |
pts = new Vector(); |
624 |
pts.add(proj.createPoint(e.minX(), e.minY())); |
625 |
pts.add(proj.createPoint(e.maxX(), e.minY())); |
626 |
pts.add(proj.createPoint(e.maxX(), e.maxY())); |
627 |
pts.add(proj.createPoint(e.minX(), e.maxY())); |
628 |
} |
629 |
} |
630 |
|
631 |
/**
|
632 |
* Cambia la vista (viewport) sobre el raster.
|
633 |
*
|
634 |
* @param v extent
|
635 |
* @param vName nombre
|
636 |
*/
|
637 |
public void setView(Extent v, String vName) { |
638 |
if (geoFile != null) { |
639 |
for (int i = 0; i < geoFile.length; i++) { |
640 |
geoFile[i].setView(v); |
641 |
} |
642 |
} else {
|
643 |
System.err.println("PxRaster.setView(): Imagen no cargada."); |
644 |
|
645 |
return;
|
646 |
} |
647 |
|
648 |
this.vName = vName;
|
649 |
} |
650 |
|
651 |
/**
|
652 |
* Obtiene la escala.
|
653 |
*
|
654 |
* @param width
|
655 |
* @param height
|
656 |
* @return
|
657 |
*/
|
658 |
public double[] getScale(int width, int height) { |
659 |
double[] scale = new double[2]; |
660 |
|
661 |
if (geoFile != null) { |
662 |
scale[0] = ((double) width) / geoFile[0].getView().width(); |
663 |
scale[1] = ((double) height) / geoFile[0].getView().height(); |
664 |
|
665 |
return scale;
|
666 |
} else {
|
667 |
System.err.println("PxRaster.getScale(): Imagen no cargada."); |
668 |
|
669 |
return null; |
670 |
} |
671 |
} |
672 |
|
673 |
/**
|
674 |
* Ajusta la extensi?n pasada por par?metro y que corresponde al extent de la vista donde
|
675 |
* se va a dibujar a los valores m?ximos y m?nimos de la imagen. Esto sirve para que la
|
676 |
* petici?n al driver nunca sobrepase los l?mites de la imagen tratada aunque la vista
|
677 |
* donde se dibuje sea de mayor tama?o.
|
678 |
*
|
679 |
* @param sz Extent completo de la vista donde se va a dibujar.
|
680 |
*/
|
681 |
protected double[] calculateNewView(Extent sz) { |
682 |
double vx = sz.minX();
|
683 |
double vy = sz.minY();
|
684 |
double vx2 = sz.maxX();
|
685 |
double vy2 = sz.maxY();
|
686 |
|
687 |
if (sz.minX() < extent.minX())
|
688 |
vx = extent.minX(); |
689 |
|
690 |
if (sz.minY() < extent.minY())
|
691 |
vy = extent.minY(); |
692 |
|
693 |
if (sz.maxX() > extent.maxX())
|
694 |
vx2 = extent.maxX(); |
695 |
|
696 |
if (sz.maxY() > extent.maxY())
|
697 |
vy2 = extent.maxY(); |
698 |
|
699 |
if (geoFile != null) { |
700 |
for (int i = 0; i < geoFile.length; i++) |
701 |
geoFile[i].setView(new Extent(vx, vy, vx2, vy2));
|
702 |
} else {
|
703 |
System.err.println("PxRaster.calculateNewView(): Imagen no cargada."); |
704 |
} |
705 |
double[] adjustedExtent = {vx, vy, vx2, vy2}; |
706 |
return adjustedExtent;
|
707 |
} |
708 |
|
709 |
/**
|
710 |
* Dibuja el raster sobre el Graphics. Para ello debemos de pasar el viewPort que corresponde a la
|
711 |
* vista. Este viewPort es ajustado a los tama?os m?ximos y m?nimos de la imagen por la funci?n
|
712 |
* calculateNewView. Esta funci?n tambi?n asignar? la vista a los drivers. Posteriormente se calcula
|
713 |
* el alto y ancho de la imagen a dibujar (wImg, hImg), as? como el punto donde se va a pintar dentro
|
714 |
* del graphics (pt). Finalmente se llama a updateImage del driver para que pinte y una vez dibujado
|
715 |
* se pasa a trav?s de la funci?n renderizeRaster que es la encargada de aplicar la pila de filtros
|
716 |
* sobre el Image que ha devuelto el driver.
|
717 |
*
|
718 |
* @param g Graphics sobre el que se pinta
|
719 |
* @param vp ViewPort de la extensi?n a dibujar
|
720 |
*/
|
721 |
public synchronized void draw(Graphics2D g, ViewPortData vp) { |
722 |
geoImage = null;
|
723 |
|
724 |
long t2;
|
725 |
long t1 = new Date().getTime(); |
726 |
lastViewPort = vp; |
727 |
|
728 |
if ((vp.getExtent().minX() > extent.maxX()) ||
|
729 |
(vp.getExtent().minY() > extent.maxY()) || |
730 |
(vp.getExtent().maxX() < extent.minX()) || |
731 |
(vp.getExtent().maxY() < extent.minY())) { |
732 |
return;
|
733 |
} |
734 |
|
735 |
double[] adjustedExtent = calculateNewView(vp.getExtent()); |
736 |
|
737 |
Extent v = geoFile[0].getView();
|
738 |
double x = v.minX();
|
739 |
double y = v.minY();
|
740 |
double w = v.width();
|
741 |
double h = v.height();
|
742 |
|
743 |
double scalex = vp.mat.getScaleX();
|
744 |
double scaley = vp.mat.getScaleY();
|
745 |
|
746 |
/*int wImg = (int) Math.round(Math.abs(w * scalex));
|
747 |
int hImg = (int) Math.round(Math.abs(h * scaley));*/
|
748 |
int wImg = (int) Math.round(Math.abs((adjustedExtent[2] - adjustedExtent[0]) * scalex)); |
749 |
int hImg = (int) Math.round(Math.abs((adjustedExtent[3] - adjustedExtent[1]) * scaley)); |
750 |
|
751 |
if ((wImg <= 0) || (hImg <= 0)) |
752 |
return;
|
753 |
|
754 |
//Para la transformaci?n usamos el extent que ha ajustado la funci?n calculateNewView y no usamos
|
755 |
//el getView porque el getView puede haber sufrido una transformaci?n en caso de que exista
|
756 |
//fichero .rmf. En caso de no existir este fichero ser?a lo mismo aplicar la funci?n:
|
757 |
//Point2D.Double pt = new Point2D.Double(x, y + h);
|
758 |
Point2D.Double pt = new Point2D.Double(adjustedExtent[0], adjustedExtent[3]); |
759 |
|
760 |
try {
|
761 |
//System.out.println("Dibujando PxRaster: pt0 = "+pt);
|
762 |
vp.mat.transform(pt, pt); |
763 |
|
764 |
//System.out.println("Dibujando PxRaster: pt1 = "+pt);
|
765 |
if ((geoFile != null) && geoFile[0] instanceof GdalFile && |
766 |
(geoFile[0].getDataType() != DataBuffer.TYPE_BYTE)) { |
767 |
//System.out.println("PxRaster: Has dado con un Raster de 16 bits");
|
768 |
RasterBuf raster = ((GdalFile) geoFile[0]).getRaster(wImg,
|
769 |
hImg, rp); |
770 |
t2 = new Date().getTime(); |
771 |
|
772 |
t2 = new Date().getTime(); |
773 |
System.out.println("Dibujando PxRaster: " + |
774 |
((t2 - t1) / 1000D) +
|
775 |
", secs. Filtrando/Renderizando");
|
776 |
t1 = t2; |
777 |
|
778 |
filterStack.setInitRasterBuf(raster); |
779 |
|
780 |
//Si la imagen es de 16 bits lleva un filtro de realce por defecto
|
781 |
if (stackManager == null) { |
782 |
stackManager = new RasterFilterStackManager(filterStack);
|
783 |
stackManager.addEnhancedFilter(false, geoFile[0].getName()); |
784 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
785 |
stackManager.addTailFilter(this.percentFilterInit, 0D, false); |
786 |
} |
787 |
|
788 |
geoImage = renderizeRaster(raster, vp, v); |
789 |
g.drawImage(geoImage, (int)(pt.getX()),
|
790 |
(int)(pt.getY()), component);
|
791 |
|
792 |
t2 = new Date().getTime(); |
793 |
System.out.println("Dibujando PxRaster: " + |
794 |
((t2 - t1) / 1000D) + ", secs. Dibujando"); |
795 |
} else if((geoFile != null) && (geoFile.length > 1) && |
796 |
(!bandSwitch.getBandR().getGeoRasterFile().getName().equals(bandSwitch.getBandG().getGeoRasterFile().getName()) || |
797 |
!bandSwitch.getBandR().getGeoRasterFile().getName().equals(bandSwitch.getBandB().getGeoRasterFile().getName()) || |
798 |
!bandSwitch.getBandG().getGeoRasterFile().getName().equals(bandSwitch.getBandB().getGeoRasterFile().getName())) |
799 |
) { // multiFiles
|
800 |
System.out.println("Dibujando PxRaster (Multifile) ... Bands " + |
801 |
geoFile.length); |
802 |
|
803 |
if (bandSwitch.getBandR().getGeoRasterFile() instanceof EcwFile) { |
804 |
((EcwFile) bandSwitch.getBandR().getGeoRasterFile()).setMultifile(true);
|
805 |
} |
806 |
|
807 |
if (bandSwitch.getBandG().getGeoRasterFile() instanceof EcwFile) { |
808 |
((EcwFile) bandSwitch.getBandG().getGeoRasterFile()).setMultifile(true);
|
809 |
} |
810 |
|
811 |
if (bandSwitch.getBandB().getGeoRasterFile() instanceof EcwFile) { |
812 |
((EcwFile) bandSwitch.getBandB().getGeoRasterFile()).setMultifile(true);
|
813 |
} |
814 |
|
815 |
//TODO:Soluci?n para que no se pinte si hay sharpening. Esto hay que pensarlo mejor
|
816 |
if (stackManager == null) |
817 |
stackManager = new RasterFilterStackManager(filterStack);
|
818 |
if(!filterStack.isActive(stackManager.getTypeFilter("sharpening"))){ |
819 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage(wImg, hImg, rp, null, 0, 0); |
820 |
geoImage = bandSwitch.getBandG().getGeoRasterFile().updateImage(wImg, hImg, rp, geoImage, |
821 |
bandSwitch.getBandG().getBand(), GeoRasterFile.GREEN_BAND); |
822 |
geoImage = bandSwitch.getBandB().getGeoRasterFile().updateImage(wImg, hImg, rp, geoImage, |
823 |
bandSwitch.getBandB().getBand(), GeoRasterFile.BLUE_BAND); |
824 |
}else{
|
825 |
geoImage = new BufferedImage(wImg, hImg, BufferedImage.TYPE_INT_RGB); |
826 |
} |
827 |
|
828 |
filterStack.setInitRasterBuf(geoImage); |
829 |
|
830 |
geoImage = renderizeRaster(geoImage, vp, v); |
831 |
|
832 |
g.drawImage(geoImage, (int)(pt.getX()), (int)(pt.getY()), component); |
833 |
t2 = new Date().getTime(); |
834 |
System.out.println("Dibujando PxRaster: " + |
835 |
((t2 - t1) / 1000D) + ", secs."); |
836 |
} else if ((geoFile != null) ) { // Una solo fichero |
837 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage(wImg, hImg, rp, null, 0, 0); |
838 |
|
839 |
filterStack.setInitRasterBuf(geoImage); |
840 |
|
841 |
geoImage = renderizeRaster(geoImage, vp, v); |
842 |
|
843 |
g.drawImage(geoImage, (int) (pt.getX()), (int) (pt.getY()), component); |
844 |
|
845 |
t2 = new Date().getTime(); |
846 |
System.out.println("Dibujando PxRaster: " + |
847 |
((t2 - t1) / 1000D) + ", secs."); |
848 |
} else { // no cargada |
849 |
System.err.println("Dibujando PxRaster: Foto no cargada."); |
850 |
} |
851 |
}catch (SupersamplingNotSupportedException e) {
|
852 |
System.err.println("Supersampling not supported"); |
853 |
return;
|
854 |
}catch (Exception e) { |
855 |
e.printStackTrace(); |
856 |
} |
857 |
|
858 |
if (pintaMarco) {
|
859 |
drawMarco(g, vp); |
860 |
} |
861 |
} |
862 |
|
863 |
/**
|
864 |
* Aplica la pila de fitros sobre el RasterBuf pasado como par?metro
|
865 |
* y lo devuelve en Image
|
866 |
* @param raster RasterBuf con la imagen sobre la que se aplicaran filtros
|
867 |
* @return Image con la imagen con los filtros puestos
|
868 |
*/
|
869 |
public Image renderizeRaster(RasterBuf raster, ViewPortData vp, Extent e) { |
870 |
if (filterStack != null) { |
871 |
filterStack.setViewPortData(vp); |
872 |
filterStack.setExtent(e); |
873 |
filterStack.execute(raster); |
874 |
} |
875 |
System.out.println("Image renderizeRaster(RasterBuf raster, ViewPortData vp) "); |
876 |
//Aplicamos el filtro para convertir a Image
|
877 |
RasterToImageFilter rti = new RasterToImageFilter();
|
878 |
rti.addParam("raster", raster);
|
879 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
880 |
rti.execute(); |
881 |
raster = null;
|
882 |
|
883 |
return (Image) rti.getResult("raster"); |
884 |
} |
885 |
|
886 |
/**
|
887 |
* Aplica la pila de filtros sobre el Image pasado como par?metro y lo devuelve.
|
888 |
* Si la salida del ?ltimo filtro es un RasterBuf lo convertir? a Image
|
889 |
* @param image Image con la imagen sobre la que se aplicaran filtros
|
890 |
* @return Image con la imagen con los filtros puestos
|
891 |
*/
|
892 |
public Image renderizeRaster(Image image, ViewPortData vp, Extent e) { |
893 |
if (filterStack != null) { |
894 |
filterStack.setViewPortData(vp); |
895 |
filterStack.setExtent(e); |
896 |
filterStack.execute(image); |
897 |
} |
898 |
|
899 |
if (filterStack.getOutDataType() != RasterBuf.TYPE_IMAGE) {
|
900 |
//Aplicamos el filtro para convertir a Image
|
901 |
RasterToImageFilter rti = new RasterToImageFilter();
|
902 |
rti.addParam("raster", (RasterBuf) filterStack.getResult());
|
903 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
904 |
rti.execute(); |
905 |
|
906 |
return (Image) rti.getResult("raster"); |
907 |
} |
908 |
return (Image) filterStack.getResult(); |
909 |
// return image;
|
910 |
} |
911 |
|
912 |
/**
|
913 |
*
|
914 |
* @param g
|
915 |
* @param vp
|
916 |
*/
|
917 |
public void drawMarco(Graphics2D g, ViewPortData vp) { |
918 |
// Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
|
919 |
Color color = new Color(128, 128, 128); |
920 |
|
921 |
// Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
|
922 |
Color fillColor = new Color(255, 220, 220, 0x20); |
923 |
GeneralPath gp = newGP(vp);
|
924 |
g.setColor(fillColor); |
925 |
g.fill(gp); |
926 |
g.setColor(color); |
927 |
g.draw(gp); |
928 |
} |
929 |
|
930 |
private GeneralPath newGP(ViewPortData vp) { |
931 |
//if (gp != null) return;
|
932 |
GeneralPath gp = new GeneralPath(); |
933 |
Point2D.Double pt0 = new Point2D.Double(0.0, 0.0); |
934 |
Point2D.Double pt1 = new Point2D.Double(0.0, 0.0); |
935 |
Point2D.Double pt2 = new Point2D.Double(0.0, 0.0); |
936 |
Point2D.Double pt3 = new Point2D.Double(0.0, 0.0); |
937 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
938 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
939 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
940 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
941 |
|
942 |
// Aspa desde el extent
|
943 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
944 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
945 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
946 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
947 |
|
948 |
// Extent
|
949 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
950 |
gp.lineTo((float) pt1.getX(), (float) pt1.getY()); |
951 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
952 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
953 |
|
954 |
if (extentOrig != extent) {
|
955 |
gp.lineTo((float) pt0.getX(), (float) pt0.getY()); |
956 |
|
957 |
Vector pts = new Vector(); |
958 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.minY())); |
959 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.minY())); |
960 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.maxY())); |
961 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.maxY())); |
962 |
|
963 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
964 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
965 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
966 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
967 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
968 |
gp.lineTo((float) pt1.getX(), (float) pt1.getY()); |
969 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
970 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
971 |
} |
972 |
|
973 |
gp.closePath(); |
974 |
|
975 |
return gp;
|
976 |
} |
977 |
|
978 |
public IProjection getProjection() {
|
979 |
return proj;
|
980 |
} |
981 |
|
982 |
public void setProjection(IProjection p) { |
983 |
proj = p; |
984 |
} |
985 |
|
986 |
public void reProject(ICoordTrans rp) { |
987 |
this.rp = rp.getInverted();
|
988 |
System.out.println("PxRaster: reProject()"); |
989 |
|
990 |
//geoFile.reProject(rp);
|
991 |
Vector savePts = pts;
|
992 |
|
993 |
pts = new Vector(); |
994 |
extent = new Extent();
|
995 |
|
996 |
Point2D ptDest = null; |
997 |
|
998 |
for (int i = 0; i < savePts.size(); i++) { |
999 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
1000 |
ptDest = rp.convert((Point2D) savePts.get(i), ptDest);
|
1001 |
pts.add(ptDest); |
1002 |
extent.add(ptDest); |
1003 |
} |
1004 |
|
1005 |
setProjection(rp.getPDest()); |
1006 |
} |
1007 |
|
1008 |
/**
|
1009 |
* Obtiene el Stack Manager
|
1010 |
* @return
|
1011 |
*/
|
1012 |
public RasterFilterStackManager getStackManager() {
|
1013 |
return this.stackManager; |
1014 |
} |
1015 |
|
1016 |
/**
|
1017 |
* Asigna el Stack Manager
|
1018 |
* @return
|
1019 |
*/
|
1020 |
public void setStackManager(RasterFilterStackManager sm) { |
1021 |
this.stackManager = sm;
|
1022 |
} |
1023 |
|
1024 |
/**
|
1025 |
* Estructura que representa la relaci?n entre un fichero y la banda que se
|
1026 |
* utiliza de este.
|
1027 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
1028 |
*/
|
1029 |
class FileBands { |
1030 |
GeoRasterFile grf; //Fichero
|
1031 |
int band; //Banda asinada |
1032 |
int filePos; //posici?n del fichero |
1033 |
|
1034 |
/**
|
1035 |
* @return Returns the band.
|
1036 |
*/
|
1037 |
public int getBand() { |
1038 |
return band;
|
1039 |
} |
1040 |
|
1041 |
/**
|
1042 |
* @param band The band to set.
|
1043 |
*/
|
1044 |
public void setBand(int band) { |
1045 |
this.band = band;
|
1046 |
} |
1047 |
|
1048 |
/**
|
1049 |
* @return Returns the band.
|
1050 |
*/
|
1051 |
public int getPos() { |
1052 |
return filePos;
|
1053 |
} |
1054 |
|
1055 |
/**
|
1056 |
* @param band The band to set.
|
1057 |
*/
|
1058 |
public void setPos(int pos) { |
1059 |
this.filePos = pos;
|
1060 |
} |
1061 |
|
1062 |
/**
|
1063 |
* @return Returns the grf.
|
1064 |
*/
|
1065 |
public GeoRasterFile getGeoRasterFile() {
|
1066 |
return grf;
|
1067 |
} |
1068 |
|
1069 |
/**
|
1070 |
* @param grf The grf to set.
|
1071 |
*/
|
1072 |
public void setGeoRasterFile(GeoRasterFile grf) { |
1073 |
this.grf = grf;
|
1074 |
} |
1075 |
} |
1076 |
|
1077 |
/**
|
1078 |
* Clase que lleva la gesti?n entre la relaci?n de ficheros representados
|
1079 |
* por un GeoRasterFile y el n?mero de bandas que contienen. Esto es necesario
|
1080 |
* para la actualizaci?n de la vista ya que para un Image dado podemos tener
|
1081 |
* multiples bandas que pueden ser leidas desde diferentes ficheros.
|
1082 |
*
|
1083 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
1084 |
*/
|
1085 |
class BandSwitch { |
1086 |
private ArrayList geoFiles = new ArrayList(); //Lista de GeoRasterFile con los ficheros raster cargados |
1087 |
private FileBands[] listBands = new FileBands[3]; |
1088 |
private boolean debug = false; |
1089 |
|
1090 |
BandSwitch() { |
1091 |
for (int i = 0; i < listBands.length; i++) |
1092 |
listBands[i] = new FileBands();
|
1093 |
} |
1094 |
|
1095 |
/**
|
1096 |
* A?ade un fichero
|
1097 |
* @param grf
|
1098 |
*/
|
1099 |
public void addFile(GeoRasterFile grf) { |
1100 |
geoFiles.add(grf); |
1101 |
|
1102 |
if (debug) {
|
1103 |
this.show("addFile"); |
1104 |
} |
1105 |
} |
1106 |
|
1107 |
/**
|
1108 |
* Elimina un fichero
|
1109 |
* @param grf
|
1110 |
*/
|
1111 |
public void removeFile(GeoRasterFile grf) { |
1112 |
for (int iFile = 0; iFile < geoFiles.size(); iFile++) { |
1113 |
if (grf.equals(geoFiles.get(iFile))) {
|
1114 |
geoFiles.remove(iFile); |
1115 |
iFile--; |
1116 |
} |
1117 |
} |
1118 |
|
1119 |
if (debug) {
|
1120 |
this.show("removeFile"); |
1121 |
} |
1122 |
} |
1123 |
|
1124 |
/**
|
1125 |
*
|
1126 |
* @param flag
|
1127 |
* @param grf
|
1128 |
* @param nBand
|
1129 |
*/
|
1130 |
public void setBand(int flag, GeoRasterFile grf, int nBand) { |
1131 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) {
|
1132 |
listBands[0].setBand(nBand);
|
1133 |
listBands[0].setGeoRasterFile(grf);
|
1134 |
} else if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) { |
1135 |
listBands[1].setBand(nBand);
|
1136 |
listBands[1].setGeoRasterFile(grf);
|
1137 |
} else if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) { |
1138 |
listBands[2].setBand(nBand);
|
1139 |
listBands[2].setGeoRasterFile(grf);
|
1140 |
} else {
|
1141 |
return;
|
1142 |
} |
1143 |
|
1144 |
grf.setBand(flag, nBand); |
1145 |
} |
1146 |
|
1147 |
/**
|
1148 |
* Asigna las bandas
|
1149 |
* @param flag
|
1150 |
* @param nBand
|
1151 |
*/
|
1152 |
public void setBand(int flag, int nBand) { |
1153 |
int cont = 0; |
1154 |
|
1155 |
for (int iGrf = 0; iGrf < geoFiles.size(); iGrf++) { |
1156 |
for (int iBand = 0; |
1157 |
iBand < ((GeoRasterFile) geoFiles.get(iGrf)).getBandCount(); |
1158 |
iBand++) { |
1159 |
if (((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) &&
|
1160 |
(cont == nBand)) { |
1161 |
listBands[0].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1162 |
listBands[0].setBand(iBand);
|
1163 |
listBands[0].setPos(iGrf);
|
1164 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1165 |
|
1166 |
//System.out.println("==>Asignando banda R FILE="+iGrf+" BANDA="+iBand);
|
1167 |
} else if (((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) && |
1168 |
(cont == nBand)) { |
1169 |
listBands[1].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1170 |
listBands[1].setBand(iBand);
|
1171 |
listBands[1].setPos(iGrf);
|
1172 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1173 |
|
1174 |
//System.out.println("==>Asignando banda G FILE="+iGrf+" BANDA="+iBand);
|
1175 |
} else if (((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) && |
1176 |
(cont == nBand)) { |
1177 |
listBands[2].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1178 |
listBands[2].setBand(iBand);
|
1179 |
listBands[2].setPos(iGrf);
|
1180 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1181 |
|
1182 |
//System.out.println("==>Asignando banda B FILE="+iGrf+" BANDA="+iBand);
|
1183 |
} |
1184 |
|
1185 |
cont++; |
1186 |
} |
1187 |
} |
1188 |
|
1189 |
if (debug) {
|
1190 |
this.show("setBand"); |
1191 |
} |
1192 |
} |
1193 |
|
1194 |
/**
|
1195 |
* Obtiene el n?mero de bandas
|
1196 |
* @return
|
1197 |
*/
|
1198 |
public int getBandCount() { |
1199 |
int nbandas = 0; |
1200 |
|
1201 |
for (int iGrf = 0; iGrf < geoFiles.size(); iGrf++) |
1202 |
nbandas += ((GeoRasterFile) geoFiles.get(iGrf)).getBandCount(); |
1203 |
|
1204 |
return nbandas;
|
1205 |
} |
1206 |
|
1207 |
/**
|
1208 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del rojo
|
1209 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1210 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1211 |
*/
|
1212 |
public FileBands getBandR() {
|
1213 |
return listBands[0]; |
1214 |
} |
1215 |
|
1216 |
/**
|
1217 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del verde
|
1218 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1219 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1220 |
*/
|
1221 |
public FileBands getBandG() {
|
1222 |
return listBands[1]; |
1223 |
} |
1224 |
|
1225 |
/**
|
1226 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del azul
|
1227 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1228 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1229 |
*/
|
1230 |
public FileBands getBandB() {
|
1231 |
return listBands[2]; |
1232 |
} |
1233 |
|
1234 |
public void show(String op) { |
1235 |
String banda = null; |
1236 |
System.out.println("** " + op + " **"); |
1237 |
|
1238 |
for (int i = 0; i < 3; i++) { |
1239 |
if (i == 0) { |
1240 |
banda = new String("Rojo"); |
1241 |
} else if (i == 1) { |
1242 |
banda = new String("Verde"); |
1243 |
} else if (i == 2) { |
1244 |
banda = new String("Azul"); |
1245 |
} |
1246 |
|
1247 |
System.out.println("** BANDA IMAGE=" + banda + " FILEPOS=" + |
1248 |
listBands[i].getBand() + |
1249 |
" BANDA DEL FICHERO=" +
|
1250 |
listBands[i].getBand()); |
1251 |
} |
1252 |
} |
1253 |
} |
1254 |
/**
|
1255 |
* @return Returns the vName.
|
1256 |
*/
|
1257 |
public String getVName() { |
1258 |
return vName;
|
1259 |
} |
1260 |
/**
|
1261 |
* @param name The vName to set.
|
1262 |
*/
|
1263 |
public void setVName(String name) { |
1264 |
vName = name; |
1265 |
} |
1266 |
} |