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