Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / buffer / cache / RasterReadOnlyHugeBuffer.java @ 11081

History | View | Annotate | Download (17.6 KB)

1 11074 nacho
package org.gvsig.raster.buffer.cache;
2
3
import java.io.FileNotFoundException;
4
5
import org.gvsig.raster.buffer.IBand;
6
import org.gvsig.raster.buffer.RasterBuffer;
7
import org.gvsig.raster.buffer.RasterMemoryBuffer;
8
import org.gvsig.raster.dataset.IBuffer;
9
import org.gvsig.raster.dataset.NotSupportedExtensionException;
10
import org.gvsig.raster.dataset.RasterDriverException;
11
import org.gvsig.raster.util.DataClassList;
12
import org.gvsig.raster.util.Histogram;
13
import org.gvsig.raster.util.HistogramException;
14
15
/**
16
 *
17
 * @author Nacho Brodin (nachobrodin@gmail.com)
18
 *
19
 */
20
public class RasterReadOnlyHugeBuffer extends RasterBuffer implements IBuffer {
21
        private Cache                         cache = null;
22
        private LRUAlgorithm          lru = null;
23
24
    /**
25
     * Constructor. Asigna las variables de inicializaci?n y crea la estructura de
26
     * la cach? con los datos pasados.
27
     * @param dataType Tipo de dato
28
     * @param width Ancho
29
     * @param height Alto
30
     * @param bandNr Banda
31
     * @param orig
32
     * @throws RasterDriverException
33
     * @throws NotSupportedExtensionException
34
     * @throws FileNotFoundException
35
     */
36
        public RasterReadOnlyHugeBuffer(int dataType, int width, int height, int nBand, String fileName)
37
                throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException{
38
                cache = new Cache(nBand, dataType, width, height, fileName);
39
                lru = new LRUAlgorithm(cache);
40
41
            this.dataType = dataType;
42
        this.width = width;
43
        this.height = height;
44
        this.nBands = nBand;
45
        }
46
47
        public void malloc(int dataType, int width, int height, int bandNr) {
48
        }
49
50
        /*
51
     * (non-Javadoc)
52
     * @see org.gvsig.raster.driver.IBuffer#isBandSwitchable()
53
     */
54
    public boolean isBandSwitchable(){
55
            return false;
56
    }
57
58
        /**
59
         * Obtiene la cach?
60
         * @return
61
         */
62
        public Cache getCache() {
63
                return cache;
64
        }
65
        //*********************************************************
66
67
        public byte[][] getLineByte(int line) {
68
                try {
69
                        lru.cacheAccess(line, true);
70
                } catch (InvalidPageNumberException e) {return null;}
71
                return cache.getAccessPage().getLineByte((line & cache.getOffset()));
72
        }
73
74
        public short[][] getLineShort(int line) {
75
                try {
76
                        lru.cacheAccess(line, true);
77
                } catch (InvalidPageNumberException e) {return null;}
78
                return cache.getAccessPage().getLineShort((line & cache.getOffset()));
79
        }
80
81
        public int[][] getLineInt(int line) {
82
                try {
83
                        lru.cacheAccess(line, true);
84
                } catch (InvalidPageNumberException e) {return null;}
85
                return cache.getAccessPage().getLineInt((line & cache.getOffset()));
86
        }
87
88
        public float[][] getLineFloat(int line) {
89
                try {
90
                        lru.cacheAccess(line, true);
91
                } catch (InvalidPageNumberException e) {return null;}
92
                return cache.getAccessPage().getLineFloat((line & cache.getOffset()));
93
        }
94
95
        public double[][] getLineDouble(int line) {
96
                try {
97
                        lru.cacheAccess(line, true);
98
                } catch (InvalidPageNumberException e) {return null;}
99
                return cache.getAccessPage().getLineDouble((line & cache.getOffset()));
100
        }
101
102
        //*********************************************************
103
104
        public void setLineByte(byte[][] data, int line) {
105
                try {
106
                        lru.cacheAccess(line, false);
107
                } catch (InvalidPageNumberException e) {return;}
108
                cache.getAccessPage().setLineByte(data, (line & cache.getOffset()));
109
        }
110
111
        public void setLineShort(short[][] data, int line) {
112
                try {
113
                        lru.cacheAccess(line, false);
114
                } catch (InvalidPageNumberException e) {return;}
115
                cache.getAccessPage().setLineShort(data, (line & cache.getOffset()));
116
        }
117
118
        public void setLineInt(int[][] data, int line) {
119
                try {
120
                        lru.cacheAccess(line, false);
121
                } catch (InvalidPageNumberException e) {return;}
122
                cache.getAccessPage().setLineInt(data, (line & cache.getOffset()));
123
        }
124
125
        public void setLineFloat(float[][] data, int line) {
126
                try {
127
                        lru.cacheAccess(line, false);
128
                } catch (InvalidPageNumberException e) {return;}
129
                cache.getAccessPage().setLineFloat(data, (line & cache.getOffset()));
130
        }
131
132
        public void setLineDouble(double[][] data, int line) {
133
                try {
134
                        lru.cacheAccess(line, false);
135
                } catch (InvalidPageNumberException e) {return;}
136
                cache.getAccessPage().setLineDouble(data, (line & cache.getOffset()));
137
        }
138
139
        //*********************************************************
140
141
        public byte[] getLineFromBandByte(int line, int band) {
142
                try {
143
                        lru.cacheAccess(line, true);
144
                } catch (InvalidPageNumberException e) {return null;}
145
                return cache.getAccessPage().getLineFromBandByte((line & cache.getOffset()), band);
146
        }
147
148
        public short[] getLineFromBandShort(int line, int band) {
149
                try {
150
                        lru.cacheAccess(line, true);
151
                } catch (InvalidPageNumberException e) {return null;}
152
                return cache.getAccessPage().getLineFromBandShort((line & cache.getOffset()), band);
153
        }
154
155
        public int[] getLineFromBandInt(int line, int band) {
156
                try {
157
                        lru.cacheAccess(line, true);
158
                } catch (InvalidPageNumberException e) {return null;}
159
                return cache.getAccessPage().getLineFromBandInt((line & cache.getOffset()), band);
160
        }
161
162
        public float[] getLineFromBandFloat(int line, int band) {
163
                try {
164
                        lru.cacheAccess(line, true);
165
                } catch (InvalidPageNumberException e) {return null;}
166
                return cache.getAccessPage().getLineFromBandFloat((line & cache.getOffset()), band);
167
        }
168
169
        public double[] getLineFromBandDouble(int line, int band) {
170
                try {
171
                        lru.cacheAccess(line, true);
172
                } catch (InvalidPageNumberException e) {return null;}
173
                return cache.getAccessPage().getLineFromBandDouble((line & cache.getOffset()), band);
174
        }
175
176
        //*********************************************************
177
178
        public void setLineInBandByte(byte[] data, int line, int band) {
179
                try {
180
                        lru.cacheAccess(line, false);
181
                } catch (InvalidPageNumberException e) {return;}
182
                cache.getAccessPage().setLineInBandByte(data, (line & cache.getOffset()), band);
183
        }
184
185
        public void setLineInBandShort(short[] data, int line, int band) {
186
                try {
187
                        lru.cacheAccess(line, false);
188
                } catch (InvalidPageNumberException e) {return;}
189
                cache.getAccessPage().setLineInBandShort(data, (line & cache.getOffset()), band);
190
        }
191
192
        public void setLineInBandInt(int[] data, int line, int band) {
193
                try {
194
                        lru.cacheAccess(line, false);
195
                } catch (InvalidPageNumberException e) {return;}
196
                cache.getAccessPage().setLineInBandInt(data, (line & cache.getOffset()), band);
197
        }
198
199
        public void setLineInBandFloat(float[] data, int line, int band) {
200
                try {
201
                        lru.cacheAccess(line, false);
202
                } catch (InvalidPageNumberException e) {return;}
203
                cache.getAccessPage().setLineInBandFloat(data, (line & cache.getOffset()), band);
204
        }
205
206
        public void setLineInBandDouble(double[] data, int line, int band) {
207
                try {
208
                        lru.cacheAccess(line, false);
209
                } catch (InvalidPageNumberException e) {return;}
210
                cache.getAccessPage().setLineInBandDouble(data, (line & cache.getOffset()), band);
211
        }
212
213
        //*********************************************************
214
215
        public byte getElemByte(int line, int col, int band) {
216
                try {
217
                        lru.cacheAccess(line, true);
218
                } catch (InvalidPageNumberException e) {
219
                        return (byte)getNoDataValue(); //No leemos el dato
220
                }
221
                return cache.getAccessPage().getElemByte((line & cache.getOffset()), col, band);
222
        }
223
224
        public short getElemShort(int line, int col, int band) {
225
                try {
226
                        lru.cacheAccess(line, true);
227
                } catch (InvalidPageNumberException e) {
228
                        return (short)getNoDataValue(); //No leemos el dato
229
                }
230
                return cache.getAccessPage().getElemShort((line & cache.getOffset()), col, band);
231
        }
232
233
        public int getElemInt(int line, int col, int band) {
234
                try {
235
                        lru.cacheAccess(line, true);
236
                } catch (InvalidPageNumberException e) {
237
                        return (int)getNoDataValue(); //No leemos el dato
238
                }
239
                return cache.getAccessPage().getElemInt((line & cache.getOffset()), col, band);
240
        }
241
242
        public float getElemFloat(int line, int col, int band) {
243
                try {
244
                        lru.cacheAccess(line, true);
245
                } catch (InvalidPageNumberException e) {
246
                        return (float)getNoDataValue(); //No leemos el dato
247
                }
248
                return cache.getAccessPage().getElemFloat((line & cache.getOffset()), col, band);
249
        }
250
251
        public double getElemDouble(int line, int col, int band) {
252
                try {
253
                        lru.cacheAccess(line, true);
254
                } catch (InvalidPageNumberException e) {
255
                        return (double)getNoDataValue(); //No leemos el dato
256
                }
257
                return cache.getAccessPage().getElemDouble((line & cache.getOffset()), col, band);
258
        }
259
260
        //*********************************************************
261
262
        public void setElem(int line, int col, int band, byte data) {
263
                try {
264
                        lru.cacheAccess(line, false);
265
                } catch (InvalidPageNumberException e) { return;}
266
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
267
        }
268
269
        public void setElem(int line, int col, int band, short data) {
270
                try {
271
                        lru.cacheAccess(line, false);
272
                } catch (InvalidPageNumberException e) {return;}
273
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
274
        }
275
276
        public void setElem(int line, int col, int band, int data) {
277
                try {
278
                        lru.cacheAccess(line, false);
279
                } catch (InvalidPageNumberException e) {return;}
280
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
281
        }
282
283
        public void setElem(int line, int col, int band, float data) {
284
                try {
285
                        lru.cacheAccess(line, false);
286
                } catch (InvalidPageNumberException e) {return;}
287
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
288
        }
289
290
        public void setElem(int line, int col, int band, double data) {
291
                try {
292
                        lru.cacheAccess(line, false);
293
                } catch (InvalidPageNumberException e) {return;}
294
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
295
        }
296
297
        //*********************************************************
298
299
        public void getElemByte(int line, int col, byte[] data) {
300
                try {
301
                        lru.cacheAccess(line, true);
302
                } catch (InvalidPageNumberException e) {
303
                        for (int iBand = 0; iBand < data.length; iBand++)
304
                    data[iBand] = (byte)getNoDataValue();
305
                }
306
                cache.getAccessPage().getElemByte((line & cache.getOffset()), col, data);
307
        }
308
309
        public void getElemShort(int line, int col, short[] data) {
310
                try {
311
                        lru.cacheAccess(line, true);
312
                } catch (InvalidPageNumberException e) {
313
                        for (int iBand = 0; iBand < data.length; iBand++)
314
                    data[iBand] = (short)getNoDataValue();
315
                }
316
                cache.getAccessPage().getElemShort((line & cache.getOffset()), col, data);
317
        }
318
319
        public void getElemInt(int line, int col, int[] data) {
320
                try {
321
                        lru.cacheAccess(line, true);
322
                } catch (InvalidPageNumberException e) {
323
                        for (int iBand = 0; iBand < data.length; iBand++)
324
                    data[iBand] = (int)getNoDataValue();
325
                }
326
                cache.getAccessPage().getElemInt((line & cache.getOffset()), col, data);
327
        }
328
329
        public void getElemFloat(int line, int col, float[] data) {
330
                try {
331
                        lru.cacheAccess(line, true);
332
                } catch (InvalidPageNumberException e) {
333
                        for (int iBand = 0; iBand < data.length; iBand++)
334
                    data[iBand] = (float)getNoDataValue();
335
                }
336
                cache.getAccessPage().getElemFloat((line & cache.getOffset()), col, data);
337
        }
338
339
        public void getElemDouble(int line, int col, double[] data) {
340
                try {
341
                        lru.cacheAccess(line, true);
342
                } catch (InvalidPageNumberException e) {
343
                        for (int iBand = 0; iBand < data.length; iBand++)
344
                    data[iBand] = (double)getNoDataValue();
345
                }
346
                cache.getAccessPage().getElemDouble((line & cache.getOffset()), col, data);
347
        }
348
349
        //*********************************************************
350
351
        public void setElemByte(int line, int col, byte[] data) {
352
                try {
353
                        lru.cacheAccess(line, false);
354
                } catch (InvalidPageNumberException e) {return;}
355
                cache.getAccessPage().setElemByte((line & cache.getOffset()), col, data);
356
        }
357
358
        public void setElemShort(int line, int col, short[] data) {
359
                try {
360
                        lru.cacheAccess(line, false);
361
                } catch (InvalidPageNumberException e) {return;}
362
                cache.getAccessPage().setElemShort((line & cache.getOffset()), col, data);
363
        }
364
365
        public void setElemInt(int line, int col, int[] data) {
366
                try {
367
                        lru.cacheAccess(line, false);
368
                } catch (InvalidPageNumberException e) {return;}
369
                cache.getAccessPage().setElemInt((line & cache.getOffset()), col, data);
370
        }
371
372
        public void setElemFloat(int line, int col, float[] data) {
373
                try {
374
                        lru.cacheAccess(line, false);
375
                } catch (InvalidPageNumberException e) {return;}
376
                cache.getAccessPage().setElemFloat((line & cache.getOffset()), col, data);
377
        }
378
379
        public void setElemDouble(int line, int col, double[] data) {
380
                try {
381
                        lru.cacheAccess(line, false);
382
                } catch (InvalidPageNumberException e) {return;}
383
                cache.getAccessPage().setElemDouble((line & cache.getOffset()), col, data);
384
        }
385
386
        //TODO: FUNCIONALIDAD: Terminar m?todos de RasterCach?
387
388
        //***********************************************
389
    //Obtiene una banda entera
390
391
    public IBand getBand(int band){
392
            return null;
393
    }
394
395
    /*
396
     *  (non-Javadoc)
397
     * @see org.gvsig.fmap.driver.IBuffer#getBandBuffer(int)
398
     */
399
    public IBuffer getBandBuffer(int iBand){
400
            return null;
401
    }
402
403
    /*
404
     *  (non-Javadoc)
405
     * @see org.gvsig.fmap.driver.IBuffer#replicateBand(int, int)
406
     */
407
        public void replicateBand(int orig, int dest) {
408
        }
409
410
        /*
411
     *  (non-Javadoc)
412
     * @see org.gvsig.fmap.dataaccess.buffer.RasterBuffer#switchBands(int[])
413
     */
414
    public void switchBands(int[] bandPosition){
415
416
    }
417
418
        //*********************************************************
419
420
        public RasterBuffer adjustRasterNearestNeighbourInterpolation(int w, int h, int[] bands) {
421
                return null;
422
        }
423
424
        public RasterBuffer adjustRasterBilinearInterpolation(int w, int h, int[] bands) {
425
                return null;
426
        }
427
428
        public RasterBuffer adjustRasterInverseDistanceInterpolation(int w, int h, int[] bands) {
429
                return null;
430
        }
431
432
        public RasterBuffer adjustRasterBicubicSplineInterpolation(int w, int h, int[] bands) {
433
                return null;
434
        }
435
436
        public RasterBuffer adjustRasterBSplineInterpolation(int w, int h, int[] bands) {
437
                return null;
438
        }
439
440
        //*********************************************************
441
442
        public void assign(int band, byte value) {
443
                for(int line = 0; line < height; line ++){
444
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
445
                    for(int col = 0; col < width; col ++){
446
                            try {
447
                                    if(beginLine){
448
                                            lru.cacheAccess(line, false);
449
                                            beginLine = false;
450
                                    }
451
                            } catch (InvalidPageNumberException e) {return;}
452
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);
453
                    }
454
                }
455
        }
