Statistics
| Revision:

root / trunk / libraries / libCq_CMS_praster / src / org / cresques / filter / enhancement / LinearEnhancementFilter.java @ 8026

History | View | Annotate | Download (4.48 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.enhancement;
25

    
26
import java.io.File;
27

    
28
import org.cresques.filter.RasterFilter;
29
import org.cresques.io.datastruct.Statistic;
30
import org.cresques.io.datastruct.Statistic.History;
31
import org.gvsig.i18n.Messages;
32

    
33

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

    
51
    /**
52
     * Constructor
53
     *
54
     */
55
    public LinearEnhancementFilter() {
56
        super();
57
        super.filterName = Messages.getText("enhancement");
58
    }
59

    
60
    /* (non-Javadoc)
61
     * @see org.cresques.io.raster.IRasterFilter#pre()
62
     */
63
    public void pre() {
64
             if (removeExtrema) { //Si est? activado eliminar extremos gastamos el 2? m?ximo/m?nimo
65

    
66
            if ((filename != null) && !filename.equals("")) {
67
                for (int i = 0; i < stats.history.size(); i++) {
68
                    Statistic.History history = (Statistic.History) stats.history.get(i);
69
                    if (history.file.equals(filename.substring((filename.lastIndexOf(File.separator) +
70
                                                                   1),
71
                                                                   filename.length()))) {
72
                        this.minBandValue = history.secMin;
73
                        this.maxBandValue = history.secMax;
74
                    }
75
                }
76
            }
77

    
78
            if ((this.minBandValue == null) || (this.maxBandValue == null)) {
79
                this.minBandValue = stats.secondMinBandValue;
80
                this.maxBandValue = stats.secondMaxBandValue;
81
            }
82
        } else { //Si no est? activado eliminar extremos
83

    
84
            if ((filename != null) && !filename.equals("")) {
85
                for (int i = 0; i < stats.history.size(); i++) {
86
                    Statistic.History history = (Statistic.History) stats.history.get(i);
87

    
88
                    if (history.file.equals(filename.substring((filename.lastIndexOf(File.separator) +
89
                                                                   1),
90
                                                                   filename.length()))) {
91
                        this.minBandValue = history.min;
92
                        this.maxBandValue = history.max;
93
                    }
94
                }
95
            }
96

    
97
            if ((this.minBandValue == null) || (this.maxBandValue == null)) {
98
                this.minBandValue = stats.minBandValue;
99
                this.maxBandValue = stats.maxBandValue;
100
            }
101
        }
102

    
103
        for (int i = 0; i < 3; i++) {
104
            scale[i] = 255D / (maxBandValue[i] - minBandValue[i]);
105
            offset[i] = (255D * minBandValue[i]) / (minBandValue[i] -
106
                        maxBandValue[i]);
107
        }
108
    }
109

    
110
    /**
111
     * Obtiene true si est? activado el flag de eliminar extremos y false si no lo est?
112
     */
113
    public Boolean getRemoveExtrema() {
114
        return new Boolean(removeExtrema);
115
    }
116
}