Statistics
| Revision:

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 @ 1081

History | View | Annotate | Download (23.1 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.ProcessInterruptedException;
32
import org.gvsig.fmap.dal.coverage.process.IncrementableTask;
33
import org.gvsig.fmap.dal.coverage.store.RasterDataStore;
34
import org.gvsig.fmap.dal.coverage.store.props.HistogramComputer;
35
import org.gvsig.raster.impl.buffer.BufferHistogramComputer;
36
import org.gvsig.raster.impl.buffer.BufferInterpolation;
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
        private BufferInterpolation interp               = null;
55
        
56
        /**
57
         * Constructor
58
         * @param dataType
59
         * @param width
60
         * @param height
61
         * @param bandNr
62
         * @param malloc
63
         */
64
        public PageBuffer(int dataType, int width, int height, int bandNr, boolean malloc, int nHddPags) {
65
                pageBandBuffer = new PageBandBuffer[bandNr];
66
                for (int i = 0; i < pageBandBuffer.length; i++)
67
                        pageBandBuffer[i] = new PageBandBuffer(dataType, width, height, 1, malloc, i);
68
        }
69
        
70
        /*
71
         * (non-Javadoc)
72
         * @see org.gvsig.raster.driver.Buffer#isBandSwitchable()
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
        /*
174
         * (non-Javadoc)
175
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getBlockHeight()
176
         */
177
        public int getBlockHeight() {
178
                return pageBandBuffer[0].getHeight();
179
        }
180
        
181
        public int getHeight() {
182
                return pageBandBuffer[0].getHeight();
183
        }
184
        
185
        public int getWidth() {
186
                return pageBandBuffer[0].getWidth();
187
        }
188

    
189
        public NoData getNoDataValue() {
190
                return pageBandBuffer[0].getNoDataValue();
191
        }
192

    
193
        public double getNotValidValue() {
194
                return pageBandBuffer[0].getNotValidValue();
195
        }
196
        
197
        public byte getElemByte(int line, int col, int band) {
198
                return pageBandBuffer[band].getElemByte(line, col, 0);
199
        }
200

    
201
        public short getElemShort(int line, int col, int band) {
202
                return pageBandBuffer[band].getElemShort(line, col, 0);
203
        }
204
        
205
        public int getElemInt(int line, int col, int band) {
206
                return pageBandBuffer[band].getElemInt(line, col, 0);
207
        }
208

    
209
        public float getElemFloat(int line, int col, int band) {
210
                return pageBandBuffer[band].getElemFloat(line, col, 0);
211
        }
212
        
213
        public double getElemDouble(int line, int col, int band) {
214
                return pageBandBuffer[band].getElemDouble(line, col, 0);
215
        }
216

    
217
        
218

    
219

    
220
        public void getElemByte(int line, int col, byte[] data) {
221
                for (int i = 0; i < pageBandBuffer.length; i++) 
222
                        data[i] = pageBandBuffer[i].getElemByte(line, col, 0);
223
        }
224
        
225
        public void getElemShort(int line, int col, short[] data) {
226
                for (int i = 0; i < pageBandBuffer.length; i++) 
227
                        data[i] = pageBandBuffer[i].getElemShort(line, col, 0);
228
        }
229

    
230
        public void getElemInt(int line, int col, int[] data) {
231
                for (int i = 0; i < pageBandBuffer.length; i++) 
232
                        data[i] = pageBandBuffer[i].getElemInt(line, col, 0);
233
        }
234

    
235
        public void getElemFloat(int line, int col, float[] data) {
236
                for (int i = 0; i < pageBandBuffer.length; i++) 
237
                        data[i] = pageBandBuffer[i].getElemFloat(line, col, 0);
238
        }
239

    
240
        public void getElemDouble(int line, int col, double[] data) {
241
                for (int i = 0; i < pageBandBuffer.length; i++) 
242
                        data[i] = pageBandBuffer[i].getElemDouble(line, col, 0);
243
        }
244
        
245
        
246
        public byte[][] getLineByte(int line) {
247
                byte[][] b = new byte[pageBandBuffer.length][];
248
                for (int i = 0; i < pageBandBuffer.length; i++) 
249
                        b[i] = pageBandBuffer[i].getLineByte(line)[0];
250
                return b;
251
        }
252

    
253
        public double[][] getLineDouble(int line) {
254
                double[][] d = new double[pageBandBuffer.length][];
255
                for (int i = 0; i < pageBandBuffer.length; i++) 
256
                        d[i] = pageBandBuffer[i].getLineDouble(line)[0];
257
                return d;
258
        }
259

    
260
        public float[][] getLineFloat(int line) {
261
                float[][] f = new float[pageBandBuffer.length][];
262
                for (int i = 0; i < pageBandBuffer.length; i++) 
263
                        f[i] = pageBandBuffer[i].getLineFloat(line)[0];
264
                return f;
265
        }
266

    
267
        public int[][] getLineInt(int line) {
268
                int[][] in = new int[pageBandBuffer.length][];
269
                for (int i = 0; i < pageBandBuffer.length; i++) 
270
                        in[i] = pageBandBuffer[i].getLineInt(line)[0];
271
                return in;
272
        }
273

    
274
        public short[][] getLineShort(int line) {
275
                short[][] s = new short[pageBandBuffer.length][];
276
                for (int i = 0; i < pageBandBuffer.length; i++) 
277
                        s[i] = pageBandBuffer[i].getLineShort(line)[0];
278
                return s;
279
        }
280
        
281
        
282
        
283
        public byte[] getLineFromBandByte(int line, int band) {
284
                return pageBandBuffer[band].getLineFromBandByte(line, 0);
285
        }
286

    
287
        public double[] getLineFromBandDouble(int line, int band) {
288
                return pageBandBuffer[band].getLineFromBandDouble(line, 0);
289
        }
290

    
291
        public float[] getLineFromBandFloat(int line, int band) {
292
                return pageBandBuffer[band].getLineFromBandFloat(line, 0);
293
        }
294

    
295
        public int[] getLineFromBandInt(int line, int band) {
296
                return pageBandBuffer[band].getLineFromBandInt(line, 0);
297
        }
298

    
299
        public short[] getLineFromBandShort(int line, int band) {
300
                return pageBandBuffer[band].getLineFromBandShort(line, 0);
301
        }
302

    
303
        
304
        
305
        
306
        public void interchangeBands(int band1, int band2) {
307
        }
308

    
309
        public void mallocOneBand(int dataType, int width, int height, int band) {
310
        }
311

    
312
        public void replicateBand(int orig, int dest) {
313
        }
314

    
315

    
316

    
317
        public void setElem(int line, int col, int band, byte data) {
318
                pageBandBuffer[band].setElem(line, col, 0, data);
319
        }
320

    
321
        public void setElem(int line, int col, int band, short data) {
322
                pageBandBuffer[band].setElem(line, col, 0, data);
323
        }
324

    
325
        public void setElem(int line, int col, int band, int data) {
326
                pageBandBuffer[band].setElem(line, col, 0, data);
327
        }
328

    
329
        public void setElem(int line, int col, int band, float data) {
330
                pageBandBuffer[band].setElem(line, col, 0, data);
331
        }
332

    
333
        public void setElem(int line, int col, int band, double data) {
334
                pageBandBuffer[band].setElem(line, col, 0, data);
335
        }
336

    
337

    
338
        
339
        public void setElemByte(int line, int col, byte[] data) {
340
                byte[] b = new byte[1];
341
                for (int i = 0; i < pageBandBuffer.length; i++) {
342
                        b[0] = data[i];
343
                        pageBandBuffer[i].setElemByte(line, col, b);
344
                }
345
        }
346

    
347
        public void setElemDouble(int line, int col, double[] data) {
348
                double[] b = new double[1];
349
                for (int i = 0; i < pageBandBuffer.length; i++) {
350
                        b[0] = data[i];
351
                        pageBandBuffer[i].setElemDouble(line, col, b);
352
                }
353
        }
354

    
355
        public void setElemFloat(int line, int col, float[] data) {
356
                float[] b = new float[1];
357
                for (int i = 0; i < pageBandBuffer.length; i++) {
358
                        b[0] = data[i];
359
                        pageBandBuffer[i].setElemFloat(line, col, b);
360
                }
361
        }
362

    
363
        public void setElemInt(int line, int col, int[] data) {
364
                int[] b = new int[1];
365
                for (int i = 0; i < pageBandBuffer.length; i++) {
366
                        b[0] = data[i];
367
                        pageBandBuffer[i].setElemInt(line, col, b);
368
                }
369
        }
370

    
371
        public void setElemShort(int line, int col, short[] data) {
372
                short[] b = new short[1];
373
                for (int i = 0; i < pageBandBuffer.length; i++) {
374
                        b[0] = data[i];
375
                        pageBandBuffer[i].setElemShort(line, col, b);
376
                }
377
        }
378
        
379
        public void setLineByte(byte[][] data, int line) {
380
                byte[][] bAux = new byte[1][];
381
                for (int i = 0; i < pageBandBuffer.length; i++) {
382
                        bAux[0] = data[i];
383
                        pageBandBuffer[i].setLineByte(bAux, line);
384
                }
385
        }
386

    
387
        public void setLineDouble(double[][] data, int line) {
388
                double[][] bAux = new double[1][];
389
                for (int i = 0; i < pageBandBuffer.length; i++) {
390
                        bAux[0] = data[i];
391
                        pageBandBuffer[i].setLineDouble(bAux, line);
392
                }
393
        }
394

    
395
        public void setLineFloat(float[][] data, int line) {
396
                float[][] bAux = new float[1][];
397
                for (int i = 0; i < pageBandBuffer.length; i++) {
398
                        bAux[0] = data[i];
399
                        pageBandBuffer[i].setLineFloat(bAux, line);
400
                }
401
        }
402
        
403
        public void setLineInt(int[][] data, int line) {
404
                int[][] bAux = new int[1][];
405
                for (int i = 0; i < pageBandBuffer.length; i++) {
406
                        bAux[0] = data[i];
407
                        pageBandBuffer[i].setLineInt(bAux, line);
408
                }
409
        }
410

    
411
        public void setLineShort(short[][] data, int line) {
412
                short[][] bAux = new short[1][];
413
                for (int i = 0; i < pageBandBuffer.length; i++) {
414
                        bAux[0] = data[i];
415
                        pageBandBuffer[i].setLineShort(bAux, line);
416
                }
417
        }
418

    
419
        public void setLineInBandByte(byte[] data, int line, int band) {
420
                pageBandBuffer[band].setLineInBandByte(data, line, 0);
421
        }
422

    
423
        public void setLineInBandDouble(double[] data, int line, int band) {
424
                pageBandBuffer[band].setLineInBandDouble(data, line, 0);
425
        }
426

    
427
        public void setLineInBandFloat(float[] data, int line, int band) {
428
                pageBandBuffer[band].setLineInBandFloat(data, line, 0);
429
        }
430

    
431
        public void setLineInBandInt(int[] data, int line, int band) {
432
                pageBandBuffer[band].setLineInBandInt(data, line, 0);
433
        }
434

    
435
        public void setLineInBandShort(short[] data, int line, int band) {
436
                pageBandBuffer[band].setLineInBandShort(data, line, 0);
437
        }
438

    
439
        public void setNoDataValue(NoData nd) {
440
                for (int i = 0; i < pageBandBuffer.length; i++)
441
                        pageBandBuffer[0].setNoDataValue(nd);
442
        }
443

    
444
        public void setNotValidValue(double value) {
445
        }
446

    
447
        public void switchBands(int[] bands) {
448
        }
449

    
450
        /*
451
         * (non-Javadoc)
452
         * @see org.gvsig.fmap.dal.coverage.store.props.Histogram#getMinimum()
453
         */
454
        public double getMinimum() {
455
                if(limits == null)
456
                        try {
457
                                limits = getLimits();
458
                        } catch (ProcessInterruptedException e) {
459
                                return 0;
460
                        }
461
                return limits[0];
462
        }
463

    
464
        /*
465
         * (non-Javadoc)
466
         * @see org.gvsig.fmap.dal.coverage.store.props.Histogram#getMaximum()
467
         */
468
        public double getMaximum() {
469
                if(limits == null)
470
                        try {
471
                                limits = getLimits();
472
                        } catch (ProcessInterruptedException e) {
473
                                return 0;
474
                        }
475
                return limits[1];
476
        }
477
        
478
        /*
479
         * (non-Javadoc)
480
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getLimits()
481
         */
482
        public double[] getLimits() throws ProcessInterruptedException {
483
                RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
484
                double max = Double.NEGATIVE_INFINITY;
485
                double secondMax = max;
486
                double min = Double.MAX_VALUE;
487
                double secondMin = min;
488
                double value = 0;
489

    
490
                switch (getDataType()) {
491
                        case Buffer.TYPE_BYTE:
492
                                for (int i = 0; i < getBandCount(); i++) {
493
                                        for (int r = 0; r < getHeight(); r++) {
494
                                                for (int c = 0; c < getWidth(); c++) {
495
                                                        value = (double) (getElemByte(r, c, i) & 0xff);
496
                                                        if (value > max) {
497
                                                                if (max != value)
498
                                                                        secondMax = max;
499
                                                                max = value;
500
                                                        }
501
                                                        if (value < min) {
502
                                                                if (min != value)
503
                                                                        secondMin = min;
504
                                                                min = value;
505
                                                        }
506
                                                }
507
                                                if (task.getEvent() != null)
508
                                                        task.manageEvent(task.getEvent());
509
                                        }
510
                                }
511
                                break;
512
                        case Buffer.TYPE_SHORT:
513
                                for (int i = 0; i < getBandCount(); i++) {
514
                                        for (int r = 0; r < getHeight(); r++) {
515
                                                for (int c = 0; c < getWidth(); c++) {
516
                                                        value = (double) getElemShort(r, c, i);
517
                                                        if (value > max) {
518
                                                                if (max != value)
519
                                                                        secondMax = max;
520
                                                                max = value;
521
                                                        }
522
                                                        if (value < min) {
523
                                                                if (min != value)
524
                                                                        secondMin = min;
525
                                                                min = value;
526
                                                        }
527
                                                }
528
                                                if (task.getEvent() != null)
529
                                                        task.manageEvent(task.getEvent());
530
                                        }
531
                                }
532
                                break;
533
                        case Buffer.TYPE_INT:
534
                                for (int i = 0; i < getBandCount(); i++) {
535
                                        for (int r = 0; r < getHeight(); r++) {
536
                                                for (int c = 0; c < getWidth(); c++) {
537
                                                        value = (double) getElemInt(r, c, i);
538
                                                        if (value > max) {
539
                                                                if (max != value)
540
                                                                        secondMax = max;
541
                                                                max = value;
542
                                                        }
543
                                                        if (value < min) {
544
                                                                if (min != value)
545
                                                                        secondMin = min;
546
                                                                min = value;
547
                                                        }
548
                                                }
549
                                                if (task.getEvent() != null)
550
                                                        task.manageEvent(task.getEvent());
551
                                        }
552
                                }
553
                                break;
554
                        case Buffer.TYPE_FLOAT:
555
                                for (int i = 0; i < getBandCount(); i++) {
556
                                        for (int r = 0; r < getHeight(); r++) {
557
                                                for (int c = 0; c < getWidth(); c++) {
558
                                                        value = (double) getElemFloat(r, c, i);
559
                                                        if (value > max) {
560
                                                                if (max != value)
561
                                                                        secondMax = max;
562
                                                                max = value;
563
                                                        }
564
                                                        if (value < min) {
565
                                                                if (min != value)
566
                                                                        secondMin = min;
567
                                                                min = value;
568
                                                        }
569
                                                }
570
                                                if (task.getEvent() != null)
571
                                                        task.manageEvent(task.getEvent());
572
                                        }
573
                                }
574
                                break;
575
                        case Buffer.TYPE_DOUBLE:
576
                                for (int i = 0; i < getBandCount(); i++) {
577
                                        for (int r = 0; r < getHeight(); r++) {
578
                                                for (int c = 0; c < getWidth(); c++) {
579
                                                        value = getElemDouble(r, c, i);
580
                                                        if (value > max) {
581
                                                                if (max != value)
582
                                                                        secondMax = max;
583
                                                                max = value;
584
                                                        }
585
                                                        if (value < min) {
586
                                                                if (min != value)
587
                                                                        secondMin = min;
588
                                                                min = value;
589
                                                        }
590
                                                }
591
                                                if (task.getEvent() != null)
592
                                                        task.manageEvent(task.getEvent());
593
                                        }
594
                                }
595
                                break;
596
                }
597
                // Si no existe un secondMax lo igualo al maximo existente
598
                if (secondMax == Double.NEGATIVE_INFINITY)
599
                        secondMax = max;
600
                // Si no existe un secondMin lo igualo al minimo existente
601
                if (secondMin == Double.MAX_VALUE)
602
                        secondMin = min;
603

    
604
                double[] values = new double[2];
605
                values[0] = min;
606
                values[1] = max;
607
                values[2] = secondMin;
608
                values[3] = secondMax;
609
                return values;
610
        }
611
        
612
        /*
613
         * (non-Javadoc)
614
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getAllBandsLimits()
615
         */
616
        public double[][] getAllBandsLimits() throws ProcessInterruptedException {
617
                RasterTask task = RasterTaskQueue.get(Thread.currentThread().toString());
618
                double max[] = new double[getBandCount()];
619
                double min[] = new double[getBandCount()];
620
                double value = 0;
621

    
622
                for (int i = 0; i < getBandCount(); i++) {
623
                        max[i] = Double.NEGATIVE_INFINITY;
624
                        min[i] = Double.MAX_VALUE;
625
                }
626

    
627
                switch (getDataType()) {
628
                        case Buffer.TYPE_BYTE:
629
                                for (int i = 0; i < getBandCount(); i++) {
630
                                        for (int r = 0; r < getHeight(); r++) {
631
                                                for (int c = 0; c < getWidth(); c++) {
632
                                                        value = (double) (getElemByte(r, c, i) & 0xff);
633
                                                        if (value > max[i])
634
                                                                max[i] = value;
635
                                                        if (value < min[i])
636
                                                                min[i] = value;
637
                                                }
638
                                                if (task.getEvent() != null)
639
                                                        task.manageEvent(task.getEvent());
640
                                        }
641
                                }
642
                                break;
643
                        case Buffer.TYPE_SHORT:
644
                                for (int i = 0; i < getBandCount(); i++) {
645
                                        for (int r = 0; r < getHeight(); r++) {
646
                                                for (int c = 0; c < getWidth(); c++) {
647
                                                        value = (double) getElemShort(r, c, i);
648
                                                        if (value > max[i])
649
                                                                max[i] = value;
650
                                                        if (value < min[i])
651
                                                                min[i] = value;
652
                                                }
653
                                                if (task.getEvent() != null)
654
                                                        task.manageEvent(task.getEvent());
655
                                        }
656
                                }
657
                                break;
658
                        case Buffer.TYPE_INT:
659
                                for (int i = 0; i < getBandCount(); i++) {
660
                                        for (int r = 0; r < getHeight(); r++) {
661
                                                for (int c = 0; c < getWidth(); c++) {
662
                                                        value = (double) getElemInt(r, c, i);
663
                                                        if (value > max[i])
664
                                                                max[i] = value;
665
                                                        if (value < min[i])
666
                                                                min[i] = value;
667
                                                }
668
                                                if (task.getEvent() != null)
669
                                                        task.manageEvent(task.getEvent());
670
                                        }
671
                                }
672
                                break;
673
                        case Buffer.TYPE_FLOAT:
674
                                for (int i = 0; i < getBandCount(); i++) {
675
                                        for (int r = 0; r < getHeight(); r++) {
676
                                                for (int c = 0; c < getWidth(); c++) {
677
                                                        value = (double) getElemFloat(r, c, i);
678
                                                        if (value > max[i])
679
                                                                max[i] = value;
680
                                                        if (value < min[i])
681
                                                                min[i] = value;
682
                                                }
683
                                                if (task.getEvent() != null)
684
                                                        task.manageEvent(task.getEvent());
685
                                        }
686
                                }
687
                                break;
688
                        case Buffer.TYPE_DOUBLE:
689
                                for (int i = 0; i < getBandCount(); i++) {
690
                                        for (int r = 0; r < getHeight(); r++) {
691
                                                for (int c = 0; c < getWidth(); c++) {
692
                                                        value = getElemDouble(r, c, i);
693
                                                        if (value > max[i])
694
                                                                max[i] = value;
695
                                                        if (value < min[i])
696
                                                                min[i] = value;
697
                                                }
698
                                                if (task.getEvent() != null)
699
                                                        task.manageEvent(task.getEvent());
700
                                        }
701
                                }
702
                                break;
703
                }
704
                double[][] values = new double[2][getBandCount()];
705

    
706
                for (int i = 0; i < getBandCount(); i++) {
707
                        values[0][i] = min[i];
708
                        values[1][i] = max[i];
709
                }
710
                return values;
711
        }
712

    
713
        /*
714
         * (non-Javadoc)
715
         * @see org.gvsig.fmap.dal.coverage.store.props.Histogramable#getHistogramComputer()
716
         */
717
        public HistogramComputer getHistogramComputer() {
718
                if(histogramComputer == null)
719
                        histogramComputer = new BufferHistogramComputer(this);
720
                return histogramComputer;
721
        }
722

    
723
        /*
724
         * (non-Javadoc)
725
         * @see org.gvsig.raster.dataset.Buffer#isInside(int, int)
726
         */
727
        public boolean isInside(int x, int y) {
728
                 if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight())
729
                                return false;
730
                        return true;
731
        }
