Statistics
| Revision:

root / branches / CqCMSDvp / libraries / libCq CMS for java.old / src / org / cresques / io / raster / ComputeMinMaxFilter.java @ 2664

History | View | Annotate | Download (3.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.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 = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
35
        protected int [] max = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
36
        protected int [] secondMin = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
37
        protected int [] secondMax = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
38
        protected int [] tmpMin = {Integer.MAX_VALUE,Integer.MAX_VALUE,Integer.MAX_VALUE};
39
        protected int [] tmpMax = {Integer.MIN_VALUE,Integer.MIN_VALUE,Integer.MIN_VALUE};
40
        
41
        /**
42
         * Constructor
43
         *
44
         */
45
        public ComputeMinMaxFilter(){
46
                super();
47
        }
48
        
49
        /**
50
         * Operaciones que se realizan antes de la ejecuci?n del filtro
51
         */
52
        public void pre(){
53
                //Obtenci?n de par?metros comunes a todos
54
                this.stats = (RasterStats)params.get("stats");
55
                this.stats.tailPercent = 0D;
56
                
57
                //Operaciones del filtro concreto
58
                this.min = new int[stats.minBandValue.length];
59
                this.max = new int[stats.maxBandValue.length];
60
                this.secondMin = new int[stats.minBandValue.length];
61
                this.secondMax = new int[stats.maxBandValue.length];
62
                this.tmpMin = new int[stats.minBandValue.length];
63
                this.tmpMax = new int[stats.maxBandValue.length];
64
                for (int i=0; i<min.length; i++) {
65
                        secondMin[i] = tmpMin[i] = min[i] = Integer.MAX_VALUE;
66
                        secondMax[i] = tmpMax[i] = max[i] = Integer.MIN_VALUE;
67
                }        
68
        }
69
                
70
        /**
71
         * Operaciones que se realizan despu?s de la ejecuci?n del filtro
72
         */
73
        public void post(){
74

    
75
                for (int i=0; i<3; i++) {
76
                        stats.minBandValue[i] = min[i];
77
                        stats.maxBandValue[i] = max[i];
78
                        stats.secondMinBandValue[i] = secondMin[i];
79
                        stats.secondMaxBandValue[i] = secondMax[i];
80
                }
81
        }
82
        
83
        /**
84
         * Obtiene le m?nimo para una banda dada
85
         * @param bandNr        banda
86
         * @return        valor m?nimo
87
         */
88
        public int getMin(int bandNr) { 
89
                return min[bandNr]; 
90
        }
91

    
92
        /**
93
         * Obtiene el m?ximo para una banda dada
94
         * @param bandNr        banda
95
         * @return        valor m?ximo
96
         */
97
        public int getMax(int bandNr) { 
98
                return max[bandNr]; 
99
        }
100
                
101
        /**
102
         * Obtiene el objeto stats con el calculo de m?ximos y m?nimos
103
         */
104
        public Object getResult(String name){
105
                if(name.equals("stats"))
106
                        return stats;
107
                else return null;
108
        }
109
                
110
}
111