gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / segmentation / FirstDerivativeListManager.java @ 2328
History | View | Annotate | Download (6.63 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter.segmentation; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
32 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
33 |
import org.gvsig.raster.impl.store.ParamImpl; |
34 |
/**
|
35 |
* Gestor de la pila de filtros para el filtro de primera derivada.
|
36 |
*
|
37 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
38 |
*/
|
39 |
public class FirstDerivativeListManager extends AbstractRasterFilterManager { |
40 |
private static String ID = "FirstDerivative"; |
41 |
|
42 |
/**
|
43 |
* Default constructor. Sets the filter list.
|
44 |
* @param filterList
|
45 |
*/
|
46 |
public FirstDerivativeListManager(RasterFilterList filterList) {
|
47 |
super(filterList);
|
48 |
} |
49 |
|
50 |
public String getManagerID() { |
51 |
return ID;
|
52 |
} |
53 |
|
54 |
public static void register() { |
55 |
AbstractRasterFilterManager.register(ID, FirstDerivativeListManager.class); |
56 |
} |
57 |
|
58 |
/**
|
59 |
* Constructor. Asigna la lista de filtros y el manager.
|
60 |
* @param filterListManager
|
61 |
*/
|
62 |
public FirstDerivativeListManager(RasterFilterListManagerImpl filterListManager) {
|
63 |
super(filterListManager.getFilterList());
|
64 |
} |
65 |
|
66 |
public boolean isDataTypeSupported(int dataType) { |
67 |
return true; |
68 |
} |
69 |
|
70 |
public Class<?> getFilterClassByID(String id) { |
71 |
if( id.compareTo("sobel") == 0 || |
72 |
id.compareTo("roberts") == 0 || |
73 |
id.compareTo("prewitt") == 0 || |
74 |
id.compareTo("freichen") == 0) |
75 |
return FirstDerivativeFilter.class;
|
76 |
return null; |
77 |
} |
78 |
|
79 |
/**
|
80 |
* A?ade un filtro de convoluc?n a la pila de filtros.
|
81 |
* @param Name Nombre del filtro
|
82 |
* @param umbral
|
83 |
* @param operator
|
84 |
* @param compare
|
85 |
* @param Name
|
86 |
* @throws FilterTypeException
|
87 |
*/
|
88 |
public void addFirstDerivativeFilter(int umbral, boolean compare, String Name) throws FilterTypeException { |
89 |
RasterFilter filter = new FirstDerivativeByteFilter();
|
90 |
|
91 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
92 |
|
93 |
if (filter != null) { |
94 |
filter.addParam("umbral", new Integer(umbral)); |
95 |
filter.addParam("compare", new Boolean(compare)); |
96 |
filter.addParam("filterName", new String(Name)); |
97 |
filter.setName(Name);
|
98 |
getFilterList().add(filter); |
99 |
} |
100 |
} |
101 |
|
102 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
103 |
if (rf instanceof FirstDerivativeFilter) { |
104 |
filterList.add("filter.firstDerivative.active=true");
|
105 |
FirstDerivativeFilter firstDerivative = (FirstDerivativeFilter) rf; |
106 |
filterList.add("filter.firstDerivative.umbral=" + firstDerivative.umbral);
|
107 |
filterList.add("filter.firstDerivative.compare=" + firstDerivative.compare);
|
108 |
filterList.add("filter.firstDerivative.filterName=" + firstDerivative.getName());
|
109 |
} |
110 |
|
111 |
return filterList;
|
112 |
} |
113 |
|
114 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
115 |
if ((fil.startsWith("filter.firstDerivative.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) { |
116 |
|
117 |
int umbral = 0; |
118 |
boolean compare = false; |
119 |
String name = ""; |
120 |
filters.remove(0);
|
121 |
|
122 |
for (int prop = 0; prop < filters.size(); prop++) { |
123 |
String elem = (String) filters.get(prop); |
124 |
if (elem.startsWith("filter.firstDerivative.umbral")) { |
125 |
umbral = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
|
126 |
filters.remove(prop); |
127 |
prop--; |
128 |
} |
129 |
if (elem.startsWith("filter.firstDerivative.compare")) { |
130 |
compare = Boolean.getBoolean(RasterFilterListManagerImpl.getValue(elem));
|
131 |
filters.remove(prop); |
132 |
prop--; |
133 |
} |
134 |
if (elem.startsWith("filter.firstDerivative.filterName")) { |
135 |
name = RasterFilterListManagerImpl.getValue(elem); |
136 |
filters.remove(prop); |
137 |
prop--; |
138 |
} |
139 |
} |
140 |
addFirstDerivativeFilter(umbral, compare, name); |
141 |
} |
142 |
return filteri;
|
143 |
} |
144 |
|
145 |
public List<Class<?>> getRasterFilterList() { |
146 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
147 |
filters.add(FirstDerivativeFilter.class); |
148 |
return filters;
|
149 |
} |
150 |
|
151 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
152 |
if (FirstDerivativeFilter.class.isAssignableFrom(classFilter)) {
|
153 |
int umbral = 0; |
154 |
boolean compare = false; |
155 |
String name = ""; |
156 |
for (int i = 0; i < params.getNumParams(); i++) { |
157 |
if (((ParamImpl)params.getParam(i)).getId().equals("Umbral") && |
158 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) |
159 |
umbral = ((Integer)((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
160 |
if (((ParamImpl)params.getParam(i)).getId().equals("Compare") && |
161 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Boolean) |
162 |
compare = ((Boolean)((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
|
163 |
if (((ParamImpl)params.getParam(i)).getId().equals("FilterName") && |
164 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) |
165 |
name = (String)((ParamImpl)params.getParam(i)).getDefaultValue();
|
166 |
} |
167 |
addFirstDerivativeFilter(umbral, compare, name); |
168 |
} |
169 |
} |
170 |
|
171 |
public void addFilter(Params params) throws FilterTypeException { |
172 |
addFilter(FirstDerivativeFilter.class, params); |
173 |
} |
174 |
|
175 |
public RasterFilter createFilter(Params params) {
|
176 |
if( params.getParamById("Umbral") != null) { |
177 |
Integer umbral = ((Integer) params.getParamById("Umbral").getDefaultValue()); |
178 |
Boolean compare = ((Boolean) params.getParamById("Compare").getDefaultValue()); |
179 |
String name = ((String) params.getParamById("FilterName").getDefaultValue()); |
180 |
|
181 |
RasterFilter filter = new FirstDerivativeByteFilter();
|
182 |
filter.addParam("umbral", new Integer(umbral)); |
183 |
filter.addParam("compare", new Boolean(compare)); |
184 |
filter.addParam("filterName", new String(name)); |
185 |
return filter;
|
186 |
} |
187 |
return null; |
188 |
} |
189 |
} |