gvsig-raster / org.gvsig.raster / branches / org.gvsig.raster_dataaccess_refactoring / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / grid / filter / histogramMatching / HistogramMatchingListManager.java @ 2328
History | View | Annotate | Download (6.49 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.histogramMatching; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
28 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
29 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
30 |
import org.gvsig.fmap.dal.coverage.grid.AbstractRasterFilterManager; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
32 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
33 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
34 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
35 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
36 |
import org.gvsig.raster.impl.store.ParamImpl; |
37 |
|
38 |
/**
|
39 |
* Gestion de la lista de filtros para el filtro de tipo HistogramMatchig
|
40 |
*
|
41 |
* @author aMu?oz (alejandro.munoz@uclm.es)
|
42 |
* @version 27-05-2008
|
43 |
*
|
44 |
* */
|
45 |
public class HistogramMatchingListManager extends AbstractRasterFilterManager { |
46 |
private static String ID = "Matching"; |
47 |
|
48 |
/**
|
49 |
* Default constructor. Sets the filter list.
|
50 |
* @param filterList
|
51 |
*/
|
52 |
public HistogramMatchingListManager(RasterFilterList filterList) {
|
53 |
super(filterList);
|
54 |
} |
55 |
|
56 |
public String getManagerID() { |
57 |
return ID;
|
58 |
} |
59 |
|
60 |
public static void register() { |
61 |
AbstractRasterFilterManager.register(ID, HistogramMatchingListManager.class); |
62 |
} |
63 |
|
64 |
public HistogramMatchingListManager(RasterFilterListManagerImpl filterListManager){
|
65 |
super(filterListManager.getFilterList());
|
66 |
} |
67 |
|
68 |
public boolean isDataTypeSupported(int dataType) { |
69 |
if(dataType != Buffer.TYPE_BYTE) |
70 |
return false; |
71 |
return true; |
72 |
} |
73 |
|
74 |
public Class<?> getFilterClassByID(String id) { |
75 |
if(id.compareTo("HistogramMatch") == 0) |
76 |
return HistogramMatchingFilter.class;
|
77 |
return null; |
78 |
} |
79 |
|
80 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
81 |
if (HistogramMatchingFilter.class.isAssignableFrom(classFilter)) {
|
82 |
String fileNameOutput = null; |
83 |
RasterDataStore raster = null;
|
84 |
int numbands=0; |
85 |
HistogramComputer histogramReference = null;
|
86 |
for (int i = 0; i < params.getNumParams(); i++) { |
87 |
if (((ParamImpl)params.getParam(i)).getId().equals("raster")) |
88 |
raster = (RasterDataStore)(((ParamImpl)params.getParam(i)).getDefaultValue()); |
89 |
if (((ParamImpl)params.getParam(i)).getId().equals("numbands")) |
90 |
numbands = ((Integer)(((ParamImpl)params.getParam(i)).getDefaultValue())).intValue();
|
91 |
if (((ParamImpl)params.getParam(i)).getId().equals("histogramReference")) |
92 |
histogramReference = (HistogramComputer)(((ParamImpl)params.getParam(i)).getDefaultValue()); |
93 |
if (((ParamImpl)params.getParam(i)).getId().equals("fileNameOutput")) |
94 |
fileNameOutput= new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()); |
95 |
} |
96 |
addHistogramMatchingFilter(raster,numbands,histogramReference,fileNameOutput); |
97 |
} |
98 |
} |
99 |
|
100 |
public void addFilter(Params params) throws FilterTypeException { |
101 |
addFilter(HistogramMatchingFilter.class, params); |
102 |
} |
103 |
|
104 |
/**
|
105 |
* A?ade un filtro HistogramMatching a la pila de filtros.
|
106 |
* @param histogramReference Histograma de referencia al que ajustar el raster
|
107 |
* @param fileNameOutput fichero de salida
|
108 |
* @throws FilterTypeException
|
109 |
*/
|
110 |
public void addHistogramMatchingFilter(RasterDataStore raster,int numbands,HistogramComputer histogramReference,String fileNameOutput) throws FilterTypeException { |
111 |
RasterFilter filter = new HistogramMatchingByteFilter();
|
112 |
if (filter != null){ |
113 |
filter.addParam("raster", raster);
|
114 |
filter.addParam("histogramReference", histogramReference);
|
115 |
filter.addParam("numbands",new Integer(numbands)); |
116 |
filter.addParam("fileNameOutput",fileNameOutput);
|
117 |
getFilterList().add(filter); |
118 |
} |
119 |
} |
120 |
|
121 |
public RasterFilter createFilter(Params params) {
|
122 |
if( params.getParamById("ladoVentana") != null) { |
123 |
RasterDataStore raster = ((RasterDataStore) params.getParamById("raster").getDefaultValue());
|
124 |
Integer numbands = ((Integer) params.getParamById("numbands").getDefaultValue()); |
125 |
HistogramComputer histogramReference = ((HistogramComputer) params.getParamById("histogramReference").getDefaultValue());
|
126 |
String fileNameOutput = ((String) params.getParamById("fileNameOutput").getDefaultValue()); |
127 |
|
128 |
RasterFilter filter = new HistogramMatchingByteFilter();
|
129 |
filter.addParam("raster", raster);
|
130 |
filter.addParam("histogramReference", histogramReference);
|
131 |
filter.addParam("numbands",new Integer(numbands)); |
132 |
filter.addParam("fileNameOutput",fileNameOutput);
|
133 |
return filter;
|
134 |
} |
135 |
return null; |
136 |
} |
137 |
|
138 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) { |
139 |
return filteri;
|
140 |
} |
141 |
|
142 |
/**
|
143 |
* Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento
|
144 |
* del array tendr? la forma de elemento=valor.
|
145 |
*/
|
146 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
147 |
|
148 |
if (rf instanceof HistogramMatchingFilter) { |
149 |
HistogramMatchingFilter histogramMatchingFilter = (HistogramMatchingFilter) rf; |
150 |
filterList.add("filter.histogramMatch.active=true");
|
151 |
filterList.add("filter.histogramMatch.histogramReference="+histogramMatchingFilter.histogramReference);
|
152 |
filterList.add("filter.histogramMatch.numbands="+histogramMatchingFilter.numbands);
|
153 |
filterList.add("filter.histogramMatch.filenameOutput="+histogramMatchingFilter.fileNameOutput);
|
154 |
filterList.add("filter.histogramMatch.filterName=" + histogramMatchingFilter.getName());
|
155 |
} |
156 |
|
157 |
return filterList;
|
158 |
} |
159 |
|
160 |
public List<Class<?>> getRasterFilterList() { |
161 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
162 |
filters.add(HistogramMatchingFilter.class); |
163 |
return filters;
|
164 |
} |
165 |
|
166 |
public static RasterFilter createHistogramMatchFilter() { |
167 |
RasterFilter filter = new HistogramMatchingFilter();
|
168 |
return filter;
|
169 |
} |
170 |
} |