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 / enhancement / EnhancementStretchListManager.java @ 1400

History | View | Annotate | Download (29.3 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.enhancement;
23

    
24
import java.util.ArrayList;
25

    
26
import org.gvsig.fmap.dal.coverage.RasterLibrary;
27
import org.gvsig.fmap.dal.coverage.datastruct.Params;
28
import org.gvsig.fmap.dal.coverage.exception.FileNotOpenException;
29
import org.gvsig.fmap.dal.coverage.exception.FilterTypeException;
30
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException;
31
import org.gvsig.fmap.dal.coverage.exception.RasterDriverException;
32
import org.gvsig.fmap.dal.coverage.grid.RasterFilter;
33
import org.gvsig.fmap.dal.coverage.grid.RasterFilterList;
34
import org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager;
35
import org.gvsig.fmap.dal.coverage.store.props.Statistics;
36
import org.gvsig.raster.impl.datastruct.DefaultStretch;
37
import org.gvsig.raster.impl.grid.filter.RasterFilterListManagerImpl;
38
import org.gvsig.raster.impl.grid.filter.statistics.StatisticsListManager;
39
import org.gvsig.raster.impl.store.ParamImpl;
40
import org.gvsig.tools.ToolsLocator;
41
import org.gvsig.tools.extensionpoint.ExtensionPoint;
42
import org.gvsig.tools.extensionpoint.ExtensionPointManager;
43
/**
44
 * Gestor de la pila de filtros para el filtro de realce por intervalos.
45
 *
46
 * @author Nacho Brodin (nachobrodin@gmail.com)
47
 */
48
public class EnhancementStretchListManager implements RasterFilterListManager {
49
        protected RasterFilterList          filterList        = null;
50
        private RasterFilterListManagerImpl filterListManager = null;
51
        private Statistics                  stats             = null;
52

    
53
        /**
54
         * Constructor
55
         * @param filterListManager
56
         */
57
        public EnhancementStretchListManager(RasterFilterList filterList) {
58
                this.filterList = filterList;
59
                stats = (Statistics)filterList.getEnvParam("IStatistics");
60
        }
61
        
62
        /**
63
         * Constructor
64
         * @param filterListManager
65
         */
66
        public EnhancementStretchListManager(RasterFilterListManagerImpl filterListManager) {
67
                this.filterListManager = filterListManager;
68
                this.filterList = filterListManager.getFilterList();
69
                stats = (Statistics)filterList.getEnvParam("IStatistics");
70
        }
71
        
72
        /*
73
         * (non-Javadoc)
74
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#containsFilter(java.lang.String)
75
         */
76
        @SuppressWarnings("unchecked")
77
        public Class getFilterClassByID(String id) {
78
                if(id.compareTo("enhanced_stretch") == 0)
79
                        return LinearStretchEnhancementFilter.class;
80
                return null;
81
        }
82

    
83
        /**
84
         * Asigna el objeto con las estadisticas.
85
         * @param stats
86
         */
87
        public void setStatistics(Statistics stats) {
88
                this.stats = stats;
89
        }
90

    
91
        /**
92
         * Registra EnhancementStretchListManager en los puntos de extension de RasterFilter
93
         */
94
        public static void register() {
95
                ExtensionPointManager extensionPoints = ToolsLocator.getExtensionPointManager();
96
                ExtensionPoint point = extensionPoints.get("RasterFilter");
97
                point.append("EnhancementStretch", "", EnhancementStretchListManager.class);
98
        }
99

    
100
        /**
101
         * A?ade un filtro de realce.
102
         * La forma de inserci?n del filtro es fija ya que la inserci?n de un realce lleva implicita
103
         * la inserci?n de un filtro de recorte de colas (tailtrim), aunque no en todos los casos.
104
         * Si ya existe un filtro de realce en la lista se obtiene la posici?n de este.
105
         * Si es necesario un recorte de colas entonces se comprueba si existe un uno reemplazandose
106
         * por el nuevo y sino se insertar? uno. Al final reemplazamos el realce que existia.
107
         *
108
         * Si por el contrario no existen realce ni trim se a?aden ambos al final de la lista.
109
         * @param stats Objeto de estadisticas asociado
110
         * @param tailTrim porcentaje de recorte de colas. Ser? un valor entre 0 y 1.
111
         * @param insertionMode Modo de inserci?n
112
         * @param renderBands bandas RGB mostradas en la visualizaci?n.
113
         * @throws FilterTypeException
114
         */
115
        public void addEnhancedStretchFilter(DefaultLinearStretchParams leParams, Statistics stats, int[] renderBands, boolean removeEnds) throws FilterTypeException {
116
                try {
117
                        if (!leParams.hasTailTrim()) { // En este caso siempre es necesario el m?ximo y
118
                                // m?nimo
119
                                if (!stats.isCalculated())
120
                                        try {
121
                                                stats.calculate(RasterLibrary.statisticsScale);
122
                                        } catch (FileNotOpenException e) {
123
                                                // No podemos aplicar el filtro
124
                                                return;
125
                                        } catch (RasterDriverException e) {
126
                                                // No podemos aplicar el filtro
127
                                                return;
128
                                        }
129
                        } else {
130
                                StatisticsListManager slm = null;
131
                                if(filterListManager !=  null)
132
                                        slm = new StatisticsListManager(filterListManager, stats);
133
                                else
134
                                        slm = new StatisticsListManager(filterList);
135
                                slm.addTailFilter(leParams.getTailTrimList(), 0D, removeEnds, stats);
136
                        }
137

    
138
                        RasterFilter filter = createEnhancedFilter(leParams, stats, renderBands, removeEnds);
139
                        if (filter != null)
140
                                filterList.add(filter);
141
                } catch (ProcessInterruptedException e) {
142
                        //Si se ha interrumpido no a?adimos el filtro
143
                }
144
        }
145
        
146
        /*
147
         * (non-Javadoc)
148
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#addFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
149
         */
150
        public void addFilter(Params params) throws FilterTypeException {
151
                int[] renderBands = (int[])params.getParamById("renderBands").getDefaultValue();
152
                Statistics stats = (Statistics)params.getParamById("stats").getDefaultValue();
153
                boolean removeEnds = ((Boolean)params.getParamById("remove").getDefaultValue()).booleanValue();
154
                
155
                DefaultLinearStretchParams p = null;
156

    
157
                try {
158
                        if(        params.getParamById("tailtrim") != null &&
159
                                params.getParamById("tailtrim").getDefaultValue() != null && 
160
                                params.getParamById("rgb").getDefaultValue() != null) {
161
                                double tailtrim = ((Double)params.getParamById("tailtrim").getDefaultValue()).doubleValue();
162
                                boolean rgb = ((Boolean)params.getParamById("rgb").getDefaultValue()).booleanValue();
163
                                p = DefaultLinearStretchParams.createStandardParam(renderBands, tailtrim, stats, rgb);
164
                        } else {
165
                                //Si stretch vale null se usan los par?metros por defecto de LinearStretchParams
166
                                if(params.getParamById("stretchs").getDefaultValue() == null) {
167
                                        boolean rgb = false;
168
                                        if(params.getParamById("rgb").getDefaultValue() != null)
169
                                                rgb = ((Boolean)params.getParamById("rgb").getDefaultValue()).booleanValue();
170
                                        p = DefaultLinearStretchParams.createStandardParam(renderBands, 0.0, stats, rgb);
171
                                }
172
                        }
173
                } catch (FileNotOpenException e) {
174
                        throw new FilterTypeException("", e);
175
                } catch (RasterDriverException e) {
176
                        throw new FilterTypeException("", e);
177
                }
178
                addEnhancedStretchFilter(p, stats, renderBands, removeEnds);
179
        }
180

    
181
        /**
182
         * Crea un filtro de realce por tramos de forma est?tica
183
         * @param leParams Par?metros del filtro
184
         * @param stats
185
         * @param renderBands
186
         * @return
187
         */
188
        public static RasterFilter createEnhancedFilter(DefaultLinearStretchParams leParams, Statistics stats, int[] renderBands, boolean removeEnds) {
189
                RasterFilter filter = new LinearStretchEnhancementFloatFilter();
190
                if (filter != null) {
191
                        filter.addParam("stats", stats);
192
                        filter.addParam("remove", new Boolean(false));
193
                        filter.addParam("renderBands", renderBands);
194
                        filter.addParam("stretchs", leParams);
195
                        filter.addParam("remove", new Boolean(removeEnds));
196
                }
197

    
198
                return filter;
199
        }
200

    
201
        /**
202
         * Convierte un array de dobles a una cadena
203
         * @param values
204
         * @return
205
         */
206
        private String convertArrayToString(double[] values) {
207
                StringBuffer buffer = new StringBuffer();
208
                for (int i = 0; i < values.length; i++) {
209
                        buffer.append(values[i]);
210
                        if (i < (values.length - 1))
211
                                buffer.append(",");
212
                }
213
                return buffer.toString();
214
        }
215

    
216
        /**
217
         * Convierte una array de enteros a una cadena
218
         * @param values
219
         * @return
220
         */
221
        private String convertArrayToString(int[] values) {
222
                StringBuffer buffer = new StringBuffer();
223
                for (int i = 0; i < values.length; i++) {
224
                        buffer.append(values[i]);
225
                        if (i < (values.length - 1))
226
                                buffer.append(",");
227
                }
228
                return buffer.toString();
229
        }
230

    
231
        /**
232
         * Convierte una cadena a un array de enteros
233
         * @param from
234
         * @return
235
         */
236
        private int[] StringToIntegerArray(String from) {
237
                String[] valueList = from.split(",");
238
                int[] values = new int[valueList.length];
239
                for (int i = 0; i < values.length; i++)
240
                        try {
241
                                values[i] = Integer.parseInt(valueList[i]);
242
                        } catch (NumberFormatException e) {
243
                        }
244
                return values;
245
        }
246

    
247
        /**
248
         * Convierte una cadena a un array de dobles
249
         * @param from
250
         * @return
251
         */
252
        private double[] StringToDoubleArray(String from) {
253
                String[] valueList = from.split(",");
254
                double[] values = new double[valueList.length];
255
                for (int i = 0; i < values.length; i++)
256
                        try {
257
                                values[i] = Double.parseDouble(valueList[i]);
258
                        } catch (NumberFormatException e) {
259
                        }
260
                return values;
261
        }
262

    
263
        /**
264
         * Guarda en el array de valores, todos los valores del objeto Strech para ser
265
         * almacenado en el
266
         * @param filterList
267
         * @param band
268
         * @param stretch
269
         */
270
        @SuppressWarnings("unchecked")
271
        private void putStretchBand(ArrayList filterList, String band, DefaultStretch stretch) {
272
                filterList.add("filter.linearstretchenhancement." + band + ".maxValue=" + stretch.maxValue);
273
                filterList.add("filter.linearstretchenhancement." + band + ".minValue=" + stretch.minValue);
274
                if (stretch.offset != null)
275
                        filterList.add("filter.linearstretchenhancement." + band + ".offset=" + convertArrayToString(stretch.offset));
276
                if (stretch.scale != null)
277
                        filterList.add("filter.linearstretchenhancement." + band + ".scale=" + convertArrayToString(stretch.scale));
278
                if (stretch.stretchIn != null)
279
                        filterList.add("filter.linearstretchenhancement." + band + ".stretchIn=" + convertArrayToString(stretch.stretchIn));
280
                if (stretch.stretchOut != null)
281
                        filterList.add("filter.linearstretchenhancement." + band + ".stretchOut=" + convertArrayToString(stretch.stretchOut));
282
                filterList.add("filter.linearstretchenhancement." + band + ".tailTrimMax=" + stretch.tailTrimMax);
283
                filterList.add("filter.linearstretchenhancement." + band + ".tailTrimMin=" + stretch.tailTrimMin);
284
                filterList.add("filter.linearstretchenhancement." + band + ".tailTrimValueMax=" + stretch.tailTrimValueMax);
285
                filterList.add("filter.linearstretchenhancement." + band + ".tailTrimValueMin=" + stretch.tailTrimValueMin);
286
                filterList.add("filter.linearstretchenhancement." + band + ".functionType=" + stretch.functionType);
287
                filterList.add("filter.linearstretchenhancement." + band + ".valueFunction=" + stretch.valueFunction);
288
        }
289

    
290
        /**
291
         * Obtiene un Array de Strings a partir de una pila de filtros. Cada elemento
292
         * del array tendr? la forma de elemento=valor.
293
         */
294
        @SuppressWarnings("unchecked")
295
        public ArrayList getStringsFromFilterList(ArrayList filterList, RasterFilter rf) {
296
                if (rf instanceof LinearStretchEnhancementFilter) {
297
                        LinearStretchEnhancementFilter filter = (LinearStretchEnhancementFilter) rf;
298
                        DefaultLinearStretchParams stretchs = (DefaultLinearStretchParams) filter.getParam("stretchs");
299
                        int [] renderBands = (int[]) filter.getParam("renderBands");
300
                        
301
                        filterList.add("filter.linearstretchenhancement.active=true");
302
                        filterList.add("filter.linearstretchenhancement.removeends=" + filter.getRemoveEnds());
303
                        putStretchBand(filterList, "red", stretchs.red);
304
                        putStretchBand(filterList, "green", stretchs.green);
305
                        putStretchBand(filterList, "blue", stretchs.blue);
306
                        filterList.add("filter.linearstretchenhancement.renderbands=" + convertArrayToString(renderBands));
307
                        filterList.add("filter.linearstretchenhancement.RGB=" + Boolean.valueOf(stretchs.rgb).toString());
308
                }
309

    
310
                return filterList;
311
        }
312

    
313
        /**
314
         * Configura algun parametro del objeto Stretch, respecto a una banda, su
315
         * propiedad y el valor, en caso de no encontrar la propiedad o no ser dicha
316
         * banda, devuelve false. Es util para usarlo para extraer los valores de
317
         * createFilterListFromStrings
318
         * @param band
319
         * @param property
320
         * @param value
321
         * @param stretch
322
         * @return
323
         */
324
        public boolean getStretchBand(String band, String property, String value, DefaultStretch stretch) {
325
                if (property.startsWith("filter.linearstretchenhancement." + band)) {
326
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".maxValue")) {
327
                                stretch.maxValue = Double.parseDouble(value);
328
                                return true;
329
                        }
330
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".minValue")) {
331
                                stretch.minValue = Double.parseDouble(value);
332
                                return true;
333
                        }