732
        
733
        /*
734
         * (non-Javadoc)
735
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#isReadOnlyBuffer()
736
         */
737
        public boolean isReadOnlyBuffer() {
738
                return false;
739
        }
740
        
741
        /*
742
         * (non-Javadoc)
743
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#isCached()
744
         */
745
        public boolean isCached() {
746
                return false;
747
        }
748
        
749
        /*
750
         * (non-Javadoc)
751
         * @see org.gvsig.fmap.dal.coverage.dataset.Buffer#getIncrementableTask()
752
         */
753
        public IncrementableTask getIncrementableTask(int type) {
754
                switch (type) {
755
                case INCREMENTABLE_INTERPOLATION:
756
                        return getBufferInterpolation();
757
                case INCREMENTABLE_HISTOGRAM:
758
                        return getHistogramComputer();
759
                }
760
                return null;
761
        }
762
        
763
        /**
764
         * Gets the buffer interpolation
765
         * @return
766
         */
767
        private BufferInterpolation getBufferInterpolation() {
768
                if(interp == null)
769
                        interp = new BufferInterpolation(this);
770
                return interp;
771
        }
772
        
773
        /*
774
         * (non-Javadoc)
775
         * @see org.gvsig.fmap.dal.coverage.buffer.Buffer#getAdjustedWindow(int, int, int)
776
         */
