gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / convolution / ConvolutionFloatFilter.java @ 2308
History | View | Annotate | Download (3.24 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.impl.grid.filter.convolution; |
23 |
|
24 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
25 |
import org.gvsig.fmap.dal.coverage.exception.FilterAddException; |
26 |
import org.gvsig.raster.impl.DefaultRasterManager; |
27 |
import org.gvsig.raster.impl.buffer.RasterBuffer; |
28 |
import org.gvsig.raster.impl.datastruct.Kernel; |
29 |
|
30 |
/**
|
31 |
* Filtro de convolucion para Buffer de tipo Float
|
32 |
* @author Alejandro Mu?oz <alejandro.munoz@uclm.es>
|
33 |
* @author Diego Guerrero Sevilla <diego.guerrero@uclm.es>
|
34 |
* */
|
35 |
public class ConvolutionFloatFilter extends ConvolutionFilter { |
36 |
|
37 |
public ConvolutionFloatFilter() {
|
38 |
super();
|
39 |
} |
40 |
|
41 |
/**
|
42 |
* @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como
|
43 |
* parametro el kernel se pretende aplicar.
|
44 |
* **/
|
45 |
public ConvolutionFloatFilter(Kernel k) { |
46 |
super();
|
47 |
super.kernel = k;
|
48 |
} |
49 |
|
50 |
public void pre() throws FilterAddException { |
51 |
super.pre();
|
52 |
rasterResult = DefaultRasterManager.getInstance().createBuffer(Buffer.TYPE_FLOAT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true); |
53 |
} |
54 |
|
55 |
/** Aplicacion del filtro para el pixel de la posicion line, col */
|
56 |
public void process(int col, int line) { |
57 |
|
58 |
int lado= kernel.getLado();
|
59 |
int semiLado = (lado - 1) >> 1; |
60 |
double ventana[][] = new double[lado][lado]; |
61 |
double resultConvolution = 0; |
62 |
for (int band = 0; band < numberOfBandsToProcess(); band++) { |
63 |
if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)){ |
64 |
for (int j = -semiLado; j <= semiLado; j++) |
65 |
for (int i = -semiLado; i <= semiLado; i++) |
66 |
ventana[i + semiLado][j + semiLado] = raster.getElemFloat(line + j, col + i, band);; |
67 |
Kernel Kventana = new Kernel(ventana); |
68 |
resultConvolution = kernel.convolution(Kventana); |
69 |
if(resultConvolution > Float.MAX_VALUE) |
70 |
resultConvolution = Float.MAX_VALUE;
|
71 |
else if (resultConvolution<0) |
72 |
resultConvolution = 0;
|
73 |
rasterResult.setElem(line, col, band,(float)resultConvolution);
|
74 |
} |
75 |
else rasterResult.setElem(line, col,band,raster.getElemFloat(line,col,band));
|
76 |
} |
77 |
} |
78 |
|
79 |
/**
|
80 |
* @return tipo de dato del buffer de entrada
|
81 |
* */
|
82 |
public int getInRasterDataType() { |
83 |
return RasterBuffer.TYPE_FLOAT;
|
84 |
} |
85 |
|
86 |
/**
|
87 |
* @return tipo de dato del buffer de salida
|
88 |
* */
|
89 |
public int getOutRasterDataType() { |
90 |
return RasterBuffer.TYPE_FLOAT;
|
91 |
} |
92 |
|
93 |
} |