Statistics
| Revision:

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

History | View | Annotate | Download (17.2 KB)

1
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.dataset.IBuffer;
8
import org.gvsig.raster.dataset.NotSupportedExtensionException;
9
import org.gvsig.raster.dataset.RasterDriverException;
10

    
11
/**
12
 * 
13
 * @author Nacho Brodin (nachobrodin@gmail.com)
14
 *
15
 */
16
public class RasterReadOnlyHugeBuffer extends RasterBuffer {
17
        private Cache                         cache = null;
18
        private LRUAlgorithm          lru = null; 
19
         
20
    /**
21
     * Constructor. Asigna las variables de inicializaci?n y crea la estructura de 
22
     * la cach? con los datos pasados.
23
     * @param dataType Tipo de dato
24
     * @param width Ancho
25
     * @param height Alto
26
     * @param bandNr Banda
27
     * @param orig
28
     * @throws RasterDriverException 
29
     * @throws NotSupportedExtensionException 
30
     * @throws FileNotFoundException 
31
     */
32
        public RasterReadOnlyHugeBuffer(int dataType, int width, int height, int nBand, String fileName) 
33
                throws FileNotFoundException, NotSupportedExtensionException, RasterDriverException{
34
                cache = new Cache(nBand, dataType, width, height, fileName);
35
                lru = new LRUAlgorithm(cache);
36
                
37
            this.dataType = dataType;
38
        this.width = width;
39
        this.height = height;
40
        this.nBands = nBand;
41
        }
42
                        
43
        public void malloc(int dataType, int width, int height, int bandNr) {
44
        }
45

    
46
        /*
47
     * (non-Javadoc)
48
     * @see org.gvsig.raster.driver.IBuffer#isBandSwitchable()
49
     */
50
    public boolean isBandSwitchable(){
51
            return false;
52
    }
53
    
54
        /**
55
         * Obtiene la cach?
56
         * @return
57
         */
58
        public Cache getCache() {
59
                return cache;
60
        }
61
        //*********************************************************
62
        
63
        public byte[][] getLineByte(int line) {
64
                try {
65
                        lru.cacheAccess(line, true);
66
                } catch (InvalidPageNumberException e) {return null;}
67
                return cache.getAccessPage().getLineByte((line & cache.getOffset()));
68
        }
69

    
70
        public short[][] getLineShort(int line) {
71
                try {
72
                        lru.cacheAccess(line, true);
73
                } catch (InvalidPageNumberException e) {return null;}
74
                return cache.getAccessPage().getLineShort((line & cache.getOffset()));
75
        }
76

    
77
        public int[][] getLineInt(int line) {
78
                try {
79
                        lru.cacheAccess(line, true);
80
                } catch (InvalidPageNumberException e) {return null;}
81
                return cache.getAccessPage().getLineInt((line & cache.getOffset()));
82
        }
83

    
84
        public float[][] getLineFloat(int line) {
85
                try {
86
                        lru.cacheAccess(line, true);
87
                } catch (InvalidPageNumberException e) {return null;}
88
                return cache.getAccessPage().getLineFloat((line & cache.getOffset()));
89
        }
90

    
91
        public double[][] getLineDouble(int line) {
92
                try {
93
                        lru.cacheAccess(line, true);
94
                } catch (InvalidPageNumberException e) {return null;}
95
                return cache.getAccessPage().getLineDouble((line & cache.getOffset()));
96
        }
97

    
98
        //*********************************************************
99
        
100
        public void setLineByte(byte[][] data, int line) {
101
                try {
102
                        lru.cacheAccess(line, false);
103
                } catch (InvalidPageNumberException e) {return;}
104
                cache.getAccessPage().setLineByte(data, (line & cache.getOffset()));
105
        }
106

    
107
        public void setLineShort(short[][] data, int line) {
108
                try {
109
                        lru.cacheAccess(line, false);
110
                } catch (InvalidPageNumberException e) {return;}
111
                cache.getAccessPage().setLineShort(data, (line & cache.getOffset()));
112
        }
113

    
114
        public void setLineInt(int[][] data, int line) {
115
                try {
116
                        lru.cacheAccess(line, false);
117
                } catch (InvalidPageNumberException e) {return;}
118
                cache.getAccessPage().setLineInt(data, (line & cache.getOffset()));
119
        }
120

    
121
        public void setLineFloat(float[][] data, int line) {
122
                try {
123
                        lru.cacheAccess(line, false);
124
                } catch (InvalidPageNumberException e) {return;}
125
                cache.getAccessPage().setLineFloat(data, (line & cache.getOffset()));
126
        }
127

    
128
        public void setLineDouble(double[][] data, int line) {
129
                try {
130
                        lru.cacheAccess(line, false);
131
                } catch (InvalidPageNumberException e) {return;}
132
                cache.getAccessPage().setLineDouble(data, (line & cache.getOffset()));
133
        }
134

    
135
        //*********************************************************
136
        
137
        public byte[] getLineFromBandByte(int line, int band) {
138
                try {
139
                        lru.cacheAccess(line, true);
140
                } catch (InvalidPageNumberException e) {return null;}
141
                return cache.getAccessPage().getLineFromBandByte((line & cache.getOffset()), band);
142
        }
143

    
144
        public short[] getLineFromBandShort(int line, int band) {
145
                try {
146
                        lru.cacheAccess(line, true);
147
                } catch (InvalidPageNumberException e) {return null;}
148
                return cache.getAccessPage().getLineFromBandShort((line & cache.getOffset()), band);
149
        }
150

    
151
        public int[] getLineFromBandInt(int line, int band) {
152
                try {
153
                        lru.cacheAccess(line, true);
154
                } catch (InvalidPageNumberException e) {return null;}
155
                return cache.getAccessPage().getLineFromBandInt((line & cache.getOffset()), band);
156
        }
157

    
158
        public float[] getLineFromBandFloat(int line, int band) {
159
                try {
160
                        lru.cacheAccess(line, true);
161
                } catch (InvalidPageNumberException e) {return null;}
162
                return cache.getAccessPage().getLineFromBandFloat((line & cache.getOffset()), band);
163
        }
164

    
165
        public double[] getLineFromBandDouble(int line, int band) {
166
                try {
167
                        lru.cacheAccess(line, true);
168
                } catch (InvalidPageNumberException e) {return null;}
169
                return cache.getAccessPage().getLineFromBandDouble((line & cache.getOffset()), band);
170
        }
171

    
172
        //*********************************************************
173
        
174
        public void setLineInBandByte(byte[] data, int line, int band) {
175
                try {
176
                        lru.cacheAccess(line, false);
177
                } catch (InvalidPageNumberException e) {return;}
178
                cache.getAccessPage().setLineInBandByte(data, (line & cache.getOffset()), band);
179
        }
180

    
181
        public void setLineInBandShort(short[] data, int line, int band) {
182
                try {
183
                        lru.cacheAccess(line, false);
184
                } catch (InvalidPageNumberException e) {return;}
185
                cache.getAccessPage().setLineInBandShort(data, (line & cache.getOffset()), band);
186
        }
187

    
188
        public void setLineInBandInt(int[] data, int line, int band) {
189
                try {
190
                        lru.cacheAccess(line, false);
191
                } catch (InvalidPageNumberException e) {return;}
192
                cache.getAccessPage().setLineInBandInt(data, (line & cache.getOffset()), band);
193
        }
194

    
195
        public void setLineInBandFloat(float[] data, int line, int band) {
196
                try {
197
                        lru.cacheAccess(line, false);
198
                } catch (InvalidPageNumberException e) {return;}
199
                cache.getAccessPage().setLineInBandFloat(data, (line & cache.getOffset()), band);
200
        }
201

    
202
        public void setLineInBandDouble(double[] data, int line, int band) {
203
                try {
204
                        lru.cacheAccess(line, false);
205
                } catch (InvalidPageNumberException e) {return;}
206
                cache.getAccessPage().setLineInBandDouble(data, (line & cache.getOffset()), band);
207
        }
208

    
209
        //*********************************************************
210
        
211
        public byte getElemByte(int line, int col, int band) {
212
                try {
213
                        lru.cacheAccess(line, true);
214
                } catch (InvalidPageNumberException e) {
215
                        return (byte)getNoDataValue(); //No leemos el dato
216
                }
217
                return cache.getAccessPage().getElemByte((line & cache.getOffset()), col, band);
218
        }
219

    
220
        public short getElemShort(int line, int col, int band) {
221
                try {
222
                        lru.cacheAccess(line, true);
223
                } catch (InvalidPageNumberException e) {
224
                        return (short)getNoDataValue(); //No leemos el dato
225
                }
226
                return cache.getAccessPage().getElemShort((line & cache.getOffset()), col, band);
227
        }
228

    
229
        public int getElemInt(int line, int col, int band) {
230
                try {
231
                        lru.cacheAccess(line, true);
232
                } catch (InvalidPageNumberException e) {
233
                        return (int)getNoDataValue(); //No leemos el dato
234
                }
235
                return cache.getAccessPage().getElemInt((line & cache.getOffset()), col, band);
236
        }
237

    
238
        public float getElemFloat(int line, int col, int band) {
239
                try {
240
                        lru.cacheAccess(line, true);
241
                } catch (InvalidPageNumberException e) {
242
                        return (float)getNoDataValue(); //No leemos el dato
243
                }
244
                return cache.getAccessPage().getElemFloat((line & cache.getOffset()), col, band);
245
        }
246

    
247
        public double getElemDouble(int line, int col, int band) {
248
                try {
249
                        lru.cacheAccess(line, true);
250
                } catch (InvalidPageNumberException e) {
251
                        return (double)getNoDataValue(); //No leemos el dato
252
                }
253
                return cache.getAccessPage().getElemDouble((line & cache.getOffset()), col, band);
254
        }
255

    
256
        //*********************************************************
257
        
258
        public void setElem(int line, int col, int band, byte data) {
259
                try {
260
                        lru.cacheAccess(line, false);
261
                } catch (InvalidPageNumberException e) { return;}
262
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
263
        }
264

    
265
        public void setElem(int line, int col, int band, short data) {
266
                try {
267
                        lru.cacheAccess(line, false);
268
                } catch (InvalidPageNumberException e) {return;}
269
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
270
        }
271

    
272
        public void setElem(int line, int col, int band, int data) {
273
                try {
274
                        lru.cacheAccess(line, false);
275
                } catch (InvalidPageNumberException e) {return;}
276
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
277
        }
278

    
279
        public void setElem(int line, int col, int band, float data) {
280
                try {
281
                        lru.cacheAccess(line, false);
282
                } catch (InvalidPageNumberException e) {return;}
283
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
284
        }
285

    
286
        public void setElem(int line, int col, int band, double data) {
287
                try {
288
                        lru.cacheAccess(line, false);
289
                } catch (InvalidPageNumberException e) {return;}
290
                cache.getAccessPage().setElem((line & cache.getOffset()), col, band, data);
291
        }
292
        
293
        //*********************************************************
294

    
295
        public void getElemByte(int line, int col, byte[] data) {
296
                try {
297
                        lru.cacheAccess(line, true);
298
                } catch (InvalidPageNumberException e) {
299
                        for (int iBand = 0; iBand < data.length; iBand++)
300
                    data[iBand] = (byte)getNoDataValue();
301
                }
302
                cache.getAccessPage().getElemByte((line & cache.getOffset()), col, data);
303
        }
304

    
305
        public void getElemShort(int line, int col, short[] data) {
306
                try {
307
                        lru.cacheAccess(line, true);
308
                } catch (InvalidPageNumberException e) {
309
                        for (int iBand = 0; iBand < data.length; iBand++)
310
                    data[iBand] = (short)getNoDataValue();
311
                }
312
                cache.getAccessPage().getElemShort((line & cache.getOffset()), col, data);
313
        }
314

    
315
        public void getElemInt(int line, int col, int[] data) {
316
                try {
317
                        lru.cacheAccess(line, true);
318
                } catch (InvalidPageNumberException e) {
319
                        for (int iBand = 0; iBand < data.length; iBand++)
320
                    data[iBand] = (int)getNoDataValue();
321
                }
322
                cache.getAccessPage().getElemInt((line & cache.getOffset()), col, data);
323
        }
324

    
325
        public void getElemFloat(int line, int col, float[] data) {
326
                try {
327
                        lru.cacheAccess(line, true);
328
                } catch (InvalidPageNumberException e) {
329
                        for (int iBand = 0; iBand < data.length; iBand++)
330
                    data[iBand] = (float)getNoDataValue();
331
                }
332
                cache.getAccessPage().getElemFloat((line & cache.getOffset()), col, data);
333
        }
334

    
335
        public void getElemDouble(int line, int col, double[] data) {
336
                try {
337
                        lru.cacheAccess(line, true);
338
                } catch (InvalidPageNumberException e) {
339
                        for (int iBand = 0; iBand < data.length; iBand++)
340
                    data[iBand] = (double)getNoDataValue();
341
                }
342
                cache.getAccessPage().getElemDouble((line & cache.getOffset()), col, data);
343
        }
344
        
345
        //*********************************************************
346
        
347
        public void setElemByte(int line, int col, byte[] data) {
348
                try {
349
                        lru.cacheAccess(line, false);
350
                } catch (InvalidPageNumberException e) {return;}
351
                cache.getAccessPage().setElemByte((line & cache.getOffset()), col, data);
352
        }
353

    
354
        public void setElemShort(int line, int col, short[] data) {
355
                try {
356
                        lru.cacheAccess(line, false);
357
                } catch (InvalidPageNumberException e) {return;}
358
                cache.getAccessPage().setElemShort((line & cache.getOffset()), col, data);
359
        }
360

    
361
        public void setElemInt(int line, int col, int[] data) {
362
                try {
363
                        lru.cacheAccess(line, false);
364
                } catch (InvalidPageNumberException e) {return;}
365
                cache.getAccessPage().setElemInt((line & cache.getOffset()), col, data);
366
        }
367

    
368
        public void setElemFloat(int line, int col, float[] data) {
369
                try {
370
                        lru.cacheAccess(line, false);
371
                } catch (InvalidPageNumberException e) {return;}
372
                cache.getAccessPage().setElemFloat((line & cache.getOffset()), col, data);
373
        }
374

    
375
        public void setElemDouble(int line, int col, double[] data) {
376
                try {
377
                        lru.cacheAccess(line, false);
378
                } catch (InvalidPageNumberException e) {return;}
379
                cache.getAccessPage().setElemDouble((line & cache.getOffset()), col, data);
380
        }
381

    
382
        //TODO: FUNCIONALIDAD: Terminar m?todos de RasterCach?
383
                
384
        //***********************************************
385
    //Obtiene una banda entera
386
    
387
    public IBand getBand(int band){
388
            return null;
389
    }
390

    
391
    /*
392
     *  (non-Javadoc)
393
     * @see org.gvsig.fmap.driver.IBuffer#getBandBuffer(int)
394
     */
395
    public IBuffer getBandBuffer(int iBand){
396
            return null;
397
    }
398
    
399
    /*
400
     *  (non-Javadoc)
401
     * @see org.gvsig.fmap.driver.IBuffer#replicateBand(int, int)
402
     */
403
        public void replicateBand(int orig, int dest) {
404
        }
405
                
406
        /*
407
     *  (non-Javadoc)
408
     * @see org.gvsig.fmap.dataaccess.buffer.RasterBuffer#switchBands(int[])
409
     */
410
    public void switchBands(int[] bandPosition){
411
            
412
    }
413

    
414
        //*********************************************************
415
        
416
        public RasterBuffer adjustRasterNearestNeighbourInterpolation(int w, int h, int[] bands) {
417
                return null;
418
        }
419

    
420
        public RasterBuffer adjustRasterBilinearInterpolation(int w, int h, int[] bands) {
421
                return null;
422
        }
423

    
424
        public RasterBuffer adjustRasterInverseDistanceInterpolation(int w, int h, int[] bands) {
425
                return null;
426
        }
427

    
428
        public RasterBuffer adjustRasterBicubicSplineInterpolation(int w, int h, int[] bands) {
429
                return null;
430
        }
431

    
432
        public RasterBuffer adjustRasterBSplineInterpolation(int w, int h, int[] bands) {
433
                return null;
434
        }
435

    
436
        //*********************************************************
437
        
438
        public void assign(int band, byte value) {
439
                for(int line = 0; line < height; line ++){
440
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
441
                    for(int col = 0; col < width; col ++){
442
                            try {
443
                                    if(beginLine){
444
                                            lru.cacheAccess(line, false);
445
                                            beginLine = false;
446
                                    }
447
                            } catch (InvalidPageNumberException e) {return;}
448
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);                
449
                    }
450
                }
451
        }
