Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / enhancement / EnhancementListManager.java @ 11710

History | View | Annotate | Download (6.29 KB)

1
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19

    
20
package org.gvsig.raster.grid.filter.enhancement;
21

    
22
import java.util.ArrayList;
23

    
24
import org.gvsig.i18n.Messages;
25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.dataset.IStatistics;
27
import org.gvsig.raster.grid.filter.IRasterFilterListManager;
28
import org.gvsig.raster.grid.filter.RasterFilter;
29
import org.gvsig.raster.grid.filter.RasterFilterList;
30
import org.gvsig.raster.grid.filter.RasterFilterListManager;
31
import org.gvsig.raster.util.extensionPoints.ExtensionPoints;
32
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton;
33

    
34
/**
35
 * Gestor de la pila de filtros para el filtro de realce.
36
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38
public class EnhancementListManager implements IRasterFilterListManager {
39
        
40
        protected RasterFilterList                         filterList = null;
41
        private RasterFilterListManager                filterListManager = null;
42
        private IStatistics                                        stats = null;
43
        
44
        /**
45
         * Constructor
46
         * @param filterListManager
47
         */
48
        public EnhancementListManager(RasterFilterListManager filterListManager) {
49
                this.filterListManager = filterListManager;
50
                this.filterList = filterListManager.getFilterList();
51
        }
52
        
53
        static {
54
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
55
                extensionPoints.add("RasterFilter", "Enhancement", EnhancementListManager.class);
56
        }
57
        
58
        /**
59
         * Asigna el objeto con las estad?sticas 
60
         * @param stats IStatistics
61
         */
62
        public void setStatistics(IStatistics stats){
63
                this.stats = stats;
64
        }
65
        
66
         /**
67
     * A?ade un filtro de realce. Esta versi?n tiene el par?metro para a?adirle el nombre
68
     * del fichero. Esto se usa para que si a un fichero se le ha calculado ya el recorte de colas
69
     * no se vuelva a calcular, evitando as? que si hacemos un draw a una imagen por bloques cada
70
     * bloque tenga un c?lculo distinto para el recorte.
71
     * @param removeAll        true si se desea eliminar cualquier filtro de brillo que 
72
     * hubiera en la pila antes y false si se acumula sobre lo que haya
73
     */
74
    public void addEnhancedFilter(boolean removeEnds, IStatistics stats, double tailTrim, boolean removeAll) {
75
        String fName = Messages.getText(LinearEnhancementFilter.genericName);
76
                
77
                if(filterList.isActive(fName))
78
                        filterList.remove(fName);
79
                
80
        RasterFilter filter = null;
81
        
82
        switch (filterList.getDataTypeInFilter(fName)) {
83
        case IBuffer.TYPE_IMAGE:
84
            //filter = new LinearEnhancementImageFilter();
85
            break;
86
        case IBuffer.TYPE_SHORT:
87
                filter = new LinearEnhancementShortFilter();
88
            break;
89
        case IBuffer.TYPE_USHORT:
90
        case IBuffer.TYPE_INT:
91
                //filter = new LinearEnhancementIntegerFilter();
92
            break;
93
        case IBuffer.TYPE_FLOAT:
94
                filter = new LinearEnhancementFloatFilter();
95
            break;
96
        case IBuffer.TYPE_DOUBLE:
97
                filter = new LinearEnhancementDoubleFilter();
98
            break;
99
        }
100

    
101
        if(filter != null){
102
                if(removeAll)
103
                                filterList.remove(LinearEnhancementFilter.genericName);
104
                filter.addParam("stats", stats);
105
                if (removeEnds) {
106
                        filter.addParam("remove", new Boolean(true));
107
                } else {
108
                        filter.addParam("remove", new Boolean(false));
109
                }
110
                filter.addParam("tailTrim", new Double(tailTrim));
111
                
112
                filterList.add(filter);
113
                filterListManager.controlTypes();
114
        }
115
    }
116
                
117
        public void createStackFromStrings(ArrayList f, Integer pos) {
118
                        
119
        }
120

    
121
        public ArrayList getStringsFromStack() {
122
                return null;
123
        }
124
        
125
        /**
126
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento del array
127
         * tendr? la forma de elemento=valor.
128
         */
129
        
130
        public ArrayList getStringsFromStack(ArrayList filterList, RasterFilter rf) {
131
                if (rf instanceof LinearEnhancementFilter) {
132
            filterList.add("filter.enhanced.active=true");
133
            filterList.add("filter.enhanced.tailTrim=" + ((LinearEnhancementFilter) rf).getTailTrim().toString());
134
            filterList.add("filter.enhanced.remove=" + ((LinearEnhancementFilter) rf).getRemoveEnds().toString());
135
                }
136
                                        
137
                return filterList;
138
        }
139

    
140
        public int createStackFromStrings(ArrayList filters, String fil, int filteri) {
141
                 if (fil.startsWith("filter.enhanced.active") &&
142
                 RasterFilterListManager.getValue(fil).equals("true")) {
143
             filters.remove(filteri);
144
             double tailTrim = 0D;
145

    
146
             for (int propFilter = 0;propFilter < filters.size();propFilter++) {
147
                 String elem = (String) filters.get(propFilter);
148

    
149
                 if (elem.startsWith("filter.enhanced.tailTrim")) {
150
                         try{
151
                                 tailTrim = new Double(RasterFilterListManager.getValue(elem)).doubleValue();
152
                         }catch(NumberFormatException ex){
153
                                 //tailTrim sigue valiendo 0
154
                         }
155
                 }
156
                 if (elem.startsWith("filter.enhanced.remove")) {
157
                     addEnhancedFilter(Boolean.valueOf(RasterFilterListManager.getValue(elem)).booleanValue(), stats, tailTrim, true);
158
                     filters.remove(propFilter);
159
                     propFilter--;
160
                 }
161
             }
162

    
163
             filteri = -1;
164
         }
165
                 return filteri;
166
        }
167

    
168
        public void createStackFromStrings(ArrayList f) {
169
        }
170

    
171
        /*
172
         * (non-Javadoc)
173
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
174
         */
175
        public ArrayList getRasterFilterList() {
176
                ArrayList filters = new ArrayList();
177
                filters.add(LinearEnhancementFilter.class);
178
                return filters;
179
        }
180
}