gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / enhancement / EqualizationManager.java @ 1427
History | View | Annotate | Download (7.44 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.grid.filter.enhancement; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.RasterLibrary; |
28 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
29 |
import org.gvsig.fmap.dal.coverage.datastruct.BufferHistogram; |
30 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
31 |
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException; |
32 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
33 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
34 |
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException; |
35 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
36 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
37 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
38 |
import org.gvsig.fmap.dal.coverage.store.props.Statistics; |
39 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
40 |
import org.gvsig.raster.impl.store.ParamImpl; |
41 |
import org.gvsig.tools.ToolsLocator; |
42 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
43 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
44 |
/**
|
45 |
* Gestor de la pila de filtros para el filtro de ecualizaci?n de histograma.
|
46 |
*
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
48 |
*/
|
49 |
public class EqualizationManager implements RasterFilterListManager { |
50 |
|
51 |
protected RasterFilterList filterList = null; |
52 |
|
53 |
/**
|
54 |
* Default constructor. Sets the filter list.
|
55 |
* @param filterList
|
56 |
*/
|
57 |
public EqualizationManager(RasterFilterList filterList) {
|
58 |
this.filterList = filterList;
|
59 |
} |
60 |
|
61 |
/**
|
62 |
* Constructor
|
63 |
* @param filterListManager
|
64 |
*/
|
65 |
public EqualizationManager(RasterFilterListManagerImpl filterListManager) {
|
66 |
this.filterList = filterListManager.getFilterList();
|
67 |
} |
68 |
|
69 |
/**
|
70 |
* Registra EqualizationManager en los puntos de extension de RasterFilter
|
71 |
*/
|
72 |
public static void register() { |
73 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
74 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
75 |
point.append("Equalization", "", EqualizationManager.class); |
76 |
} |
77 |
|
78 |
public boolean isDataTypeSupported(int dataType) { |
79 |
if(dataType != Buffer.TYPE_BYTE) |
80 |
return false; |
81 |
return true; |
82 |
} |
83 |
|
84 |
public Class<?> getFilterClassByID(String id) { |
85 |
if(id.compareTo("equalization") == 0) |
86 |
return EqualizationFilter.class;
|
87 |
return null; |
88 |
} |
89 |
|
90 |
/**
|
91 |
* A?ade un filtro de ecualizaci?n de histograma.
|
92 |
* @param IStatistics
|
93 |
* @throws FilterTypeException
|
94 |
*/
|
95 |
public void addEqualizationFilter(Statistics stats, int[] renderBands, BufferHistogram hist, int[] ecualizedBands) throws FilterTypeException { |
96 |
try {
|
97 |
if (!stats.isCalculated()) {
|
98 |
try {
|
99 |
stats.calculate(RasterLibrary.statisticsScale); |
100 |
} catch (FileNotOpenException e) {
|
101 |
// No podemos aplicar el filtro
|
102 |
return;
|
103 |
} catch (RasterDriverException e) {
|
104 |
// No podemos aplicar el filtro
|
105 |
return;
|
106 |
} |
107 |
} |
108 |
|
109 |
RasterFilter filter = createEnhancedFilter(stats, renderBands, hist, ecualizedBands); |
110 |
if (filter != null) |
111 |
filterList.add(filter); |
112 |
} catch (ProcessInterruptedException e) {
|
113 |
//Si se ha interrumpido no a?adimos el filtro
|
114 |
} |
115 |
} |
116 |
|
117 |
/**
|
118 |
* Crea un filtro de Ecualizaci?n de histograma.
|
119 |
* @param stats
|
120 |
* @param renderBands
|
121 |
* @return
|
122 |
*/
|
123 |
public static RasterFilter createEnhancedFilter(Statistics stats, int[] renderBands, BufferHistogram hist, int[] ecualizedBands) { |
124 |
RasterFilter filter = new EqualizationByteFilter();
|
125 |
if (filter != null) { |
126 |
filter.addParam("stats", stats);
|
127 |
filter.addParam("renderBands", renderBands);
|
128 |
filter.addParam("histogram", hist);
|
129 |
filter.addParam("ecualizedBands", ecualizedBands);
|
130 |
} |
131 |
return filter;
|
132 |
} |
133 |
|
134 |
/**
|
135 |
* Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento
|
136 |
* del array tendr? la forma de elemento=valor.
|
137 |
*/
|
138 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
139 |
return filterList;
|
140 |
} |
141 |
|
142 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) throws FilterTypeException { |
143 |
return filteri;
|
144 |
} |
145 |
|
146 |
public List<Class<?>> getRasterFilterList() { |
147 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
148 |
filters.add(EqualizationFilter.class); |
149 |
return filters;
|
150 |
} |
151 |
|
152 |
/*
|
153 |
* (non-Javadoc)
|
154 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
|
155 |
*/
|
156 |
@SuppressWarnings("unchecked") |
157 |
public void addFilter(Class classFilter, Params params) throws FilterTypeException { |
158 |
if (EqualizationFilter.class.isAssignableFrom(classFilter)) {
|
159 |
int[] renderBands = { 0, 1, 2 }; |
160 |
int[] ecualizedBands = { 0, 1, 2 }; |
161 |
BufferHistogram hist = null;
|
162 |
for (int i = 0; i < params.getNumParams(); i++) { |
163 |
if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") && |
164 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) { |
165 |
String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" "); |
166 |
renderBands[0] = new Integer(bands[0]).intValue(); |
167 |
renderBands[1] = new Integer(bands[1]).intValue(); |
168 |
renderBands[2] = new Integer(bands[2]).intValue(); |
169 |
continue;
|
170 |
} |
171 |
if (((ParamImpl)params.getParam(i)).getId().equals("Histogram") && |
172 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof BufferHistogram) {
|
173 |
hist = (BufferHistogram)((ParamImpl)params.getParam(i)).getDefaultValue(); |
174 |
} |
175 |
if (((ParamImpl)params.getParam(i)).getId().equals("EcualizedBands") && |
176 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof int[]) { |
177 |
ecualizedBands = (int[])((ParamImpl)params.getParam(i)).getDefaultValue(); |
178 |
} |
179 |
} |
180 |
|
181 |
addEqualizationFilter((Statistics) filterList.getEnvParam("IStatistics"), renderBands, hist, ecualizedBands);
|
182 |
} |
183 |
} |
184 |
|
185 |
/*
|
186 |
* (non-Javadoc)
|
187 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
188 |
*/
|
189 |
public void addFilter(Params params) throws FilterTypeException { |
190 |
addFilter(EqualizationFilter.class, params); |
191 |
} |
192 |
|
193 |
/*
|
194 |
* (non-Javadoc)
|
195 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
196 |
*/
|
197 |
public RasterFilter createFilter(Params params) {
|
198 |
//TODO: crear un filtro de este tipo
|
199 |
return null; |
200 |
} |
201 |
|
202 |
/*
|
203 |
* (non-Javadoc)
|
204 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
205 |
*/
|
206 |
public RasterFilterList getFilterList() {
|
207 |
return filterList;
|
208 |
} |
209 |
|
210 |
/*
|
211 |
* (non-Javadoc)
|
212 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
213 |
*/
|
214 |
public void setFilterList(RasterFilterList filterList) { |
215 |
this.filterList = filterList;
|
216 |
} |
217 |
} |