gvsig-raster / org.gvsig.raster / trunk / org.gvsig.raster / org.gvsig.raster.lib / org.gvsig.raster.lib.impl / src / main / java / org / gvsig / raster / impl / buffer / cache / PageBuffer.java @ 1029
History | View | Annotate | Download (21.4 KB)
1 |
/* gvSIG. Geographic Information System of the Valencian Government
|
---|---|
2 |
*
|
3 |
* Copyright (C) 2007-2008 Infrastructures and Transports Department
|
4 |
* of the Valencian Government (CIT)
|
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., 51 Franklin Street, Fifth Floor, Boston,
|
19 |
* MA 02110-1301, USA.
|
20 |
*
|
21 |
*/
|
22 |
package org.gvsig.raster.impl.buffer.cache; |
23 |
|
24 |
import java.awt.geom.Rectangle2D; |
25 |
import java.io.IOException; |
26 |
|
27 |
import org.gvsig.fmap.dal.DataStore; |
28 |
import org.gvsig.fmap.dal.coverage.dataset.Buffer; |
29 |
import org.gvsig.fmap.dal.coverage.datastruct.Band; |
30 |
import org.gvsig.fmap.dal.coverage.datastruct.NoData; |
31 |
import org.gvsig.fmap.dal.coverage.exception.HistogramException; |
32 |
import org.gvsig.fmap.dal.coverage.exception.ProcessInterruptedException; |
33 |
import org.gvsig.fmap.dal.coverage.process.IncrementableTask; |
34 |
import org.gvsig.fmap.dal.coverage.store.RasterDataStore; |
35 |
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer; |
36 |
import org.gvsig.raster.impl.buffer.BufferHistogramComputer; |
37 |
import org.gvsig.raster.impl.process.RasterTask; |
38 |
import org.gvsig.raster.impl.process.RasterTaskQueue; |
39 |
import org.gvsig.tools.exception.BaseException; |
40 |
import org.gvsig.tools.visitor.Visitor; |
41 |
|
42 |
/**
|
43 |
* Esta clase representa una p?gina de cache.Cada p?gina de cach? est? compuesta por
|
44 |
* varios objetos PageBandBuffer donde cada uno es una p?gina que corresponde a una
|
45 |
* banda de raster cacheada.
|
46 |
*
|
47 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
48 |
*
|
49 |
*/
|
50 |
public class PageBuffer implements Buffer { |
51 |
private PageBandBuffer[] pageBandBuffer = null; |
52 |
private double[] limits = null; |
53 |
private HistogramComputer histogramComputer = null; |
54 |
|
55 |
/**
|
56 |
* Constructor
|
57 |
* @param dataType
|
58 |
* @param width
|
59 |
* @param height
|
60 |
* @param bandNr
|
61 |
* @param malloc
|
62 |
*/
|
63 |
public PageBuffer(int dataType, int width, int height, int bandNr, boolean malloc, int nHddPags) { |
64 |
pageBandBuffer = new PageBandBuffer[bandNr];
|
65 |
for (int i = 0; i < pageBandBuffer.length; i++) |
66 |
pageBandBuffer[i] = new PageBandBuffer(dataType, width, height, 1, malloc, i); |
67 |
} |
68 |
|
69 |
/*
|
70 |
* (non-Javadoc)
|
71 |
* @see org.gvsig.raster.driver.Buffer#isBandSwitchable()
|
72 |
*/
|
73 |
public boolean isBandSwitchable() { |
74 |
return false; |
75 |
} |
76 |
|
77 |
/**
|
78 |
* Asigna la lista de paginas de disco
|
79 |
* @param hddList Lista de p?ginas de disco
|
80 |
*/
|
81 |
public void setHddPages(HddPage[] hddList) { |
82 |
for (int i = 0; i < pageBandBuffer.length; i++) |
83 |
pageBandBuffer[i].setHddPages(hddList); |
84 |
} |
85 |
|
86 |
/**
|
87 |
* Carga una p?gina especificada en el par?metro nPag con los datos necesarios.
|
88 |
* Para esto recorre todas las bandas de la p?gina llamando al load de cada una.
|
89 |
*
|
90 |
* @param nPag N?mero de p?gina a cargar
|
91 |
*/
|
92 |
public void loadPage(int nPag) { |
93 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
94 |
try {
|
95 |
pageBandBuffer[i].loadPage(nPag); |
96 |
} catch (ProcessInterruptedException e) {
|
97 |
//Cuando se cancela la carga de una p?gina salimos al acabar la p?gina anterior
|
98 |
break;
|
99 |
} |
100 |
} |
101 |
} |
102 |
|
103 |
/**
|
104 |
* Salva una p?gina especificada en el par?metro nPag a disco.
|
105 |
* Para esto recorre todas las bandas de la p?gina llamando al save de cada una.
|
106 |
*
|
107 |
* @param nPag N?mero de p?gina a salvar
|
108 |
* @throws IOException
|
109 |
*/
|
110 |
public void savePage(int nPag) throws IOException { |
111 |
for (int i = 0; i < pageBandBuffer.length; i++) |
112 |
pageBandBuffer[i].savePage(nPag); |
113 |
} |
114 |
|
115 |
public void assign(int band, byte value) { |
116 |
pageBandBuffer[band].assign(0, value);
|
117 |
} |
118 |
|
119 |
public void assign(int band, short value) { |
120 |
pageBandBuffer[band].assign(0, value);
|
121 |
} |
122 |
|
123 |
public void assign(int band, int value) { |
124 |
pageBandBuffer[band].assign(0, value);
|
125 |
} |
126 |
|
127 |
public void assign(int band, float value) { |
128 |
pageBandBuffer[band].assign(0, value);
|
129 |
} |
130 |
|
131 |
public void assign(int band, double value) { |
132 |
pageBandBuffer[band].assign(0, value);
|
133 |
} |
134 |
|
135 |
public void assignBand(int nBand, Band band) { |
136 |
} |
137 |
|
138 |
public void assignBandToNotValid(int Band) { |
139 |
} |
140 |
|
141 |
public Buffer cloneBuffer() { |
142 |
return null; |
143 |
} |
144 |
|
145 |
public void copyBand(int nBand, Band band) { |
146 |
} |
147 |
|
148 |
public Band createBand(byte defaultValue) { |
149 |
return null; |
150 |
} |
151 |
|
152 |
public Band getBand(int nBand) { |
153 |
return null; |
154 |
} |
155 |
|
156 |
public Buffer getBandBuffer(int nBand) { |
157 |
return null; |
158 |
} |
159 |
|
160 |
public int getBandCount() { |
161 |
return pageBandBuffer[0].getBandCount(); |
162 |
} |
163 |
|
164 |
public int getDataType() { |
165 |
return pageBandBuffer[0].getDataType(); |
166 |
} |
167 |
|
168 |
public void setDataType(int dataType) { |
169 |
|
170 |
} |
171 |
|
172 |
public int getHeight() { |
173 |
return pageBandBuffer[0].getHeight(); |
174 |
} |
175 |
|
176 |
public int getWidth() { |
177 |
return pageBandBuffer[0].getWidth(); |
178 |
} |
179 |
|
180 |
public NoData getNoDataValue() {
|
181 |
return pageBandBuffer[0].getNoDataValue(); |
182 |
} |
183 |
|
184 |
public double getNotValidValue() { |
185 |
return pageBandBuffer[0].getNotValidValue(); |
186 |
} |
187 |
|
188 |
public byte getElemByte(int line, int col, int band) { |
189 |
return pageBandBuffer[band].getElemByte(line, col, 0); |
190 |
} |
191 |
|
192 |
public short getElemShort(int line, int col, int band) { |
193 |
return pageBandBuffer[band].getElemShort(line, col, 0); |
194 |
} |
195 |
|
196 |
public int getElemInt(int line, int col, int band) { |
197 |
return pageBandBuffer[band].getElemInt(line, col, 0); |
198 |
} |
199 |
|
200 |
public float getElemFloat(int line, int col, int band) { |
201 |
return pageBandBuffer[band].getElemFloat(line, col, 0); |
202 |
} |
203 |
|
204 |
public double getElemDouble(int line, int col, int band) { |
205 |
return pageBandBuffer[band].getElemDouble(line, col, 0); |
206 |
} |
207 |
|
208 |
|
209 |
|
210 |
|
211 |
public void getElemByte(int line, int col, byte[] data) { |
212 |
for (int i = 0; i < pageBandBuffer.length; i++) |
213 |
data[i] = pageBandBuffer[i].getElemByte(line, col, 0);
|
214 |
} |
215 |
|
216 |
public void getElemShort(int line, int col, short[] data) { |
217 |
for (int i = 0; i < pageBandBuffer.length; i++) |
218 |
data[i] = pageBandBuffer[i].getElemShort(line, col, 0);
|
219 |
} |
220 |
|
221 |
public void getElemInt(int line, int col, int[] data) { |
222 |
for (int i = 0; i < pageBandBuffer.length; i++) |
223 |
data[i] = pageBandBuffer[i].getElemInt(line, col, 0);
|
224 |
} |
225 |
|
226 |
public void getElemFloat(int line, int col, float[] data) { |
227 |
for (int i = 0; i < pageBandBuffer.length; i++) |
228 |
data[i] = pageBandBuffer[i].getElemFloat(line, col, 0);
|
229 |
} |
230 |
|
231 |
public void getElemDouble(int line, int col, double[] data) { |
232 |
for (int i = 0; i < pageBandBuffer.length; i++) |
233 |
data[i] = pageBandBuffer[i].getElemDouble(line, col, 0);
|
234 |
} |
235 |
|
236 |
|
237 |
public byte[][] getLineByte(int line) { |
238 |
byte[][] b = new byte[pageBandBuffer.length][]; |
239 |
for (int i = 0; i < pageBandBuffer.length; i++) |
240 |
b[i] = pageBandBuffer[i].getLineByte(line)[0];
|
241 |
return b;
|
242 |
} |
243 |
|
244 |
public double[][] getLineDouble(int line) { |
245 |
double[][] d = new double[pageBandBuffer.length][]; |
246 |
for (int i = 0; i < pageBandBuffer.length; i++) |
247 |
d[i] = pageBandBuffer[i].getLineDouble(line)[0];
|
248 |
return d;
|
249 |
} |
250 |
|
251 |
public float[][] getLineFloat(int line) { |
252 |
float[][] f = new float[pageBandBuffer.length][]; |
253 |
for (int i = 0; i < pageBandBuffer.length; i++) |
254 |
f[i] = pageBandBuffer[i].getLineFloat(line)[0];
|
255 |
return f;
|
256 |
} |
257 |
|
258 |
public int[][] getLineInt(int line) { |
259 |
int[][] in = new int[pageBandBuffer.length][]; |
260 |
for (int i = 0; i < pageBandBuffer.length; i++) |
261 |
in[i] = pageBandBuffer[i].getLineInt(line)[0];
|
262 |
return in;
|
263 |
} |
264 |
|
265 |
public short[][] getLineShort(int line) { |
266 |
short[][] s = new short[pageBandBuffer.length][]; |
267 |
for (int i = 0; i < pageBandBuffer.length; i++) |
268 |
s[i] = pageBandBuffer[i].getLineShort(line)[0];
|
269 |
return s;
|
270 |
} |
271 |
|
272 |
|
273 |
|
274 |
public byte[] getLineFromBandByte(int line, int band) { |
275 |
return pageBandBuffer[band].getLineFromBandByte(line, 0); |
276 |
} |
277 |
|
278 |
public double[] getLineFromBandDouble(int line, int band) { |
279 |
return pageBandBuffer[band].getLineFromBandDouble(line, 0); |
280 |
} |
281 |
|
282 |
public float[] getLineFromBandFloat(int line, int band) { |
283 |
return pageBandBuffer[band].getLineFromBandFloat(line, 0); |
284 |
} |
285 |
|
286 |
public int[] getLineFromBandInt(int line, int band) { |
287 |
return pageBandBuffer[band].getLineFromBandInt(line, 0); |
288 |
} |
289 |
|
290 |
public short[] getLineFromBandShort(int line, int band) { |
291 |
return pageBandBuffer[band].getLineFromBandShort(line, 0); |
292 |
} |
293 |
|
294 |
|
295 |
|
296 |
|
297 |
public void interchangeBands(int band1, int band2) { |
298 |
} |
299 |
|
300 |
public void mallocOneBand(int dataType, int width, int height, int band) { |
301 |
} |
302 |
|
303 |
public void replicateBand(int orig, int dest) { |
304 |
} |
305 |
|
306 |
|
307 |
|
308 |
public void setElem(int line, int col, int band, byte data) { |
309 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
310 |
} |
311 |
|
312 |
public void setElem(int line, int col, int band, short data) { |
313 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
314 |
} |
315 |
|
316 |
public void setElem(int line, int col, int band, int data) { |
317 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
318 |
} |
319 |
|
320 |
public void setElem(int line, int col, int band, float data) { |
321 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
322 |
} |
323 |
|
324 |
public void setElem(int line, int col, int band, double data) { |
325 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
326 |
} |
327 |
|
328 |
|
329 |
|
330 |
public void setElemByte(int line, int col, byte[] data) { |
331 |
byte[] b = new byte[1]; |
332 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
333 |
b[0] = data[i];
|
334 |
pageBandBuffer[i].setElemByte(line, col, b); |
335 |
} |
336 |
} |
337 |
|
338 |
public void setElemDouble(int line, int col, double[] data) { |
339 |
double[] b = new double[1]; |
340 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
341 |
b[0] = data[i];
|
342 |
pageBandBuffer[i].setElemDouble(line, col, b); |
343 |
} |
344 |
} |
345 |
|
346 |
public void setElemFloat(int line, int col, float[] data) { |
347 |
float[] b = new float[1]; |
348 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
349 |
b[0] = data[i];
|
350 |
pageBandBuffer[i].setElemFloat(line, col, b); |
351 |
} |
352 |
} |
353 |
|
354 |
public void setElemInt(int line, int col, int[] data) { |
355 |
int[] b = new int[1]; |
356 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
357 |
b[0] = data[i];
|
358 |
pageBandBuffer[i].setElemInt(line, col, b); |
359 |
} |
360 |
} |
361 |
|
362 |
public void setElemShort(int line, int col, short[] data) { |
363 |
short[] b = new short[1]; |
364 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
365 |
b[0] = data[i];
|
366 |
pageBandBuffer[i].setElemShort(line, col, b); |
367 |
} |
368 |
} |
369 |
|
370 |
public void setLineByte(byte[][] data, int line) { |
371 |
byte[][] bAux = new byte[1][]; |
372 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
373 |
bAux[0] = data[i];
|
374 |
pageBandBuffer[i].setLineByte(bAux, line); |
375 |
} |
376 |
} |
377 |
|
378 |
public void setLineDouble(double[][] data, int line) { |
379 |
double[][] bAux = new double[1][]; |
380 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
381 |
bAux[0] = data[i];
|
382 |
pageBandBuffer[i].setLineDouble(bAux, line); |
383 |
} |
384 |
} |
385 |
|
386 |
public void setLineFloat(float[][] data, int line) { |
387 |
float[][] bAux = new float[1][]; |
388 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
389 |
bAux[0] = data[i];
|
390 |
pageBandBuffer[i].setLineFloat(bAux, line); |
391 |
} |
392 |
} |
393 |
|
394 |
public void setLineInt(int[][] data, int line) { |
395 |
int[][] bAux = new int[1][]; |
396 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
397 |
bAux[0] = data[i];
|
398 |
pageBandBuffer[i].setLineInt(bAux, line); |
399 |
} |
400 |
} |
401 |
|
402 |
public void setLineShort(short[][] data, int line) { |
403 |
short[][] bAux = new short[1][]; |
404 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
405 |
bAux[0] = data[i];
|
406 |
pageBandBuffer[i].setLineShort(bAux, line); |
407 |
} |
408 |
} |
409 |
|
410 |
public void setLineInBandByte(byte[] data, int line, int band) { |
411 |
pageBandBuffer[band].setLineInBandByte(data, line, 0);
|
412 |
} |
413 |
|
414 |
public void setLineInBandDouble(double[] data, int line, int band) { |
415 |
pageBandBuffer[band].setLineInBandDouble(data, line, 0);
|
416 |
} |
417 |
|
418 |
public void setLineInBandFloat(float[] data, int line, int band) { |
419 |
pageBandBuffer[band].setLineInBandFloat(data, line, 0);
|
420 |
} |
421 |
|
422 |
public void setLineInBandInt(int[] data, int line, int band) { |
423 |
pageBandBuffer[band].setLineInBandInt(data, line, 0);
|
424 |
} |
425 |
|
426 |
public void setLineInBandShort(short[] data, int line, int band) { |
427 |
pageBandBuffer[band].setLineInBandShort(data, line, 0);
|
428 |
} |
429 |
|
430 |
public void setNoDataValue(NoData nd) { |
431 |
for (int i = 0; i < pageBandBuffer.length; i++) |
432 |
pageBandBuffer[0].setNoDataValue(nd);
|
433 |
} |
434 |
|
435 |
public void setNotValidValue(double value) { |
436 |
} |
437 |
|
438 |
public void switchBands(int[] bands) { |
439 |
} |
440 |
|
441 |
/*
|
442 |
* (non-Javadoc)
|
443 |
* @see org.gvsig.fmap.dal.coverage.store.props.Histogram#getMinimum()
|
444 |
*/
|
445 |
public double getMinimum() { |
446 |
if(limits == null) |
447 |
try {
|
448 |
limits = getLimits(); |
449 |
} catch (ProcessInterruptedException e) {
|
450 |
return 0; |
451 |
} |
452 |
return limits[0]; |
453 |
} |
454 |
|
455 |
/*
|
456 |
* (non-Javadoc)
|
457 |
* @see org.gvsig.fmap.dal.coverage.store.props.Histogram#getMaximum()
|
458 |
*/
|
459 |
public double getMaximum() { |
460 |
if(limits == null) |
461 |
try {
|
462 |
limits = getLimits(); |
463 |
} catch (ProcessInterruptedException e) {
|
464 |
return 0; |
465 |
} |
466 |
return limits[1]; |
467 |
} |
468 |
|
469 |
/*
|
470 |
* (non-Javadoc)
|
471 |
* @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getLimits()
|
472 |
*/
|
473 |
public double[] getLimits() throws ProcessInterruptedException { |
474 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
475 |
double max = Double.NEGATIVE_INFINITY; |
476 |
double secondMax = max;
|
477 |
double min = Double.MAX_VALUE; |
478 |
double secondMin = min;
|
479 |
double value = 0; |
480 |
|
481 |
switch (getDataType()) {
|
482 |
case Buffer.TYPE_BYTE: |
483 |
for (int i = 0; i < getBandCount(); i++) { |
484 |
for (int r = 0; r < getHeight(); r++) { |
485 |
for (int c = 0; c < getWidth(); c++) { |
486 |
value = (double) (getElemByte(r, c, i) & 0xff); |
487 |
if (value > max) {
|
488 |
if (max != value)
|
489 |
secondMax = max; |
490 |
max = value; |
491 |
} |
492 |
if (value < min) {
|
493 |
if (min != value)
|
494 |
secondMin = min; |
495 |
min = value; |
496 |
} |
497 |
} |
498 |
if (task.getEvent() != null) |
499 |
task.manageEvent(task.getEvent()); |
500 |
} |
501 |
} |
502 |
break;
|
503 |
case Buffer.TYPE_SHORT: |
504 |
for (int i = 0; i < getBandCount(); i++) { |
505 |
for (int r = 0; r < getHeight(); r++) { |
506 |
for (int c = 0; c < getWidth(); c++) { |
507 |
value = (double) getElemShort(r, c, i);
|
508 |
if (value > max) {
|
509 |
if (max != value)
|
510 |
secondMax = max; |
511 |
max = value; |
512 |
} |
513 |
if (value < min) {
|
514 |
if (min != value)
|
515 |
secondMin = min; |
516 |
min = value; |
517 |
} |
518 |
} |
519 |
if (task.getEvent() != null) |
520 |
task.manageEvent(task.getEvent()); |
521 |
} |
522 |
} |
523 |
break;
|
524 |
case Buffer.TYPE_INT: |
525 |
for (int i = 0; i < getBandCount(); i++) { |
526 |
for (int r = 0; r < getHeight(); r++) { |
527 |
for (int c = 0; c < getWidth(); c++) { |
528 |
value = (double) getElemInt(r, c, i);
|
529 |
if (value > max) {
|
530 |
if (max != value)
|
531 |
secondMax = max; |
532 |
max = value; |
533 |
} |
534 |
if (value < min) {
|
535 |
if (min != value)
|
536 |
secondMin = min; |
537 |
min = value; |
538 |
} |
539 |
} |
540 |
if (task.getEvent() != null) |
541 |
task.manageEvent(task.getEvent()); |
542 |
} |
543 |
} |
544 |
break;
|
545 |
case Buffer.TYPE_FLOAT: |
546 |
for (int i = 0; i < getBandCount(); i++) { |
547 |
for (int r = 0; r < getHeight(); r++) { |
548 |
for (int c = 0; c < getWidth(); c++) { |
549 |
value = (double) getElemFloat(r, c, i);
|
550 |
if (value > max) {
|
551 |
if (max != value)
|
552 |
secondMax = max; |
553 |
max = value; |
554 |
} |
555 |
if (value < min) {
|
556 |
if (min != value)
|
557 |
secondMin = min; |
558 |
min = value; |
559 |
} |
560 |
} |
561 |
if (task.getEvent() != null) |
562 |
task.manageEvent(task.getEvent()); |
563 |
} |
564 |
} |
565 |
break;
|
566 |
case Buffer.TYPE_DOUBLE: |
567 |
for (int i = 0; i < getBandCount(); i++) { |
568 |
for (int r = 0; r < getHeight(); r++) { |
569 |
for (int c = 0; c < getWidth(); c++) { |
570 |
value = getElemDouble(r, c, i); |
571 |
if (value > max) {
|
572 |
if (max != value)
|
573 |
secondMax = max; |
574 |
max = value; |
575 |
} |
576 |
if (value < min) {
|
577 |
if (min != value)
|
578 |
secondMin = min; |
579 |
min = value; |
580 |
} |
581 |
} |
582 |
if (task.getEvent() != null) |
583 |
task.manageEvent(task.getEvent()); |
584 |
} |
585 |
} |
586 |
break;
|
587 |
} |
588 |
// Si no existe un secondMax lo igualo al maximo existente
|
589 |
if (secondMax == Double.NEGATIVE_INFINITY) |
590 |
secondMax = max; |
591 |
// Si no existe un secondMin lo igualo al minimo existente
|
592 |
if (secondMin == Double.MAX_VALUE) |
593 |
secondMin = min; |
594 |
|
595 |
double[] values = new double[2]; |
596 |
values[0] = min;
|
597 |
values[1] = max;
|
598 |
values[2] = secondMin;
|
599 |
values[3] = secondMax;
|
600 |
return values;
|
601 |
} |
602 |
|
603 |
/*
|
604 |
* (non-Javadoc)
|
605 |
* @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getAllBandsLimits()
|
606 |
*/
|
607 |
public double[][] getAllBandsLimits() throws ProcessInterruptedException { |
608 |
RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
|
609 |
double max[] = new double[getBandCount()]; |
610 |
double min[] = new double[getBandCount()]; |
611 |
double value = 0; |
612 |
|
613 |
for (int i = 0; i < getBandCount(); i++) { |
614 |
max[i] = Double.NEGATIVE_INFINITY;
|
615 |
min[i] = Double.MAX_VALUE;
|
616 |
} |
617 |
|
618 |
switch (getDataType()) {
|
619 |
case Buffer.TYPE_BYTE: |
620 |
for (int i = 0; i < getBandCount(); i++) { |
621 |
for (int r = 0; r < getHeight(); r++) { |
622 |
for (int c = 0; c < getWidth(); c++) { |
623 |
value = (double) (getElemByte(r, c, i) & 0xff); |
624 |
if (value > max[i])
|
625 |
max[i] = value; |
626 |
if (value < min[i])
|
627 |
min[i] = value; |
628 |
} |
629 |
if (task.getEvent() != null) |
630 |
task.manageEvent(task.getEvent()); |
631 |
} |
632 |
} |
633 |
break;
|
634 |
case Buffer.TYPE_SHORT: |
635 |
for (int i = 0; i < getBandCount(); i++) { |
636 |
for (int r = 0; r < getHeight(); r++) { |
637 |
for (int c = 0; c < getWidth(); c++) { |
638 |
value = (double) getElemShort(r, c, i);
|
639 |
if (value > max[i])
|
640 |
max[i] = value; |
641 |
if (value < min[i])
|
642 |
min[i] = value; |
643 |
} |
644 |
if (task.getEvent() != null) |
645 |
task.manageEvent(task.getEvent()); |
646 |
} |
647 |
} |
648 |
break;
|
649 |
case Buffer.TYPE_INT: |
650 |
for (int i = 0; i < getBandCount(); i++) { |
651 |
for (int r = 0; r < getHeight(); r++) { |
652 |
for (int c = 0; c < getWidth(); c++) { |
653 |
value = (double) getElemInt(r, c, i);
|
654 |
if (value > max[i])
|
655 |
max[i] = value; |
656 |
if (value < min[i])
|
657 |
min[i] = value; |
658 |
} |
659 |
if (task.getEvent() != null) |
660 |
task.manageEvent(task.getEvent()); |
661 |
} |
662 |
} |
663 |
break;
|
664 |
case Buffer.TYPE_FLOAT: |
665 |
for (int i = 0; i < getBandCount(); i++) { |
666 |
for (int r = 0; r < getHeight(); r++) { |
667 |
for (int c = 0; c < getWidth(); c++) { |
668 |
value = (double) getElemFloat(r, c, i);
|
669 |
if (value > max[i])
|
670 |
max[i] = value; |
671 |
if (value < min[i])
|
672 |
min[i] = value; |
673 |
} |
674 |
if (task.getEvent() != null) |
675 |
task.manageEvent(task.getEvent()); |
676 |
} |
677 |
} |
678 |
break;
|
679 |
case Buffer.TYPE_DOUBLE: |
680 |
for (int i = 0; i < getBandCount(); i++) { |
681 |
for (int r = 0; r < getHeight(); r++) { |
682 |
for (int c = 0; c < getWidth(); c++) { |
683 |
value = getElemDouble(r, c, i); |
684 |
if (value > max[i])
|
685 |
max[i] = value; |
686 |
if (value < min[i])
|
687 |
min[i] = value; |
688 |
} |
689 |
if (task.getEvent() != null) |
690 |
task.manageEvent(task.getEvent()); |
691 |
} |
692 |
} |
693 |
break;
|
694 |
} |
695 |
double[][] values = new double[2][getBandCount()]; |
696 |
|
697 |
for (int i = 0; i < getBandCount(); i++) { |
698 |
values[0][i] = min[i];
|
699 |
values[1][i] = max[i];
|
700 |
} |
701 |
return values;
|
702 |
} |
703 |
|
704 |
/*
|
705 |
* (non-Javadoc)
|
706 |
* @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#getHistogramComputer()
|
707 |
*/
|
708 |
public HistogramComputer getHistogramComputer()
|
709 |
throws HistogramException, InterruptedException { |
710 |
if(histogramComputer == null) |
711 |
histogramComputer = new BufferHistogramComputer(this); |
712 |
return histogramComputer;
|
713 |
} |
714 |
|
715 |
/*
|
716 |
* (non-Javadoc)
|
717 |
* @see org.gvsig.raster.dataset.Buffer#isInside(int, int)
|
718 |
*/
|
719 |
public boolean isInside(int x, int y) { |
720 |
if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) |
721 |
return false; |
722 |
return true; |
723 |
} |
724 |
|
725 |
/*
|
726 |
* (non-Javadoc)
|
727 |
* @see org.gvsig.fmap.dal.coverage.dataset.Buffer#isReadOnlyBuffer()
|
728 |
*/
|
729 |
public boolean isReadOnlyBuffer() { |
730 |
return false; |
731 |
} |
732 |
|
733 |
/*
|
734 |
* (non-Javadoc)
|
735 |
* @see org.gvsig.fmap.dal.coverage.dataset.Buffer#isCached()
|
736 |
*/
|
737 |
public boolean isCached() { |
738 |
return false; |
739 |
} |
740 |
|
741 |
/*
|
742 |
* (non-Javadoc)
|
743 |
* @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getIncrementableTask()
|
744 |
*/
|
745 |
public IncrementableTask getIncrementableTask() {
|
746 |
return null; |
747 |
} |
748 |
|
749 |
/**
|
750 |
* Libera el buffer de memoria
|
751 |
*/
|
752 |
public void free() { |
753 |
if(pageBandBuffer != null) |
754 |
for (int i = 0; i < pageBandBuffer.length; i++) |
755 |
pageBandBuffer[i].free(); |
756 |
} |
757 |
|
758 |
/*
|
759 |
* (non-Javadoc)
|
760 |
* @see org.gvsig.fmap.dal.coverage.buffer.Buffer#getAdjustedWindow(int, int, int)
|
761 |
*/
|
762 |
public Buffer getAdjustedWindow(int w, int h, int interpolationMethod) throws ProcessInterruptedException { |
763 |
return null; |
764 |
} |
765 |
|
766 |
public Rectangle2D getDataExtent() { |
767 |
// TODO Auto-generated method stub
|
768 |
return null; |
769 |
} |
770 |
|
771 |
public void setDataExtent(Rectangle2D r) { |
772 |
// TODO Auto-generated method stub
|
773 |
} |
774 |
|
775 |
public RasterDataStore getStore() {
|
776 |
return null; |
777 |
} |
778 |
|
779 |
public void setStore(RasterDataStore store) { |
780 |
} |
781 |
|
782 |
public void addDrawableBands(int[] db) {} |
783 |
|
784 |
//****************************************************
|
785 |
//*********Implementing DataSet methods***************
|
786 |
//****************************************************
|
787 |
|
788 |
/*
|
789 |
* (non-Javadoc)
|
790 |
* @see org.gvsig.fmap.dal.DataSet#isFromStore(org.gvsig.fmap.dal.DataStore)
|
791 |
*/
|
792 |
public boolean isFromStore(DataStore store) { |
793 |
// TODO Auto-generated method stub
|
794 |
return false; |
795 |
} |
796 |
|
797 |
//****************************************************
|
798 |
//*********Implementing Visitable methods*************
|
799 |
//****************************************************
|
800 |
|
801 |
/*
|
802 |
* (non-Javadoc)
|
803 |
* @see org.gvsig.tools.visitor.Visitable#accept(org.gvsig.tools.visitor.Visitor)
|
804 |
*/
|
805 |
public void accept(Visitor visitor) throws BaseException { |
806 |
// TODO Auto-generated method stub
|
807 |
|
808 |
} |
809 |
|
810 |
//****************************************************
|
811 |
//*********Implementing Disposable methods************
|
812 |
//****************************************************
|
813 |
|
814 |
/*
|
815 |
* (non-Javadoc)
|
816 |
* @see org.gvsig.tools.dispose.Disposable#dispose()
|
817 |
*/
|
818 |
public void dispose() { |
819 |
free(); |
820 |
} |
821 |
} |