Revision 20733

View differences:

trunk/extensions/extRemoteSensing/src/org/gvsig/remotesensing/mosaic/process/MosaicProcess.java
90 90
	// Buffers con las imagenes
91 91
	RasterBuffer buffers[]= null;
92 92
	
93
	// codigo operacion maypr, menor, valor de la situada encima.
94
	int codOp= 0;
93
	// Codigo operacion mayor, menor,media valor de la situada encima.
94
	int codOp= 0; 
95 95
	
96 96
	// indicador de proceso
97
	int proceso=0; // Carga de datos
98
	
99 97
	 int percent=0;
100

  
98
	 
99
	// writer para escritura en fichero 
100
	WriterBufferServer writerBufferServer =null;
101
	 
102
	 
101 103
	/** Inicializaci?n de los par?metros
102 104
	 *  layers -  FLayers con los layers seleccionados para el mosaico.
103 105
	 * 
......
105 107
	 * */
106 108
	
107 109
	public void init() {
108
		
109 110
		layers= (FLayers)getParam("layers");
110 111
		codOp= getIntParam("codOp");
111 112
		
112 113
		// Calculo del extend resultante
113 114
		fullExtend= calculateExtend(layers);
114
		
115 115
		try {
116 116
				mosaicGrid= new Grid(fullExtend,fullExtend,IBuffer.TYPE_BYTE,new int[]{0,1,2});
117 117
		} catch (RasterBufferInvalidException e) {
......
120 120
	}
121 121

  
122 122
	
123
	
124 123
	/**
125 124
	 *  Proceso
126 125
	 * */
......
136 135
			double maxX=  fullExtend.getMax().getX();
137 136
			double maxY=  fullExtend.getMax().getY();
138 137
			// Se cargan todos los raster en los grid correspondientes
138
			percent=0;
139 139
			for(int i=0; i< layers.getLayersCount();i++)
140 140
			{
141 141
				dsetCopy = ((FLyrRasterSE)layers.getLayer(i)).getDataSource().newDataset();
142 142
				BufferFactory bufferFactory = new BufferFactory(dsetCopy);
143 143
				bufferFactory.setAdjustToExtent(false);
144
				if (!RasterBuffer.loadInMemory(dsetCopy))
145
					bufferFactory.setReadOnly(true);
144 146
				bufferFactory.setDrawableBands(((FLyrRasterSE)layers.getLayer(i)).getRenderBands());
145 147
				bufferFactory.setAreaOfInterest(minX,minY,maxX,maxY,fullExtend.getNX(),fullExtend.getNY());
146 148
				buffers[i]= (RasterBuffer) bufferFactory.getRasterBuf();
149
				percent=(int)i*100/layers.getLayersCount();
147 150
			}
148 151
		}catch (RasterDriverException e) {
149
			// TODO Auto-generated catch block
150
			e.printStackTrace();
152
			RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_writer"), this, e);	
151 153
		} catch (InvalidSetViewException e) {
152
			// TODO Auto-generated catch block
153
			e.printStackTrace();
154
			RasterToolsUtil.messageBoxError(PluginServices.getText(this, "error_extension"), this, e);	
154 155
		} catch (InterruptedException e) {
155
			// TODO Auto-generated catch block
156
			e.printStackTrace();
156
			Thread.currentThread().interrupt();
157 157
		}
158 158
		
159
	    
160
// 		Construccion del mosaico: Operaci?n M?ximo
161
		if(codOp==0){
162
			for(int col=0; col<mosaicGrid.getLayerNY(); col++){
163
				for(int row=0; row<mosaicGrid.getLayerNX();row++){
164
					setValueMax(row,col);
165
					percent= col*100/mosaicGrid.getLayerNY();
166
				}
167
			}
168
		}
159 169
		
160
		percent= 22;
170
//		 Construccion del mosaico: Operaci?n M?nimo
171
		if(codOp==1){
172
			for(int col=0; col<mosaicGrid.getLayerNY(); col++){
173
				for(int row=0; row<mosaicGrid.getLayerNX();row++){
174
					setValueMin(row,col);
175
					percent= col*100/mosaicGrid.getLayerNY();
176
				}
177
			}
178
		}
161 179
		
162
		// CONSTRUCCION DE LA IMAGEN
180
//		 Construccion del mosaico: Operaci?n Media
181
		if(codOp==2){
182
			for(int col=0; col<mosaicGrid.getLayerNY(); col++){
183
				for(int row=0; row<mosaicGrid.getLayerNX();row++){
184
					setValueMax(row,col);
185
					percent= col*100/mosaicGrid.getLayerNY();
186
				}
187
			}
188
		}
163 189
		
