Revision 22800

View differences:

trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/MosaicProcess.java
64 64
import com.iver.cit.gvsig.exceptions.layers.LoadLayerException;
65 65

  
66 66
/** 
67
* Clase que implementa el proceso de construccion de un mosaico.
67
* Clase que implementa el proceso de construccion de un mosaico mediante los m?todos b?sicos.
68 68
* 
69
* @params
70
* <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
71
* <LI>int "methodCode": M?todo de construcci?n (0:Valor m?ximo, 1:Valor m?nimo, 2: Valor Medio,
72
* 3: Valor del pixel de la capa superior, 4:Valor del pixel de la capa inferior)</LI>
73
* <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
74
* 
75
* @result
76
* <LI>outputRassterLayers[]: Capas raster resultantes</LI>
77
*
78
* 
69 79
* @author aMu?oz (alejandro.mu?oz@uclm.es)
70 80
* @version 30/4/2008
71 81
* */
72 82

  
73 83
public class MosaicProcess extends RasterProcess {
84
	
85
	public static final int MAX 		= 0;
86
	public static final int MIN 		= 1;
87
	public static final int AVERAGE 	= 2;
88
	public static final int FRONT 		= 3;
89
	public static final int BACK 		= 4;
74 90

  
75 91
	// Layers que intervienen en el proceso
76 92
	private FLyrRasterSE inputRasterLayers[] = null;
......
96 112
	// writer para escritura en fichero 
97 113
	private WriterBufferServer writerBufferServer =null;
98 114
	
99
//  Numero de bandas 3 o 1 dependiendo de si es RGB o Nivel de gris
100
	int numbands=0;
115
	//  Numero de bandas 3 o 1 dependiendo de si es RGB o Nivel de gris
116
	int resultbandCount=0;
101 117
	 
102 118
	// Fichero de salida
103 119
	private String fileName=null; 
......
112 128
	public void init() {
113 129
		
114 130
		inputRasterLayers= (FLyrRasterSE[])getParam("inputRasterLayers");
115
		codOp= getIntParam("codOp");
116
		numbands= getIntParam("numbands");
117
		fileName = getStringParam("filename");
131
		codOp= getIntParam("methodCode");
132
		resultbandCount= getIntParam("numbands");
133
		fileName = getStringParam("outputPath");
118 134
		
119 135
// 		Calculo del extend resultante
120 136
		fullExtend= calculateExtend(inputRasterLayers);
121 137
		
122
		int bands[]= new int[numbands];
123
		for(int i=0; i<numbands;i++)
124
			bands[i]=i;
125 138
		try {
126
				mosaicGrid= new Grid(fullExtend,fullExtend,IBuffer.TYPE_BYTE,bands);
139
				mosaicGrid= new Grid(fullExtend,fullExtend,IBuffer.TYPE_BYTE,new int[] { 0, 1, 2 });
140
				resultbandCount = mosaicGrid.getBandCount();
127 141
		} catch (RasterBufferInvalidException e) {
128 142
			RasterToolsUtil.messageBoxError("buffer_incorrecto", this, e);
129 143
		}
......
154 168
				if (!RasterBuffer.loadInMemory(dsetCopy))
155 169
					bufferFactory.setReadOnly(true);
156 170
				// Si pongo solo las renderizadas en algunos casos da problemas
157
				bufferFactory.setAllDrawableBands();
171
				bufferFactory.setDrawableBands(inputRasterLayers[i].getRenderBands());
158 172
				bufferFactory.setAreaOfInterest(minX,minY,maxX,maxY,fullExtend.getNX(),fullExtend.getNY());
159 173
				buffers[i]= (RasterBuffer) bufferFactory.getRasterBuf();
160 174
				percent=(int)((i+1)*100/inputRasterLayers.length);
......
174 188
// 		Construccion del mosaico: Operaci?n M?ximo
175 189
		if(codOp==0){
176 190
			int progress = 0;
177
			for(int band=0; band<numbands; band++){
191
			for(int band=0; band<resultbandCount; band++){
178 192
				mosaicGrid.setBandToOperate(band);
179 193
				for(int col=0; col<mosaicGrid.getLayerNY(); col++){
180 194
					progress++;
181 195
					for(int row=0; row<mosaicGrid.getLayerNX();row++){
182 196
						setValueMax(row,col,band);
183 197
					}
184
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*numbands));
198
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
185 199
				}
186 200
			}
187 201
		}
......
189 203
//		Construccion del mosaico: Operaci?n M?nimo
190 204
		if(codOp==1){
191 205
			int progress = 0;
192
			for(int band=0; band<numbands; band++){
206
			for(int band=0; band<resultbandCount; band++){
193 207
				mosaicGrid.setBandToOperate(band);
194 208
				for(int col=0; col<mosaicGrid.getLayerNY(); col++){
195 209
					progress++;
196 210
					for(int row=0; row<mosaicGrid.getLayerNX();row++){
197 211
						setValueMin(row,col,band);
198 212
					}
199
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*numbands));
213
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
200 214
				}
201 215
			}
202 216
		}
