Statistics
| Revision:

svn-gvsig-desktop / trunk / extensions / extRasterTools-SE / src / org / gvsig / raster / filter / mask / MaskDoubleFilter.java @ 27361

History | View | Annotate | Download (3 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.image.DataBuffer;
22

    
23
import org.gvsig.raster.grid.roi.ROI;
24

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

    
46
                
47
                if(inverse) {
48
                        for (int i = 0; i < rois.size(); i++) {
49
                                if (((ROI) rois.get(i)).isInside(wcX, wcY, dataset.getCellSize(), dataset.getCellSize())) {
50
                                        for (int j = 0; j < raster.getBandCount(); j++) 
51
                                                rasterResult.setElem(y, x, j, (double)nodata);
52
                                        return;
53
                                }
54
                        }
55
                        
56
                        for (int j = 0; j < raster.getBandCount(); j++) 
57
                                rasterResult.setElem(y, x, j, raster.getElemDouble(y, x, j));
58
                        return;
59
                }
60
                
61
                for (int i = 0; i < rois.size(); i++) {
62
                        if (((ROI) rois.get(i)).isInside(wcX, wcY, dataset.getCellSize(), dataset.getCellSize())) {
63
                                for (int j = 0; j < raster.getBandCount(); j++) 
64
                                        rasterResult.setElem(y, x, j, raster.getElemDouble(y, x, j));
65
                                return;
66
                        }
67
                }
68
                
69
                for (int j = 0; j < raster.getBandCount(); j++) 
70
                        rasterResult.setElem(y, x, j, (double)nodata);
71
                return;
72
        }
73
        
74
        /*
75
         * (non-Javadoc)
76
         * @see org.gvsig.raster.filter.mask.MaskFilter#getInRasterDataType()
77
         */
78
        public int getInRasterDataType() {
79
                return DataBuffer.TYPE_DOUBLE;
80
        }
81
        
82
        /*
83
         * (non-Javadoc)
84
         * @see org.gvsig.raster.filter.mask.MaskFilter#getOutRasterDataType()
85
         */
86
        public int getOutRasterDataType() { 
87
                return DataBuffer.TYPE_DOUBLE;
88
        }
89
}