Statistics
| Revision:

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

History | View | Annotate | Download (5.08 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.util.ArrayList;
22

    
23
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
24
import org.gvsig.raster.buffer.RasterBuffer;
25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.dataset.MultiRasterDataset;
27
import org.gvsig.raster.dataset.Params;
28
import org.gvsig.raster.grid.GridExtent;
29
import org.gvsig.raster.grid.filter.RasterFilter;
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.
35
 * 
36
 * 14/03/2008
37
 * @author Nacho Brodin nachobrodin@gmail.com
38
 */
39
public class MaskFilter extends RasterFilter {
40
        public static String[]         names           = new String[] { "mask" };
41
        protected MaskUI               maskUI          = null;
42
        protected ArrayList            rois            = null;
43
        protected double               nodata          = -99999;
44
        protected boolean              inverse         = false;
45
        
46
        //Extent de la ventana de datos y de la imagen completa.
47
        protected GridExtent           gridExtent      = null;
48
        protected GridExtent           windowExtent    = null;
49
        protected MultiRasterDataset   dataset         = null;
50
        protected IBuffer              rasterAlpha     = null;
51
                
52
        /**
53
         * Constructor
54
         */
55
        public MaskFilter() {
56
                super();
57
                setName(names[0]);
58
        }
59

    
60
        /*
61
         * (non-Javadoc)
62
         * @see org.gvsig.raster.grid.filter.RasterFilter#getGroup()
63
         */
64
        public String getGroup() {
65
                return "mascaras";
66
        }
67

    
68
        /*
69
         * (non-Javadoc)
70
         * @see org.gvsig.raster.grid.filter.RasterFilter#getNames()
71
         */
72
        public String[] getNames() {
73
                return names;
74
        }
75

    
76
        /*
77
         * (non-Javadoc)
78
         * @see org.gvsig.raster.grid.filter.RasterFilter#getResult(java.lang.String)
79
         */
80
        public Object getResult(String name) {
81
                if (name.equals("alphaBand"))
82
                        return rasterAlpha;
83
                
84
                if (!name.equals("raster"))
85
                        return null;
86

    
87
                if (!exec)
88
                        return (Object) this.raster;
89

    
90
                return (Object) this.rasterResult;
91
        }
92

    
93
        /*
94
         * (non-Javadoc)
95
         * @see org.gvsig.raster.grid.filter.RasterFilter#getUIParams(java.lang.String)
96
         */
97
        public Params getUIParams(String nameFilter) {
98
                Params params = new Params();
99
                params.setParam("Panel", getMaskUI(), -1, null);
100
                params.setParam("FilterName", nameFilter, -1, null);
101
                return params;
102
        }
103
        
104
        /**
105
         * Obtiene el interfaz gr?fico para el filtro de m?scara.
106
         * @return MaskUI
107
         */
108
        private MaskUI getMaskUI() {
109
                if (maskUI == null) {
110
                        maskUI = new MaskUI();
111
                        FLyrRasterSE raster = (FLyrRasterSE) getEnv().get("initRaster");
112
                        maskUI.setRois(rois);
113
                        maskUI.setLayer(raster);
114
                }
115
                return maskUI;
116
        }
117

    
118
        /*
119
         * (non-Javadoc)
120
         * @see org.gvsig.raster.grid.filter.RasterFilter#pre()
121
         */
122
        public void pre() {
123
                exec = true;
124
                raster = rasterResult;
125
                raster = (RasterBuffer) params.get("raster");
126
                Boolean inverseBoolean = (Boolean)params.get("inverse");
127
                if(inverseBoolean != null)
128
                        inverse = inverseBoolean.booleanValue();
129
                Double nodataDouble = (Double)params.get("nodata");
130
                if(nodataDouble != null)
131
                        nodata = nodataDouble.doubleValue();
132
                Boolean transpBoolean = (Boolean)params.get("transparency");
133
                                                                
134
                rois = (ArrayList) params.get("rois");
135
                if (rois == null)
136
                        rois = new ArrayList();
137
                height = raster.getHeight();
138
                width = raster.getWidth();
139
                
140
                gridExtent = (GridExtent) environment.get("GridExtent");
141
                windowExtent = (GridExtent) environment.get("WindowExtent");
142
                dataset = (MultiRasterDataset) environment.get("MultiRasterDataset");
143
                
144
                rasterResult = RasterBuffer.getBuffer(raster.getDataType(), raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
145
                
146
                if(transpBoolean.booleanValue() && raster.getDataType() == IBuffer.TYPE_BYTE) 
147
                        rasterAlpha = RasterBuffer.getBuffer(IBuffer.TYPE_BYTE, raster.getWidth(), raster.getHeight(), 1, true);
148
        }
149
                
150
        /*
151
         * (non-Javadoc)
152
         * @see org.gvsig.raster.grid.filter.RasterFilter#process(int, int)
153
         */
154
        public void process(int x, int y) throws InterruptedException {
155
        }
156

    
157
        /*
158
         * (non-Javadoc)
159
         * @see org.gvsig.raster.grid.filter.RasterFilter#post()
160
         */
161
        public void post() {
162
        }
163
  
164
        public int getInRasterDataType() {return 0;}
165
        public int getOutRasterDataType() {return 0;}
166
}