root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / convolution / ConvolutionListManager.java @ 12333
History | View | Annotate | Download (3.54 KB)
1 |
package org.gvsig.raster.grid.filter.convolution; |
---|---|
2 |
|
3 |
import java.util.ArrayList; |
4 |
|
5 |
import org.gvsig.raster.dataset.Params; |
6 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
7 |
import org.gvsig.raster.grid.filter.RasterFilter; |
8 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
9 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
10 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
11 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
12 |
|
13 |
/**Gestion de la lista de filtros*/
|
14 |
public class ConvolutionListManager implements IRasterFilterListManager{ |
15 |
|
16 |
protected RasterFilterList filterList = null; |
17 |
private RasterFilterListManager filterListManager = null; |
18 |
|
19 |
|
20 |
public ConvolutionListManager(RasterFilterListManager filterListManager){
|
21 |
this.filterListManager = filterListManager;
|
22 |
this.filterList = filterListManager.getFilterList();
|
23 |
} |
24 |
|
25 |
public static void register() { |
26 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
27 |
extensionPoints.add("RasterFilter", "Convolucion", ConvolutionListManager.class); |
28 |
} |
29 |
/**
|
30 |
* A?ade un filtro de convolucion a la pila de filtros.
|
31 |
* @param ladoVentana
|
32 |
*/
|
33 |
public void addConvolutionFilter(String Name,int ladoVentana) { |
34 |
RasterFilter filter = new ConvolutionByteFilter();
|
35 |
|
36 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
37 |
if (filter != null) { |
38 |
filter.addParam("ladoVentana", new Integer(ladoVentana)); |
39 |
filter.addParam("filterName", new String(Name)); |
40 |
filterList.add(filter); |
41 |
} |
42 |
} |
43 |
|
44 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
45 |
|
46 |
if (rf instanceof ConvolutionFilter) { |
47 |
filterList.add("filter.convolution.active=true");
|
48 |
ConvolutionFilter convolutionFilter = (ConvolutionFilter) rf; |
49 |
switch(convolutionFilter.ladoVentana) {
|
50 |
case 3: filterList.add("filter.convolution.ladoVentana=" + 0); break; |
51 |
case 5: filterList.add("filter.convolution.ladoVentana=" + 1); break; |
52 |
case 7: filterList.add("filter.convolution.ladoVentana=" + 2); break; |
53 |
} |
54 |
|
55 |
filterList.add("filter.convolution.filterName=" + convolutionFilter.getName());
|
56 |
} |
57 |
|
58 |
return filterList;
|
59 |
} |
60 |
|
61 |
public void addFilter(Class classFilter, Params params) { |
62 |
if (classFilter.equals(ConvolutionFilter.class)) {
|
63 |
int ladoVentana = 0; |
64 |
String name=""; |
65 |
for (int i = 0; i < params.getNumParams(); i++) { |
66 |
if (params.getParam(i).id.equals("LadoVentana")) |
67 |
ladoVentana = new Integer((String) params.getParam(i).defaultValue).intValue(); |
68 |
|
69 |
if (params.getParam(i).id.equals("FilterName")) |
70 |
name = new String((String) params.getParam(i).defaultValue); |
71 |
} |
72 |
addConvolutionFilter(name, ladoVentana); |
73 |
} |
74 |
} |
75 |
|
76 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) { |
77 |
if ((fil.startsWith("filter.convolution.active")) && (RasterFilterListManager.getValue(fil).equals("true"))) { |
78 |
|
79 |
int ladoVentana = 0; |
80 |
String name = ""; |
81 |
filters.remove(0);
|
82 |
for (int prop = 0; prop < filters.size(); prop++) { |
83 |
String elem = (String) filters.get(prop); |
84 |
if (elem.startsWith("filter.convolution.ladoVentana")) { |
85 |
ladoVentana = Integer.parseInt(RasterFilterListManager.getValue(elem));
|
86 |
filters.remove(prop); |
87 |
prop--; |
88 |
} |
89 |
if (elem.startsWith("filter.convolution.filterName")) { |
90 |
name = RasterFilterListManager.getValue(elem); |
91 |
filters.remove(prop); |
92 |
prop--; |
93 |
} |
94 |
} |
95 |
addConvolutionFilter(name, ladoVentana); |
96 |
} |
97 |
return filteri;
|
98 |
} |
99 |
|
100 |
public ArrayList getRasterFilterList() { |
101 |
ArrayList filters = new ArrayList(); |
102 |
filters.add(ConvolutionFilter.class); |
103 |
return filters;
|
104 |
} |
105 |
|
106 |
|
107 |
} |