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 / correction / MedianListManager.java @ 1427
History | View | Annotate | Download (5.89 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.correction; |
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 mediana.
|
39 |
*
|
40 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
41 |
*/
|
42 |
public class MedianListManager implements RasterFilterListManager { |
43 |
protected RasterFilterList filterList = null; |
44 |
|
45 |
/**
|
46 |
* Default constructor. Sets the filter list.
|
47 |
* @param filterList
|
48 |
*/
|
49 |
public MedianListManager(RasterFilterList filterList) {
|
50 |
this.filterList = filterList;
|
51 |
} |
52 |
|
53 |
/**
|
54 |
* Constructor. Asigna la lista de filtros y el manager.
|
55 |
* @param filterListManager
|
56 |
*/
|
57 |
public MedianListManager(RasterFilterListManagerImpl filterListManager) {
|
58 |
this.filterList = filterListManager.getFilterList();
|
59 |
} |
60 |
|
61 |
/**
|
62 |
* Registra MedianListManager en los puntos de extension de RasterFilter
|
63 |
*/
|
64 |
public static void register() { |
65 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
66 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
67 |
point.append("Median", "", MedianListManager.class); |
68 |
} |
69 |
|
70 |
public boolean isDataTypeSupported(int dataType) { |
71 |
return true; |
72 |
} |
73 |
|
74 |
public Class<?> getFilterClassByID(String id) { |
75 |
if(id.compareTo("median") == 0) |
76 |
return MedianFilter.class;
|
77 |
return null; |
78 |
} |
79 |
|
80 |
/**
|
81 |
* A?ade un filtro de mediana a la pila de filtros.
|
82 |
* @param ladoVentana
|
83 |
* @throws FilterTypeException
|
84 |
*/
|
85 |
public void addMedianFilter(int ladoVentana) throws FilterTypeException { |
86 |
RasterFilter filter = new MedianByteFilter();
|
87 |
|
88 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
89 |
|
90 |
if (filter != null) { |
91 |
filter.addParam("ladoVentana", new Integer(ladoVentana)); |
92 |
filterList.add(filter); |
93 |
} |
94 |
} |
95 |
|
96 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
97 |
if (rf instanceof MedianFilter) { |
98 |
filterList.add("filter.median.active=true");
|
99 |
MedianFilter medianFilter = (MedianFilter) rf; |
100 |
filterList.add("filter.median.ladoVentana=" + medianFilter.getSideWindow());
|
101 |
} |
102 |
|
103 |
return filterList;
|
104 |
} |
105 |
|
106 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
107 |
if ((fil.startsWith("filter.median.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) { |
108 |
|
109 |
int ladoVentana = 0; |
110 |
filters.remove(0);
|
111 |
|
112 |
for (int prop = 0; prop < filters.size(); prop++) { |
113 |
String elem = (String) filters.get(prop); |
114 |
if (elem.startsWith("filter.median.ladoVentana")) { |
115 |
ladoVentana = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
|
116 |
filters.remove(prop); |
117 |
prop--; |
118 |
} |
119 |
} |
120 |
addMedianFilter(ladoVentana); |
121 |
} |
122 |
return filteri;
|
123 |
} |
124 |
|
125 |
public List<Class<?>> getRasterFilterList() { |
126 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
127 |
filters.add(MedianFilter.class); |
128 |
return filters;
|
129 |
} |
130 |
|
131 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
132 |
if (MedianFilter.class.isAssignableFrom(classFilter)) {
|
133 |
int ladoVentana = 0; |
134 |
for (int i = 0; i < params.getNumParams(); i++) { |
135 |
if (((ParamImpl)params.getParam(i)).getId().equals("ladoVentana") && |
136 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) |
137 |
ladoVentana = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
|
138 |
} |
139 |
addMedianFilter(ladoVentana); |
140 |
} |
141 |
} |
142 |
|
143 |
/*
|
144 |
* (non-Javadoc)
|
145 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
146 |
*/
|
147 |
public void addFilter(Params params) throws FilterTypeException { |
148 |
addFilter(MedianFilter.class, params); |
149 |
} |
150 |
|
151 |
/*
|
152 |
* (non-Javadoc)
|
153 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
154 |
*/
|
155 |
public RasterFilter createFilter(Params params) {
|
156 |
if( params.getParamById("ladoVentana") != null) { |
157 |
int ladoVentana = ((Integer) params.getParamById("ladoVentana").getDefaultValue()).intValue(); |
158 |
RasterFilter filter = new MedianByteFilter();
|
159 |
filter.addParam("ladoVentana", new Integer(ladoVentana)); |
160 |
return filter;
|
161 |
} |
162 |
return null; |
163 |
} |
164 |
|
165 |
/*
|
166 |
* (non-Javadoc)
|
167 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
168 |
*/
|
169 |
public RasterFilterList getFilterList() {
|
170 |
return filterList;
|
171 |
} |
172 |
|
173 |
/*
|
174 |
* (non-Javadoc)
|
175 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
176 |
*/
|
177 |
public void setFilterList(RasterFilterList filterList) { |
178 |
this.filterList = filterList;
|
179 |
} |
180 |
} |