Statistics
| Revision:

svn-gvsig-desktop / trunk / libraries / libCq CMS for java.old / src / org / cresques / io / raster / LinearEnhancementFilter.java @ 4578

History | View | Annotate | Download (4.25 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
import java.io.File;
27

    
28

    
29
/**
30
 * Clase base para los filtros de realzado lineal. Lee el m?nimo y m?xmo de la clase
31
 * RasterStats que ser?n calculados por PercentTailTrimFilter o ComputeMinMaxFilter dependiendo
32
 * de si est? activado el recorte de colas o no. En RasterStats tambi?n est?n los segundos
33
 * valores despu?s del m?nimo y m?ximo que son los que se utilizan con la opci?n eliminar
34
 * extremos activada. Estos se usaran en vez del m?nimo y m?ximo cuando la variable
35
 * removeExtrema est? a true.
36
 * @author Nacho Brodin (brodin_ign@gva.es)
37
 */
38
public abstract class LinearEnhancementFilter extends RasterFilter {
39
    protected double[] scale = new double[3];
40
    protected double[] offset = new double[3];
41
    protected int[] minBandValue = null;
42
    protected int[] maxBandValue = null;
43
    protected boolean removeExtrema = false;
44
    protected String filename = null;
45

    
46
    /**
47
     * Constructor
48
     *
49
     */
50
    public LinearEnhancementFilter() {
51
        super();
52
    }
53

    
54
    /* (non-Javadoc)
55
     * @see org.cresques.io.raster.IRasterFilter#pre()
56
     */
57
    public void pre() {
58
             if (removeExtrema) { //Si est? activado eliminar extremos gastamos el 2? m?ximo/m?nimo
59

    
60
            if ((filename != null) && !filename.equals("")) {
61
                for (int i = 0; i < stats.history.size(); i++) {
62
                    RasterStats.History history = (RasterStats.History) stats.history.get(i);
63
                    if (history.file.equals(filename.substring((filename.lastIndexOf(File.separator) +
64
                                                                   1),
65
                                                                   filename.length()))) {
66
                        this.minBandValue = history.secMin;
67
                        this.maxBandValue = history.secMax;
68
                    }
69
                }
70
            }
71

    
72
            if ((this.minBandValue == null) || (this.maxBandValue == null)) {
73
                this.minBandValue = stats.secondMinBandValue;
74
                this.maxBandValue = stats.secondMaxBandValue;
75
            }
76
        } else { //Si no est? activado eliminar extremos
77

    
78
            if ((filename != null) && !filename.equals("")) {
79
                for (int i = 0; i < stats.history.size(); i++) {
80
                    RasterStats.History history = (RasterStats.History) stats.history.get(i);
81

    
82
                    if (history.file.equals(filename.substring((filename.lastIndexOf(File.separator) +
83
                                                                   1),
84
                                                                   filename.length()))) {
85
                        this.minBandValue = history.min;
86
                        this.maxBandValue = history.max;
87
                    }
88
                }
89
            }
90

    
91
            if ((this.minBandValue == null) || (this.maxBandValue == null)) {
92
                this.minBandValue = stats.minBandValue;
93
                this.maxBandValue = stats.maxBandValue;
94
            }
95
        }
96

    
97
        for (int i = 0; i < 3; i++) {
98
            scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
99
            offset[i] = (255D * minBandValue[i]) / (minBandValue[i] -
100
                        maxBandValue[i]);
101
        }
102
    }
103

    
104
    /**
105
     * Obtiene true si est? activado el flag de eliminar extremos y false si no lo est?
106
     */
107
    public Boolean getRemoveExtrema() {
108
        return new Boolean(removeExtrema);
109
    }
110
}