......
204 218
// 		Construccion del mosaico: Operaci?n Media
205 219
		if(codOp==2){
206 220
			int progress = 0;
207
			for(int band=0; band<numbands; band++){
221
			for(int band=0; band<resultbandCount; band++){
208 222
				mosaicGrid.setBandToOperate(band);
209 223
				for(int col=0; col<mosaicGrid.getLayerNY(); col++){
210 224
					progress++;
211 225
					for(int row=0; row<mosaicGrid.getLayerNX();row++){
212 226
						setValueMean(row,col,band);
213 227
					}
214
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*numbands));
228
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
215 229
				}
216 230
			}
217 231
		}
......
219 233
//		Construccion del mosaico: Operacion valor de capa de delantera
220 234
		if(codOp==3){
221 235
			int progress = 0;
222
			for(int band=0; band<numbands; band++){
236
			for(int band=0; band<resultbandCount; band++){
223 237
				mosaicGrid.setBandToOperate(band);
224 238
				for(int col=0; col<mosaicGrid.getLayerNY(); col++){
225 239
					progress++;
226 240
					for(int row=0; row<mosaicGrid.getLayerNX();row++){
227 241
						setValueFront(row,col,band);
228 242
					}
229
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*numbands));
243
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
230 244
				}
231 245
			}
232 246
		}
......
245 259
				k--;
246 260
			}
247 261
			int progress = 0;
248
			for(int band=0; band<numbands; band++){
262
			for(int band=0; band<resultbandCount; band++){
249 263
				mosaicGrid.setBandToOperate(band);
250 264
				for(int col=0; col<mosaicGrid.getLayerNY(); col++){
251 265
					progress++;
252 266
					for(int row=0; row<mosaicGrid.getLayerNX();row++){
253 267
						setValueBack(row,col,band);
254 268
					}
255
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*numbands));
269
					percent=(int)( progress*100/(mosaicGrid.getLayerNY()*resultbandCount));
256 270
				}
257 271
			}
258 272
		}
......
329 343
		int buffTotales= buffers.length;
