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