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 / histogramMatching / HistogramMatchingListManager.java @ 1426

History | View | Annotate | Download (7.63 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.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.store.RasterDataStore;
33
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
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
/**
41
 * Gestion  de la lista de filtros para el filtro de tipo HistogramMatchig
42
 *
43
 * @author aMu?oz (alejandro.munoz@uclm.es)
44
 * @version 27-05-2008
45
 *
46
 * */
47
public class HistogramMatchingListManager implements RasterFilterListManager {
48

    
49
        protected RasterFilterList                        filterList                                = null;
50

    
51
        /**
52
         * Default constructor. Sets the filter list.
53
         * @param filterList
54
         */
55
        public HistogramMatchingListManager(RasterFilterList filterList) {
56
                this.filterList = filterList;
57
        }
58
        
59
        // Constructor
60
        public HistogramMatchingListManager(RasterFilterListManagerImpl filterListManager){
61
                this.filterList = filterListManager.getFilterList();
62
        }
63

    
64
        /** Metodo de registro del filtro */
65
        public static void register() {
66
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
67
                ExtensionPoint point = extensionPoints.get("RasterFilter");
68
                point.append("Matching", "", HistogramMatchingListManager.class);
69
        }
70
        
71
        /*
72
         * (non-Javadoc)
73
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#containsFilter(java.lang.String)
74
         */
75
        public Class<?> getFilterClassByID(String id) {
76
                if(id.compareTo("HistogramMatch") == 0)
77
                        return HistogramMatchingFilter.class;
78
                return null;
79
        }
80

    
81
        /*
82
         * (non-Javadoc)
83
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(java.lang.Class, org.gvsig.fmap.dal.coverage.datastruct.Params)
84
         */
85
        public void addFilter(Class<?> classFilter, Params params) throws FilterTypeException {
86
                if (HistogramMatchingFilter.class.isAssignableFrom(classFilter)) {
87
                        String fileNameOutput = null;
88
                        RasterDataStore raster = null;
89
                        int numbands=0;
90
                        HistogramComputer histogramReference                = null;
91
                        for (int i = 0; i < params.getNumParams(); i++) {
92
                                if (((ParamImpl)params.getParam(i)).getId().equals("raster"))
93
                                        raster = (RasterDataStore)(((ParamImpl)params.getParam(i)).getDefaultValue());
94
                                if (((ParamImpl)params.getParam(i)).getId().equals("numbands"))
95
                                        numbands = ((Integer)(((ParamImpl)params.getParam(i)).getDefaultValue())).intValue();
96
                                if (((ParamImpl)params.getParam(i)).getId().equals("histogramReference"))
97
                                        histogramReference = (HistogramComputer)(((ParamImpl)params.getParam(i)).getDefaultValue());
98
                                if (((ParamImpl)params.getParam(i)).getId().equals("fileNameOutput"))
99
                                        fileNameOutput= new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue());
100
                        }
101
                        addHistogramMatchingFilter(raster,numbands,histogramReference,fileNameOutput);
102
                }
103
        }
104
        
105
        /*
106
         * (non-Javadoc)
107
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
108
         */
109
        public void addFilter(Params params) throws FilterTypeException {
110
                addFilter(HistogramMatchingFilter.class, params);
111
        }
112

    
113
        /**
114
         * A?ade un filtro HistogramMatching a la pila de filtros.
115
         * @param histogramReference Histograma de referencia al que ajustar el raster
116
         * @param fileNameOutput fichero de salida
117
         * @throws FilterTypeException
118
         */
119
        public void addHistogramMatchingFilter(RasterDataStore raster,int numbands,HistogramComputer histogramReference,String fileNameOutput) throws FilterTypeException {
120
                RasterFilter filter = new HistogramMatchingByteFilter();
121
                if (filter != null){
122
                        filter.addParam("raster", raster);
123
                        filter.addParam("histogramReference", histogramReference);
124
                        filter.addParam("numbands",new Integer(numbands));
125
                        filter.addParam("fileNameOutput",fileNameOutput);
126
                        filterList.add(filter);
127
                }
128
        }
129
        
130
        /*
131
         * (non-Javadoc)
132
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
133
         */
134
        public RasterFilter createFilter(Params params) {
135
                if(        params.getParamById("ladoVentana") != null) {
136
                        RasterDataStore raster = ((RasterDataStore) params.getParamById("raster").getDefaultValue());
137
                        Integer numbands = ((Integer) params.getParamById("numbands").getDefaultValue());
138
                        HistogramComputer histogramReference = ((HistogramComputer) params.getParamById("histogramReference").getDefaultValue());
139
                        String fileNameOutput = ((String) params.getParamById("fileNameOutput").getDefaultValue());
140
                        
141
                        RasterFilter filter = new HistogramMatchingByteFilter();
142
                        filter.addParam("raster", raster);
143
                        filter.addParam("histogramReference", histogramReference);
144
                        filter.addParam("numbands",new Integer(numbands));
145
                        filter.addParam("fileNameOutput",fileNameOutput);
146
                        return filter;
147
                }
148
                return null;
149
        }
150

    
151
        public int createFilterListFromStrings(List<String> filters, String fil, int filteri) {
152
                return filteri;
153
        }
154

    
155

    
156
        /**
157
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento
158
         * del array tendr? la forma de elemento=valor.
159
         */
160
        public List<String> getStringsFromFilterList(List<String> filterList, RasterFilter rf) {
161

    
162
                if (rf instanceof HistogramMatchingFilter) {
163
                        HistogramMatchingFilter histogramMatchingFilter = (HistogramMatchingFilter) rf;
164
                        filterList.add("filter.histogramMatch.active=true");
165
                        filterList.add("filter.histogramMatch.histogramReference="+histogramMatchingFilter.histogramReference);
166
                        filterList.add("filter.histogramMatch.numbands="+histogramMatchingFilter.numbands);
167
                        filterList.add("filter.histogramMatch.filenameOutput="+histogramMatchingFilter.fileNameOutput);
168
                        filterList.add("filter.histogramMatch.filterName=" + histogramMatchingFilter.getName());
169
                }
170

    
171
                return filterList;
172
        }
173

    
174
        public List<Class<?>> getRasterFilterList() {
175
                List<Class<?>> filters = new ArrayList<Class<?>>();
176
                filters.add(HistogramMatchingFilter.class);
177
                return filters;
178
        }
179

    
180
        public static RasterFilter createHistogramMatchFilter() {
181
                RasterFilter filter = new HistogramMatchingFilter();
182
                return filter;
183
        }
184
        
185
        /*
186
         * (non-Javadoc)
187
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
188
         */
189
        public RasterFilterList getFilterList() {
190
                return filterList;
191
        }
192
        
193
        /*
194
         * (non-Javadoc)
195
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
196
         */
197
        public void setFilterList(RasterFilterList filterList) {
198
                this.filterList = filterList;
199
        }
200
}