330 344
		for(int buf=0;buf<buffers.length;buf++){
331 345
			int data = (int)((byte)(buffers[buf].getElemByte(y,x,band)));
332
//			TO DO: TENER EN CUENTA NODATA REAL DEL BUFER
346
			//TODO: TENER EN CUENTA NODATA REAL DEL BUFER
333 347
			if(data==(byte)mosaicGrid.getNoDataValue()){
334 348
				buffTotales--;
335 349
				data =0;
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/FeatherProcessBuff.java
51 51
import org.gvsig.raster.buffer.BufferFactory;
52 52
import org.gvsig.raster.buffer.RasterBufferInvalidException;
53 53
import org.gvsig.raster.buffer.WriterBufferServer;
54
import org.gvsig.raster.dataset.FileNotOpenException;
54 55
import org.gvsig.raster.dataset.GeoRasterWriter;
55 56
import org.gvsig.raster.dataset.IBuffer;
56 57
import org.gvsig.raster.dataset.IRasterDataSource;
......
61 62
import org.gvsig.raster.grid.Grid;
62 63
import org.gvsig.raster.grid.GridExtent;
63 64
import org.gvsig.raster.grid.OutOfGridException;
65
import org.gvsig.raster.grid.filter.RasterFilter;
66
import org.gvsig.raster.grid.filter.enhancement.LinearEnhancementFilter;
67
import org.gvsig.raster.grid.filter.enhancement.LinearStretchEnhancementByteFilter;
68
import org.gvsig.raster.grid.filter.enhancement.LinearStretchEnhancementFilter;
69
import org.gvsig.raster.grid.filter.enhancement.LinearStretchParams;
64 70
import org.gvsig.raster.util.RasterToolsUtil;
65 71

  
66 72
import com.iver.andami.PluginServices;
......
70 76
 * Proceso para la obtenci?n de una imagen mosaico a partir de un conjunto de
71 77
 * im?genes por el metodo de degradado (Feathering).
72 78
 * 
79
 * @params
80
 * <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
81
 * <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
82
 * 
83
 * @result
84
 * <LI>FLyrRasterSE: Capa raster con el resultado del mosaico</LI>
85
 *
73 86
 * @author Diego Guerrero Sevilla (diego.guerrero@uclm.es)
74 87
 * 
75 88
 */
......
140 153
		} catch (RasterBufferInvalidException e) {
141 154
			RasterToolsUtil.messageBoxError("error_datos_entrada", this, e);
142 155
		}
143
		fileName = getStringParam("filename");
156
		fileName = getStringParam("outputPath");
144 157
		values = new byte[resultbandCount];
145 158
		result = new double[resultbandCount];
146 159

  
......
155 168
		IRasterDataSource dsetCopy = null;
156 169

  
157 170
		inputBuffers = new IBuffer[inputRasterLayers.length];
158
		int drawableBands[] = { 0, 1, 2 };
159 171
		for (int l = 0; l < inputRasterLayers.length; l++) {
160 172
			dsetCopy = inputRasterLayers[l].getDataSource().newDataset();
161 173
			BufferFactory bufferFactory = new BufferFactory(dsetCopy);
162 174
			bufferFactory.setAdjustToExtent(false);
163 175
			bufferFactory.setNoDataToFill(resultGrid.getNoDataValue());
164
			bufferFactory.setDrawableBands(drawableBands);
176
			bufferFactory.setDrawableBands(inputRasterLayers[l].getRenderBands());
165 177

  
166 178
			try {
167
					bufferFactory.setReadOnly(true);
179
				bufferFactory.setReadOnly(true);
168 180

  
169 181
				bufferFactory.setAreaOfInterest(resultGridExtent.getMin().getX(), resultGridExtent.getMax().getY(), 
170 182
						resultGridExtent.getMax().getX(), resultGridExtent.getMin().getY(), resultGridExtent.getNX(),resultGridExtent.getNY());
......
174 186
			} catch (RasterDriverException e) {
175 187
				RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_datos_entrada"), this, e);	
176 188
			}
189
			/*
190
			//Aplicar filtro de realce si es necesario:
191
			LinearStretchParams leParams = null;
192
			try {
193
				leParams = LinearStretchParams.createStandardParam(inputRasterLayers[l].getRenderBands(), 0.0, bufferFactory.getDataSource().getStatistics(), false);
194
			} catch (FileNotOpenException e) {
195
				// TODO Auto-generated catch block
196
				e.printStackTrace();
197
			} catch (RasterDriverException e) {
198
				// TODO Auto-generated catch block
199
				e.printStackTrace();
200
			}
201
			RasterFilter linearStretchEnhancementFilter = new LinearStretchEnhancementFilter();
202
			linearStretchEnhancementFilter.addParam("raster", bufferFactory.getRasterBuf());
203
			linearStretchEnhancementFilter.addParam("stats", bufferFactory.getDataSource().getStatistics());
204
			linearStretchEnhancementFilter.addParam("renderBands",inputRasterLayers[l].getRenderBands());
205
			linearStretchEnhancementFilter.addParam("remove",new Boolean(false));
206
			linearStretchEnhancementFilter.addParam("stretchs", leParams);
207
			linearStretchEnhancementFilter.execute();
208
			
209
			inputBuffers[l] = (IBuffer)linearStretchEnhancementFilter.getResult("raster");*/
210
			
177 211
			inputBuffers[l] = bufferFactory.getRasterBuf();
178 212
		}
179 213

  
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/HistogramMatchProcess.java
54 54
import org.gvsig.raster.dataset.NotSupportedExtensionException;
55 55
import org.gvsig.raster.dataset.io.RasterDriverException;
56 56
import org.gvsig.raster.datastruct.Histogram;
57
import org.gvsig.raster.grid.Grid;
58 57
import org.gvsig.raster.grid.filter.RasterFilter;
59 58
import org.gvsig.raster.grid.filter.histogramMatching.HistogramMatchingByteFilter;
60 59
import org.gvsig.raster.util.RasterToolsUtil;
......
66 65
/** 
67 66
 * Clase que implementa el proceso de Histogram Matching para un conjuto de  imagenes
68 67
 * que se quieren hacer corresponder con un histogram de referencia. El proceso tomara como parametros 
69
 * un conjunto de capas y un histograma maestro y ejecutara de forma secuencial un filtro de histogramMatch para cada 
68
 * un conjunto de capas y un histograma maestro y ejecutara de forma secuencial un filtro de histogramMatch 
69
 * para cada una de ellas. El proceso se realiza sobre las bandas de visulaizaci?n.
70
 * 
71
 * @params
72
 * <LI>FLyrRasterSE[] "inputRasterLayers": Capas raster de entrada</LI>
73
 * <LI>Histogram "masterHistogram": Histograma con el que se hace la correspondencia</LI>
74
 * <LI>int "numbandas": PROVISIONAL.</LI>
75
 * <LI>String "outputPath": Ruta completa al fichero de salida del proceso</LI>
76
 * 
77
 * @result
78
 * <LI>outputRassterLayers[]: Capas raster resultantes</LI>
79
 *
70 80
 * par histograma source - histograma referencia.
71 81
 * 
72 82
 * @author aMu?oz (alejandro.mu?oz@uclm.es)
......
93 103
	 * */
94 104
	
95 105
	public void init() {
96
		inputRasterLayers =(FLyrRasterSE []) getParam("layers");
106
		inputRasterLayers =(FLyrRasterSE []) getParam("inputRasterLayers");
97 107
		outputRassterLayers = new FLyrRasterSE[inputRasterLayers.length];
98
		histogramMaster= (Histogram) getParam("histogramMaster");
99
		numbands = ((Integer)getParam("numbands")).intValue();
100
		path = (String) getStringParam("resultsPath");
108
		histogramMaster= (Histogram) getParam("masterHistogram");
109
		numbands = ((Integer)getParam("numbands")).intValue(); //******************************
110
		path = (String) getStringParam("outputPath");
101 111
	}
102 112

  
103 113
	
......
117 127
					IRasterDataSource dsetCopy = null; 
118 128
					dsetCopy = inputRasterLayers[i].getDataSource().newDataset();
119 129
					BufferFactory bufferFactory = new BufferFactory(dsetCopy);
130
					bufferFactory.setDrawableBands(inputRasterLayers[i].getRenderBands());
120 131
					if (!RasterBuffer.loadInMemory(dsetCopy))
121
						bufferFactory.setReadOnly(true);			
122
					Grid g= new Grid(bufferFactory);
123
					filtro.addParam("raster",g.getRasterBuf());
132
						bufferFactory.setReadOnly(true);	
133
					bufferFactory.setAreaOfInterest();
134
					filtro.addParam("raster",bufferFactory.getRasterBuf());
124 135
					filtro.addParam("histogramReference",histogramMaster);
125 136
					filtro.addParam("numbands",new Integer(numbands));
126 137
					filtro.addParam("filterName",new String("histogram"));
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/gui/MosaicDialog.java
80 80
import org.gvsig.gui.beans.defaultbuttonspanel.DefaultButtonsPanel;
81 81
import org.gvsig.raster.IProcessActions;
82 82
import org.gvsig.raster.RasterLibrary;
83
import org.gvsig.raster.buffer.BufferFactory;
84
import org.gvsig.raster.buffer.RasterBuffer;
83 85
import org.gvsig.raster.dataset.GeoRasterWriter;
86
import org.gvsig.raster.dataset.IRasterDataSource;
84 87
import org.gvsig.raster.datastruct.Histogram;
85 88
import org.gvsig.raster.hierarchy.IHistogramable;
86 89
import org.gvsig.raster.util.ExtendedFileFilter;
......
446 449
		try{
447 450
			FLyrRasterSE capas[]= new FLyrRasterSE[getPanelSouth().getLayers().getLayersCount()];
448 451
			hmMasterRaster= (FLyrRasterSE) getPanelSouth().getLayers().getLayer((String)getPanelSouth().getMasterImageCombo().getSelectedItem());
449
			Histogram histogramReference=hmMasterRaster.getDataSource().getHistogram();
452
			
453
			IRasterDataSource dsetCopy = null; 
454
			dsetCopy = hmMasterRaster.getDataSource().newDataset();
455
			BufferFactory bufferFactory = new BufferFactory(dsetCopy);
456
			bufferFactory.setDrawableBands(hmMasterRaster.getRenderBands());
457
			if (!RasterBuffer.loadInMemory(dsetCopy))
458
				bufferFactory.setReadOnly(true);	
459
			bufferFactory.setAreaOfInterest();
460
			Histogram histogramReference = bufferFactory.getRasterBuf().getHistogram();
461
				
462
			//Histogram histogramReference=hmMasterRaster.getDataSource().getHistogram();
450 463
			for(int i=0; i<getPanelSouth().getLayers().getLayersCount();i++)
451 464
				if(!hmMasterRaster.getName().equals(getPanelSouth().getLayers().getLayer(i).getName())){
452 465
					capas[i]= (FLyrRasterSE) getPanelSouth().getLayers().getLayer(i).cloneLayer();
......
458 471
			tempHMDir.mkdir();
459 472
			
460 473
			HistogramMatchProcess proceso = new HistogramMatchProcess();
461
			proceso.addParam("histogramMaster",histogramReference);
474
			proceso.addParam("masterHistogram",histogramReference);
462 475
			proceso.addParam("numbands",new Integer(3)); //*********************************
463
			proceso.addParam("layers",capas);
464
			proceso.addParam("resultsPath",tempHMDir.getAbsolutePath());
476
			proceso.addParam("inputRasterLayers",capas);
477
			proceso.addParam("outputPath",tempHMDir.getAbsolutePath());
465 478
			proceso.setActions(this);
466 479
			proceso.start();
467 480
	
......
513 526
			//Borrar las ficheros intermedios (el resultado del H.M.)
514 527
			File tempDir = new File(Utilities.createTempDirectory()+File.separator+"HMResults");
515 528
			File filesToDelete[] = tempDir.listFiles();
516
			for (int i = 0; i<filesToDelete.length; i++)
517
				filesToDelete[i].delete();
529
			if (filesToDelete!=null)
530
				for (int i = 0; i<filesToDelete.length; i++)
531
					filesToDelete[i].delete();
518 532
			tempDir.delete();
519 533
			break;
520 534
		}
......
524 538
		FeatherProcessBuff featherProcess= new FeatherProcessBuff();
525 539
		
526 540
		featherProcess.addParam("inputRasterLayers",inputRasterLayers);
527
		featherProcess.addParam("filename", getFileSelected());
541
		featherProcess.addParam("outputPath", getFileSelected());
528 542
		featherProcess.setActions(this);
529 543
		featherProcess.start();
530 544
	}
......
538 552
		} catch (Exception e1) {
539 553
			e1.printStackTrace();
540 554
		}
