Revision 5482 org.gvsig.raster/branches/org.gvsig.raster.2.4/org.gvsig.raster/org.gvsig.raster.lib/org.gvsig.raster.lib.buffer/org.gvsig.raster.lib.buffer.impl/src/main/java/org/gvsig/raster/lib/buffer/impl/statistics/HistogramOperation.java
HistogramOperation.java | ||
---|---|---|
1 | 1 |
package org.gvsig.raster.lib.buffer.impl.statistics; |
2 | 2 |
|
3 |
import java.util.ArrayList; |
|
4 |
import java.util.List; |
|
5 |
|
|
6 |
import org.gvsig.raster.lib.buffer.api.Band; |
|
7 |
import org.gvsig.raster.lib.buffer.api.BufferManager; |
|
8 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramBand; |
|
9 |
import org.gvsig.raster.lib.buffer.api.statistics.HistogramClass; |
|
3 | 10 |
import org.gvsig.raster.lib.buffer.api.statistics.StatisticsBand; |
4 | 11 |
|
5 |
|
|
12 |
/** |
|
13 |
* @author fdiaz |
|
14 |
* |
|
15 |
*/ |
|
6 | 16 |
public class HistogramOperation implements StatisticalOperation { |
7 | 17 |
|
18 |
private StatisticsBand statisticsBand; |
|
19 |
private List<HistogramClass> histogramClasses; |
|
20 |
private HistogramBand histogramBand; |
|
21 |
private Band band; |
|
8 | 22 |
|
23 |
public HistogramOperation(StatisticsBand statisticsBand, Band band) { |
|
24 |
this.statisticsBand = statisticsBand; |
|
25 |
this.band = band; |
|
26 |
} |
|
9 | 27 |
|
10 | 28 |
@Override |
11 |
public void preOperation(StatisticsBand statisticsBand) { |
|
12 |
// TODO Auto-generated method stub |
|
29 |
public void pre() { |
|
30 |
int dataType = this.statisticsBand.getDataType(); |
|
31 |
if(dataType == BufferManager.TYPE_DOUBLE || dataType == BufferManager.TYPE_FLOAT){ |
|
32 |
calculateHistogramClasses(); |
|
33 |
histogramBand = new DefaultHistogramBand(band, this.histogramClasses); |
|
13 | 34 |
|
35 |
} else { |
|
36 |
histogramBand = new DefaultHistogramBand(band); |
|
37 |
} |
|
14 | 38 |
} |
15 | 39 |
|
16 |
@Override
|
|
17 |
public void executionOperation(Object value) {
|
|
18 |
// TODO Auto-generated method stub
|
|
40 |
private void calculateHistogramClasses() {
|
|
41 |
int classesNumber = new Double(Math.ceil(Math.sqrt(this.statisticsBand.getBandLenght()))).intValue();
|
|
42 |
histogramClasses = new ArrayList<HistogramClass>(classesNumber);
|
|
19 | 43 |
|
44 |
double range = this.statisticsBand.getMaximum()-this.statisticsBand.getMinimum(); |
|
45 |
double widthInterval = range/classesNumber; |
|
46 |
double minInterval = this.statisticsBand.getMinimum(); |
|
47 |
double maxInterval; // = this.statisticsBand.getMaximum(); |
|
48 |
for(int i=0; i<classesNumber-1; i++){ |
|
49 |
maxInterval = minInterval+widthInterval; |
|
50 |
DefaultHistogramClass histogramClass = new DefaultHistogramClass(minInterval, maxInterval); |
|
51 |
histogramClass.setValue(0); |
|
52 |
histogramClasses.add(histogramClass); |
|
53 |
minInterval = maxInterval; |
|
54 |
} |
|
55 |
DefaultHistogramClass histogramClass = new DefaultHistogramClass(minInterval, this.statisticsBand.getMaximum()); |
|
56 |
histogramClasses.add(histogramClass); |
|
57 |
|
|
20 | 58 |
} |
21 | 59 |
|
22 | 60 |
@Override |
23 |
public void postOperation(StatisticsBand statisticsBand) { |
|
24 |
// TODO Auto-generated method stub |
|
61 |
public void addValue(Number value) { |
|
62 |
((DefaultHistogramBand)histogramBand).addValue(value.doubleValue()); |
|
63 |
} |
|
25 | 64 |
|
65 |
@Override |
|
66 |
public void post() { |
|
67 |
// do nothing |
|
26 | 68 |
} |
27 | 69 |
|
28 | 70 |
@Override |
29 | 71 |
public Object getResult() { |
30 |
// TODO Auto-generated method stub |
|
31 |
return null; |
|
72 |
return histogramBand; |
|
32 | 73 |
} |
33 | 74 |
|
34 | 75 |
} |
Also available in: Unified diff