Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / convolution / ConvolutionShortFilter.java @ 15961

History | View | Annotate | Download (2.36 KB)

1
package org.gvsig.raster.grid.filter.convolution;
2

    
3
import org.gvsig.raster.buffer.RasterBuffer;
4
import org.gvsig.raster.dataset.IBuffer;
5

    
6
/**
7
 * Filtro de convolucion para Buffer de tipo Short
8
 * @author Alejandro Mu?oz        <alejandro.munoz@uclm.es>
9
 * @author Diego Guerrero Sevilla  <diego.guerrero@uclm.es>
10
 * */
11
public class ConvolutionShortFilter extends ConvolutionFilter {
12

    
13
        protected IBuffer                rasterResult = null;
14

    
15

    
16
        public ConvolutionShortFilter(){
17
                super();
18
        }
19

    
20
        /**
21
         * @param Kernel a aplicar. En caso de que no se trate de un kernel definido en ConvolutionFilter, se puede pasar como
22
         * parametro el kernel se pretende aplicar.
23
         * **/
24
        public ConvolutionShortFilter(Kernel k){
25
                super();
26
                super.kernel=k;
27
        }
28

    
29
        public void pre(){
30
                super.pre();
31
                rasterResult = RasterBuffer.getBuffer(IBuffer.TYPE_SHORT, raster.getWidth(), raster.getHeight(), raster.getBandCount(), true);
32
        }
33

    
34
        /** Aplicacion del filtro para el pixel de la posicion line, col */
35
        public void process(int col, int line) {
36
                int lado = kernel.getLado();
37
                int semiLado = (lado - 1) >> 1;
38
                double ventana[][] = new double[lado][lado];
39
                double resultConvolution = 0;
40
                for (int band = 0; band < raster.getBandCount(); band++) {
41
                        if ((col - semiLado >= 0) && (line - semiLado >= 0) && (col + semiLado < width) && (line + semiLado < height)) {
42
                                for (int j = -semiLado; j <= semiLado; j++)
43
                                        for (int i = -semiLado; i <= semiLado; i++)
44
                                                ventana[i + semiLado][j + semiLado] = raster.getElemShort(line + j, col + i, band) & 0xff;
45
                                Kernel Kventana = new Kernel(ventana);
46
                                resultConvolution = kernel.convolution(Kventana);
47
                                if (resultConvolution > Short.MAX_VALUE)
48
                                        resultConvolution = Short.MAX_VALUE;
49
                                else
50
                                        if (resultConvolution < 0)
51
                                                resultConvolution = 0;
52
                                rasterResult.setElem(line, col, band, (short) resultConvolution);
53
                        } else
54
                                rasterResult.setElem(line, col, band, (short) raster.getElemShort(line, col, band));
55
                }
56
        }
57

    
58
        /**
59
         * @return  tipo de dato del buffer de entrada
60
         * */
61
        public int getInRasterDataType() {
62
                return RasterBuffer.TYPE_SHORT;
63
        }
64

    
65
        /**
66
         * @return  tipo de dato del buffer de salida
67
         * */
68
        public int getOutRasterDataType() {
69
                return RasterBuffer.TYPE_SHORT;
70
        }
71

    
72
        /**
73
         * @return  buffer resultante tras aplicar el filtro
74
         * */
75
        public Object getResult(String name) {
76
                if (name.equals("raster"))
77
                        return (Object) this.rasterResult;
78
                return null;
79
        }
80

    
81
}