svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / RasterFilterStackManager.java @ 1812
History | View | Annotate | Download (6.77 KB)
1 |
/*
|
---|---|
2 |
* Created on 12-abr-2005
|
3 |
*/
|
4 |
package org.cresques.io.raster; |
5 |
|
6 |
/**
|
7 |
*
|
8 |
* @author Nacho Brodin <brodin_ign@gva.es>
|
9 |
*
|
10 |
* Esta clase es de la parte cliente y es la encargada de la gesti?n
|
11 |
* de la pila de filtros. Es la que conoce el orden en que se deben apilar
|
12 |
* estos para que la ejecuci?n sea correcta. Un cliente que desee aplicar un
|
13 |
* filtro deber? introducirlo en la pil usando para ello esta clase.
|
14 |
*/
|
15 |
public class RasterFilterStackManager{ |
16 |
|
17 |
private RasterFilterStack filterStack = null; |
18 |
|
19 |
public final static int transparency = 0; |
20 |
public final static int enhanced = 1; |
21 |
public final static int computeminmax = 2; |
22 |
public final static int tail = 3; |
23 |
|
24 |
public int[] order = { RasterFilterStackManager.computeminmax, |
25 |
RasterFilterStackManager.tail, |
26 |
RasterFilterStackManager.enhanced, |
27 |
RasterFilterStackManager.transparency |
28 |
}; |
29 |
|
30 |
public RasterFilterStackManager(RasterFilterStack filterStack){
|
31 |
this.filterStack = filterStack;
|
32 |
this.filterStack.setOrder(order);
|
33 |
} |
34 |
|
35 |
/**
|
36 |
* A?ade un filtro de transparencia
|
37 |
* @param red Intervalos de la banda del rojo a poner transparentes
|
38 |
* @param green Intervalos de la banda del verde a poner transparentes
|
39 |
* @param blue Intervalos de la banda del azul a poner transparentes
|
40 |
* @param alpha Transparencia
|
41 |
* @param transparencyRed Color en la banda del rojo de la transparencia
|
42 |
* @param transparencyGreen Color en la banda del verde de la transparencia
|
43 |
* @param transparencyBlue Color en la banda del azul de la transparencia
|
44 |
*/
|
45 |
public void addTransparencyFilter( int[][] red, |
46 |
int[][] green, |
47 |
int[][] blue, |
48 |
int alpha,
|
49 |
int transparencyRed,
|
50 |
int transparencyGreen,
|
51 |
int transparencyBlue){
|
52 |
RasterFilter filtro = null;
|
53 |
switch(filterStack.getDataTypeInFilter(RasterFilterStackManager.transparency)){
|
54 |
case RasterBuf.TYPE_IMAGE:filtro = new TransparencyImageFilter();break; |
55 |
case RasterBuf.TYPE_SHORT:
|
56 |
case RasterBuf.TYPE_USHORT:
|
57 |
case RasterBuf.TYPE_INT:filtro = new TransparencyShortFilter();break; |
58 |
} |
59 |
if(red != null)filtro.addParam("red", red); |
60 |
if(green != null)filtro.addParam("green", green); |
61 |
if(blue != null)filtro.addParam("blue", blue); |
62 |
filtro.addParam("alpha", new Integer(alpha)); |
63 |
filtro.addParam("transparencyRed", new Integer(transparencyRed)); |
64 |
filtro.addParam("transparencyGreen", new Integer(transparencyGreen)); |
65 |
filtro.addParam("transparencyBlue", new Integer(transparencyBlue)); |
66 |
|
67 |
//Elimina los filtros que son equivalentes a este
|
68 |
|
69 |
for(int i=0;i<filterStack.lenght();i++){ |
70 |
if( filterStack.get(i) instanceof TransparencyImageFilter || |
71 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
72 |
|
73 |
//Si este filtro es equivalente a uno de la pila se elimina este
|
74 |
if(((TransparencyFilter)filtro).isEquivalent((TransparencyFilter)filterStack.get(i)))
|
75 |
filterStack.removeFilter(filterStack.get(i)); |
76 |
|
77 |
} |
78 |
} |
79 |
|
80 |
//A?ade el filtro si no hay uno equivalente
|
81 |
|
82 |
boolean equivalentFilter = false; |
83 |
for(int i=0;i<filterStack.lenght();i++){ |
84 |
if( filterStack.get(i) instanceof TransparencyImageFilter || |
85 |
filterStack.get(i) instanceof TransparencyShortFilter){
|
86 |
|
87 |
//Si no existe en la pila un filtro equivalente se a?ade
|
88 |
if(((TransparencyFilter)filterStack.get(i)).isEquivalent((TransparencyFilter)filtro)){
|
89 |
equivalentFilter = true;
|
90 |
break;
|
91 |
} |
92 |
} |
93 |
} |
94 |
if(!equivalentFilter)
|
95 |
filterStack.addFilter(RasterFilterStackManager.transparency, filtro); |
96 |
} |
97 |
|
98 |
/**
|
99 |
* A?ade un filtro de recorte de colas
|
100 |
* @param tail porcentaje de recorte
|
101 |
* @param samples porcentaje de muestras tomadas del total de la imagen
|
102 |
*/
|
103 |
public void addTailFilter( double tail, double samples){ |
104 |
if(filterStack.isActive(RasterFilterStackManager.tail))
|
105 |
filterStack.removeFilter(RasterFilterStackManager.tail); |
106 |
|
107 |
RasterFilter filtro = null;
|
108 |
switch(filterStack.getDataTypeInFilter(RasterFilterStackManager.tail)){
|
109 |
case RasterBuf.TYPE_IMAGE:filtro = new PercentTailTrimImageFilter();break; |
110 |
case RasterBuf.TYPE_SHORT:
|
111 |
case RasterBuf.TYPE_USHORT:
|
112 |
case RasterBuf.TYPE_INT:filtro = new PercentTailTrimShortFilter();break; |
113 |
} |
114 |
filtro.addParam("stats", filterStack.getStats());
|
115 |
filtro.addParam("tail", new Double(tail)); |
116 |
filtro.addParam("samples", new Double(samples)); |
117 |
filterStack.addFilter(RasterFilterStackManager.tail, filtro); |
118 |
} |
119 |
|
120 |
/**
|
121 |
* A?ade un filtro de realce
|
122 |
*/
|
123 |
public void addEnhancedFilter(){ |
124 |
if(filterStack.isActive(RasterFilterStackManager.enhanced))
|
125 |
filterStack.removeFilter(RasterFilterStackManager.enhanced); |
126 |
|
127 |
RasterFilter filtro = null;
|
128 |
switch(filterStack.getDataTypeInFilter(RasterFilterStackManager.enhanced)){
|
129 |
case RasterBuf.TYPE_IMAGE:filtro = new LinearEnhancementImageFilter();break; |
130 |
case RasterBuf.TYPE_SHORT:
|
131 |
case RasterBuf.TYPE_USHORT:
|
132 |
case RasterBuf.TYPE_INT:filtro = new LinearEnhancementShortFilter();break; |
133 |
} |
134 |
filtro.addParam("stats", filterStack.getStats());
|
135 |
filterStack.addFilter(RasterFilterStackManager.enhanced, filtro); |
136 |
} |
137 |
|
138 |
/**
|
139 |
* A?ade un filtro ComputeMinMax
|
140 |
*/
|
141 |
public void addComputeMinMaxFilter(){ |
142 |
if(!filterStack.isActive(RasterFilterStackManager.computeminmax)){ //Solo lo a?adimos si no est? |
143 |
RasterFilter filtro = null;
|
144 |
switch(filterStack.getDataTypeInFilter(RasterFilterStackManager.computeminmax)){
|
145 |
case RasterBuf.TYPE_IMAGE:filtro = new ComputeMinMaxImageFilter();break; |
146 |
case RasterBuf.TYPE_SHORT:
|
147 |
case RasterBuf.TYPE_USHORT:
|
148 |
case RasterBuf.TYPE_INT:filtro = new ComputeMinMaxShortFilter();break; |
149 |
} |
150 |
filtro.addParam("stats", filterStack.getStats());
|
151 |
filterStack.addFilter(RasterFilterStackManager.computeminmax, filtro); |
152 |
} |
153 |
} |
154 |
|
155 |
/**
|
156 |
* M?todo que devuelve true si el tipo de filtro pasado por par?metro est? en la
|
157 |
* pila y false si no lo est?.
|
158 |
* @param filter Tipo de filtro a comprobar
|
159 |
* @return true si est? en la pila y false si no lo est?
|
160 |
*/
|
161 |
public boolean isActive(int type){ |
162 |
return filterStack.isActive(type);
|
163 |
} |
164 |
|
165 |
/**
|
166 |
* Elimina los filtros de la pila de un determinado tipo
|
167 |
* @param type Tipo de filtro a eliminar
|
168 |
*/
|
169 |
public void removeFilter(int type){ |
170 |
filterStack.removeFilter(type); |
171 |
} |
172 |
|
173 |
/**
|
174 |
* Resetea el flag de temporalidad de los filtros de la pila.
|
175 |
* Esto equivale a fijar los filtros que ya existen en la pila. A partir de
|
176 |
* ese momento los filtros que se introduzcan podr?n ser eliminados de golpe
|
177 |
* llamando a la funci?n deleteTempFilters
|
178 |
*/
|
179 |
public void resetTempFilters(){ |
180 |
filterStack.resetTempFilters(); |
181 |
} |
182 |
|
183 |
/**
|
184 |
* Elimina los filtros temporales, es decir, todos los filtros introducidos desde
|
185 |
* el ?ltimo resetTempFilters que se ha realizado.
|
186 |
*/
|
187 |
public void deleteTempFilters(){ |
188 |
filterStack.deleteTempFilters(); |
189 |
} |
190 |
|
191 |
/**
|
192 |
* Obtiene el objeto de estadisticas asignado a la pila.
|
193 |
* @return
|
194 |
*/
|
195 |
public RasterStats getStackStats(){
|
196 |
return filterStack.getStats();
|
197 |
} |
198 |
} |