777
        public Buffer getAdjustedWindow(int w, int h, int interpolationMethod) throws ProcessInterruptedException {
778
                getBufferInterpolation();
779
                if (w == getWidth() && h == getHeight())
780
                        return this;
781
                Buffer rasterBuf = null;
782
                switch (interpolationMethod) {
783
                        case Buffer.INTERPOLATION_NearestNeighbour:
784
                                rasterBuf = interp.adjustRasterNearestNeighbourInterpolation(w, h);
785
                                break;
786
                        case Buffer.INTERPOLATION_Bilinear:
787
                                rasterBuf = interp.adjustRasterBilinearInterpolation(w, h);
788
                                break;
789
                        case Buffer.INTERPOLATION_InverseDistance:
790
                                rasterBuf = interp.adjustRasterInverseDistanceInterpolation(w, h);
791
                                break;
792
                        case Buffer.INTERPOLATION_BicubicSpline:
793
                                rasterBuf = interp.adjustRasterBicubicSplineInterpolation(w, h);
794
                                break;
795
                        case Buffer.INTERPOLATION_BSpline:
796
                                rasterBuf = interp.adjustRasterBSplineInterpolation(w, h);
797
                                break;
798
                }
799
                if (rasterBuf != null)
800
                        return rasterBuf;
801
                else
802
                        return this;
803
        }
