svn-gvsig-desktop / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / mosaic / process / HistogramMatchProcess.java @ 21080
History | View | Annotate | Download (5.84 KB)
1 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2006 Instituto de Desarrollo Regional 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 |
* For more information, contact:
|
20 |
*
|
21 |
* Generalitat Valenciana
|
22 |
* Conselleria d'Infraestructures i Transport
|
23 |
* Av. Blasco Iba?ez, 50
|
24 |
* 46010 VALENCIA
|
25 |
* SPAIN
|
26 |
*
|
27 |
* +34 963862235
|
28 |
* gvsig@gva.es
|
29 |
* www.gvsig.gva.es
|
30 |
*
|
31 |
* or
|
32 |
*
|
33 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
34 |
* Campus Universitario s/n
|
35 |
* 02071 Alabacete
|
36 |
* Spain
|
37 |
*
|
38 |
* +34 967 599 200
|
39 |
*/
|
40 |
|
41 |
package org.gvsig.remotesensing.mosaic.process; |
42 |
|
43 |
import java.io.File; |
44 |
import java.util.ArrayList; |
45 |
|
46 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
47 |
import org.gvsig.raster.RasterProcess; |
48 |
import org.gvsig.raster.beans.previewbase.ParamStruct; |
49 |
import org.gvsig.raster.dataset.Params; |
50 |
import org.gvsig.raster.datastruct.Histogram; |
51 |
import org.gvsig.raster.grid.filter.RasterFilter; |
52 |
import org.gvsig.raster.grid.filter.histogramMatching.HistogramMatchingFilter; |
53 |
import org.gvsig.raster.grid.filter.histogramMatching.HistogramMatchingListManager; |
54 |
import org.gvsig.raster.util.RasterNotLoadException; |
55 |
import org.gvsig.raster.util.RasterToolsUtil; |
56 |
import org.gvsig.raster.util.process.FilterProcess; |
57 |
|
58 |
import com.iver.andami.PluginServices; |
59 |
import com.iver.andami.Utilities; |
60 |
import com.iver.cit.gvsig.project.documents.view.gui.View; |
61 |
|
62 |
|
63 |
/**
|
64 |
* Clase que implementa el proceso de Histogram Matching para un conjuto de imagenes
|
65 |
* que se quieren hacer corresponder con un histogram de referencia. El proceso tomara como parametros
|
66 |
* un conjunto de capas y un histograma maestro y ejecutara de forma secuencial un filtro para cada
|
67 |
* par histograma source - histograma referencia.
|
68 |
*
|
69 |
* @author aMu?oz (alejandro.mu?oz@uclm.es)
|
70 |
* @version 30/4/2008
|
71 |
* */
|
72 |
public class HistogramMatchProcess extends RasterProcess{ |
73 |
|
74 |
FLyrRasterSE layers[]= null; |
75 |
Histogram histogramMaster= null;
|
76 |
View view= null; |
77 |
int progreso=0; |
78 |
String activeLayer = null; |
79 |
FilterProcess filterProcess= null;
|
80 |
String layerInProcess= null; |
81 |
int countInProcess=0; |
82 |
|
83 |
/** Metodo en el que se recogen los par?metros para el proceso
|
84 |
* layers conjunto de capas a las que se aplica el proceso
|
85 |
* histogramMaster histograma de referencia
|
86 |
* view vista sobre la que se cargan los resultados
|
87 |
* */
|
88 |
|
89 |
public void init() { |
90 |
layers =(FLyrRasterSE []) getParam("layers"); |
91 |
histogramMaster= (Histogram) getParam("histogramMaster");
|
92 |
view= (View)getParam("view"); |
93 |
} |
94 |
|
95 |
|
96 |
/** Proceso.
|
97 |
* Para cada capa de las contenidas en layers, se aplica un filtro de histogramMatching
|
98 |
* entre la capa y el histograma de referencia pasado como paramero.
|
99 |
* */
|
100 |
public void process() throws InterruptedException { |
101 |
try{
|
102 |
progreso=0;
|
103 |
int k=0; |
104 |
String path= null; |
105 |
for (int i=0; i< layers.length;i++){ |
106 |
path = Utilities.createTempDirectory() + File.separator + "hist"+i+ ".tif"; |
107 |
// Para el resto de los histogramas seleccionados
|
108 |
if(layers[i]!=null){ |
109 |
k++; |
110 |
FLyrRasterSE raster= (FLyrRasterSE) layers[i].cloneLayer(); |
111 |
layerInProcess= layers[i].getName(); |
112 |
countInProcess=k; |
113 |
// Proceso de filtro. Se a?aden los parametros determinados del filtro.
|
114 |
/*FilterProcess*/
|
115 |
filterProcess = new FilterProcess();
|
116 |
filterProcess.addParam("rendering", null); |
117 |
filterProcess.addParam("filename", path);
|
118 |
|
119 |
filterProcess.addParam("rasterdatasource", raster.getDataSource());
|
120 |
ArrayList listFilterUsed = new ArrayList(); |
121 |
RasterFilter filter = HistogramMatchingListManager.createHistogramMatchFilter(); |
122 |
Params params = (Params) filter.getUIParams(filter.getName()).clone(); |
123 |
// A?ado el parametro RenderBands a los parametros del filtro
|
124 |
params.setParam("histogramReference",histogramMaster,0,null); |
125 |
ParamStruct newParam = new ParamStruct();
|
126 |
newParam.setFilterClass(HistogramMatchingFilter.class); |
127 |
newParam.setFilterName(filter.getName()); |
128 |
newParam.setFilterParam(params); |
129 |
listFilterUsed.add(newParam); |
130 |
|
131 |
filterProcess.addParam("listfilterused", listFilterUsed);
|
132 |
filterProcess.setProgressActive(false);
|
133 |
progreso=(int)(i*100/layers.length); |
134 |
filterProcess.run(); |
135 |
filterProcess=null;
|
136 |
loadLayerInToc(path); |
137 |
} |
138 |
} |
139 |
|
140 |
}catch (Exception e2) { |
141 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "filter_error"), this, e2); |
142 |
} |
143 |
} |
144 |
|
145 |
|
146 |
/** Metodo que carga del fichero pasado como par?metro en la vista.
|
147 |
* @param filename path con el fichero a cargar
|
148 |
* * */
|
149 |
public void loadLayerInToc(String fileName) { |
150 |
if(!new File(fileName).exists()) |
151 |
return;
|
152 |
try {
|
153 |
RasterToolsUtil.loadLayer(PluginServices.getMDIManager().getWindowInfo(view).getTitle(), fileName, null);
|
154 |
} catch (RasterNotLoadException e) {
|
155 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
156 |
} |
157 |
} |
158 |
|
159 |
|
160 |
public String getTitle() { |
161 |
return PluginServices.getText(this,"histohramMatchProcess"); |
162 |
} |
163 |
|
164 |
public int getPercent() { |
165 |
//return filterProcess.getPercent();
|
166 |
return 0; |
167 |
} |
168 |
|
169 |
/** log con la informaci?n del proceso */
|
170 |
public String getLog(){ |
171 |
return PluginServices.getText(this,"hiatogramMatchLog")+layerInProcess+" (/"+countInProcess+")"; |
172 |
|
173 |
} |
174 |
|
175 |
|
176 |
} |