root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / px / PxRaster.java @ 2147
History | View | Annotate | Download (28 KB)
1 |
/*
|
---|---|
2 |
* PxRaster.java
|
3 |
*/
|
4 |
package org.cresques.px; |
5 |
|
6 |
import java.awt.Color; |
7 |
import java.awt.Component; |
8 |
import java.awt.Graphics2D; |
9 |
import java.awt.Image; |
10 |
import java.awt.geom.GeneralPath; |
11 |
import java.awt.geom.Point2D; |
12 |
import java.awt.image.DataBuffer; |
13 |
import java.awt.image.ImageObserver; |
14 |
import java.util.ArrayList; |
15 |
import java.util.Date; |
16 |
import java.util.Vector; |
17 |
|
18 |
import org.cresques.cts.ICoordTrans; |
19 |
import org.cresques.cts.IProjection; |
20 |
import org.cresques.geo.Projected; |
21 |
import org.cresques.geo.ViewPortData; |
22 |
import org.cresques.io.GdalFile; |
23 |
import org.cresques.io.GeoRasterFile; |
24 |
import org.cresques.io.raster.RasterBuf; |
25 |
import org.cresques.io.raster.RasterFilterStack; |
26 |
import org.cresques.io.raster.RasterFilterStackManager; |
27 |
import org.cresques.io.raster.RasterStats; |
28 |
import org.cresques.io.raster.RasterToImageFilter; |
29 |
|
30 |
public class PxRaster extends PxObj implements Projected { |
31 |
protected GeoRasterFile[] geoFile = null; |
32 |
protected ImageObserver component = null; |
33 |
Vector pts = null; |
34 |
// Soporte para n bandas, visibles de 3 en 3, en ficheros separados
|
35 |
//protected GeoRasterFile [] colorBand = null;
|
36 |
protected int rBand = 1, gBand = 2, bBand = 3; |
37 |
|
38 |
public RasterStats stats = new RasterStats(); |
39 |
int transparente = 0x10ffff80; |
40 |
|
41 |
String vName = null; |
42 |
protected boolean pintaMarco = false; //true; |
43 |
IProjection proj = null;
|
44 |
protected Extent extentOrig = null; |
45 |
ICoordTrans rp = null;
|
46 |
|
47 |
public RasterFilterStack filterStack = new RasterFilterStack(stats); |
48 |
private BandSwitch bandSwitch = new BandSwitch(); |
49 |
private boolean firstPxRaster = true; |
50 |
private final double percentFilterInit = 0.02; |
51 |
private RasterFilterStackManager stackManager = null; |
52 |
|
53 |
/**
|
54 |
* Estructura que representa la relaci?n entre un fichero y la banda que se
|
55 |
* utiliza de este.
|
56 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
57 |
*/
|
58 |
class FileBands{ |
59 |
GeoRasterFile grf; //Fichero
|
60 |
int band; //Banda asinada |
61 |
int filePos; //posici?n del fichero |
62 |
|
63 |
|
64 |
/**
|
65 |
* @return Returns the band.
|
66 |
*/
|
67 |
public int getBand() { |
68 |
return band;
|
69 |
} |
70 |
/**
|
71 |
* @param band The band to set.
|
72 |
*/
|
73 |
public void setBand(int band) { |
74 |
this.band = band;
|
75 |
} |
76 |
/**
|
77 |
* @return Returns the band.
|
78 |
*/
|
79 |
public int getPos() { |
80 |
return filePos;
|
81 |
} |
82 |
/**
|
83 |
* @param band The band to set.
|
84 |
*/
|
85 |
public void setPos(int pos) { |
86 |
this.filePos = pos;
|
87 |
} |
88 |
/**
|
89 |
* @return Returns the grf.
|
90 |
*/
|
91 |
public GeoRasterFile getGeoRasterFile() {
|
92 |
return grf;
|
93 |
} |
94 |
/**
|
95 |
* @param grf The grf to set.
|
96 |
*/
|
97 |
public void setGeoRasterFile(GeoRasterFile grf) { |
98 |
this.grf = grf;
|
99 |
} |
100 |
} |
101 |
|
102 |
/**
|
103 |
* Clase que lleva la gesti?n entre la relaci?n de ficheros representados
|
104 |
* por un GeoRasterFile y el n?mero de bandas que contienen. Esto es necesario
|
105 |
* para la actualizaci?n de la vista ya que para un Image dado podemos tener
|
106 |
* multiples bandas que pueden ser leidas desde diferentes ficheros.
|
107 |
*
|
108 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
109 |
*/
|
110 |
class BandSwitch{ |
111 |
private ArrayList geoFiles = new ArrayList(); //Lista de GeoRasterFile con los ficheros raster cargados |
112 |
private FileBands[] listBands = new FileBands[3]; |
113 |
private boolean debug = false; |
114 |
|
115 |
BandSwitch(){ |
116 |
for(int i=0;i<listBands.length;i++) |
117 |
listBands[i] = new FileBands();
|
118 |
} |
119 |
|
120 |
/**
|
121 |
* A?ade un fichero
|
122 |
* @param grf
|
123 |
*/
|
124 |
public void addFile(GeoRasterFile grf){ |
125 |
geoFiles.add(grf); |
126 |
if(debug)
|
127 |
this.show("addFile"); |
128 |
} |
129 |
|
130 |
/**
|
131 |
* Elimina un fichero
|
132 |
* @param grf
|
133 |
*/
|
134 |
public void removeFile(GeoRasterFile grf){ |
135 |
for(int iFile=0;iFile<geoFiles.size();iFile++){ |
136 |
if(grf.equals(geoFiles.get(iFile))){
|
137 |
geoFiles.remove(iFile); |
138 |
iFile--; |
139 |
} |
140 |
} |
141 |
|
142 |
if(debug)
|
143 |
this.show("removeFile"); |
144 |
} |
145 |
|
146 |
/**
|
147 |
*
|
148 |
* @param flag
|
149 |
* @param grf
|
150 |
* @param nBand
|
151 |
*/
|
152 |
public void setBand(int flag, GeoRasterFile grf, int nBand){ |
153 |
if ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND){
|
154 |
listBands[0].setBand(nBand);
|
155 |
listBands[0].setGeoRasterFile(grf);
|
156 |
}else if ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND){ |
157 |
listBands[1].setBand(nBand);
|
158 |
listBands[1].setGeoRasterFile(grf);
|
159 |
}else if ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND){ |
160 |
listBands[2].setBand(nBand);
|
161 |
listBands[2].setGeoRasterFile(grf);
|
162 |
}else
|
163 |
return;
|
164 |
grf.setBand(flag, nBand); |
165 |
} |
166 |
|
167 |
/**
|
168 |
* Asigna las bandas
|
169 |
* @param flag
|
170 |
* @param nBand
|
171 |
*/
|
172 |
public void setBand(int flag, int nBand){ |
173 |
int cont = 0; |
174 |
for(int iGrf=0;iGrf<geoFiles.size();iGrf++){ |
175 |
for(int iBand=0;iBand<((GeoRasterFile)geoFiles.get(iGrf)).getBandCount();iBand++){ |
176 |
if ( ((flag & GeoRasterFile.RED_BAND) == GeoRasterFile.RED_BAND) &&
|
177 |
cont == nBand){ |
178 |
listBands[0].setGeoRasterFile(((GeoRasterFile)geoFiles.get(iGrf)));
|
179 |
listBands[0].setBand(iBand);
|
180 |
listBands[0].setPos(iGrf);
|
181 |
((GeoRasterFile)geoFiles.get(iGrf)).setBand(flag, iBand); |
182 |
//System.out.println("==>Asignando banda R FILE="+iGrf+" BANDA="+iBand);
|
183 |
}else if ( ((flag & GeoRasterFile.GREEN_BAND) == GeoRasterFile.GREEN_BAND) && |
184 |
cont == nBand){ |
185 |
listBands[1].setGeoRasterFile(((GeoRasterFile)geoFiles.get(iGrf)));
|
186 |
listBands[1].setBand(iBand);
|
187 |
listBands[1].setPos(iGrf);
|
188 |
((GeoRasterFile)geoFiles.get(iGrf)).setBand(flag, iBand); |
189 |
//System.out.println("==>Asignando banda G FILE="+iGrf+" BANDA="+iBand);
|
190 |
}else if ( ((flag & GeoRasterFile.BLUE_BAND) == GeoRasterFile.BLUE_BAND) && |
191 |
cont == nBand){ |
192 |
listBands[2].setGeoRasterFile(((GeoRasterFile)geoFiles.get(iGrf)));
|
193 |
listBands[2].setBand(iBand);
|
194 |
listBands[2].setPos(iGrf);
|
195 |
((GeoRasterFile)geoFiles.get(iGrf)).setBand(flag, iBand); |
196 |
//System.out.println("==>Asignando banda B FILE="+iGrf+" BANDA="+iBand);
|
197 |
} |
198 |
cont++; |
199 |
} |
200 |
} |
201 |
if(debug)
|
202 |
this.show("setBand"); |
203 |
} |
204 |
|
205 |
/**
|
206 |
* Obtiene el n?mero de bandas
|
207 |
* @return
|
208 |
*/
|
209 |
public int getBandCount(){ |
210 |
int nbandas = 0; |
211 |
for(int iGrf=0;iGrf<geoFiles.size();iGrf++) |
212 |
nbandas += ((GeoRasterFile)geoFiles.get(iGrf)).getBandCount(); |
213 |
return nbandas;
|
214 |
} |
215 |
|
216 |
/**
|
217 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del rojo
|
218 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
219 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
220 |
*/
|
221 |
public FileBands getBandR(){
|
222 |
return listBands[0]; |
223 |
} |
224 |
|
225 |
/**
|
226 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del verde
|
227 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
228 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
229 |
*/
|
230 |
public FileBands getBandG(){
|
231 |
return listBands[1]; |
232 |
} |
233 |
|
234 |
/**
|
235 |
* Obtiene el GeoRasterFile que hay que leer para cargar la banda del azul
|
236 |
* y la banda de este fichero que se utiliza para esta asignaci?n.
|
237 |
* @return Estructura FileBand con la relaci?n fichero-banda
|
238 |
*/
|
239 |
public FileBands getBandB(){
|
240 |
return listBands[2]; |
241 |
} |
242 |
|
243 |
public void show(String op){ |
244 |
String banda = null; |
245 |
System.out.println("** "+op+" **"); |
246 |
for(int i=0;i<3;i++){ |
247 |
if(i==0) |
248 |
banda = new String("Rojo"); |
249 |
else if(i==1) |
250 |
banda = new String("Verde"); |
251 |
else if(i==2) |
252 |
banda = new String("Azul"); |
253 |
|
254 |
System.out.println("** BANDA IMAGE="+banda+" FILEPOS="+listBands[i].getBand()+" BANDA DEL FICHERO="+listBands[i].getBand()); |
255 |
} |
256 |
} |
257 |
} |
258 |
|
259 |
/*public boolean transparencyFilterEnabled = false;
|
260 |
public boolean enhancedFilterEnabled = false;
|
261 |
public boolean tailFilterEnabled = false;*/
|
262 |
|
263 |
/**
|
264 |
* Constructor.
|
265 |
* @param component
|
266 |
*/
|
267 |
public PxRaster(ImageObserver component) { |
268 |
this.component = component;
|
269 |
} |
270 |
|
271 |
/**
|
272 |
* Contructor para un solo fichero
|
273 |
* @param proj Proyeccci?n
|
274 |
* @param fname Nombre del fichero
|
275 |
* @param component
|
276 |
*/
|
277 |
public PxRaster(IProjection proj, String fname, ImageObserver component) { |
278 |
geoFile = new GeoRasterFile[1]; |
279 |
geoFile[0] = GeoRasterFile.openFile(proj, fname);//loadECW(fname); |
280 |
geoFile[0].setUpdatable((Component) component); |
281 |
this.proj = proj;
|
282 |
this.component = component;
|
283 |
setExtent(geoFile[0].getExtent());
|
284 |
geoFile[0].setView(geoFile[0].getExtent()); |
285 |
extentOrig = extent; |
286 |
bandSwitch.addFile(geoFile[0]);
|
287 |
if (geoFile[0].getBandCount()>=3) { |
288 |
setBand(GeoRasterFile.RED_BAND, 0);
|
289 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
290 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
291 |
} else if (geoFile[0].getBandCount()==2) { |
292 |
setBand(GeoRasterFile.RED_BAND, 0);
|
293 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
294 |
setBand(GeoRasterFile.BLUE_BAND, 1);
|
295 |
} else if (geoFile[0].getBandCount()==1) { |
296 |
//setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
297 |
setBand(GeoRasterFile.RED_BAND, 0);
|
298 |
setBand(GeoRasterFile.GREEN_BAND, 0);
|
299 |
setBand(GeoRasterFile.BLUE_BAND, 0);
|
300 |
} |
301 |
} |
302 |
|
303 |
/**
|
304 |
* Constructor para multiples ficheros
|
305 |
*/
|
306 |
public PxRaster(IProjection proj, String [] fnames, ImageObserver component) { |
307 |
this.proj = proj;
|
308 |
this.component = component;
|
309 |
geoFile = new GeoRasterFile[fnames.length];
|
310 |
for (int i=0; i<geoFile.length; i++) { |
311 |
geoFile[i] = GeoRasterFile.openFile(proj, fnames[i]);//loadECW(fname);
|
312 |
geoFile[i].setUpdatable((Component) component);
|
313 |
setExtent(geoFile[i].getExtent()); |
314 |
geoFile[i].setView(geoFile[i].getExtent()); |
315 |
bandSwitch.addFile(geoFile[i]); |
316 |
} |
317 |
//geoFile = geoFile[0];
|
318 |
extentOrig = extent; |
319 |
if (fnames.length >= 3 || geoFile[0].getBandCount()>2) { |
320 |
setBand(GeoRasterFile.RED_BAND, 0);
|
321 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
322 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
323 |
} else {
|
324 |
setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
325 |
} |
326 |
} |
327 |
|
328 |
/**
|
329 |
* A?ade un GeoRasterFile al PxRaster
|
330 |
* @param fileName Nombre del fichero
|
331 |
*/
|
332 |
public void addFile(String fileName){ |
333 |
if(geoFile!=null){ |
334 |
GeoRasterFile[] listFiles = new GeoRasterFile[geoFile.length+1]; |
335 |
for(int i=0;i<geoFile.length;i++) |
336 |
listFiles[i] = geoFile[i]; |
337 |
listFiles[geoFile.length] = GeoRasterFile.openFile(proj, fileName); |
338 |
listFiles[geoFile.length].setUpdatable((Component) component);
|
339 |
setExtent(listFiles[geoFile.length].getExtent()); |
340 |
listFiles[geoFile.length].setView(listFiles[geoFile.length].getExtent()); |
341 |
bandSwitch.addFile(listFiles[geoFile.length]); |
342 |
geoFile = listFiles; |
343 |
}else {
|
344 |
System.err.println("PxRaster.addFile(): Imagen no cargada."); |
345 |
return;
|
346 |
} |
347 |
} |
348 |
|
349 |
/**
|
350 |
* Devuelve el Extent de un fichero son necesidad de a?adirlo
|
351 |
* al PxRaster
|
352 |
* @param fileName
|
353 |
* @return
|
354 |
*/
|
355 |
public Extent testExtentFile(String fileName){ |
356 |
GeoRasterFile grf = GeoRasterFile.openFile(proj, fileName); |
357 |
return grf.getExtent();
|
358 |
} |
359 |
|
360 |
/**
|
361 |
* Elimina un GeoRasterFile al PxRaster
|
362 |
* @param finaName Nombre del fichero
|
363 |
*/
|
364 |
public void delFile(String fileName){ |
365 |
if(geoFile!=null){ |
366 |
Vector grfTemp = new Vector(); |
367 |
for(int i=0;i<geoFile.length;i++){ |
368 |
if(!fileName.endsWith(geoFile[i].getName()))
|
369 |
grfTemp.add(geoFile[i]); |
370 |
} |
371 |
GeoRasterFile[] listFiles = new GeoRasterFile[grfTemp.size()]; |
372 |
for(int i=0;i<listFiles.length;i++) |
373 |
listFiles[i] = (GeoRasterFile)grfTemp.get(i); |
374 |
|
375 |
//Lo eliminamos del bandSwitch
|
376 |
|
377 |
for(int i=0;i<geoFile.length;i++){ |
378 |
if(fileName.endsWith(geoFile[i].getName())){
|
379 |
bandSwitch.removeFile(geoFile[i]); |
380 |
} |
381 |
} |
382 |
|
383 |
geoFile = listFiles; |
384 |
/*if(geoFile!=null)
|
385 |
setExtent(geoFile[0].getExtent());*/
|
386 |
|
387 |
}else {
|
388 |
System.err.println("PxRaster.addFile(): Imagen no cargada."); |
389 |
return;
|
390 |
} |
391 |
} |
392 |
|
393 |
public PxRaster(GeoRasterFile eFile, ImageObserver component, Extent view) { |
394 |
geoFile = new GeoRasterFile[1]; |
395 |
geoFile[0] = eFile;//loadECW(fname); |
396 |
geoFile[0].setUpdatable((Component) component); |
397 |
setProjection(geoFile[0].getProjection());
|
398 |
this.component = component;
|
399 |
|
400 |
setExtent(geoFile[0].getExtent());
|
401 |
geoFile[0].setView(view); //geoFile.getExtent()); |
402 |
extentOrig = extent; |
403 |
bandSwitch.addFile(eFile); |
404 |
if (geoFile[0].getBandCount()>=3) { |
405 |
setBand(GeoRasterFile.RED_BAND, 0);
|
406 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
407 |
setBand(GeoRasterFile.BLUE_BAND, 2);
|
408 |
} else if (geoFile[0].getBandCount()==2) { |
409 |
setBand(GeoRasterFile.RED_BAND, 0);
|
410 |
setBand(GeoRasterFile.GREEN_BAND, 1);
|
411 |
setBand(GeoRasterFile.BLUE_BAND, 1);
|
412 |
} else if (geoFile[0].getBandCount()==1) { |
413 |
//setBand(GeoRasterFile.RED_BAND|GeoRasterFile.GREEN_BAND|GeoRasterFile.BLUE_BAND, 0);
|
414 |
setBand(GeoRasterFile.RED_BAND, 0);
|
415 |
setBand(GeoRasterFile.GREEN_BAND, 0);
|
416 |
setBand(GeoRasterFile.BLUE_BAND, 0);
|
417 |
} |
418 |
} |
419 |
|
420 |
/**
|
421 |
* Obtiene el tama?o de bloque
|
422 |
* @return
|
423 |
*/
|
424 |
public int getBlockSize(){ |
425 |
return geoFile[0].getBlockSize(); |
426 |
} |
427 |
|
428 |
/**
|
429 |
*
|
430 |
* @return
|
431 |
*/
|
432 |
public GeoRasterFile[] getGeoFiles(){ |
433 |
return geoFile;
|
434 |
} |
435 |
|
436 |
public GeoRasterFile getGeoFile(){
|
437 |
return geoFile[0]; |
438 |
} |
439 |
|
440 |
/**
|
441 |
* Obtiene el n?mero de bandas del PxRaster. Si ls longitud de geoFile es 1 quiere
|
442 |
* decir que hay un solo fichero que contiene todas las bandas. Si hay m?s de un geoFile
|
443 |
* el n?mero de bandas ser? la suma de todas las bandas de las im?genes que forman
|
444 |
* el geoFile
|
445 |
* @return N?mero de bandas
|
446 |
*/
|
447 |
public int getBandCount() { |
448 |
return bandSwitch.getBandCount();
|
449 |
} |
450 |
|
451 |
/**
|
452 |
* Obtiene el tipo de dato del primer GeoRasterFile
|
453 |
* @return
|
454 |
*/
|
455 |
public int getDataType(){ |
456 |
if(geoFile!=null){ |
457 |
return geoFile[0].getDataType(); |
458 |
}else
|
459 |
System.err.println("PxRaster.getDataType(): Imagen no cargada."); |
460 |
return 0; |
461 |
} |
462 |
/**
|
463 |
* Obtiene el vector de GeoRasterFile que componen el PxRaster
|
464 |
* @return vector GeoRasterFile
|
465 |
*/
|
466 |
public GeoRasterFile [] getFiles() { |
467 |
return geoFile;
|
468 |
} |
469 |
|
470 |
/**
|
471 |
* Asocia un colorBand al rojo, verde o azul.
|
472 |
* @param flag cual (o cuales) de las bandas.
|
473 |
* @param nBand que colorBand
|
474 |
*/
|
475 |
public void setBand(int flag, int nBand) { |
476 |
bandSwitch.setBand(flag, nBand); |
477 |
} |
478 |
|
479 |
/**
|
480 |
* Obtiene la posici?n del fichero asignado a la banda
|
481 |
* que se le pasa por par?metro
|
482 |
* @return
|
483 |
*/
|
484 |
public int getPosFile(int flag){ |
485 |
if (flag == GeoRasterFile.RED_BAND){
|
486 |
return bandSwitch.getBandR().getPos();
|
487 |
}else if (flag == GeoRasterFile.GREEN_BAND){ |
488 |
return bandSwitch.getBandG().getPos();
|
489 |
}else if (flag == GeoRasterFile.BLUE_BAND){ |
490 |
return bandSwitch.getBandB().getPos();
|
491 |
}else
|
492 |
return -1; |
493 |
} |
494 |
|
495 |
/**
|
496 |
* Devuelve el colorBand activo en la banda especificada.
|
497 |
* @param flag banda.
|
498 |
*/
|
499 |
public int getBand(int flag) { |
500 |
if (flag == GeoRasterFile.RED_BAND){
|
501 |
return bandSwitch.getBandR().getBand();
|
502 |
}else if (flag == GeoRasterFile.GREEN_BAND){ |
503 |
return bandSwitch.getBandG().getBand();
|
504 |
}else if (flag == GeoRasterFile.BLUE_BAND){ |
505 |
return bandSwitch.getBandB().getBand();
|
506 |
}else
|
507 |
return -1; |
508 |
} |
509 |
|
510 |
/**
|
511 |
* @param pm
|
512 |
*/
|
513 |
public void setDrawBorder(boolean pm) { |
514 |
pintaMarco = pm; |
515 |
} |
516 |
|
517 |
/**
|
518 |
* Obtiene el nombre del fichero si solo hay uno
|
519 |
* @return Nombre del fichero
|
520 |
*/
|
521 |
public String getFName() { |
522 |
return geoFile[0].getName(); |
523 |
} |
524 |
|
525 |
/**
|
526 |
* Obtiene el nombre del fichero GeoRasterFile seleccionado
|
527 |
* @param i posici?n del GeoRasterFile
|
528 |
* @return Nombre del fichero
|
529 |
*/
|
530 |
public String getFName(int i){ |
531 |
if(geoFile!=null){ |
532 |
if(i<geoFile.length)
|
533 |
return geoFile[i].getName();
|
534 |
else
|
535 |
return null; |
536 |
}else {
|
537 |
System.err.println("PxRaster.getFName(): Imagen no cargada."); |
538 |
return null; |
539 |
} |
540 |
} |
541 |
|
542 |
/**
|
543 |
* Obtiene una lista de Strings con los nombres de todos los ficheros
|
544 |
* que tiene el PxRaster
|
545 |
* @return Lista de nombres
|
546 |
*/
|
547 |
public String[] getLisName(){ |
548 |
if(geoFile!=null){ |
549 |
String[] list = new String[geoFile.length]; |
550 |
for(int i=0;i<geoFile.length;i++) |
551 |
list[i] = geoFile[i].getName(); |
552 |
return list;
|
553 |
}else {
|
554 |
System.err.println("PxRaster.getListName(): Imagen no cargada."); |
555 |
return null; |
556 |
} |
557 |
} |
558 |
|
559 |
/**
|
560 |
* Devuelve la anchura total del fichero, en pixeles.
|
561 |
* @return ancho en pixeles
|
562 |
*/
|
563 |
public int getFWidth() { |
564 |
if(geoFile!=null) |
565 |
return geoFile[0].getWidth(); |
566 |
else {
|
567 |
System.err.println("PxRaster.getFWidth(): Imagen no cargada."); |
568 |
return 0; |
569 |
} |
570 |
} |
571 |
|
572 |
|
573 |
/**
|
574 |
* Devuelve la anchura total del fichero, en pixeles.
|
575 |
* @return ancho en pixeles
|
576 |
*/
|
577 |
public int getFWidth(int i) { |
578 |
if(i<geoFile.length)
|
579 |
return geoFile[i].getWidth();
|
580 |
else {
|
581 |
System.err.println("PxRaster.getFWidth(): Imagen no cargada."); |
582 |
return 0; |
583 |
} |
584 |
} |
585 |
|
586 |
/**
|
587 |
* Devuelve la altura total del fichero, en pixeles.
|
588 |
* @return alto en pixeles
|
589 |
*/
|
590 |
public int getFHeight() { |
591 |
if(geoFile!=null) |
592 |
return geoFile[0].getHeight(); |
593 |
else {
|
594 |
System.err.println("PxRaster.getFHeight(): Imagen no cargada."); |
595 |
return 0; |
596 |
} |
597 |
} |
598 |
|
599 |
/**
|
600 |
* Devuelve la altura total del fichero, en pixeles.
|
601 |
* @return alto en pixeles
|
602 |
*/
|
603 |
public int getFHeight(int i) { |
604 |
if(i<geoFile.length)
|
605 |
return geoFile[i].getHeight();
|
606 |
else {
|
607 |
System.err.println("PxRaster.getFHeight(): Imagen no cargada."); |
608 |
return 0; |
609 |
} |
610 |
} |
611 |
|
612 |
/**
|
613 |
* Devuelve el n?mero de ficheros que componen el PxRaster
|
614 |
* @return N?mero de ficheros
|
615 |
*/
|
616 |
public int nFiles(){ |
617 |
if(geoFile!=null) |
618 |
return geoFile.length;
|
619 |
else
|
620 |
return 0; |
621 |
} |
622 |
|
623 |
/**
|
624 |
* Activa o desactiva la transparencia de los ficheros que forman el PxRaster
|
625 |
* @param t true o false para activar o desactivar transparencia
|
626 |
*/
|
627 |
public void setTransparency(boolean t) { |
628 |
if(geoFile!=null){ |
629 |
for(int i=0;i<geoFile.length;i++){ |
630 |
geoFile[i].setTransparency(t); |
631 |
} |
632 |
}else {
|
633 |
System.err.println("PxRaster.setTransparency(): Imagen no cargada."); |
634 |
return;
|
635 |
} |
636 |
} |
637 |
|
638 |
/**
|
639 |
* Pone la transparencia de los ficheros de la imagen a un valor
|
640 |
* @param t Valor para la transparencia
|
641 |
*/
|
642 |
public void setTransparency(int t) { |
643 |
if(geoFile!=null){ |
644 |
for(int i=0;i<geoFile.length;i++){ |
645 |
geoFile[i].setTransparency(t); |
646 |
} |
647 |
}else {
|
648 |
System.err.println("PxRaster.setTransparency(): Imagen no cargada."); |
649 |
return;
|
650 |
} |
651 |
} |
652 |
|
653 |
/**
|
654 |
* Obtiene el alpha del primer fichero. Han de ser iguales en todos
|
655 |
* los ficheros de la imagen.
|
656 |
* @return alpha
|
657 |
*/
|
658 |
public int getAlpha() { |
659 |
if(geoFile!=null) |
660 |
return geoFile[0].getAlpha(); |
661 |
else {
|
662 |
System.err.println("PxRaster.getAlpha(): Imagen no cargada."); |
663 |
return 0; |
664 |
} |
665 |
} |
666 |
|
667 |
/**
|
668 |
* Asigna el extent
|
669 |
* @param e extent
|
670 |
*/
|
671 |
public void setExtent(Extent e) { |
672 |
super.extent = e;
|
673 |
pts = new Vector(); |
674 |
pts.add(proj.createPoint(e.minX(), e.minY())); |
675 |
pts.add(proj.createPoint(e.maxX(), e.minY())); |
676 |
pts.add(proj.createPoint(e.maxX(), e.maxY())); |
677 |
pts.add(proj.createPoint(e.minX(), e.maxY())); |
678 |
} |
679 |
|
680 |
/**
|
681 |
* Cambia la vista (viewport) sobre el raster.
|
682 |
*
|
683 |
* @param v extent
|
684 |
* @param vName nombre
|
685 |
*/
|
686 |
public void setView(Extent v, String vName) { |
687 |
if(geoFile!=null){ |
688 |
for(int i=0;i<geoFile.length;i++){ |
689 |
geoFile[i].setView(v); |
690 |
} |
691 |
}else {
|
692 |
System.err.println("PxRaster.setView(): Imagen no cargada."); |
693 |
return;
|
694 |
} |
695 |
this.vName = vName;
|
696 |
} |
697 |
|
698 |
/**
|
699 |
* Obtiene la escala.
|
700 |
*
|
701 |
* @param width
|
702 |
* @param height
|
703 |
* @return
|
704 |
*/
|
705 |
|
706 |
public double[] getScale(int width, int height) { |
707 |
double scale[] = new double[2]; |
708 |
if(geoFile!=null){ |
709 |
scale[0] = ((double) width) /geoFile[0].getView().width(); |
710 |
scale[1] = ((double) height)/geoFile[0].getView().height(); |
711 |
return scale;
|
712 |
}else {
|
713 |
System.err.println("PxRaster.getScale(): Imagen no cargada."); |
714 |
return null; |
715 |
} |
716 |
} |
717 |
|
718 |
/**
|
719 |
* 'Normaliza' la vista en funci?n del extent del raster.
|
720 |
*
|
721 |
* @param mat
|
722 |
* @param sz
|
723 |
*/
|
724 |
|
725 |
protected void calculateNewView(Extent sz) { |
726 |
double vx = sz.minX(), vy = sz.minY(), vx2 = sz.maxX(), vy2 = sz.maxY();
|
727 |
if (sz.minX() < extent.minX()) vx = extent.minX();
|
728 |
if (sz.minY() < extent.minY()) vy = extent.minY();
|
729 |
if (sz.maxX() > extent.maxX()) vx2 = extent.maxX();
|
730 |
if (sz.maxY() > extent.maxY()) vy2 = extent.maxY();
|
731 |
if (geoFile != null) { |
732 |
for (int i=0; i<geoFile.length; i++) |
733 |
geoFile[i].setView(new Extent(vx, vy, vx2, vy2));
|
734 |
} else {
|
735 |
System.err.println("PxRaster.calculateNewView(): Imagen no cargada."); |
736 |
} |
737 |
} |
738 |
|
739 |
/**
|
740 |
* Dibuja el raster
|
741 |
*/
|
742 |
|
743 |
public void draw(Graphics2D g, ViewPortData vp) { |
744 |
Image geoImage = null; |
745 |
long t2, t1 = new Date().getTime(); |
746 |
//System.out.println("PxRaster.draw(): vp.extent = "+ vp.getExtent());
|
747 |
//System.out.println("PxRaster.draw(): extent = "+ getExtent());
|
748 |
if (vp.getExtent().minX()> extent.maxX()) return; |
749 |
if (vp.getExtent().minY()> extent.maxY()) return; |
750 |
if (vp.getExtent().maxX()< extent.minX()) return; |
751 |
if (vp.getExtent().maxY()< extent.minY()) return; |
752 |
calculateNewView(vp.getExtent()); |
753 |
Extent v = geoFile[0].getView();
|
754 |
double x = v.minX();
|
755 |
double y = v.minY();
|
756 |
double w = v.width();
|
757 |
double h = v.height();
|
758 |
//System.out.println("Pinto PxRaster:" + v);
|
759 |
|
760 |
double scalex = vp.mat.getScaleX() /* g.getTransform().getScaleX()*/ , |
761 |
scaley = vp.mat.getScaleY() /* g.getTransform().getScaleY() */;
|
762 |
int wImg = (int) Math.abs(w*scalex)+1, hImg = (int) Math.abs(h*scaley)+1; |
763 |
//System.out.println("Sz=("+wImg+","+hImg+"); scale=("+scalex+","+scaley+")");
|
764 |
if (wImg <= 0 || hImg <= 0) return; |
765 |
|
766 |
Point2D.Double pt = new Point2D.Double(x, y+h); |
767 |
try {
|
768 |
//System.out.println("Dibujando PxRaster: pt0 = "+pt);
|
769 |
vp.mat.transform(pt, pt); |
770 |
//System.out.println("Dibujando PxRaster: pt1 = "+pt);
|
771 |
if (geoFile != null && geoFile[0] instanceof GdalFile && |
772 |
(geoFile[0].getDataType() != DataBuffer.TYPE_BYTE)) { |
773 |
System.out.println("PxRaster: Has dado con un Raster de 16 bits"); |
774 |
//System.out.println("Dibujando PxRaster sz=("+wImg+","+hImg+"...");
|
775 |
RasterBuf raster = ((GdalFile) geoFile[0]).getRaster(wImg, hImg, rp);
|
776 |
t2 = new Date().getTime(); |
777 |
//System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Obteniendo"); t1 = t2;
|
778 |
//geoImage = renderizeRaster(raster);
|
779 |
t2 = new Date().getTime(); |
780 |
System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Filtrando/Renderizando");t1 = t2; |
781 |
|
782 |
//filterStack.setDataTypeInFilter(RasterBuf.TYPE_SHORT);
|
783 |
filterStack.setInitRasterBuf(raster); |
784 |
|
785 |
//Si la imagen es de 16 bits lleva un filtro de realce por defecto
|
786 |
if(stackManager == null){ |
787 |
stackManager = new RasterFilterStackManager(filterStack);
|
788 |
stackManager.addEnhancedFilter(false);
|
789 |
stackManager.removeFilter(stackManager.getTypeFilter("computeminmax"));
|
790 |
stackManager.addTailFilter( this.percentFilterInit, 0D, false); |
791 |
} |
792 |
//geoImage = renderizeRaster(geoImage);
|
793 |
geoImage = renderizeRaster(raster); |
794 |
g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), component); |
795 |
|
796 |
t2 = new Date().getTime(); |
797 |
System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs. Dibujando"); |
798 |
} else if (geoFile != null && geoFile.length > 1) { // multiFiles |
799 |
System.out.println("Dibujando PxRaster (Multifile) ... Bands "+geoFile.length); |
800 |
|
801 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage |
802 |
(wImg, hImg, rp, null, 0, 0); |
803 |
geoImage = bandSwitch.getBandG().getGeoRasterFile().updateImage |
804 |
(wImg, hImg, rp, geoImage, bandSwitch.getBandG().getBand(), GeoRasterFile.GREEN_BAND); |
805 |
geoImage = bandSwitch.getBandB().getGeoRasterFile().updateImage |
806 |
(wImg, hImg, rp, geoImage, bandSwitch.getBandB().getBand(), GeoRasterFile.BLUE_BAND); |
807 |
|
808 |
filterStack.setInitRasterBuf(geoImage); |
809 |
|
810 |
geoImage = renderizeRaster(geoImage); |
811 |
g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), component); |
812 |
t2 = new Date().getTime(); |
813 |
System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs."); |
814 |
|
815 |
} else if (geoFile != null && geoFile.length == 1) { // Una solo fichero |
816 |
|
817 |
geoImage = bandSwitch.getBandR().getGeoRasterFile().updateImage |
818 |
(wImg, hImg, rp, null, 0, 0); |
819 |
//System.out.println("Dibujando PxRaster sz=("+wImg+","+hImg+"...");
|
820 |
|
821 |
filterStack.setInitRasterBuf(geoImage); |
822 |
|
823 |
geoImage = renderizeRaster(geoImage); |
824 |
g.drawImage(geoImage, (int) Math.round(pt.getX()), (int) Math.round(pt.getY()), component); |
825 |
t2 = new Date().getTime(); |
826 |
System.out.println("Dibujando PxRaster: "+(t2-t1)/1000D+", secs."); |
827 |
} else { // no cargada |
828 |
System.err.println("Dibujando PxRaster: Foto no cargada."); |
829 |
} |
830 |
} catch (Exception e) { |
831 |
e.printStackTrace(); |
832 |
}; |
833 |
|
834 |
if (pintaMarco) {
|
835 |
drawMarco(g, vp); |
836 |
} |
837 |
} |
838 |
|
839 |
/**
|
840 |
* Aplica la pila de fitros sobre el RasterBuf pasado como par?metro
|
841 |
* y lo devuelve en Image
|
842 |
* @param raster RasterBuf con la imagen sobre la que se aplicaran filtros
|
843 |
* @return Image con la imagen con los filtros puestos
|
844 |
*/
|
845 |
public Image renderizeRaster(RasterBuf raster) { |
846 |
if (filterStack != null){ |
847 |
filterStack.execute(raster); |
848 |
} |
849 |
|
850 |
//Aplicamos el filtro para convertir a Image
|
851 |
RasterToImageFilter rti = new RasterToImageFilter();
|
852 |
rti.addParam("raster", raster);
|
853 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
854 |
rti.execute(); |
855 |
raster = null;
|
856 |
return (Image)rti.getResult("raster"); |
857 |
} |
858 |
|
859 |
/**
|
860 |
* Aplica la pila de filtros sobre el Image pasado como par?metro y lo devuelve.
|
861 |
* Si la salida del ?ltimo filtro es un RasterBuf lo convertir? a Image
|
862 |
* @param image Image con la imagen sobre la que se aplicaran filtros
|
863 |
* @return Image con la imagen con los filtros puestos
|
864 |
*/
|
865 |
public Image renderizeRaster(Image image) { |
866 |
if (filterStack != null){ |
867 |
filterStack.execute(image); |
868 |
} |
869 |
|
870 |
if(filterStack.getOutDataType() != RasterBuf.TYPE_IMAGE){
|
871 |
//Aplicamos el filtro para convertir a Image
|
872 |
RasterToImageFilter rti = new RasterToImageFilter();
|
873 |
rti.addParam("raster", (RasterBuf)filterStack.getResult());
|
874 |
rti.addParam("alpha", new Integer(this.getAlpha())); |
875 |
rti.execute(); |
876 |
return (Image)rti.getResult("raster"); |
877 |
} |
878 |
return image;
|
879 |
} |
880 |
|
881 |
/**
|
882 |
*
|
883 |
* @param g
|
884 |
* @param vp
|
885 |
*/
|
886 |
public void drawMarco(Graphics2D g, ViewPortData vp) { |
887 |
// Color color = new Color(255,222,165,128), fillColor = new Color(255,214,132,128);
|
888 |
Color color = new Color(128,128,128), fillColor = new Color(255,220,220,0x20); |
889 |
GeneralPath gp = newGP(vp);
|
890 |
g.setColor(fillColor); |
891 |
g.fill(gp); |
892 |
g.setColor(color); |
893 |
g.draw(gp); |
894 |
} |
895 |
|
896 |
private GeneralPath newGP(ViewPortData vp) { |
897 |
//if (gp != null) return;
|
898 |
GeneralPath gp = new GeneralPath(); |
899 |
Point2D.Double pt0 = new Point2D.Double(0.0, 0.0); |
900 |
Point2D.Double pt1 = new Point2D.Double(0.0, 0.0); |
901 |
Point2D.Double pt2 = new Point2D.Double(0.0, 0.0); |
902 |
Point2D.Double pt3 = new Point2D.Double(0.0, 0.0); |
903 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
904 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
905 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
906 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
907 |
// Aspa desde el extent
|
908 |
gp.moveTo( (float) pt0.getX(), (float) pt0.getY() ); |
909 |
gp.lineTo( (float) pt2.getX(), (float) pt2.getY() ); |
910 |
gp.moveTo( (float) pt1.getX(), (float) pt1.getY() ); |
911 |
gp.lineTo( (float) pt3.getX(), (float) pt3.getY() ); |
912 |
// Extent
|
913 |
gp.moveTo( (float) pt0.getX(), (float) pt0.getY() ); |
914 |
gp.lineTo( (float) pt1.getX(), (float) pt1.getY() ); |
915 |
gp.lineTo( (float) pt2.getX(), (float) pt2.getY() ); |
916 |
gp.lineTo( (float) pt3.getX(), (float) pt3.getY() ); |
917 |
if (extentOrig != extent) {
|
918 |
gp.lineTo( (float) pt0.getX(), (float) pt0.getY() ); |
919 |
Vector pts = new Vector(); |
920 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.minY())); |
921 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.minY())); |
922 |
pts.add(proj.createPoint(extentOrig.maxX(), extentOrig.maxY())); |
923 |
pts.add(proj.createPoint(extentOrig.minX(), extentOrig.maxY())); |
924 |
|
925 |
vp.mat.transform((Point2D) pts.get(0), pt0); |
926 |
vp.mat.transform((Point2D) pts.get(1), pt1); |
927 |
vp.mat.transform((Point2D) pts.get(2), pt2); |
928 |
vp.mat.transform((Point2D) pts.get(3), pt3); |
929 |
gp.moveTo( (float) pt0.getX(), (float) pt0.getY() ); |
930 |
gp.lineTo( (float) pt1.getX(), (float) pt1.getY() ); |
931 |
gp.lineTo( (float) pt2.getX(), (float) pt2.getY() ); |
932 |
gp.lineTo( (float) pt3.getX(), (float) pt3.getY() ); |
933 |
} |
934 |
gp.closePath(); |
935 |
return gp;
|
936 |
} |
937 |
|
938 |
public IProjection getProjection() { return proj; } |
939 |
public void setProjection(IProjection p) { proj = p; } |
940 |
|
941 |
public void reProject(ICoordTrans rp) { |
942 |
this.rp = rp.getInverted();
|
943 |
System.out.println("PxRaster: reProject()"); |
944 |
//geoFile.reProject(rp);
|
945 |
Vector savePts = pts;
|
946 |
|
947 |
pts = new Vector(); |
948 |
extent = new Extent();
|
949 |
Point2D ptDest = null; |
950 |
for (int i=0; i<savePts.size(); i++) { |
951 |
ptDest = rp.getPDest().createPoint(0.0,0.0); |
952 |
ptDest = rp.convert((Point2D) savePts.get(i), ptDest);
|
953 |
pts.add(ptDest); |
954 |
extent.add(ptDest); |
955 |
} |
956 |
setProjection(rp.getPDest()); |
957 |
} |
958 |
|
959 |
/**
|
960 |
* Obtiene el Stack Manager
|
961 |
* @return
|
962 |
*/
|
963 |
public RasterFilterStackManager getStackManager(){
|
964 |
return this.stackManager; |
965 |
} |
966 |
|
967 |
/**
|
968 |
* Asigna el Stack Manager
|
969 |
* @return
|
970 |
*/
|
971 |
public void setStackManager(RasterFilterStackManager sm){ |
972 |
this.stackManager = sm;
|
973 |
} |
974 |
} |