Statistics
| Revision:

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 / segmentation / FirstDerivativeListManager.java @ 2443

History | View | Annotate | Download (5.08 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.segmentation;
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.AbstractRasterFilterManager;
30
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
32
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
33
import org.gvsig.raster.impl.store.ParamImpl;
34
/**
35
 * Gestor de la pila de filtros para el filtro de primera derivada.
36
 *
37
 * @author Diego Guerrero Sevilla  <diego.guerrero@uclm.es>
38
 */
39
public class FirstDerivativeListManager extends AbstractRasterFilterManager {
40
        private static String   ID = "FirstDerivative";
41
        
42
        /**
43
         * Default constructor. Sets the filter list.
44
         * @param filterList
45
         */
46
        public FirstDerivativeListManager(RasterFilterList filterList) {
47
                super(filterList);
48
        }
49
        
50
        public String getManagerID() {
51
                return ID;
52
        }
53

    
54
        public static void register() {
55
                AbstractRasterFilterManager.register(ID, FirstDerivativeListManager.class);
56
        }
57
        
58
        /**
59
         * Constructor. Asigna la lista de filtros y el manager.
60
         * @param filterListManager
61
         */
62
        public FirstDerivativeListManager(RasterFilterListManagerImpl filterListManager) {
63
                super(filterListManager.getFilterList());
64
        }
65
        
66
        public boolean isDataTypeSupported(int dataType) {
67
                return true;
68
        }
69
        
70
        public Class<?> getFilterClassByID(String id) {
71
                if( id.compareTo("sobel") == 0 ||
72
                        id.compareTo("roberts") == 0 ||
73
                        id.compareTo("prewitt") == 0 ||
74
                        id.compareTo("freichen") == 0)
75
                        return FirstDerivativeFilter.class;
76
                return null;
77
        }
78

    
79
        /**
80
         * A?ade un filtro de convoluc?n a la pila de filtros.
81
         * @param Name Nombre del filtro
82
         * @param umbral
83
         * @param operator
84
         * @param compare
85
         * @param Name
86
         * @throws FilterTypeException
87
         */
88
        public void addFirstDerivativeFilter(int umbral, boolean compare, String Name) throws FilterTypeException {
89
                RasterFilter filter = new FirstDerivativeByteFilter();
90

    
91
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
92

    
93
                if (filter != null) {
94
                        filter.addParam("umbral", new Integer(umbral));
95
                        filter.addParam("compare", new Boolean(compare));
96
                        filter.addParam("filterName", new String(Name));
97
                        filter.setName(Name);
98
                        getFilterList().add(filter);
99
                }
100
        }
101

    
102
        public List<Class<?>> getRasterFilterList() {
103
                List<Class<?>> filters = new ArrayList<Class<?>>();
104
                filters.add(FirstDerivativeFilter.class);
105
                return filters;
106
        }
107

    
108
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
109
                if (FirstDerivativeFilter.class.isAssignableFrom(classFilter)) {
110
                        int umbral = 0;
111
                        boolean compare = false;
112
                        String name = "";
113
                        for (int i = 0; i < params.getNumParams(); i++) {
114
                                if (((ParamImpl)params.getParam(i)).getId().equals("Umbral") &&
115
                                        ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
116
                                        umbral = ((Integer)((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
117
                                if (((ParamImpl)params.getParam(i)).getId().equals("Compare") &&
118
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Boolean)
119
                                        compare = ((Boolean)((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
120
                                if (((ParamImpl)params.getParam(i)).getId().equals("FilterName") &&
121
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String)
122
                                        name = (String)((ParamImpl)params.getParam(i)).getDefaultValue();
123
                        }
124
                        addFirstDerivativeFilter(umbral, compare, name);
125
                }
126
        }
127
        
128
        public void addFilter(Params params) throws FilterTypeException {
129
                addFilter(FirstDerivativeFilter.class, params);
130
        }
131
        
132
        public RasterFilter createFilter(Params params) {
133
                if(        params.getParamById("Umbral") != null) {
134
                        Integer umbral = ((Integer) params.getParamById("Umbral").getDefaultValue());
135
                        Boolean compare = ((Boolean) params.getParamById("Compare").getDefaultValue());
136
                        String name = ((String) params.getParamById("FilterName").getDefaultValue());
137
                        
138
                        RasterFilter filter = new FirstDerivativeByteFilter();
139
                        filter.addParam("umbral", new Integer(umbral));
140
                        filter.addParam("compare", new Boolean(compare));
141
                        filter.addParam("filterName", new String(name));
142
                        return filter;
143
                }
144
                return null;
145
        }
146
}