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