Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / statistics / ComputeMinMaxFilter.java @ 8026

History | View | Annotate | Download (4.36 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
import org.gvsig.i18n.Messages;
29

    
30

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

    
63
    /**
64
     * Constructor
65
     *
66
     */
67
    public ComputeMinMaxFilter() {
68
        super();
69
        //super.filterName = Messages.getText("compute_minmax");
70
    }
71

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

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

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

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

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

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

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