Statistics
| Revision:

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 / band / ToLumSaManager.java @ 2308

History | View | Annotate | Download (6.42 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.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.RasterFilter;
31
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager;
33
import org.gvsig.fmap.dal.coverage.grid.filter.BaseRasterFilter;
34
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
35
import org.gvsig.raster.impl.store.ParamImpl;
36
import org.gvsig.tools.ToolsLocator;
37
import org.gvsig.tools.extensionpoint.ExtensionPoint;
38
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
39
/**
40
 * Gestor del filtro de Tono, Saturaci?n y Brillo
41
 *
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 boolean isDataTypeSupported(int dataType) {
58
                if(dataType != Buffer.TYPE_BYTE)
59
                        return false;
60
                return true;
61
        }
62
        
63
        public Class<?> getFilterClassByID(String id) {
64
                if( id.compareTo("tolumsa") == 0)
65
                        return ToLumSaFilter.class;
66
                return null;
67
        }
68
        
69
        /**
70
         * Default constructor. Sets the filter list.
71
         * @param filterList
72
         */
73
        public ToLumSaManager(RasterFilterList filterList) {
74
                this.filterList = filterList;
75
        }
76

    
77
        /**
78
         * Constructor.
79
         * Asigna la lista de filtros y el managener global.
80
         *
81
         * @param filterListManager
82
         */
83
        public ToLumSaManager(RasterFilterListManagerImpl filterListManager) {
84
                this.filterList = filterListManager.getFilterList();
85
        }
86

    
87
        /**
88
         * A?ade un filtro de control de Tono, Saturaci?n y Brillo a la lista de filtros.
89
 * @throws FilterTypeException
90
         */
91
        public void addToLumSaFilter(double hue, double luminosity, double saturation, int[] renderBands) throws FilterTypeException {
92
                BaseRasterFilter filter = new ToLumSaByteFilter();
93

    
94
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
95
                if (filter != null) {
96
                        filter.addParam("hue", new Double(hue));
97
                        filter.addParam("luminosity", new Double(luminosity));
98
                        filter.addParam("saturation", new Double(saturation));
99
                        filter.addParam("renderBands", renderBands);
100
                        filterList.add(filter);
101
                }
102
        }
103

    
104
        public List<Class<?>> getRasterFilterList() {
105
                List<Class<?>> filters = new ArrayList<Class<?>>();
106
                filters.add(ToLumSaFilter.class);
107
                return filters;
108
        }
109

    
110
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
111
                if (ToLumSaFilter.class.isAssignableFrom(classFilter)) {
112
                        double hue = 0, saturation = 0, luminosity = 0;
113
                        int[] renderBands = { 0, 1, 2, 3 };
114

    
115
                        for (int i = 0; i < params.getNumParams(); i++) {
116
                                if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") &&
117
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) {
118
                                        String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" ");
119
                                        renderBands[0] = new Integer(bands[0]).intValue();
120
                                        renderBands[1] = new Integer(bands[1]).intValue();
121
                                        renderBands[2] = new Integer(bands[2]).intValue();
122
                                        continue;
123
                                }
124
                                if (((ParamImpl)params.getParam(i)).getId().equals("alphaBand") &&
125
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer) {
126
                                        renderBands[3] = (Integer)((ParamImpl)params.getParam(i)).getDefaultValue();
127
                                        continue;
128
                                }
129
                                if (((ParamImpl)params.getParam(i)).getId().equals("hue"))
130
                                        hue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
131
                                if (((ParamImpl)params.getParam(i)).getId().equals("saturation"))
132
                                        saturation = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
133
                                if (((ParamImpl)params.getParam(i)).getId().equals("luminosity"))
134
                                        luminosity = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
135

    
136
                        }
137
                        addToLumSaFilter(hue, luminosity, saturation, renderBands);
138
                }
139
        }
140
        
141
        public void addFilter(Params params) throws FilterTypeException {
142
                addFilter(ToLumSaFilter.class, params);
143
        }
144
        
145
        public RasterFilter createFilter(Params params) {
146
                int[] renderBands = { 0, 1, 2 };
147
                String b = ((String) params.getParamById("RenderBands").getDefaultValue());
148
                String[] bands = b.split(" "); 
149
                renderBands[0] = new Integer(bands[0]).intValue();
150
                renderBands[1] = new Integer(bands[1]).intValue();
151
                renderBands[2] = new Integer(bands[2]).intValue();
152
                Double hue = ((Double) params.getParamById("hue").getDefaultValue());
153
                Double sat = ((Double) params.getParamById("saturation").getDefaultValue());
154
                Double lum = ((Double) params.getParamById("luminosity").getDefaultValue());
155
                
156
                RasterFilter filter = new ToLumSaByteFilter();
157
                filter.addParam("hue", hue);
158
                filter.addParam("luminosity", lum);
159
                filter.addParam("saturation", sat);
160
                filter.addParam("renderBands", renderBands);
161
                return filter;
162
        }
163

    
164
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) {
165
                return filteri;
166
        }
167

    
168
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
169
                return filterList;
170
        }
171
        
172
        public RasterFilterList getFilterList() {
173
                return filterList;
174
        }
175
        
176
        public void setFilterList(RasterFilterList filterList) {
177
                this.filterList = filterList;
178
        }
179
}