Statistics
| Revision:

gvsig-raster / org.gvsig.raster.tools / branches / org.gvsig.raster.tools_dataaccess_refactoring / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / mask / MaskListManager.java @ 2328

History | View | Annotate | Download (5.58 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.tools.app.basic.tool.filter.mask;
23

    
24
import java.util.ArrayList;
25
import java.util.List;
26

    
27
import org.gvsig.fmap.dal.coverage.RasterLocator;
28
import org.gvsig.fmap.dal.coverage.datastruct.NoData;
29
import org.gvsig.fmap.dal.coverage.datastruct.Params;
30
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
31
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
33
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
34
import org.gvsig.fmap.dal.coverage.grid.RegistrableFilterListener;
35
import org.gvsig.raster.roi.ROI;
36

    
37
/**
38
 * Gestor de los filtros de mascara. Los filtros de m?scara generan una
39
 * capa enmascarando con regiones de inter?s. Las zonas fuera del ROI se
40
 * pondr?n a NoData.
41
 *
42
 * @author Nacho Brodin nachobrodin@gmail.com
43
 */
44
public class MaskListManager extends AbstractRasterFilterManager {
45
        private static String   ID = "Mask";
46
        
47
        /**
48
         * Default constructor. Sets the filter list.
49
         * @param filterList
50
         */
51
        public MaskListManager(RasterFilterList filterList) {
52
                super(filterList);
53
        }
54
        
55
        public String getManagerID() {
56
                return ID;
57
        }
58

    
59
        public static void register() {
60
                AbstractRasterFilterManager.register(ID, MaskListManager.class);
61
        }
62
        
63
        public boolean isDataTypeSupported(int dataType) {
64
                return true;
65
        }
66
        
67
        public Class<?> getFilterClassByID(String id) {
68
                if( id.compareTo("mask") == 0)
69
                        return MaskFilter.class;
70
                return null;
71
        }
72

    
73
        /**
74
         * A?ade un filtro de m?scara
75
         * @param rois Lista de ROIs
76
         * @param noData Valor a asignar fuera de las ROI
77
         * @param inverse Inversa
78
         * @throws FilterTypeException
79
         */
80
        public void addMaskFilter(List<ROI> rois, NoData noData, Boolean inverse, Boolean transp) throws FilterTypeException {
81
                RasterFilter filter = new MaskByteFilter();
82

    
83
                //Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
84
                if (filter != null) {
85
                        filter.addParam("rois", rois);
86
                        filter.addParam("nodata", noData);
87
                        filter.addParam("inverse", inverse);
88
                        filter.addParam("transparency", transp);
89
                        getFilterList().add(filter);
90
                }
91
        }
92

    
93
        public List<Class<?>> getRasterFilterList() {
94
                List<Class<?>> filters = new ArrayList<Class<?>>();
95
                filters.add(MaskFilter.class);
96
                return filters;
97
        }
98
        
99
        @SuppressWarnings("unchecked")
100
        public RasterFilter createFilter(Params params) {
101
                ArrayList<ROI> rois = ((ArrayList<ROI>) params.getParamById("rois").getDefaultValue());
102
                NoData nodata = ((NoData) params.getParamById("nodata").getDefaultValue());
103
                Boolean inverse = ((Boolean) params.getParamById("inverse").getDefaultValue());
104
                Boolean transparency = ((Boolean) params.getParamById("transparency").getDefaultValue());
105
                
106
                RasterFilter filter = new MaskByteFilter();
107
                filter.addParam("rois", rois);
108
                filter.addParam("inverse", inverse);
109
                filter.addParam("transparency", transparency);
110
                filter.addParam("nodata", nodata);
111
                return filter;
112
        }
113
        
114
        public void addFilter(Params params) throws FilterTypeException {
115
                addFilter(MaskFilter.class, params);
116
        }
117

    
118
        @SuppressWarnings("unchecked")
119
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
120
                if (classFilter.equals(MaskFilter.class)) {
121
                        ArrayList<ROI> rois = new ArrayList<ROI>();
122
                        Boolean inverse = new Boolean(false);
123
                        Boolean transp = new Boolean(false);
124
                        NoData nodata = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, null, 1);
125

    
126
                        Params paramsUI = null;
127
                        for (int i = 0; i < params.getNumParams(); i++) {
128
                                if (params.getParam(i).getId().equals("Panel") &&
129
                                        params.getParam(i).getDefaultValue() instanceof RegistrableFilterListener) {
130
                                        paramsUI = ((RegistrableFilterListener) params.getParam(i).getDefaultValue()).getParams();
131
                                }
132
                        }
133

    
134
                        if (paramsUI != null) {
135
                                for (int i = 0; i < paramsUI.getNumParams(); i++) {
136
                                        if (paramsUI.getParam(i).getId().equals("rois"))
137
                                                rois = (ArrayList<ROI>) paramsUI.getParam(i).getDefaultValue();
138
                                        if (paramsUI.getParam(i).getId().equals("inverse"))
139
                                                inverse = (Boolean) paramsUI.getParam(i).getDefaultValue();
140
                                        if (paramsUI.getParam(i).getId().equals("nodata"))
141
                                                nodata = (NoData) paramsUI.getParam(i).getDefaultValue();
142
                                        if (paramsUI.getParam(i).getId().equals("transparency"))
143
                                                transp = (Boolean) paramsUI.getParam(i).getDefaultValue();
144
                                }
145
                        }
146
                        addMaskFilter(rois, nodata, inverse, transp);
147
                }
148
        }
149

    
150
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException {
151
                return filteri;
152
        }
153

    
154
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
155
                return filterList;
156
        }
157
}