gvsig-raster / org.gvsig.raster.tools / trunk / org.gvsig.raster.tools / org.gvsig.raster.tools.app.basic / src / main / java / org / gvsig / raster / tools / app / basic / tool / filter / mask / MaskByteFilter.java @ 2125
History | View | Annotate | Download (3.62 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.awt.image.DataBuffer; |
25 |
|
26 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
27 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
28 |
import org.gvsig.raster.roi.ROI; |
29 |
|
30 |
/**
|
31 |
* Filtro que aplica una m?scara con la lista de ROIS. Los p?xeles dentro
|
32 |
* de la ROI se ponen al valor de la imagen de origen. Los p?xeles fuera
|
33 |
* de la ROI se ponen a NoData. Esta clase es la gestiona los datos para los
|
34 |
* raster de tipo byte.
|
35 |
*
|
36 |
* 14/03/2008
|
37 |
* @author Nacho Brodin nachobrodin@gmail.com
|
38 |
*/
|
39 |
public class MaskByteFilter extends MaskFilter { |
40 |
private byte nodata = RasterLibrary.defaultByteNoDataValue; |
41 |
|
42 |
public void pre() { |
43 |
super.pre();
|
44 |
noData = (NoData)params.get("nodata");
|
45 |
if(noData != null && noData.isDefined()) |
46 |
nodata = noData.getValue().byteValue(); |
47 |
} |
48 |
|
49 |
/*
|
50 |
* (non-Javadoc)
|
51 |
* @see org.gvsig.raster.filter.mask.MaskFilter#process(int, int)
|
52 |
*/
|
53 |
public void process(int x, int y) { |
54 |
if ((windowExtent == null) || (gridExtent == null)) |
55 |
return;
|
56 |
double wcX = windowExtent.minX() + ((((double) x) * windowExtent.width()) / ((double) raster.getWidth())); |
57 |
double wcY = windowExtent.minY() + ((((double) (raster.getHeight() - (y))) * windowExtent.height()) / ((double) raster.getHeight())); |
58 |
|
59 |
|
60 |
if(inverse) {
|
61 |
for (int i = 0; i < rois.size(); i++) { |
62 |
if (((ROI) rois.get(i)).isInside(wcX, wcY, cellsize, cellsize)) {
|
63 |
for (int j = 0; j < raster.getBandCount(); j++) |
64 |
rasterResult.setElem(y, x, j, (byte)nodata);
|
65 |
if(rasterAlpha != null) |
66 |
rasterAlpha.setElem(y, x, 0, (byte)0); |
67 |
return;
|
68 |
} |
69 |
} |
70 |
|
71 |
for (int j = 0; j < raster.getBandCount(); j++) |
72 |
rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j)); |
73 |
|
74 |
if(rasterAlpha != null) |
75 |
rasterAlpha.setElem(y, x, 0, (byte)255); |
76 |
return;
|
77 |
} |
78 |
|
79 |
for (int i = 0; i < rois.size(); i++) { |
80 |
if (((ROI) rois.get(i)).isInside(wcX, wcY, cellsize, cellsize)) {
|
81 |
for (int j = 0; j < raster.getBandCount(); j++) |
82 |
rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j)); |
83 |
if(rasterAlpha != null) |
84 |
rasterAlpha.setElem(y, x, 0, (byte)255); |
85 |
return;
|
86 |
} |
87 |
} |
88 |
|
89 |
for (int j = 0; j < raster.getBandCount(); j++) |
90 |
rasterResult.setElem(y, x, j, (byte)nodata);
|
91 |
|
92 |
if(rasterAlpha != null) |
93 |
rasterAlpha.setElem(y, x, 0, (byte)0); |
94 |
return;
|
95 |
} |
96 |
|
97 |
/*
|
98 |
* (non-Javadoc)
|
99 |
* @see org.gvsig.raster.filter.mask.MaskFilter#getInRasterDataType()
|
100 |
*/
|
101 |
public int getInRasterDataType() { |
102 |
return DataBuffer.TYPE_BYTE; |
103 |
} |
104 |
|
105 |
/*
|
106 |
* (non-Javadoc)
|
107 |
* @see org.gvsig.raster.filter.mask.MaskFilter#getOutRasterDataType()
|
108 |
*/
|
109 |
public int getOutRasterDataType() { |
110 |
return DataBuffer.TYPE_BYTE; |
111 |
} |
112 |
} |