root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / segmentation / FirstDerivativeListManager.java @ 17108
History | View | Annotate | Download (5.95 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.segmentation; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.raster.dataset.Params; |
24 |
import org.gvsig.raster.grid.filter.FilterTypeException; |
25 |
import org.gvsig.raster.grid.filter.IRasterFilterListManager; |
26 |
import org.gvsig.raster.grid.filter.RasterFilter; |
27 |
import org.gvsig.raster.grid.filter.RasterFilterList; |
28 |
import org.gvsig.raster.grid.filter.RasterFilterListManager; |
29 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
30 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
31 |
/**
|
32 |
* Gestor de la pila de filtros para el filtro de primera derivada.
|
33 |
*
|
34 |
* @version 04/06/2007
|
35 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
36 |
*/
|
37 |
public class FirstDerivativeListManager implements IRasterFilterListManager { |
38 |
protected RasterFilterList filterList = null; |
39 |
//private RasterFilterListManager filterListManager = null;
|
40 |
|
41 |
/**
|
42 |
* Constructor. Asigna la lista de filtros y el manager.
|
43 |
* @param filterListManager
|
44 |
*/
|
45 |
public FirstDerivativeListManager(RasterFilterListManager filterListManager) {
|
46 |
//this.filterListManager = filterListManager;
|
47 |
this.filterList = filterListManager.getFilterList();
|
48 |
} |
49 |
|
50 |
public static void register() { |
51 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
52 |
extensionPoints.add("RasterFilter", "FirstDerivative", FirstDerivativeListManager.class); |
53 |
} |
54 |
|
55 |
/**
|
56 |
* A?ade un filtro de convoluc?n a la pila de filtros.
|
57 |
* @param Name Nombre del filtro
|
58 |
* @param umbral
|
59 |
* @param operator
|
60 |
* @param compare
|
61 |
* @param Name
|
62 |
* @throws FilterTypeException
|
63 |
*/
|
64 |
public void addFirstDerivativeFilter(int umbral, boolean compare, String Name) throws FilterTypeException { |
65 |
RasterFilter filter = new FirstDerivativeByteFilter();
|
66 |
|
67 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
68 |
|
69 |
if (filter != null) { |
70 |
filter.addParam("umbral", new Integer(umbral)); |
71 |
filter.addParam("compare", new Boolean(compare)); |
72 |
filter.addParam("filterName", new String(Name)); |
73 |
filter.setName(Name);
|
74 |
filterList.add(filter); |
75 |
} |
76 |
} |
77 |
|
78 |
/*
|
79 |
* (non-Javadoc)
|
80 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList, org.gvsig.raster.grid.filter.RasterFilter)
|
81 |
*/
|
82 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
83 |
if (rf instanceof FirstDerivativeFilter) { |
84 |
filterList.add("filter.firstDerivative.active=true");
|
85 |
FirstDerivativeFilter firstDerivative = (FirstDerivativeFilter) rf; |
86 |
filterList.add("filter.firstDerivative.umbral=" + firstDerivative.umbral);
|
87 |
filterList.add("filter.firstDerivative.compare=" + firstDerivative.compare);
|
88 |
filterList.add("filter.firstDerivative.filterName=" + firstDerivative.getName());
|
89 |
} |
90 |
|
91 |
return filterList;
|
92 |
} |
93 |
|
94 |
/*
|
95 |
* (non-Javadoc)
|
96 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
97 |
*/
|
98 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) throws FilterTypeException { |
99 |
if ((fil.startsWith("filter.firstDerivative.active")) && (RasterFilterListManager.getValue(fil).equals("true"))) { |
100 |
|
101 |
int umbral = 0; |
102 |
boolean compare = false; |
103 |
String name = ""; |
104 |
filters.remove(0);
|
105 |
|
106 |
for (int prop = 0; prop < filters.size(); prop++) { |
107 |
String elem = (String) filters.get(prop); |
108 |
if (elem.startsWith("filter.firstDerivative.umbral")) { |
109 |
umbral = Integer.parseInt(RasterFilterListManager.getValue(elem));
|
110 |
filters.remove(prop); |
111 |
prop--; |
112 |
} |
113 |
if (elem.startsWith("filter.firstDerivative.compare")) { |
114 |
compare = Boolean.getBoolean(RasterFilterListManager.getValue(elem));
|
115 |
filters.remove(prop); |
116 |
prop--; |
117 |
} |
118 |
if (elem.startsWith("filter.firstDerivative.filterName")) { |
119 |
name = RasterFilterListManager.getValue(elem); |
120 |
filters.remove(prop); |
121 |
prop--; |
122 |
} |
123 |
} |
124 |
addFirstDerivativeFilter(umbral, compare, name); |
125 |
} |
126 |
return filteri;
|
127 |
} |
128 |
|
129 |
/*
|
130 |
* (non-Javadoc)
|
131 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
|
132 |
*/
|
133 |
public ArrayList getRasterFilterList() { |
134 |
ArrayList filters = new ArrayList(); |
135 |
filters.add(FirstDerivativeFilter.class); |
136 |
return filters;
|
137 |
} |
138 |
|
139 |
/*
|
140 |
* (non-Javadoc)
|
141 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
|
142 |
*/
|
143 |
public void addFilter(Class classFilter, Params params) throws FilterTypeException { |
144 |
if (classFilter.equals(FirstDerivativeFilter.class)) {
|
145 |
int umbral = 0; |
146 |
boolean compare = false; |
147 |
String name = ""; |
148 |
for (int i = 0; i < params.getNumParams(); i++) { |
149 |
if (params.getParam(i).id.equals("Umbral") && |
150 |
params.getParam(i).defaultValue instanceof Integer) |
151 |
umbral = ((Integer)params.getParam(i).defaultValue).intValue();
|
152 |
if (params.getParam(i).id.equals("Compare") && |
153 |
params.getParam(i).defaultValue instanceof Boolean) |
154 |
compare = ((Boolean)params.getParam(i).defaultValue).booleanValue();
|
155 |
if (params.getParam(i).id.equals("FilterName") && |
156 |
params.getParam(i).defaultValue instanceof String) |
157 |
name = (String)params.getParam(i).defaultValue;
|
158 |
} |
159 |
addFirstDerivativeFilter(umbral, compare, name); |
160 |
} |
161 |
} |
162 |
} |