Revision 11396 trunk/libraries/libRaster/src/org/gvsig/raster/buffer/BufferFactory.java

View differences:

BufferFactory.java
21 21

  
22 22
import java.awt.geom.Point2D;
23 23

  
24
import org.gvsig.raster.dataset.FileFoundInListException;
24
import org.gvsig.raster.dataset.FileNotFoundInListException;
25 25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.dataset.InvalidSetViewException;
26 27
import org.gvsig.raster.dataset.NotSupportedExtensionException;
27 28
import org.gvsig.raster.dataset.RasterDataset;
28 29
import org.gvsig.raster.dataset.RasterDriverException;
......
116 117
			mDataset.addDataset(grf);
117 118
			width = grf.getWidth();
118 119
			height = grf.getHeight();
119
		}catch(FileFoundInListException e) {
120
		}catch(FileNotFoundInListException e) {
120 121
			//El fichero est? en la lista por lo que no lo a?adimos
121 122
		}
122 123
	}
......
132 133
			mDataset.addDataset(filename);
133 134
			width = (int)mDataset.getWidth()[0];
134 135
			height = (int)mDataset.getHeight()[0];
135
		}catch(FileFoundInListException e) {
136
		}catch(FileNotFoundInListException e) {
136 137
			//El fichero est? en la lista por lo que no lo a?adimos
137 138
		}
138 139
	}
......
258 259
	 * @param adjustToExtent Flag que dice si el extent solicitado debe ajustarse al extent del raster o no.
259 260
	 * @throws ArrayIndexOutOfBoundsException
260 261
	 */
261
	public void setAreaOfInterest(double x, double y, double w, double h, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException{
262
	public void setAreaOfInterest(double x, double y, double w, double h, boolean adjustToExtent) 
263
		throws ArrayIndexOutOfBoundsException {
262 264
		dataExtent = new Extent(x, y, x + w, y - h);
263 265
		if(adjustToExtent) {
264 266
			Extent adjustedDataExtent = RasterUtilities.calculateAdjustedView(dataExtent, mDataset.getExtent());
......
269 271
				newW = (adjustedDataExtent.width() * w) / dataExtent.width();  
270 272
				newH = (adjustedDataExtent.height() * h) / dataExtent.height();
271 273
			}
272
			rasterBuf = mDataset.getWindowRaster(adjustedDataExtent.getMin().getX(), adjustedDataExtent.getMax().getY(), newW, newH, adjustToExtent);
273
		}else
274
			rasterBuf = mDataset.getWindowRaster(dataExtent.getMin().getX(), dataExtent.getMax().getY(), w, h, adjustToExtent);
274
			try {
275
				rasterBuf = mDataset.getWindowRaster(adjustedDataExtent.getMin().getX(), adjustedDataExtent.getMax().getY(), newW, newH, adjustToExtent);
276
			} catch (InvalidSetViewException e) {
277
				//Esta excepci?n no debe darse ya que se hace un calculateAdjustedView antes de la llamada.
278
			}
279
		} else {
280
			try {
281
				rasterBuf = mDataset.getWindowRaster(dataExtent.getMin().getX(), dataExtent.getMax().getY(), w, h, adjustToExtent);
282
			} catch (InvalidSetViewException e) {
283
				//Esta excepci?n no debe darse ya que se hace un calculateAdjustedView antes de la llamada.
284
			}
285
		}
275 286
	}
276 287
		
277 288
	/**
......
288 299
	 * un array de dos elementos que representan el desplazamiento en pixels de X e Y de la esquina superior izquierda. 
289 300
	 * @throws ArrayIndexOutOfBoundsException
290 301
	 */
