svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / buffer / cache / PageBuffer.java @ 27361
History | View | Annotate | Download (19.8 KB)
1 |
|
---|---|
2 |
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
|
3 |
*
|
4 |
* Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
|
5 |
*
|
6 |
* This program is free software; you can redistribute it and/or
|
7 |
* modify it under the terms of the GNU General Public License
|
8 |
* as published by the Free Software Foundation; either version 2
|
9 |
* of the License, or (at your option) any later version.
|
10 |
*
|
11 |
* This program is distributed in the hope that it will be useful,
|
12 |
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
13 |
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
14 |
* GNU General Public License for more details.
|
15 |
*
|
16 |
* You should have received a copy of the GNU General Public License
|
17 |
* along with this program; if not, write to the Free Software
|
18 |
* Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307,USA.
|
19 |
*/
|
20 |
package org.gvsig.raster.buffer.cache; |
21 |
|
22 |
import java.io.IOException; |
23 |
|
24 |
import org.gvsig.raster.buffer.IBand; |
25 |
import org.gvsig.raster.dataset.IBuffer; |
26 |
import org.gvsig.raster.datastruct.Histogram; |
27 |
import org.gvsig.raster.process.RasterTask; |
28 |
import org.gvsig.raster.process.RasterTaskQueue; |
29 |
|
30 |
/**
|
31 |
* Esta clase representa una p?gina de cache.Cada p?gina de cach? est? compuesta por
|
32 |
* varios objetos PageBandBuffer donde cada uno es una p?gina que corresponde a una
|
33 |
* banda de raster cacheada.
|
34 |
*
|
35 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
36 |
*
|
37 |
*/
|
38 |
public class PageBuffer implements IBuffer { |
39 |
private PageBandBuffer[] pageBandBuffer = null; |
40 |
|
41 |
private int percent = 0; |
42 |
|
43 |
/**
|
44 |
* Constructor
|
45 |
* @param dataType
|
46 |
* @param width
|
47 |
* @param height
|
48 |
* @param bandNr
|
49 |
* @param malloc
|
50 |
*/
|
51 |
public PageBuffer(int dataType, int width, int height, int bandNr, boolean malloc, int nHddPags) { |
52 |
pageBandBuffer = new PageBandBuffer[bandNr];
|
53 |
for (int i = 0; i < pageBandBuffer.length; i++) |
54 |
pageBandBuffer[i] = new PageBandBuffer(dataType, width, height, 1, malloc, i); |
55 |
} |
56 |
|
57 |
/*
|
58 |
* (non-Javadoc)
|
59 |
* @see org.gvsig.raster.driver.IBuffer#isBandSwitchable()
|
60 |
*/
|
61 |
public boolean isBandSwitchable() { |
62 |
return false; |
63 |
} |
64 |
|
65 |
/**
|
66 |
* Asigna la lista de paginas de disco
|
67 |
* @param hddList Lista de p?ginas de disco
|
68 |
*/
|
69 |
public void setHddPages(HddPage[] hddList) { |
70 |
for (int i = 0; i < pageBandBuffer.length; i++) |
71 |
pageBandBuffer[i].setHddPages(hddList); |
72 |
} |
73 |
|
74 |
/**
|
75 |
* Carga una p?gina especificada en el par?metro nPag con los datos necesarios.
|
76 |
* Para esto recorre todas las bandas de la p?gina llamando al load de cada una.
|
77 |
*
|
78 |
* @param nPag N?mero de p?gina a cargar
|
79 |
* @throws InterruptedException
|
80 |
*/
|
81 |
public void loadPage(int nPag) throws InterruptedException { |
82 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
83 |
pageBandBuffer[i].loadPage(nPag); |
84 |
} |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Salva una p?gina especificada en el par?metro nPag a disco.
|
89 |
* Para esto recorre todas las bandas de la p?gina llamando al save de cada una.
|
90 |
*
|
91 |
* @param nPag N?mero de p?gina a salvar
|
92 |
* @throws IOException
|
93 |
* @throws InterruptedException
|
94 |
*/
|
95 |
public void savePage(int nPag) throws IOException, InterruptedException { |
96 |
for (int i = 0; i < pageBandBuffer.length; i++) |
97 |
pageBandBuffer[i].savePage(nPag); |
98 |
} |
99 |
|
100 |
public void assign(int band, byte value) { |
101 |
pageBandBuffer[band].assign(0, value);
|
102 |
} |
103 |
|
104 |
public void assign(int band, short value) { |
105 |
pageBandBuffer[band].assign(0, value);
|
106 |
} |
107 |
|
108 |
public void assign(int band, int value) { |
109 |
pageBandBuffer[band].assign(0, value);
|
110 |
} |
111 |
|
112 |
public void assign(int band, float value) { |
113 |
pageBandBuffer[band].assign(0, value);
|
114 |
} |
115 |
|
116 |
public void assign(int band, double value) { |
117 |
pageBandBuffer[band].assign(0, value);
|
118 |
} |
119 |
|
120 |
public void assignBand(int nBand, IBand band) { |
121 |
} |
122 |
|
123 |
public void assignBandToNotValid(int iBand) { |
124 |
} |
125 |
|
126 |
public IBuffer cloneBuffer() {
|
127 |
return null; |
128 |
} |
129 |
|
130 |
public void copyBand(int nBand, IBand band) { |
131 |
} |
132 |
|
133 |
public IBand createBand(byte defaultValue) { |
134 |
return null; |
135 |
} |
136 |
|
137 |
public IBand getBand(int nBand) { |
138 |
return null; |
139 |
} |
140 |
|
141 |
public IBuffer getBandBuffer(int nBand) { |
142 |
return null; |
143 |
} |
144 |
|
145 |
public int getBandCount() { |
146 |
return pageBandBuffer[0].getBandCount(); |
147 |
} |
148 |
|
149 |
public int getDataType() { |
150 |
return pageBandBuffer[0].getDataType(); |
151 |
} |
152 |
|
153 |
public void setDataType(int dataType) { |
154 |
|
155 |
} |
156 |
|
157 |
public int getHeight() { |
158 |
return pageBandBuffer[0].getHeight(); |
159 |
} |
160 |
|
161 |
public int getWidth() { |
162 |
return pageBandBuffer[0].getWidth(); |
163 |
} |
164 |
|
165 |
|
166 |
|
167 |
public byte getByteNoDataValue() { |
168 |
return pageBandBuffer[0].getByteNoDataValue(); |
169 |
} |
170 |
|
171 |
public float getFloatNoDataValue() { |
172 |
return pageBandBuffer[0].getFloatNoDataValue(); |
173 |
} |
174 |
|
175 |
public int getIntNoDataValue() { |
176 |
return pageBandBuffer[0].getIntNoDataValue(); |
177 |
} |
178 |
|
179 |
public double getNoDataValue() { |
180 |
return pageBandBuffer[0].getNoDataValue(); |
181 |
} |
182 |
|
183 |
public double getNotValidValue() { |
184 |
return pageBandBuffer[0].getNotValidValue(); |
185 |
} |
186 |
|
187 |
public short getShortNoDataValue() { |
188 |
return pageBandBuffer[0].getShortNoDataValue(); |
189 |
} |
190 |
|
191 |
|
192 |
|
193 |
public byte getElemByte(int line, int col, int band) { |
194 |
return pageBandBuffer[band].getElemByte(line, col, 0); |
195 |
} |
196 |
|
197 |
public short getElemShort(int line, int col, int band) { |
198 |
return pageBandBuffer[band].getElemShort(line, col, 0); |
199 |
} |
200 |
|
201 |
public int getElemInt(int line, int col, int band) { |
202 |
return pageBandBuffer[band].getElemInt(line, col, 0); |
203 |
} |
204 |
|
205 |
public float getElemFloat(int line, int col, int band) { |
206 |
return pageBandBuffer[band].getElemFloat(line, col, 0); |
207 |
} |
208 |
|
209 |
public double getElemDouble(int line, int col, int band) { |
210 |
return pageBandBuffer[band].getElemDouble(line, col, 0); |
211 |
} |
212 |
|
213 |
|
214 |
|
215 |
|
216 |
public void getElemByte(int line, int col, byte[] data) { |
217 |
for (int i = 0; i < pageBandBuffer.length; i++) |
218 |
data[i] = pageBandBuffer[i].getElemByte(line, col, 0);
|
219 |
} |
220 |
|
221 |
public void getElemShort(int line, int col, short[] data) { |
222 |
for (int i = 0; i < pageBandBuffer.length; i++) |
223 |
data[i] = pageBandBuffer[i].getElemShort(line, col, 0);
|
224 |
} |
225 |
|
226 |
public void getElemInt(int line, int col, int[] data) { |
227 |
for (int i = 0; i < pageBandBuffer.length; i++) |
228 |
data[i] = pageBandBuffer[i].getElemInt(line, col, 0);
|
229 |
} |
230 |
|
231 |
public void getElemFloat(int line, int col, float[] data) { |
232 |
for (int i = 0; i < pageBandBuffer.length; i++) |
233 |
data[i] = pageBandBuffer[i].getElemFloat(line, col, 0);
|
234 |
} |
235 |
|
236 |
public void getElemDouble(int line, int col, double[] data) { |
237 |
for (int i = 0; i < pageBandBuffer.length; i++) |
238 |
data[i] = pageBandBuffer[i].getElemDouble(line, col, 0);
|
239 |
} |
240 |
|
241 |
|
242 |
public byte[][] getLineByte(int line) { |
243 |
byte[][] b = new byte[pageBandBuffer.length][]; |
244 |
for (int i = 0; i < pageBandBuffer.length; i++) |
245 |
b[i] = pageBandBuffer[i].getLineByte(line)[0];
|
246 |
return b;
|
247 |
} |
248 |
|
249 |
public double[][] getLineDouble(int line) { |
250 |
double[][] d = new double[pageBandBuffer.length][]; |
251 |
for (int i = 0; i < pageBandBuffer.length; i++) |
252 |
d[i] = pageBandBuffer[i].getLineDouble(line)[0];
|
253 |
return d;
|
254 |
} |
255 |
|
256 |
public float[][] getLineFloat(int line) { |
257 |
float[][] f = new float[pageBandBuffer.length][]; |
258 |
for (int i = 0; i < pageBandBuffer.length; i++) |
259 |
f[i] = pageBandBuffer[i].getLineFloat(line)[0];
|
260 |
return f;
|
261 |
} |
262 |
|
263 |
public int[][] getLineInt(int line) { |
264 |
int[][] in = new int[pageBandBuffer.length][]; |
265 |
for (int i = 0; i < pageBandBuffer.length; i++) |
266 |
in[i] = pageBandBuffer[i].getLineInt(line)[0];
|
267 |
return in;
|
268 |
} |
269 |
|
270 |
public short[][] getLineShort(int line) { |
271 |
short[][] s = new short[pageBandBuffer.length][]; |
272 |
for (int i = 0; i < pageBandBuffer.length; i++) |
273 |
s[i] = pageBandBuffer[i].getLineShort(line)[0];
|
274 |
return s;
|
275 |
} |
276 |
|
277 |
|
278 |
|
279 |
public byte[] getLineFromBandByte(int line, int band) { |
280 |
return pageBandBuffer[band].getLineFromBandByte(line, 0); |
281 |
} |
282 |
|
283 |
public double[] getLineFromBandDouble(int line, int band) { |
284 |
return pageBandBuffer[band].getLineFromBandDouble(line, 0); |
285 |
} |
286 |
|
287 |
public float[] getLineFromBandFloat(int line, int band) { |
288 |
return pageBandBuffer[band].getLineFromBandFloat(line, 0); |
289 |
} |
290 |
|
291 |
public int[] getLineFromBandInt(int line, int band) { |
292 |
return pageBandBuffer[band].getLineFromBandInt(line, 0); |
293 |
} |
294 |
|
295 |
public short[] getLineFromBandShort(int line, int band) { |
296 |
return pageBandBuffer[band].getLineFromBandShort(line, 0); |
297 |
} |
298 |
|
299 |
|
300 |
|
301 |
|
302 |
public void interchangeBands(int band1, int band2) { |
303 |
} |
304 |
|
305 |
public void mallocOneBand(int dataType, int width, int height, int band) { |
306 |
} |
307 |
|
308 |
public void replicateBand(int orig, int dest) { |
309 |
} |
310 |
|
311 |
|
312 |
|
313 |
public void setElem(int line, int col, int band, byte data) { |
314 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
315 |
} |
316 |
|
317 |
public void setElem(int line, int col, int band, short data) { |
318 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
319 |
} |
320 |
|
321 |
public void setElem(int line, int col, int band, int data) { |
322 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
323 |
} |
324 |
|
325 |
public void setElem(int line, int col, int band, float data) { |
326 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
327 |
} |
328 |
|
329 |
public void setElem(int line, int col, int band, double data) { |
330 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
331 |
} |
332 |
|
333 |
|
334 |
|
335 |
public void setElemByte(int line, int col, byte[] data) { |
336 |
byte[] b = new byte[1]; |
337 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
338 |
b[0] = data[i];
|
339 |
pageBandBuffer[i].setElemByte(line, col, b); |
340 |
} |
341 |
} |
342 |
|
343 |
public void setElemDouble(int line, int col, double[] data) { |
344 |
double[] b = new double[1]; |
345 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
346 |
b[0] = data[i];
|
347 |
pageBandBuffer[i].setElemDouble(line, col, b); |
348 |
} |
349 |
} |
350 |
|
351 |
public void setElemFloat(int line, int col, float[] data) { |
352 |
float[] b = new float[1]; |
353 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
354 |
b[0] = data[i];
|
355 |
pageBandBuffer[i].setElemFloat(line, col, b); |
356 |
} |
357 |
} |
358 |
|
359 |
public void setElemInt(int line, int col, int[] data) { |
360 |
int[] b = new int[1]; |
361 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
362 |
b[0] = data[i];
|
363 |
pageBandBuffer[i].setElemInt(line, col, b); |
364 |
} |
365 |
} |
366 |
|
367 |
public void setElemShort(int line, int col, short[] data) { |
368 |
short[] b = new short[1]; |
369 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
370 |
b[0] = data[i];
|
371 |
pageBandBuffer[i].setElemShort(line, col, b); |
372 |
} |
373 |
} |
374 |
|
375 |
public void setLineByte(byte[][] data, int line) { |
376 |
byte[][] bAux = new byte[1][]; |
377 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
378 |
bAux[0] = data[i];
|
379 |
pageBandBuffer[i].setLineByte(bAux, line); |
380 |
} |
381 |
} |
382 |
|
383 |
public void setLineDouble(double[][] data, int line) { |
384 |
double[][] bAux = new double[1][]; |
385 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
386 |
bAux[0] = data[i];
|
387 |
pageBandBuffer[i].setLineDouble(bAux, line); |
388 |
} |
389 |
} |
390 |
|
391 |
public void setLineFloat(float[][] data, int line) { |
392 |
float[][] bAux = new float[1][]; |
393 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
394 |
bAux[0] = data[i];
|
395 |
pageBandBuffer[i].setLineFloat(bAux, line); |
396 |
} |
397 |
} |
398 |
|
399 |
public void setLineInt(int[][] data, int line) { |
400 |
int[][] bAux = new int[1][]; |
401 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
402 |
bAux[0] = data[i];
|
403 |
pageBandBuffer[i].setLineInt(bAux, line); |
404 |
} |
405 |
} |
406 |
|
407 |
public void setLineShort(short[][] data, int line) { |
408 |
short[][] bAux = new short[1][]; |
409 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
410 |
bAux[0] = data[i];
|
411 |
pageBandBuffer[i].setLineShort(bAux, line); |
412 |
} |
413 |
} |
414 |
|
415 |
public void setLineInBandByte(byte[] data, int line, int band) { |
416 |
pageBandBuffer[band].setLineInBandByte(data, line, 0);
|
417 |
} |
418 |
|
419 |
public void setLineInBandDouble(double[] data, int line, int band) { |
420 |
pageBandBuffer[band].setLineInBandDouble(data, line, 0);
|
421 |
} |
422 |
|
423 |
public void setLineInBandFloat(float[] data, int line, int band) { |
424 |
pageBandBuffer[band].setLineInBandFloat(data, line, 0);
|
425 |
} |
426 |
|
427 |
public void setLineInBandInt(int[] data, int line, int band) { |
428 |
pageBandBuffer[band].setLineInBandInt(data, line, 0);
|
429 |
} |
430 |
|
431 |
public void setLineInBandShort(short[] data, int line, int band) { |
432 |
pageBandBuffer[band].setLineInBandShort(data, line, 0);
|
433 |
} |
434 |
|
435 |
public void setNoDataValue(double nd) { |
436 |
} |
437 |
|
438 |
public void setNotValidValue(double value) { |
439 |
} |
440 |
|
441 |
public void switchBands(int[] bands) { |
442 |
} |
443 |
|
444 |
/*
|
445 |
* (non-Javadoc)
|
446 |
* @see org.gvsig.raster.dataset.IBuffer#getLimits()
|
447 |
*/
|
448 |
public double[] getLimits() throws InterruptedException { |
449 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
450 |
double max = Double.NEGATIVE_INFINITY; |
451 |
double secondMax = max;
|
452 |
double min = Double.MAX_VALUE; |
453 |
double secondMin = min;
|
454 |
double value = 0; |
455 |
|
456 |
switch (getDataType()) {
|
457 |
case IBuffer.TYPE_BYTE:
|
458 |
for (int i = 0; i < getBandCount(); i++) { |
459 |
for (int r = 0; r < getHeight(); r++) { |
460 |
for (int c = 0; c < getWidth(); c++) { |
461 |
value = (double) (getElemByte(r, c, i) & 0xff); |
462 |
if (value > max) {
|
463 |
if (max != value)
|
464 |
secondMax = max; |
465 |
max = value; |
466 |
} |
467 |
if (value < min) {
|
468 |
if (min != value)
|
469 |
secondMin = min; |
470 |
min = value; |
471 |
} |
472 |
} |
473 |
if (task.getEvent() != null) |
474 |
task.manageEvent(task.getEvent()); |
475 |
} |
476 |
} |
477 |
break;
|
478 |
case IBuffer.TYPE_SHORT:
|
479 |
for (int i = 0; i < getBandCount(); i++) { |
480 |
for (int r = 0; r < getHeight(); r++) { |
481 |
for (int c = 0; c < getWidth(); c++) { |
482 |
value = (double) getElemShort(r, c, i);
|
483 |
if (value > max) {
|
484 |
if (max != value)
|
485 |
secondMax = max; |
486 |
max = value; |
487 |
} |
488 |
if (value < min) {
|
489 |
if (min != value)
|
490 |
secondMin = min; |
491 |
min = value; |
492 |
} |
493 |
} |
494 |
if (task.getEvent() != null) |
495 |
task.manageEvent(task.getEvent()); |
496 |
} |
497 |
} |
498 |
break;
|
499 |
case IBuffer.TYPE_INT:
|
500 |
for (int i = 0; i < getBandCount(); i++) { |
501 |
for (int r = 0; r < getHeight(); r++) { |
502 |
for (int c = 0; c < getWidth(); c++) { |
503 |
value = (double) getElemInt(r, c, i);
|
504 |
if (value > max) {
|
505 |
if (max != value)
|
506 |
secondMax = max; |
507 |
max = value; |
508 |
} |
509 |
if (value < min) {
|
510 |
if (min != value)
|
511 |
secondMin = min; |
512 |
min = value; |
513 |
} |
514 |
} |
515 |
if (task.getEvent() != null) |
516 |
task.manageEvent(task.getEvent()); |
517 |
} |
518 |
} |
519 |
break;
|
520 |
case IBuffer.TYPE_FLOAT:
|
521 |
for (int i = 0; i < getBandCount(); i++) { |
522 |
for (int r = 0; r < getHeight(); r++) { |
523 |
for (int c = 0; c < getWidth(); c++) { |
524 |
value = (double) getElemFloat(r, c, i);
|
525 |
if (value > max) {
|
526 |
if (max != value)
|
527 |
secondMax = max; |
528 |
max = value; |
529 |
} |
530 |
if (value < min) {
|
531 |
if (min != value)
|
532 |
secondMin = min; |
533 |
min = value; |
534 |
} |
535 |
} |
536 |
if (task.getEvent() != null) |
537 |
task.manageEvent(task.getEvent()); |
538 |
} |
539 |
} |
540 |
break;
|
541 |
case IBuffer.TYPE_DOUBLE:
|
542 |
for (int i = 0; i < getBandCount(); i++) { |
543 |
for (int r = 0; r < getHeight(); r++) { |
544 |
for (int c = 0; c < getWidth(); c++) { |
545 |
value = getElemDouble(r, c, i); |
546 |
if (value > max) {
|
547 |
if (max != value)
|
548 |
secondMax = max; |
549 |
max = value; |
550 |
} |
551 |
if (value < min) {
|
552 |
if (min != value)
|
553 |
secondMin = min; |
554 |
min = value; |
555 |
} |
556 |
} |
557 |
if (task.getEvent() != null) |
558 |
task.manageEvent(task.getEvent()); |
559 |
} |
560 |
} |
561 |
break;
|
562 |
} |
563 |
// Si no existe un secondMax lo igualo al maximo existente
|
564 |
if (secondMax == Double.NEGATIVE_INFINITY) |
565 |
secondMax = max; |
566 |
// Si no existe un secondMin lo igualo al minimo existente
|
567 |
if (secondMin == Double.MAX_VALUE) |
568 |
secondMin = min; |
569 |
|
570 |
double[] values = new double[2]; |
571 |
values[0] = min;
|
572 |
values[1] = max;
|
573 |
values[2] = secondMin;
|
574 |
values[3] = secondMax;
|
575 |
return values;
|
576 |
} |
577 |
|
578 |
|
579 |
private double[][] getAllBandsLimits() throws InterruptedException { |
580 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
581 |
double max[] = new double[getBandCount()]; |
582 |
double min[] = new double[getBandCount()]; |
583 |
double value = 0; |
584 |
|
585 |
for (int i = 0; i < getBandCount(); i++) { |
586 |
max[i] = Double.NEGATIVE_INFINITY;
|
587 |
min[i] = Double.MAX_VALUE;
|
588 |
} |
589 |
|
590 |
switch (getDataType()) {
|
591 |
case IBuffer.TYPE_BYTE:
|
592 |
for (int i = 0; i < getBandCount(); i++) { |
593 |
for (int r = 0; r < getHeight(); r++) { |
594 |
for (int c = 0; c < getWidth(); c++) { |
595 |
value = (double) (getElemByte(r, c, i) & 0xff); |
596 |
if (value > max[i])
|
597 |
max[i] = value; |
598 |
if (value < min[i])
|
599 |
min[i] = value; |
600 |
} |
601 |
if (task.getEvent() != null) |
602 |
task.manageEvent(task.getEvent()); |
603 |
} |
604 |
} |
605 |
break;
|
606 |
case IBuffer.TYPE_SHORT:
|
607 |
for (int i = 0; i < getBandCount(); i++) { |
608 |
for (int r = 0; r < getHeight(); r++) { |
609 |
for (int c = 0; c < getWidth(); c++) { |
610 |
value = (double) getElemShort(r, c, i);
|
611 |
if (value > max[i])
|
612 |
max[i] = value; |
613 |
if (value < min[i])
|
614 |
min[i] = value; |
615 |
} |
616 |
if (task.getEvent() != null) |
617 |
task.manageEvent(task.getEvent()); |
618 |
} |
619 |
} |
620 |
break;
|
621 |
case IBuffer.TYPE_INT:
|
622 |
for (int i = 0; i < getBandCount(); i++) { |
623 |
for (int r = 0; r < getHeight(); r++) { |
624 |
for (int c = 0; c < getWidth(); c++) { |
625 |
value = (double) getElemInt(r, c, i);
|
626 |
if (value > max[i])
|
627 |
max[i] = value; |
628 |
if (value < min[i])
|
629 |
min[i] = value; |
630 |
} |
631 |
if (task.getEvent() != null) |
632 |
task.manageEvent(task.getEvent()); |
633 |
} |
634 |
} |
635 |
break;
|
636 |
case IBuffer.TYPE_FLOAT:
|
637 |
for (int i = 0; i < getBandCount(); i++) { |
638 |
for (int r = 0; r < getHeight(); r++) { |
639 |
for (int c = 0; c < getWidth(); c++) { |
640 |
value = (double) getElemFloat(r, c, i);
|
641 |
if (value > max[i])
|
642 |
max[i] = value; |
643 |
if (value < min[i])
|
644 |
min[i] = value; |
645 |
} |
646 |
if (task.getEvent() != null) |
647 |
task.manageEvent(task.getEvent()); |
648 |
} |
649 |
} |
650 |
break;
|
651 |
case IBuffer.TYPE_DOUBLE:
|
652 |
for (int i = 0; i < getBandCount(); i++) { |
653 |
for (int r = 0; r < getHeight(); r++) { |
654 |
for (int c = 0; c < getWidth(); c++) { |
655 |
value = getElemDouble(r, c, i); |
656 |
if (value > max[i])
|
657 |
max[i] = value; |
658 |
if (value < min[i])
|
659 |
min[i] = value; |
660 |
} |
661 |
if (task.getEvent() != null) |
662 |
task.manageEvent(task.getEvent()); |
663 |
} |
664 |
} |
665 |
break;
|
666 |
} |
667 |
double[][] values = new double[2][getBandCount()]; |
668 |
|
669 |
for (int i = 0; i < getBandCount(); i++) { |
670 |
values[0][i] = min[i];
|
671 |
values[1][i] = max[i];
|
672 |
} |
673 |
return values;
|
674 |
} |
675 |
|
676 |
/*
|
677 |
* (non-Javadoc)
|
678 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
|
679 |
*/
|
680 |
public Histogram getHistogram() throws InterruptedException { |
681 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
682 |
percent = 0;
|
683 |
Histogram hist = null;
|
684 |
double[][] limits = getAllBandsLimits(); |
685 |
|
686 |
hist = new Histogram(getBandCount(), limits[0], limits[1], getDataType()); |
687 |
|
688 |
hist.setNoDataValue(pageBandBuffer[0].getNoDataValue());
|
689 |
|
690 |
for (int iBand = 0; iBand < getBandCount(); iBand++) { |
691 |
for (int row = 0; row < getHeight(); row++) { |
692 |
switch(getDataType()) {
|
693 |
case IBuffer.TYPE_BYTE:
|
694 |
for (int col = 0; col < getWidth(); col++) |
695 |
hist.incrementPxValue(iBand, (double)(getElemByte(row, col, iBand) & 0xff)); |
696 |
break;
|
697 |
case IBuffer.TYPE_SHORT:
|
698 |
for (int col = 0; col < getWidth(); col++) |
699 |
hist.incrementPxValue(iBand, (double)(getElemShort(row, col, iBand) & 0xffff)); |
700 |
break;
|
701 |
case IBuffer.TYPE_INT:
|
702 |
for (int col = 0; col < getWidth(); col++) |
703 |
hist.incrementPxValue(iBand, (double)(getElemInt(row, col, iBand) & 0xffffffff)); |
704 |
break;
|
705 |
case IBuffer.TYPE_FLOAT:
|
706 |
for (int col = 0; col < getWidth(); col++) |
707 |
hist.incrementPxValue(iBand, (double)getElemFloat(row, col, iBand));
|
708 |
break;
|
709 |
case IBuffer.TYPE_DOUBLE:
|
710 |
for (int col = 0; col < getWidth(); col++) |
711 |
hist.incrementPxValue(iBand, getElemDouble(row, col, iBand)); |
712 |
break;
|
713 |
} |
714 |
|
715 |
if (task.getEvent() != null) |
716 |
task.manageEvent(task.getEvent()); |
717 |
percent = ((iBand*getHeight() + row) * 100) /(getHeight() * getBandCount());
|
718 |
} |
719 |
} |
720 |
percent = 100;
|
721 |
return hist;
|
722 |
} |
723 |
|
724 |
/*
|
725 |
* (non-Javadoc)
|
726 |
* @see org.gvsig.raster.util.IHistogramable#resetPercent()
|
727 |
*/
|
728 |
public void resetPercent() { |
729 |
percent = 0;
|
730 |
} |
731 |
|
732 |
/*
|
733 |
* (non-Javadoc)
|
734 |
* @see org.gvsig.raster.util.IHistogramable#getPercent()
|
735 |
*/
|
736 |
public int getPercent() { |
737 |
return percent;
|
738 |
} |
739 |
|
740 |
/*
|
741 |
* (non-Javadoc)
|
742 |
* @see org.gvsig.raster.dataset.IBuffer#isInside(int, int)
|
743 |
*/
|
744 |
public boolean isInside(int x, int y) { |
745 |
if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) |
746 |
return false; |
747 |
return true; |
748 |
} |
749 |
|
750 |
/**
|
751 |
* Libera el buffer de memoria
|
752 |
*/
|
753 |
public void free(){ |
754 |
if(pageBandBuffer != null) |
755 |
for (int i = 0; i < pageBandBuffer.length; i++) |
756 |
pageBandBuffer[i].free(); |
757 |
} |
758 |
} |