Statistics
| Revision:

svn-gvsig-desktop / tags / Root_v06 / libraries / libCq CMS for java.old / src / org / cresques / io / raster / RasterFilter.java @ 4811

History | View | Annotate | Download (4.97 KB)

1
/* Cresques Mapping Suite. Graphic Library for constructing mapping applications.
2
 *
3
 * Copyright (C) 2004-5.
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
 * For more information, contact:
20
 *
21
 * cresques@gmail.com
22
 */
23
package org.cresques.io.raster;
24

    
25
import java.awt.Image;
26
import java.util.Hashtable;
27

    
28
import org.cresques.geo.ViewPortData;
29
import org.cresques.px.Extent;
30

    
31

    
32
/**
33
 * Filtro para raster. Ancestro de todos los filtros.
34
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
35
 */
36
public abstract class RasterFilter implements IRasterFilter {
37
    protected RasterBuf         raster = null;
38
    protected RasterStats         stats = null;
39
    protected Image                 image = null;
40
    protected int[]                 px = new int[4];
41
    protected int                         height = 0;
42
    protected int                         width = 0;
43
    protected Hashtable         params = new Hashtable();
44
    protected int                         incX = 1;
45
    protected int                         incY = 1;
46
    protected ViewPortData        viewPortData = null;
47
    protected Extent                extent = null;
48
    
49
    /**
50
     * Variable que control la aplicaci?n o no del filtro. Si est? a false aunque est? en 
51
     * la pila el filtro no se ejecutar?.
52
     */
53
    protected boolean                 exec = true; 
54

    
55
    /**
56
     * @author Nacho Brodin (brodin_ign@gva.es)
57
     */
58
    public static class Kernel{
59
            public float[][] kernel = null;
60
            public Kernel(float[][] k){
61
                    this.kernel = k;
62
            }
63
            
64
            public float kernelOperation(Kernel k){
65
                    float res = 0;
66
                    for(int i=0;i<3;i++)
67
                            for(int j=0;j<3;j++)
68
                                    res += kernel[i][j] *  k.kernel[i][j];
69
                    return res;
70
            }
71
            
72
    }
73

    
74
    /**
75
     * Constructor
76
     */
77
    public RasterFilter() {
78
    }
79

    
80
    /**
81
     * Aplica el filtro sobre el raster pasado pixel a pixel
82
     */
83
    public void execute() {
84
        pre();
85
        if (exec) {
86
            for (int y = 0; y < height; y = y + incY)
87
                for (int x = 0; x < width; x = x + incX) {
88
                    process(x, y);
89
                }
90
        }
91
        post();
92
    }
93

    
94
    /**
95
     * Aplica el filtro sobre el raster pasado por lineas
96
     */
97
    public void executeLines() {
98
        if (exec) {
99
            for (int y = 0; y < height; y++)
100
                processLine(y);
101
        }
102
    }
103

    
104
    /**
105
     * A?ade un par?metro al filtro
106
     * @param name        Clave del par?metro
107
     * @param param Objeto pasado como par?metro
108
     */
109
    public void addParam(String name, Object param) {
110
        params.put(name, param);
111
    }
112

    
113
    /**
114
     * Elimina un par?metro del filtro
115
     * @param name Clave del par?metro a eliminar
116
     */
117
    public void removeParam(String name){
118
            params.remove(name);
119
    }
120
    
121
    /**
122
     * Obtiene un par?metro a partir de la clave
123
     * @param name Par?metro
124
     * @return Par?metro
125
     */
126
    public Object getParam(String name){
127
            return params.get(name);
128
    }
129
    
130
    /**
131
     * Funci?n que contiene el c?digo a ejecutar antes de aplicar el filtro
132
     */
133
    abstract public void pre();
134

    
135
    /**
136
     * Funci?n que contiene el c?digo a ejecutar despues de aplicar el filtro
137
     */
138
    abstract public void post();
139

    
140
    /**
141
     * Ejecuci?n del filtro para un pixel de la imagen
142
     */
143
    abstract public void process(int x, int y);
144

    
145
    /**
146
     * Ejecuci?n del filtro para una l?nea de la imagen
147
     */
148
    abstract public void processLine(int y);
149

    
150
    /**
151
     * Obtiene el tipo de datos del raster de entrada
152
     */
153
    abstract public int getInRasterDataType();
154

    
155
    /**
156
     * Obtiene el tipo de datos del raster de salida
157
     */
158
    abstract public int getOutRasterDataType();
159

    
160
    /**
161
     * Obtiene el resultado del filtro despues de su ejecuci?n a trav?s de una clave
162
     * @param name        clave para obtener un objeto resultado del filtro.
163
     */
164
    abstract public Object getResult(String name);
165

    
166
        /**
167
         * @param viewPortData The viewPortData to set.
168
         */
169
        public void setViewPortData(ViewPortData viewPortData) {
170
                this.viewPortData = viewPortData;
171
        }
172
        /**
173
         * @param extent The extent to set.
174
         */
175
        public void setExtent(Extent extent) {
176
                this.extent = extent;
177
        }
178

    
179
        /**
180
         * Obtiene true si el filtro va a ser ejecutado o false si no va a serlo
181
         * @return
182
         */
183
        public boolean isExec() {
184
                return exec;
185
        }
186

    
187
        /**
188
         * Asigna el valor a la variable exec. Esta estar? a true si el filtro se ejecutar? la pr?xima
189
         * vez que se repinte o false si no se ejecuta.
190
         * @param exec
191
         */
192
        public void setExec(boolean exec) {
193
                this.exec = exec;
194
        }
195
}