root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / correction / MedianListManager.java @ 12167
History | View | Annotate | Download (4.39 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2004 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.grid.filter.correction; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
25 |
import org.gvsig.raster.grid.filter.RasterFilter; |
26 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
27 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
28 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
30 |
/**
|
31 |
* Gestor de la pila de filtros para el filtro de mediana.
|
32 |
*
|
33 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
34 |
*/
|
35 |
public class MedianListManager implements IRasterFilterListManager { |
36 |
protected RasterFilterList filterList = null; |
37 |
private RasterFilterListManager filterListManager = null; |
38 |
|
39 |
/**
|
40 |
* Constructor. Asigna la lista de filtros y el manager.
|
41 |
* @param filterListManager
|
42 |
*/
|
43 |
public MedianListManager(RasterFilterListManager filterListManager) {
|
44 |
this.filterListManager = filterListManager;
|
45 |
this.filterList = filterListManager.getFilterList();
|
46 |
} |
47 |
|
48 |
public static void register() { |
49 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
50 |
extensionPoints.add("RasterFilter", "Median", MedianListManager.class); |
51 |
} |
52 |
|
53 |
/**
|
54 |
* A?ade un filtro de mediana a la pila de filtros.
|
55 |
* @param ladoVentana
|
56 |
*/
|
57 |
public void addMedianFilter(int ladoVentana) { |
58 |
RasterFilter filter = new MedianByteFilter();
|
59 |
|
60 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
61 |
|
62 |
if (filter != null) { |
63 |
filter.addParam("ladoVentana", new Integer(ladoVentana)); |
64 |
filterList.add(filter); |
65 |
} |
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList, org.gvsig.raster.grid.filter.RasterFilter)
|
71 |
*/
|
72 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
73 |
if (rf instanceof MedianFilter) { |
74 |
filterList.add("filter.median.active=true");
|
75 |
MedianFilter medianFilter = (MedianFilter) rf; |
76 |
filterList.add("filter.median.ladoVentana=" + medianFilter.ladoVentana);
|
77 |
} |
78 |
|
79 |
return filterList;
|
80 |
} |
81 |
|
82 |
|
83 |
/*
|
84 |
* (non-Javadoc)
|
85 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
86 |
*/
|
87 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) { |
88 |
if ((fil.startsWith("filter.median.active")) && (RasterFilterListManager.getValue(fil).equals("true"))) { |
89 |
|
90 |
int ladoVentana = 0; |
91 |
filters.remove(0);
|
92 |
|
93 |
for (int prop = 0; prop < filters.size(); prop++) { |
94 |
String elem = (String) filters.get(prop); |
95 |
if (elem.startsWith("filter.median.ladoVentana")) { |
96 |
ladoVentana = Integer.parseInt(RasterFilterListManager.getValue(elem));
|
97 |
filters.remove(prop); |
98 |
prop--; |
99 |
} |
100 |
} |
101 |
addMedianFilter(ladoVentana); |
102 |
} |
103 |
return filteri;
|
104 |
} |
105 |
|
106 |
/*
|
107 |
* (non-Javadoc)
|
108 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
|
109 |
*/
|
110 |
public ArrayList getRasterFilterList() { |
111 |
ArrayList filters = new ArrayList(); |
112 |
filters.add(MedianFilter.class); |
113 |
return filters;
|
114 |
} |
115 |
|
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
|
119 |
*/
|
120 |
public void addFilter(Class classFilter, Params params) { |
121 |
if (classFilter.equals(MedianFilter.class)) {
|
122 |
int ladoVentana = 0; |
123 |
for (int i = 0; i < params.getNumParams(); i++) { |
124 |
if (params.getParam(i).id.equals("LadoVentana")) |
125 |
ladoVentana = new Integer(params.getParam(i).defaultValue).intValue(); |
126 |
} |
127 |
addMedianFilter(ladoVentana); |
128 |
} |
129 |
} |
130 |
} |