291
	public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, boolean adjustToExtent) throws ArrayIndexOutOfBoundsException{
302
	public int[] setAreaOfInterest(double minX, double minY, double maxX, double maxY, int bufWidth, int bufHeight, boolean adjustToExtent) 
303
		throws ArrayIndexOutOfBoundsException {
292 304
		//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada
293 305
		dataExtent = new Extent(minX, minY, maxX, maxY);
294 306
		Extent adjustedDataExtent = new Extent(dataExtent);
......
306 318
			nHeight = ((adjustedDataExtent.height() * mDataset.getDataset(0).getHeight()) / mDataset.getDataset(0).getExtent().height());
307 319

  
308 320
			if(bufWidth > Math.ceil(nWidth) && bufHeight > Math.ceil(nHeight)) {				
309
				rasterBuf = mDataset.getWindowRaster(minX, maxY, Math.abs(maxX - minX), Math.abs(maxY - minY), adjustToExtent);
321
				try {
322
					rasterBuf = mDataset.getWindowRaster(minX, maxY, Math.abs(maxX - minX), Math.abs(maxY - minY), adjustToExtent);
323
				} catch (InvalidSetViewException e) {
324
					//Esta excepci?n no debe darse ya que se hace un calculateAdjustedView antes de la llamada.
325
				}
310 326
				int[] step = mDataset.calcSteps(minX, maxY, maxX, minY, nWidth, nHeight, bufWidth, bufHeight);
311 327
				return step;
312 328
			}
313 329
		}
314 330
		
315
		rasterBuf = mDataset.getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight, adjustToExtent);
331
		try {
332
			rasterBuf = mDataset.getWindowRaster(minX, minY, maxX, maxY, bufWidth, bufHeight, adjustToExtent);
333
		} catch (InvalidSetViewException e) {
334
			//Esta excepci?n no debe darse ya que se hace un calculateAdjustedView antes de la llamada.
335
		}
316 336
		return null;
317 337
	}
318 338
	
......
325 345
	 * @param h Alto del ?rea
326 346
	 * @throws ArrayIndexOutOfBoundsException
327 347
	 */
328
	public void setAreaOfInterest(int x, int y, int w, int h) throws ArrayIndexOutOfBoundsException{
329
		if((x + w) > getWidth() || (y + h) > getHeight())
330
			throw new ArrayIndexOutOfBoundsException("Out of Image");
348
	public void setAreaOfInterest(int x, int y, int w, int h){
349
		x = (x < 0) ? 0 : x;
350
		y = (y < 0) ? 0 : y;
351
		w = (w > getWidth()) ? getWidth() : w;
352
		h = (w > getHeight()) ? getHeight() : h;
353
		
331 354
		dataExtent = new Extent(mDataset.rasterToWorld(new Point2D.Double(x, y)), 
332 355
								mDataset.rasterToWorld(new Point2D.Double(x + w, y + h)));
333
		rasterBuf = mDataset.getWindowRaster(x, y, w, h);
356
		try {
357
			rasterBuf = mDataset.getWindowRaster(x, y, w, h);
358
		} catch (InvalidSetViewException e) {
359
			//Esta excepci?n no debe darse ya que se hace un calculateAdjustedView antes de la llamada.
360
		}
334 361
	}
335 362
	
336 363
	/**
337 364
	 * Asigna el ?rea de inter?s a toda la extensi?n del raster.
338 365
	 */
339
	public void setAreaOfInterest() {		
366
	public void setAreaOfInterest() throws InvalidSetViewException {		
340 367
		dataExtent = mDataset.getExtent();
341 368
		rasterBuf = mDataset.getWindowRaster(0, 0, (int)mDataset.getWidth()[0], (int)mDataset.getHeight()[0]);
342 369
	}
......
353 380
	 * @param bufHeight Alto del buffer
354 381
	 * @throws ArrayIndexOutOfBoundsException
355 382
	 */
356
	public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth, int bufHeight) throws ArrayIndexOutOfBoundsException{
383
	public void setAreaOfInterest(int x, int y, int w, int h, int bufWidth, int bufHeight) 
384
		throws InvalidSetViewException {
357 385
		//TODO: VALIDACI?N: Comprobaci?n de exceso de memoria reservada
358
		if(x < 0 || y < 0 || (x + w) > getWidth() || (y + h) > getHeight())
359
			throw new ArrayIndexOutOfBoundsException("Out of Image");
386
		x = (x < 0) ? 0 : x;
387
		y = (y < 0) ? 0 : y;
388
		w = (w > getWidth()) ? getWidth() : w;
389
		h = (w > getHeight()) ? getHeight() : h;
390
		
360 391
		dataExtent = new Extent(mDataset.rasterToWorld(new Point2D.Double(x, y)), 
361 392
								mDataset.rasterToWorld(new Point2D.Double(x + w, y + h)));
362 393

  

Also available in: Unified diff