gvsig-raster / 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 / segmentation / FirstDerivativeListManager.java @ 1426
History | View | Annotate | Download (7.64 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.RasterFilter; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
32 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
33 |
import org.gvsig.raster.impl.store.ParamImpl; |
34 |
import org.gvsig.tools.ToolsLocator; |
35 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
36 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
37 |
/**
|
38 |
* Gestor de la pila de filtros para el filtro de primera derivada.
|
39 |
*
|
40 |
* @version 04/06/2007
|
41 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
42 |
*/
|
43 |
public class FirstDerivativeListManager implements RasterFilterListManager { |
44 |
protected RasterFilterList filterList = null; |
45 |
|
46 |
/**
|
47 |
* Default constructor. Sets the filter list.
|
48 |
* @param filterList
|
49 |
*/
|
50 |
public FirstDerivativeListManager(RasterFilterList filterList) {
|
51 |
this.filterList = filterList;
|
52 |
} |
53 |
|
54 |
/**
|
55 |
* Constructor. Asigna la lista de filtros y el manager.
|
56 |
* @param filterListManager
|
57 |
*/
|
58 |
public FirstDerivativeListManager(RasterFilterListManagerImpl filterListManager) {
|
59 |
this.filterList = filterListManager.getFilterList();
|
60 |
} |
61 |
|
62 |
/**
|
63 |
* Registra FirstDerivativeListManager en los puntos de extension de RasterFilter
|
64 |
*/
|
65 |
public static void register() { |
66 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
67 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
68 |
point.append("FirstDerivative", "", FirstDerivativeListManager.class); |
69 |
} |
70 |
|
71 |
public Class<?> getFilterClassByID(String id) { |
72 |
if( id.compareTo("sobel") == 0 || |
73 |
id.compareTo("roberts") == 0 || |
74 |
id.compareTo("prewitt") == 0 || |
75 |
id.compareTo("freichen") == 0) |
76 |
return FirstDerivativeFilter.class;
|
77 |
return null; |
78 |
} |
79 |
|
80 |
/**
|
81 |
* A?ade un filtro de convoluc?n a la pila de filtros.
|
82 |
* @param Name Nombre del filtro
|
83 |
* @param umbral
|
84 |
* @param operator
|
85 |
* @param compare
|
86 |
* @param Name
|
87 |
* @throws FilterTypeException
|
88 |
*/
|
89 |
public void addFirstDerivativeFilter(int umbral, boolean compare, String Name) throws FilterTypeException { |
90 |
RasterFilter filter = new FirstDerivativeByteFilter();
|
91 |
|
92 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
93 |
|
94 |
if (filter != null) { |
95 |
filter.addParam("umbral", new Integer(umbral)); |
96 |
filter.addParam("compare", new Boolean(compare)); |
97 |
filter.addParam("filterName", new String(Name)); |
98 |
filter.setName(Name);
|
99 |
filterList.add(filter); |
100 |
} |
101 |
} |
102 |
|
103 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
104 |
if (rf instanceof FirstDerivativeFilter) { |
105 |
filterList.add("filter.firstDerivative.active=true");
|
106 |
FirstDerivativeFilter firstDerivative = (FirstDerivativeFilter) rf; |
107 |
filterList.add("filter.firstDerivative.umbral=" + firstDerivative.umbral);
|
108 |
filterList.add("filter.firstDerivative.compare=" + firstDerivative.compare);
|
109 |
filterList.add("filter.firstDerivative.filterName=" + firstDerivative.getName());
|
110 |
} |
111 |
|
112 |
return filterList;
|
113 |
} |
114 |
|
115 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
116 |
if ((fil.startsWith("filter.firstDerivative.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) { |
117 |
|
118 |
int umbral = 0; |
119 |
boolean compare = false; |
120 |
String name = ""; |
121 |
filters.remove(0);
|
122 |
|
123 |
for (int prop = 0; prop < filters.size(); prop++) { |
124 |
String elem = (String) filters.get(prop); |
125 |
if (elem.startsWith("filter.firstDerivative.umbral")) { |
126 |
umbral = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
|
127 |
filters.remove(prop); |
128 |
prop--; |
129 |
} |
130 |
if (elem.startsWith("filter.firstDerivative.compare")) { |
131 |
compare = Boolean.getBoolean(RasterFilterListManagerImpl.getValue(elem));
|
132 |
filters.remove(prop); |
133 |
prop--; |
134 |
} |
135 |
if (elem.startsWith("filter.firstDerivative.filterName")) { |
136 |
name = RasterFilterListManagerImpl.getValue(elem); |
137 |
filters.remove(prop); |
138 |
prop--; |
139 |
} |
140 |
} |
141 |
addFirstDerivativeFilter(umbral, compare, name); |
142 |
} |
143 |
return filteri;
|
144 |
} |
145 |
|
146 |
public List<Class<?>> getRasterFilterList() { |
147 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
148 |
filters.add(FirstDerivativeFilter.class); |
149 |
return filters;
|
150 |
} |
151 |
|
152 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
153 |
if (FirstDerivativeFilter.class.isAssignableFrom(classFilter)) {
|
154 |
int umbral = 0; |
155 |
boolean compare = false; |
156 |
String name = ""; |
157 |
for (int i = 0; i < params.getNumParams(); i++) { |
158 |
if (((ParamImpl)params.getParam(i)).getId().equals("Umbral") && |
159 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) |
160 |
umbral = ((Integer)((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
161 |
if (((ParamImpl)params.getParam(i)).getId().equals("Compare") && |
162 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Boolean) |
163 |
compare = ((Boolean)((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
|
164 |
if (((ParamImpl)params.getParam(i)).getId().equals("FilterName") && |
165 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) |
166 |
name = (String)((ParamImpl)params.getParam(i)).getDefaultValue();
|
167 |
} |
168 |
addFirstDerivativeFilter(umbral, compare, name); |
169 |
} |
170 |
} |
171 |
|
172 |
/*
|
173 |
* (non-Javadoc)
|
174 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
175 |
*/
|
176 |
public void addFilter(Params params) throws FilterTypeException { |
177 |
addFilter(FirstDerivativeFilter.class, params); |
178 |
} |
179 |
|
180 |
/*
|
181 |
* (non-Javadoc)
|
182 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
183 |
*/
|
184 |
public RasterFilter createFilter(Params params) {
|
185 |
if( params.getParamById("Umbral") != null) { |
186 |
Integer umbral = ((Integer) params.getParamById("Umbral").getDefaultValue()); |
187 |
Boolean compare = ((Boolean) params.getParamById("Compare").getDefaultValue()); |
188 |
String name = ((String) params.getParamById("FilterName").getDefaultValue()); |
189 |
|
190 |
RasterFilter filter = new FirstDerivativeByteFilter();
|
191 |
filter.addParam("umbral", new Integer(umbral)); |
192 |
filter.addParam("compare", new Boolean(compare)); |
193 |
filter.addParam("filterName", new String(name)); |
194 |
return filter;
|
195 |
} |
196 |
return null; |
197 |
} |
198 |
|
199 |
/*
|
200 |
* (non-Javadoc)
|
201 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
202 |
*/
|
203 |
public RasterFilterList getFilterList() {
|
204 |
return filterList;
|
205 |
} |
206 |
|
207 |
/*
|
208 |
* (non-Javadoc)
|
209 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
210 |
*/
|
211 |
public void setFilterList(RasterFilterList filterList) { |
212 |
this.filterList = filterList;
|
213 |
} |
214 |
} |