452

    
453
        public void assign(int band, short value) {
454
                for(int line = 0; line < height; line ++){
455
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
456
                    for(int col = 0; col < width; col ++){
457
                            try {
458
                                    if(beginLine){
459
                                            lru.cacheAccess(line, false);
460
                                            beginLine = false;
461
                                    }
462
                            } catch (InvalidPageNumberException e) {return;}
463
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);                
464
                    }
465
                }                
466
        }
467

    
468
        public void assign(int band, int value) {
469
                for(int line = 0; line < height; line ++){
470
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
471
                    for(int col = 0; col < width; col ++){
472
                            try {
473
                                    if(beginLine){
474
                                            lru.cacheAccess(line, false);
475
                                            beginLine = false;
476
                                    }
477
                            } catch (InvalidPageNumberException e) {return;}
478
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);                
479
                    }
480
                }        
481
        }
482

    
483
        public void assign(int band, float value) {
484
                for(int line = 0; line < height; line ++){
485
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
486
                    for(int col = 0; col < width; col ++){
487
                            try {
488
                                    if(beginLine){
489
                                            lru.cacheAccess(line, false);
490
                                            beginLine = false;
491
                                    }
492
                            } catch (InvalidPageNumberException e) {return;}
493
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);                
494
                    }
495
                }        
