Revision 11072 trunk/libraries/libRaster/src/org/gvsig/raster/dataset/properties/DatasetHistogram.java
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 |
|
Also available in: Unified diff