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 / MaskShortFilter.java @ 2480

History | View | Annotate | Download (3.22 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.fmap.dal.coverage.exception.FilterAddException;
29
import org.gvsig.raster.roi.ROI;
30

    
31
/**
32
 * Filtro que aplica una m?scara con la lista de ROIS. Los p?xeles dentro
33
 * de la ROI se ponen al valor de la imagen de origen. Los p?xeles fuera
34
 * de la ROI se ponen a NoData. Esta clase es la gestiona los datos para los
35
 * raster de tipo short.
36
 * 
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class MaskShortFilter extends MaskFilter {
40
        private short nodata     = RasterLibrary.defaultShortNoDataValue;
41
        
42
        public void pre() throws FilterAddException {
43
                super.pre();
44
                noData = (NoData)params.get("nodata");
45
                if(noData != null && noData.isDefined())
46
                        nodata = noData.getValue().shortValue();
47
        }
48
        
49
        public void process(int x, int y) {
50
                if(bufferExtent == null) {
51
                        for (int j = 0; j < raster.getBandCount(); j++) 
52
                                rasterResult.setElem(y, x, j, raster.getElemShort(y, x, j));
53
                        return;
54
                }
55
                double wcX = bufferExtent.minX() + ((((double) x) * bufferExtent.width()) / ((double) raster.getWidth()));
56
                double wcY = bufferExtent.minY() + ((((double) (raster.getHeight() - (y))) * bufferExtent.height()) / ((double) raster.getHeight()));
57

    
58
                
59
                if(inverse) {
60
                        for (int i = 0; i < rois.size(); i++) {
61
                                if (((ROI) rois.get(i)).isInside(wcX, wcY, cellsize, cellsize)) {
62
                                        for (int j = 0; j < numberOfBandsToProcess(); j++) 
63
                                                rasterResult.setElem(y, x, j, (short)nodata);
64
                                        return;
65
                                }
66
                        }
67
                        
68
                        for (int j = 0; j < numberOfBandsToProcess(); j++) 
69
                                rasterResult.setElem(y, x, j, raster.getElemShort(y, x, j));
70
                        
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 < numberOfBandsToProcess(); j++) 
77
                                        rasterResult.setElem(y, x, j, raster.getElemShort(y, x, j));
78
                                return;
79
                        }
80
                }
81
                
82
                for (int j = 0; j < numberOfBandsToProcess(); j++) 
83
                        rasterResult.setElem(y, x, j, (short)nodata);
84
                
85
                return;
86
        }
87
        
88
        public int getInRasterDataType() {
89
                return DataBuffer.TYPE_SHORT;
90
        }
91
        
92
        public int getOutRasterDataType() { 
93
                return DataBuffer.TYPE_SHORT;
94
        }
95
}