root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / segmentation / FirstDerivativeStackManager.java @ 8026
History | View | Annotate | Download (5.45 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 |
|
20 |
package org.cresques.filter.segmentation; |
21 |
|
22 |
import java.util.ArrayList; |
23 |
|
24 |
import org.cresques.filter.IStackManager; |
25 |
import org.cresques.filter.RasterFilter; |
26 |
import org.cresques.filter.RasterFilterStack; |
27 |
import org.cresques.filter.RasterFilterStackManager; |
28 |
import org.cresques.io.GeoRasterFile; |
29 |
import org.cresques.io.data.RasterBuf; |
30 |
|
31 |
/**
|
32 |
* Gestor de la pila de filtros para el filtro de Sobel.
|
33 |
*
|
34 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
35 |
*
|
36 |
*/
|
37 |
|
38 |
public class FirstDerivativeStackManager implements IStackManager { |
39 |
|
40 |
public final static int firstDerivative = 12; |
41 |
protected RasterFilterStack filterStack = null; |
42 |
private RasterFilterStackManager filterStackManager = null; |
43 |
private GeoRasterFile[] grfList = null; |
44 |
|
45 |
|
46 |
public FirstDerivativeStackManager(RasterFilterStackManager filterStackManager) {
|
47 |
this.filterStackManager = filterStackManager;
|
48 |
this.filterStack = filterStackManager.getFilterStack();
|
49 |
filterStackManager.addTypeFilter("firstDerivative", FirstDerivativeStackManager.firstDerivative, 8); |
50 |
} |
51 |
|
52 |
/**
|
53 |
* A�ade un filtro de convoluci�n a la pila de filtros.
|
54 |
* @param kernel
|
55 |
*/
|
56 |
public void addFirstDerivativeFilter(int umbral,int operator,boolean compare,String Name){ |
57 |
|
58 |
RasterFilter filtro = null;
|
59 |
|
60 |
switch(filterStack.getDataTypeInFilter(((Integer)this.filterStackManager.getTypeFilters().get("firstDerivative")).intValue())){ |
61 |
case RasterBuf.TYPE_IMAGE:
|
62 |
filtro = new FirstDerivativeImageFilter(Name); |
63 |
break;
|
64 |
case RasterBuf.TYPE_SHORT:
|
65 |
filtro = new FirstDerivativeShortFilter(Name); |
66 |
break;
|
67 |
case RasterBuf.TYPE_USHORT:
|
68 |
filtro = new FirstDerivativeShortFilter(Name); |
69 |
break;
|
70 |
case RasterBuf.TYPE_INT:
|
71 |
filtro = new FirstDerivativeIntegerFilter(Name); |
72 |
break;
|
73 |
case RasterBuf.TYPE_FLOAT:
|
74 |
filtro = new FirstDerivativeFloatFilter(Name); |
75 |
break;
|
76 |
case RasterBuf.TYPE_DOUBLE:
|
77 |
filtro = new FirstDerivativeDoubleFilter(Name); |
78 |
break;
|
79 |
} |
80 |
|
81 |
//Cuando el filtro esta creado, tomamos los valores y lo a�adimos a la pila
|
82 |
|
83 |
if(filtro != null){ |
84 |
filtro.addParam("umbral",new Integer(umbral)); |
85 |
filtro.addParam("compare",new Boolean(compare)); |
86 |
filtro.addParam("operator",new Integer(operator)); |
87 |
filterStack.addFilter(((Integer) filterStackManager.getTypeFilters().get("firstDerivative")).intValue(), filtro); |
88 |
filterStackManager.controlTypes(); |
89 |
} |
90 |
} |
91 |
|
92 |
public ArrayList getStringsFromStack() { |
93 |
// TODO Auto-generated method stub
|
94 |
return null; |
95 |
} |
96 |
|
97 |
public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) { |
98 |
if(rf instanceof FirstDerivativeFilter){ |
99 |
filterList.add("filter.firstDerivative.active=true");
|
100 |
FirstDerivativeFilter firstDerivative = (FirstDerivativeFilter) rf; |
101 |
filterList.add("filter.firstDerivative.umbral="+firstDerivative.umbral);
|
102 |
filterList.add("filter.firstDerivative.operartor="+firstDerivative.operator);
|
103 |
filterList.add("filter.firstDerivative.compare="+firstDerivative.compare);
|
104 |
filterList.add("filter.firstDerivative.filterName="+firstDerivative.getFilterName());
|
105 |
} |
106 |
return filterList;
|
107 |
} |
108 |
|
109 |
public void createStackFromStrings(ArrayList f, Integer pos) { |
110 |
// TODO Auto-generated method stub
|
111 |
|
112 |
} |
113 |
|
114 |
public int createStackFromStrings(ArrayList filters, String fil, |
115 |
GeoRasterFile[] grfList, int filteri) { |
116 |
this.grfList = grfList;
|
117 |
|
118 |
if((fil.startsWith("filter.firstDerivative.active"))&& |
119 |
(RasterFilterStackManager.getValue(fil).equals("true"))){
|
120 |
|
121 |
int umbral = 0; |
122 |
boolean compare = false; |
123 |
int operator = 0; |
124 |
String name=""; |
125 |
filters.remove(0);
|
126 |
|
127 |
for(int prop = 0; prop < filters.size() ; prop++){ |
128 |
String elem = (String) filters.get(prop); |
129 |
if(elem.startsWith("filter.firstDerivative.umbral")){ |
130 |
umbral = Integer.parseInt(RasterFilterStackManager.getValue(elem));
|
131 |
filters.remove(prop); |
132 |
prop--; |
133 |
} |
134 |
if(elem.startsWith("filter.firstDerivative.compare")){ |
135 |
compare = Boolean.getBoolean(RasterFilterStackManager.getValue(elem));
|
136 |
filters.remove(prop); |
137 |
prop--; |
138 |
} |
139 |
if(elem.startsWith("filter.firstDerivative.operartor")){ |
140 |
operator = Integer.parseInt(RasterFilterStackManager.getValue(elem));
|
141 |
filters.remove(prop); |
142 |
prop--; |
143 |
} |
144 |
if(elem.startsWith("filter.firstDerivative.filterName")){ |
145 |
name = RasterFilterStackManager.getValue(elem); |
146 |
filters.remove(prop); |
147 |
prop--; |
148 |
} |
149 |
} |
150 |
addFirstDerivativeFilter(umbral,operator,compare,name); |
151 |
} |
152 |
//return filteri;
|
153 |
return -1; |
154 |
} |
155 |
|
156 |
/**
|
157 |
* Obtiene el valor entero que corresponde al tipo de filtro.
|
158 |
* @param rasterFilter
|
159 |
* @return
|
160 |
*/
|
161 |
public int getType(RasterFilter rasterFilter){ |
162 |
if(rasterFilter instanceof FirstDerivativeFilter) |
163 |
return FirstDerivativeStackManager.firstDerivative;
|
164 |
|
165 |
return -1; |
166 |
} |
167 |
|
168 |
} |