Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / statistics / StatisticsListManager.java @ 12333

History | View | Annotate | Download (5.69 KB)

1 10740 nacho
/* 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
package org.gvsig.raster.grid.filter.statistics;
20
21
import java.util.ArrayList;
22
23
import org.gvsig.i18n.Messages;
24 11750 bsanchez
import org.gvsig.raster.dataset.Params;
25 10740 nacho
import org.gvsig.raster.grid.filter.IRasterFilterListManager;
26
import org.gvsig.raster.grid.filter.RasterFilter;
27
import org.gvsig.raster.grid.filter.RasterFilterList;
28
import org.gvsig.raster.grid.filter.RasterFilterListManager;
29 12252 nacho
import org.gvsig.raster.shared.IStatistics;
30 12333 bsanchez
import org.gvsig.raster.util.extensionPoints.ExtensionPoints;
31
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton;
32 10740 nacho
/**
33 11767 nacho
 * Gestor de la pila de filtros para filtros estad?sticos.
34 11921 bsanchez
 *
35
 * @version 31/05/2007
36 10740 nacho
 * @author Nacho Brodin (nachobrodin@gmail.com)
37
 */
38 11921 bsanchez
public class StatisticsListManager implements IRasterFilterListManager {
39
        protected RasterFilterList                        filterList                                = null;
40
        private RasterFilterListManager        filterListManager        = null;
41
        private IStatistics                                                        stats                                                        = null;
42
43 11711 nacho
        /**
44
         * Constructor. Asigna el gestor de todos los filtros y el objeto que
45
         * contiene las estad?sticas.
46 12333 bsanchez
         * @param filterListManager Gestor general de filtros donde se registran los gestores de filtros
47 11711 nacho
         * de las extensiones
48
         * @param stats Estadisticas
49
         */
50 11719 nacho
        public StatisticsListManager(RasterFilterListManager filterListManager) {
51 10740 nacho
                this.filterListManager = filterListManager;
52
                this.filterList = filterListManager.getFilterList();
53 11719 nacho
                stats = (IStatistics)filterListManager.getFilterList().getParam("IStatistics");
54
        }
55 11921 bsanchez
56 12333 bsanchez
        public static void register() {
57
                ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance();
58
                extensionPoints.add("RasterFilter", "Statistics", StatisticsListManager.class);
59
        }
60
61 11719 nacho
        /**
62
         * Constructor. Asigna el gestor de todos los filtros y el objeto que
63
         * contiene las estad?sticas.
64 12333 bsanchez
         * @param filterListManager Gestor general de filtros donde se registran los gestores de filtros
65 11719 nacho
         * de las extensiones
66
         * @param stats Estadisticas
67
         */
68
        public StatisticsListManager(RasterFilterListManager filterListManager, IStatistics stats) {
69
                this(filterListManager);
70 10740 nacho
                this.stats = stats;
71
        }
72 11921 bsanchez
73 10740 nacho
        /**
74 11921 bsanchez
         * A?ade un filtro de recorte de colas.
75
         * @param tail porcentaje de recorte
76
         * @param samples porcentaje de muestras tomadas del total de la imagen
77
         * @param removeMaxValue
78 12180 bsanchez
         * @param stats
79 11921 bsanchez
         */
80 12166 bsanchez
        public void addTailFilter(double tail, double samples, boolean removeMaxValue, IStatistics stats) {
81 12180 bsanchez
                RasterFilter filter = createTailFilter(tail, samples, removeMaxValue, stats);
82 10740 nacho
83 12180 bsanchez
                if (filter != null)
84
                        filterList.add(filter);
85
        }
86
87
        public static RasterFilter createTailFilter(double tail, double samples, boolean removeMaxValue, IStatistics stats) {
88
                RasterFilter filter = new TailTrimFloatFilter();
89
90 11921 bsanchez
                if (filter != null) {
91
                        filter.addParam("stats", stats);
92
                        filter.addParam("tail", new Double(tail));
93
                        filter.addParam("samples", new Double(samples));
94
                        filter.addParam("remove", new Boolean(removeMaxValue));
95 12180 bsanchez
                }
96 11921 bsanchez
97 12180 bsanchez
                return filter;
98 11921 bsanchez
        }
99
100 11711 nacho
        /*
101
         * (non-Javadoc)
102 12333 bsanchez
         *
103 11921 bsanchez
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList,
104
         *      org.gvsig.raster.grid.filter.RasterFilter)
105
         */
106 11716 nacho
        public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) {
107 10740 nacho
                if (rf instanceof TailTrimFilter) {
108 11921 bsanchez
                        filterList.add("filter.tail.active=true");
109
                        filterList.add("filter.tail.value=" + ((TailTrimFilter) rf).tailPercent);
110
                        filterList.add("filter.tail.remove=" + ((TailTrimFilter) rf).removeMaxValue());
111
                }
112
113 10740 nacho
                return filterList;
114
        }
115
116 11711 nacho
        /*
117
         * (non-Javadoc)
118 12333 bsanchez
         *
119 11921 bsanchez
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList,
120
         *      java.lang.String, int)
121 11711 nacho
         */
122
        public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) {
123 11921 bsanchez
                if (fil.startsWith("filter.tail.active") && RasterFilterListManager.getValue(fil).equals("true")) {
124
                        filters.remove(filteri);
125 11963 bsanchez
                        filterListManager.removeFilter(Messages.getText(TailTrimFilter.names[0]));
126 10740 nacho
127 11921 bsanchez
                        double recorte = 0D;
128
                        boolean remove = false;
129 10740 nacho
130 11921 bsanchez
                        for (int propFilter = 0; propFilter < filters.size(); propFilter++) {
131
                                String elem = (String) filters.get(propFilter);
132 10740 nacho
133 11921 bsanchez
                                if (elem.startsWith("filter.tail.value")) {
134
                                        recorte = Double.parseDouble(RasterFilterListManager.getValue(elem));
135
                                        filters.remove(propFilter);
136
                                        propFilter--;
137
                                }
138 10740 nacho
139 11921 bsanchez
                                if (elem.startsWith("filter.tail.remove")) {
140
                                        remove = Boolean.valueOf(RasterFilterListManager.getValue(elem)).booleanValue();
141
                                        filters.remove(propFilter);
142
                                        propFilter--;
143
                                }
144
                        }
145 10740 nacho
146 12166 bsanchez
                        this.addTailFilter(recorte, 0D, remove, stats);
147 11921 bsanchez
                        filteri = -1;
148
                }
149 10740 nacho
                return filteri;
150
        }
151
152 11652 bsanchez
        /*
153
         * (non-Javadoc)
154 12333 bsanchez
         *
155 11652 bsanchez
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
156
         */
157
        public ArrayList getRasterFilterList() {
158
                ArrayList filters = new ArrayList();
159
                filters.add(TailTrimFilter.class);
160
                return filters;
161 11553 bsanchez
        }
162 11750 bsanchez
163
        public void addFilter(Class classFilter, Params params) {
164 11767 nacho
                // TODO: FUNCIONALIDAD: Implementacion de a?adir un filtro
165 11750 bsanchez
        }
166 11652 bsanchez
}