Statistics
| Revision:

gvsig-raster / org.gvsig.raster.app / trunk / org.gvsig.raster.app / org.gvsig.raster.app.tools / src / main / java / org / gvsig / raster / app / extension / tool / filter / mask / MaskByteFilter.java @ 152

History | View | Annotate | Download (3.33 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.app.extension.tool.filter.mask;
23

    
24
import java.awt.image.DataBuffer;
25

    
26
import org.gvsig.fmap.dal.coverage.grid.ROI;
27

    
28
/**
29
 * Filtro que aplica una m?scara con la lista de ROIS. Los p?xeles dentro
30
 * de la ROI se ponen al valor de la imagen de origen. Los p?xeles fuera
31
 * de la ROI se ponen a NoData. Esta clase es la gestiona los datos para los
32
 * raster de tipo byte.
33
 * 
34
 * 14/03/2008
35
 * @author Nacho Brodin nachobrodin@gmail.com
36
 */
37
public class MaskByteFilter extends MaskFilter {
38
        /*
39
         * (non-Javadoc)
40
         * @see org.gvsig.raster.filter.mask.MaskFilter#process(int, int)
41
         */
42
        public void process(int x, int y) {
43
                if ((windowExtent == null) || (gridExtent == null))
44
                        return;
45
                double wcX = windowExtent.minX() + ((((double) x) * windowExtent.width()) / ((double) raster.getWidth()));
46
                double wcY = windowExtent.minY() + ((((double) (raster.getHeight() - (y))) * windowExtent.height()) / ((double) raster.getHeight()));
47

    
48
                
49
                if(inverse) {
50
                        for (int i = 0; i < rois.size(); i++) {
51
                                if (((ROI) rois.get(i)).isInside(wcX, wcY, dataset.getCellSize(), dataset.getCellSize())) {
52
                                        for (int j = 0; j < raster.getBandCount(); j++) 
53
                                                rasterResult.setElem(y, x, j, (byte)nodata);
54
                                        if(rasterAlpha != null)
55
                                                rasterAlpha.setElem(y, x, 0, (byte)0);
56
                                        return;
57
                                }
58
                        }
59
                        
60
                        for (int j = 0; j < raster.getBandCount(); j++) 
61
                                rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j));
62
                        
63
                        if(rasterAlpha != null)
64
                                rasterAlpha.setElem(y, x, 0, (byte)255);
65
                        return;
66
                }
67
                
68
                for (int i = 0; i < rois.size(); i++) {
69
                        if (((ROI) rois.get(i)).isInside(wcX, wcY, dataset.getCellSize(), dataset.getCellSize())) {
70
                                for (int j = 0; j < raster.getBandCount(); j++) 
71
                                        rasterResult.setElem(y, x, j, raster.getElemByte(y, x, j));
72
                                if(rasterAlpha != null)
73
                                        rasterAlpha.setElem(y, x, 0, (byte)255);
74
                                return;
75
                        }
76
                }
77
                
78
                for (int j = 0; j < raster.getBandCount(); j++) 
79
                        rasterResult.setElem(y, x, j, (byte)nodata);
80
                
81
                if(rasterAlpha != null)
82
                        rasterAlpha.setElem(y, x, 0, (byte)0);
83
                return;
84
        }
85
        
86
        /*
87
         * (non-Javadoc)
88
         * @see org.gvsig.raster.filter.mask.MaskFilter#getInRasterDataType()
89
         */
90
        public int getInRasterDataType() {
91
                return DataBuffer.TYPE_BYTE;
92
        }
93
        
94
        /*
95
         * (non-Javadoc)
96
         * @see org.gvsig.raster.filter.mask.MaskFilter#getOutRasterDataType()
97
         */
98
        public int getOutRasterDataType() { 
99
                return DataBuffer.TYPE_BYTE;
100
        }
101
}