svn-gvsig-desktop / tags / gvSIGv0_6_1RELEASE / libraries / libCq CMS for java.old / src / org / cresques / px / PxRaster.java @ 5222
History | View | Annotate | Download (41.1 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 |
* 'Normaliza' la vista en funci?n del extent del raster.
|
675 |
*
|
676 |
* @param mat
|
677 |
* @param sz
|
678 |
*/
|
679 |
protected void calculateNewView(Extent sz) { |
680 |
double vx = sz.minX();
|
681 |
double vy = sz.minY();
|
682 |
double vx2 = sz.maxX();
|
683 |
double vy2 = sz.maxY();
|
684 |
|
685 |
if (sz.minX() < extent.minX()) {
|
686 |
vx = extent.minX(); |
687 |
} |
688 |
|
689 |
if (sz.minY() < extent.minY()) {
|
690 |
vy = extent.minY(); |
691 |
} |
692 |
|
693 |
if (sz.maxX() > extent.maxX()) {
|
694 |
vx2 = extent.maxX(); |
695 |
} |
696 |
|
697 |
if (sz.maxY() > extent.maxY()) {
|
698 |
vy2 = extent.maxY(); |
699 |
} |
700 |
|
701 |
if (geoFile != null) { |
702 |
for (int i = 0; i < geoFile.length; i++) |
703 |
geoFile[i].setView(new Extent(vx, vy, vx2, vy2));
|
704 |
} else {
|
705 |
System.err.println("PxRaster.calculateNewView(): Imagen no cargada."); |
706 |
} |
707 |
} |
708 |
|
709 |
/**
|
710 |
* Dibuja el raster
|
711 |
*/
|
712 |
public synchronized void draw(Graphics2D g, ViewPortData vp) { |
713 |
geoImage = null;
|
714 |
|
715 |
long t2;
|
716 |
long t1 = new Date().getTime(); |
717 |
lastViewPort = vp; |
718 |
|
719 |
//System.out.println("PxRaster.draw(): vp.extent = "+ vp.getExtent());
|
720 |
//System.out.println("PxRaster.draw(): extent = "+ getExtent());
|
721 |
if ((vp.getExtent().minX() > extent.maxX()) ||
|
722 |
(vp.getExtent().minY() > extent.maxY()) || |
723 |
(vp.getExtent().maxX() < extent.minX()) || |
724 |
(vp.getExtent().maxY() < extent.minY())) { |
725 |
return;
|
726 |
} |
727 |
|
728 |
calculateNewView(vp.getExtent()); |
729 |
|
730 |
Extent v = geoFile[0].getView();
|
731 |
double x = v.minX();
|
732 |
double y = v.minY();
|
733 |
double w = v.width();
|
734 |
double h = v.height();
|
735 |
|
736 |
//System.out.println("Pinto PxRaster:" + v);
|
737 |
double scalex = vp.mat.getScaleX() /* g.getTransform().getScaleX()*/; |
738 |
|
739 |
//System.out.println("Pinto PxRaster:" + v);
|
740 |
double scaley = vp.mat.getScaleY() /* g.getTransform().getScaleY() */; |
741 |
int wImg = (int) Math.round(Math.abs(w * scalex)); |
742 |
int hImg = (int) Math.round(Math.abs(h * scaley)); |
743 |
|
744 |
//System.out.println("Sz=("+wImg+","+hImg+"); scale=("+scalex+","+scaley+")");
|
745 |
if ((wImg <= 0) || (hImg <= 0)) { |
746 |
return;
|
747 |
} |
748 |
|
749 |
Point2D.Double pt = new Point2D.Double(x, y + h); |
750 |
//Point2D.Double pt = new Point2D.Double(vp.getExtent().getMin().getX(), vp.getExtent().getMax().getY());
|
751 |
|
752 |
try {
|
753 |
//System.out.println("Dibujando PxRaster: pt0 = "+pt);
|
754 |
vp.mat.transform(pt, pt); |
755 |
|
756 |
//System.out.println("Dibujando PxRaster: pt1 = "+pt);
|
757 |
if ((geoFile != null) && geoFile[0] instanceof GdalFile && |
758 |
(geoFile[0].getDataType() != DataBuffer.TYPE_BYTE)) { |
759 |
//System.out.println("PxRaster: Has dado con un Raster de 16 bits");
|
760 |
RasterBuf raster = ((GdalFile) geoFile[0]).getRaster(wImg,
|
761 |
hImg, rp); |
762 |
t2 = new Date().getTime(); |
763 |
|
764 |
t2 = new Date().getTime(); |
765 |
System.out.println("Dibujando PxRaster: " + |
766 |
((t2 - t1) / 1000D) +
|
767 |
", secs. Filtrando/Renderizando");
|
768 |
t1 = t2; |
769 |
|
770 |
filterStack.setInitRasterBuf(raster); |
771 |
|
772 |
//Si la imagen es de 16 bits lleva un filtro de realce por defecto
|
773 |
if (stackManager == null) { |
774 |
stackManager = new RasterFilterStackManager(filterStack);
|
775 |
stackManager.addEnhancedFilter(false, geoFile[0].getName()); |
776 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
777 |
stackManager.addTailFilter(this.percentFilterInit, 0D, false); |
778 |
} |
779 |
|
780 |
geoImage = renderizeRaster(raster, vp, v); |
781 |
g.drawImage(geoImage, (int)(pt.getX()),
|
782 |
(int)(pt.getY()), component);
|
783 |
|
784 |
t2 = new Date().getTime(); |
785 |
System.out.println("Dibujando PxRaster: " + |
786 |
((t2 - t1) / 1000D) + ", secs. Dibujando"); |
787 |
} else if((geoFile != null) && (geoFile.length > 1) && |
788 |
(!bandSwitch.getBandR().getGeoRasterFile().getName().equals(bandSwitch.getBandG().getGeoRasterFile().getName()) || |
789 |
!bandSwitch.getBandR().getGeoRasterFile().getName().equals(bandSwitch.getBandB().getGeoRasterFile().getName()) || |
790 |
!bandSwitch.getBandG().getGeoRasterFile().getName().equals(bandSwitch.getBandB().getGeoRasterFile().getName())) |
791 |
) { // multiFiles
|
792 |
System.out.println("Dibujando PxRaster (Multifile) ... Bands " + |
793 |
geoFile.length); |
794 |
|
795 |
if (bandSwitch.getBandR().getGeoRasterFile() instanceof EcwFile) { |
796 |
((EcwFile) bandSwitch.getBandR().getGeoRasterFile()).setMultifile(true);
|
797 |
} |
798 |
|
799 |
if (bandSwitch.getBandG().getGeoRasterFile() instanceof EcwFile) { |
800 |
((EcwFile) bandSwitch.getBandG().getGeoRasterFile()).setMultifile(true);
|
801 |
} |
802 |
|
803 |
if (bandSwitch.getBandB().getGeoRasterFile() instanceof EcwFile) { |
804 |
((EcwFile) bandSwitch.getBandB().getGeoRasterFile()).setMultifile(true);
|
805 |
} |
806 |
|
807 |
//TODO:Soluci?n para que no se pinte si hay sharpening. Esto hay que pensarlo mejor
|
808 |
if (stackManager == null) |
809 |
stackManager = new RasterFilterStackManager(filterStack);
|
810 |
if(!filterStack.isActive(stackManager.getTypeFilter("sharpening"))){ |
811 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage(wImg, hImg, rp, null, 0, 0); |
812 |
geoImage = bandSwitch.getBandG().getGeoRasterFile().updateImage(wImg, hImg, rp, geoImage, |
813 |
bandSwitch.getBandG().getBand(), GeoRasterFile.GREEN_BAND); |
814 |
geoImage = bandSwitch.getBandB().getGeoRasterFile().updateImage(wImg, hImg, rp, geoImage, |
815 |
bandSwitch.getBandB().getBand(), GeoRasterFile.BLUE_BAND); |
816 |
}else{
|
817 |
geoImage = new BufferedImage(wImg, hImg, BufferedImage.TYPE_INT_RGB); |
818 |
} |
819 |
|
820 |
filterStack.setInitRasterBuf(geoImage); |
821 |
|
822 |
geoImage = renderizeRaster(geoImage, vp, v); |
823 |
|
824 |
g.drawImage(geoImage, (int)(pt.getX()), (int)(pt.getY()), component); |
825 |
t2 = new Date().getTime(); |
826 |
System.out.println("Dibujando PxRaster: " + |
827 |
((t2 - t1) / 1000D) + ", secs."); |
828 |
} else if ((geoFile != null) ) { // Una solo fichero |
829 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage(wImg, hImg, rp, null, 0, 0); |
830 |
|
831 |
filterStack.setInitRasterBuf(geoImage); |
832 |
|
833 |
geoImage = renderizeRaster(geoImage, vp, v); |
834 |
|
835 |
g.drawImage(geoImage, (int) (pt.getX()), (int) (pt.getY()), component); |
836 |
|
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 (SupersamplingNotSupportedException e) {
|
844 |
System.err.println("Supersampling not supported"); |
845 |
return;
|
846 |
}catch (Exception e) { |
847 |
e.printStackTrace(); |
848 |
} |
849 |
|
850 |
if (pintaMarco) {
|
851 |
drawMarco(g, vp); |
852 |
} |
853 |
} |
854 |
|
855 |
/**
|
856 |
* Aplica la pila de fitros sobre el RasterBuf pasado como par?metro
|
857 |
* y lo devuelve en Image
|
858 |
* @param raster RasterBuf con la imagen sobre la que se aplicaran filtros
|
859 |
* @return Image con la imagen con los filtros puestos
|
860 |
*/
|
861 |
public Image renderizeRaster(RasterBuf raster, ViewPortData vp, Extent e) { |
862 |
if (filterStack != null) { |
863 |
filterStack.setViewPortData(vp); |
864 |
filterStack.setExtent(e); |
865 |
filterStack.execute(raster); |
866 |
} |
867 |
System.out.println("Image renderizeRaster(RasterBuf raster, ViewPortData vp) "); |
868 |
//Aplicamos el filtro para convertir a Image
|
869 |
RasterToImageFilter rti = new RasterToImageFilter();
|
870 |
rti.addParam("raster", raster);
|
871 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
872 |
rti.execute(); |
873 |
raster = null;
|
874 |
|
875 |
return (Image) rti.getResult("raster"); |
876 |
} |
877 |
|
878 |
/**
|
879 |
* Aplica la pila de filtros sobre el Image pasado como par?metro y lo devuelve.
|
880 |
* Si la salida del ?ltimo filtro es un RasterBuf lo convertir? a Image
|
881 |
* @param image Image con la imagen sobre la que se aplicaran filtros
|
882 |
* @return Image con la imagen con los filtros puestos
|
883 |
*/
|
884 |
public Image renderizeRaster(Image image, ViewPortData vp, Extent e) { |
885 |
if (filterStack != null) { |
886 |
filterStack.setViewPortData(vp); |
887 |
filterStack.setExtent(e); |
888 |
filterStack.execute(image); |
889 |
} |
890 |
|
891 |
if (filterStack.getOutDataType() != RasterBuf.TYPE_IMAGE) {
|
892 |
//Aplicamos el filtro para convertir a Image
|
893 |
RasterToImageFilter rti = new RasterToImageFilter();
|
894 |
rti.addParam("raster", (RasterBuf) filterStack.getResult());
|
895 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
896 |
rti.execute(); |
897 |
|
898 |
return (Image) rti.getResult("raster"); |
899 |
} |
900 |
return (Image) filterStack.getResult(); |
901 |
// return image;
|
902 |
} |
903 |
|
904 |
/**
|
905 |
*
|
906 |
* @param g
|
907 |
* @param vp
|
908 |
*/
|
909 |
public void drawMarco(Graphics2D g, ViewPortData vp) { |
910 |
// Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
|
911 |
Color color = new Color(128, 128, 128); |
912 |
|
913 |
// Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
|
914 |
Color fillColor = new Color(255, 220, 220, 0x20); |
915 |
GeneralPath gp = newGP(vp);
|
916 |
g.setColor(fillColor); |
917 |
g.fill(gp); |
918 |
g.setColor(color); |
919 |
g.draw(gp); |
920 |
} |
921 |
|
922 |
private GeneralPath newGP(ViewPortData vp) { |
923 |
//if (gp != null) return;
|
924 |
GeneralPath gp = new GeneralPath(); |
925 |
Point2D.Double pt0 = new Point2D.Double(0.0, 0.0); |
926 |
Point2D.Double pt1 = new Point2D.Double(0.0, 0.0); |
927 |
Point2D.Double pt2 = new Point2D.Double(0.0, 0.0); |
928 |
Point2D.Double pt3 = new Point2D.Double(0.0, 0.0); |
929 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
930 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
931 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
932 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
933 |
|
934 |
// Aspa desde el extent
|
935 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
936 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
937 |
gp.moveTo((float) pt1.getX(), (float) pt1.getY()); |
938 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
939 |
|
940 |
// Extent
|
941 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
942 |
gp.lineTo((float) pt1.getX(), (float) pt1.getY()); |
943 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
944 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
945 |
|
946 |
if (extentOrig != extent) {
|
947 |
gp.lineTo((float) pt0.getX(), (float) pt0.getY()); |
948 |
|
949 |
Vector pts = new Vector(); |
950 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.minY())); |
951 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.minY())); |
952 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.maxY())); |
953 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.maxY())); |
954 |
|
955 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
956 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
957 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
958 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
959 |
gp.moveTo((float) pt0.getX(), (float) pt0.getY()); |
960 |
gp.lineTo((float) pt1.getX(), (float) pt1.getY()); |
961 |
gp.lineTo((float) pt2.getX(), (float) pt2.getY()); |
962 |
gp.lineTo((float) pt3.getX(), (float) pt3.getY()); |
963 |
} |
964 |
|
965 |
gp.closePath(); |
966 |
|
967 |
return gp;
|
968 |
} |
969 |
|
970 |
public IProjection getProjection() {
|
971 |
return proj;
|
972 |
} |
973 |
|
974 |
public void setProjection(IProjection p) { |
975 |
proj = p; |
976 |
} |
977 |
|
978 |
public void reProject(ICoordTrans rp) { |
979 |
this.rp = rp.getInverted();
|
980 |
System.out.println("PxRaster: reProject()"); |
981 |
|
982 |
//geoFile.reProject(rp);
|
983 |
Vector savePts = pts;
|
984 |
|
985 |
pts = new Vector(); |
986 |
extent = new Extent();
|
987 |
|
988 |
Point2D ptDest = null; |
989 |
|
990 |
for (int i = 0; i < savePts.size(); i++) { |
991 |
ptDest = rp.getPDest().createPoint(0.0, 0.0); |
992 |
ptDest = rp.convert((Point2D) savePts.get(i), ptDest);
|
993 |
pts.add(ptDest); |
994 |
extent.add(ptDest); |
995 |
} |
996 |
|
997 |
setProjection(rp.getPDest()); |
998 |
} |
999 |
|
1000 |
/**
|
1001 |
* Obtiene el Stack Manager
|
1002 |
* @return
|
1003 |
*/
|
1004 |
public RasterFilterStackManager getStackManager() {
|
1005 |
return this.stackManager; |
1006 |
} |
1007 |
|
1008 |
/**
|
1009 |
* Asigna el Stack Manager
|
1010 |
* @return
|
1011 |
*/
|
1012 |
public void setStackManager(RasterFilterStackManager sm) { |
1013 |
this.stackManager = sm;
|
1014 |
} |
1015 |
|
1016 |
/**
|
1017 |
* Estructura que representa la relaci?n entre un fichero y la banda que se
|
1018 |
* utiliza de este.
|
1019 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
1020 |
*/
|
1021 |
class FileBands { |
1022 |
GeoRasterFile grf; //Fichero
|
1023 |
int band; //Banda asinada |
1024 |
int filePos; //posici?n del fichero |
1025 |
|
1026 |
/**
|
1027 |
* @return Returns the band.
|
1028 |
*/
|
1029 |
public int getBand() { |
1030 |
return band;
|
1031 |
} |
1032 |
|
1033 |
/**
|
1034 |
* @param band The band to set.
|
1035 |
*/
|
1036 |
public void setBand(int band) { |
1037 |
this.band = band;
|
1038 |
} |
1039 |
|
1040 |
/**
|
1041 |
* @return Returns the band.
|
1042 |
*/
|
1043 |
public int getPos() { |
1044 |
return filePos;
|
1045 |
} |
1046 |
|
1047 |
/**
|
1048 |
* @param band The band to set.
|
1049 |
*/
|
1050 |
public void setPos(int pos) { |
1051 |
this.filePos = pos;
|
1052 |
} |
1053 |
|
1054 |
/**
|
1055 |
* @return Returns the grf.
|
1056 |
*/
|
1057 |
public GeoRasterFile getGeoRasterFile() {
|
1058 |
return grf;
|
1059 |
} |
1060 |
|
1061 |
/**
|
1062 |
* @param grf The grf to set.
|
1063 |
*/
|
1064 |
public void setGeoRasterFile(GeoRasterFile grf) { |
1065 |
this.grf = grf;
|
1066 |
} |
1067 |
} |
1068 |
|
1069 |
/**
|
1070 |
* Clase que lleva la gesti?n entre la relaci?n de ficheros representados
|
1071 |
* por un GeoRasterFile y el n?mero de bandas que contienen. Esto es necesario
|
1072 |
* para la actualizaci?n de la vista ya que para un Image dado podemos tener
|
1073 |
* multiples bandas que pueden ser leidas desde diferentes ficheros.
|
1074 |
*
|
1075 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
1076 |
*/
|
1077 |
class BandSwitch { |
1078 |
private ArrayList geoFiles = new ArrayList(); //Lista de GeoRasterFile con los ficheros raster cargados |
1079 |
private FileBands[] listBands = new FileBands[3]; |
1080 |
private boolean debug = false; |
1081 |
|
1082 |
BandSwitch() { |
1083 |
for (int i = 0; i < listBands.length; i++) |
1084 |
listBands[i] = new FileBands();
|
1085 |
} |
1086 |
|
1087 |
/**
|
1088 |
* A?ade un fichero
|
1089 |
* @param grf
|
1090 |
*/
|
1091 |
public void addFile(GeoRasterFile grf) { |
1092 |
geoFiles.add(grf); |
1093 |
|
1094 |
if (debug) {
|
1095 |
this.show("addFile"); |
1096 |
} |
1097 |
} |
1098 |
|
1099 |
/**
|
1100 |
* Elimina un fichero
|
1101 |
* @param grf
|
1102 |
*/
|
1103 |
public void removeFile(GeoRasterFile grf) { |
1104 |
for (int iFile = 0; iFile < geoFiles.size(); iFile++) { |
1105 |
if (grf.equals(geoFiles.get(iFile))) {
|
1106 |
geoFiles.remove(iFile); |
1107 |
iFile--; |
1108 |
} |
1109 |
} |
1110 |
|
1111 |
if (debug) {
|
1112 |
this.show("removeFile"); |
1113 |
} |
1114 |
} |
1115 |
|
1116 |
/**
|
1117 |
*
|
1118 |
* @param flag
|
1119 |
* @param grf
|
1120 |
* @param nBand
|
1121 |
*/
|
1122 |
public void setBand(int flag, GeoRasterFile grf, int nBand) { |
1123 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) {
|
1124 |
listBands[0].setBand(nBand);
|
1125 |
listBands[0].setGeoRasterFile(grf);
|
1126 |
} else if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) { |
1127 |
listBands[1].setBand(nBand);
|
1128 |
listBands[1].setGeoRasterFile(grf);
|
1129 |
} else if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) { |
1130 |
listBands[2].setBand(nBand);
|
1131 |
listBands[2].setGeoRasterFile(grf);
|
1132 |
} else {
|
1133 |
return;
|
1134 |
} |
1135 |
|
1136 |
grf.setBand(flag, nBand); |
1137 |
} |
1138 |
|
1139 |
/**
|
1140 |
* Asigna las bandas
|
1141 |
* @param flag
|
1142 |
* @param nBand
|
1143 |
*/
|
1144 |
public void setBand(int flag, int nBand) { |
1145 |
int cont = 0; |
1146 |
|
1147 |
for (int iGrf = 0; iGrf < geoFiles.size(); iGrf++) { |
1148 |
for (int iBand = 0; |
1149 |
iBand < ((GeoRasterFile) geoFiles.get(iGrf)).getBandCount(); |
1150 |
iBand++) { |
1151 |
if (((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) &&
|
1152 |
(cont == nBand)) { |
1153 |
listBands[0].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1154 |
listBands[0].setBand(iBand);
|
1155 |
listBands[0].setPos(iGrf);
|
1156 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1157 |
|
1158 |
//System.out.println("==>Asignando banda R FILE="+iGrf+" BANDA="+iBand);
|
1159 |
} else if (((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) && |
1160 |
(cont == nBand)) { |
1161 |
listBands[1].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1162 |
listBands[1].setBand(iBand);
|
1163 |
listBands[1].setPos(iGrf);
|
1164 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1165 |
|
1166 |
//System.out.println("==>Asignando banda G FILE="+iGrf+" BANDA="+iBand);
|
1167 |
} else if (((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) && |
1168 |
(cont == nBand)) { |
1169 |
listBands[2].setGeoRasterFile(((GeoRasterFile) geoFiles.get(iGrf)));
|
1170 |
listBands[2].setBand(iBand);
|
1171 |
listBands[2].setPos(iGrf);
|
1172 |
((GeoRasterFile) geoFiles.get(iGrf)).setBand(flag, iBand); |
1173 |
|
1174 |
//System.out.println("==>Asignando banda B FILE="+iGrf+" BANDA="+iBand);
|
1175 |
} |
1176 |
|
1177 |
cont++; |
1178 |
} |
1179 |
} |
1180 |
|
1181 |
if (debug) {
|
1182 |
this.show("setBand"); |
1183 |
} |
1184 |
} |
1185 |
|
1186 |
/**
|
1187 |
* Obtiene el n?mero de bandas
|
1188 |
* @return
|
1189 |
*/
|
1190 |
public int getBandCount() { |
1191 |
int nbandas = 0; |
1192 |
|
1193 |
for (int iGrf = 0; iGrf < geoFiles.size(); iGrf++) |
1194 |
nbandas += ((GeoRasterFile) geoFiles.get(iGrf)).getBandCount(); |
1195 |
|
1196 |
return nbandas;
|
1197 |
} |
1198 |
|
1199 |
/**
|
1200 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del rojo
|
1201 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1202 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1203 |
*/
|
1204 |
public FileBands getBandR() {
|
1205 |
return listBands[0]; |
1206 |
} |
1207 |
|
1208 |
/**
|
1209 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del verde
|
1210 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1211 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1212 |
*/
|
1213 |
public FileBands getBandG() {
|
1214 |
return listBands[1]; |
1215 |
} |
1216 |
|
1217 |
/**
|
1218 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del azul
|
1219 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
1220 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
1221 |
*/
|
1222 |
public FileBands getBandB() {
|
1223 |
return listBands[2]; |
1224 |
} |
1225 |
|
1226 |
public void show(String op) { |
1227 |
String banda = null; |
1228 |
System.out.println("** " + op + " **"); |
1229 |
|
1230 |
for (int i = 0; i < 3; i++) { |
1231 |
if (i == 0) { |
1232 |
banda = new String("Rojo"); |
1233 |
} else if (i == 1) { |
1234 |
banda = new String("Verde"); |
1235 |
} else if (i == 2) { |
1236 |
banda = new String("Azul"); |
1237 |
} |
1238 |
|
1239 |
System.out.println("** BANDA IMAGE=" + banda + " FILEPOS=" + |
1240 |
listBands[i].getBand() + |
1241 |
" BANDA DEL FICHERO=" +
|
1242 |
listBands[i].getBand()); |
1243 |
} |
1244 |
} |
1245 |
} |
1246 |
/**
|
1247 |
* @return Returns the vName.
|
1248 |
*/
|
1249 |
public String getVName() { |
1250 |
return vName;
|
1251 |
} |
1252 |
/**
|
1253 |
* @param name The vName to set.
|
1254 |
*/
|
1255 |
public void setVName(String name) { |
1256 |
vName = name; |
1257 |
} |
1258 |
} |