Statistics
| Revision:

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 @ 2438

History | View | Annotate | Download (5.72 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.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.grid.filter.BaseRasterFilter;
34
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
35
import org.gvsig.raster.impl.store.ParamImpl;
36
/**
37
 * Gestor del filtro de Tono, Saturaci?n y Brillo
38
 *
39
 * @author Nacho Brodin (nachobrodin@gmail.com)
40
 */
41
public class ToLumSaManager extends AbstractRasterFilterManager {
42
        private static String   ID = "ToLumSa";
43
        
44
        /**
45
         * Default constructor. Sets the filter list.
46
         * @param filterList
47
         */
48
        public ToLumSaManager(RasterFilterList filterList) {
49
                super(filterList);
50
        }
51
        
52
        public String getManagerID() {
53
                return ID;
54
        }
55

    
56
        public static void register() {
57
                AbstractRasterFilterManager.register(ID, ToLumSaManager.class);
58
        }
59

    
60
        public boolean isDataTypeSupported(int dataType) {
61
                if(dataType != Buffer.TYPE_BYTE)
62
                        return false;
63
                return true;
64
        }
65
        
66
        public Class<?> getFilterClassByID(String id) {
67
                if( id.compareTo("tolumsa") == 0)
68
                        return ToLumSaFilter.class;
69
                return null;
70
        }
71

    
72
        /**
73
         * Constructor.
74
         * Asigna la lista de filtros y el managener global.
75
         *
76
         * @param filterListManager
77
         */
78
        public ToLumSaManager(RasterFilterListManagerImpl filterListManager) {
79
                super(filterListManager.getFilterList());
80
        }
81

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

    
89
                // Cuando el filtro esta creado, tomamos los valores y lo a?adimos a la pila
90
                if (filter != null) {
91
                        filter.addParam("hue", new Double(hue));
92
                        filter.addParam("luminosity", new Double(luminosity));
93
                        filter.addParam("saturation", new Double(saturation));
94
                        filter.addParam("renderBands", renderBands);
95
                        getFilterList().add(filter);
96
                }
97
        }
98

    
99
        public List<Class<?>> getRasterFilterList() {
100
                List<Class<?>> filters = new ArrayList<Class<?>>();
101
                filters.add(ToLumSaFilter.class);
102
                return filters;
103
        }
104

    
105
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
106
                if (ToLumSaFilter.class.isAssignableFrom(classFilter)) {
107
                        double hue = 0, saturation = 0, luminosity = 0;
108
                        int[] renderBands = { 0, 1, 2, 3 };
109

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

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