334
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".offset")) {
335
                                stretch.offset = StringToDoubleArray(value);
336
                                return true;
337
                        }
338
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".scale")) {
339
                                stretch.scale = StringToDoubleArray(value);
340
                                return true;
341
                        }
342
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".stretchIn")) {
343
                                stretch.stretchIn = StringToDoubleArray(value);
344
                                return true;
345
                        }
346
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".stretchOut")) {
347
                                stretch.stretchOut = StringToIntegerArray(value);
348
                                return true;
349
                        }
350
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".tailTrimMax")) {
351
                                stretch.tailTrimMax = Double.parseDouble(value);
352
                                return true;
353
                        }
354
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".tailTrimMin")) {
355
                                stretch.tailTrimMin = Double.parseDouble(value);
356
                                return true;
357
                        }
358
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".tailTrimValueMax")) {
359
                                stretch.tailTrimValueMax = Double.parseDouble(value);
360
                                return true;
361
                        }
362
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".tailTrimValueMin")) {
363
                                stretch.tailTrimValueMin = Double.parseDouble(value);
364
                                return true;
365
                        }
366
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".functionType")) {
367
                                stretch.functionType = Integer.parseInt(value);
368
                                return true;
369
                        }
370
                        if (property.startsWith("filter.linearstretchenhancement." + band + ".valueFunction")) {
371
                                stretch.valueFunction = Double.parseDouble(value);
372
                                return true;
373
                        }