804

    
805
        public Rectangle2D getDataExtent() {
806
                // TODO Auto-generated method stub
807
                return null;
808
        }
809

    
810
        public void setDataExtent(Rectangle2D r) {
811
                // TODO Auto-generated method stub
812
        }
813
        
814
        public RasterDataStore getStore() {
815
                return null;
816
        }
817

    
818
        public void setStore(RasterDataStore store) {
819
        }
820
        
821
        public void addDrawableBands(int[] db) {}
822
        
823
        //****************************************************
824
        //*********Implementing DataSet methods***************
825
        //****************************************************
826

    
827
        /*
828
         * (non-Javadoc)
829
         * @see org.gvsig.fmap.dal.DataSet#isFromStore(org.gvsig.fmap.dal.DataStore)
830
         */
831
        public boolean isFromStore(DataStore store) {
832
                // TODO Auto-generated method stub
833
                return false;
834
        }
835

    
836
        //****************************************************
837
        //*********Implementing Visitable methods*************
838
        //****************************************************
839
        
840
        /*
841
         * (non-Javadoc)
842
         * @see org.gvsig.tools.visitor.Visitable#accept(org.gvsig.tools.visitor.Visitor)
843
         */
844
        public void accept(Visitor visitor) throws BaseException {
845
                // TODO Auto-generated method stub
846
                
847
        }
848
        
849
        //****************************************************
850
        //*********Implementing Disposable methods************
851
        //****************************************************
852
        
853
        /*
854
         * (non-Javadoc)
855
         * @see org.gvsig.tools.dispose.Disposable#dispose()
856
         */
857
        public void dispose() {
858
                if(pageBandBuffer != null) {
859
                        for (int i = 0; i < pageBandBuffer.length; i++) { 
860
                                pageBandBuffer[i].dispose();
861
                        }
862
                }
863
                try {
864
                        finalize();
865
                } catch (Throwable e) {
866
                }
867
        }
868
        
869
        /*
870
         * (non-Javadoc)
871
         * @see java.lang.Object#finalize()
872
         */
873
        protected void finalize() throws Throwable {
874
                limits               = null;
875
                histogramComputer    = null;
876
                if(pageBandBuffer != null) {
877
                        for (int i = 0; i < pageBandBuffer.length; i++) { 
878
                                pageBandBuffer[i] = null;
879
                        }
880
                        pageBandBuffer = null;
881
                }
882
                limits = null;
883
                super.finalize();
884
        }
885
}