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 / convolution / ConvolutionListManager.java @ 2443

History | View | Annotate | Download (5.64 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.convolution;
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.fmap.dal.coverage.grid.RegistrableFilterListener;
33
import org.gvsig.raster.impl.datastruct.Kernel;
34
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
35
import org.gvsig.raster.impl.store.ParamImpl;
36
/**
37
 * Gestion  de la lista de filtros
38
 */
39
public class ConvolutionListManager extends AbstractRasterFilterManager {
40
        private static String   ID = "Convolucion";
41
        
42
        /**
43
         * Default constructor. Sets the filter list.
44
         * @param filterList
45
         */
46
        public ConvolutionListManager(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, ConvolutionListManager.class, ConvolutionUI.class);
56
        }
57
        
58
        public boolean isDataTypeSupported(int dataType) {
59
                return true;
60
        }
61
        
62
        public Class<?> getFilterClassByID(String id) {
63
                if( id.compareTo("media") == 0 ||
64
                        id.compareTo("pasobajo") == 0 ||
65
                        id.compareTo("sharpen") == 0 ||
66
                        id.compareTo("gauss") == 0 ||
67
                        id.compareTo("personalizado") == 0)
68
                        return ConvolutionFilter.class;
69
                return null;
70
        }
71
        
72
        public ConvolutionListManager(RasterFilterListManagerImpl filterListManager) {
73
                super(filterListManager.getFilterList());
74
        }
75

    
76
        /**
77
         * A?ade un filtro de convolucion  a la pila de filtros.
78
         * @param ladoVentana
79
         * @throws FilterTypeException
80
         */
81
        public void addConvolutionFilter(String Name,int ladoVentana, double agudeza, Kernel kernel) throws FilterTypeException {
82
                RasterFilter filter = new ConvolutionByteFilter();
83

    
84
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
85
                if (filter != null) {
86
                        filter.addParam("ladoVentana", Integer.valueOf(ladoVentana));
87
                        filter.addParam("Agudeza", Double.valueOf(agudeza));
88
                        filter.addParam("filterName", String.valueOf(Name));
89
                        filter.addParam("kernel", kernel);
90
                        getFilterList().add(filter);
91
                }
92
        }
93

    
94
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
95
                if (ConvolutionFilter.class.isAssignableFrom(classFilter)) {
96
                        int ladoVentana = 0;
97
                        double agudeza = 0;
98
                        Kernel kernel = null;
99
                        String name = "";
100
                        for (int i = 0; i < params.getNumParams(); i++) {
101
                                if (((ParamImpl)params.getParam(i)).getId().equals("Panel") &&
102
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof RegistrableFilterListener) {
103
                                        params = ((RegistrableFilterListener) ((ParamImpl)params.getParam(i)).getDefaultValue()).getParams();
104
                                        break;
105
                                }
106
                        }
107

    
108
                        for (int i = 0; i < params.getNumParams(); i++) {
109
                                if (((ParamImpl)params.getParam(i)).getId().equals("LadoVentana") &&
110
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
111
                                        ladoVentana = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
112

    
113
                                if (((ParamImpl)params.getParam(i)).getId().equals("FilterName")) {
114
                                        Object obj = ((ParamImpl)params.getParam(i)).getDefaultValue();
115
                                        if(obj != null)
116
                                                name = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue());
117
                                }
118

    
119
                                if (((ParamImpl)params.getParam(i)).getId().equals("Kernel") &&
120
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Kernel)
121
                                        kernel = (Kernel) ((ParamImpl)params.getParam(i)).getDefaultValue();
122

    
123
                                if (((ParamImpl)params.getParam(i)).getId().equals("Agudeza") &&
124
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
125
                                        agudeza = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
126
                        }
127
                        addConvolutionFilter(name, ladoVentana, agudeza, kernel);
128
                }
129
        }
130
        
131
        public void addFilter(Params params) throws FilterTypeException {
132
                addFilter(ConvolutionFilter.class, params);
133
        }
134
        
135
        public RasterFilter createFilter(Params params) {
136
                Integer ladoVentana = ((Integer) params.getParamById("LadoVentana").getDefaultValue());
137
                String name = ((String) params.getParamById("FilterName").getDefaultValue());
138
                Kernel kernel = ((Kernel) params.getParamById("Kernel").getDefaultValue());
139
                Double agudeza = ((Double) params.getParamById("Agudeza").getDefaultValue());
140
                
141
                RasterFilter filter = new ConvolutionByteFilter();
142
                filter.addParam("LadoVentana", ladoVentana);
143
                filter.addParam("Agudeza", agudeza);
144
                filter.addParam("filterName", name);
145
                filter.addParam("kernel", kernel);
146
                return filter;
147
        }
148

    
149
        public List<Class<?>> getRasterFilterList() {
150
                List<Class<?>> filters = new ArrayList<Class<?>>();
151
                filters.add(ConvolutionFilter.class);
152
                return filters;
153
        }
154
}