456
457
        public void assign(int band, short value) {
458
                for(int line = 0; line < height; line ++){
459
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
460
                    for(int col = 0; col < width; col ++){
461
                            try {
462
                                    if(beginLine){
463
                                            lru.cacheAccess(line, false);
464
                                            beginLine = false;
465
                                    }
466
                            } catch (InvalidPageNumberException e) {return;}
467
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);
468
                    }
469
                }
470
        }
471
472
        public void assign(int band, int value) {
473
                for(int line = 0; line < height; line ++){
474
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
475
                    for(int col = 0; col < width; col ++){
476
                            try {
477
                                    if(beginLine){
478
                                            lru.cacheAccess(line, false);
479
                                            beginLine = false;
480
                                    }
481
                            } catch (InvalidPageNumberException e) {return;}
482
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);
483
                    }
484
                }
485
        }
486
487
        public void assign(int band, float value) {
488
                for(int line = 0; line < height; line ++){
489
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
490
                    for(int col = 0; col < width; col ++){
491
                            try {
492
                                    if(beginLine){
493
                                            lru.cacheAccess(line, false);
494
                                            beginLine = false;
495
                                    }
496
                            } catch (InvalidPageNumberException e) {return;}
497
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);
498
                    }
499
                }
500
        }
501
502
        public void assign(int band, double value) {
503
                for(int line = 0; line < height; line ++){
504
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
505
                    for(int col = 0; col < width; col ++){
506
                            try {
507
                                    if(beginLine){
508
                                            lru.cacheAccess(line, false);
509
                                            beginLine = false;
510
                                    }
511
                            } catch (InvalidPageNumberException e) {return;}
512
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);
513
                    }
514
                }
