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 / band / ToLumSaManager.java @ 1426
History | View | Annotate | Download (6.92 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.band; |
23 |
|
24 |
import java.util.ArrayList; |
25 |
import java.util.List; |
26 |
|
27 |
import org.gvsig.fmap.dal.coverage.datastruct.Params; |
28 |
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException; |
29 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilter; |
30 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList; |
31 |
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager; |
32 |
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter; |
33 |
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl; |
34 |
import org.gvsig.raster.impl.store.ParamImpl; |
35 |
import org.gvsig.tools.ToolsLocator; |
36 |
import org.gvsig.tools.extensionpoint.ExtensionPoint; |
37 |
import org.gvsig.tools.extensionpoint.ExtensionPointManager; |
38 |
/**
|
39 |
* Gestor del filtro de Tono, Saturaci?n y Brillo
|
40 |
*
|
41 |
* @version 04/12/2007
|
42 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
43 |
*/
|
44 |
public class ToLumSaManager implements RasterFilterListManager { |
45 |
|
46 |
protected RasterFilterList filterList = null; |
47 |
|
48 |
/**
|
49 |
* Registra ToLumSaManager en los puntos de extension de RasterFilter
|
50 |
*/
|
51 |
public static void register() { |
52 |
ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager(); |
53 |
ExtensionPoint point = extensionPoints.get("RasterFilter");
|
54 |
point.append("ToLumSa", "", ToLumSaManager.class); |
55 |
} |
56 |
|
57 |
public Class<?> getFilterClassByID(String id) { |
58 |
if( id.compareTo("tolumsa") == 0) |
59 |
return ToLumSaFilter.class;
|
60 |
return null; |
61 |
} |
62 |
|
63 |
/**
|
64 |
* Default constructor. Sets the filter list.
|
65 |
* @param filterList
|
66 |
*/
|
67 |
public ToLumSaManager(RasterFilterList filterList) {
|
68 |
this.filterList = filterList;
|
69 |
} |
70 |
|
71 |
/**
|
72 |
* Constructor.
|
73 |
* Asigna la lista de filtros y el managener global.
|
74 |
*
|
75 |
* @param filterListManager
|
76 |
*/
|
77 |
public ToLumSaManager(RasterFilterListManagerImpl filterListManager) {
|
78 |
this.filterList = filterListManager.getFilterList();
|
79 |
} |
80 |
|
81 |
/**
|
82 |
* A?ade un filtro de control de Tono, Saturaci?n y Brillo a la lista de filtros.
|
83 |
* @throws FilterTypeException
|
84 |
*/
|
85 |
public void addToLumSaFilter(double hue, double luminosity, double saturation, int[] renderBands) throws FilterTypeException { |
86 |
BaseRasterFilter filter = new ToLumSaByteFilter();
|
87 |
|
88 |
// Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
|
89 |
if (filter != null) { |
90 |
filter.addParam("hue", new Double(hue)); |
91 |
filter.addParam("luminosity", new Double(luminosity)); |
92 |
filter.addParam("saturation", new Double(saturation)); |
93 |
filter.addParam("renderBands", renderBands);
|
94 |
filterList.add(filter); |
95 |
} |
96 |
} |
97 |
|
98 |
public List<Class<?>> getRasterFilterList() { |
99 |
List<Class<?>> filters = new ArrayList<Class<?>>(); |
100 |
filters.add(ToLumSaFilter.class); |
101 |
return filters;
|
102 |
} |
103 |
|
104 |
public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException { |
105 |
if (ToLumSaFilter.class.isAssignableFrom(classFilter)) {
|
106 |
double hue = 0, saturation = 0, luminosity = 0; |
107 |
int[] renderBands = { 0, 1, 2 }; |
108 |
|
109 |
for (int i = 0; i < params.getNumParams(); i++) { |
110 |
if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") && |
111 |
((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) { |
112 |
String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" "); |
113 |
renderBands[0] = new Integer(bands[0]).intValue(); |
114 |
renderBands[1] = new Integer(bands[1]).intValue(); |
115 |
renderBands[2] = new Integer(bands[2]).intValue(); |
116 |
continue;
|
117 |
} |
118 |
if (((ParamImpl)params.getParam(i)).getId().equals("hue")) |
119 |
hue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
|
120 |
if (((ParamImpl)params.getParam(i)).getId().equals("saturation")) |
121 |
saturation = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
|
122 |
if (((ParamImpl)params.getParam(i)).getId().equals("luminosity")) |
123 |
luminosity = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
|
124 |
|
125 |
} |
126 |
addToLumSaFilter(hue, luminosity, saturation, renderBands); |
127 |
} |
128 |
} |
129 |
|
130 |
/*
|
131 |
* (non-Javadoc)
|
132 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
133 |
*/
|
134 |
public void addFilter(Params params) throws FilterTypeException { |
135 |
addFilter(ToLumSaFilter.class, params); |
136 |
} |
137 |
|
138 |
/*
|
139 |
* (non-Javadoc)
|
140 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
|
141 |
*/
|
142 |
public RasterFilter createFilter(Params params) {
|
143 |
int[] renderBands = { 0, 1, 2 }; |
144 |
String b = ((String) params.getParamById("RenderBands").getDefaultValue()); |
145 |
String[] bands = b.split(" "); |
146 |
renderBands[0] = new Integer(bands[0]).intValue(); |
147 |
renderBands[1] = new Integer(bands[1]).intValue(); |
148 |
renderBands[2] = new Integer(bands[2]).intValue(); |
149 |
Double hue = ((Double) params.getParamById("hue").getDefaultValue()); |
150 |
Double sat = ((Double) params.getParamById("saturation").getDefaultValue()); |
151 |
Double lum = ((Double) params.getParamById("luminosity").getDefaultValue()); |
152 |
|
153 |
RasterFilter filter = new ToLumSaByteFilter();
|
154 |
filter.addParam("hue", hue);
|
155 |
filter.addParam("luminosity", lum);
|
156 |
filter.addParam("saturation", sat);
|
157 |
filter.addParam("renderBands", renderBands);
|
158 |
return filter;
|
159 |
} |
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
|
164 |
*/
|
165 |
public int createFilterListFromStrings(List<String> filters, String fil, int filteri) { |
166 |
return filteri;
|
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getStringsFromFilterList(java.util.ArrayList, org.gvsig.raster.grid.filter.RasterFilter)
|
172 |
*/
|
173 |
public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) { |
174 |
return filterList;
|
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
|
180 |
*/
|
181 |
public RasterFilterList getFilterList() {
|
182 |
return filterList;
|
183 |
} |
184 |
|
185 |
/*
|
186 |
* (non-Javadoc)
|
187 |
* @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
|
188 |
*/
|
189 |
public void setFilterList(RasterFilterList filterList) { |
190 |
this.filterList = filterList;
|
191 |
} |
192 |
} |