svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / filter / mask / MaskByteFilter.java @ 19894
History | View | Annotate | Download (3.4 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.awt.geom.Point2D; |
22 |
import java.awt.image.DataBuffer; |
23 |
|
24 |
import org.gvsig.raster.grid.roi.ROI; |
25 |
|
26 |
/**
|
27 |
* Filtro que aplica una m?scara con la lista de ROIS. Los p?xeles dentro
|
28 |
* de la ROI se ponen al valor de la imagen de origen. Los p?xeles fuera
|
29 |
* de la ROI se ponen a NoData. Esta clase es la gestiona los datos para los
|
30 |
* raster de tipo byte.
|
31 |
*
|
32 |
* 14/03/2008
|
33 |
* @author Nacho Brodin nachobrodin@gmail.com
|
34 |
*/
|
35 |
public class MaskByteFilter extends MaskFilter { |
36 |
/*
|
37 |
* (non-Javadoc)
|
38 |
* @see org.gvsig.raster.filter.mask.MaskFilter#process(int, int)
|
39 |
*/
|
40 |
public void process(int x, int y) { |
41 |
if ((windowExtent == null) || (gridExtent == null)) |
42 |
return;
|
43 |
|
44 |
double newX = windowExtent.minX() + ((((double) x) * windowExtent.width()) / ((double) raster.getWidth())); |
45 |
double newY = windowExtent.minY() + ((( (double) (raster.getHeight() - (y ))) * windowExtent.height()) / ((double) raster.getHeight())); |
46 |
|
47 |
Point2D point2D = dataset.worldToRaster(new Point2D.Double(newX, newY)); |
48 |
newX = point2D.getX(); |
49 |
newY = point2D.getY(); |
50 |
|
51 |
if(inverse) {
|
52 |
for (int i = 0; i < rois.size(); i++) { |
53 |
if (((ROI) rois.get(i)).isInGrid((int) Math.round(newX), (int) Math.round(newY))) { |
54 |
for (int j = 0; j < raster.getBandCount(); j++) |
55 |
rasterResult.setElem(y, x, j, (byte)nodata);
|
56 |
if(rasterAlpha != null) |
57 |
rasterAlpha.setElem(y, x, 0, (byte)0); |
58 |
return;
|
59 |
} |
60 |
} |
61 |
|
62 |
for (int j = 0; j < raster.getBandCount(); j++) |
63 |
rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j)); |
64 |
|
65 |
if(rasterAlpha != null) |
66 |
rasterAlpha.setElem(y, x, 0, (byte)255); |
67 |
return;
|
68 |
} |
69 |
|
70 |
for (int i = 0; i < rois.size(); i++) { |
71 |
if (((ROI) rois.get(i)).isInGrid((int) Math.round(newX), (int) Math.round(newY))) { |
72 |
for (int j = 0; j < raster.getBandCount(); j++) |
73 |
rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j)); |
74 |
if(rasterAlpha != null) |
75 |
rasterAlpha.setElem(y, x, 0, (byte)255); |
76 |
return;
|
77 |
} |
78 |
} |
79 |
|
80 |
for (int j = 0; j < raster.getBandCount(); j++) |
81 |
rasterResult.setElem(y, x, j, (byte)nodata);
|
82 |
|
83 |
if(rasterAlpha != null) |
84 |
rasterAlpha.setElem(y, x, 0, (byte)0); |
85 |
return;
|
86 |
} |
87 |
|
88 |
/*
|
89 |
* (non-Javadoc)
|
90 |
* @see org.gvsig.raster.filter.mask.MaskFilter#getInRasterDataType()
|
91 |
*/
|
92 |
public int getInRasterDataType() { |
93 |
return DataBuffer.TYPE_BYTE; |
94 |
} |
95 |
|
96 |
/*
|
97 |
* (non-Javadoc)
|
98 |
* @see org.gvsig.raster.filter.mask.MaskFilter#getOutRasterDataType()
|
99 |
*/
|
100 |
public int getOutRasterDataType() { |
101 |
return DataBuffer.TYPE_BYTE; |
102 |
} |
103 |
} |