515
        }
516
517
    /*
518
     *  (non-Javadoc)
519
     * @see org.gvsig.fmap.driver.IBuffer#cloneBuffer()
520
     */
521
    public IBuffer cloneBuffer(){
522
            return null;
523
    }
524
525
    /*
526
     * (non-Javadoc)
527
     * @see org.gvsig.fmap.driver.IBuffer#interchangeBands(int, int)
528
     */
529
        public void interchangeBands(int band1, int band2) {
530
        }
531
532
    /*
533
     * (non-Javadoc)
534
     * @see org.gvsig.fmap.driver.IBuffer#interchangeBands(int[])
535
     */
536
    public void interchangeBands(int[] bands){
537
538
    }
539
540
    /*
541
     *  (non-Javadoc)
542
     * @see org.gvsig.fmap.driver.IBuffer#mallocOneBand(int, int, int, int)
543
     */
544
    public void mallocOneBand(int dataType, int width, int height, int band) {
545
546
        }
547
548
    /*
549
     *  (non-Javadoc)
550
     * @see org.gvsig.fmap.driver.IBuffer#copyBand(int, org.gvsig.fmap.dataaccess.buffer.IBand)
551
     */
552
        public void copyBand(int nBand, IBand band) {
553
554
        }
555
556
        /*
557
         *  (non-Javadoc)
558
         * @see org.gvsig.fmap.driver.IBuffer#assignBand(int, org.gvsig.fmap.dataaccess.buffer.IBand)
559
         */
560
        public void assignBand(int nBand, IBand band) {
561
562
        }
563
564
        /*
565
         *  (non-Javadoc)
566
         * @see org.gvsig.fmap.driver.IBuffer#createBand(byte)
567
         */
568
        public IBand createBand(byte defaultValue) {
569
570
                return null;
571
        }
572
573
        /*
574
         *  (non-Javadoc)
575
         * @see org.gvsig.fmap.driver.IBuffer#assignBandToNotValid(int)
576
         */
577
        public void assignBandToNotValid(int iBand) {
578
579
        }
580
581
        public int getPercent() {
582
                return super.percent;
583
        }
584
585 11081 nacho
        public void resetPercent() {
586
        }
587
588
        public boolean isCanceled() {
589
                return false;
590
        }
591
592
        public void setCanceled(boolean value) {
593
        }
594
595 11074 nacho
}