164
		for(int row=0; row<mosaicGrid.getLayerNY(); row++){
165
			for(int col=0; col<mosaicGrid.getLayerNX();col++){
166
				setValue(row,col,0);
190
//		 Construccion del mosaico: Operaci?n Superior
191
		if(codOp==3){
192
			for(int col=0; col<mosaicGrid.getLayerNY(); col++){
193
				for(int row=0; row<mosaicGrid.getLayerNX();row++){
194
					setValueMax(row,col);
195
					percent= col*100/mosaicGrid.getLayerNY();
196
				}
167 197
			}
168 198
		}
169 199
		
200
		// Escritura en fichero
201
		writeToFile();
170 202
	}
171 203

  
172 204
	
173

  
174 205
	/**
206
	 *  M?todo que establece para la coordenada x,y el valor m?ximo 
207
	 *  de todos los valores para ese p?xel en cualquiera de las imagenes.
208
	 *  Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta 
209
	 *  @param cordenada x 
210
	 *  @param coordenada y  
211
	 * */
212
	public void setValueMax(int x, int y){
213
		byte result[]= new byte[3];
214
		result[0]=(byte) -128;
215
		result[1]=(byte) -128;
216
		result[2]=(byte) -128;
217
		for(int band=0; band<3;band++){
218
			for(int buf=0;buf<buffers.length;buf++){
219
				byte data = (byte)(buffers[buf].getElemByte(y,x,band));
220
//				 TO DO: TENER EN CUENTA NO DATA REAL DEL BUFER
221
				if(data==97)
222
					data=-128;
223
				result[band]=(byte) Math.max(result[band],data);		
224
			}
225
			try {
226
				mosaicGrid.setBandToOperate(band);
227
				mosaicGrid.setCellValue(x,y,(byte)result[band]);
228
			} catch (OutOfGridException e) {
229
				// TODO Auto-generated catch block
230
				e.printStackTrace();
231
			}
232
		}
233
	}
234
	
235
	
236
	/**
237
	 *  M?todo que establece para la coordenada x,y el valor m?ximo 
238
	 *  de todos los valores para ese p?xel en cualquiera de las imagenes.
239
	 *  Si el valor en cualquiera de las imagenes es noData no es tenido en cuenta 
240
	 *  @param cordenada x 
241
	 *  @param coordenada y  
242
	 * */
243
	public void setValueMin(int x, int y){
244
		byte result[]= new byte[3];
245
		result[0]=(byte) 127;
246
		result[1]=(byte) 127;
247
		result[2]=(byte) 127;
248
		for(int band=0; band<3;band++){
249
			for(int buf=0;buf<buffers.length;buf++){
250
				byte data = (byte)(buffers[buf].getElemByte(y,x,band));
251
				// TO DO: TENER EN CUENTA NO DATA
252
				if(data==97)
253
					data=127;
254
				result[band]=(byte) Math.min(result[band],data);	
255
				
256
					
257
			}
258
			try {
259
				mosaicGrid.setBandToOperate(band);
260
				mosaicGrid.setCellValue(x,y,(byte)result[band]);
261
			} catch (OutOfGridException e) {
262
				// TODO Auto-generated catch block
263
				e.printStackTrace();
264
			}
265
		}
266
	}
267
	
268
	
269
	
270
	/**
175 271
	 * M?todo que calcula el extend resultante para la operaci?n de mosaico
176 272
	 * 
177 273
	 * @param layers que intervienen en la operacion.
......
206 302
		return result;
207 303
	}
208 304
	
209
	
305
	/**
306
	 *  M?todo que escribe en fichero el grid resultante de la operaci?n de mosaico.
307
	 *  
308
	 * */
210 309
	public void writeToFile(){
211

  
212 310
		try{
213 311
			
214
			String filename= "mosaico.img";
312
			String filename= "mosaico"+codOp+".tif";
215 313
			GeoRasterWriter grw = null;
216
			WriterBufferServer writerBufferServer = new WriterBufferServer(mosaicGrid.getRasterBuf());
314
			writerBufferServer = new WriterBufferServer(mosaicGrid.getRasterBuf());
217 315
			AffineTransform aTransform = new AffineTransform(fullExtend.getCellSize(),0.0,0.0,-fullExtend.getCellSize(),fullExtend.getMin().getX(),fullExtend.getMax().getY());
218 316
			grw = GeoRasterWriter.getWriter(writerBufferServer, filename, mosaicGrid.getBandCount(),aTransform, mosaicGrid.getRasterBuf().getWidth(), mosaicGrid.getRasterBuf().getHeight(), mosaicGrid.getRasterBuf().getDataType(), GeoRasterWriter.getWriter(filename).getParams(), null);
219 317
			grw.dataWrite();
......
250 348
	}
251 349
	
252 350
	
253
	
254
	public byte[] setValue(int x, int y, int codop){
255
		byte result[]= new byte[3];
256
		result[0]=(byte) -128;
257
		for(int band=0; band<3;band++){
258
			for(int buf=0;buf<buffers.length;buf++){
259
				result[band]=(byte) Math.max(result[band],(byte)(buffers[buf].getElemByte(x,y,band)&0xff));
260
				
261
			}
262
			try {
263
				mosaicGrid.setBandToOperate(band);
264
				mosaicGrid.setCellValue(y,x,(byte)result[band]);
265
			} catch (OutOfGridException e) {
266
				// TODO Auto-generated catch block
267
				e.printStackTrace();
268
			}
269
		}
270
		
271
		
272
		return result;
273
		
274
	}
275
	
276
	
351
	/**
352
	 * @return descripcion
353
	 * */
277 354
	public String getTitle() {
278 355
		return PluginServices.getText(this,"mosaic_process");
279 356
	}
280 357

  
281 358
	
359
	/**
360
	 * @return  indicador de progreso
361
	 * */
282 362
	public int getPercent() {
283
		// TODO Auto-generated method stub
284
		return percent;
363
		if(writerBufferServer==null)
364
			return percent;
365
		else 
366
			return writerBufferServer.getPercent();
285 367
	}
286 368

  
287 369

  
288
	
289
	
290
	
291
	
292
	
293 370
	/*
294 371
	// Identificaci?n de zonas de solapamiento
295 372
	public boolean getSolapes(FLyrRasterSE raster1, FLyrRasterSE raster2){

Also available in: Unified diff