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 / regionalpha / RegionAlphaFilter.java @ 2313
History | View | Annotate | Download (4.7 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.regionalpha; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLocator; |
27 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
28 |
import org.gvsig.fmap.dal.coverage.datastruct.Extent; |
29 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
30 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
31 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
32 |
import org.gvsig.fmap.dal.coverage.store.props.ColorInterpretation; |
33 |
import org.gvsig.fmap.mapcontext.layers.FLayer; |
34 |
import org.gvsig.raster.fmap.layers.FLyrRaster; |
35 |
import org.gvsig.raster.roi.ROI; |
36 |
|
37 |
/**
|
38 |
*
|
39 |
* @author BorSanZa - Borja S?nchez Zamorano
|
40 |
*/
|
41 |
public class RegionAlphaFilter extends BaseRasterFilter { |
42 |
public static String[] names = new String[] { "regionalpha" }; |
43 |
private RegionAlphaUI regionAlphaUI = null; |
44 |
protected ArrayList<ROI> rois = null; |
45 |
protected int alpha = 255; |
46 |
protected boolean inverse = false; |
47 |
|
48 |
/* Variables que hacen falta en el process */
|
49 |
protected double cellsize = 0D; |
50 |
protected Extent bufferExtent = null; |
51 |
|
52 |
/**
|
53 |
* Constructor
|
54 |
*/
|
55 |
public RegionAlphaFilter() {
|
56 |
super();
|
57 |
setName(names[0]);
|
58 |
} |
59 |
|
60 |
public String getGroup() { |
61 |
return "mascaras"; |
62 |
} |
63 |
|
64 |
public String[] getNames() { |
65 |
return names;
|
66 |
} |
67 |
|
68 |
public Params getUIParams(String nameFilter) { |
69 |
Params params = RasterLocator.getManager().createParams( |
70 |
"Panel", getRegionAlphaUI(), -1, null); |
71 |
params.setParam("FilterName", nameFilter, -1, null); |
72 |
params.setParam("Alpha",
|
73 |
new Integer(alpha), |
74 |
Params.SLIDER, |
75 |
new String[]{ "0", "255", "0", "1", "25" }); //min, max, valor defecto, intervalo peque?o, intervalo grande; |
76 |
|
77 |
return params;
|
78 |
} |
79 |
|
80 |
private RegionAlphaUI getRegionAlphaUI() {
|
81 |
if (regionAlphaUI == null) { |
82 |
regionAlphaUI = new RegionAlphaUI();
|
83 |
FLayer raster = (FLayer) getEnv().get("initRaster");
|
84 |
regionAlphaUI.setRois(rois); |
85 |
if(raster instanceof FLyrRaster) |
86 |
regionAlphaUI.setLayer((FLyrRaster)raster); |
87 |
} |
88 |
return regionAlphaUI;
|
89 |
} |
90 |
|
91 |
@SuppressWarnings("unchecked") |
92 |
public void pre() throws FilterAddException { |
93 |
super.pre();
|
94 |
|
95 |
Boolean inverseBoolean = (Boolean) params.get("inverse"); |
96 |
if (inverseBoolean != null) |
97 |
inverse = inverseBoolean.booleanValue(); |
98 |
|
99 |
rois = (ArrayList<ROI>) params.get("rois"); |
100 |
|
101 |
alpha = ((Integer) params.get("alpha")).intValue(); |
102 |
|
103 |
if(raster.getDataExtent() == null) |
104 |
throw new FilterAddException("Buffer extension cannot be null"); |
105 |
|
106 |
bufferExtent = RasterLocator.getManager().getDataStructFactory().createExtent(raster.getDataExtent()); |
107 |
cellsize = raster.getDataExtent().getWidth() / raster.getWidth(); |
108 |
|
109 |
if(hasInputTransparency())
|
110 |
createBufferResult(raster.getDataType(), raster.getBandCount()); |
111 |
else
|
112 |
createBufferResult(raster.getDataType(), raster.getBandCount() + 1);
|
113 |
} |
114 |
|
115 |
/**
|
116 |
* Gets the result of this filter
|
117 |
*/
|
118 |
public Object getResult(String name) { |
119 |
if (name.equals(RESULT_TRANSPARENCY)) {
|
120 |
String[] values = new String[rasterResult.getBandCount()]; |
121 |
for (int i = 0; i < values.length; i++) { |
122 |
values[i] = ColorInterpretation.UNDEF_BAND; |
123 |
} |
124 |
ColorInterpretation ci = RasterLocator.getManager().getDataStructFactory().createColorInterpretation(values); |
125 |
ci.setColorInterpValue(rasterResult.getBandCount() - 1, ColorInterpretation.ALPHA_BAND);
|
126 |
transparency.setColorInterpretation(ci); |
127 |
transparency.activeTransparency(); |
128 |
return transparency;
|
129 |
} |
130 |
|
131 |
return super.getResult(name); |
132 |
} |
133 |
|
134 |
public void post() { |
135 |
} |
136 |
|
137 |
public void process(int x, int y) { |
138 |
} |
139 |
|
140 |
public int getInRasterDataType() { |
141 |
return Buffer.TYPE_BYTE; |
142 |
} |
143 |
|
144 |
public int getOutRasterDataType() { |
145 |
return Buffer.TYPE_BYTE; |
146 |
} |
147 |
} |