Statistics
| Revision:

gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / correction / MedianListManager.java @ 2341

History | View | Annotate | Download (4.85 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.correction;
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 mediana.
36
 *
37
 * @author Diego Guerrero Sevilla  <diego.guerrero@uclm.es>
38
 */
39
public class MedianListManager extends AbstractRasterFilterManager {
40
        private static String   ID = "Median";
41
        
42
        /**
43
         * Default constructor. Sets the filter list.
44
         * @param filterList
45
         */
46
        public MedianListManager(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, MedianListManager.class);
56
        }
57
        
58
        /**
59
         * Constructor. Asigna la lista de filtros y el manager.
60
         * @param filterListManager
61
         */
62
        public MedianListManager(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("median") == 0)
72
                        return MedianFilter.class;
73
                return null;
74
        }
75

    
76
        /**
77
         * A?ade un filtro de mediana a la pila de filtros.
78
         * @param ladoVentana
79
         * @throws FilterTypeException
80
         */
81
        public void addMedianFilter(int ladoVentana) throws FilterTypeException {
82
                RasterFilter filter = new MedianByteFilter();
83

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

    
86
                if (filter != null) {
87
                        filter.addParam("ladoVentana", new Integer(ladoVentana));
88
                        getFilterList().add(filter);
89
                }
90
        }
91

    
92
        /*public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
93
                if (rf instanceof MedianFilter) {
94
                        filterList.add("filter.median.active=true");
95
                        MedianFilter medianFilter = (MedianFilter) rf;
96
                        filterList.add("filter.median.ladoVentana=" + medianFilter.getSideWindow());
97
                }
98

99
                return filterList;
100
        }
101

102
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException {
103
                if ((fil.startsWith("filter.median.active")) && (RasterFilterListManagerImpl.getValue(fil).equals("true"))) {
104

105
                        int ladoVentana = 0;
106
                        filters.remove(0);
107

108
                        for (int prop = 0; prop < filters.size(); prop++) {
109
                                String elem = (String) filters.get(prop);
110
                                if (elem.startsWith("filter.median.ladoVentana")) {
111
                                        ladoVentana = Integer.parseInt(RasterFilterListManagerImpl.getValue(elem));
112
                                        filters.remove(prop);
113
                                        prop--;
114
                                }
115
                        }
116
                        addMedianFilter(ladoVentana);
117
                }
118
                return filteri;
119
        }*/
120

    
121
        public List<Class<?>> getRasterFilterList() {
122
                List<Class<?>> filters = new ArrayList<Class<?>>();
123
                filters.add(MedianFilter.class);
124
                return filters;
125
        }
126

    
127
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
128
                if (MedianFilter.class.isAssignableFrom(classFilter)) {
129
                        int ladoVentana = 0;
130
                        for (int i = 0; i < params.getNumParams(); i++) {
131
                                if (((ParamImpl)params.getParam(i)).getId().equals("ladoVentana") &&
132
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
133
                                        ladoVentana = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
134
                        }
135
                        addMedianFilter(ladoVentana);
136
                }
137
        }
138
        
139
        public void addFilter(Params params) throws FilterTypeException {
140
                addFilter(MedianFilter.class, params);
141
        }
142
        
143
        public RasterFilter createFilter(Params params) {
144
                if(        params.getParamById("ladoVentana") != null) {
145
                        int ladoVentana = ((Integer) params.getParamById("ladoVentana").getDefaultValue()).intValue();
146
                        RasterFilter filter = new MedianByteFilter();
147
                        filter.addParam("ladoVentana", new Integer(ladoVentana));
148
                        return filter;
149
                }
150
                return null;
151
        }
152
}