Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / rocache / ReadOnlyCacheBand.java @ 1939

History | View | Annotate | Download (12.5 KB)

1
package org.gvsig.raster.cache.buffer.impl.rocache;
2

    
3
import java.io.IOException;
4
import java.util.ArrayList;
5

    
6
import org.gvsig.raster.cache.buffer.Buffer;
7
import org.gvsig.raster.cache.buffer.BufferDataSource;
8
import org.gvsig.raster.cache.buffer.PxTile;
9
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
10
import org.gvsig.raster.cache.buffer.exception.ProcessInterruptedException;
11
import org.gvsig.raster.cache.buffer.impl.BandImpl;
12
import org.gvsig.raster.cache.buffer.impl.memory.RasterMemoryBuffer;
13

    
14
/**
15
 * Base class for a ReadOnlyCacheBand
16
 * 
17
 * @author Nacho Brodin (nachobrodin@gmail.com)
18
 */
19
public abstract class ReadOnlyCacheBand extends BandImpl {
20
        /**
21
         * Loaded page
22
         */
23
        protected Buffer                     page              = null;
24
        protected Buffer                     secondPage        = null;
25
        protected BufferDataSource           dataSource        = null;
26
        protected ArrayList<PxTile>          stripeList        = null;
27
        
28
        /**
29
         * Band number in the list of the raster
30
         */
31
        protected int                        nBand             = -1;
32
        /**
33
         * Number of page loaded in IBuffer
34
         */
35
        protected int                        loadedPage        = -1;
36
        protected int                        loadedSecondPage  = -1;
37
        
38
        protected int                        bitsPag           = 0;
39
        /**
40
         * Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con 
41
         * con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser?
42
         * 16 - 1 = 15 porque 15 en binario es 1111.
43
         * 
44
         * Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del
45
         * desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir
46
         * que la l?nea 83 del raster es la 3 de su p?gina. 
47
         */
48
        protected int                         offset           = 1;
49
        
50
    /**
51
     * Constructor a llamar desde las clases hijas
52
     */
53
    public ReadOnlyCacheBand(ArrayList<PxTile> stripeList,
54
                                                    BufferDataSource dataSource,
55
                                                    int offset,
56
                                                    int bitsPag,
57
                                                    int nBand, 
58
                                                    int width, 
59
                                                    int height, 
60
                                                    int dataType) {
61
            super(width, height);
62
            super.setDataType(dataType);
63
            this.nBand = nBand;
64
            this.dataSource = dataSource;
65
            this.stripeList = stripeList;
66
            this.offset = offset;
67
            this.bitsPag = bitsPag;
68
            
69
            //Creamos las p?ginas en memoria
70
                this.page = new RasterMemoryBuffer(getDataType(), 
71
                                                                                        width,
72
                                                                                        getBlockSize(),
73
                                                                                        1,
74
                                                                                        true);
75
                this.secondPage = new RasterMemoryBuffer(getDataType(), 
76
                                                                                                width, 
77
                                                                                                getBlockSize(),
78
                                                                                                1,
79
                                                                                                true);
80
    }
81
    
82
        /**
83
         * Load a page with data from disk
84
         * @param nPage
85
         */
86
        protected void loadOrSwapPage(int nPage) {
87
                if(loadedSecondPage == nPage) {
88
                        swapPages();
89
                        return;
90
                }
91
                loadPage(nPage);
92
        }
93
        
94
        /**
95
         * Swap the two pages
96
         */
97
        protected void loadPage(int nPage) {
98
                try {
99
                        if(dataSource != null) {
100
                                dataSource.loadPage(page, stripeList.get(nPage), nBand);
101
                                dataSource.loadPage(secondPage, stripeList.get((nPage + 1) % stripeList.size()), nBand);
102
                        }
103
                        loadedPage = nPage;
104
                        loadedSecondPage = (nPage + 1) % stripeList.size();
105
                        //System.out.println("Load:" + loadedPage + " " + loadedSecondPage);
106
                } catch (OperationNotSupportedException e) {
107
                } catch (IOException e) {
108
                } catch (ProcessInterruptedException e) {
109
                }
110
        }
111

    
112
        /**
113
         * Swap the two pages
114
         */
115
        protected void swapPages() {
116
                int aux = loadedPage;
117
                loadedPage = loadedSecondPage;
118
                loadedSecondPage = aux;
119
                Buffer pAux = page;
120
                page = secondPage;
121
                secondPage = pAux;
122
                //System.out.println("Swap:" + loadedPage + " " + loadedSecondPage);
123
        }
124
            
125
        /*
126
         * (non-Javadoc)
127
         * @see org.gvsig.raster.buffer.IRasterBand#getBlockHeight()
128
         */
129
        public int getBlockSize() {
130
                return (int)stripeList.get(0).getHeight();
131
        }
132
        
133
        /*
134
         * (non-Javadoc)
135
         * @see org.gvsig.raster.buffer.IRasterBand#getNumberOfBlocks()
136
         */
137
        public int getNumberOfBlocks() {
138
                return stripeList.size();
139
        }
140
                
141
        /*
142
         * (non-Javadoc)
143
         * @see org.gvsig.raster.buffer.IRasterBand#setBandNumber(int)
144
         */
145
        public void setBandNumber(int band) {
146
                this.nBand = band;
147
        }
148
        
149
        /*
150
         * (non-Javadoc)
151
         * @see org.gvsig.raster.buffer.IRasterBand#getBandNumber()
152
         */
153
        public int getBandNumber() {
154
                return this.nBand;
155
        }
156
                
157
        //***********************************************
158
    //Getting a block of data
159
        
160
    /*
161
     * (non-Javadoc)
162
     * @see org.gvsig.raster.buffer.IRasterBand#getByteBlock(int)
163
     */
164
        public byte[][] getByteBlock(int block){
165
                return null;
166
        }
167
        
168
        /*
169
         * (non-Javadoc)
170
         * @see org.gvsig.raster.buffer.IRasterBand#getShortBlock(int)
171
         */
172
        public short[][] getShortBlock(int block) {
173
                return null;
174
        }
175
        
176
        /*
177
         * (non-Javadoc)
178
         * @see org.gvsig.raster.buffer.IRasterBand#getIntBlock(int)
179
         */
180
        public int[][] getIntBlock(int block) {
181
                return null;
182
        }
183
        
184
        /*
185
         * (non-Javadoc)
186
         * @see org.gvsig.raster.buffer.IRasterBand#getFloatBlock(int)
187
         */
188
        public float[][] getFloatBlock(int block) {
189
                return null;
190
        }
191
        
192
        /*
193
         * (non-Javadoc)
194
         * @see org.gvsig.raster.buffer.IRasterBand#getDoubleBlock(int)
195
         */
196
        public double[][] getDoubleBlock(int block) {
197
                return null;
198
        }
199
        
200
        //*****************************************************
201
        
202
        /*
203
         * (non-Javadoc)
204
         * @see org.gvsig.raster.buffer.IRasterBand#getElemByte(int, int)
205
         */
206
        public byte getElemByte(int line, int col) {
207
                return 0;
208
        }
209

    
210
        /*
211
         * (non-Javadoc)
212
         * @see org.gvsig.raster.buffer.IRasterBand#getElemDouble(int, int)
213
         */
214
        public double getElemDouble(int line, int col) {
215
                return 0;
216
        }
217
        
218
        /*
219
         * (non-Javadoc)
220
         * @see org.gvsig.raster.buffer.IRasterBand#getElemFloat(int, int)
221
         */
222
        public float getElemFloat(int line, int col) {
223
                return 0;
224
        }
225

    
226
        /*
227
         * (non-Javadoc)
228
         * @see org.gvsig.raster.buffer.IRasterBand#getElemInt(int, int)
229
         */
230
        public int getElemInt(int line, int col) {
231
                return 0;
232
        }
233

    
234
        /*
235
         * (non-Javadoc)
236
         * @see org.gvsig.raster.buffer.IRasterBand#getElemShort(int, int)
237
         */
238
        public short getElemShort(int line, int col) {
239
                return 0;
240
        }
241
        
242
        //*****************************************************
243
        
244
        /*
245
         * (non-Javadoc)
246
         * @see org.gvsig.raster.buffer.IRasterBand#getByteLine(int)
247
         */
248
        public byte[] getByteLine(int line) throws OperationNotSupportedException {
249
                return null;
250
        }
251

    
252
        /*
253
         * (non-Javadoc)
254
         * @see org.gvsig.raster.buffer.IRasterBand#getDoubleLine(int)
255
         */
256
        public double[] getDoubleLine(int line) throws OperationNotSupportedException {
257
                return null;
258
        }
259
        
260
        /*
261
         * (non-Javadoc)
262
         * @see org.gvsig.raster.buffer.IRasterBand#getFloatLine(int)
263
         */
264
        public float[] getFloatLine(int line) throws OperationNotSupportedException {
265
                return null;
266
        }
267

    
268
        /*
269
         * (non-Javadoc)
270
         * @see org.gvsig.raster.buffer.IRasterBand#getIntLine(int)
271
         */
272
        public int[] getIntLine(int line) throws OperationNotSupportedException {
273
                return null;
274
        }
275

    
276
        /*
277
         * (non-Javadoc)
278
         * @see org.gvsig.raster.buffer.IRasterBand#getShortLine(int)
279
         */
280
        public short[] getShortLine(int line) throws OperationNotSupportedException {
281
                return null;
282
        }
283

    
284
        /*
285
         * (non-Javadoc)
286
         * @see org.gvsig.raster.buffer.IRasterBand#setElem(int, int, byte)
287
         */
288
        public void setElem(int line, int col, byte data) throws OperationNotSupportedException {
289
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
290
        }
291

    
292
        /*
293
         * (non-Javadoc)
294
         * @see org.gvsig.raster.buffer.IRasterBand#setElem(int, int, short)
295
         */
296
        public void setElem(int line, int col, short data) throws OperationNotSupportedException {
297
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
298
        }
299

    
300
        /*
301
         * (non-Javadoc)
302
         * @see org.gvsig.raster.buffer.IRasterBand#setElem(int, int, int)
303
         */
304
        public void setElem(int line, int col, int data) throws OperationNotSupportedException {
305
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
306
        }
307

    
308
        /*
309
         * (non-Javadoc)
310
         * @see org.gvsig.raster.buffer.IRasterBand#setElem(int, int, float)
311
         */
312
        public void setElem(int line, int col, float data) throws OperationNotSupportedException {
313
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
314
        }
315

    
316
        /*
317
         * (non-Javadoc)
318
         * @see org.gvsig.raster.buffer.IRasterBand#setElem(int, int, double)
319
         */
320
        public void setElem(int line, int col, double data) throws OperationNotSupportedException {
321
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
322
        }
323

    
324
        /*
325
         * (non-Javadoc)
326
         * @see org.gvsig.raster.buffer.IRasterBand#setByteLine(byte[], int)
327
         */
328
        public void setByteLine(byte[] data, int line) throws OperationNotSupportedException {
329
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
330
        }
331

    
332
        /*
333
         * (non-Javadoc)
334
         * @see org.gvsig.raster.buffer.IRasterBand#setDoubleLine(double[], int)
335
         */
336
        public void setDoubleLine(double[] data, int line) throws OperationNotSupportedException {
337
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
338
        }
339
                
340
        /*
341
         * (non-Javadoc)
342
         * @see org.gvsig.raster.buffer.IRasterBand#setFloatLine(float[], int)
343
         */
344
        public void setFloatLine(float[] data, int line) throws OperationNotSupportedException {
345
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
346
        }
347

    
348
        /*
349
         * (non-Javadoc)
350
         * @see org.gvsig.raster.buffer.IRasterBand#setIntLine(int[], int)
351
         */
352
        public void setIntLine(int[] data, int line) throws OperationNotSupportedException {
353
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
354
        }
355

    
356
        /*
357
         * (non-Javadoc)
358
         * @see org.gvsig.raster.buffer.IRasterBand#setShortLine(short[], int)
359
         */
360
        public void setShortLine(short[] data, int line) throws OperationNotSupportedException {
361
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
362
        }
363
        
364
        /*
365
         * (non-Javadoc)
366
         * @see org.gvsig.raster.buffer.IRasterBand#setByteBlock(byte[][], int)
367
         */
368
        public void setByteBlock(byte[][] data, int block) throws OperationNotSupportedException {
369
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
370
        }
371
        
372
        /*
373
         * (non-Javadoc)
374
         * @see org.gvsig.raster.buffer.IRasterBand#setShortBlock(short[][], int)
375
         */
376
        public void setShortBlock(short[][] data, int block) throws OperationNotSupportedException {
377
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
378
        }
379
        
380
        /*
381
         * (non-Javadoc)
382
         * @see org.gvsig.raster.buffer.IRasterBand#setIntBlock(int[][], int)
383
         */
384
        public void setIntBlock(int[][] data, int block) throws OperationNotSupportedException {
385
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
386
        }
387
        
388
        /*
389
         * (non-Javadoc)
390
         * @see org.gvsig.raster.buffer.IRasterBand#setFloatBlock(float[][], int)
391
         */
392
        public void setFloatBlock(float[][] data, int block) throws OperationNotSupportedException {
393
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
394
        }
395
        
396
        /*
397
         * (non-Javadoc)
398
         * @see org.gvsig.raster.buffer.IRasterBand#setDoubleBlock(double[][], int)
399
         */
400
        public void setDoubleBlock(double[][] data, int block) throws OperationNotSupportedException {
401
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
402
        }
403
        
404
        /*
405
         * (non-Javadoc)
406
         * @see org.fv.raster.buffer.IBand#assign(byte)
407
         */
408
        public void assign(byte value) throws OperationNotSupportedException {
409
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
410
        }
411

    
412
        /*
413
         * (non-Javadoc)
414
         * @see org.fv.raster.buffer.IBand#assign(short)
415
         */
416
        public void assign(short value) throws OperationNotSupportedException {
417
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
418
        }
419

    
420
        /*
421
         * (non-Javadoc)
422
         * @see org.fv.raster.buffer.IBand#assign(int)
423
         */
424
        public void assign(int value) throws OperationNotSupportedException {
425
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
426
        }
427

    
428
        /*
429
         * (non-Javadoc)
430
         * @see org.fv.raster.buffer.IBand#assign(float)
431
         */
432
        public void assign(float value) throws OperationNotSupportedException {
433
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
434
        }
435

    
436
        /*
437
         * (non-Javadoc)
438
         * @see org.fv.raster.buffer.IBand#assign(double)
439
         */
440
        public void assign(double value) throws OperationNotSupportedException {
441
                throw new OperationNotSupportedException("ReadOnlyCacheBand doesn't support this operation");
442
        }
443

    
444
}