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