Statistics
| Revision:

root / trunk / extensions / extRasterTools-SE / src / org / gvsig / rastertools / vectorizacion / stretch / StretchProcess.java @ 29999

History | View | Annotate | Download (5.51 KB)

1 22811 nbrodin
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
2
 *
3
 * Copyright (C) 2007 IVER T.I. and Generalitat Valenciana.
4
 *
5
 * This program is free software; you can redistribute it and/or
6
 * modify it under the terms of the GNU General Public License
7
 * as published by the Free Software Foundation; either version 2
8
 * of the License, or (at your option) any later version.
9
 *
10
 * This program is distributed in the hope that it will be useful,
11
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13
 * GNU General Public License for more details.
14
 *
15
 * You should have received a copy of the GNU General Public License
16
 * along with this program; if not, write to the Free Software
17
 * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
18
 */
19
package org.gvsig.rastertools.vectorizacion.stretch;
20
21 22841 nbrodin
import java.io.File;
22
import java.util.ArrayList;
23
24 22811 nbrodin
import org.gvsig.fmap.raster.layers.FLyrRasterSE;
25
import org.gvsig.raster.IProcessActions;
26 22841 nbrodin
import org.gvsig.raster.RasterLibrary;
27
import org.gvsig.raster.RasterProcess;
28
import org.gvsig.raster.beans.previewbase.ParamStruct;
29
import org.gvsig.raster.dataset.Params;
30
import org.gvsig.raster.grid.filter.FilterTypeException;
31
import org.gvsig.raster.grid.filter.RasterFilter;
32
import org.gvsig.raster.grid.filter.RasterFilterList;
33
import org.gvsig.raster.grid.filter.RasterFilterListManager;
34
import org.gvsig.raster.grid.filter.enhancement.LinearStretchEnhancementFilter;
35
import org.gvsig.raster.util.RasterToolsUtil;
36
import org.gvsig.raster.util.process.FilterProcess;
37 22811 nbrodin
38 22841 nbrodin
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
39
40 22811 nbrodin
/**
41
 * Proceso para la generaci?n de la imagen intermedia dividida en tramos.
42
 *
43
 * 19/08/2008
44
 * @author Nacho Brodin nachobrodin@gmail.com
45
 */
46
public class StretchProcess implements IProcessActions {
47
        private FLyrRasterSE                  sourceLayer       = null;
48
        private IProcessActions               endActions        = null;
49
50
        /**
51
         * Asigna el objeto para informar que el proceso ha terminado
52
         * @param endActions
53
         */
54
        public StretchProcess(IProcessActions endActions) {
55
                this.endActions = endActions;
56
        }
57
58 22841 nbrodin
        /**
59
         * Aplica el proceso de filtrado sobre una capa dando como resultado otra capa
60
         * @throws FilterTypeException
61
         */
62
        public void stretchProcess(StretchPreviewRender prevRender, StretchData data ) throws FilterTypeException {
63
                if(sourceLayer == null)
64
                        return;
65
                sourceLayer.setRenderBands(sourceLayer.getRenderBands());
66
67
                RasterProcess filterProcess = new FilterProcess();
68
                filterProcess.setActions(this);
69
                filterProcess.addParam("rendering", sourceLayer);
70
                String tempRaster = RasterLibrary.tempCacheDirectoryPath + File.separator + RasterLibrary.usesOnlyLayerName();
71
                filterProcess.addParam("filename", tempRaster + ".tif");
72
                filterProcess.addParam("rasterdatasource", sourceLayer.getDataSource());
73
                filterProcess.addParam("listfilterused", getParamStruct(sourceLayer, prevRender, data));
74
                filterProcess.addParam("onlyrenderbands", Boolean.TRUE);
75 29999 nbrodin
                filterProcess.addParam("layer", sourceLayer);
76 22841 nbrodin
                filterProcess.start();
77
        }
78
79
        /**
80
         * Obtiene la lista de par?metros de los filtros a?adidos
81
         * @param lyr Capa raster
82
         * @return ArrayList
83
         */
84
        public ArrayList getParamStruct(FLyrRasterSE lyr, StretchPreviewRender prevRender, StretchData data) {
85
                RasterFilterList filterList = new RasterFilterList();
86
                filterList.setInitDataType(lyr.getDataType()[0]);
87
                RasterFilterListManager filterManager = new RasterFilterListManager(filterList);
88
89
                try {
90
                        prevRender.addPosterization(filterManager, lyr);
91
                } catch (FilterTypeException e1) {
92
                        RasterToolsUtil.messageBoxError(RasterToolsUtil.getText(null, "noposterization"), null, e1);
93
                }
94
95
                return getParams(filterList);
96
        }
97
98
        /**
99
         * A partir de una lista de filtros devuelve un array con sus par?metros
100
         * @param filterList
101
         * @return ArrayList
102
         */
103
        public ArrayList getParams(RasterFilterList filterList) {
104
                ArrayList listFilterUsed = new ArrayList();
105
                for (int i = 0; i < filterList.lenght(); i++) {
106
                        try {
107
                                RasterFilter filter = (RasterFilter)filterList.get(i);
108
                                Params params = (Params) filter.getUIParams(filter.getName()).clone();
109
110
                                ParamStruct newParam = new ParamStruct();
111
                                Class c = null;
112
                                if(filter instanceof LinearStretchEnhancementFilter)
113
                                        c = LinearStretchEnhancementFilter.class;
114
                                newParam.setFilterClass(c);
115
                                newParam.setFilterName(filter.getName());
116
                                newParam.setFilterParam(params);
117
                                listFilterUsed.add(newParam);
118
                        } catch (CloneNotSupportedException e) {
119
                        }
120
                }
121
                return listFilterUsed;
122
        }
123
124 22811 nbrodin
        /*
125
         * (non-Javadoc)
126
         * @see org.gvsig.raster.IProcessActions#end(java.lang.Object)
127
         */
128
        public void end(Object param) {
129 22841 nbrodin
                FLyrRasterSE grayConv = null;
130
                try {
131
                        if(param instanceof String)
132
                                grayConv = FLyrRasterSE.createLayer(RasterLibrary.getOnlyLayerName(), (String)param, sourceLayer.getProjection());
133
                } catch (LoadLayerException e) {
134
                        RasterToolsUtil.messageBoxError("error_generating_layer", null, e);
135
                }
136
                if(endActions != null)
137
                        endActions.end(new Object[]{this, grayConv});
138 22811 nbrodin
        }
139
140
        /*
141
         * (non-Javadoc)
142
         * @see org.gvsig.raster.IProcessActions#interrupted()
143
         */
144
        public void interrupted() {
145
        }
146
147
        /**
148
         * Asigna la capa fuente
149
         * @param sourceLayer
150
         */
151
        public void setSourceLayer(FLyrRasterSE sourceLayer) {
152
                this.sourceLayer = sourceLayer;
153
        }
154
155
        /**
156
         * Asigna el interfaz para que el proceso ejectute las acciones de finalizaci?n
157
         * al acabar.
158
         * @param endActions
159
         */
160
        public void setProcessActions(IProcessActions endActions) {
161
                this.endActions = endActions;
162
        }
163
}