541
		proceso.addParam("numbands",new Integer(3)); //*************************************
542
		proceso.addParam("codOp",new Integer(getPanelSouth().getComboOverlapFunction().getSelectedIndex()));
543
		proceso.addParam("filename",getFileSelected());
555
		proceso.addParam("methodCode",new Integer(getPanelSouth().getComboOverlapFunction().getSelectedIndex()));
556
		proceso.addParam("outputPath",getFileSelected());
544 557
		proceso.setActions(this);
545 558
		proceso.start();
546 559
	}
......
609 622
				inputRasterLayers[i]=(FLyrRasterSE) getPanelSouth().getLayers().getLayer(i);
610 623
			this.end(inputRasterLayers);
611 624
		}
612
		/*
613
		if(getPanelSouth().getCheckFeathering().isSelected()){
614
			
615
			// Caso de degradado de borde seleccionado
616
			if(getPanelSouth().getRButtomEdge().isSelected()){
617
				
618
				FeatherProcessBuff featherProcess= new FeatherProcessBuff();
619
				FLyrRasterSE layers[]= new FLyrRasterSE[getPanelSouth().getLayers().getLayersCount()];
620
				for(int i=0; i<layers.length;i++)
621
					layers[i]=(FLyrRasterSE) getPanelSouth().getLayers().getLayer(i);
622
				
623
				featherProcess.addParam("inputRasterLayers",layers);
624
				featherProcess.addParam("filename", getFileSelected());
625
				featherProcess.addParam("view", view);
626
				featherProcess.start();
627
			}
628
			
629
			// Caso sin degradado
630
		}
631
		
632
		else {
633
			
634
			MosaicProcess proceso= new MosaicProcess ();
635
			try {
636
				proceso.addParam("layers",getPanelSouth().getLayers().cloneLayer());
637
			} catch (Exception e1) {
638
				e1.printStackTrace();
639
			}
640
			proceso.addParam("numbands",new Integer(3));
641
			proceso.addParam("codOp",new Integer(getPanelSouth().getComboOverlapFunction().getSelectedIndex()));
642
			proceso.addParam("filename",getFileSelected());
643
			proceso.addParam("vista",view);
644
			proceso.start();
645
		}
646
		
647
		*/
648 625
	}
649 626
	
650 627
}
trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/principalcomponents/PCImageProcess.java
66 66
 *Proceso de contrucci?n de la imagen resultante del analisis de componentes principales a partir de los 
67 67
 *componentes seleccionados.
68 68
 *
69
 *@par?metros
69
 *@params
70 70
 * <LI>FLyrRasterSE "inputRasterLayer": Capa raster de entrada</LI>
71 71
 * <LI>PCStatistics "statistics": Estad?sticas del An?lisis de C.P. (ej.: las generadas por PCStatisticsProcess)</LI>
72 72
 * <LI>boolean[] "selectedBands": Bandas del raster original que se tienen en cuenta para la transformaci?n</LI>

Also available in: Unified diff