Revision 2438 org.gvsig.raster/trunk/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.impl/src/main/java/org/gvsig/raster/impl/grid/filter/convolution/ConvolutionListManager.java
ConvolutionListManager.java | ||
---|---|---|
26 | 26 |
|
27 | 27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
28 | 28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
|
29 | 30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
30 | 31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
|
32 | 32 |
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener; |
33 | 33 |
import org.gvsig.raster.impl.datastruct.Kernel; |
34 | 34 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
35 | 35 |
import org.gvsig.raster.impl.store.ParamImpl; |
36 |
import org.gvsig.tools.ToolsLocator; |
|
37 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
|
38 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
|
39 | 36 |
/** |
40 | 37 |
* Gestion de la lista de filtros |
41 | 38 |
*/ |
42 |
public class ConvolutionListManager implements RasterFilterListManager {
|
|
43 |
protected RasterFilterList filterList = null;
|
|
44 |
|
|
39 |
public class ConvolutionListManager extends AbstractRasterFilterManager {
|
|
40 |
private static String ID = "Convolucion";
|
|
41 |
|
|
45 | 42 |
/** |
46 |
* Registra ConvolutionListManager en los puntos de extension de RasterFilter |
|
43 |
* Default constructor. Sets the filter list. |
|
44 |
* @param filterList |
|
47 | 45 |
*/ |
46 |
public ConvolutionListManager(RasterFilterList filterList) { |
|
47 |
super(filterList); |
|
48 |
} |
|
49 |
|
|
50 |
public String getManagerID() { |
|
51 |
return ID; |
|
52 |
} |
|
53 |
|
|
48 | 54 |
public static void register() { |
49 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
|
50 |
ExtensionPoint point = extensionPoints.get("RasterFilter"); |
|
51 |
point.append("Convolucion", "", ConvolutionListManager.class); |
|
55 |
AbstractRasterFilterManager.register(ID, ConvolutionListManager.class, ConvolutionUI.class); |
|
52 | 56 |
} |
53 | 57 |
|
54 | 58 |
public boolean isDataTypeSupported(int dataType) { |
... | ... | |
65 | 69 |
return null; |
66 | 70 |
} |
67 | 71 |
|
68 |
/** |
|
69 |
* Default constructor. Sets the filter list. |
|
70 |
* @param filterList |
|
71 |
*/ |
|
72 |
public ConvolutionListManager(RasterFilterList filterList) { |
|
73 |
this.filterList = filterList; |
|
74 |
} |
|
75 |
|
|
76 | 72 |
public ConvolutionListManager(RasterFilterListManagerImpl filterListManager) { |
77 |
this.filterList = filterListManager.getFilterList();
|
|
73 |
super(filterListManager.getFilterList());
|
|
78 | 74 |
} |
79 | 75 |
|
80 | 76 |
/** |
... | ... | |
91 | 87 |
filter.addParam("Agudeza", Double.valueOf(agudeza)); |
92 | 88 |
filter.addParam("filterName", String.valueOf(Name)); |
93 | 89 |
filter.addParam("kernel", kernel); |
94 |
filterList.add(filter);
|
|
90 |
getFilterList().add(filter);
|
|
95 | 91 |
} |
96 | 92 |
} |
97 | 93 |
|
98 |
/* |
|
99 |
* (non-Javadoc) |
|
100 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getStringsFromFilterList(java.util.ArrayList, org.gvsig.fmap.dal.coverage.grid.RasterFilter) |
|
101 |
*/ |
|
102 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
|
103 |
if (rf instanceof ConvolutionFilter) { |
|
104 |
filterList.add("filter.convolution.active=true"); |
|
105 |
ConvolutionFilter convolutionFilter = (ConvolutionFilter) rf; |
|
106 |
switch (convolutionFilter.ladoVentana) { |
|
107 |
case 0: |
|
108 |
filterList.add("filter.convolution.ladoVentana=3"); |
|
109 |
break; |
|
110 |
case 1: |
|
111 |
filterList.add("filter.convolution.ladoVentana=5"); |
|
112 |
break; |
|
113 |
case 2: |
|
114 |
filterList.add("filter.convolution.ladoVentana=7"); |
|
115 |
break; |
|
116 |
} |
|
117 |
|
|
118 |
filterList.add("filter.convolution.filterName=" + convolutionFilter.getName()); |
|
119 |
if (convolutionFilter.getName().equals("personalizado")) { |
|
120 |
double[][] listDouble = convolutionFilter.kernel.kernel; |
|
121 |
String listString = ""; |
|
122 |
for (int i = 0; i < listDouble.length; i++) |
|
123 |
for (int j = 0; j < listDouble[0].length; j++) |
|
124 |
listString = listString + listDouble[i][j] + " "; |
|
125 |
|
|
126 |
listString = listString.trim(); |
|
127 |
filterList.add("filter.convolution.kernel=" + listString); |
|
128 |
} |
|
129 |
} |
|
130 |
|
|
131 |
return filterList; |
|
132 |
} |
|
133 |
|
|
134 | 94 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
135 | 95 |
if (ConvolutionFilter.class.isAssignableFrom(classFilter)) { |
136 | 96 |
int ladoVentana = 0; |
... | ... | |
168 | 128 |
} |
169 | 129 |
} |
170 | 130 |
|
171 |
/* |
|
172 |
* (non-Javadoc) |
|
173 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params) |
|
174 |
*/ |
|
175 | 131 |
public void addFilter(Params params) throws FilterTypeException { |
176 | 132 |
addFilter(ConvolutionFilter.class, params); |
177 | 133 |
} |
178 | 134 |
|
179 |
/* |
|
180 |
* (non-Javadoc) |
|
181 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params) |
|
182 |
*/ |
|
183 | 135 |
public RasterFilter createFilter(Params params) { |
184 | 136 |
Integer ladoVentana = ((Integer) params.getParamById("LadoVentana").getDefaultValue()); |
185 | 137 |
String name = ((String) params.getParamById("FilterName").getDefaultValue()); |
... | ... | |
194 | 146 |
return filter; |
195 | 147 |
} |
196 | 148 |
|
197 |
/* |
|
198 |
* (non-Javadoc) |
|
199 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int) |
|
200 |
*/ |
|
201 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
|
202 |
if ((fil.startsWith("filter.convolution.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) { |
|
203 |
int ladoVentana = 0; |
|
204 |
double agudeza = 0; |
|
205 |
String name = ""; |
|
206 |
Kernel kernel = null; |
|
207 |
filters.remove(0); |
|
208 |
for (int prop = 0; prop < filters.size(); prop++) { |
|
209 |
String elem = (String) filters.get(prop); |
|
210 |
if (elem.startsWith("filter.convolution.ladoVentana")) { |
|
211 |
ladoVentana = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem)); |
|
212 |
ladoVentana = (ladoVentana == 7) ? 2 : (ladoVentana == 5) ? 1 : 0; |
|
213 |
filters.remove(prop); |
|
214 |
prop--; |
|
215 |
} |
|
216 |
if (elem.startsWith("filter.convolution.filterName")) { |
|
217 |
name = RasterFilterListManagerImpl.getValue(elem); |
|
218 |
filters.remove(prop); |
|
219 |
prop--; |
|
220 |
} |
|
221 |
if (elem.startsWith("filter.convolution.kernel")) { |
|
222 |
String k = RasterFilterListManagerImpl.getValue(elem); |
|
223 |
String[] listString = k.split(" "); |
|
224 |
if (listString != null) { |
|
225 |
int lado = (ladoVentana == 0) ? 3 : (ladoVentana == 1) ? 5 : 7; |
|
226 |
double[][] listDouble = new double[lado][lado]; |
|
227 |
int cont = 0; |
|
228 |
for (int i = 0; i < lado; i++) { |
|
229 |
for (int j = 0; j < lado; j++) { |
|
230 |
try { |
|
231 |
listDouble[i][j] = Double.parseDouble(listString[cont]); |
|
232 |
cont++; |
|
233 |
} catch (NumberFormatException e) { |
|
234 |
} |
|
235 |
} |
|
236 |
} |
|
237 |
kernel = new Kernel(listDouble); |
|
238 |
} |
|
239 |
filters.remove(prop); |
|
240 |
prop--; |
|
241 |
} |
|
242 |
if (elem.startsWith("filter.convolution.agudeza")) { |
|
243 |
agudeza = Double.parseDouble(RasterFilterListManagerImpl.getValue(elem)); |
|
244 |
filters.remove(prop); |
|
245 |
prop--; |
|
246 |
} |
|
247 |
} |
|
248 |
addConvolutionFilter(name, ladoVentana, agudeza, kernel); |
|
249 |
} |
|
250 |
return filteri; |
|
251 |
} |
|
252 |
|
|
253 | 149 |
public List<Class<?>> getRasterFilterList() { |
254 | 150 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
255 | 151 |
filters.add(ConvolutionFilter.class); |
256 | 152 |
return filters; |
257 | 153 |
} |
258 |
|
|
259 |
/* |
|
260 |
* (non-Javadoc) |
|
261 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList() |
|
262 |
*/ |
|
263 |
public RasterFilterList getFilterList() { |
|
264 |
return filterList; |
|
265 |
} |
|
266 |
|
|
267 |
/* |
|
268 |
* (non-Javadoc) |
|
269 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList) |
|
270 |
*/ |
|
271 |
public void setFilterList(RasterFilterList filterList) { |
|
272 |
this.filterList = filterList; |
|
273 |
} |
|
274 | 154 |
} |
Also available in: Unified diff