Statistics
| Revision:

gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / stripecache / horizontal / FloatBand.java @ 1939

History | View | Annotate | Download (3.76 KB)

1
package org.gvsig.raster.cache.buffer.impl.stripecache.horizontal;
2

    
3
import org.gvsig.raster.cache.buffer.exception.InvalidPageNumberException;
4
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException;
5
import org.gvsig.raster.cache.buffer.impl.RasterBuffer;
6
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand;
7
import org.gvsig.raster.cache.buffer.impl.stripecache.LRUAlgorithm;
8

    
9

    
10
/**
11
 * This class represent a byte band loaded in cache.
12
 * 
13
 * @author Nacho Brodin (nachobrodin@gmail.com)
14
 */
15
public class FloatBand extends CacheBand {
16
                
17
        public FloatBand(CacheHorzImpl cache, LRUAlgorithm lru, int band){
18
                super(cache, lru, band);
19
                this.setDataType(RasterBuffer.TYPE_FLOAT);
20
        }
21
        
22
        /*
23
         * (non-Javadoc)
24
         * @see org.gvsig.raster.cache.buffer.impl.BandImpl#getNumberOfBlocks()
25
         */
26
        public int getNumberOfBlocks() {
27
                return (int)Math.ceil((double)getHeight() / (double)getBlockSize());
28
        }
29

    
30
        /*
31
         * (non-Javadoc)
32
         * @see org.gvsig.raster.buffer.RasterBand#assign(float)
33
         */
34
        public void assign(float value) {
35
                for(int line = 0; line < getHeight(); line ++){
36
                        boolean beginLine = true;  //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea
37
                    for(int col = 0; col < getWidth(); col ++){
38
                            try {
39
                                    if(beginLine){
40
                                            lru.cacheAccess(line, false);
41
                                            beginLine = false;
42
                                    }
43
                            } catch (InvalidPageNumberException e) {return;
44
                            } catch (InterruptedException e) {return;}
45
                            cache.getAccessPage().setElem((line & cache.getOffset()), col, nBand, value);                
46
                    }
47
                }
48
        }
49
        
50
        /*
51
         * (non-Javadoc)
52
         * @see org.gvsig.raster.buffer.RasterBand#getFloatBlock(int)
53
         */
54
        public float[][] getFloatBlock(int block) {
55
                int line = block * getBlockSize();
56
                try {
57
                        lru.cacheAccess(line, true);
58
                } catch (InvalidPageNumberException e) {return null;}
59
                catch (InterruptedException e) {return null;}
60
                return cache.getAccessPage().getBand(nBand).getFloatBlock(block);
61
        }
62
        
63
        /*
64
         * (non-Javadoc)
65
         * @see org.gvsig.raster.buffer.IRasterBand#setFloatBlock(float[][], int)
66
         */
67
        public void setFloatBlock(float[][] data, int block) {
68
                int line = block * getBlockSize();
69
                try {
70
                        lru.cacheAccess(line, true);
71
                } catch (InvalidPageNumberException e) {return;}
72
                catch (InterruptedException e) {return;}
73
                try {
74
                        cache.getAccessPage().getBand(nBand).setFloatBlock(data, block);
75
                } catch (OperationNotSupportedException e) {
76
                        //Solo buffers de solo lectura
77
                }
78
        }
79

    
80
        /*
81
         * (non-Javadoc)
82
         * @see org.gvsig.raster.buffer.RasterBand#getFloatLine(int)
83
         */
84
        public float[] getFloatLine(int line) {
85
                if(exists(line)) {
86
                        return cache.getAccessPage().getLineFromBandFloat(
87
                                        (line & cache.getOffset()), nBand);
88
                }
89
                return null;
90
        }
91

    
92
        /*
93
         * (non-Javadoc)
94
         * @see org.gvsig.raster.buffer.RasterBand#getElemByte(int, int)
95
         */
96
        public float getElemFloat(int line, int col) {
97
                if(exists(line)) {
98
                        return cache.getAccessPage().getElemFloat(
99
                                        (line & cache.getOffset()), col, nBand);
100
                }
101
                return getNoDataValue().getValue().floatValue();
102
        }
103

    
104
        /*
105
         * (non-Javadoc)
106
         * @see org.gvsig.raster.buffer.RasterBand#setByteLine(float[], int)
107
         */
108
        public void setByteLine(float[] data, int line) {
109
                if(exists(line)) {
110
                        cache.getAccessPage().setLineInBandFloat(
111
                                        data, (line & cache.getOffset()), nBand);
112
                }
113
        }
114

    
115
        /*
116
         * (non-Javadoc)
117
         * @see org.gvsig.raster.buffer.RasterBand#setElem(int, int, float)
118
         */
119
        public void setElem(int line, int col, float data) {
120
                if(exists(line)) {
121
                        cache.getAccessPage().setElem(
122
                                        (line & cache.getOffset()), col, nBand, data);
123
                }
124
        }
125
        
126
        /*
127
         * (non-Javadoc)
128
         * @see java.lang.Object#clone()
129
         */
130
        public Object clone() {
131
                CacheHorzImpl cloneCache = (CacheHorzImpl)cache.clone();
132
                LRUAlgorithm cloneLRU = new LRUAlgorithm(cloneCache);
133
                return new FloatBand(cloneCache, cloneLRU, nBand);
134
        }
135
}