Revision 11072

View differences:

trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetHistogram.java
77 77
	 */
78 78
	public Histogram getHistogram() throws FileNotOpenException, RasterDriverException {
79 79
		try {
80
			if(dataset != null){
81
				if(classes == null){
82
					if(dataset.getDataType() == IBuffer.TYPE_BYTE){
80
			if (dataset != null) {
81
				if (classes == null) {
82
					if (dataset.getDataType() == IBuffer.TYPE_BYTE) {
83 83
						histogram = new Histogram(dataset.getBandCount(), 256);
84 84
						return getHistogramByValue();
85
					}else{
85
					} else {
86 86
						DatasetStatistics stats = dataset.getStatistics();
87 87
						stats.calcFullStatistics();
88 88
						classes = DataClassList.getClasses(stats.getMinimun(), stats.getMaximun(), RasterLibrary.defaultNumberOfClasses);
......
107 107
	 */
108 108
	private Histogram getHistogramByValue() throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
109 109
		percent = 0;
110
		if(dataset.getDataType() != IBuffer.TYPE_BYTE)
111
			return null;
110
		if (dataset.getDataType() != IBuffer.TYPE_BYTE) return null;
112 111
		
113 112
		for (int band = 0; band < dataset.getBandCount(); band++) {
114 113
			for (int line = 0; line < dataset.getHeight(); line++) {
......
129 128
	 * @return Histograma correspondiente a la lista de clases
130 129
	 */
131 130
	private Histogram getHistogramByClass() throws InvalidSetViewException, FileNotOpenException, RasterDriverException {
132
		if(classes == null)
133
			return null;
131
		percent = 0;
132
		if (classes == null) return null;
134 133
		for (int band = 0; band < dataset.getBandCount(); band++) {
135 134
			for (int line = 0; line < dataset.getHeight(); line++) {
136 135
				Object obj = dataset.readCompleteLine(line, band);
137
				switch(dataset.getDataType()){
138
				case IBuffer.TYPE_BYTE:		byte[] bLine = (byte[])obj;
139
											for (int k = 0; k < bLine.length; k++) {
140
												int pixelValue = classes.getClassPosition((double)bLine[k]);
141
												if(pixelValue >= 0)
142
													histogram.incrementPxValue(band, pixelValue);
143
												
144
											}
145
											break;
146
				case IBuffer.TYPE_SHORT:	short[] sLine = (short[])obj;
147
											for (int k = 0; k < sLine.length; k++) {
148
												int pixelValue = classes.getClassPosition((double)sLine[k]);
149
												if(pixelValue >= 0)
150
													histogram.incrementPxValue(band, pixelValue);
151
											}
152
											break;
153
				case IBuffer.TYPE_INT:		int[] iLine = (int[])obj;
154
											for (int k = 0; k < iLine.length; k++) {
155
												int pixelValue = classes.getClassPosition((double)iLine[k]);
156
												if(pixelValue >= 0)
157
													histogram.incrementPxValue(band, pixelValue);
158
											}
159
											break;
160
				case IBuffer.TYPE_FLOAT:	float[] fLine = (float[])obj;
161
											for (int k = 0; k < fLine.length; k++) {
162
												int pixelValue = classes.getClassPosition((double)fLine[k]);
163
												if(pixelValue >= 0)
164
													histogram.incrementPxValue(band, pixelValue);
165
											}
166
											break;
167
				case IBuffer.TYPE_DOUBLE:	double[] dLine = (double[])obj;
168
											for (int k = 0; k < dLine.length; k++) {
169
												int pixelValue = classes.getClassPosition((double)dLine[k]);
170
												if(pixelValue >= 0)
171
													histogram.incrementPxValue(band, pixelValue);
172
											}
173
											break;
136
				switch(dataset.getDataType()) {
137
					case IBuffer.TYPE_BYTE:
138
						byte[] bLine = (byte[])obj;
139
						for (int k = 0; k < bLine.length; k++) {
140
							int pixelValue = classes.getClassPosition((double)bLine[k]);
141
							if (pixelValue >= 0) histogram.incrementPxValue(band, pixelValue);
142
						}
143
						break;
144
					case IBuffer.TYPE_SHORT:
145
						short[] sLine = (short[])obj;
146
						for (int k = 0; k < sLine.length; k++) {
147
							int pixelValue = classes.getClassPosition((double)sLine[k]);
148
							if (pixelValue >= 0) histogram.incrementPxValue(band, pixelValue);
149
						}
150
						break;
151
					case IBuffer.TYPE_INT:
152
						int[] iLine = (int[])obj;
153
						for (int k = 0; k < iLine.length; k++) {
154
							int pixelValue = classes.getClassPosition((double)iLine[k]);
155
							if (pixelValue >= 0) histogram.incrementPxValue(band, pixelValue);
156
						}
157
						break;
158
					case IBuffer.TYPE_FLOAT:
159
						float[] fLine = (float[])obj;
160
						for (int k = 0; k < fLine.length; k++) {
161
							int pixelValue = classes.getClassPosition((double)fLine[k]);
162
							if (pixelValue >= 0) histogram.incrementPxValue(band, pixelValue);
163
						}
164
						break;
165
					case IBuffer.TYPE_DOUBLE:
166
						double[] dLine = (double[])obj;
167
						for (int k = 0; k < dLine.length; k++) {
168
							int pixelValue = classes.getClassPosition((double)dLine[k]);
169
							if (pixelValue >= 0) histogram.incrementPxValue(band, pixelValue);
170
						}
171
						break;
174 172
				}
175
				
173
				if (isCanceled()) return null;
174
				percent = ((band * dataset.getHeight() + line) * 100) / (dataset.getBandCount() * dataset.getHeight());
176 175
			}
177
		} 
176
		}
177
		percent = 100;
178 178
		return histogram;
179 179
	}
180 180

  
trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/cache/PageBuffer.java
426 426
				for (int row = 0; row < getWidth(); row++) 
427 427
					hist.incrementPxValue(iBand, getElemByte(row, col, iBand));
428 428
				if (isCanceled()) return null;
429
				percent = ((iBand * getHeight() + col) * 100) / (getBandCount() * getHeight());
429 430
			}
430 431
		percent = 100;
431 432
		return hist;
......
436 437
	 * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
437 438
 	 */
438 439
	public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException {
440
		percent = 0;
439 441
		Histogram hist = new Histogram(getBandCount(), classes.length());
440 442
		for (int iBand = 0; iBand < getBandCount(); iBand++) { 
441 443
			for (int col = 0; col < getHeight(); col++) {
442 444
				for (int row = 0; row < getWidth(); row++) {
443 445
					int pixelValue = -1;
444
					switch(this.getDataType()){
445
					case IBuffer.TYPE_BYTE: pixelValue = classes.getClassPosition((double)getElemByte(row, col, iBand)); break;
446
					case IBuffer.TYPE_SHORT: pixelValue = classes.getClassPosition((double)getElemShort(row, col, iBand)); break;
447
					case IBuffer.TYPE_INT: pixelValue = classes.getClassPosition((double)getElemInt(row, col, iBand)); break;
448
					case IBuffer.TYPE_FLOAT: pixelValue = classes.getClassPosition((double)getElemFloat(row, col, iBand)); break;
449
					case IBuffer.TYPE_DOUBLE: pixelValue = classes.getClassPosition((double)getElemDouble(row, col, iBand)); break;
446
					switch (this.getDataType()) {
447
						case IBuffer.TYPE_BYTE:
448
							pixelValue = classes.getClassPosition((double)getElemByte(row, col, iBand));
449
							break;
450
						case IBuffer.TYPE_SHORT:
451
							pixelValue = classes.getClassPosition((double)getElemShort(row, col, iBand));
452
							break;
453
						case IBuffer.TYPE_INT:
454
							pixelValue = classes.getClassPosition((double)getElemInt(row, col, iBand));
455
							break;
456
						case IBuffer.TYPE_FLOAT:
457
							pixelValue = classes.getClassPosition((double)getElemFloat(row, col, iBand));
458
							break;
459
						case IBuffer.TYPE_DOUBLE:
460
							pixelValue = classes.getClassPosition((double)getElemDouble(row, col, iBand));
461
							break;
450 462
					}		 
451
					if(pixelValue >= 0)
452
						hist.incrementPxValue(iBand, pixelValue);
453
				}		
463
					if (pixelValue >= 0) hist.incrementPxValue(iBand, pixelValue);
464
				}	
465
				if (isCanceled()) return null;
466
				percent = ((iBand * getHeight() + col) * 100) / (getBandCount() * getHeight());
454 467
			}
455 468
		}
469
		percent = 100;
456 470
		return hist;
457 471
	}
458 472

  
trunk/libraries/libRaster/src/org/gvsig/raster/dataaccess/buffer/RasterBuffer.java
398 398
	 * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
399 399
 	 */
400 400
	public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException {
401
		percent = 0;
401 402
		Histogram hist = new Histogram(getBandCount(), classes.length());
402 403
		for (int iBand = 0; iBand < getBandCount(); iBand++) { 
403 404
			for (int col = 0; col < getHeight(); col++) {
......
412 413
					}		 
413 414
					if(pixelValue >= 0)
414 415
						hist.incrementPxValue(iBand, pixelValue);
415
				}		
416
				}
417
				if (isCanceled()) return null;
418
				percent = ((iBand*getHeight() + col) * 100) / (getHeight() * getBandCount());
416 419
			}
417 420
		}
421
		percent = 100;
418 422
		return hist;
419 423
	}
420 424

  
trunk/libraries/libRaster/src/org/gvsig/raster/util/Histogram.java
153 153
			for (int iBand = 0; iBand < histogram.length; iBand++) {
154 154
				for (int j = 0; j < histogram[iBand].length; j++)
155 155
					// Lo multiplico por 1000 para que no se pierdan datos al redondear
156
					hist[iBand][j] = (long) (java.lang.Math.log((double) (histogram[iBand][j] - min + 1))*1000);
156
					hist[iBand][j] = (long) (1000.0 * java.lang.Math.log((double) (histogram[iBand][j] - min + 1)));
157 157
			}
158 158
			return hist;
159 159
		}

Also available in: Unified diff