496
        }
497

    
498
        public void assign(int band, double value) {
499
                for(int line = 0; line < height; line ++){
500
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
501
                    for(int col = 0; col < width; col ++){
502
                            try {
503
                                    if(beginLine){
504
                                            lru.cacheAccess(line, false);
505
                                            beginLine = false;
506
                                    }
507
                            } catch (InvalidPageNumberException e) {return;}
508
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, band, value);                
509
                    }
510
                }
511
        }
512
    
513
    /*
514
     *  (non-Javadoc)
515
     * @see org.gvsig.fmap.driver.IBuffer#cloneBuffer()
516
     */
517
    public IBuffer cloneBuffer(){
518
            return null;
519
    }
520
    
521
    /*
522
     * (non-Javadoc)
523
     * @see org.gvsig.fmap.driver.IBuffer#interchangeBands(int, int)
524
     */
525
        public void interchangeBands(int band1, int band2) {
526
        }
527
        
528
    /*
529
     * (non-Javadoc)
530
     * @see org.gvsig.fmap.driver.IBuffer#interchangeBands(int[])
531
     */
532
    public void interchangeBands(int[] bands){
533
            
534
    }
535
    
536
    /*
537
     *  (non-Javadoc)
538
     * @see org.gvsig.fmap.driver.IBuffer#mallocOneBand(int, int, int, int)
539
     */
540
    public void mallocOneBand(int dataType, int width, int height, int band) {
541
                        
542
        }
543

    
544
    /*
545
     *  (non-Javadoc)
546
     * @see org.gvsig.fmap.driver.IBuffer#copyBand(int, org.gvsig.fmap.dataaccess.buffer.IBand)
547
     */
548
        public void copyBand(int nBand, IBand band) {
549
                                
550
        }
551

    
552
        /*
553
         *  (non-Javadoc)
554
         * @see org.gvsig.fmap.driver.IBuffer#assignBand(int, org.gvsig.fmap.dataaccess.buffer.IBand)
555
         */
556
        public void assignBand(int nBand, IBand band) {
557
                                
558
        }
559

    
560
        /*
561
         *  (non-Javadoc)
562
         * @see org.gvsig.fmap.driver.IBuffer#createBand(byte)
563
         */
564
        public IBand createBand(byte defaultValue) {
565
                
566
                return null;
567
        }
568

    
569
        /*
570
         *  (non-Javadoc)
571
         * @see org.gvsig.fmap.driver.IBuffer#assignBandToNotValid(int)
572
         */
573
        public void assignBandToNotValid(int iBand) {
574
                                
575
        }
576

    
577
}