svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / filter / mask / MaskFilter.java @ 19894
History | View | Annotate | Download (5.81 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2005 IVER T.I. and Generalitat Valenciana.
|
4 |
*
|
5 |
* This program is free software; you can redistribute it and/or
|
6 |
* modify it under the terms of the GNU General Public License
|
7 |
* as published by the Free Software Foundation; either version 2
|
8 |
* of the License, or (at your option) any later version.
|
9 |
*
|
10 |
* This program is distributed in the hope that it will be useful,
|
11 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
12 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
13 |
* GNU General Public License for more details.
|
14 |
*
|
15 |
* You should have received a copy of the GNU General Public License
|
16 |
* along with this program; if not, write to the Free Software
|
17 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
18 |
*/
|
19 |
package org.gvsig.raster.filter.mask; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
24 |
import org.gvsig.raster.buffer.RasterBuffer; |
25 |
import org.gvsig.raster.dataset.IBuffer; |
26 |
import org.gvsig.raster.dataset.MultiRasterDataset; |
27 |
import org.gvsig.raster.dataset.Params; |
28 |
import org.gvsig.raster.grid.GridExtent; |
29 |
import org.gvsig.raster.grid.filter.RasterFilter; |
30 |
|
31 |
/**
|
32 |
* Filtro que aplica una m?scara con la lista de ROIS. Los p?xeles dentro
|
33 |
* de la ROI se ponen al valor de la imagen de origen. Los p?xeles fuera
|
34 |
* de la ROI se ponen a NoData.
|
35 |
*
|
36 |
* 14/03/2008
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com
|
38 |
*/
|
39 |
public class MaskFilter extends RasterFilter { |
40 |
public static String[] names = new String[] { "mask" }; |
41 |
protected MaskUI maskUI = null; |
42 |
protected ArrayList rois = null; |
43 |
protected double nodata = -99999; |
44 |
protected boolean inverse = false; |
45 |
|
46 |
/* Variables que hacen falta en el process */
|
47 |
protected GridExtent gridExtent = null; |
48 |
protected GridExtent windowExtent = null; |
49 |
protected MultiRasterDataset dataset = null; |
50 |
protected IBuffer rasterAlpha = null; |
51 |
|
52 |
/**
|
53 |
* Constructor
|
54 |
*/
|
55 |
public MaskFilter() {
|
56 |
super();
|
57 |
setName(names[0]);
|
58 |
} |
59 |
|
60 |
/*
|
61 |
* (non-Javadoc)
|
62 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
|
63 |
*/
|
64 |
public String getGroup() { |
65 |
return "mascaras"; |
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
|
71 |
*/
|
72 |
public String[] getNames() { |
73 |
return names;
|
74 |
} |
75 |
|
76 |
/*
|
77 |
* (non-Javadoc)
|
78 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
|
79 |
*/
|
80 |
public Object getResult(String name) { |
81 |
if (!name.equals("raster")) |
82 |
return null; |
83 |
|
84 |
if (!exec)
|
85 |
return (Object) this.raster; |
86 |
|
87 |
return (Object) this.rasterResult; |
88 |
} |
89 |
|
90 |
/*
|
91 |
* (non-Javadoc)
|
92 |
* @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams(java.lang.String)
|
93 |
*/
|
94 |
public Params getUIParams(String nameFilter) { |
95 |
Params params = new Params();
|
96 |
params.setParam("Panel", getMaskUI(), -1, null); |
97 |
params.setParam("FilterName", nameFilter, -1, null); |
98 |
return params;
|
99 |
} |
100 |
|
101 |
/**
|
102 |
* Obtiene el interfaz gr?fico para el filtro de m?scara.
|
103 |
* @return MaskUI
|
104 |
*/
|
105 |
private MaskUI getMaskUI() {
|
106 |
if (maskUI == null) { |
107 |
maskUI = new MaskUI();
|
108 |
FLyrRasterSE raster = (FLyrRasterSE) getEnv().get("initRaster");
|
109 |
maskUI.setRois(rois); |
110 |
maskUI.setLayer(raster); |
111 |
} |
112 |
return maskUI;
|
113 |
} |
114 |
|
115 |
/*
|
116 |
* (non-Javadoc)
|
117 |
* @see org.gvsig.raster.grid.filter.RasterFilter#pre()
|
118 |
*/
|
119 |
public void pre() { |
120 |
exec = true;
|
121 |
raster = rasterResult; |
122 |
raster = (RasterBuffer) params.get("raster");
|
123 |
Boolean inverseBoolean = (Boolean)params.get("inverse"); |
124 |
if(inverseBoolean != null) |
125 |
inverse = inverseBoolean.booleanValue(); |
126 |
Double nodataDouble = (Double)params.get("nodata"); |
127 |
if(nodataDouble != null) |
128 |
nodata = nodataDouble.doubleValue(); |
129 |
Boolean transpBoolean = (Boolean)params.get("transparency"); |
130 |
|
131 |
rois = (ArrayList) params.get("rois"); |
132 |
if (rois == null) |
133 |
rois = new ArrayList(); |
134 |
height = raster.getHeight(); |
135 |
width = raster.getWidth(); |
136 |
|
137 |
gridExtent = (GridExtent) environment.get("GridExtent");
|
138 |
windowExtent = (GridExtent) environment.get("WindowExtent");
|
139 |
dataset = (MultiRasterDataset) environment.get("MultiRasterDataset");
|
140 |
|
141 |
rasterResult = RasterBuffer.getBuffer(raster.getDataType(), raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
|
142 |
|
143 |
if(transpBoolean.booleanValue() && raster.getDataType() == IBuffer.TYPE_BYTE)
|
144 |
rasterAlpha = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), 1, true); |
145 |
} |
146 |
|
147 |
/**
|
148 |
* Obtiene el extent m?ximo de todas las ROIs
|
149 |
* @param rois Lista de ROIs para calcular la extensi?n m?xima que ocupan
|
150 |
* @return Entent m?ximo
|
151 |
*/
|
152 |
/*private Extent getMaximunExtent(ArrayList rois) {
|
153 |
double minx = 0, miny = 0, maxx = 0, maxy = 0;
|
154 |
for (int i = 0; i < rois.size(); i++) {
|
155 |
Extent ext = ((ROI) rois.get(i)).getGridExtent();
|
156 |
if(i == 0) {
|
157 |
minx = ext.minX();
|
158 |
miny = ext.minY();
|
159 |
maxx = ext.maxX();
|
160 |
maxy = ext.maxY();
|
161 |
} else {
|
162 |
if(ext.minX() < minx)
|
163 |
minx = ext.minX();
|
164 |
if(ext.minY() < miny)
|
165 |
miny = ext.minY();
|
166 |
if(ext.maxX() < maxx)
|
167 |
maxx = ext.maxX();
|
168 |
if(ext.maxY() < maxy)
|
169 |
maxy = ext.maxY();
|
170 |
}
|
171 |
}
|
172 |
return new Extent(minx, miny, maxx, maxy);
|
173 |
}*/
|
174 |
|
175 |
/*
|
176 |
* (non-Javadoc)
|
177 |
* @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
|
178 |
*/
|
179 |
public void process(int x, int y) { |
180 |
} |
181 |
|
182 |
/*
|
183 |
* (non-Javadoc)
|
184 |
* @see org.gvsig.raster.grid.filter.RasterFilter#post()
|
185 |
*/
|
186 |
public void post() { |
187 |
if(rasterAlpha != null) |
188 |
mergeBufferTransparency(rasterAlpha); |
189 |
raster = null;
|
190 |
} |
191 |
|
192 |
public int getInRasterDataType() {return 0;} |
193 |
public int getOutRasterDataType() {return 0;} |
194 |
} |