svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / RasterFilterStackManager.java @ 2255
History | View | Annotate | Download (21.5 KB)
1 |
/*
|
---|---|
2 |
* Created on 17-may-2005
|
3 |
*
|
4 |
* To change the template for this generated file go to
|
5 |
* Window>Preferences>Java>Code Generation>Code and Comments
|
6 |
*/
|
7 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
8 |
*
|
9 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
10 |
*
|
11 |
* This program is free software; you can redistribute it and/or
|
12 |
* modify it under the terms of the GNU General Public License
|
13 |
* as published by the Free Software Foundation; either version 2
|
14 |
* of the License, or (at your option) any later version.
|
15 |
*
|
16 |
* This program is distributed in the hope that it will be useful,
|
17 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
18 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
19 |
* GNU General Public License for more details.
|
20 |
*
|
21 |
* You should have received a copy of the GNU General Public License
|
22 |
* along with this program; if not, write to the Free Software
|
23 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
24 |
*
|
25 |
* For more information, contact:
|
26 |
*
|
27 |
* Generalitat Valenciana
|
28 |
* Conselleria d'Infraestructures i Transport
|
29 |
* Av. Blasco Ib??ez, 50
|
30 |
* 46010 VALENCIA
|
31 |
* SPAIN
|
32 |
*
|
33 |
* +34 963862235
|
34 |
* gvsig@gva.es
|
35 |
* www.gvsig.gva.es
|
36 |
*
|
37 |
* or
|
38 |
*
|
39 |
* IVER T.I. S.A
|
40 |
* Salamanca 50
|
41 |
* 46005 Valencia
|
42 |
* Spain
|
43 |
*
|
44 |
* +34 963163400
|
45 |
* dac@iver.es
|
46 |
*/
|
47 |
package org.cresques.io.raster; |
48 |
|
49 |
import java.lang.reflect.Constructor; |
50 |
import java.util.ArrayList; |
51 |
import java.util.Hashtable; |
52 |
import java.util.StringTokenizer; |
53 |
import java.util.regex.Matcher; |
54 |
import java.util.regex.Pattern; |
55 |
|
56 |
/**
|
57 |
* Esta clase es de la parte cliente y es la encargada de la gesti?n
|
58 |
* de la pila de filtros. Es la que conoce el orden en que se deben apilar
|
59 |
* estos para que la ejecuci?n sea correcta. Un cliente que desee aplicar un
|
60 |
* filtro deber? introducirlo en la pila usando para ello esta clase.
|
61 |
* @author Nacho Brodin (brodin_ign@gva.es)
|
62 |
*
|
63 |
*/
|
64 |
public class RasterFilterStackManager implements IStackManager{ |
65 |
|
66 |
protected RasterFilterStack filterStack = null; |
67 |
private boolean debug = false; |
68 |
|
69 |
protected Hashtable typeFilters = new Hashtable(); |
70 |
public int[] order = null; |
71 |
private ArrayList managers = new ArrayList(); |
72 |
protected ArrayList filterList = null; |
73 |
|
74 |
/**
|
75 |
* Constructor
|
76 |
* @param filterStack
|
77 |
*/
|
78 |
public RasterFilterStackManager(RasterFilterStack filterStack){
|
79 |
this.filterStack = filterStack;
|
80 |
typeFilters.put("transparency", new Integer(0)); |
81 |
typeFilters.put("enhanced", new Integer(1)); |
82 |
typeFilters.put("computeminmax", new Integer(2)); |
83 |
typeFilters.put("tail", new Integer(3)); |
84 |
init(); |
85 |
this.filterStack.setOrder(order);
|
86 |
} |
87 |
|
88 |
/**
|
89 |
* Registra un manager del sistema
|
90 |
* @param manager
|
91 |
*/
|
92 |
protected void register(IStackManager manager){ |
93 |
managers.add(manager); |
94 |
} |
95 |
|
96 |
/**
|
97 |
* Inicializaci?n. Asigna el orden de los filtros
|
98 |
*
|
99 |
*/
|
100 |
protected void init(){ |
101 |
order = new int[typeFilters.size()]; |
102 |
order[0] = ((Integer)typeFilters.get("computeminmax")).intValue(); |
103 |
order[1] = ((Integer)typeFilters.get("tail")).intValue(); |
104 |
order[2] = ((Integer)typeFilters.get("enhanced")).intValue(); |
105 |
order[3] = ((Integer)typeFilters.get("transparency")).intValue(); |
106 |
} |
107 |
|
108 |
/**
|
109 |
* A?ade un nuevo tipo de filtro
|
110 |
* @param key Nombre del filtro
|
111 |
* @param type Constante entera asignada a ese tipo
|
112 |
*/
|
113 |
protected void addTypeFilter(String key, int type, int position){ |
114 |
typeFilters.put(key, new Integer(type)); |
115 |
int[] newOrder = new int[order.length+1]; |
116 |
for(int i=0;i<position;i++) |
117 |
newOrder[i] = order[i]; |
118 |
newOrder[position] = type; |
119 |
for(int i=position+1;i<newOrder.length;i++) |
120 |
newOrder[i] = order[i-1];
|
121 |
order = newOrder; |
122 |
this.filterStack.setOrder(order);
|
123 |
} |
124 |
|
125 |
/**
|
126 |
* Obtiene la constante correspondiente a un tipo de filtro
|
127 |
* @param key Clave para obtener la constante que corresponde al nombre del filtro
|
128 |
* @return Tipo de filtro
|
129 |
*/
|
130 |
public int getTypeFilter(String key){ |
131 |
return ((Integer)typeFilters.get(key)).intValue(); |
132 |
} |
133 |
|
134 |
/**
|
135 |
* A?ade un filtro de transparencia
|
136 |
* @param red Intervalos de la banda del rojo a poner transparentes
|
137 |
* @param green Intervalos de la banda del verde a poner transparentes
|
138 |
* @param blue Intervalos de la banda del azul a poner transparentes
|
139 |
* @param alpha Transparencia
|
140 |
* @param transparencyRed Color en la banda del rojo de la transparencia
|
141 |
* @param transparencyGreen Color en la banda del verde de la transparencia
|
142 |
* @param transparencyBlue Color en la banda del azul de la transparencia
|
143 |
*/
|
144 |
public void addTransparencyFilter( int[][] red, |
145 |
int[][] green, |
146 |
int[][] blue, |
147 |
int alpha,
|
148 |
int transparencyRed,
|
149 |
int transparencyGreen,
|
150 |
int transparencyBlue){
|
151 |
RasterFilter filtro = null;
|
152 |
switch(filterStack.getDataTypeInFilter(((Integer)typeFilters.get("transparency")).intValue())){ |
153 |
case RasterBuf.TYPE_IMAGE:filtro = new TransparencyImageFilter();break; |
154 |
case RasterBuf.TYPE_SHORT:
|
155 |
case RasterBuf.TYPE_USHORT:
|
156 |
case RasterBuf.TYPE_INT:filtro = new TransparencyShortFilter();break; |
157 |
} |
158 |
if(red != null)filtro.addParam("red", red); |
159 |
if(green != null)filtro.addParam("green", green); |
160 |
if(blue != null)filtro.addParam("blue", blue); |
161 |
filtro.addParam("alpha", new Integer(alpha)); |
162 |
filtro.addParam("transparencyRed", new Integer(transparencyRed)); |
163 |
filtro.addParam("transparencyGreen", new Integer(transparencyGreen)); |
164 |
filtro.addParam("transparencyBlue", new Integer(transparencyBlue)); |
165 |
|
166 |
//Elimina los filtros que son equivalentes a este
|
167 |
|
168 |
/*for(int i=0;i<filterStack.lenght();i++){
|
169 |
if( filterStack.get(i) instanceof TransparencyImageFilter ||
|
170 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
171 |
|
172 |
//Si este filtro es equivalente a uno de la pila se elimina este
|
173 |
if(((TransparencyFilter)filtro).isEquivalent((TransparencyFilter)filterStack.get(i)))
|
174 |
filterStack.removeFilter(filterStack.get(i));
|
175 |
|
176 |
}
|
177 |
}
|
178 |
|
179 |
//A?ade el filtro si no hay uno equivalente
|
180 |
|
181 |
boolean equivalentFilter = false;
|
182 |
for(int i=0;i<filterStack.lenght();i++){
|
183 |
if( filterStack.get(i) instanceof TransparencyImageFilter ||
|
184 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
185 |
|
186 |
//Si no existe en la pila un filtro equivalente se a?ade
|
187 |
if(((TransparencyFilter)filterStack.get(i)).isEquivalent((TransparencyFilter)filtro)){
|
188 |
equivalentFilter = true;
|
189 |
break;
|
190 |
}
|
191 |
}
|
192 |
}
|
193 |
if(!equivalentFilter)*/
|
194 |
filterStack.removeFilter(((Integer)typeFilters.get("transparency")).intValue()); |
195 |
filterStack.addFilter(((Integer)typeFilters.get("transparency")).intValue(), filtro); |
196 |
this.controlTypes();
|
197 |
} |
198 |
|
199 |
/**
|
200 |
* Obtiene el rango de rojo del filtro de transparencia de la pila
|
201 |
* @return rango de rojo
|
202 |
*/
|
203 |
public int[][] getTransparecyR(){ |
204 |
for(int i=0;i<filterStack.lenght();i++){ |
205 |
if( filterStack.get(i) instanceof TransparencyImageFilter || |
206 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
207 |
return ((TransparencyFilter)filterStack.get(i)).rangesR;
|
208 |
} |
209 |
} |
210 |
return null; |
211 |
} |
212 |
|
213 |
/**
|
214 |
* Obtiene el rango de verde del filtro de transparencia de la pila
|
215 |
* @return rango de verde
|
216 |
*/
|
217 |
public int[][] getTransparecyG(){ |
218 |
for(int i=0;i<filterStack.lenght();i++){ |
219 |
if( filterStack.get(i) instanceof TransparencyImageFilter || |
220 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
221 |
return ((TransparencyFilter)filterStack.get(i)).rangesG;
|
222 |
} |
223 |
} |
224 |
return null; |
225 |
} |
226 |
|
227 |
/**
|
228 |
* Obtiene el rango de azul del filtro de transparencia de la pila
|
229 |
* @return rango de azul
|
230 |
*/
|
231 |
public int[][] getTransparecyB(){ |
232 |
for(int i=0;i<filterStack.lenght();i++){ |
233 |
if( filterStack.get(i) instanceof TransparencyImageFilter || |
234 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
235 |
return ((TransparencyFilter)filterStack.get(i)).rangesB;
|
236 |
} |
237 |
} |
238 |
return null; |
239 |
} |
240 |
|
241 |
/**
|
242 |
* A?ade un filtro de recorte de colas.
|
243 |
* @param tail porcentaje de recorte
|
244 |
* @param samples porcentaje de muestras tomadas del total de la imagen
|
245 |
*/
|
246 |
public void addTailFilter( double tail, double samples, boolean removeMaxValue){ |
247 |
if(filterStack.isActive(((Integer)typeFilters.get("tail")).intValue())) |
248 |
filterStack.removeFilter(((Integer)typeFilters.get("tail")).intValue()); |
249 |
|
250 |
RasterFilter filtro = null;
|
251 |
switch(filterStack.getDataTypeInFilter(((Integer)typeFilters.get("tail")).intValue())){ |
252 |
case RasterBuf.TYPE_IMAGE:filtro = new PercentTailTrimImageFilter();break; |
253 |
case RasterBuf.TYPE_SHORT:
|
254 |
case RasterBuf.TYPE_USHORT:
|
255 |
case RasterBuf.TYPE_INT:filtro = new PercentTailTrimShortFilter();break; |
256 |
} |
257 |
filtro.addParam("stats", filterStack.getStats());
|
258 |
filtro.addParam("tail", new Double(tail)); |
259 |
filtro.addParam("samples", new Double(samples)); |
260 |
filtro.addParam("remove", new Boolean(removeMaxValue)); |
261 |
|
262 |
filterStack.addFilter(((Integer)typeFilters.get("tail")).intValue(), filtro); |
263 |
this.controlTypes();
|
264 |
} |
265 |
|
266 |
/**
|
267 |
* A?ade un filtro de realce. Esta versi?n tiene el par?metro para a?adirle el nombre
|
268 |
* del fichero. Esto se usa para que si a un fichero se le ha calculado ya el recorte de colas
|
269 |
* no se vuelva a calcular, evitando as? que si hacemos un draw a una imagen por bloques cada
|
270 |
* bloque tenga un calculo distinto para el recorte.
|
271 |
*/
|
272 |
public void addEnhancedFilter(boolean remove, String fileName){ |
273 |
if(filterStack.isActive(((Integer)typeFilters.get("enhanced")).intValue())) |
274 |
filterStack.removeFilter(((Integer)typeFilters.get("enhanced")).intValue()); |
275 |
|
276 |
RasterFilter filtro = null;
|
277 |
switch(filterStack.getDataTypeInFilter(((Integer)typeFilters.get("enhanced")).intValue())){ |
278 |
case RasterBuf.TYPE_IMAGE:filtro = new LinearEnhancementImageFilter();break; |
279 |
case RasterBuf.TYPE_SHORT:
|
280 |
case RasterBuf.TYPE_USHORT:
|
281 |
case RasterBuf.TYPE_INT:filtro = new LinearEnhancementShortFilter();break; |
282 |
} |
283 |
filtro.addParam("stats", filterStack.getStats());
|
284 |
if(remove)
|
285 |
filtro.addParam("remove", new Boolean(true)); |
286 |
else
|
287 |
filtro.addParam("remove", new Boolean(false)); |
288 |
if(fileName != null) |
289 |
filtro.addParam("filename", fileName);
|
290 |
else
|
291 |
filtro.addParam("filename", new String("")); |
292 |
filterStack.addFilter(((Integer)typeFilters.get("enhanced")).intValue(), filtro); |
293 |
this.controlTypes();
|
294 |
} |
295 |
|
296 |
/**
|
297 |
* A?ade un filtro de realce
|
298 |
*/
|
299 |
public void addEnhancedFilter(boolean remove){ |
300 |
addEnhancedFilter( remove, "");
|
301 |
} |
302 |
|
303 |
/**
|
304 |
* A?ade un filtro ComputeMinMax
|
305 |
*/
|
306 |
public void addComputeMinMaxFilter(){ |
307 |
if(!filterStack.isActive(((Integer)typeFilters.get("computeminmax")).intValue())){ //Solo lo a?adimos si no est? |
308 |
RasterFilter filtro = null;
|
309 |
switch(filterStack.getDataTypeInFilter(((Integer)typeFilters.get("computeminmax")).intValue())){ |
310 |
case RasterBuf.TYPE_IMAGE:filtro = new ComputeMinMaxImageFilter();break; |
311 |
case RasterBuf.TYPE_SHORT:
|
312 |
case RasterBuf.TYPE_USHORT:
|
313 |
case RasterBuf.TYPE_INT:filtro = new ComputeMinMaxShortFilter();break; |
314 |
} |
315 |
filtro.addParam("stats", filterStack.getStats());
|
316 |
filterStack.addFilter(((Integer)typeFilters.get("computeminmax")).intValue(), filtro); |
317 |
} |
318 |
this.controlTypes();
|
319 |
} |
320 |
|
321 |
/**
|
322 |
* Obtiene el tipo de filtro a partir del objeto RasterFilter
|
323 |
* @param rasterFilter Objeto RasterFilter del cual se quiere saber que tipo de filtro contiene
|
324 |
* @return Tipo de filtro seg?n las constantes contenidas en RasterFilterStackManager
|
325 |
*/
|
326 |
protected int getType(RasterFilter rasterFilter){ |
327 |
if(rasterFilter instanceof TransparencyFilter) |
328 |
return 0; |
329 |
if(rasterFilter instanceof LinearEnhancementFilter) |
330 |
return 1; |
331 |
if(rasterFilter instanceof ComputeMinMaxFilter) |
332 |
return 2; |
333 |
if(rasterFilter instanceof PercentTailTrimFilter) |
334 |
return 3; |
335 |
return -1; |
336 |
} |
337 |
|
338 |
/**
|
339 |
* Controla que los tipos de los filtros de la pila sean correctos, es decir, que
|
340 |
* el tipo de salida de un filtro de salida coincida con el tipo de la entrada del
|
341 |
* siguiente. En caso de no ser as? crea el filtro de tipo adecuado y lo sustituye
|
342 |
* en el no coincidente. Esto es necesario ya que en la eliminaci?n de filtros puede
|
343 |
* quedarse en inconsistencia de tipos.
|
344 |
*/
|
345 |
protected void controlTypes(){ |
346 |
if(debug)filterStack.show();
|
347 |
for(int i=filterStack.lenght();i>=0;i--){ |
348 |
if(i-1 >= 0){ |
349 |
|
350 |
//Para el primer filtro comprobamos con el tipo de dato de entrada a la pila
|
351 |
if(i == filterStack.lenght()){
|
352 |
if(filterStack.getInitDataType() != filterStack.get(i-1).getInRasterDataType()){ |
353 |
String oldClass = filterStack.get(i-1).getClass().toString().substring( |
354 |
filterStack.get(i-1).getClass().toString().lastIndexOf(".")+1, |
355 |
filterStack.get(i-1).getClass().toString().length());
|
356 |
Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i-1).getInRasterDataType())); |
357 |
Matcher m = p.matcher(oldClass);
|
358 |
String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.getInitDataType()));
|
359 |
//System.out.println("==>"+oldClass+" "+newClass);
|
360 |
try{
|
361 |
Class filterClass = Class.forName("org.cresques.io.raster."+newClass); |
362 |
Constructor con = filterClass.getConstructor(null); |
363 |
RasterFilter newFilter = (RasterFilter)con.newInstance(null);
|
364 |
newFilter.params = filterStack.get(i-1).params;
|
365 |
filterStack.replace(newFilter, i-1, this.getType(newFilter)); |
366 |
} catch (Exception e) { |
367 |
e.printStackTrace(); |
368 |
} |
369 |
} |
370 |
|
371 |
//Desde el filtro 2 en adelante se compara la salida de uno con la entrada del siguiente
|
372 |
|
373 |
}else if(filterStack.get(i).getOutRasterDataType() != filterStack.get(i-1).getInRasterDataType()){ |
374 |
String oldClass = filterStack.get(i-1).getClass().toString().substring( |
375 |
filterStack.get(i-1).getClass().toString().lastIndexOf(".")+1, |
376 |
filterStack.get(i-1).getClass().toString().length());
|
377 |
Pattern p = Pattern.compile(RasterBuf.typesToString(filterStack.get(i-1).getInRasterDataType())); |
378 |
Matcher m = p.matcher(oldClass);
|
379 |
String newClass = m.replaceAll(RasterBuf.typesToString(filterStack.get(i).getOutRasterDataType()));
|
380 |
//System.out.println("==>"+oldClass+" "+newClass);
|
381 |
try{
|
382 |
Class filterClass = Class.forName("org.cresques.io.raster."+newClass); |
383 |
Constructor con = filterClass.getConstructor(null); |
384 |
RasterFilter newFilter = (RasterFilter)con.newInstance(null);
|
385 |
newFilter.params = filterStack.get(i-1).params;
|
386 |
filterStack.replace(newFilter, i-1, this.getType(newFilter)); |
387 |
} catch (Exception e) { |
388 |
e.printStackTrace(); |
389 |
} |
390 |
} |
391 |
|
392 |
|
393 |
} |
394 |
|
395 |
} |
396 |
if(debug)filterStack.show();
|
397 |
} |
398 |
|
399 |
/**
|
400 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la
|
401 |
* pila y false si no lo est?.
|
402 |
* @param filter Tipo de filtro a comprobar
|
403 |
* @return true si est? en la pila y false si no lo est?
|
404 |
*/
|
405 |
public boolean isActive(int type){ |
406 |
return filterStack.isActive(type);
|
407 |
} |
408 |
|
409 |
/**
|
410 |
* Elimina los filtros de la pila de un determinado tipo
|
411 |
* @param type Tipo de filtro a eliminar
|
412 |
*/
|
413 |
public void removeFilter(int type){ |
414 |
filterStack.removeFilter(type); |
415 |
this.controlTypes();
|
416 |
} |
417 |
|
418 |
/**
|
419 |
* Resetea el flag de temporalidad de los filtros de la pila.
|
420 |
* Esto equivale a fijar los filtros que ya existen en la pila. A partir de
|
421 |
* ese momento los filtros que se introduzcan podr?n ser eliminados de golpe
|
422 |
* llamando a la funci?n deleteTempFilters
|
423 |
*/
|
424 |
public void resetTempFilters(){ |
425 |
filterStack.resetTempFilters(); |
426 |
} |
427 |
|
428 |
/**
|
429 |
* Elimina los filtros temporales, es decir, todos los filtros introducidos desde
|
430 |
* el ?ltimo resetTempFilters que se ha realizado.
|
431 |
*/
|
432 |
public void deleteTempFilters(){ |
433 |
filterStack.deleteTempFilters(); |
434 |
} |
435 |
|
436 |
/**
|
437 |
* Obtiene el objeto de estadisticas asignado a la pila.
|
438 |
* @return
|
439 |
*/
|
440 |
public RasterStats getStackStats(){
|
441 |
return filterStack.getStats();
|
442 |
} |
443 |
|
444 |
|
445 |
/* (non-Javadoc)
|
446 |
* @see org.cresques.io.raster.StackManager#getStringsFromStack()
|
447 |
*/
|
448 |
public ArrayList getStringsFromStack(){ |
449 |
filterList = new ArrayList(); |
450 |
for(int i=0;i<filterStack.lenght();i++){ |
451 |
RasterFilter rf = filterStack.get(i); |
452 |
if(rf instanceof TransparencyFilter){ |
453 |
filterList.add("filter.transparency.active=true");
|
454 |
filterList.add("filter.transparency.rangeR="+rangeToString(((TransparencyFilter)rf).getRangeR()));
|
455 |
filterList.add("filter.transparency.rangeG="+rangeToString(((TransparencyFilter)rf).getRangeG()));
|
456 |
filterList.add("filter.transparency.rangeB="+rangeToString(((TransparencyFilter)rf).getRangeB()));
|
457 |
|
458 |
}else if(rf instanceof LinearEnhancementFilter){ |
459 |
filterList.add("filter.enhanced.active=true");
|
460 |
filterList.add("filter.enhanced.remove="+((LinearEnhancementFilter)rf).getRemoveExtrema().toString());
|
461 |
|
462 |
}else if(rf instanceof ComputeMinMaxFilter){ |
463 |
filterList.add("filter.computeminmax.active=true");
|
464 |
|
465 |
}else if(rf instanceof PercentTailTrimFilter){ |
466 |
filterList.add("filter.tail.active=true");
|
467 |
filterList.add("filter.tail.value="+this.getStackStats().tailPercent); |
468 |
filterList.add("filter.tail.remove="+((PercentTailTrimFilter)rf).removeMaxValue());
|
469 |
}else{ //Se recorren todos los managers registrados comprobando si corresponde a la clase del filtro |
470 |
for(int j=0;j<managers.size();j++) |
471 |
((IStackManager)managers.get(j)).getStringsFromStack(); |
472 |
} |
473 |
} |
474 |
return filterList;
|
475 |
} |
476 |
|
477 |
/**
|
478 |
* Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe
|
479 |
* tener la forma elemento=valor.
|
480 |
* @param filters
|
481 |
*/
|
482 |
public void createStackFromStrings(ArrayList f){ |
483 |
this.createStackFromStrings(f, new Integer(0)); |
484 |
} |
485 |
|
486 |
/* (non-Javadoc)
|
487 |
* @see org.cresques.io.raster.StackManager#createStackFromStrings(java.util.ArrayList)
|
488 |
*/
|
489 |
public void createStackFromStrings(ArrayList f, Integer pos){ |
490 |
ArrayList filters = (ArrayList)f.clone(); |
491 |
filterStack.clear(); |
492 |
int filteri = pos.intValue();
|
493 |
|
494 |
//Busca un filtro activo y despu?s todas las propiedades que necesita ese filtro para
|
495 |
//ser creado. Una vez las tiene a?ade en la pila el tipo de filtro.
|
496 |
|
497 |
while(filters.size()>0 && filteri<filters.size()){ |
498 |
String fil = (String)filters.get(filteri); |
499 |
if(fil.startsWith("filter.transparency.active") && getValue(fil).equals("true")){ |
500 |
filters.remove(filteri); |
501 |
int[][] r = null, g = null, b = null; |
502 |
for(int propFilter=0;propFilter<filters.size();propFilter++){ |
503 |
String elem = (String)filters.get(propFilter); |
504 |
if(elem.startsWith("filter.transparency.rangeR")){ |
505 |
r = stringToRange(getValue(elem)); |
506 |
filters.remove(propFilter); |
507 |
propFilter--; |
508 |
} |
509 |
if(elem.startsWith("filter.transparency.rangeG")){ |
510 |
g = stringToRange(getValue(elem)); |
511 |
filters.remove(propFilter); |
512 |
propFilter--; |
513 |
} |
514 |
if(elem.startsWith("filter.transparency.rangeB")){ |
515 |
b = stringToRange(getValue(elem)); |
516 |
filters.remove(propFilter); |
517 |
propFilter--; |
518 |
} |
519 |
} |
520 |
this.addTransparencyFilter( r, g, b, 0x10, 0xff, 0xff, 0xff); |
521 |
filteri = -1;
|
522 |
} |
523 |
|
524 |
if(fil.startsWith("filter.enhanced.active") && getValue(fil).equals("true")){ |
525 |
filters.remove(filteri); |
526 |
boolean remove = false; |
527 |
for(int propFilter=0;propFilter<filters.size();propFilter++){ |
528 |
String elem = (String)filters.get(propFilter); |
529 |
if(elem.startsWith("filter.enhanced.remove")){ |
530 |
this.addEnhancedFilter(Boolean.valueOf(getValue(elem)).booleanValue()); |
531 |
filters.remove(propFilter); |
532 |
propFilter--; |
533 |
} |
534 |
} |
535 |
|
536 |
this.addComputeMinMaxFilter();
|
537 |
filteri = -1;
|
538 |
} |
539 |
|
540 |
if(fil.startsWith("filter.tail.active") && getValue(fil).equals("true")){ |
541 |
filters.remove(filteri); |
542 |
this.removeFilter(this.getTypeFilter("computeminmax")); |
543 |
double recorte = 0D; |
544 |
boolean remove = false; |
545 |
for(int propFilter=0;propFilter<filters.size();propFilter++){ |
546 |
String elem = (String)filters.get(propFilter); |
547 |
if(elem.startsWith("filter.tail.value")){ |
548 |
recorte = Double.parseDouble(getValue(elem));
|
549 |
filters.remove(propFilter); |
550 |
propFilter--; |
551 |
} |
552 |
if(elem.startsWith("filter.tail.remove")){ |
553 |
remove = Boolean.valueOf(getValue(elem)).booleanValue();
|
554 |
filters.remove(propFilter); |
555 |
propFilter--; |
556 |
} |
557 |
} |
558 |
this.addTailFilter( recorte, 0D, remove); |
559 |
filteri = -1;
|
560 |
} |
561 |
|
562 |
for(int j=0;j<managers.size();j++) |
563 |
((IStackManager)managers.get(j)).createStackFromStrings(filters, new Integer(filteri)); |
564 |
|
565 |
filteri++; |
566 |
} |
567 |
} |
568 |
|
569 |
/**
|
570 |
* Obtiene el elemento de una cadena de la forma elemento=valor
|
571 |
* @param cadena
|
572 |
* @return
|
573 |
*/
|
574 |
public String getElem(String cadena){ |
575 |
if(cadena!=null) |
576 |
return cadena.substring(0, cadena.indexOf("=")); |
577 |
else
|
578 |
return null; |
579 |
} |
580 |
|
581 |
/**
|
582 |
* Obtiene el valor de una cadena de la forma elemento=valor
|
583 |
* @param cadena
|
584 |
* @return
|
585 |
*/
|
586 |
public String getValue(String cadena){ |
587 |
if(cadena!=null) |
588 |
return cadena.substring(cadena.indexOf("=")+1, cadena.length()); |
589 |
else
|
590 |
return null; |
591 |
} |
592 |
|
593 |
/**
|
594 |
* Convierte un rango contenido en una array doble en una cadena
|
595 |
* de strings para poder salvar a xml
|
596 |
* @param rang
|
597 |
* @return
|
598 |
*/
|
599 |
private String rangeToString(int[][] rang){ |
600 |
StringBuffer rangoStr = new StringBuffer(); |
601 |
if(rang!=null){ |
602 |
for(int i=0;i<rang.length;i++){ |
603 |
rangoStr.append(String.valueOf(rang[i][0])+":"); |
604 |
rangoStr.append(String.valueOf(rang[i][1])+":"); |
605 |
} |
606 |
String r = rangoStr.toString();
|
607 |
if(r.endsWith(":")) |
608 |
r = r.substring(0, r.length()-1); |
609 |
return r;
|
610 |
}else
|
611 |
return null; |
612 |
|
613 |
} |
614 |
|
615 |
/**
|
616 |
* Convierte una cadena en una lista de rangos numericos para poder
|
617 |
* asignar transparencias a la imagen
|
618 |
* @param rang
|
619 |
* @return
|
620 |
*/
|
621 |
private int[][] stringToRange(String rang){ |
622 |
if(rang!=null && !rang.equals("null")){ |
623 |
ArrayList lista = new ArrayList(); |
624 |
StringTokenizer tokenizer = new StringTokenizer(rang, ":"); |
625 |
while (tokenizer.hasMoreTokens())
|
626 |
lista.add(tokenizer.nextToken()); |
627 |
int[][] intervalos = new int[(int)(lista.size()/2)][2]; |
628 |
|
629 |
for(int i=0;i<lista.size();i=i+2){ |
630 |
intervalos[i/2][0] = Integer.valueOf((String)lista.get(i)).intValue(); |
631 |
intervalos[i/2][1] = Integer.valueOf((String)lista.get(i+1)).intValue(); |
632 |
} |
633 |
return intervalos;
|
634 |
}else
|
635 |
return null; |
636 |
} |
637 |
|
638 |
|
639 |
} |