374
                }
375
                return false;
376
        }
377

    
378
        /*
379
         * (non-Javadoc)
380
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#createFilterListFromStrings(java.util.ArrayList, java.lang.String, int)
381
         */
382
        @SuppressWarnings("unchecked")
383
        public int createFilterListFromStrings(ArrayList filters, String fil, int filteri) throws FilterTypeException {
384
                String pkgBase = "filter.linearstretchenhancement.";
385
                if (fil.startsWith(pkgBase + "active")) {
386
                        boolean exec = true;
387
                        boolean removeEnds = false;
388
                        if ((RasterFilterListManagerImpl.getValue(fil).equals("false")))
389
                                exec = false;
390
                        filters.remove(0);
391
                        int[] renderBands = new int[] { 0, 0, 0 };
392
                        DefaultLinearStretchParams stretchParams = new DefaultLinearStretchParams();
393

    
394
                        for (int propFilter = 0; propFilter < filters.size(); propFilter++) {
395
                                String elem = (String) filters.get(propFilter);
396
                                String value = RasterFilterListManagerImpl.getValue(elem);
397

    
398
                                if (elem.startsWith("filter.linearstretchenhancement.renderbands")) {
399
                                        renderBands = StringToIntegerArray(value);
400
                                        continue;
401
                                }
402

    
403
                                if (elem.startsWith("filter.linearstretchenhancement.RGB")) {
404
                                        stretchParams.rgb = Boolean.parseBoolean(value);
405
                                        continue;
406
                                }
407

    
408
                                if (elem
409
                                                .startsWith("filter.linearstretchenhancement.removeends")) {
410
                                        removeEnds = Boolean.parseBoolean(value);
411
                                        continue;
412
                                }
413

    
414
                                if (getStretchBand("red", elem, value, stretchParams.red))
415
                                        continue;
416
                                if (getStretchBand("green", elem, value, stretchParams.green))
417
                                        continue;
418
                                if (getStretchBand("blue", elem, value, stretchParams.blue))
419
                                        continue;
420
                        }
421

    
422
                        filterList.remove(LinearStretchEnhancementFilter.class);
423
                        addEnhancedStretchFilter(stretchParams, stats, renderBands,
424
                                        removeEnds);
425

    
426
                        LinearStretchEnhancementFilter lsef = (LinearStretchEnhancementFilter) filterList.getFilterByBaseClass(LinearStretchEnhancementFilter.class);
427
                        lsef.setExec(exec);
428
                }
429
                return filteri;
430
        }
