gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / src / main / java / org / gvsig / raster / cache / buffer / impl / stripecache / vertical / RasterVertCacheBuffer.java @ 995
History | View | Annotate | Download (27.6 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.stripecache.vertical; |
---|---|
2 |
|
3 |
import java.io.IOException; |
4 |
import java.util.ArrayList; |
5 |
|
6 |
import org.gvsig.raster.cache.buffer.Band; |
7 |
import org.gvsig.raster.cache.buffer.Buffer; |
8 |
import org.gvsig.raster.cache.buffer.BufferNoData; |
9 |
import org.gvsig.raster.cache.buffer.exception.BandNotCompatibleException; |
10 |
import org.gvsig.raster.cache.buffer.exception.InvalidPageNumberException; |
11 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
12 |
import org.gvsig.raster.cache.buffer.exception.WrongParameterException; |
13 |
import org.gvsig.raster.cache.buffer.impl.RasterBuffer; |
14 |
import org.gvsig.raster.cache.buffer.impl.stripecache.Cache; |
15 |
import org.gvsig.raster.cache.buffer.impl.stripecache.CacheBand; |
16 |
import org.gvsig.raster.cache.buffer.impl.stripecache.LRUAlgorithm; |
17 |
|
18 |
/**
|
19 |
* Esta clase representa un buffer de datos cacheado. El estar en cache significa que
|
20 |
* solo una parte de los datos estar?n en memoria y que gestiona, dependiendo de las
|
21 |
* peticiones, que partes hay que cargar a memoria y en que momento. Para esto el buffer
|
22 |
* no se llena de golpe sino que utiliza una clase que sirve los datos desde la fuente.
|
23 |
* Esta clase servidora de datos debe implementar el interfaz ICacheDatasetSourcepara
|
24 |
* servir datos de la forma requerida.
|
25 |
*
|
26 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
27 |
*
|
28 |
*/
|
29 |
public class RasterVertCacheBuffer extends RasterBuffer { |
30 |
private CacheVertImpl cache = null; |
31 |
private LRUAlgorithm lru = null; |
32 |
private CacheBandListVert bands = null; |
33 |
private int lastColumn = -1; |
34 |
|
35 |
/**
|
36 |
* Constructor. Asigna las variables de inicializaci?n y crea la estructura de
|
37 |
* la cach? con los datos pasados.
|
38 |
* @param dataType Tipo de dato del buffer
|
39 |
* @param width Ancho del buffer
|
40 |
* @param height Alto del buffer
|
41 |
* @param nBands N?mero de bandas del buffer
|
42 |
*/
|
43 |
public RasterVertCacheBuffer(int dataType, int width, int height, int nBands) { |
44 |
super(0, 0, width, height, dataType, nBands); |
45 |
cache = new CacheVertImpl(nBands, dataType, width, height);
|
46 |
lru = new LRUAlgorithm(cache);
|
47 |
|
48 |
bands = new CacheBandListVert();
|
49 |
for (int i = 0; i < nBands; i++) { |
50 |
switch(dataType) {
|
51 |
case RasterBuffer.TYPE_BYTE: bands.add(new ByteBand(cache, lru, i)); break; |
52 |
case RasterBuffer.TYPE_SHORT: bands.add(new ShortBand(cache, lru, i)); break; |
53 |
case RasterBuffer.TYPE_INT: bands.add(new IntBand(cache, lru, i)); break; |
54 |
case RasterBuffer.TYPE_FLOAT: bands.add(new FloatBand(cache, lru, i)); break; |
55 |
case RasterBuffer.TYPE_DOUBLE: bands.add(new DoubleBand(cache, lru, i)); break; |
56 |
} |
57 |
} |
58 |
} |
59 |
|
60 |
/**
|
61 |
* Borra la cach? cuando se elimina el objeto RasterCache ya que
|
62 |
* los trozos ya no pueden ser referenciados.
|
63 |
*/
|
64 |
protected void finalize() throws Throwable { |
65 |
free(); |
66 |
} |
67 |
|
68 |
/*
|
69 |
* (non-Javadoc)
|
70 |
* @see org.gvsig.raster.driver.IRasterBuffer#isBandSwitchable()
|
71 |
*/
|
72 |
public boolean isBandSwitchable(){ |
73 |
return true; |
74 |
} |
75 |
|
76 |
/**
|
77 |
* Obtiene la cach?
|
78 |
* @return
|
79 |
*/
|
80 |
public Cache getCache() {
|
81 |
return cache;
|
82 |
} |
83 |
|
84 |
/**
|
85 |
* Asigna la cache
|
86 |
* @param cache
|
87 |
*/
|
88 |
public void setCache(CacheVertImpl cache) { |
89 |
this.cache = cache;
|
90 |
this.lru.setCache(cache);
|
91 |
} |
92 |
|
93 |
/*
|
94 |
* (non-Javadoc)
|
95 |
* @see org.fv.raster.buffer.IRasterBuffer#isWritable()
|
96 |
*/
|
97 |
public boolean isWritable() { |
98 |
return true; |
99 |
} |
100 |
|
101 |
private boolean exists(int column) { |
102 |
// Store the last line checked so we don't check it again for each
|
103 |
// pixel of the same line
|
104 |
if (column != lastColumn) {
|
105 |
try {
|
106 |
lru.cacheAccess(column, false);
|
107 |
this.lastColumn = column;
|
108 |
} catch (InvalidPageNumberException e) {
|
109 |
return false; |
110 |
} catch (InterruptedException e) { |
111 |
return false; |
112 |
} |
113 |
} |
114 |
return true; |
115 |
} |
116 |
|
117 |
/***********************************************/
|
118 |
|
119 |
/*
|
120 |
* (non-Javadoc)
|
121 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineByte(int)
|
122 |
*/
|
123 |
public byte[][] getLineByte(int line) throws OperationNotSupportedException { |
124 |
throw new OperationNotSupportedException("Operation getLineByte not supported by cache with vertical stripes"); |
125 |
} |
126 |
|
127 |
/*
|
128 |
* (non-Javadoc)
|
129 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineShort(int)
|
130 |
*/
|
131 |
public short[][] getLineShort(int line) throws OperationNotSupportedException { |
132 |
throw new OperationNotSupportedException("Operation getLineShort not supported by cache with vertical stripes"); |
133 |
} |
134 |
|
135 |
/*
|
136 |
* (non-Javadoc)
|
137 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineInt(int)
|
138 |
*/
|
139 |
public int[][] getLineInt(int line) throws OperationNotSupportedException { |
140 |
throw new OperationNotSupportedException("Operation getLineInt not supported by cache with vertical stripes"); |
141 |
} |
142 |
|
143 |
/*
|
144 |
* (non-Javadoc)
|
145 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFloat(int)
|
146 |
*/
|
147 |
public float[][] getLineFloat(int line) throws OperationNotSupportedException { |
148 |
throw new OperationNotSupportedException("Operation getLineFloat not supported by cache with vertical stripes"); |
149 |
} |
150 |
|
151 |
/*
|
152 |
* (non-Javadoc)
|
153 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineDouble(int)
|
154 |
*/
|
155 |
public double[][] getLineDouble(int line) throws OperationNotSupportedException { |
156 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
157 |
} |
158 |
|
159 |
//***********************************************
|
160 |
|
161 |
/*
|
162 |
* (non-Javadoc)
|
163 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineByte(byte[][], int)
|
164 |
*/
|
165 |
public void setLineByte(byte[][] data, int line) throws OperationNotSupportedException { |
166 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
167 |
} |
168 |
|
169 |
/*
|
170 |
* (non-Javadoc)
|
171 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineShort(short[][], int)
|
172 |
*/
|
173 |
public void setLineShort(short[][] data, int line) throws OperationNotSupportedException { |
174 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
175 |
} |
176 |
|
177 |
/*
|
178 |
* (non-Javadoc)
|
179 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInt(int[][], int)
|
180 |
*/
|
181 |
public void setLineInt(int[][] data, int line) throws OperationNotSupportedException { |
182 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
183 |
} |
184 |
|
185 |
/*
|
186 |
* (non-Javadoc)
|
187 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineFloat(float[][], int)
|
188 |
*/
|
189 |
public void setLineFloat(float[][] data, int line) throws OperationNotSupportedException { |
190 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
191 |
} |
192 |
|
193 |
/*
|
194 |
* (non-Javadoc)
|
195 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineDouble(double[][], int)
|
196 |
*/
|
197 |
public void setLineDouble(double[][] data, int line) throws OperationNotSupportedException { |
198 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
199 |
} |
200 |
|
201 |
//*********************************************************
|
202 |
|
203 |
/*
|
204 |
* (non-Javadoc)
|
205 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFromBandByte(int, int)
|
206 |
*/
|
207 |
public byte[] getLineFromBandByte(int line, int band) throws OperationNotSupportedException { |
208 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
209 |
} |
210 |
|
211 |
/*
|
212 |
* (non-Javadoc)
|
213 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFromBandShort(int, int)
|
214 |
*/
|
215 |
public short[] getLineFromBandShort(int line, int band) throws OperationNotSupportedException { |
216 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
217 |
} |
218 |
|
219 |
/*
|
220 |
* (non-Javadoc)
|
221 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFromBandInt(int, int)
|
222 |
*/
|
223 |
public int[] getLineFromBandInt(int line, int band) throws OperationNotSupportedException { |
224 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
225 |
} |
226 |
|
227 |
/*
|
228 |
* (non-Javadoc)
|
229 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFromBandFloat(int, int)
|
230 |
*/
|
231 |
public float[] getLineFromBandFloat(int line, int band) throws OperationNotSupportedException { |
232 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
233 |
} |
234 |
|
235 |
/*
|
236 |
* (non-Javadoc)
|
237 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getLineFromBandDouble(int, int)
|
238 |
*/
|
239 |
public double[] getLineFromBandDouble(int line, int band) throws OperationNotSupportedException { |
240 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
241 |
} |
242 |
|
243 |
//*********************************************************
|
244 |
|
245 |
/*
|
246 |
* (non-Javadoc)
|
247 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInBandByte(byte[], int, int)
|
248 |
*/
|
249 |
public void setLineInBandByte(byte[] data, int line, int band) throws OperationNotSupportedException { |
250 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
251 |
} |
252 |
|
253 |
/*
|
254 |
* (non-Javadoc)
|
255 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInBandShort(short[], int, int)
|
256 |
*/
|
257 |
public void setLineInBandShort(short[] data, int line, int band) throws OperationNotSupportedException { |
258 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
259 |
} |
260 |
|
261 |
/*
|
262 |
* (non-Javadoc)
|
263 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInBandInt(int[], int, int)
|
264 |
*/
|
265 |
public void setLineInBandInt(int[] data, int line, int band) throws OperationNotSupportedException { |
266 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
267 |
} |
268 |
|
269 |
/*
|
270 |
* (non-Javadoc)
|
271 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInBandFloat(float[], int, int)
|
272 |
*/
|
273 |
public void setLineInBandFloat(float[] data, int line, int band) throws OperationNotSupportedException { |
274 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
275 |
} |
276 |
|
277 |
/*
|
278 |
* (non-Javadoc)
|
279 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setLineInBandDouble(double[], int, int)
|
280 |
*/
|
281 |
public void setLineInBandDouble(double[] data, int line, int band) throws OperationNotSupportedException { |
282 |
throw new OperationNotSupportedException("Operation getLineDouble not supported by cache with vertical stripes"); |
283 |
} |
284 |
|
285 |
//*********************************************************
|
286 |
|
287 |
/*
|
288 |
* (non-Javadoc)
|
289 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemByte(int, int, int)
|
290 |
*/
|
291 |
public byte getElemByte(int line, int col, int band) { |
292 |
if(exists(col)) {
|
293 |
return cache.getAccessPage().getElemByte(line, (col & cache.getOffset()), band);
|
294 |
} |
295 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().byteValue() : BufferNoData.defaultByteNoDataValue;
|
296 |
} |
297 |
|
298 |
/*
|
299 |
* (non-Javadoc)
|
300 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemShort(int, int, int)
|
301 |
*/
|
302 |
public short getElemShort(int line, int col, int band) { |
303 |
if(exists(col)) {
|
304 |
return cache.getAccessPage().getElemShort(line, (col & cache.getOffset()), band);
|
305 |
} |
306 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().shortValue() : BufferNoData.defaultShortNoDataValue;
|
307 |
} |
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemInt(int, int, int)
|
312 |
*/
|
313 |
public int getElemInt(int line, int col, int band) { |
314 |
if(exists(col)) {
|
315 |
return cache.getAccessPage().getElemInt(line, (col & cache.getOffset()), band);
|
316 |
} |
317 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().intValue() : BufferNoData.defaultIntegerNoDataValue;
|
318 |
} |
319 |
|
320 |
/*
|
321 |
* (non-Javadoc)
|
322 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemFloat(int, int, int)
|
323 |
*/
|
324 |
public float getElemFloat(int line, int col, int band) { |
325 |
if(exists(col)) {
|
326 |
return cache.getAccessPage().getElemFloat(line, (col & cache.getOffset()), band);
|
327 |
} |
328 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().floatValue() : BufferNoData.defaultFloatNoDataValue;
|
329 |
} |
330 |
|
331 |
/*
|
332 |
* (non-Javadoc)
|
333 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemDouble(int, int, int)
|
334 |
*/
|
335 |
public double getElemDouble(int line, int col, int band) { |
336 |
if(exists(col)) {
|
337 |
return cache.getAccessPage().getElemDouble(line, (col & cache.getOffset()), band);
|
338 |
} |
339 |
return getNoDataValue().isDefined() ? getNoDataValue().getValue().doubleValue() : BufferNoData.defaultDoubleNoDataValue;
|
340 |
} |
341 |
|
342 |
//*********************************************************
|
343 |
|
344 |
/*
|
345 |
* (non-Javadoc)
|
346 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setElem(int, int, int, byte)
|
347 |
*/
|
348 |
public void setElem(int line, int col, int band, byte data) { |
349 |
if(exists(col)) {
|
350 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, data); |
351 |
} |
352 |
} |
353 |
|
354 |
/*
|
355 |
* (non-Javadoc)
|
356 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setElem(int, int, int, short)
|
357 |
*/
|
358 |
public void setElem(int line, int col, int band, short data) { |
359 |
if(exists(col)) {
|
360 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, data); |
361 |
} |
362 |
} |
363 |
|
364 |
/*
|
365 |
* (non-Javadoc)
|
366 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setElem(int, int, int, int)
|
367 |
*/
|
368 |
public void setElem(int line, int col, int band, int data) { |
369 |
if(exists(col)) {
|
370 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, data); |
371 |
} |
372 |
} |
373 |
|
374 |
/*
|
375 |
* (non-Javadoc)
|
376 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setElem(int, int, int, float)
|
377 |
*/
|
378 |
public void setElem(int line, int col, int band, float data) { |
379 |
if(exists(col)) {
|
380 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, data); |
381 |
} |
382 |
} |
383 |
|
384 |
/*
|
385 |
* (non-Javadoc)
|
386 |
* @see org.gvsig.raster.buffer.IRasterBuffer#setElem(int, int, int, double)
|
387 |
*/
|
388 |
public void setElem(int line, int col, int band, double data) { |
389 |
if(exists(col)) {
|
390 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, data); |
391 |
} |
392 |
} |
393 |
|
394 |
//*********************************************************
|
395 |
|
396 |
/*
|
397 |
* (non-Javadoc)
|
398 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getElemByte(int, int, byte[])
|
399 |
*/
|
400 |
public void getElemByte(int line, int col, byte[] data) { |
401 |
if(exists(line)) {
|
402 |
cache.getAccessPage().getElemByte( |
403 |
line, (col & cache.getOffset()), data); |
404 |
return;
|
405 |
} |
406 |
if(getNoDataValue().isDefined()) {
|
407 |
for (int iBand = 0; iBand < data.length; iBand++) |
408 |
data[iBand] = getNoDataValue().getValue().byteValue(); |
409 |
} else {
|
410 |
for (int iBand = 0; iBand < data.length; iBand++) |
411 |
data[iBand] = BufferNoData.defaultByteNoDataValue; |
412 |
} |
413 |
} |
414 |
|
415 |
public void getElemShort(int line, int col, short[] data) { |
416 |
if(exists(line)) {
|
417 |
cache.getAccessPage().getElemShort( |
418 |
line, (col & cache.getOffset()), data); |
419 |
return;
|
420 |
} |
421 |
if(getNoDataValue().isDefined()) {
|
422 |
for (int iBand = 0; iBand < data.length; iBand++) |
423 |
data[iBand] = getNoDataValue().getValue().shortValue(); |
424 |
} else {
|
425 |
for (int iBand = 0; iBand < data.length; iBand++) |
426 |
data[iBand] = BufferNoData.defaultShortNoDataValue; |
427 |
} |
428 |
} |
429 |
|
430 |
public void getElemInt(int line, int col, int[] data) { |
431 |
if(exists(line)) {
|
432 |
cache.getAccessPage().getElemInt( |
433 |
line, (col & cache.getOffset()), data); |
434 |
return;
|
435 |
} |
436 |
if(getNoDataValue().isDefined()) {
|
437 |
for (int iBand = 0; iBand < data.length; iBand++) |
438 |
data[iBand] = getNoDataValue().getValue().intValue(); |
439 |
} else {
|
440 |
for (int iBand = 0; iBand < data.length; iBand++) |
441 |
data[iBand] = BufferNoData.defaultIntegerNoDataValue; |
442 |
} |
443 |
} |
444 |
|
445 |
public void getElemFloat(int line, int col, float[] data) { |
446 |
if(exists(line)) {
|
447 |
cache.getAccessPage().getElemFloat( |
448 |
line, (col & cache.getOffset()), data); |
449 |
return;
|
450 |
} |
451 |
if(getNoDataValue().isDefined()) {
|
452 |
for (int iBand = 0; iBand < data.length; iBand++) |
453 |
data[iBand] = getNoDataValue().getValue().floatValue(); |
454 |
} else {
|
455 |
for (int iBand = 0; iBand < data.length; iBand++) |
456 |
data[iBand] = BufferNoData.defaultFloatNoDataValue; |
457 |
} |
458 |
} |
459 |
|
460 |
public void getElemDouble(int line, int col, double[] data) { |
461 |
if(exists(line)) {
|
462 |
cache.getAccessPage().getElemDouble( |
463 |
line, (col & cache.getOffset()), data); |
464 |
return;
|
465 |
} |
466 |
if(getNoDataValue().isDefined()) {
|
467 |
for (int iBand = 0; iBand < data.length; iBand++) |
468 |
data[iBand] = getNoDataValue().getValue().doubleValue(); |
469 |
} else {
|
470 |
for (int iBand = 0; iBand < data.length; iBand++) |
471 |
data[iBand] = BufferNoData.defaultDoubleNoDataValue; |
472 |
} |
473 |
} |
474 |
|
475 |
//*********************************************************
|
476 |
|
477 |
public void setElemByte(int line, int col, byte[] data) { |
478 |
if(exists(col)) {
|
479 |
cache.getAccessPage().setElemByte( |
480 |
line, (col & cache.getOffset()), data); |
481 |
} |
482 |
} |
483 |
|
484 |
public void setElemShort(int line, int col, short[] data) { |
485 |
if(exists(col)) {
|
486 |
cache.getAccessPage().setElemShort( |
487 |
line, (col & cache.getOffset()), data); |
488 |
} |
489 |
} |
490 |
|
491 |
public void setElemInt(int line, int col, int[] data) { |
492 |
if(exists(col)) {
|
493 |
cache.getAccessPage().setElemInt( |
494 |
line, (col & cache.getOffset()), data); |
495 |
} |
496 |
} |
497 |
|
498 |
public void setElemFloat(int line, int col, float[] data) { |
499 |
if(exists(col)) {
|
500 |
cache.getAccessPage().setElemFloat( |
501 |
line, (col & cache.getOffset()), data); |
502 |
} |
503 |
} |
504 |
|
505 |
public void setElemDouble(int line, int col, double[] data) { |
506 |
if(exists(col)) {
|
507 |
cache.getAccessPage().setElemDouble( |
508 |
line, (col & cache.getOffset()), data); |
509 |
} |
510 |
} |
511 |
|
512 |
//*********************************************************
|
513 |
|
514 |
public void assign(int band, byte value) { |
515 |
for(int line = 0; line < getHeight(); line ++) { |
516 |
boolean beginLine = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea |
517 |
for(int col = 0; col < getWidth(); col ++) { |
518 |
try {
|
519 |
if(beginLine) {
|
520 |
lru.cacheAccess(line, false);
|
521 |
beginLine = false;
|
522 |
} |
523 |
} catch (InvalidPageNumberException e) {
|
524 |
return;
|
525 |
} catch (InterruptedException e) { |
526 |
return;
|
527 |
} |
528 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, value); |
529 |
} |
530 |
} |
531 |
} |
532 |
|
533 |
public void assign(int band, short value) { |
534 |
for(int line = 0; line < getHeight(); line ++) { |
535 |
boolean beginLine = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea |
536 |
for(int col = 0; col < getWidth(); col ++) { |
537 |
try {
|
538 |
if(beginLine) {
|
539 |
lru.cacheAccess(line, false);
|
540 |
beginLine = false;
|
541 |
} |
542 |
} catch (InvalidPageNumberException e) {
|
543 |
return;
|
544 |
} catch (InterruptedException e) { |
545 |
return;
|
546 |
} |
547 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, value); |
548 |
} |
549 |
} |
550 |
} |
551 |
|
552 |
public void assign(int band, int value) { |
553 |
for(int line = 0; line < getHeight(); line ++) { |
554 |
boolean beginLine = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea |
555 |
for(int col = 0; col < getWidth(); col ++) { |
556 |
try {
|
557 |
if(beginLine) {
|
558 |
lru.cacheAccess(line, false);
|
559 |
beginLine = false;
|
560 |
} |
561 |
} catch (InvalidPageNumberException e) {
|
562 |
return;
|
563 |
} catch (InterruptedException e) { |
564 |
return;
|
565 |
} |
566 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, value); |
567 |
} |
568 |
} |
569 |
} |
570 |
|
571 |
public void assign(int band, float value) { |
572 |
for(int line = 0; line < getHeight(); line ++) { |
573 |
boolean beginLine = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea |
574 |
for(int col = 0; col < getWidth(); col ++) { |
575 |
try {
|
576 |
if(beginLine) {
|
577 |
lru.cacheAccess(line, false);
|
578 |
beginLine = false;
|
579 |
} |
580 |
} catch (InvalidPageNumberException e) {
|
581 |
return;
|
582 |
} catch (InterruptedException e) { |
583 |
return;
|
584 |
} |
585 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, value); |
586 |
} |
587 |
} |
588 |
} |
589 |
|
590 |
public void assign(int band, double value) { |
591 |
for(int line = 0; line < getHeight(); line ++){ |
592 |
boolean beginLine = true; //Para acelerar solo comprobar? si la p?gina est? en cach? cada vez que empieza una l?nea |
593 |
for(int col = 0; col < getWidth(); col ++){ |
594 |
try {
|
595 |
if(beginLine) {
|
596 |
lru.cacheAccess(line, false);
|
597 |
beginLine = false;
|
598 |
} |
599 |
} catch (InvalidPageNumberException e) {
|
600 |
return;
|
601 |
} catch (InterruptedException e) { |
602 |
return;
|
603 |
} |
604 |
cache.getAccessPage().setElem(line, (col & cache.getOffset()), band, value); |
605 |
} |
606 |
} |
607 |
} |
608 |
|
609 |
//**************************************
|
610 |
//**********BANDS OPERATIONS************
|
611 |
//**************************************
|
612 |
|
613 |
/*
|
614 |
* (non-Javadoc)
|
615 |
* @see org.gvsig.raster.buffer.IRasterBuffer#removeBand(int)
|
616 |
*/
|
617 |
public void removeBand(int iBand) throws IOException { |
618 |
if(iBand < 0 || iBand >= getBandCount()) |
619 |
return;
|
620 |
cache.removeBand(iBand); |
621 |
bands.remove(iBand); |
622 |
bandLessLess(); |
623 |
} |
624 |
|
625 |
/*
|
626 |
* (non-Javadoc)
|
627 |
* @see org.gvsig.raster.buffer.IRasterBuffer#addBand(int)
|
628 |
*/
|
629 |
public Band addBand(int pos) throws IOException { |
630 |
cache.addBand(pos); |
631 |
CacheBand cb = bands.add(pos, cache, lru, getDataType()); |
632 |
bandPlusPlus(); |
633 |
return cb;
|
634 |
} |
635 |
|
636 |
/*
|
637 |
* (non-Javadoc)
|
638 |
* @see org.gvsig.raster.buffer.IRasterBuffer#getBands()
|
639 |
*/
|
640 |
public Band[] getBands() { |
641 |
Band[] b = new Band[bands.size()]; |
642 |
for (int i = 0; i < bands.size(); i++) |
643 |
b[i] = bands.get(i); |
644 |
return b;
|
645 |
} |
646 |
|
647 |
/*
|
648 |
* (non-Javadoc)
|
649 |
* @see org.fv.raster.buffer.IRasterBuffer#getBandList()
|
650 |
*/
|
651 |
public ArrayList<Band> getBandList() { |
652 |
ArrayList<Band> result = new ArrayList<Band>(); |
653 |
for (int i = 0; i < bands.size(); i++) |
654 |
result.add(bands.get(i)); |
655 |
return result;
|
656 |
} |
657 |
|
658 |
/**
|
659 |
* Set the band to the selected position. To assign a cache band firstly it will
|
660 |
* check if the band to assign is compatible, then it will
|
661 |
* load in each page in disk the page indicated by the target object. Finally it will
|
662 |
* assign the Cache object to the new band.
|
663 |
* @throws IOException
|
664 |
*/
|
665 |
public void assignBand(int pos, Band band) throws IOException, BandNotCompatibleException { |
666 |
if( band.getDataType() != getDataType())
|
667 |
throw new BandNotCompatibleException("Data type not compatible"); |
668 |
if(getBand(0) != null && band.getClass() != getBand(0).getClass()) |
669 |
throw new BandNotCompatibleException("buffer type not compatible"); |
670 |
if( band.getHeight() != cache.getDataSourceHeight() || band.getWidth() != cache.getDataSourceWidth())
|
671 |
throw new BandNotCompatibleException("Bands with diferents sizes"); |
672 |
|
673 |
cache.addBand(pos, band); |
674 |
bands.add(pos, cache, lru, getDataType()); |
675 |
bandPlusPlus(); |
676 |
} |
677 |
|
678 |
/*
|
679 |
* (non-Javadoc)
|
680 |
* @see org.gvsig.raster.driver.IRasterBuffer#getBandByRef(int)
|
681 |
*/
|
682 |
public Band getBand(int band) { |
683 |
if(bands.size() == 0 || band < 0 || band > (bands.size() - 1)) |
684 |
return null; |
685 |
return bands.get(band);
|
686 |
} |
687 |
|
688 |
/*
|
689 |
* (non-Javadoc)
|
690 |
* @see org.gvsig.raster.driver.IRasterBuffer#getBand(int)
|
691 |
*/
|
692 |
public Band getBandCopy(int band) { |
693 |
switch (getDataType()) {
|
694 |
case RasterBuffer.TYPE_BYTE:
|
695 |
return (ByteBand)((ByteBand)bands.get(band)).clone();
|
696 |
case RasterBuffer.TYPE_SHORT:
|
697 |
return (ShortBand)((ShortBand)bands.get(band)).clone();
|
698 |
case RasterBuffer.TYPE_INT:
|
699 |
return (IntBand)((IntBand)bands.get(band)).clone();
|
700 |
case RasterBuffer.TYPE_FLOAT:
|
701 |
return (FloatBand)((FloatBand)bands.get(band)).clone();
|
702 |
case RasterBuffer.TYPE_DOUBLE:
|
703 |
return (DoubleBand)((DoubleBand)bands.get(band)).clone();
|
704 |
} |
705 |
return null; |
706 |
} |
707 |
|
708 |
/*
|
709 |
* (non-Javadoc)
|
710 |
* @see org.gvsig.fmap.driver.IRasterBuffer#getBandBuffer(int)
|
711 |
*/
|
712 |
public Buffer getBufferWithOneBand(int iBand) throws IOException { |
713 |
//Creamos un buffer del mismo tama?o que el original para que la estructura de cache
|
714 |
//sea la misma. Luego eliminaremos las bandas para a?adirle solo una.
|
715 |
RasterVertCacheBuffer rcb = new RasterVertCacheBuffer(getDataType(), getWidth(), getHeight(), getBandCount());
|
716 |
for (int i = getBandCount() - 1; i >= 0; i--) |
717 |
rcb.removeBand(i); |
718 |
try {
|
719 |
rcb.assignBand(0, getBand(iBand));
|
720 |
} catch (BandNotCompatibleException e) {
|
721 |
//It can't be throwed
|
722 |
} |
723 |
return rcb;
|
724 |
} |
725 |
|
726 |
/*
|
727 |
* (non-Javadoc)
|
728 |
* @see org.gvsig.fmap.dataaccess.buffer.RasterBuffer#switchBands(int[])
|
729 |
*/
|
730 |
public void swapBands(int[] bandPosition) throws WrongParameterException, IOException { |
731 |
super.swapBands(bandPosition);
|
732 |
cache.swapBands(bandPosition); |
733 |
bands.swapBands(bandPosition); |
734 |
} |
735 |
|
736 |
/*
|
737 |
* (non-Javadoc)
|
738 |
* @see org.gvsig.fmap.driver.IRasterBuffer#swapBands(int, int)
|
739 |
*/
|
740 |
public void swapBands(int band1, int band2) throws WrongParameterException, IOException { |
741 |
if(band1 < 0 || band1 > getBandCount() - 1 || band2 < 0 || band2 > getBandCount() - 1) |
742 |
return;
|
743 |
|
744 |
int[] bandPosition = new int[getBandCount()]; |
745 |
for (int i = 0; i < bandPosition.length; i++) { |
746 |
if(i == band1)
|
747 |
bandPosition[i] = band2; |
748 |
else if(i == band2) |
749 |
bandPosition[i] = band1; |
750 |
else
|
751 |
bandPosition[i] = i; |
752 |
} |
753 |
swapBands(bandPosition); |
754 |
} |
755 |
|
756 |
/*
|
757 |
* (non-Javadoc)
|
758 |
* @see org.gvsig.fmap.driver.IRasterBuffer#copyBand(int, org.gvsig.fmap.dataaccess.buffer.IBand)
|
759 |
*/
|
760 |
public void copyBand(int iBand, Band band) throws BandNotCompatibleException, OperationNotSupportedException { |
761 |
super.copyBand(iBand, band);
|
762 |
} |
763 |
|
764 |
/*
|
765 |
* (non-Javadoc)
|
766 |
* @see org.gvsig.fmap.driver.IRasterBuffer#replicateBand(int, int)
|
767 |
*/
|
768 |
public void replicateBand(int orig, int dest) throws IOException { |
769 |
Band origBand = getBandCopy(orig); |
770 |
try {
|
771 |
assignBand(dest, origBand); |
772 |
} catch (BandNotCompatibleException e) {
|
773 |
//It can't be throwed
|
774 |
} |
775 |
} |
776 |
|
777 |
/**
|
778 |
* Create a band with the current cache information.
|
779 |
*/
|
780 |
public Band createBand(double defaultValue) { |
781 |
CacheVertImpl clonCache = cache.cloneStructure(); |
782 |
LRUAlgorithm lru = new LRUAlgorithm(clonCache);
|
783 |
for (int i = getBandCount() - 1; i >= 0 ; i--) { |
784 |
try {
|
785 |
clonCache.removeBand(i); |
786 |
} catch (IOException e) { |
787 |
return null; |
788 |
} |
789 |
} |
790 |
clonCache.createPages(1);
|
791 |
|
792 |
switch (getDataType()) {
|
793 |
case RasterBuffer.TYPE_BYTE:
|
794 |
ByteBand bb = new ByteBand(clonCache, lru, 0); |
795 |
bb.assign((byte)defaultValue);
|
796 |
return bb;
|
797 |
case RasterBuffer.TYPE_SHORT:
|
798 |
ShortBand sb = new ShortBand(clonCache, lru, 0); |
799 |
sb.assign((short)defaultValue);
|
800 |
return sb;
|
801 |
case RasterBuffer.TYPE_INT:
|
802 |
IntBand ib = new IntBand(clonCache, lru, 0); |
803 |
ib.assign((int)defaultValue);
|
804 |
return ib;
|
805 |
case RasterBuffer.TYPE_FLOAT:
|
806 |
FloatBand fb = new FloatBand(clonCache, lru, 0); |
807 |
fb.assign((float)defaultValue);
|
808 |
return fb;
|
809 |
case RasterBuffer.TYPE_DOUBLE:
|
810 |
DoubleBand db = new DoubleBand(clonCache, lru, 0); |
811 |
db.assign(defaultValue); |
812 |
return db;
|
813 |
} |
814 |
return null; |
815 |
} |
816 |
|
817 |
/*
|
818 |
* (non-Javadoc)
|
819 |
* @see org.gvsig.fmap.driver.IRasterBuffer#assignBandToNotValid(int)
|
820 |
*/
|
821 |
public void assignBandToNotValid(int iBand) { |
822 |
switch (getDataType()) {
|
823 |
case RasterBuffer.TYPE_BYTE:
|
824 |
for (int row = 0; row < getHeight(); row++) |
825 |
for (int col = 0; col < getWidth(); col++) |
826 |
setElem(row, col, iBand, (byte)notValidValue);
|
827 |
case RasterBuffer.TYPE_SHORT:
|
828 |
for (int row = 0; row < getHeight(); row++) |
829 |
for (int col = 0; col < getWidth(); col++) |
830 |
setElem(row, col, iBand, (short)notValidValue);
|
831 |
case RasterBuffer.TYPE_INT:
|
832 |
for (int row = 0; row < getHeight(); row++) |
833 |
for (int col = 0; col < getWidth(); col++) |
834 |
setElem(row, col, iBand, (int)notValidValue);
|
835 |
case RasterBuffer.TYPE_FLOAT:
|
836 |
for (int row = 0; row < getHeight(); row++) |
837 |
for (int col = 0; col < getWidth(); col++) |
838 |
setElem(row, col, iBand, (float)notValidValue);
|
839 |
case RasterBuffer.TYPE_DOUBLE:
|
840 |
for (int row = 0; row < getHeight(); row++) |
841 |
for (int col = 0; col < getWidth(); col++) |
842 |
setElem(row, col, iBand, (double)notValidValue);
|
843 |
} |
844 |
} |
845 |
|
846 |
/*
|
847 |
* (non-Javadoc)
|
848 |
* @see org.gvsig.raster.dataset.IRasterBuffer#free()
|
849 |
*/
|
850 |
public void free() throws IOException { |
851 |
cache.clearCache(); |
852 |
} |
853 |
|
854 |
/*
|
855 |
* (non-Javadoc)
|
856 |
* @see org.gvsig.fmap.driver.IRasterBuffer#cloneBuffer()
|
857 |
*/
|
858 |
public Buffer cloneBuffer(){ |
859 |
return null; |
860 |
} |
861 |
} |