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