Statistics
| Revision:

svn-gvsig-desktop / branches / v10 / libraries / libCq CMS for java.old / src / org / cresques / filter / statistics / ComputeMinMaxFilter.java @ 9056

History | View | Annotate | Download (4.26 KB)

1
/*
2
 * Cresques Mapping Suite. Graphic Library for constructing mapping applications.
3
 *
4
 * Copyright (C) 2004-5.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 *
20
 * For more information, contact:
21
 *
22
 * cresques@gmail.com
23
 */
24
package org.cresques.filter.statistics;
25

    
26
import org.cresques.filter.RasterFilter;
27
import org.cresques.io.datastruct.Statistic;
28

    
29

    
30
/**
31
 * Calcula el m?ximo y el m?nimo de un raster, As? como el segundo menor valor y
32
 * el segundo mayor valor.
33
 * @author Luis W. Sevilla (sevilla_lui@gva.es)
34
 * @author Nacho Brodin (brodin_ign@gva.es)
35
 */
36
public abstract class ComputeMinMaxFilter extends RasterFilter {
37
    protected int[] min = {
38
                              Integer.MAX_VALUE, Integer.MAX_VALUE,
39
                              Integer.MAX_VALUE
40
                          };
41
    protected int[] max = {
42
                              Integer.MIN_VALUE, Integer.MIN_VALUE,
43
                              Integer.MIN_VALUE
44
                          };
45
    protected int[] secondMin = {
46
                                    Integer.MAX_VALUE, Integer.MAX_VALUE,
47
                                    Integer.MAX_VALUE
48
                                };
49
    protected int[] secondMax = {
50
                                    Integer.MIN_VALUE, Integer.MIN_VALUE,
51
                                    Integer.MIN_VALUE
52
                                };
53
    protected int[] tmpMin = {
54
                                 Integer.MAX_VALUE, Integer.MAX_VALUE,
55
                                 Integer.MAX_VALUE
56
                             };
57
    protected int[] tmpMax = {
58
                                 Integer.MIN_VALUE, Integer.MIN_VALUE,
59
                                 Integer.MIN_VALUE
60
                             };
61

    
62
    /**
63
     * Constructor
64
     *
65
     */
66
    public ComputeMinMaxFilter() {
67
        super();
68
    }
69

    
70
    /**
71
     * Operaciones que se realizan antes de la ejecuci?n del filtro
72
     */
73
    public void pre() {
74
        //Obtenci?n de par?metros comunes a todos
75
        this.stats = (Statistic) params.get("stats");
76
        this.stats.tailPercent = 0D;
77

    
78
        //Operaciones del filtro concreto
79
        this.min = new int[stats.minBandValue.length];
80
        this.max = new int[stats.maxBandValue.length];
81
        this.secondMin = new int[stats.minBandValue.length];
82
        this.secondMax = new int[stats.maxBandValue.length];
83
        this.tmpMin = new int[stats.minBandValue.length];
84
        this.tmpMax = new int[stats.maxBandValue.length];
85

    
86
        for (int i = 0; i < min.length; i++) {
87
            secondMin[i] = tmpMin[i] = min[i] = Integer.MAX_VALUE;
88
            secondMax[i] = tmpMax[i] = max[i] = Integer.MIN_VALUE;
89
        }
90
    }
91

    
92
    /**
93
     * Operaciones que se realizan despu?s de la ejecuci?n del filtro
94
     */
95
    public void post() {
96
        for (int i = 0; i < 3; i++) {
97
            stats.minBandValue[i] = min[i];
98
            stats.maxBandValue[i] = max[i];
99
            stats.secondMinBandValue[i] = secondMin[i];
100
            stats.secondMaxBandValue[i] = secondMax[i];
101
        }
102
    }
103

    
104
    /**
105
     * Obtiene le m?nimo para una banda dada
106
     * @param bandNr        banda
107
     * @return        valor m?nimo
108
     */
109
    public int getMin(int bandNr) {
110
        return min[bandNr];
111
    }
112

    
113
    /**
114
     * Obtiene el m?ximo para una banda dada
115
     * @param bandNr        banda
116
     * @return        valor m?ximo
117
     */
118
    public int getMax(int bandNr) {
119
        return max[bandNr];
120
    }
121

    
122
    /**
123
     * Obtiene el objeto stats con el calculo de m?ximos y m?nimos
124
     */
125
    public Object getResult(String name) {
126
        if (name.equals("stats")) {
127
            return stats;
128
        } else {
129
            return null;
130
        }
131
    }
132
}