Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / statistics / TailTrimByteFilter.java @ 19409

History | View | Annotate | Download (3.24 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 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.grid.filter.statistics;
20

    
21
import org.gvsig.raster.dataset.IBuffer;
22
/**
23
 * Proceso del filtro de recorte de colas aplicado al tipo de datos byte
24
 * @version 31/05/2007
25
 * @author Nacho Brodin (nachobrodin@gmail.com)
26
 */
27
public class TailTrimByteFilter extends TailTrimFilter {
28

    
29
        /**
30
         * Array con el resultado. La primera dimensi?n es el n?mero de bandas y la segunda son dos elementos 
31
         * el m?ximo y el m?nimo para esa banda.
32
         */
33
        private double[][]        result        = null;
34

    
35
        public TailTrimByteFilter() {}
36

    
37
        /**
38
         * Obtiene par?metros para el filtro y obtiene el ancho y alto de
39
         * la imagen sobre la que se aplica el filtro
40
         */
41
        public void pre() {
42
                super.pre();
43
                sample = new int[raster.getBandCount()][nSamples];
44
                result = new double[raster.getBandCount()][2];
45
        }
46

    
47
        /**
48
         * Carga sobre el vector de muestras los valores de estas cogidos
49
         * de la imagen
50
         */
51
        public void process(int col, int line) {
52
                for (int iBand = 0; iBand < raster.getBandCount(); iBand++)
53
                        sample[iBand][count] = (raster.getElemByte(line, col, iBand) & 0xff);
54
                count++;
55
        }
56

    
57
        /*
58
         * (non-Javadoc)
59
         * @see org.gvsig.raster.grid.filter.statistics.TailTrimFilter#getInRasterDataType()
60
         */
61
        public int getInRasterDataType() {
62
                return IBuffer.TYPE_BYTE;
63
        }
64

    
65
        /*
66
         * (non-Javadoc)
67
         * @see org.gvsig.raster.grid.filter.statistics.TailTrimFilter#getOutRasterDataType()
68
         */
69
        public int getOutRasterDataType() {
70
                return IBuffer.TYPE_BYTE;
71
        }
72

    
73
        /*
74
         * (non-Javadoc)
75
         * @see org.gvsig.raster.grid.filter.statistics.TailTrimFilter#post()
76
         */
77
        public void post() {
78
                super.post();
79

    
80
                //Cogemos el minimo y m?ximo para cada banda
81
                for (int i = 0; i < raster.getBandCount(); i++) {
82
                        result[i][0] = sample[i][posInit + tailSize];
83
                        result[i][1] = sample[i][(posInit + nSamples) - tailSize];
84
                }
85
                stats.setTailTrimValue(tailPercent, result);
86
                
87
                //Cogemos el minimo y m?ximo para cada banda
88
                for (int iValue = 0; iValue < tailSizeList.length; iValue++) {
89
                        double [][] res = new double[raster.getBandCount()][2];
90
                        for (int i = 0; i < raster.getBandCount(); i++) {
91
                                res[i][0] = sample[i][posInit + tailSizeList[iValue]];
92
                                res[i][1] = sample[i][(posInit + nSamples) - tailSizeList[iValue]];
93
                        }
94
                        stats.setTailTrimValue(tailPercentList[iValue], res);
95
                }
96
        }
97

    
98
        /**
99
         * Obtiene el objeto con el m?ximo y m?nimo calculado
100
         */
101
        public Object getResult(String name) {
102
                if (name.equals("raster"))
103
                        return (Object) this.raster;
104
                else
105
                        return result;
106
        }
107
}