svn-gvsig-desktop / trunk / extensions / extRasterTools / src / org / gvsig / rasterTools / brightnessContrast / filter / BrightnessContrastStackManager.java @ 5247
History | View | Annotate | Download (7.59 KB)
1 |
package org.gvsig.rasterTools.brightnessContrast.filter; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.cresques.io.GeoRasterFile; |
6 |
import org.cresques.io.raster.IStackManager; |
7 |
import org.cresques.io.raster.LinearEnhancementFilter; |
8 |
import org.cresques.io.raster.LinearEnhancementImageFilter; |
9 |
import org.cresques.io.raster.LinearEnhancementShortFilter; |
10 |
import org.cresques.io.raster.RasterBuf; |
11 |
import org.cresques.io.raster.RasterFilter; |
12 |
import org.cresques.io.raster.RasterFilterStack; |
13 |
import org.cresques.io.raster.RasterFilterStackManager; |
14 |
import org.gvsig.rasterTools.histogram.filter.HistogramFilter; |
15 |
import org.gvsig.rasterTools.histogram.filter.HistogramImageFilter; |
16 |
|
17 |
/**
|
18 |
* Gestor de la pila de filtros para el filtro de brillo.
|
19 |
* @author Miguel ?ngel Querol Carratal? <querol_mig@gva.es>
|
20 |
*
|
21 |
*/
|
22 |
|
23 |
public class BrightnessContrastStackManager implements IStackManager{ |
24 |
|
25 |
public final static int brightness = 7; |
26 |
public final static int histogram = 6; |
27 |
public final static int contrast = 8; |
28 |
protected RasterFilterStack filterStack = null; |
29 |
private RasterFilterStackManager filterStackManager = null; |
30 |
|
31 |
public BrightnessContrastStackManager(RasterFilterStackManager filterStackManager){
|
32 |
this.filterStackManager = filterStackManager;
|
33 |
this.filterStack = filterStackManager.getFilterStack();
|
34 |
filterStackManager.addTypeFilter("histogram", BrightnessContrastStackManager.histogram, 5); |
35 |
filterStackManager.addTypeFilter("brightness", BrightnessContrastStackManager.brightness, 6); |
36 |
filterStackManager.addTypeFilter("contrast", BrightnessContrastStackManager.contrast, 7); |
37 |
|
38 |
} |
39 |
|
40 |
|
41 |
/**
|
42 |
* Obtiene el valor entero que corresponde al tipo de filtro.
|
43 |
* @param rasterFilter
|
44 |
* @return
|
45 |
*/
|
46 |
public int getType(RasterFilter rasterFilter){ |
47 |
if(rasterFilter instanceof BrightnessFilter) |
48 |
return BrightnessContrastStackManager.brightness;
|
49 |
if(rasterFilter instanceof HistogramFilter) |
50 |
return BrightnessContrastStackManager.histogram;
|
51 |
if(rasterFilter instanceof ContrastFilter) |
52 |
return BrightnessContrastStackManager.contrast;
|
53 |
|
54 |
return filterStackManager.getType(rasterFilter);
|
55 |
} |
56 |
|
57 |
/**
|
58 |
* A?ade un filtro de brillo a la pila de filtros.
|
59 |
* @param incrBrillo
|
60 |
*/
|
61 |
public void addBrightnessFilter(int incrBrillo){ |
62 |
//Si ya hay un filtro de brillo en la pila lo sobreescribimos
|
63 |
|
64 |
if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue())) |
65 |
filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue()); |
66 |
|
67 |
RasterFilter filtro = null;
|
68 |
|
69 |
switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("brightness")).intValue())){ |
70 |
case RasterBuf.TYPE_IMAGE:
|
71 |
filtro = new BrightnessImageFilter();
|
72 |
case RasterBuf.TYPE_SHORT:
|
73 |
case RasterBuf.TYPE_USHORT:
|
74 |
case RasterBuf.TYPE_INT:
|
75 |
break;
|
76 |
} |
77 |
|
78 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
79 |
|
80 |
if(filtro != null){ |
81 |
filtro.addParam("incrBrillo", new Integer(incrBrillo)); |
82 |
|
83 |
filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("brightness")).intValue(), filtro); |
84 |
|
85 |
filterStackManager.controlTypes(); |
86 |
} |
87 |
} |
88 |
|
89 |
/**
|
90 |
* A?ade un filtro de histograma a la pila de filtros
|
91 |
*
|
92 |
*/
|
93 |
public void addHistogramFilter(){ |
94 |
|
95 |
RasterFilter filtro = null;
|
96 |
|
97 |
//Si ya hay un filtro de histrograma en la pila lo sobreescribimos
|
98 |
|
99 |
if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue())) |
100 |
filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue()); |
101 |
|
102 |
//Crea el filtro a partir del dato de entrada que tenemos
|
103 |
switch(filterStack.getDataTypeInFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue())){ |
104 |
case RasterBuf.TYPE_IMAGE:
|
105 |
filtro = new HistogramImageFilter();
|
106 |
case RasterBuf.TYPE_SHORT:
|
107 |
case RasterBuf.TYPE_USHORT:
|
108 |
case RasterBuf.TYPE_INT:
|
109 |
break;
|
110 |
} |
111 |
|
112 |
if(filtro != null){ |
113 |
filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("histogram")).intValue(),filtro); |
114 |
|
115 |
filterStackManager.controlTypes(); |
116 |
} |
117 |
} |
118 |
|
119 |
|
120 |
/**
|
121 |
* A?ade un filtro de contraste a la pila de filtros.
|
122 |
* @param incrBrillo
|
123 |
*/
|
124 |
public void addContrastFilter(int incrContraste){ |
125 |
//Si ya hay un filtro de contraste en la pila lo sobreescribimos
|
126 |
|
127 |
if(filterStack.isActive(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue())) |
128 |
filterStack.removeFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue()); |
129 |
|
130 |
RasterFilter filtro = null;
|
131 |
|
132 |
switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("contrast")).intValue())){ |
133 |
case RasterBuf.TYPE_IMAGE:
|
134 |
filtro = new ContrastImageFilter();
|
135 |
case RasterBuf.TYPE_SHORT:
|
136 |
case RasterBuf.TYPE_USHORT:
|
137 |
case RasterBuf.TYPE_INT:
|
138 |
break;
|
139 |
} |
140 |
|
141 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
142 |
|
143 |
if(filtro != null){ |
144 |
filtro.addParam("incrContraste", new Integer(incrContraste)); |
145 |
|
146 |
filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("contrast")).intValue(), filtro); |
147 |
|
148 |
filterStackManager.controlTypes(); |
149 |
} |
150 |
} |
151 |
|
152 |
|
153 |
public void createStackFromStrings(ArrayList f, Integer pos) { |
154 |
// TODO Auto-generated method stub
|
155 |
|
156 |
} |
157 |
|
158 |
|
159 |
/**
|
160 |
* Crea una pila de filtros a partir de un Array de Strings. Cada elemento del array debe
|
161 |
* tener la forma elemento=valor.
|
162 |
* @param filters
|
163 |
*/
|
164 |
public int createStackFromStrings(ArrayList filters, String fil, GeoRasterFile[] grfList, int filteri) { |
165 |
|
166 |
if((fil.startsWith("filter.brightness.active"))&& |
167 |
(RasterFilterStackManager.getValue(fil).equals("true"))&&
|
168 |
(grfList!=null)){
|
169 |
|
170 |
int incrBrillo = 0; |
171 |
|
172 |
for(int prop = 0; prop < filters.size() ; prop++){ |
173 |
String elem = (String) filters.get(prop); |
174 |
if(elem.startsWith("filter.brightness.incrBrillo")){ |
175 |
incrBrillo = Integer.parseInt(RasterFilterStackManager.getValue(elem));
|
176 |
filters.remove(prop); |
177 |
prop--; |
178 |
} |
179 |
} |
180 |
|
181 |
addBrightnessFilter(incrBrillo); |
182 |
} |
183 |
|
184 |
if((fil.startsWith("filter.contrast.active")) && |
185 |
(RasterFilterStackManager.getValue(fil).equals("true")) &&
|
186 |
(grfList!=null)){
|
187 |
|
188 |
int incrContraste = 0; |
189 |
|
190 |
for(int prop = 0 ; prop < filters.size() ; prop++){ |
191 |
String elem = (String) filters.get(prop); |
192 |
if(elem.startsWith("filter.contrast.incrContraste")){ |
193 |
incrContraste = Integer.parseInt(RasterFilterStackManager.getValue(elem));
|
194 |
filters.remove(prop); |
195 |
prop--; |
196 |
} |
197 |
} |
198 |
|
199 |
addContrastFilter(incrContraste); |
200 |
} |
201 |
|
202 |
if(fil.startsWith("filter.histogram.active") && |
203 |
RasterFilterStackManager.getValue(fil).equals("true") &&
|
204 |
grfList != null){
|
205 |
|
206 |
addHistogramFilter(); |
207 |
filteri = -1;
|
208 |
|
209 |
} |
210 |
|
211 |
return filteri;
|
212 |
} |
213 |
|
214 |
public ArrayList getStringsFromStack() { |
215 |
// TODO Auto-generated method stub
|
216 |
return null; |
217 |
} |
218 |
|
219 |
/**
|
220 |
* Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
|
221 |
* tendr? la forma de elemento=valor.
|
222 |
*/
|
223 |
|
224 |
public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) { |
225 |
|
226 |
|
227 |
if(rf instanceof BrightnessFilter){ |
228 |
BrightnessFilter bright = (BrightnessFilter) rf; |
229 |
filterList.add("filter.brightness.active=true");
|
230 |
filterList.add("filter.brightness.incrBrillo="+bright.incrBrillo);
|
231 |
}else if(rf instanceof ContrastFilter){ |
232 |
ContrastFilter contrast = (ContrastFilter) rf; |
233 |
filterList.add("filter.contrast.active=true");
|
234 |
filterList.add("filter.contrast.incrContraste="+contrast.incrContraste);
|
235 |
}else if(rf instanceof HistogramFilter){ |
236 |
filterList.add("filter.histogram.active=true");
|
237 |
} |
238 |
|
239 |
return filterList;
|
240 |
} |
241 |
|
242 |
} |