Statistics
| Revision:

svn-gvsig-desktop / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / ComputeMinMaxFilter.java @ 2669

History | View | Annotate | Download (4.17 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.io.raster;
25

    
26

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

    
59
    /**
60
     * Constructor
61
     *
62
     */
63
    public ComputeMinMaxFilter() {
64
        super();
65
    }
66

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

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

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

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

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

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

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