Statistics
| Revision:

root / trunk / libraries / libRaster / src / org / gvsig / raster / buffer / cache / PageBuffer.java @ 11074

History | View | Annotate | Download (12.2 KB)

1

    
2
/* gvSIG. Sistema de Informaci?n Geogr?fica de la Generalitat Valenciana
3
 *
4
 * Copyright (C) 2006 IVER T.I. and Generalitat Valenciana.
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., 59 Temple Place - Suite 330, Boston, MA  02111-1307,USA.
19
 */
20
package org.gvsig.raster.buffer.cache;
21

    
22
import java.io.IOException;
23

    
24
import org.gvsig.raster.buffer.IBand;
25
import org.gvsig.raster.dataset.IBuffer;
26
import org.gvsig.raster.util.DataClassList;
27
import org.gvsig.raster.util.Histogram;
28
import org.gvsig.raster.util.HistogramException;
29

    
30
/**
31
 * Esta clase representa una p?gina de cache.Cada p?gina de cach? est? compuesta por
32
 * varios objetos PageBandBuffer donde cada uno es una p?gina que corresponde a una 
33
 * banda de raster cacheada. 
34
 * 
35
 * @author Nacho Brodin (nachobrodin@gmail.com)
36
 *
37
 */
38
public class PageBuffer implements IBuffer{
39

    
40
        private PageBandBuffer[] pageBandBuffer = null;
41
        private int        percent = 0;
42
        
43
        /**
44
         * Constructor
45
         * @param dataType
46
         * @param width
47
         * @param height
48
         * @param bandNr
49
         * @param malloc
50
         */
51
        public PageBuffer(int dataType, int width, int height, int bandNr, boolean malloc, int nHddPags){
52
                pageBandBuffer = new PageBandBuffer[bandNr];
53
                for (int i = 0; i < pageBandBuffer.length; i++)
54
                        pageBandBuffer[i] = new PageBandBuffer(dataType, width, height, 1, malloc, i);
55
        }
56
        
57
        /*
58
     * (non-Javadoc)
59
     * @see org.gvsig.raster.driver.IBuffer#isBandSwitchable()
60
     */
61
    public boolean isBandSwitchable(){
62
            return false;
63
    }
64
        
65
        /**
66
         * Asigna la lista de paginas de disco
67
         * @param hddList Lista de p?ginas de disco
68
         */
69
        public void setHddPages(HddPage[] hddList){
70
                for (int i = 0; i < pageBandBuffer.length; i++)
71
                        pageBandBuffer[i].setHddPages(hddList);
72
        }
73
        
74
        /**
75
         * Carga una p?gina especificada en el par?metro nPag con los datos necesarios.
76
         * Para esto recorre todas las bandas de la p?gina llamando al load de cada una.
77
         *   
78
         * @param nPag N?mero de p?gina a cargar
79
         */
80
        public void loadPage(int nPag){
81
                for (int i = 0; i < pageBandBuffer.length; i++)
82
                        pageBandBuffer[i].loadPage(nPag);
83
        }
84
        
85
        /**
86
         * Salva una p?gina especificada en el par?metro nPag a disco. 
87
         * Para esto recorre todas las bandas de la p?gina llamando al save de cada una.
88
         *   
89
         * @param nPag N?mero de p?gina a salvar
90
         * @throws IOException
91
         */
92
        public void savePage(int nPag) throws IOException{
93
                for (int i = 0; i < pageBandBuffer.length; i++)
94
                        pageBandBuffer[i].savePage(nPag);
95
        }
96
        
97
        public void assign(int band, byte value) {
98
                pageBandBuffer[band].assign(0, value);
99
        }
100

    
101
        public void assign(int band, short value) {
102
                pageBandBuffer[band].assign(0, value);
103
        }
104

    
105
        public void assign(int band, int value) {
106
                pageBandBuffer[band].assign(0, value);
107
        }
108

    
109
        public void assign(int band, float value) {
110
                pageBandBuffer[band].assign(0, value);
111
        }
112

    
113
        public void assign(int band, double value) {
114
                pageBandBuffer[band].assign(0, value);
115
        }
116

    
117
        public void assignBand(int nBand, IBand band) {
118
        }
119

    
120
        public void assignBandToNotValid(int iBand) {
121
        }
122

    
123
        public IBuffer cloneBuffer() {
124
                return null;
125
        }
126

    
127
        public void copyBand(int nBand, IBand band) {
128
        }
129

    
130
        public IBand createBand(byte defaultValue) {
131
                return null;
132
        }
133

    
134
        public IBand getBand(int nBand) {
135
                return null;
136
        }
137

    
138
        public IBuffer getBandBuffer(int nBand) {
139
                return null;
140
        }
141

    
142
        public int getBandCount() {
143
                return pageBandBuffer[0].getBandCount();
144
        }
145
        
146
        public int getDataType() {
147
                return pageBandBuffer[0].getDataType();
148
        }
149

    
150
        public void setDataType(int dataType) {
151
        
152
        }
153
        
154
        public int getHeight() {
155
                return pageBandBuffer[0].getHeight();
156
        }
157
        
158
        public int getWidth() {
159
                return pageBandBuffer[0].getWidth();
160
        }
161

    
162
        
163
        
164
        public byte getByteNoDataValue() {
165
                return pageBandBuffer[0].getByteNoDataValue();
166
        }
167
        
168
        public float getFloatNoDataValue() {
169
                return pageBandBuffer[0].getFloatNoDataValue();
170
        }
171

    
172
        public int getIntNoDataValue() {
173
                return pageBandBuffer[0].getIntNoDataValue();
174
        }
175

    
176
        public double getNoDataValue() {
177
                return pageBandBuffer[0].getNoDataValue();
178
        }
179

    
180
        public double getNotValidValue() {
181
                return pageBandBuffer[0].getNotValidValue();
182
        }
183

    
184
        public short getShortNoDataValue() {
185
                return pageBandBuffer[0].getShortNoDataValue();
186
        }
187

    
188

    
189
        
190
        public byte getElemByte(int line, int col, int band) {
191
                return pageBandBuffer[band].getElemByte(line, col, 0);
192
        }
193

    
194
        public short getElemShort(int line, int col, int band) {
195
                return pageBandBuffer[band].getElemShort(line, col, 0);
196
        }
197
        
198
        public int getElemInt(int line, int col, int band) {
199
                return pageBandBuffer[band].getElemInt(line, col, 0);
200
        }
201

    
202
        public float getElemFloat(int line, int col, int band) {
203
                return pageBandBuffer[band].getElemFloat(line, col, 0);
204
        }
205
        
206
        public double getElemDouble(int line, int col, int band) {
207
                return pageBandBuffer[band].getElemDouble(line, col, 0);
208
        }
209

    
210
        
211

    
212

    
213
        public void getElemByte(int line, int col, byte[] data) {
214
                for (int i = 0; i < pageBandBuffer.length; i++) 
215
                        data[i] = pageBandBuffer[i].getElemByte(line, col, 0);
216
        }
217
        
218
        public void getElemShort(int line, int col, short[] data) {
219
                for (int i = 0; i < pageBandBuffer.length; i++) 
220
                        data[i] = pageBandBuffer[i].getElemShort(line, col, 0);
221
        }
222

    
223
        public void getElemInt(int line, int col, int[] data) {
224
                for (int i = 0; i < pageBandBuffer.length; i++) 
225
                        data[i] = pageBandBuffer[i].getElemInt(line, col, 0);
226
        }
227

    
228
        public void getElemFloat(int line, int col, float[] data) {
229
                for (int i = 0; i < pageBandBuffer.length; i++) 
230
                        data[i] = pageBandBuffer[i].getElemFloat(line, col, 0);
231
        }
232

    
233
        public void getElemDouble(int line, int col, double[] data) {
234
                for (int i = 0; i < pageBandBuffer.length; i++) 
235
                        data[i] = pageBandBuffer[i].getElemDouble(line, col, 0);
236
        }
237
        
238
        
239
        public byte[][] getLineByte(int line) {
240
                byte[][] b = new byte[pageBandBuffer.length][];
241
                for (int i = 0; i < pageBandBuffer.length; i++) 
242
                        b[i] = pageBandBuffer[i].getLineByte(line)[0];
243
                return b;
244
        }
245

    
246
        public double[][] getLineDouble(int line) {
247
                double[][] d = new double[pageBandBuffer.length][];
248
                for (int i = 0; i < pageBandBuffer.length; i++) 
249
                        d[i] = pageBandBuffer[i].getLineDouble(line)[0];
250
                return d;
251
        }
252

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

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

    
267
        public short[][] getLineShort(int line) {
268
                short[][] s = new short[pageBandBuffer.length][];
269
                for (int i = 0; i < pageBandBuffer.length; i++) 
270
                        s[i] = pageBandBuffer[i].getLineShort(line)[0];
271
                return s;
272
        }
273
        
274
        
275
        
276
        public byte[] getLineFromBandByte(int line, int band) {
277
                return pageBandBuffer[band].getLineFromBandByte(line, 0);
278
        }
279

    
280
        public double[] getLineFromBandDouble(int line, int band) {
281
                return pageBandBuffer[band].getLineFromBandDouble(line, 0);
282
        }
283

    
284
        public float[] getLineFromBandFloat(int line, int band) {
285
                return pageBandBuffer[band].getLineFromBandFloat(line, 0);
286
        }
287

    
288
        public int[] getLineFromBandInt(int line, int band) {
289
                return pageBandBuffer[band].getLineFromBandInt(line, 0);
290
        }
291

    
292
        public short[] getLineFromBandShort(int line, int band) {
293
                return pageBandBuffer[band].getLineFromBandShort(line, 0);
294
        }
295

    
296
        
297
        
298
        
299
        public void interchangeBands(int band1, int band2) {
300
        }
301

    
302
        public void mallocOneBand(int dataType, int width, int height, int band) {
303
        }
304

    
305
        public void replicateBand(int orig, int dest) {
306
        }
307

    
308

    
309

    
310
        public void setElem(int line, int col, int band, byte data) {
311
                pageBandBuffer[band].setElem(line, col, 0, data);
312
        }
313

    
314
        public void setElem(int line, int col, int band, short data) {
315
                pageBandBuffer[band].setElem(line, col, 0, data);
316
        }
317

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

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

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

    
330

    
331
        
332
        public void setElemByte(int line, int col, byte[] data) {
333
                byte[] b = new byte[1];
334
                for (int i = 0; i < pageBandBuffer.length; i++) {
335
                        b[0] = data[i];
336
                        pageBandBuffer[i].setElemByte(line, col, b);
337
                }
338
        }
339

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

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

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

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

    
372
        
373
        
374
        public void setLineByte(byte[][] data, int line) {
375
        }
376

    
377
        public void setLineDouble(double[][] data, int line) {
378
        }
379

    
380
        public void setLineFloat(float[][] data, int line) {
381
        }
382

    
383
        public void setLineInBandByte(byte[] data, int line, int band) {
384
        }
385

    
386
        public void setLineInBandDouble(double[] data, int line, int band) {
387
        }
388

    
389
        public void setLineInBandFloat(float[] data, int line, int band) {
390
        }
391

    
392
        public void setLineInBandInt(int[] data, int line, int band) {
393
        }
394

    
395
        public void setLineInBandShort(short[] data, int line, int band) {
396
        }
397

    
398
        public void setLineInt(int[][] data, int line) {
399
        }
400

    
401
        public void setLineShort(short[][] data, int line) {
402
        }
403

    
404
        public void setNoDataValue(double nd) {
405
        }
406

    
407
        public void setNotValidValue(double value) {
408
        }
409

    
410
        public void switchBands(int[] bands) {
411
        }
412

    
413
    /*
414
     * (non-Javadoc)
415
     * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
416
     */
417
        public Histogram getHistogram() throws HistogramException {
418
                percent = 0;
419
                if(getDataType() != IBuffer.TYPE_BYTE)
420
                        return null;
421
                Histogram hist = new Histogram(getBandCount(), 256);
422
                for (int iBand = 0; iBand < getBandCount(); iBand++) 
423
                        for (int col = 0; col < getHeight(); col++) 
424
                                for (int row = 0; row < getWidth(); row++) 
425
                                        hist.incrementPxValue(iBand, getElemByte(row, col, iBand));
426
                percent = 100;
427
                return hist;
428
        }
429

    
430
        /*
431
         * (non-Javadoc)
432
         * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
433
          */
434
        public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException {
435
                Histogram hist = new Histogram(getBandCount(), classes.length());
436
                for (int iBand = 0; iBand < getBandCount(); iBand++) { 
437
                        for (int col = 0; col < getHeight(); col++) {
438
                                for (int row = 0; row < getWidth(); row++) {
439
                                        int pixelValue = -1;
440
                                        switch(this.getDataType()){
441
                                        case IBuffer.TYPE_BYTE: pixelValue = classes.getClassPosition((double)getElemByte(row, col, iBand)); break;
442
                                        case IBuffer.TYPE_SHORT: pixelValue = classes.getClassPosition((double)getElemShort(row, col, iBand)); break;
443
                                        case IBuffer.TYPE_INT: pixelValue = classes.getClassPosition((double)getElemInt(row, col, iBand)); break;
444
                                        case IBuffer.TYPE_FLOAT: pixelValue = classes.getClassPosition((double)getElemFloat(row, col, iBand)); break;
445
                                        case IBuffer.TYPE_DOUBLE: pixelValue = classes.getClassPosition((double)getElemDouble(row, col, iBand)); break;
446
                                        }                 
447
                                        if(pixelValue >= 0)
448
                                                hist.incrementPxValue(iBand, pixelValue);
449
                                }                
450
                        }
451
                }
452
                return hist;
453
        }
454

    
455
        /*
456
         * (non-Javadoc)
457
         * @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getPercent()
458
         */
459
        public int getPercent() {
460
                return percent;
461
        }
462
}