Revision 22446
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/HistogramMatchProcess.java | ||
---|---|---|
41 | 41 |
package org.gvsig.remotesensing.mosaic.process; |
42 | 42 |
|
43 | 43 |
import java.io.File; |
44 |
import java.util.ArrayList;
|
|
44 |
import java.io.IOException;
|
|
45 | 45 |
|
46 | 46 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
47 | 47 |
import org.gvsig.raster.RasterProcess; |
48 |
import org.gvsig.raster.beans.previewbase.ParamStruct; |
|
49 |
import org.gvsig.raster.dataset.Params; |
|
48 |
import org.gvsig.raster.buffer.BufferFactory; |
|
49 |
import org.gvsig.raster.buffer.RasterBuffer; |
|
50 |
import org.gvsig.raster.buffer.WriterBufferServer; |
|
51 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
|
52 |
import org.gvsig.raster.dataset.IRasterDataSource; |
|
53 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
|
54 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
|
50 | 55 |
import org.gvsig.raster.datastruct.Histogram; |
56 |
import org.gvsig.raster.grid.Grid; |
|
51 | 57 |
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; |
|
58 |
import org.gvsig.raster.grid.filter.histogramMatching.HistogramMatchingByteFilter; |
|
54 | 59 |
import org.gvsig.raster.util.RasterToolsUtil; |
55 |
import org.gvsig.raster.util.process.FilterProcess; |
|
56 | 60 |
|
57 | 61 |
import com.iver.andami.PluginServices; |
58 | 62 |
import com.iver.andami.Utilities; |
... | ... | |
76 | 80 |
View view= null; |
77 | 81 |
int progreso=0; |
78 | 82 |
String activeLayer = null; |
79 |
FilterProcess filterProcess= null; |
|
80 | 83 |
String layerInProcess= null; |
81 | 84 |
int countInProcess=0,totalcount=0; |
82 | 85 |
int numbands = 0; |
86 |
RasterFilter filtro= new HistogramMatchingByteFilter(); |
|
87 |
RasterBuffer rasterResult=null; |
|
88 |
WriterBufferServer writerBufferServer=null; |
|
89 |
boolean optionLoad= false; |
|
90 |
|
|
91 |
|
|
83 | 92 |
/** Metodo en el que se recogen los par?metros para el proceso |
84 | 93 |
* layers conjunto de capas a las que se aplica el proceso |
85 | 94 |
* histogramMaster histograma de referencia |
... | ... | |
91 | 100 |
histogramMaster= (Histogram) getParam("histogramMaster"); |
92 | 101 |
numbands = ((Integer)getParam("numbands")).intValue(); |
93 | 102 |
view= (View)getParam("view"); |
103 |
// Opcion para carga de resultados en la vista |
|
104 |
optionLoad = getBooleanParam("load"); |
|
105 |
// PROVISIONAL |
|
106 |
optionLoad=true; |
|
94 | 107 |
} |
95 | 108 |
|
96 | 109 |
|
... | ... | |
100 | 113 |
* */ |
101 | 114 |
public void process() throws InterruptedException { |
102 | 115 |
try{ |
103 |
progreso=0; |
|
104 | 116 |
int k=0; |
105 | 117 |
String path= null; |
106 | 118 |
totalcount= layers.length-1; |
... | ... | |
109 | 121 |
// Para el resto de los histogramas seleccionados |
110 | 122 |
if(layers[i]!=null){ |
111 | 123 |
k++; |
112 |
FLyrRasterSE raster= (FLyrRasterSE) layers[i].cloneLayer(); |
|
113 | 124 |
layerInProcess= layers[i].getName(); |
114 |
countInProcess=k; |
|
115 |
// Proceso de filtro. Se a?aden los parametros determinados del filtro. |
|
116 |
filterProcess = new FilterProcess(); |
|
117 |
filterProcess.addParam("rendering", null); |
|
118 |
filterProcess.addParam("filename", path); |
|
119 |
|
|
120 |
filterProcess.addParam("rasterdatasource", raster.getDataSource()); |
|
121 |
ArrayList listFilterUsed = new ArrayList(); |
|
122 |
RasterFilter filter = HistogramMatchingListManager.createHistogramMatchFilter(); |
|
123 |
Params params = (Params) filter.getUIParams(filter.getName()).clone(); |
|
124 |
// A?ado el parametro RenderBands a los parametros del filtro |
|
125 |
params.setParam("histogramReference",histogramMaster,0,null); |
|
126 |
params.setParam("numbands",new Integer(numbands),0,null); |
|
127 |
ParamStruct newParam = new ParamStruct(); |
|
128 |
newParam.setFilterClass(HistogramMatchingFilter.class); |
|
129 |
newParam.setFilterName(filter.getName()); |
|
130 |
newParam.setFilterParam(params); |
|
131 |
listFilterUsed.add(newParam); |
|
132 |
|
|
133 |
filterProcess.addParam("listfilterused", listFilterUsed); |
|
134 |
filterProcess.setProgressActive(false); |
|
135 |
filterProcess.run(); |
|
136 |
filterProcess=null; |
|
137 |
loadLayerInToc(path); |
|
125 |
IRasterDataSource dsetCopy = null; |
|
126 |
dsetCopy = layers[i].getDataSource().newDataset(); |
|
127 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy); |
|
128 |
if (!RasterBuffer.loadInMemory(dsetCopy)) |
|
129 |
bufferFactory.setReadOnly(true); |
|
130 |
Grid g= new Grid(bufferFactory); |
|
131 |
filtro.addParam("raster",g.getRasterBuf()); |
|
132 |
filtro.addParam("histogramReference",histogramMaster); |
|
133 |
filtro.addParam("numbands",new Integer(numbands)); |
|
134 |
filtro.addParam("filterName",new String("histogram")); |
|
135 |
filtro.execute(); |
|
136 |
rasterResult=(RasterBuffer) filtro.getResult("raster"); |
|
137 |
if(optionLoad) |
|
138 |
writeToFile(rasterResult,path,i); |
|
138 | 139 |
} |
139 | 140 |
} |
140 | 141 |
|
... | ... | |
144 | 145 |
} |
145 | 146 |
|
146 | 147 |
|
147 |
/** Metodo que carga del fichero pasado como par?metro en la vista. |
|
148 |
* @param filename path con el fichero a cargar |
|
149 |
* * */ |
|
150 |
public void loadLayerInToc(String fileName) { |
|
151 |
//if(!new File(fileName).exists()) |
|
152 |
//return; |
|
153 |
try { |
|
154 |
|
|
155 |
FLyrRasterSE lyr = null; |
|
156 |
int endIndex = fileName.lastIndexOf("."); |
|
157 |
if (endIndex < 0) |
|
158 |
endIndex = fileName.length(); |
|
159 |
|
|
160 |
lyr = FLyrRasterSE.createLayer( |
|
161 |
fileName.substring(fileName.lastIndexOf(File.separator) + 1, endIndex), |
|
162 |
fileName, |
|
163 |
view.getMapControl().getProjection() |
|
164 |
); |
|
165 |
//TODO: TRATAMIENTO DE BANDAS |
|
166 |
if(numbands == 3) |
|
167 |
lyr.setRenderBands(new int[]{0,1,2}); |
|
168 |
else if (numbands==1) |
|
169 |
lyr.setRenderBands(new int[]{0,0,0}); |
|
170 |
if(view == null) |
|
171 |
return; |
|
172 |
view.getModel().getMapContext().getLayers().addLayer(lyr); |
|
173 |
} catch (LoadLayerException e) { |
|
174 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
|
175 |
} |
|
176 |
} |
|
177 |
|
|
178 | 148 |
|
179 | 149 |
public String getTitle() { |
180 | 150 |
return PluginServices.getText(this,"histohramMatchProcess"); |
181 | 151 |
} |
182 | 152 |
|
183 | 153 |
public int getPercent() { |
184 |
//return filterProcess.getPercent(); |
|
185 |
return 0; |
|
154 |
if(writerBufferServer!=null) |
|
155 |
return writerBufferServer.getPercent(); |
|
156 |
else |
|
157 |
return filtro.getPercent(); |
|
186 | 158 |
} |
187 | 159 |
|
188 | 160 |
/** log con la informaci?n del proceso */ |
... | ... | |
191 | 163 |
|
192 | 164 |
} |
193 | 165 |
|
166 |
|
|
167 |
public void writeToFile(RasterBuffer rb, String path,int i){ |
|
168 |
|
|
169 |
try{ |
|
170 |
if(path==null) |
|
171 |
return; |
|
172 |
GeoRasterWriter grw = null; |
|
173 |
writerBufferServer = new WriterBufferServer(rasterResult); |
|
174 |
grw = GeoRasterWriter.getWriter(writerBufferServer, path, rasterResult.getBandCount(),layers[i].getAffineTransform(), rasterResult.getWidth(), rasterResult.getHeight(), rasterResult.getDataType(), GeoRasterWriter.getWriter(path).getParams(), null); |
|
175 |
|
|
176 |
grw.dataWrite(); |
|
177 |
grw.setWkt(layers[i].getWktProjection()); |
|
178 |
grw.writeClose(); |
|
179 |
rasterResult.free(); |
|
180 |
|
|
181 |
int endIndex = path.lastIndexOf("."); |
|
182 |
if (endIndex < 0) |
|
183 |
endIndex = path.length(); |
|
184 |
FLyrRasterSE lyr = FLyrRasterSE.createLayer( |
|
185 |
path.substring(path.lastIndexOf(File.separator) + 1, endIndex), |
|
186 |
path, |
|
187 |
view.getMapControl().getProjection() |
|
188 |
); |
|
189 |
|
|
190 |
view.getMapControl().getMapContext().getLayers().addLayer(lyr); |
|
191 |
view.getMapControl().getMapContext().endAtomicEvent(); |
|
192 |
view.getMapControl().getMapContext().invalidate(); |
|
193 |
|
|
194 |
} catch (NotSupportedExtensionException e) { |
|
195 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer_notsupportedextension"), this, e); |
|
196 |
} catch (RasterDriverException e) { |
|
197 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
|
198 |
} catch (IOException e) { |
|
199 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
|
200 |
} catch (InterruptedException e) { |
|
201 |
Thread.currentThread().interrupt(); |
|
202 |
} catch (LoadLayerException e) { |
|
203 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
|
204 |
} |
|
205 |
|
|
206 |
} |
|
207 |
|
|
194 | 208 |
} |
Also available in: Unified diff