431

    
432
        /*
433
         * (non-Javadoc)
434
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#getRasterFilterList()
435
         */
436
        @SuppressWarnings("unchecked")
437
        public ArrayList getRasterFilterList() {
438
                ArrayList filters = new ArrayList();
439
                filters.add(LinearStretchEnhancementFilter.class);
440
                return filters;
441
        }
442

    
443
        /*
444
         * (non-Javadoc)
445
         * @see org.gvsig.raster.grid.filter.IRasterFilterListManager#addFilter(java.lang.Class, org.gvsig.raster.dataset.Params)
446
         */
447
        @SuppressWarnings("unchecked")
448
        public void addFilter(Class classFilter, Params params) throws FilterTypeException {
449
                if (LinearStretchEnhancementFilter.class.isAssignableFrom(classFilter)) {
450
                        int[] renderBands = { 0, 1, 2 };
451
                        boolean removeEnds = false;
452

    
453
                        DefaultLinearStretchParams leParams = new DefaultLinearStretchParams();
454

    
455
                        for (int i = 0; i < params.getNumParams(); i++) {
456
                                if (((ParamImpl)params.getParam(i)).getId().equals("RenderBands") &&
457
                                        ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof String) {
458
                                        String[] bands = new String((String) ((ParamImpl)params.getParam(i)).getDefaultValue()).split(" ");
459
                                        renderBands[0] = new Integer(bands[0]).intValue();
460
                                        renderBands[1] = new Integer(bands[1]).intValue();
461
                                        renderBands[2] = new Integer(bands[2]).intValue();
462
                                        continue;
463
                                }
464

    
465
                                if (((ParamImpl)params.getParam(i)).getId().equals("Remove"))
466
                                        removeEnds = ((Boolean) ((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
467

    
468
                                if (((ParamImpl)params.getParam(i)).getId().equals("RGB"))
469
                                        leParams.rgb = ((Boolean) ((ParamImpl)params.getParam(i)).getDefaultValue()).booleanValue();
470

    
471
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchInRed") &&
472
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
473
                                        leParams.red.stretchIn = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
474
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchInGreen") &&
475
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
476
                                        leParams.green.stretchIn = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
477
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchInBlue") &&
478
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
479
                                        leParams.blue.stretchIn = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
480
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchOutRed") &&
481
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof int[])
482
                                        leParams.red.stretchOut = ((int[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
483
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchOutGreen") &&
484
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof int[])
485
                                        leParams.green.stretchOut = ((int[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
486
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchOutBlue") &&
487
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof int[])
488
                                        leParams.blue.stretchOut = ((int[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
489

    
490
                                
491
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimRedMin") &&
492
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
493
                                        leParams.red.tailTrimMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
494
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimRedMax") &&
495
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
496
                                        leParams.red.tailTrimMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
497
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimGreenMin") &&
498
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
499
                                        leParams.green.tailTrimMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
500
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimGreenMax") &&
501
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
502
                                        leParams.green.tailTrimMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
503
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimBlueMin") &&
504
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
505
                                        leParams.blue.tailTrimMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
506
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimBlueMax") &&
507
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
508
                                        leParams.blue.tailTrimMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
509

    
510
                                
511
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchRedFunctionType") &&
512
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
513
                                                leParams.red.functionType = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
514
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchRedValueFunction") &&
515
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
516
                                                leParams.red.valueFunction = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
517
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchGreenFunctionType") &&
518
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
519
                                                leParams.green.functionType = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
520
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchGreenValueFunction") &&
521
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
522
                                                leParams.green.valueFunction = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
523
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchBlueFunctionType") &&
524
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Integer)
525
                                                leParams.blue.functionType = ((Integer) ((ParamImpl)params.getParam(i)).getDefaultValue()).intValue();
526
                                if (((ParamImpl)params.getParam(i)).getId().equals("StretchBlueValueFunction") &&
527
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
528
                                                leParams.blue.valueFunction = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
529
                                
530
                                
531
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimRedValueMin") &&
532
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
533
                                                leParams.red.tailTrimValueMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
534
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimRedValueMax") &&
535
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
536
                                                leParams.red.tailTrimValueMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
537
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimGreenValueMin") &&
538
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
539
                                                leParams.green.tailTrimValueMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
540
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimGreenValueMax") &&
541
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
542
                                                leParams.green.tailTrimValueMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
543
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimBlueValueMin") &&
544
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
545
                                                leParams.blue.tailTrimValueMin = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
546
                                if (((ParamImpl)params.getParam(i)).getId().equals("TailTrimBlueValueMax") &&
547
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
548
                                                leParams.blue.tailTrimValueMax = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
549
                                
550
                                
551
                                if (((ParamImpl)params.getParam(i)).getId().equals("RedMaxValue") &&
552
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
553
                                                leParams.red.maxValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
554
                                if (((ParamImpl)params.getParam(i)).getId().equals("RedMinValue") &&
555
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
556
                                                leParams.red.minValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
557
                                if (((ParamImpl)params.getParam(i)).getId().equals("GreenMaxValue") &&
558
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
559
                                                leParams.green.maxValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
560
                                if (((ParamImpl)params.getParam(i)).getId().equals("GreenMinValue") &&
561
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
562
                                                leParams.green.minValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
563
                                if (((ParamImpl)params.getParam(i)).getId().equals("BlueMaxValue") &&
564
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
565
                                                leParams.blue.maxValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
566
                                if (((ParamImpl)params.getParam(i)).getId().equals("BlueMinValue") &&
567
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof Double)
568
                                                leParams.blue.minValue = ((Double) ((ParamImpl)params.getParam(i)).getDefaultValue()).doubleValue();
569

    
570
                                
571
                                if (((ParamImpl)params.getParam(i)).getId().equals("RedOffset") &&
572
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
573
                                        leParams.red.offset = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
574
                                if (((ParamImpl)params.getParam(i)).getId().equals("GreenOffset") &&
575
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
576
                                        leParams.green.offset = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
577
                                if (((ParamImpl)params.getParam(i)).getId().equals("BlueOffset") &&
578
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
579
                                        leParams.blue.offset = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
580
                                if (((ParamImpl)params.getParam(i)).getId().equals("RedScale") &&
581
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
582
                                        leParams.red.scale = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
583
                                if (((ParamImpl)params.getParam(i)).getId().equals("GreenScale") &&
584
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
585
                                        leParams.green.scale = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
586
                                if (((ParamImpl)params.getParam(i)).getId().equals("BlueScale") &&
587
                                                ((ParamImpl)params.getParam(i)).getDefaultValue() instanceof double[])
588
                                        leParams.blue.scale = ((double[]) ((ParamImpl)params.getParam(i)).getDefaultValue());
589
                        }
590

    
591
                        addEnhancedStretchFilter(leParams, (Statistics) filterList.getEnvParam("IStatistics"), renderBands, removeEnds);
592
                }
593
        }
594
        
595
        /*
596
         * (non-Javadoc)
597
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#getFilterList()
598
         */
599
        public RasterFilterList getFilterList() {
600
                return filterList;
601
        }
602
        
603
        /*
604
         * (non-Javadoc)
605
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#setFilterList(org.gvsig.fmap.dal.coverage.grid.RasterFilterList)
606
         */
607
        public void setFilterList(RasterFilterList filterList) {
608
                this.filterList = filterList;
609
        }
610
        
611
        /*
612
         * (non-Javadoc)
613
         * @see org.gvsig.fmap.dal.coverage.grid.RasterFilterListManager#createFilter(org.gvsig.fmap.dal.coverage.datastruct.Params)
614
         */
615
        public RasterFilter createFilter(Params params) throws FilterTypeException {
616
                int[] renderBands = null;
617
                Statistics stats = null;
618
                Boolean removeEnds = null;
619
                
620
                if(params.getParamById("renderBands") != null)
621
                        renderBands = (int[])params.getParamById("renderBands").getDefaultValue();
622
                if(params.getParamById("stats") != null)
623
                        stats = (Statistics)params.getParamById("stats").getDefaultValue();
624
                if(params.getParamById("remove") != null)
625
                        removeEnds = ((Boolean)params.getParamById("remove").getDefaultValue());
626
                
627
                DefaultLinearStretchParams p = null;
628

    
629
                try {
630
                        if(        params.getParamById("tailtrim") != null && 
631
                                params.getParamById("rgb") != null &&
632
                                params.getParamById("tailtrim").getDefaultValue() != null && 
633
                                params.getParamById("rgb").getDefaultValue() != null) {
634
                                double tailtrim = ((Double)params.getParamById("tailtrim").getDefaultValue()).doubleValue();
635
                                boolean rgb = ((Boolean)params.getParamById("rgb").getDefaultValue()).booleanValue();
636
                                p = DefaultLinearStretchParams.createStandardParam(renderBands, tailtrim, stats, rgb);
637
                        } else {
638
                                //Si stretch vale null se usan los par?metros por defecto de LinearStretchParams
639
                                if(        params.getParamById("stretchs") != null &&
640
                                        params.getParamById("stretchs").getDefaultValue() == null) {
641
                                        p = DefaultLinearStretchParams.createStandardParam(renderBands, 0.0, stats, removeEnds.booleanValue());
642
                                }
643
                        }
644
                } catch (FileNotOpenException e) {
645
                        throw new FilterTypeException("", e);
646
                } catch (RasterDriverException e) {
647
                        throw new FilterTypeException("", e);
648
                }
649
                return createEnhancedFilter(p, stats, renderBands, removeEnds != null ? removeEnds.booleanValue() : true);
650
        }
651
}