root / trunk / extensions / extRemoteSensing / src / org / gvsig / remotesensing / imagefusion / process / ImageFusionProcess.java @ 22197
History | View | Annotate | Download (7.12 KB)
1 |
/*
|
---|---|
2 |
* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2006 Instituto de Desarrollo Regional and Generalitat Valenciana.
|
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., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*
|
20 |
* For more information, contact:
|
21 |
*
|
22 |
* Generalitat Valenciana
|
23 |
* Conselleria d'Infraestructures i Transport
|
24 |
* Av. Blasco Iba?ez, 50
|
25 |
* 46010 VALENCIA
|
26 |
* SPAIN
|
27 |
*
|
28 |
* +34 963862235
|
29 |
* gvsig@gva.es
|
30 |
* www.gvsig.gva.es
|
31 |
*
|
32 |
* or
|
33 |
*
|
34 |
* Instituto de Desarrollo Regional (Universidad de Castilla La-Mancha)
|
35 |
* Campus Universitario s/n
|
36 |
* 02071 Alabacete
|
37 |
* Spain
|
38 |
*
|
39 |
* +34 967 599 200
|
40 |
*/
|
41 |
|
42 |
package org.gvsig.remotesensing.imagefusion.process; |
43 |
|
44 |
import java.io.IOException; |
45 |
|
46 |
import org.gvsig.fmap.raster.layers.FLyrRasterSE; |
47 |
import org.gvsig.raster.RasterProcess; |
48 |
import org.gvsig.raster.buffer.BufferFactory; |
49 |
import org.gvsig.raster.buffer.RasterBuffer; |
50 |
import org.gvsig.raster.buffer.RasterBufferInvalidException; |
51 |
import org.gvsig.raster.buffer.WriterBufferServer; |
52 |
import org.gvsig.raster.dataset.GeoRasterWriter; |
53 |
import org.gvsig.raster.dataset.IRasterDataSource; |
54 |
import org.gvsig.raster.dataset.NotSupportedExtensionException; |
55 |
import org.gvsig.raster.dataset.io.RasterDriverException; |
56 |
import org.gvsig.raster.grid.Grid; |
57 |
import org.gvsig.raster.util.ColorConversion; |
58 |
import org.gvsig.raster.util.RasterNotLoadException; |
59 |
import org.gvsig.raster.util.RasterToolsUtil; |
60 |
|
61 |
import com.iver.andami.PluginServices; |
62 |
|
63 |
/**
|
64 |
* ImageFusionProccess es la clase que representa el proceso general de fusion de una imagen
|
65 |
*
|
66 |
*@author Alejandro Mu?oz Sanchez (alejandro.munoz@uclm.es)
|
67 |
*@version 28/2/2007
|
68 |
* */
|
69 |
|
70 |
public abstract class ImageFusionProcess extends RasterProcess { |
71 |
|
72 |
protected FLyrRasterSE rasterSE= null; |
73 |
protected Grid inputGrid = null; |
74 |
protected FLyrRasterSE rasterBand= null; |
75 |
protected Grid highBandGrid = null; |
76 |
protected int method= 0; |
77 |
protected double coef = 0.0; |
78 |
protected RasterBuffer rasterResult = null; |
79 |
protected double cellFactorX = 0.0; |
80 |
protected double cellFactorY = 0.0; |
81 |
protected int percent= 0; |
82 |
protected String filename= null ; |
83 |
protected String viewName =null; |
84 |
protected WriterBufferServer writerBufferServer = null; |
85 |
protected ColorConversion colorConversion = new ColorConversion(); |
86 |
protected int band = 0; |
87 |
|
88 |
/** Metodo que recoge los parametros del proceso de fusion de imagenes.
|
89 |
* <LI> rasterSE: Capa de entrada para la fusion</LI>
|
90 |
* <LI> bandaHigth: Banda alta resolucion</LI>
|
91 |
* <LI> metodo: metodo seleccionado </LI>
|
92 |
* <LI> view: vista sobre la que se carga la capa al acabar el proceso</LI>
|
93 |
* <LI> filename: path con el fichero de salida</LI>
|
94 |
*/
|
95 |
public void init() { |
96 |
rasterSE = (FLyrRasterSE) getParam("layer");
|
97 |
rasterBand = (FLyrRasterSE) getParam("high_band");
|
98 |
band= getIntParam("band");
|
99 |
|
100 |
/** if((rasterSE.getDataSource().getExtent().getLLX() != rasterBand.getDataSource().getExtent().getLLX())
|
101 |
|| (rasterSE.getDataSource().getExtent().getLLX() != rasterBand.getDataSource().getExtent().getLLX())
|
102 |
|| (rasterSE.getDataSource().getExtent().getLLX() != rasterBand.getDataSource().getExtent().getLLX())
|
103 |
|| (rasterSE.getDataSource().getExtent().getLLX() != rasterBand.getDataSource().getExtent().getLLX() ))
|
104 |
{
|
105 |
|
106 |
incrementableTask.processFinalize();
|
107 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "extends_distintos"), this);
|
108 |
return;
|
109 |
|
110 |
}
|
111 |
**/
|
112 |
coef = getDoubleParam("coef");
|
113 |
filename = getStringParam("filename");
|
114 |
viewName= (String)getParam("view"); |
115 |
if(rasterSE != null) |
116 |
initparams(); |
117 |
} |
118 |
|
119 |
/**
|
120 |
* Establece el grid con las bandas recogidas en bandList.
|
121 |
*/
|
122 |
public void initparams(){ |
123 |
|
124 |
IRasterDataSource dsetCopy = null;
|
125 |
dsetCopy = rasterSE.getDataSource().newDataset(); |
126 |
BufferFactory bufferFactory = new BufferFactory(dsetCopy);
|
127 |
IRasterDataSource dsetCopy2 = null;
|
128 |
|
129 |
// Ninguna banda seleccionada de alta resolucion seleccionada
|
130 |
if(rasterBand==null){ |
131 |
try {
|
132 |
incrementableTask.processFinalize(); |
133 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "no_band_selected"), this); |
134 |
return;
|
135 |
} catch (Throwable e) { |
136 |
e.printStackTrace(); |
137 |
} |
138 |
} |
139 |
|
140 |
dsetCopy2 = rasterBand.getDataSource().newDataset(); |
141 |
BufferFactory bufferFactory2 = new BufferFactory(dsetCopy2);
|
142 |
|
143 |
if (!RasterBuffer.loadInMemory(dsetCopy))
|
144 |
bufferFactory.setReadOnly(true);
|
145 |
if (!RasterBuffer.loadInMemory(dsetCopy2))
|
146 |
bufferFactory2.setReadOnly(true);
|
147 |
try {
|
148 |
// ELECCION DE BANDAS CASO DEL PROCESO QUE LO PERMITA
|
149 |
bufferFactory.setDrawableBands(rasterSE.getRenderBands()); |
150 |
inputGrid = new Grid(bufferFactory);
|
151 |
|
152 |
highBandGrid = new Grid(bufferFactory2,new int[]{band}); |
153 |
cellFactorX = (double)highBandGrid.getRasterBuf().getWidth()/inputGrid.getRasterBuf().getWidth();
|
154 |
cellFactorY = (double)highBandGrid.getRasterBuf().getHeight()/inputGrid.getRasterBuf().getHeight();
|
155 |
|
156 |
// Comprobar si las dos imagenes tienen el mismo extend
|
157 |
|
158 |
} catch (RasterBufferInvalidException e) {
|
159 |
RasterToolsUtil.messageBoxError("buffer_incorrecto", this, e); |
160 |
} |
161 |
} |
162 |
|
163 |
|
164 |
public String getTitle() { |
165 |
return PluginServices.getText(this,"image_fusion_process"); |
166 |
} |
167 |
|
168 |
public int getPercent() { |
169 |
if(writerBufferServer==null) |
170 |
return percent;
|
171 |
else
|
172 |
return writerBufferServer.getPercent();
|
173 |
} |
174 |
|
175 |
/**
|
176 |
* Escritura del resultado en disco.
|
177 |
*/
|
178 |
public void writeToFile(){ |
179 |
try{
|
180 |
// Escritura de los datos a fichero temporal
|
181 |
int endIndex = filename.lastIndexOf("."); |
182 |
if (endIndex < 0) |
183 |
endIndex = filename.length(); |
184 |
GeoRasterWriter grw = null;
|
185 |
writerBufferServer = new WriterBufferServer(rasterResult);
|
186 |
grw = GeoRasterWriter.getWriter(writerBufferServer, filename, rasterResult.getBandCount(),rasterBand.getAffineTransform(), rasterResult.getWidth(), rasterResult.getHeight(), rasterResult.getDataType(), GeoRasterWriter.getWriter(filename).getParams(), null);
|
187 |
grw.dataWrite(); |
188 |
grw.setWkt(rasterSE.getWktProjection()); |
189 |
grw.writeClose(); |
190 |
rasterResult.free(); |
191 |
RasterToolsUtil.loadLayer(viewName, filename, null);
|
192 |
|
193 |
} catch (NotSupportedExtensionException e) {
|
194 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer_notsupportedextension"), this, e); |
195 |
} catch (IOException e) { |
196 |
RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e); |
197 |
} catch (InterruptedException e) { |
198 |
Thread.currentThread().interrupt();
|
199 |
} catch (RasterNotLoadException e) {
|
200 |
RasterToolsUtil.messageBoxError("error_cargar_capa", this, e); |
201 |
} catch (RasterDriverException e) {
|
202 |
e.printStackTrace(); |
203 |
} |
204 |
|
205 |
} |
206 |
|
207 |
} |