Revision 11196

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/dataset/IStatistics.java
18 18
 */
19 19
package org.gvsig.raster.dataset;
20 20

  
21
import org.gvsig.raster.util.ICancellable;
21 22

  
22 23

  
24

  
23 25
/**
24 26
 * Interfaz a implementar por las clases que ofrecen estadisticas raster.
25 27
 *  
26 28
 * @author Nacho Brodin (nachobrodin@gmail.com)
27 29
 */
28
public interface IStatistics{
30
public interface IStatistics extends ICancellable {
29 31
	
30 32
	/**
31 33
	 * Obtiene el valor m?ximo
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetStatistics.java
53 53
	protected RasterDataset		grf = null;
54 54
	protected boolean				calculated = false;
55 55
	protected Hashtable			tailTrim = new Hashtable();
56
	private boolean					canceled = false;
56 57
	
57 58
	/**
58 59
	 * Constructor. Asigna el fichero asociado.
......
205 206

  
206 207
		byte[] b = null;short[] s = null;int[] i = null;float[] f = null;double[] d = null;
207 208
	
208
		for(int iBand = 0; iBand < grf.getBandCount(); iBand ++){
209
		for (int iBand = 0; iBand < grf.getBandCount(); iBand ++){
209 210
			iValues = 0;
210 211
			max[iBand] = Double.MIN_VALUE; 
211 212
			min[iBand] = Double.MAX_VALUE;
212 213
			secondMax[iBand] = Double.MIN_VALUE; 
213 214
			secondMin[iBand] = Double.MAX_VALUE;
214 215
			mean[iBand] = variance[iBand] = 0;
215
			for(int line = 0; line < grf.getHeight(); line ++){
216
			for (int line = 0; line < grf.getHeight(); line ++) {
216 217
				Object buf = null;
217 218
				try {
218 219
					buf = grf.readCompleteLine(line, iBand);
......
255 256
					mean[iBand] += z;
256 257
					variance[iBand] += z * z;
257 258
					iValues++;
258
				}		
259
				}
260
				
261
				if (isCanceled())
262
					return;
259 263
			}
260 264
			if( iValues > 0 ){
261 265
				mean[iBand] /= (double) iValues;
......
316 320
		String s = new Double(percent).toString();
317 321
		return tailTrim.get(s);
318 322
	}
319
	
320
}
323

  
324
	/*
325
	 * (non-Javadoc)
326
	 * @see org.gvsig.raster.util.ICancellable#isCanceled()
327
	 */
328
	public boolean isCanceled() {
329
		return canceled;
330
	}
331

  
332
	/*
333
	 * (non-Javadoc)
334
	 * @see org.gvsig.raster.util.ICancellable#setCanceled(boolean)
335
	 */
336
	public void setCanceled(boolean value) {
337
		canceled = value;
338
	}
339
}
trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetHistogram.java
82 82

  
83 83
				dataset.getStatistics().calcFullStatistics();
84 84

  
85
				if (isCanceled()) 
86
					return null;
87

  
85 88
				if (dataset.getDataType() == IBuffer.TYPE_BYTE)
86 89
					histogram = new Histogram(dataset.getBandCount(), 255, dataset.getStatistics().getMinimun(), dataset.getStatistics().getMaximun());
87 90
				else
......
150 153
	
151 154
	public void setCanceled(boolean value) {
152 155
		canceled = value;
156
		if (dataset != null)
157
			dataset.getStatistics().setCanceled(value);
153 158
	}
154 159
	
155 160
	public boolean isCanceled() {
trunk/libraries/libRaster/src/org/gvsig/raster/buffer/RasterBuffer.java
385 385
		switch (getDataType()) {
386 386
			case IBuffer.TYPE_BYTE:
387 387
				for (int i = 0; i < getBandCount(); i++)
388
					for (int r = 0; r < getHeight(); r++)
388
					for (int r = 0; r < getHeight(); r++) {
389 389
						for (int c = 0; c < getWidth(); c++) {
390 390
							value = (double) (getElemByte(r, c, i) & 0xff);
391 391
							if (value > max) max = value;
392 392
							if (value < min) min = value;
393 393
						}
394
						if (isCanceled())
395
							return null;
396
					}
394 397
				break;
395 398
			case IBuffer.TYPE_SHORT:
396 399
				for (int i = 0; i < getBandCount(); i++)
397
					for (int r = 0; r < getHeight(); r++)
400
					for (int r = 0; r < getHeight(); r++) {
398 401
						for (int c = 0; c < getWidth(); c++) {
399 402
							value = (double) (getElemShort(r, c, i) & 0xffff);
400 403
							if (value > max) max = value;
401 404
							if (value < min) min = value;
402 405
						}
406
						if (isCanceled())
407
							return null;
408
					}
403 409
				break;
404 410
			case IBuffer.TYPE_INT:
405 411
				for (int i = 0; i < getBandCount(); i++)
406
					for (int r = 0; r < getHeight(); r++)
412
					for (int r = 0; r < getHeight(); r++) {
407 413
						for (int c = 0; c < getWidth(); c++) {
408 414
							value = (double) (getElemInt(r, c, i) & 0xffffffff);
409 415
							if (value > max) max = value;
410 416
							if (value < min) min = value;
411 417
						}
418
						if (isCanceled())
419
							return null;
420
					}
412 421
				break;
413 422
			case IBuffer.TYPE_FLOAT:
414 423
				for (int i = 0; i < getBandCount(); i++)
415
					for (int r = 0; r < getHeight(); r++)
424
					for (int r = 0; r < getHeight(); r++) {
416 425
						for (int c = 0; c < getWidth(); c++) {
417 426
							value =  (double) getElemFloat(r, c, i);
418 427
							if (value > max) max = value;
419 428
							if (value < min) min = value;
420 429
						}
430
						if (isCanceled())
431
							return null;
432
					}
421 433
				break;
422 434
			case IBuffer.TYPE_DOUBLE:
423 435
				for (int i = 0; i < getBandCount(); i++)
424
					for (int r = 0; r < getHeight(); r++)
436
					for (int r = 0; r < getHeight(); r++) {
425 437
						for (int c = 0; c < getWidth(); c++) {
426 438
							value = getElemDouble(r, c, i);
427 439
							if (value > max) max = value;
428 440
							if (value < min) min = value;
429 441
						}
442
						if (isCanceled())
443
							return null;
444
					}
430 445
				break;
431 446
		}
432 447
		double[] values = new double[2];
......
444 459
		Histogram hist = null;
445 460
		double[] limits = getLimits();
446 461

  
462
		if (limits == null)
463
			return null;
464

  
447 465
		if (getDataType() == IBuffer.TYPE_BYTE)
448 466
			hist = new Histogram(getBandCount(), 255, limits[0], limits[1]);
449 467
		else
......
474 492
					break;
475 493
				}
476 494
				
477
				if (isCanceled()) 
495
				if (isCanceled())
478 496
					return null;
497

  
479 498
				percent = ((iBand*getHeight() + row) * 100) /(getHeight() * getBandCount());
480 499
			}
481 500
		}

Also available in: Unified diff