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