Revision 2669 branches/CqCMSDvp/libraries/libCq CMS for java.old/src/org/cresques/io/raster/RasterFilterStack.java
RasterFilterStack.java | ||
---|---|---|
1 | 1 |
/* |
2 | 2 |
* Cresques Mapping Suite. Graphic Library for constructing mapping applications. |
3 |
* |
|
4 |
* Copyright (C) 2004-5. |
|
5 | 3 |
* |
4 |
* Copyright (C) 2004-5. |
|
5 |
* |
|
6 | 6 |
* This program is free software; you can redistribute it and/or |
7 | 7 |
* modify it under the terms of the GNU General Public License |
8 | 8 |
* as published by the Free Software Foundation; either version 2 |
... | ... | |
18 | 18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA. |
19 | 19 |
* |
20 | 20 |
* For more information, contact: |
21 |
*
|
|
21 |
* |
|
22 | 22 |
* cresques@gmail.com |
23 | 23 |
*/ |
24 | 24 |
package org.cresques.io.raster; |
25 | 25 |
|
26 | 26 |
import java.awt.Image; |
27 |
|
|
27 | 28 |
import java.util.Vector; |
28 | 29 |
|
30 |
|
|
29 | 31 |
/** |
30 |
* Esta clase representa la pila de filtros que debe ser manejada desde el
|
|
32 |
* Esta clase representa la pila de filtros que debe ser manejada desde el |
|
31 | 33 |
* RasterFilterStackManager. |
32 | 34 |
* @author Nacho Brodin (brodin_ign@gva.es) |
33 |
*
|
|
35 |
* |
|
34 | 36 |
*/ |
35 |
public class RasterFilterStack{ |
|
36 |
|
|
37 |
private Image image = null; |
|
38 |
private RasterBuf rasterBuf = null; |
|
39 |
private RasterFilter rasterFilter = null; |
|
40 |
private int[] order = null; |
|
41 |
private RasterStats stats = null; |
|
42 |
|
|
43 |
Vector stack = new Vector(); |
|
44 |
private int typeFilter = -2; |
|
45 |
|
|
46 |
/** |
|
47 |
* Un RasterFilterStack almacena objetos Filter que representan a un filtro. Esta |
|
48 |
* clase contiene la informaci?n necesaria para el mantenimiento de de la pila y el |
|
49 |
* RasterFilter para cuando se aplica la pila sobre el raster de entrada. |
|
50 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
51 |
*/ |
|
52 |
class Filter{ |
|
37 |
public class RasterFilterStack { |
|
38 |
private Image image = null; |
|
39 |
private RasterBuf rasterBuf = null; |
|
40 |
private RasterFilter rasterFilter = null; |
|
41 |
private int[] order = null; |
|
42 |
private RasterStats stats = null; |
|
43 |
Vector stack = new Vector(); |
|
44 |
private int typeFilter = -2; |
|
53 | 45 |
|
54 |
public int type = 0; //Tipo de filtro. Ctes en RasterFilterStackManager |
|
55 |
public boolean tmp = true; //Flag de temporalidad |
|
56 |
public RasterFilter filter = null; //Filtro |
|
57 |
|
|
58 |
public Filter(int type, RasterFilter filter){ |
|
59 |
this.filter = filter; |
|
60 |
this.type = type; |
|
61 |
} |
|
62 |
} |
|
63 |
|
|
64 |
/** |
|
65 |
* Constructor |
|
66 |
* @param stats |
|
67 |
*/ |
|
68 |
public RasterFilterStack(RasterStats stats){ |
|
69 |
this.stats = stats; |
|
70 |
} |
|
71 |
|
|
72 |
/** |
|
73 |
* Resetea el flag de temporalidad de los filtros de la pila. |
|
74 |
* Esto equivale a fijar los filtros que ya existen en la pila. A partir de |
|
75 |
* ese momento los filtros que se introduzcan podr?n ser eliminados de golpe |
|
76 |
* llamando a la funci?n deleteTempFilters |
|
77 |
*/ |
|
78 |
public void resetTempFilters(){ |
|
79 |
for(int i=stack.size()-1;i>=0;i--) |
|
80 |
((Filter)stack.get(i)).tmp = false; |
|
81 |
} |
|
82 |
|
|
83 |
/** |
|
84 |
* Elimina los filtros temporales, es decir, todos los filtros introducidos desde |
|
85 |
* el ?ltimo resetTempFilters que se ha realizado. |
|
86 |
*/ |
|
87 |
public void deleteTempFilters(){ |
|
88 |
for(int i=stack.size()-1;i>=0;i--){ |
|
89 |
if(((Filter)stack.get(i)).tmp) |
|
90 |
stack.remove(i); |
|
91 |
} |
|
92 |
sort(); |
|
93 |
} |
|
94 |
|
|
95 |
/** |
|
96 |
* A?ade un filtro a la pila |
|
97 |
* @param type Tipo de filtro |
|
98 |
* @param filter filtro a?adido |
|
99 |
*/ |
|
100 |
public void addFilter(int type, RasterFilter filter){ |
|
101 |
stack.add(new Filter(type, filter)); |
|
102 |
this.sort(); |
|
103 |
} |
|
104 |
|
|
105 |
/** |
|
106 |
* Elimina el ?ltimo filtro de la pila |
|
107 |
*/ |
|
108 |
public void removeFilter(){ |
|
109 |
stack.remove(stack.size()-1); |
|
110 |
} |
|
111 |
|
|
112 |
/** |
|
113 |
* Asigna el tipo filtro |
|
114 |
* @param type |
|
115 |
*/ |
|
116 |
public void setDataTypeInFilter(int type){ |
|
117 |
this.typeFilter = type; |
|
118 |
} |
|
119 |
|
|
120 |
/** |
|
121 |
* Devuelve el tipo de dato de retorno al aplicar la pila de filtros |
|
122 |
* @return |
|
123 |
*/ |
|
124 |
public int getOutDataType(){ |
|
125 |
if(image != null && rasterBuf == null) |
|
126 |
return RasterBuf.TYPE_IMAGE; |
|
127 |
else |
|
128 |
return rasterBuf.getDataType(); |
|
129 |
} |
|
130 |
|
|
131 |
/** |
|
132 |
* Devuelve el raster o image resultado de la aplicacion de la pila de filtros |
|
133 |
* @return |
|
134 |
*/ |
|
135 |
public Object getResult(){ |
|
136 |
if(image != null && rasterBuf == null) |
|
137 |
return image; |
|
138 |
else |
|
139 |
return rasterBuf; |
|
140 |
} |
|
141 |
|
|
142 |
/** |
|
143 |
* Devuelve true si typeA est? por encima de typeB en la pila y false si no lo est? |
|
144 |
* @param typeA Tipo de filtro |
|
145 |
* @param typeB Tipo de filtro |
|
146 |
* @return |
|
147 |
*/ |
|
148 |
private boolean isOnTop(int typeA, int typeB){ |
|
149 |
int posA=-1; |
|
150 |
int posB=-1; |
|
151 |
for(int i=0;i<order.length;i++){ |
|
152 |
if(order[i] == typeA)posA = i; |
|
153 |
if(order[i] == typeB)posB = i; |
|
154 |
if(posA != -1 && posB != -1)break; |
|
155 |
} |
|
156 |
if(posA<posB)return true; |
|
157 |
else return false; |
|
158 |
} |
|
159 |
|
|
160 |
/** |
|
161 |
* Dado un tipo de filtro calcula a partir de la pila en que posici?n est? situado y |
|
162 |
* obtiene el tipo de dato de la salida anterior. Esto le dir? al cliente de que tipo |
|
163 |
* es el filtro que tiene que introducir. |
|
164 |
* @param type |
|
165 |
*/ |
|
166 |
public int getDataTypeInFilter(int type){ |
|
167 |
for(int i=0; i<stack.size(); i++){ |
|
168 |
if( isOnTop(((Filter)stack.get(i)).type , type ) ){ |
|
169 |
return ((Filter)stack.get(i)).filter.getOutRasterDataType(); |
|
170 |
} |
|
171 |
} |
|
172 |
return this.typeFilter; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Asigna el vector para la ordenaci?n por tipos |
|
177 |
* @param order |
|
178 |
*/ |
|
179 |
public void setOrder(int[] order){ |
|
180 |
this.order = order; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Ordena los filtros en el orden establecido por el Manager |
|
185 |
*/ |
|
186 |
public void sort(){ |
|
187 |
Vector aux = new Vector(); |
|
188 |
for(int norden=order.length-1;norden>=0;norden--){ |
|
189 |
for(int i=stack.size()-1;i>=0;i--){ |
|
190 |
if(((Filter)stack.get(i)).type == order[norden]){ |
|
191 |
aux.add(stack.get(i)); |
|
192 |
} |
|
193 |
} |
|
194 |
} |
|
195 |
stack = aux; |
|
196 |
aux = null; |
|
197 |
} |
|
198 |
|
|
199 |
/** |
|
200 |
* Elimina los filtros de la pila de un determinado tipo |
|
201 |
* @param type Tipo de filtro a eliminar |
|
202 |
*/ |
|
203 |
public void removeFilter(int type){ |
|
204 |
for(int i=stack.size()-1;i>=0;i--){ |
|
205 |
if(((Filter)stack.get(i)).type == type){ |
|
206 |
stack.remove(i); |
|
207 |
} |
|
208 |
} |
|
209 |
} |
|
210 |
|
|
211 |
/** |
|
212 |
* Elimina un filtro concreto de la pila |
|
213 |
* @param type |
|
214 |
*/ |
|
215 |
public void removeFilter(RasterFilter filter){ |
|
216 |
for(int i=stack.size()-1;i>=0;i--){ |
|
217 |
if(((Filter)stack.get(i)).filter.equals(filter)){ |
|
218 |
stack.remove(i); |
|
219 |
} |
|
220 |
} |
|
221 |
} |
|
222 |
|
|
223 |
/** |
|
224 |
* Obtiene la cantidad de filtros en la pila |
|
225 |
* @return N?mero de filtros apilados |
|
226 |
*/ |
|
227 |
public int lenght(){ |
|
228 |
return stack.size(); |
|
229 |
} |
|
230 |
|
|
231 |
/** |
|
232 |
* Obtiene el filtro apilado de la posici?n i |
|
233 |
* @param i Posici?n a acceder en la pila |
|
234 |
* @return Filtro |
|
235 |
*/ |
|
236 |
public RasterFilter get(int i){ |
|
237 |
return ((Filter)stack.get(i)).filter; |
|
238 |
} |
|
239 |
|
|
240 |
/** |
|
241 |
* Obtiene el tipo del filtro de la pila de la posici?n i |
|
242 |
* @param i Posici?n a acceder en la pila |
|
243 |
* @return tipo de filtro |
|
244 |
*/ |
|
245 |
public int getType(int i){ |
|
246 |
return ((Filter)stack.get(i)).type; |
|
247 |
} |
|
248 |
|
|
249 |
/** |
|
250 |
* Elimina todos los filtros de la pila |
|
251 |
*/ |
|
252 |
public void clear(){ |
|
253 |
stack.removeAllElements(); |
|
254 |
} |
|
46 |
/** |
|
47 |
* Constructor |
|
48 |
* @param stats |
|
49 |
*/ |
|
50 |
public RasterFilterStack(RasterStats stats) { |
|
51 |
this.stats = stats; |
|
52 |
} |
|
255 | 53 |
|
256 |
/** |
|
257 |
* Sustituye un filtro de una posici?n de la pila por otro |
|
258 |
* @param filter |
|
259 |
* @param i |
|
260 |
*/ |
|
261 |
public void replace(RasterFilter filter, int i, int type){ |
|
262 |
((Filter)stack.get(i)).filter = filter; |
|
263 |
((Filter)stack.get(i)).type = type; |
|
264 |
} |
|
265 |
|
|
266 |
/** |
|
267 |
* Asigna el raster de entrada inicial |
|
268 |
* @param raster |
|
269 |
*/ |
|
270 |
public void setInitRasterBuf(Object raster){ |
|
271 |
if(raster instanceof RasterBuf){ |
|
272 |
rasterBuf = (RasterBuf)raster; |
|
273 |
this.typeFilter = rasterBuf.getDataType(); |
|
274 |
} |
|
275 |
if(raster instanceof Image){ |
|
276 |
image = (Image)raster; |
|
277 |
this.typeFilter = RasterBuf.TYPE_IMAGE; |
|
278 |
} |
|
279 |
} |
|
280 |
|
|
281 |
/** |
|
282 |
* Devuelve el tipo de datos inicial de la pila |
|
283 |
* @return Tipo de dato del raster inicial |
|
284 |
*/ |
|
285 |
public int getInitDataType(){ |
|
286 |
return typeFilter; |
|
287 |
} |
|
288 |
|
|
289 |
/** |
|
290 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la |
|
291 |
* pila y false si no lo est?. |
|
292 |
* @param type Tipo de par?metro a comprobar |
|
293 |
* @return true si est? en la pila y false si no lo est? |
|
294 |
*/ |
|
295 |
public boolean isActive(int type){ |
|
296 |
for(int i=stack.size()-1;i>=0;i--){ |
|
297 |
if(((Filter)stack.get(i)).type == type) |
|
298 |
return true; |
|
299 |
} |
|
300 |
return false; |
|
301 |
} |
|
302 |
|
|
303 |
/** |
|
304 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la |
|
305 |
* pila y false si no lo est?. |
|
306 |
* @param filter Tipo de filtro a comprobar |
|
307 |
* @return true si est? en la pila y false si no lo est? |
|
308 |
*/ |
|
309 |
public boolean isActive(RasterFilter filter){ |
|
310 |
for(int i=stack.size()-1;i>=0;i--){ |
|
311 |
if(((Filter)stack.get(i)).filter.equals(filter)) |
|
312 |
return true; |
|
313 |
} |
|
314 |
return false; |
|
315 |
} |
|
316 |
|
|
317 |
/** |
|
318 |
* Obtiene el objeto RasterStats |
|
319 |
* @return |
|
320 |
*/ |
|
321 |
public RasterStats getStats(){ |
|
322 |
return this.stats; |
|
323 |
} |
|
324 |
|
|
325 |
/** |
|
326 |
* Aplica los filtros de la pila sobre el buffer correspondiente |
|
327 |
* @param dataType |
|
328 |
*/ |
|
329 |
private void executeFilterByDataType(int dataType){ |
|
330 |
for(int i=stack.size()-1;i>=0;i--){ |
|
331 |
RasterFilter filter = ((Filter)stack.get(i)).filter; |
|
332 |
//System.err.println("SACANDO FILTRO "+i+" "+filter.toString()); |
|
333 |
if(filter.getInRasterDataType() == RasterBuf.TYPE_IMAGE) |
|
334 |
filter.addParam("raster", image); |
|
335 |
else |
|
336 |
filter.addParam("raster", rasterBuf); |
|
337 |
|
|
338 |
filter.execute(); |
|
339 |
|
|
340 |
if(filter.getResult("stats")!=null) |
|
341 |
this.stats = (RasterStats)filter.getResult("stats"); |
|
342 |
|
|
343 |
if(filter.getOutRasterDataType() == RasterBuf.TYPE_IMAGE){ |
|
344 |
if(filter.getResult("raster")!=null){ |
|
345 |
this.image = (Image)filter.getResult("raster"); |
|
346 |
this.rasterBuf = null; |
|
347 |
} |
|
348 |
}else{ |
|
349 |
if(filter.getResult("raster")!=null){ |
|
350 |
this.rasterBuf = (RasterBuf)filter.getResult("raster"); |
|
351 |
this.image = null; |
|
352 |
} |
|
353 |
} |
|
354 |
|
|
355 |
} |
|
356 |
} |
|
357 |
|
|
358 |
/** |
|
359 |
* Aplica los filtros sobre un Image |
|
360 |
* @param image Buffer inicial sobre el que se aplican los filtros |
|
361 |
*/ |
|
362 |
public void execute(Image image){ |
|
363 |
this.image = image; |
|
364 |
executeFilterByDataType(RasterBuf.TYPE_IMAGE); |
|
365 |
} |
|
366 |
|
|
367 |
/** |
|
368 |
* Aplica los filtros sobre un RasterBuf |
|
369 |
* @param rasterBuf Buffer inicial sobre el que se aplican los filtros |
|
370 |
*/ |
|
371 |
public void execute(RasterBuf rasterBuf){ |
|
372 |
this.rasterBuf = rasterBuf; |
|
373 |
executeFilterByDataType(RasterBuf.TYPE_SHORT); |
|
374 |
} |
|
375 |
|
|
376 |
/** |
|
377 |
*Muestra el contenido de la pila de filtros para depuraci?n |
|
378 |
*/ |
|
379 |
public void show(){ |
|
380 |
System.out.println("--------------------------------------------"); |
|
381 |
for(int i=stack.size()-1;i>=0;i--){ |
|
382 |
System.out.println( "FILTRO:"+i+ |
|
383 |
" TIPO:"+((Filter)stack.get(i)).type+ |
|
384 |
" TEMP:"+((Filter)stack.get(i)).tmp+ |
|
385 |
" FIL:"+((Filter)stack.get(i)).filter.toString()); |
|
386 |
} |
|
387 |
} |
|
388 |
|
|
389 |
} |
|
54 |
/** |
|
55 |
* Resetea el flag de temporalidad de los filtros de la pila. |
|
56 |
* Esto equivale a fijar los filtros que ya existen en la pila. A partir de |
|
57 |
* ese momento los filtros que se introduzcan podr?n ser eliminados de golpe |
|
58 |
* llamando a la funci?n deleteTempFilters |
|
59 |
*/ |
|
60 |
public void resetTempFilters() { |
|
61 |
for (int i = stack.size() - 1; i >= 0; i--) |
|
62 |
((Filter) stack.get(i)).tmp = false; |
|
63 |
} |
|
64 |
|
|
65 |
/** |
|
66 |
* Elimina los filtros temporales, es decir, todos los filtros introducidos desde |
|
67 |
* el ?ltimo resetTempFilters que se ha realizado. |
|
68 |
*/ |
|
69 |
public void deleteTempFilters() { |
|
70 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
71 |
if (((Filter) stack.get(i)).tmp) { |
|
72 |
stack.remove(i); |
|
73 |
} |
|
74 |
} |
|
75 |
|
|
76 |
sort(); |
|
77 |
} |
|
78 |
|
|
79 |
/** |
|
80 |
* A?ade un filtro a la pila |
|
81 |
* @param type Tipo de filtro |
|
82 |
* @param filter filtro a?adido |
|
83 |
*/ |
|
84 |
public void addFilter(int type, RasterFilter filter) { |
|
85 |
stack.add(new Filter(type, filter)); |
|
86 |
this.sort(); |
|
87 |
} |
|
88 |
|
|
89 |
/** |
|
90 |
* Elimina el ?ltimo filtro de la pila |
|
91 |
*/ |
|
92 |
public void removeFilter() { |
|
93 |
stack.remove(stack.size() - 1); |
|
94 |
} |
|
95 |
|
|
96 |
/** |
|
97 |
* Asigna el tipo filtro |
|
98 |
* @param type |
|
99 |
*/ |
|
100 |
public void setDataTypeInFilter(int type) { |
|
101 |
this.typeFilter = type; |
|
102 |
} |
|
103 |
|
|
104 |
/** |
|
105 |
* Devuelve el tipo de dato de retorno al aplicar la pila de filtros |
|
106 |
* @return |
|
107 |
*/ |
|
108 |
public int getOutDataType() { |
|
109 |
if ((image != null) && (rasterBuf == null)) { |
|
110 |
return RasterBuf.TYPE_IMAGE; |
|
111 |
} else { |
|
112 |
return rasterBuf.getDataType(); |
|
113 |
} |
|
114 |
} |
|
115 |
|
|
116 |
/** |
|
117 |
* Devuelve el raster o image resultado de la aplicacion de la pila de filtros |
|
118 |
* @return |
|
119 |
*/ |
|
120 |
public Object getResult() { |
|
121 |
if ((image != null) && (rasterBuf == null)) { |
|
122 |
return image; |
|
123 |
} else { |
|
124 |
return rasterBuf; |
|
125 |
} |
|
126 |
} |
|
127 |
|
|
128 |
/** |
|
129 |
* Devuelve true si typeA est? por encima de typeB en la pila y false si no lo est? |
|
130 |
* @param typeA Tipo de filtro |
|
131 |
* @param typeB Tipo de filtro |
|
132 |
* @return |
|
133 |
*/ |
|
134 |
private boolean isOnTop(int typeA, int typeB) { |
|
135 |
int posA = -1; |
|
136 |
int posB = -1; |
|
137 |
|
|
138 |
for (int i = 0; i < order.length; i++) { |
|
139 |
if (order[i] == typeA) { |
|
140 |
posA = i; |
|
141 |
} |
|
142 |
|
|
143 |
if (order[i] == typeB) { |
|
144 |
posB = i; |
|
145 |
} |
|
146 |
|
|
147 |
if ((posA != -1) && (posB != -1)) { |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
|
|
152 |
if (posA < posB) { |
|
153 |
return true; |
|
154 |
} else { |
|
155 |
return false; |
|
156 |
} |
|
157 |
} |
|
158 |
|
|
159 |
/** |
|
160 |
* Dado un tipo de filtro calcula a partir de la pila en que posici?n est? situado y |
|
161 |
* obtiene el tipo de dato de la salida anterior. Esto le dir? al cliente de que tipo |
|
162 |
* es el filtro que tiene que introducir. |
|
163 |
* @param type |
|
164 |
*/ |
|
165 |
public int getDataTypeInFilter(int type) { |
|
166 |
for (int i = 0; i < stack.size(); i++) { |
|
167 |
if (isOnTop(((Filter) stack.get(i)).type, type)) { |
|
168 |
return ((Filter) stack.get(i)).filter.getOutRasterDataType(); |
|
169 |
} |
|
170 |
} |
|
171 |
|
|
172 |
return this.typeFilter; |
|
173 |
} |
|
174 |
|
|
175 |
/** |
|
176 |
* Asigna el vector para la ordenaci?n por tipos |
|
177 |
* @param order |
|
178 |
*/ |
|
179 |
public void setOrder(int[] order) { |
|
180 |
this.order = order; |
|
181 |
} |
|
182 |
|
|
183 |
/** |
|
184 |
* Ordena los filtros en el orden establecido por el Manager |
|
185 |
*/ |
|
186 |
public void sort() { |
|
187 |
Vector aux = new Vector(); |
|
188 |
|
|
189 |
for (int norden = order.length - 1; norden >= 0; norden--) { |
|
190 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
191 |
if (((Filter) stack.get(i)).type == order[norden]) { |
|
192 |
aux.add(stack.get(i)); |
|
193 |
} |
|
194 |
} |
|
195 |
} |
|
196 |
|
|
197 |
stack = aux; |
|
198 |
aux = null; |
|
199 |
} |
|
200 |
|
|
201 |
/** |
|
202 |
* Elimina los filtros de la pila de un determinado tipo |
|
203 |
* @param type Tipo de filtro a eliminar |
|
204 |
*/ |
|
205 |
public void removeFilter(int type) { |
|
206 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
207 |
if (((Filter) stack.get(i)).type == type) { |
|
208 |
stack.remove(i); |
|
209 |
} |
|
210 |
} |
|
211 |
} |
|
212 |
|
|
213 |
/** |
|
214 |
* Elimina un filtro concreto de la pila |
|
215 |
* @param type |
|
216 |
*/ |
|
217 |
public void removeFilter(RasterFilter filter) { |
|
218 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
219 |
if (((Filter) stack.get(i)).filter.equals(filter)) { |
|
220 |
stack.remove(i); |
|
221 |
} |
|
222 |
} |
|
223 |
} |
|
224 |
|
|
225 |
/** |
|
226 |
* Obtiene la cantidad de filtros en la pila |
|
227 |
* @return N?mero de filtros apilados |
|
228 |
*/ |
|
229 |
public int lenght() { |
|
230 |
return stack.size(); |
|
231 |
} |
|
232 |
|
|
233 |
/** |
|
234 |
* Obtiene el filtro apilado de la posici?n i |
|
235 |
* @param i Posici?n a acceder en la pila |
|
236 |
* @return Filtro |
|
237 |
*/ |
|
238 |
public RasterFilter get(int i) { |
|
239 |
return ((Filter) stack.get(i)).filter; |
|
240 |
} |
|
241 |
|
|
242 |
/** |
|
243 |
* Obtiene el tipo del filtro de la pila de la posici?n i |
|
244 |
* @param i Posici?n a acceder en la pila |
|
245 |
* @return tipo de filtro |
|
246 |
*/ |
|
247 |
public int getType(int i) { |
|
248 |
return ((Filter) stack.get(i)).type; |
|
249 |
} |
|
250 |
|
|
251 |
/** |
|
252 |
* Elimina todos los filtros de la pila |
|
253 |
*/ |
|
254 |
public void clear() { |
|
255 |
stack.removeAllElements(); |
|
256 |
} |
|
257 |
|
|
258 |
/** |
|
259 |
* Sustituye un filtro de una posici?n de la pila por otro |
|
260 |
* @param filter |
|
261 |
* @param i |
|
262 |
*/ |
|
263 |
public void replace(RasterFilter filter, int i, int type) { |
|
264 |
((Filter) stack.get(i)).filter = filter; |
|
265 |
((Filter) stack.get(i)).type = type; |
|
266 |
} |
|
267 |
|
|
268 |
/** |
|
269 |
* Asigna el raster de entrada inicial |
|
270 |
* @param raster |
|
271 |
*/ |
|
272 |
public void setInitRasterBuf(Object raster) { |
|
273 |
if (raster instanceof RasterBuf) { |
|
274 |
rasterBuf = (RasterBuf) raster; |
|
275 |
this.typeFilter = rasterBuf.getDataType(); |
|
276 |
} |
|
277 |
|
|
278 |
if (raster instanceof Image) { |
|
279 |
image = (Image) raster; |
|
280 |
this.typeFilter = RasterBuf.TYPE_IMAGE; |
|
281 |
} |
|
282 |
} |
|
283 |
|
|
284 |
/** |
|
285 |
* Devuelve el tipo de datos inicial de la pila |
|
286 |
* @return Tipo de dato del raster inicial |
|
287 |
*/ |
|
288 |
public int getInitDataType() { |
|
289 |
return typeFilter; |
|
290 |
} |
|
291 |
|
|
292 |
/** |
|
293 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la |
|
294 |
* pila y false si no lo est?. |
|
295 |
* @param type Tipo de par?metro a comprobar |
|
296 |
* @return true si est? en la pila y false si no lo est? |
|
297 |
*/ |
|
298 |
public boolean isActive(int type) { |
|
299 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
300 |
if (((Filter) stack.get(i)).type == type) { |
|
301 |
return true; |
|
302 |
} |
|
303 |
} |
|
304 |
|
|
305 |
return false; |
|
306 |
} |
|
307 |
|
|
308 |
/** |
|
309 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la |
|
310 |
* pila y false si no lo est?. |
|
311 |
* @param filter Tipo de filtro a comprobar |
|
312 |
* @return true si est? en la pila y false si no lo est? |
|
313 |
*/ |
|
314 |
public boolean isActive(RasterFilter filter) { |
|
315 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
316 |
if (((Filter) stack.get(i)).filter.equals(filter)) { |
|
317 |
return true; |
|
318 |
} |
|
319 |
} |
|
320 |
|
|
321 |
return false; |
|
322 |
} |
|
323 |
|
|
324 |
/** |
|
325 |
* Obtiene el objeto RasterStats |
|
326 |
* @return |
|
327 |
*/ |
|
328 |
public RasterStats getStats() { |
|
329 |
return this.stats; |
|
330 |
} |
|
331 |
|
|
332 |
/** |
|
333 |
* Aplica los filtros de la pila sobre el buffer correspondiente |
|
334 |
* @param dataType |
|
335 |
*/ |
|
336 |
private void executeFilterByDataType(int dataType) { |
|
337 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
338 |
RasterFilter filter = ((Filter) stack.get(i)).filter; |
|
339 |
|
|
340 |
//System.err.println("SACANDO FILTRO "+i+" "+filter.toString()); |
|
341 |
if (filter.getInRasterDataType() == RasterBuf.TYPE_IMAGE) { |
|
342 |
filter.addParam("raster", image); |
|
343 |
} else { |
|
344 |
filter.addParam("raster", rasterBuf); |
|
345 |
} |
|
346 |
|
|
347 |
filter.execute(); |
|
348 |
|
|
349 |
if (filter.getResult("stats") != null) { |
|
350 |
this.stats = (RasterStats) filter.getResult("stats"); |
|
351 |
} |
|
352 |
|
|
353 |
if (filter.getOutRasterDataType() == RasterBuf.TYPE_IMAGE) { |
|
354 |
if (filter.getResult("raster") != null) { |
|
355 |
this.image = (Image) filter.getResult("raster"); |
|
356 |
this.rasterBuf = null; |
|
357 |
} |
|
358 |
} else { |
|
359 |
if (filter.getResult("raster") != null) { |
|
360 |
this.rasterBuf = (RasterBuf) filter.getResult("raster"); |
|
361 |
this.image = null; |
|
362 |
} |
|
363 |
} |
|
364 |
} |
|
365 |
} |
|
366 |
|
|
367 |
/** |
|
368 |
* Aplica los filtros sobre un Image |
|
369 |
* @param image Buffer inicial sobre el que se aplican los filtros |
|
370 |
*/ |
|
371 |
public void execute(Image image) { |
|
372 |
this.image = image; |
|
373 |
executeFilterByDataType(RasterBuf.TYPE_IMAGE); |
|
374 |
} |
|
375 |
|
|
376 |
/** |
|
377 |
* Aplica los filtros sobre un RasterBuf |
|
378 |
* @param rasterBuf Buffer inicial sobre el que se aplican los filtros |
|
379 |
*/ |
|
380 |
public void execute(RasterBuf rasterBuf) { |
|
381 |
this.rasterBuf = rasterBuf; |
|
382 |
executeFilterByDataType(RasterBuf.TYPE_SHORT); |
|
383 |
} |
|
384 |
|
|
385 |
/** |
|
386 |
*Muestra el contenido de la pila de filtros para depuraci?n |
|
387 |
*/ |
|
388 |
public void show() { |
|
389 |
System.out.println("--------------------------------------------"); |
|
390 |
|
|
391 |
for (int i = stack.size() - 1; i >= 0; i--) { |
|
392 |
System.out.println("FILTRO:" + i + " TIPO:" + |
|
393 |
((Filter) stack.get(i)).type + " TEMP:" + |
|
394 |
((Filter) stack.get(i)).tmp + " FIL:" + |
|
395 |
((Filter) stack.get(i)).filter.toString()); |
|
396 |
} |
|
397 |
} |
|
398 |
|
|
399 |
/** |
|
400 |
* Un RasterFilterStack almacena objetos Filter que representan a un filtro. Esta |
|
401 |
* clase contiene la informaci?n necesaria para el mantenimiento de de la pila y el |
|
402 |
* RasterFilter para cuando se aplica la pila sobre el raster de entrada. |
|
403 |
* @author Nacho Brodin <brodin_ign@gva.es> |
|
404 |
*/ |
|
405 |
class Filter { |
|
406 |
public int type = 0; //Tipo de filtro. Ctes en RasterFilterStackManager |
|
407 |
public boolean tmp = true; //Flag de temporalidad |
|
408 |
public RasterFilter filter = null; //Filtro |
|
409 |
|
|
410 |
public Filter(int type, RasterFilter filter) { |
|
411 |
this.filter = filter; |
|
412 |
this.type = type; |
|
413 |
} |
|
414 |
} |
|
415 |
} |
Also available in: Unified diff