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 @ 2341
History | View | Annotate | Download (5.67 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 |
* @deprecated Exists a plugin with a process which include this functionality
|
44 |
*/
|
45 |
public class MaskListManager extends AbstractRasterFilterManager { |
46 |
public static String ID = "Mask"; |
47 |
|
48 |
/**
|
49 |
* Default constructor. Sets the filter list.
|
50 |
* @param filterList
|
51 |
*/
|
52 |
public MaskListManager(RasterFilterList filterList) {
|
53 |
super(filterList);
|
54 |
} |
55 |
|
56 |
public String getManagerID() { |
57 |
return ID;
|
58 |
} |
59 |
|
60 |
public static void register() { |
61 |
AbstractRasterFilterManager.register(ID, MaskListManager.class, MaskUI.class); |
62 |
} |
63 |
|
64 |
public boolean isDataTypeSupported(int dataType) { |
65 |
return true; |
66 |
} |
67 |
|
68 |
public Class<?> getFilterClassByID(String id) { |
69 |
if( id.compareTo("mask") == 0) |
70 |
return MaskFilter.class;
|
71 |
return null; |
72 |
} |
73 |
|
74 |
/**
|
75 |
* A?ade un filtro de m?scara
|
76 |
* @param rois Lista de ROIs
|
77 |
* @param noData Valor a asignar fuera de las ROI
|
78 |
* @param inverse Inversa
|
79 |
* @throws FilterTypeException
|
80 |
*/
|
81 |
public void addMaskFilter(List<ROI> rois, NoData noData, Boolean inverse, Boolean transp) throws FilterTypeException { |
82 |
RasterFilter filter = new MaskByteFilter();
|
83 |
|
84 |
//Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
85 |
if (filter != null) { |
86 |
filter.addParam("rois", rois);
|
87 |
filter.addParam("nodata", noData);
|
88 |
filter.addParam("inverse", inverse);
|
89 |
filter.addParam("transparency", transp);
|
90 |
getFilterList().add(filter); |
91 |
} |
92 |
} |
93 |
|
94 |
public List<Class<?>> getRasterFilterList() { |
95 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
96 |
filters.add(MaskFilter.class); |
97 |
return filters;
|
98 |
} |
99 |
|
100 |
@SuppressWarnings("unchecked") |
101 |
public RasterFilter createFilter(Params params) {
|
102 |
ArrayList<ROI> rois = ((ArrayList<ROI>) params.getParamById("rois").getDefaultValue()); |
103 |
NoData nodata = ((NoData) params.getParamById("nodata").getDefaultValue());
|
104 |
Boolean inverse = ((Boolean) params.getParamById("inverse").getDefaultValue()); |
105 |
Boolean transparency = ((Boolean) params.getParamById("transparency").getDefaultValue()); |
106 |
|
107 |
RasterFilter filter = new MaskByteFilter();
|
108 |
filter.addParam("rois", rois);
|
109 |
filter.addParam("inverse", inverse);
|
110 |
filter.addParam("transparency", transparency);
|
111 |
filter.addParam("nodata", nodata);
|
112 |
return filter;
|
113 |
} |
114 |
|
115 |
public void addFilter(Params params) throws FilterTypeException { |
116 |
addFilter(MaskFilter.class, params); |
117 |
} |
118 |
|
119 |
@SuppressWarnings("unchecked") |
120 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
121 |
if (classFilter.equals(MaskFilter.class)) {
|
122 |
ArrayList<ROI> rois = new ArrayList<ROI>(); |
123 |
Boolean inverse = new Boolean(false); |
124 |
Boolean transp = new Boolean(false); |
125 |
NoData nodata = RasterLocator.getManager().getDataStructFactory().createNoData(null, null, null, 1); |
126 |
|
127 |
Params paramsUI = null;
|
128 |
for (int i = 0; i < params.getNumParams(); i++) { |
129 |
if (params.getParam(i).getId().equals("Panel") && |
130 |
params.getParam(i).getDefaultValue() instanceof RegistrableFilterListener) {
|
131 |
paramsUI = ((RegistrableFilterListener) params.getParam(i).getDefaultValue()).getParams(); |
132 |
} |
133 |
} |
134 |
|
135 |
if (paramsUI != null) { |
136 |
for (int i = 0; i < paramsUI.getNumParams(); i++) { |
137 |
if (paramsUI.getParam(i).getId().equals("rois")) |
138 |
rois = (ArrayList<ROI>) paramsUI.getParam(i).getDefaultValue();
|
139 |
if (paramsUI.getParam(i).getId().equals("inverse")) |
140 |
inverse = (Boolean) paramsUI.getParam(i).getDefaultValue();
|
141 |
if (paramsUI.getParam(i).getId().equals("nodata")) |
142 |
nodata = (NoData) paramsUI.getParam(i).getDefaultValue(); |
143 |
if (paramsUI.getParam(i).getId().equals("transparency")) |
144 |
transp = (Boolean) paramsUI.getParam(i).getDefaultValue();
|
145 |
} |
146 |
} |
147 |
addMaskFilter(rois, nodata, inverse, transp); |
148 |
} |
149 |
} |
150 |
|
151 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
152 |
return filteri;
|
153 |
} |
154 |
|
155 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
156 |
return filterList;
|
157 |
} |
158 |
} |