gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / stripecache / vertical / FloatBand.java @ 1939
History | View | Annotate | Download (4.29 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.vertical; |
---|---|
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.Cache; |
7 |
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand; |
8 |
import org.gvsig.raster.cache.buffer.impl.stripecache.LRUAlgorithm; |
9 |
|
10 |
|
11 |
/**
|
12 |
* This class represent a byte band loaded in cache.
|
13 |
*
|
14 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
15 |
*/
|
16 |
public class FloatBand extends CacheBand { |
17 |
|
18 |
public FloatBand(Cache cache, LRUAlgorithm lru, int band){ |
19 |
super(cache, lru, band);
|
20 |
this.setDataType(RasterBuffer.TYPE_FLOAT);
|
21 |
} |
22 |
|
23 |
/*
|
24 |
* (non-Javadoc)
|
25 |
* @see org.gvsig.raster.buffer.IRasterBand#getNumberOfBlocks()
|
26 |
*/
|
27 |
@Override
|
28 |
public int getNumberOfBlocks() { |
29 |
return (int)Math.ceil((double)getWidth() / (double)getBlockSize()); |
30 |
} |
31 |
|
32 |
/*
|
33 |
* (non-Javadoc)
|
34 |
* @see org.gvsig.raster.cache.buffer.Band#isHorizontalBlock()
|
35 |
*/
|
36 |
public boolean isHorizontalBlock() { |
37 |
return false; |
38 |
} |
39 |
|
40 |
/*
|
41 |
* (non-Javadoc)
|
42 |
* @see org.gvsig.raster.buffer.RasterBand#assign(float)
|
43 |
*/
|
44 |
public void assign(float value) { |
45 |
for(int col = 0; col < getWidth(); col ++) { |
46 |
boolean beginCol = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una columna |
47 |
for(int line = 0; line < getHeight(); line ++) { |
48 |
try {
|
49 |
if(beginCol) {
|
50 |
lru.cacheAccess(col, false);
|
51 |
beginCol = false;
|
52 |
} |
53 |
} catch (InvalidPageNumberException e) {
|
54 |
return;
|
55 |
} catch (InterruptedException e) { |
56 |
return;
|
57 |
} |
58 |
cache.getAccessPage().setElem(line, (col& cache.getOffset()), nBand, value); |
59 |
} |
60 |
} |
61 |
} |
62 |
|
63 |
/*
|
64 |
* (non-Javadoc)
|
65 |
* @see org.gvsig.raster.buffer.RasterBand#getFloatBlock(int)
|
66 |
*/
|
67 |
public float[][] getFloatBlock(int block) { |
68 |
int col = block * getBlockSize();
|
69 |
try {
|
70 |
lru.cacheAccess(col, true);
|
71 |
} catch (InvalidPageNumberException e) {
|
72 |
return null; |
73 |
} catch (InterruptedException e) { |
74 |
return null; |
75 |
} |
76 |
return cache.getAccessPage().getBand(nBand).getFloatBlock(block);
|
77 |
} |
78 |
|
79 |
/*
|
80 |
* (non-Javadoc)
|
81 |
* @see org.gvsig.raster.buffer.IRasterBand#setFloatBlock(float[][], int)
|
82 |
*/
|
83 |
public void setFloatBlock(float[][] data, int block) { |
84 |
int col = block * getBlockSize();
|
85 |
try {
|
86 |
lru.cacheAccess(col, true);
|
87 |
} catch (InvalidPageNumberException e) {
|
88 |
return;
|
89 |
} catch (InterruptedException e) { |
90 |
return;
|
91 |
} |
92 |
try {
|
93 |
cache.getAccessPage().getBand(nBand).setFloatBlock(data, block); |
94 |
} catch (OperationNotSupportedException e) { |
95 |
//Solo buffers de solo lectura
|
96 |
} |
97 |
} |
98 |
|
99 |
/*
|
100 |
* (non-Javadoc)
|
101 |
* @see org.gvsig.raster.buffer.RasterBand#getFloatLine(int)
|
102 |
*/
|
103 |
public float[] getFloatLine(int line) throws OperationNotSupportedException { |
104 |
throw new OperationNotSupportedException("Operation getByteLine not supported for a vertical band of cache"); |
105 |
} |
106 |
|
107 |
/*
|
108 |
* (non-Javadoc)
|
109 |
* @see org.gvsig.raster.buffer.RasterBand#getElemByte(int, int)
|
110 |
*/
|
111 |
public float getElemFloat(int line, int col) { |
112 |
try {
|
113 |
lru.cacheAccess(col, true);
|
114 |
} catch (InvalidPageNumberException e) {
|
115 |
return (float)getNoDataValue().getValue().floatValue(); |
116 |
} catch (InterruptedException e) { |
117 |
return (float)getNoDataValue().getValue().floatValue(); |
118 |
} |
119 |
return cache.getAccessPage().getElemFloat(line, (col& cache.getOffset()), nBand);
|
120 |
} |
121 |
|
122 |
/*
|
123 |
* (non-Javadoc)
|
124 |
* @see org.gvsig.raster.buffer.RasterBand#setByteLine(float[], int)
|
125 |
*/
|
126 |
public void setByteLine(float[] data, int line) throws OperationNotSupportedException { |
127 |
throw new OperationNotSupportedException("Operation getByteLine not supported for a vertical band of cache"); |
128 |
} |
129 |
|
130 |
/*
|
131 |
* (non-Javadoc)
|
132 |
* @see org.gvsig.raster.buffer.RasterBand#setElem(int, int, float)
|
133 |
*/
|
134 |
public void setElem(int line, int col, float data) { |
135 |
try {
|
136 |
lru.cacheAccess(col, false);
|
137 |
} catch (InvalidPageNumberException e) {
|
138 |
return;
|
139 |
} catch (InterruptedException e) { |
140 |
return;
|
141 |
} |
142 |
cache.getAccessPage().setElem(line, (col& cache.getOffset()), nBand, data); |
143 |
} |
144 |
|
145 |
/*
|
146 |
* (non-Javadoc)
|
147 |
* @see java.lang.Object#clone()
|
148 |
*/
|
149 |
public Object clone() { |
150 |
Cache cloneCache = (Cache)cache.clone(); |
151 |
LRUAlgorithm cloneLRU = new LRUAlgorithm(cloneCache);
|
152 |
return new FloatBand(cloneCache, cloneLRU, nBand); |
153 |
} |
154 |
} |