Statistics
| Revision:

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 / MaskFloatFilter.java @ 2125

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.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 float.
35
 * 
36
 * 14/03/2008
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class MaskFloatFilter extends MaskFilter {
40
        private float nodata     = RasterLibrary.defaultFloatNoDataValue;
41
        
42
        public void pre() {
43
                super.pre();
44
                noData = (NoData)params.get("nodata");
45
                if(noData != null && noData.isDefined())
46
                        nodata = noData.getValue().floatValue();
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, (float)nodata);
65
                                        return;
66
                                }
67
                        }
68
                        
69
                        for (int j = 0; j < raster.getBandCount(); j++) 
70
                                rasterResult.setElem(y, x, j, raster.getElemFloat(y, x, j));
71
                        return;
72
                }
73
                
74
                for (int i = 0; i < rois.size(); i++) {
75
                        if (((ROI) rois.get(i)).isInside(wcX, wcY, cellsize, cellsize)) {
76
                                for (int j = 0; j < raster.getBandCount(); j++) 
77
                                        rasterResult.setElem(y, x, j, raster.getElemFloat(y, x, j));
78
                                return;
79
                        }
80
                }
81
                
82
                for (int j = 0; j < raster.getBandCount(); j++) 
83
                        rasterResult.setElem(y, x, j, (float)nodata);
84
                return;
85
        }
86
        
87
        /*
88
         * (non-Javadoc)
89
         * @see org.gvsig.raster.filter.mask.MaskFilter#getInRasterDataType()
90
         */
91
        public int getInRasterDataType() {
92
                return DataBuffer.TYPE_FLOAT;
93
        }
94
        
95
        /*
96
         * (non-Javadoc)
97
         * @see org.gvsig.raster.filter.mask.MaskFilter#getOutRasterDataType()
98
         */
99
        public int getOutRasterDataType() { 
100
                return DataBuffer.TYPE_FLOAT;
101
        }
102
}