root / trunk / libraries / libRaster / src / org / gvsig / raster / grid / filter / statistics / StatisticsListManager.java @ 12333
History | View | Annotate | Download (5.69 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 |
package org.gvsig.raster.grid.filter.statistics; |
20 |
|
21 |
import java.util.ArrayList; |
22 |
|
23 |
import org.gvsig.i18n.Messages; |
24 |
import org.gvsig.raster.dataset.Params; |
25 |
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 |
import org.gvsig.raster.shared.IStatistics; |
30 |
import org.gvsig.raster.util.extensionPoints.ExtensionPoints; |
31 |
import org.gvsig.raster.util.extensionPoints.ExtensionPointsSingleton; |
32 |
/**
|
33 |
* Gestor de la pila de filtros para filtros estad?sticos.
|
34 |
*
|
35 |
* @version 31/05/2007
|
36 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
37 |
*/
|
38 |
public class StatisticsListManager implements IRasterFilterListManager { |
39 |
protected RasterFilterList filterList = null; |
40 |
private RasterFilterListManager filterListManager = null; |
41 |
private IStatistics stats = null; |
42 |
|
43 |
/**
|
44 |
* Constructor. Asigna el gestor de todos los filtros y el objeto que
|
45 |
* contiene las estad?sticas.
|
46 |
* @param filterListManager Gestor general de filtros donde se registran los gestores de filtros
|
47 |
* de las extensiones
|
48 |
* @param stats Estadisticas
|
49 |
*/
|
50 |
public StatisticsListManager(RasterFilterListManager filterListManager) {
|
51 |
this.filterListManager = filterListManager;
|
52 |
this.filterList = filterListManager.getFilterList();
|
53 |
stats = (IStatistics)filterListManager.getFilterList().getParam("IStatistics");
|
54 |
} |
55 |
|
56 |
public static void register() { |
57 |
ExtensionPoints extensionPoints = ExtensionPointsSingleton.getInstance(); |
58 |
extensionPoints.add("RasterFilter", "Statistics", StatisticsListManager.class); |
59 |
} |
60 |
|
61 |
/**
|
62 |
* Constructor. Asigna el gestor de todos los filtros y el objeto que
|
63 |
* contiene las estad?sticas.
|
64 |
* @param filterListManager Gestor general de filtros donde se registran los gestores de filtros
|
65 |
* de las extensiones
|
66 |
* @param stats Estadisticas
|
67 |
*/
|
68 |
public StatisticsListManager(RasterFilterListManager filterListManager, IStatistics stats) {
|
69 |
this(filterListManager);
|
70 |
this.stats = stats;
|
71 |
} |
72 |
|
73 |
/**
|
74 |
* 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 |
* @param stats
|
79 |
*/
|
80 |
public void addTailFilter(double tail, double samples, boolean removeMaxValue, IStatistics stats) { |
81 |
RasterFilter filter = createTailFilter(tail, samples, removeMaxValue, stats); |
82 |
|
83 |
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 |
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 |
} |
96 |
|
97 |
return filter;
|
98 |
} |
99 |
|
100 |
/*
|
101 |
* (non-Javadoc)
|
102 |
*
|
103 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList,
|
104 |
* org.gvsig.raster.grid.filter.RasterFilter)
|
105 |
*/
|
106 |
public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) { |
107 |
if (rf instanceof TailTrimFilter) { |
108 |
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 |
return filterList;
|
114 |
} |
115 |
|
116 |
/*
|
117 |
* (non-Javadoc)
|
118 |
*
|
119 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList,
|
120 |
* java.lang.String, int)
|
121 |
*/
|
122 |
public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) { |
123 |
if (fil.startsWith("filter.tail.active") && RasterFilterListManager.getValue(fil).equals("true")) { |
124 |
filters.remove(filteri); |
125 |
filterListManager.removeFilter(Messages.getText(TailTrimFilter.names[0]));
|
126 |
|
127 |
double recorte = 0D; |
128 |
boolean remove = false; |
129 |
|
130 |
for (int propFilter = 0; propFilter < filters.size(); propFilter++) { |
131 |
String elem = (String) filters.get(propFilter); |
132 |
|
133 |
if (elem.startsWith("filter.tail.value")) { |
134 |
recorte = Double.parseDouble(RasterFilterListManager.getValue(elem));
|
135 |
filters.remove(propFilter); |
136 |
propFilter--; |
137 |
} |
138 |
|
139 |
if (elem.startsWith("filter.tail.remove")) { |
140 |
remove = Boolean.valueOf(RasterFilterListManager.getValue(elem)).booleanValue();
|
141 |
filters.remove(propFilter); |
142 |
propFilter--; |
143 |
} |
144 |
} |
145 |
|
146 |
this.addTailFilter(recorte, 0D, remove, stats); |
147 |
filteri = -1;
|
148 |
} |
149 |
return filteri;
|
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
*
|
155 |
* @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 |
} |
162 |
|
163 |
public void addFilter(Class classFilter, Params params) { |
164 |
// TODO: FUNCIONALIDAD: Implementacion de a?adir un filtro
|
165 |
} |
166 |
} |