gvsig-raster / org.gvsig.raster.cache / trunk / org.gvsig.raster.cache / org.gvsig.raster.cache.lib.impl / deprecated / buffer / impl / rocache / RasterReadOnlyBuffer.java @ 1939
History | View | Annotate | Download (30.3 KB)
1 |
package org.gvsig.raster.cache.buffer.impl.rocache; |
---|---|
2 |
|
3 |
import java.io.FileNotFoundException; |
4 |
import java.io.IOException; |
5 |
import java.util.ArrayList; |
6 |
|
7 |
import org.gvsig.raster.cache.buffer.Band; |
8 |
import org.gvsig.raster.cache.buffer.BufferDataSource; |
9 |
import org.gvsig.raster.cache.buffer.Buffer; |
10 |
import org.gvsig.raster.cache.buffer.BufferParam; |
11 |
import org.gvsig.raster.cache.buffer.PxTile; |
12 |
import org.gvsig.raster.cache.buffer.exception.BandNotCompatibleException; |
13 |
import org.gvsig.raster.cache.buffer.exception.OperationNotSupportedException; |
14 |
import org.gvsig.raster.cache.buffer.exception.WrongParameterException; |
15 |
import org.gvsig.raster.cache.buffer.impl.BufferCacheManagerImpl; |
16 |
import org.gvsig.raster.cache.buffer.impl.PxTileImpl; |
17 |
import org.gvsig.raster.cache.buffer.impl.RasterBuffer; |
18 |
import org.gvsig.raster.cache.buffer.impl.datasource.DriverException; |
19 |
|
20 |
/**
|
21 |
* Read Only buffer.
|
22 |
* This buffer has a reference to original raster. Firstly its load only two pages in memory. When more
|
23 |
* data out of those pages are required other stripes will be loaded.
|
24 |
*
|
25 |
* At the beginning the cache's structure is calculated creating an array of pieces. Each one of this pieces
|
26 |
* is represented by the object ReadOnlyStripe.
|
27 |
*
|
28 |
* @author Nacho Brodin (nachobrodin@gmail.com)
|
29 |
*
|
30 |
*/
|
31 |
public class RasterReadOnlyBuffer extends RasterBuffer { |
32 |
/**
|
33 |
* Pagina cargada
|
34 |
*/
|
35 |
private ArrayList<ReadOnlyCacheBand> bandList = null; |
36 |
/**
|
37 |
* N?mero de p?gina cargada en IBuffer
|
38 |
*/
|
39 |
private int loadedPage = -1; |
40 |
private int loadedSecondPage = -1; |
41 |
|
42 |
private int bitsPag = 0; |
43 |
|
44 |
/**
|
45 |
* N?mero total de p?ginas en las que se divide el raster
|
46 |
*/
|
47 |
private int nTotalPags = 0; |
48 |
|
49 |
private int[] possibleHeights = {2, 4, 8, 16, 32, 64, 128, 256, 512, 1024, 2048, 4096, 8192, 16384, 32768, 65536}; |
50 |
|
51 |
/**
|
52 |
* Para extraer el desplazamiento de una direcci?n (l?nea de raster) hay que hacer una operaci?n And con
|
53 |
* con la altura de la p?gina -1. Por ejemplo, una p?gina de 16 l?neas de altura el desplazamiento ser?
|
54 |
* 16 - 1 = 15 porque 15 en binario es 1111.
|
55 |
*
|
56 |
* Si queremos acceder a la linea del raster n?mero 83 (1010011) realizando la operaci?n And con el valor del
|
57 |
* desplazamiento obtenemos (0001111 & 1010011 = 0000011), es decir el valor 3 en decimal. Esto quiere decir
|
58 |
* que la l?nea 83 del raster es la 3 de su p?gina.
|
59 |
*/
|
60 |
private int offset = 1; |
61 |
/**
|
62 |
* Altura de la p?gina de cada banda en l?neas.
|
63 |
*/
|
64 |
private int hPag = 1; |
65 |
private BufferDataSource dataSource = null; |
66 |
private ArrayList<PxTile> stripeList = null; |
67 |
|
68 |
/**
|
69 |
* Constructor. Asigna las variables de inicializaci?n y crea la estructura de
|
70 |
* la cach? con los datos pasados.
|
71 |
* @param dataType Tipo de dato
|
72 |
* @param width Ancho
|
73 |
* @param getDataType() Alto
|
74 |
* @param bandNr Banda
|
75 |
* @param orig
|
76 |
* @throws DriverException
|
77 |
* @throws NotSupportedExtensionException
|
78 |
* @throws FileNotFoundException
|
79 |
*/
|
80 |
public RasterReadOnlyBuffer(BufferDataSource dataSource, int x, int y, int w, int h, int[] bands) { |
81 |
super(x, y, w, h, dataSource.getDataType(), bands.length);
|
82 |
this.dataSource = dataSource;
|
83 |
stripeList = new ArrayList<PxTile>(); |
84 |
createStructure(bands); |
85 |
} |
86 |
|
87 |
/**
|
88 |
* Constructor. Asigna las variables de inicializaci?n y crea la estructura de
|
89 |
* la cach? con los datos pasados.
|
90 |
* @param dataSource
|
91 |
* Datasource
|
92 |
* @param bands
|
93 |
*/
|
94 |
public RasterReadOnlyBuffer(BufferDataSource dataSource, int[] bands) { |
95 |
super( 0, |
96 |
0,
|
97 |
dataSource.getWidth(), |
98 |
dataSource.getHeight(), |
99 |
dataSource.getDataType(), |
100 |
bands.length); |
101 |
this.dataSource = dataSource;
|
102 |
stripeList = new ArrayList<PxTile>(); |
103 |
createStructure(bands); |
104 |
} |
105 |
|
106 |
/**
|
107 |
* Constructor. Asigna las variables de inicializaci?n y crea la estructura de
|
108 |
* la cach? con los datos pasados.
|
109 |
* @param dataSource
|
110 |
* Datasource
|
111 |
*/
|
112 |
public RasterReadOnlyBuffer(BufferDataSource dataSource) {
|
113 |
super( 0, |
114 |
0,
|
115 |
dataSource.getWidth(), |
116 |
dataSource.getHeight(), |
117 |
dataSource.getDataType(), |
118 |
dataSource.getBandCount()); |
119 |
this.dataSource = dataSource;
|
120 |
stripeList = new ArrayList<PxTile>(); |
121 |
int[] bands = new int[dataSource.getBandCount()]; |
122 |
for (int i = 0; i < bands.length; i++) { |
123 |
bands[i] = i; |
124 |
} |
125 |
createStructure(bands); |
126 |
} |
127 |
|
128 |
/**
|
129 |
* Constructor. Asigna las variables de inicializaci?n y crea la estructura de
|
130 |
* la cach? con los datos pasados.
|
131 |
* @param dataSource
|
132 |
* Datasource
|
133 |
*/
|
134 |
public RasterReadOnlyBuffer(BufferParam param) {
|
135 |
super( param.getX(),
|
136 |
param.getY(), |
137 |
param.getWidth(), |
138 |
param.getHeight(), |
139 |
param.getDataSource().getDataType(), |
140 |
param.getBandCount()); |
141 |
this.dataSource = param.getDataSource();
|
142 |
stripeList = new ArrayList<PxTile>(); |
143 |
createStructure(param.getBandList()); |
144 |
} |
145 |
|
146 |
/**
|
147 |
*
|
148 |
*/
|
149 |
private void createStructure(int[] bands) { |
150 |
//Pasamos los megas a bytes
|
151 |
double pageSize = BufferCacheManagerImpl.pageSize * 1048576; |
152 |
|
153 |
long pageSizePerBand = (long)(pageSize / getBandCount()); |
154 |
|
155 |
int dataSizePerBand = 0; |
156 |
if (getDataType() == Buffer.TYPE_BYTE) { |
157 |
dataSizePerBand = 1;
|
158 |
} else if ((getDataType() == Buffer.TYPE_SHORT) | (getDataType() == Buffer.TYPE_USHORT)) { |
159 |
dataSizePerBand = 2;
|
160 |
} else if (getDataType() == Buffer.TYPE_INT) { |
161 |
dataSizePerBand = 4;
|
162 |
} else if (getDataType() == Buffer.TYPE_FLOAT) { |
163 |
dataSizePerBand = 4;
|
164 |
} else if (getDataType() == Buffer.TYPE_DOUBLE) { |
165 |
dataSizePerBand = 8;
|
166 |
} |
167 |
|
168 |
//La altura de la p?gina depende del ancho de esta y del tipo de dato
|
169 |
for(int i = (possibleHeights.length - 1); i >= 0; i --) { |
170 |
long size = (long)getWidth() * (long)possibleHeights[i] * (long)dataSizePerBand; |
171 |
if(size <= pageSizePerBand) {
|
172 |
hPag = possibleHeights[i]; |
173 |
break;
|
174 |
} |
175 |
} |
176 |
|
177 |
//Calculamos el tama?o de p?gina en bytes
|
178 |
pageSizePerBand = getWidth() * hPag * dataSizePerBand; |
179 |
|
180 |
int h = hPag;
|
181 |
while(h > 1){ |
182 |
h >>= 1;
|
183 |
bitsPag ++; |
184 |
} |
185 |
|
186 |
//Calculamos el n?mero total de p?ginas en cach?
|
187 |
nTotalPags = (int)Math.ceil((double)getHeight() / (double)hPag); |
188 |
int fullPages = (int)Math.floor((double)getHeight() / (double)hPag); |
189 |
|
190 |
//Calculamos la lista de franjas con sus coordenadas
|
191 |
int y = 0; |
192 |
int x = 0; |
193 |
for (int i = 0; i < fullPages; i++) { |
194 |
stripeList.add(new PxTileImpl(x, y, getWidth(), hPag));
|
195 |
y += hPag; |
196 |
} |
197 |
offset = hPag - 1;
|
198 |
|
199 |
int hLastPage = getHeight() - (fullPages * hPag);
|
200 |
for (int i = fullPages; i < nTotalPags; i++) |
201 |
stripeList.add(new PxTileImpl(x, y, getWidth(), hLastPage));
|
202 |
|
203 |
//Creamos las p?ginas en memoria
|
204 |
//createMemoryPages();
|
205 |
createBands(bands); |
206 |
} |
207 |
|
208 |
private void createBands(int[] bands) { |
209 |
bandList = new ArrayList<ReadOnlyCacheBand>(); |
210 |
for (int i = 0; i < bands.length; i++) { |
211 |
BufferDataSource ds = dataSource.clone(); |
212 |
ds.setSelectedBand(bands[i]); |
213 |
switch (getDataType()) {
|
214 |
case RasterBuffer.TYPE_BYTE:
|
215 |
bandList.add(new ByteBand(stripeList, ds, offset, bitsPag, bands[i], getWidth(), getHeight()));
|
216 |
break;
|
217 |
case RasterBuffer.TYPE_SHORT:
|
218 |
bandList.add(new ShortBand(stripeList, ds, offset, bitsPag, bands[i], getWidth(), getHeight()));
|
219 |
break;
|
220 |
case RasterBuffer.TYPE_INT:
|
221 |
bandList.add(new IntBand(stripeList, ds, offset, bitsPag, bands[i], getWidth(), getHeight()));
|
222 |
break;
|
223 |
case RasterBuffer.TYPE_FLOAT:
|
224 |
bandList.add(new FloatBand(stripeList, ds, offset, bitsPag, bands[i], getWidth(), getHeight()));
|
225 |
break;
|
226 |
case RasterBuffer.TYPE_DOUBLE:
|
227 |
bandList.add(new DoubleBand(stripeList, ds, offset, bitsPag, bands[i], getWidth(), getHeight()));
|
228 |
break;
|
229 |
} |
230 |
} |
231 |
} |
232 |
|
233 |
/**
|
234 |
* Load a page with data from disk
|
235 |
* @param nPage
|
236 |
*/
|
237 |
private void loadPage(int nPage) { |
238 |
if(loadedSecondPage == nPage) {
|
239 |
for (int i = 0; i < bandList.size(); i++) |
240 |
bandList.get(i).swapPages(); |
241 |
this.loadedPage = bandList.get(0).loadedPage; |
242 |
this.loadedSecondPage = bandList.get(0).loadedSecondPage; |
243 |
return;
|
244 |
} |
245 |
|
246 |
for (int i = 0; i < getBandCount(); i++) |
247 |
bandList.get(i).loadPage(nPage); |
248 |
this.loadedPage = bandList.get(0).loadedPage; |
249 |
this.loadedSecondPage = bandList.get(0).loadedSecondPage; |
250 |
} |
251 |
|
252 |
/*
|
253 |
* (non-Javadoc)
|
254 |
* @see org.gvsig.raster.cache.buffer.Buffer#isWritable()
|
255 |
*/
|
256 |
public boolean isWritable() { |
257 |
return false; |
258 |
} |
259 |
|
260 |
public void addDrawableBands(int[] bands) { |
261 |
stripeList = new ArrayList<PxTile>(); |
262 |
createStructure(bands); |
263 |
} |
264 |
|
265 |
//*********************************************************
|
266 |
|
267 |
/*
|
268 |
* (non-Javadoc)
|
269 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineByte(int)
|
270 |
*/
|
271 |
public byte[][] getLineByte(int line) throws OperationNotSupportedException { |
272 |
int pag = line >> bitsPag;
|
273 |
if(pag != loadedPage)
|
274 |
loadPage(pag); |
275 |
byte[][] result = new byte[getBandCount()][]; |
276 |
for (int i = 0; i < getBandCount(); i++) |
277 |
result[i] = bandList.get(i).page.getLineByte(line & offset)[0];
|
278 |
return result;
|
279 |
} |
280 |
|
281 |
/*
|
282 |
* (non-Javadoc)
|
283 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineShort(int)
|
284 |
*/
|
285 |
public short[][] getLineShort(int line) throws OperationNotSupportedException { |
286 |
int pag = line >> bitsPag;
|
287 |
if(pag != loadedPage)
|
288 |
loadPage(pag); |
289 |
short[][] result = new short[getBandCount()][]; |
290 |
for (int i = 0; i < getBandCount(); i++) |
291 |
result[i] = bandList.get(i).page.getLineShort(line & offset)[0];
|
292 |
return result;
|
293 |
} |
294 |
|
295 |
/*
|
296 |
* (non-Javadoc)
|
297 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineInt(int)
|
298 |
*/
|
299 |
public int[][] getLineInt(int line) throws OperationNotSupportedException { |
300 |
int pag = line >> bitsPag;
|
301 |
if(pag != loadedPage)
|
302 |
loadPage(pag); |
303 |
int[][] result = new int[getBandCount()][]; |
304 |
for (int i = 0; i < getBandCount(); i++) |
305 |
result[i] = bandList.get(i).page.getLineInt(line & offset)[0];
|
306 |
return result;
|
307 |
} |
308 |
|
309 |
/*
|
310 |
* (non-Javadoc)
|
311 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFloat(int)
|
312 |
*/
|
313 |
public float[][] getLineFloat(int line) throws OperationNotSupportedException { |
314 |
int pag = line >> bitsPag;
|
315 |
if(pag != loadedPage)
|
316 |
loadPage(pag); |
317 |
float[][] result = new float[getBandCount()][]; |
318 |
for (int i = 0; i < getBandCount(); i++) |
319 |
result[i] = bandList.get(i).page.getLineFloat(line & offset)[0];
|
320 |
return result;
|
321 |
} |
322 |
|
323 |
/*
|
324 |
* (non-Javadoc)
|
325 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineDouble(int)
|
326 |
*/
|
327 |
public double[][] getLineDouble(int line) throws OperationNotSupportedException { |
328 |
int pag = line >> bitsPag;
|
329 |
if(pag != loadedPage)
|
330 |
loadPage(pag); |
331 |
double[][] result = new double[getBandCount()][]; |
332 |
for (int i = 0; i < getBandCount(); i++) |
333 |
result[i] = bandList.get(i).page.getLineDouble(line & offset)[0];
|
334 |
return result;
|
335 |
} |
336 |
|
337 |
//*********************************************************
|
338 |
|
339 |
/*
|
340 |
* (non-Javadoc)
|
341 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFromBandByte(int, int)
|
342 |
*/
|
343 |
public byte[] getLineFromBandByte(int line, int band) throws OperationNotSupportedException { |
344 |
int pag = line >> bitsPag;
|
345 |
if(pag != loadedPage)
|
346 |
loadPage(pag); |
347 |
return this.bandList.get(band).page.getLineFromBandByte(line & offset, 0); |
348 |
} |
349 |
|
350 |
/*
|
351 |
* (non-Javadoc)
|
352 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFromBandShort(int, int)
|
353 |
*/
|
354 |
public short[] getLineFromBandShort(int line, int band) throws OperationNotSupportedException { |
355 |
int pag = line >> bitsPag;
|
356 |
if(pag != loadedPage)
|
357 |
loadPage(pag); |
358 |
return this.bandList.get(band).page.getLineFromBandShort(line & offset, 0); |
359 |
} |
360 |
|
361 |
/*
|
362 |
* (non-Javadoc)
|
363 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFromBandInt(int, int)
|
364 |
*/
|
365 |
public int[] getLineFromBandInt(int line, int band) throws OperationNotSupportedException { |
366 |
int pag = line >> bitsPag;
|
367 |
if(pag != loadedPage)
|
368 |
loadPage(pag); |
369 |
return this.bandList.get(band).page.getLineFromBandInt(line & offset, 0); |
370 |
} |
371 |
|
372 |
/*
|
373 |
* (non-Javadoc)
|
374 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFromBandFloat(int, int)
|
375 |
*/
|
376 |
public float[] getLineFromBandFloat(int line, int band) throws OperationNotSupportedException { |
377 |
int pag = line >> bitsPag;
|
378 |
if(pag != loadedPage)
|
379 |
loadPage(pag); |
380 |
return this.bandList.get(band).page.getLineFromBandFloat(line & offset, 0); |
381 |
} |
382 |
|
383 |
/*
|
384 |
* (non-Javadoc)
|
385 |
* @see org.gvsig.raster.cache.buffer.Buffer#getLineFromBandDouble(int, int)
|
386 |
*/
|
387 |
public double[] getLineFromBandDouble(int line, int band) throws OperationNotSupportedException { |
388 |
int pag = line >> bitsPag;
|
389 |
if(pag != loadedPage)
|
390 |
loadPage(pag); |
391 |
return this.bandList.get(band).page.getLineFromBandDouble(line & offset, 0); |
392 |
} |
393 |
|
394 |
//*********************************************************
|
395 |
|
396 |
/*
|
397 |
* (non-Javadoc)
|
398 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemByte(int, int, int)
|
399 |
*/
|
400 |
public byte getElemByte(int line, int col, int band) { |
401 |
int pag = line >> bitsPag;
|
402 |
if(pag != loadedPage)
|
403 |
loadPage(pag); |
404 |
return this.bandList.get(band).page.getElemByte(line & offset, col, 0); |
405 |
} |
406 |
|
407 |
/*
|
408 |
* (non-Javadoc)
|
409 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemShort(int, int, int)
|
410 |
*/
|
411 |
public short getElemShort(int line, int col, int band) { |
412 |
int pag = line >> bitsPag;
|
413 |
if(pag != loadedPage)
|
414 |
loadPage(pag); |
415 |
return this.bandList.get(band).page.getElemShort(line & offset, col, 0); |
416 |
} |
417 |
|
418 |
/*
|
419 |
* (non-Javadoc)
|
420 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemInt(int, int, int)
|
421 |
*/
|
422 |
public int getElemInt(int line, int col, int band) { |
423 |
int pag = line >> bitsPag;
|
424 |
if(pag != loadedPage)
|
425 |
loadPage(pag); |
426 |
return this.bandList.get(band).page.getElemInt(line & offset, col, 0); |
427 |
} |
428 |
|
429 |
/*
|
430 |
* (non-Javadoc)
|
431 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemFloat(int, int, int)
|
432 |
*/
|
433 |
public float getElemFloat(int line, int col, int band) { |
434 |
int pag = line >> bitsPag;
|
435 |
if(pag != loadedPage)
|
436 |
loadPage(pag); |
437 |
return this.bandList.get(band).page.getElemFloat(line & offset, col, 0); |
438 |
} |
439 |
|
440 |
/*
|
441 |
* (non-Javadoc)
|
442 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemDouble(int, int, int)
|
443 |
*/
|
444 |
public double getElemDouble(int line, int col, int band) { |
445 |
int pag = line >> bitsPag;
|
446 |
if(pag != loadedPage)
|
447 |
loadPage(pag); |
448 |
return this.bandList.get(band).page.getElemDouble(line & offset, col, 0); |
449 |
} |
450 |
|
451 |
//*********************************************************
|
452 |
|
453 |
/*
|
454 |
* (non-Javadoc)
|
455 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemByte(int, int, byte[])
|
456 |
*/
|
457 |
public void getElemByte(int line, int col, byte[] data) { |
458 |
int pag = line >> bitsPag;
|
459 |
if(pag != loadedPage)
|
460 |
loadPage(pag); |
461 |
for (int i = 0; i < getBandCount(); i++) |
462 |
data[i] = bandList.get(i).page.getElemByte(line & offset, col, 0);
|
463 |
} |
464 |
|
465 |
/*
|
466 |
* (non-Javadoc)
|
467 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemShort(int, int, short[])
|
468 |
*/
|
469 |
public void getElemShort(int line, int col, short[] data) { |
470 |
int pag = line >> bitsPag;
|
471 |
if(pag != loadedPage)
|
472 |
loadPage(pag); |
473 |
for (int i = 0; i < getBandCount(); i++) |
474 |
data[i] = bandList.get(i).page.getElemShort(line & offset, col, 0);
|
475 |
} |
476 |
|
477 |
/*
|
478 |
* (non-Javadoc)
|
479 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemInt(int, int, int[])
|
480 |
*/
|
481 |
public void getElemInt(int line, int col, int[] data) { |
482 |
int pag = line >> bitsPag;
|
483 |
if(pag != loadedPage)
|
484 |
loadPage(pag); |
485 |
for (int i = 0; i < getBandCount(); i++) |
486 |
data[i] = bandList.get(i).page.getElemInt(line & offset, col, 0);
|
487 |
} |
488 |
|
489 |
/*
|
490 |
* (non-Javadoc)
|
491 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemFloat(int, int, float[])
|
492 |
*/
|
493 |
public void getElemFloat(int line, int col, float[] data) { |
494 |
int pag = line >> bitsPag;
|
495 |
if(pag != loadedPage)
|
496 |
loadPage(pag); |
497 |
for (int i = 0; i < getBandCount(); i++) |
498 |
data[i] = bandList.get(i).page.getElemFloat(line & offset, col, 0);
|
499 |
} |
500 |
|
501 |
/*
|
502 |
* (non-Javadoc)
|
503 |
* @see org.gvsig.raster.cache.buffer.Buffer#getElemDouble(int, int, double[])
|
504 |
*/
|
505 |
public void getElemDouble(int line, int col, double[] data) { |
506 |
int pag = line >> bitsPag;
|
507 |
if(pag != loadedPage)
|
508 |
loadPage(pag); |
509 |
for (int i = 0; i < getBandCount(); i++) |
510 |
data[i] = bandList.get(i).page.getElemDouble(line & offset, col, 0);
|
511 |
} |
512 |
|
513 |
//*********************************************************
|
514 |
|
515 |
/*
|
516 |
* (non-Javadoc)
|
517 |
* @see org.gvsig.raster.cache.buffer.Buffer#assignBandToNotValid(int)
|
518 |
*/
|
519 |
public void assignBandToNotValid(int iBand) throws OperationNotSupportedException { |
520 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
521 |
} |
522 |
|
523 |
/*
|
524 |
* (non-Javadoc)
|
525 |
* @see org.gvsig.raster.cache.buffer.Buffer#assign(int, byte)
|
526 |
*/
|
527 |
public void assign(int band, byte value) throws OperationNotSupportedException { |
528 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
529 |
} |
530 |
|
531 |
/*
|
532 |
* (non-Javadoc)
|
533 |
* @see org.gvsig.raster.cache.buffer.Buffer#assign(int, short)
|
534 |
*/
|
535 |
public void assign(int band, short value) throws OperationNotSupportedException { |
536 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
537 |
} |
538 |
|
539 |
/*
|
540 |
* (non-Javadoc)
|
541 |
* @see org.gvsig.raster.cache.buffer.Buffer#assign(int, int)
|
542 |
*/
|
543 |
public void assign(int band, int value) throws OperationNotSupportedException { |
544 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
545 |
} |
546 |
|
547 |
/*
|
548 |
* (non-Javadoc)
|
549 |
* @see org.gvsig.raster.cache.buffer.Buffer#assign(int, float)
|
550 |
*/
|
551 |
public void assign(int band, float value) throws OperationNotSupportedException { |
552 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
553 |
} |
554 |
|
555 |
/*
|
556 |
* (non-Javadoc)
|
557 |
* @see org.gvsig.raster.cache.buffer.Buffer#assign(int, double)
|
558 |
*/
|
559 |
public void assign(int band, double value) throws OperationNotSupportedException { |
560 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
561 |
} |
562 |
|
563 |
/*
|
564 |
* (non-Javadoc)
|
565 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElem(int, int, int, byte)
|
566 |
*/
|
567 |
public void setElem(int line, int col, int band, byte data) throws OperationNotSupportedException { |
568 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
569 |
} |
570 |
|
571 |
/*
|
572 |
* (non-Javadoc)
|
573 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElem(int, int, int, short)
|
574 |
*/
|
575 |
public void setElem(int line, int col, int band, short data) throws OperationNotSupportedException { |
576 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
577 |
} |
578 |
|
579 |
/*
|
580 |
* (non-Javadoc)
|
581 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElem(int, int, int, int)
|
582 |
*/
|
583 |
public void setElem(int line, int col, int band, int data) throws OperationNotSupportedException { |
584 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
585 |
} |
586 |
|
587 |
/*
|
588 |
* (non-Javadoc)
|
589 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElem(int, int, int, float)
|
590 |
*/
|
591 |
public void setElem(int line, int col, int band, float data) throws OperationNotSupportedException { |
592 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
593 |
} |
594 |
|
595 |
/*
|
596 |
* (non-Javadoc)
|
597 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElem(int, int, int, double)
|
598 |
*/
|
599 |
public void setElem(int line, int col, int band, double data) throws OperationNotSupportedException { |
600 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
601 |
} |
602 |
|
603 |
/*
|
604 |
* (non-Javadoc)
|
605 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElemByte(int, int, byte[])
|
606 |
*/
|
607 |
public void setElemByte(int line, int col, byte[] data) throws OperationNotSupportedException { |
608 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
609 |
} |
610 |
|
611 |
/*
|
612 |
* (non-Javadoc)
|
613 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElemDouble(int, int, double[])
|
614 |
*/
|
615 |
public void setElemDouble(int line, int col, double[] data) throws OperationNotSupportedException { |
616 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
617 |
} |
618 |
|
619 |
/*
|
620 |
* (non-Javadoc)
|
621 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElemFloat(int, int, float[])
|
622 |
*/
|
623 |
public void setElemFloat(int line, int col, float[] data) throws OperationNotSupportedException { |
624 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
625 |
} |
626 |
|
627 |
/*
|
628 |
* (non-Javadoc)
|
629 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElemInt(int, int, int[])
|
630 |
*/
|
631 |
public void setElemInt(int line, int col, int[] data) throws OperationNotSupportedException { |
632 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
633 |
} |
634 |
|
635 |
/*
|
636 |
* (non-Javadoc)
|
637 |
* @see org.gvsig.raster.cache.buffer.Buffer#setElemShort(int, int, short[])
|
638 |
*/
|
639 |
public void setElemShort(int line, int col, short[] data) throws OperationNotSupportedException { |
640 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
641 |
} |
642 |
|
643 |
/*
|
644 |
* (non-Javadoc)
|
645 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineByte(byte[][], int)
|
646 |
*/
|
647 |
public void setLineByte(byte[][] data, int line) throws OperationNotSupportedException { |
648 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
649 |
} |
650 |
|
651 |
/*
|
652 |
* (non-Javadoc)
|
653 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineDouble(double[][], int)
|
654 |
*/
|
655 |
public void setLineDouble(double[][] data, int line) throws OperationNotSupportedException { |
656 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
657 |
} |
658 |
|
659 |
/*
|
660 |
* (non-Javadoc)
|
661 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineFloat(float[][], int)
|
662 |
*/
|
663 |
public void setLineFloat(float[][] data, int line) throws OperationNotSupportedException { |
664 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
665 |
} |
666 |
|
667 |
/*
|
668 |
* (non-Javadoc)
|
669 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInBandByte(byte[], int, int)
|
670 |
*/
|
671 |
public void setLineInBandByte(byte[] data, int line, int band) throws OperationNotSupportedException { |
672 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
673 |
} |
674 |
|
675 |
/*
|
676 |
* (non-Javadoc)
|
677 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInBandDouble(double[], int, int)
|
678 |
*/
|
679 |
public void setLineInBandDouble(double[] data, int line, int band) throws OperationNotSupportedException { |
680 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
681 |
} |
682 |
|
683 |
/*
|
684 |
* (non-Javadoc)
|
685 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInBandFloat(float[], int, int)
|
686 |
*/
|
687 |
public void setLineInBandFloat(float[] data, int line, int band) throws OperationNotSupportedException { |
688 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
689 |
} |
690 |
|
691 |
/*
|
692 |
* (non-Javadoc)
|
693 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInBandInt(int[], int, int)
|
694 |
*/
|
695 |
public void setLineInBandInt(int[] data, int line, int band) throws OperationNotSupportedException { |
696 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
697 |
} |
698 |
|
699 |
/*
|
700 |
* (non-Javadoc)
|
701 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInBandShort(short[], int, int)
|
702 |
*/
|
703 |
public void setLineInBandShort(short[] data, int line, int band) throws OperationNotSupportedException { |
704 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
705 |
} |
706 |
|
707 |
/*
|
708 |
* (non-Javadoc)
|
709 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineInt(int[][], int)
|
710 |
*/
|
711 |
public void setLineInt(int[][] data, int line) throws OperationNotSupportedException { |
712 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
713 |
} |
714 |
|
715 |
/*
|
716 |
* (non-Javadoc)
|
717 |
* @see org.gvsig.raster.cache.buffer.Buffer#setLineShort(short[][], int)
|
718 |
*/
|
719 |
public void setLineShort(short[][] data, int line) throws OperationNotSupportedException { |
720 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
721 |
} |
722 |
|
723 |
//**************************************
|
724 |
//**********BANDS OPERATIONS************
|
725 |
//**************************************
|
726 |
|
727 |
/*
|
728 |
* (non-Javadoc)
|
729 |
* @see org.gvsig.raster.cache.buffer.impl.RasterBuffer#swapBands(int[])
|
730 |
*/
|
731 |
public void swapBands(int[] bandPosition) throws WrongParameterException, IOException{ |
732 |
super.swapBands(bandPosition);
|
733 |
ArrayList<ReadOnlyCacheBand> result = new ArrayList<ReadOnlyCacheBand>(); |
734 |
for (int i = 0; i < bandList.size(); i++) |
735 |
result.add(bandList.get(bandPosition[i])); |
736 |
bandList = result; |
737 |
} |
738 |
|
739 |
/*
|
740 |
* (non-Javadoc)
|
741 |
* @see org.gvsig.raster.cache.buffer.Buffer#getBands()
|
742 |
*/
|
743 |
public Band[] getBands() { |
744 |
Band[] result = new Band[bandList.size()]; |
745 |
for (int i = 0; i < result.length; i++) |
746 |
result[i] = bandList.get(i); |
747 |
return result;
|
748 |
} |
749 |
|
750 |
/*
|
751 |
* (non-Javadoc)
|
752 |
* @see org.gvsig.raster.cache.buffer.Buffer#getBandList()
|
753 |
*/
|
754 |
public ArrayList<Band> getBandList() { |
755 |
ArrayList<Band> result = new ArrayList<Band>(); |
756 |
for (int i = 0; i < bandList.size(); i++) |
757 |
result.add(bandList.get(i)); |
758 |
return result;
|
759 |
} |
760 |
|
761 |
/*
|
762 |
* (non-Javadoc)
|
763 |
* @see org.gvsig.raster.cache.buffer.Buffer#getBand(int)
|
764 |
*/
|
765 |
public Band getBand(int band){ |
766 |
return this.bandList.get(band); |
767 |
} |
768 |
|
769 |
/*
|
770 |
* (non-Javadoc)
|
771 |
* @see org.gvsig.raster.cache.buffer.impl.RasterBuffer#swapBands(int, int)
|
772 |
*/
|
773 |
public void swapBands(int band1, int band2) throws WrongParameterException, IOException { |
774 |
ReadOnlyCacheBand aux1 = bandList.get(band1); |
775 |
ReadOnlyCacheBand aux2 = bandList.get(band2); |
776 |
|
777 |
bandList.remove(band1); |
778 |
bandList.add(band1, aux2); |
779 |
bandList.remove(band2); |
780 |
bandList.add(band2, aux1); |
781 |
} |
782 |
|
783 |
/*
|
784 |
* (non-Javadoc)
|
785 |
* @see org.gvsig.raster.cache.buffer.Buffer#removeBand(int)
|
786 |
*/
|
787 |
public void removeBand(int pos) throws IOException { |
788 |
bandList.remove(pos); |
789 |
bandLessLess(); |
790 |
} |
791 |
|
792 |
/*
|
793 |
* (non-Javadoc)
|
794 |
* @see org.gvsig.raster.cache.buffer.Buffer#addBand(int)
|
795 |
*/
|
796 |
public Band addBand(int pos) throws IOException { |
797 |
bandPlusPlus(); |
798 |
switch (getDataType()) {
|
799 |
case RasterBuffer.TYPE_BYTE:
|
800 |
ByteBand bb = new ByteBand(stripeList, null, offset, bitsPag, 0, getWidth(), getHeight()); |
801 |
bandList.add(pos, bb); |
802 |
return bb;
|
803 |
case RasterBuffer.TYPE_SHORT:
|
804 |
ShortBand sb = new ShortBand(stripeList, null, offset, bitsPag, 0, getWidth(), getHeight()); |
805 |
bandList.add(pos, sb); |
806 |
return sb;
|
807 |
case RasterBuffer.TYPE_INT:
|
808 |
IntBand ib = new IntBand(stripeList, null, offset, bitsPag, 0, getWidth(), getHeight()); |
809 |
bandList.add(pos, ib); |
810 |
return ib;
|
811 |
case RasterBuffer.TYPE_FLOAT:
|
812 |
FloatBand fb = new FloatBand(stripeList, null, offset, bitsPag, 0, getWidth(), getHeight()); |
813 |
bandList.add(pos, fb); |
814 |
return fb;
|
815 |
case RasterBuffer.TYPE_DOUBLE:
|
816 |
DoubleBand db = new DoubleBand(stripeList, null, offset, bitsPag, 0, getWidth(), getHeight()); |
817 |
bandList.add(pos, db); |
818 |
return db;
|
819 |
} |
820 |
return null; |
821 |
} |
822 |
|
823 |
/*
|
824 |
* (non-Javadoc)
|
825 |
* @see org.gvsig.raster.cache.buffer.Buffer#getBufferWithOneBand(int)
|
826 |
*/
|
827 |
public Buffer getBufferWithOneBand(int nBand) throws IOException { |
828 |
int[] bands = new int[]{nBand}; |
829 |
return new RasterReadOnlyBuffer(this.dataSource.clone(), bands); |
830 |
} |
831 |
|
832 |
/*
|
833 |
* (non-Javadoc)
|
834 |
* @see org.gvsig.raster.cache.buffer.impl.RasterBuffer#copyBand(int, org.gvsig.raster.cache.buffer.Band)
|
835 |
*/
|
836 |
public void copyBand(int iBand, Band band) throws BandNotCompatibleException, OperationNotSupportedException { |
837 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
838 |
} |
839 |
|
840 |
/*
|
841 |
* (non-Javadoc)
|
842 |
* @see org.gvsig.raster.cache.buffer.Buffer#assignBand(int, org.gvsig.raster.cache.buffer.Band)
|
843 |
*/
|
844 |
public void assignBand(int nBand, Band band) throws BandNotCompatibleException { |
845 |
if( band.getDataType() != getDataType())
|
846 |
throw new BandNotCompatibleException("Data type not compatible"); |
847 |
if( band.getHeight() != getHeight() || band.getWidth() != getWidth())
|
848 |
throw new BandNotCompatibleException("Bands with diferents sizes"); |
849 |
if(band.getClass() != getBand(0).getClass() || !(band instanceof ReadOnlyCacheBand)) |
850 |
throw new BandNotCompatibleException("buffer type not compatible"); |
851 |
|
852 |
bandPlusPlus(); |
853 |
switch (getDataType()) {
|
854 |
case RasterBuffer.TYPE_BYTE:
|
855 |
ByteBand bb = new ByteBand(stripeList, ((ReadOnlyCacheBand)band).dataSource, offset, bitsPag, ((ReadOnlyCacheBand)band).nBand, getWidth(), getHeight());
|
856 |
this.bandList.add(nBand, bb);
|
857 |
break;
|
858 |
case RasterBuffer.TYPE_SHORT:
|
859 |
ShortBand sb = new ShortBand(stripeList, ((ReadOnlyCacheBand)band).dataSource, offset, bitsPag, ((ReadOnlyCacheBand)band).nBand, getWidth(), getHeight());
|
860 |
this.bandList.add(nBand, sb);
|
861 |
break;
|
862 |
case RasterBuffer.TYPE_INT:
|
863 |
IntBand ib = new IntBand(stripeList, ((ReadOnlyCacheBand)band).dataSource, offset, bitsPag, ((ReadOnlyCacheBand)band).nBand, getWidth(), getHeight());
|
864 |
this.bandList.add(nBand, ib);
|
865 |
break;
|
866 |
case RasterBuffer.TYPE_FLOAT:
|
867 |
FloatBand fb = new FloatBand(stripeList, ((ReadOnlyCacheBand)band).dataSource, offset, bitsPag, ((ReadOnlyCacheBand)band).nBand, getWidth(), getHeight());
|
868 |
this.bandList.add(nBand, fb);
|
869 |
break;
|
870 |
case RasterBuffer.TYPE_DOUBLE:
|
871 |
DoubleBand db = new DoubleBand(stripeList, ((ReadOnlyCacheBand)band).dataSource, offset, bitsPag, ((ReadOnlyCacheBand)band).nBand, getWidth(), getHeight());
|
872 |
this.bandList.add(nBand, db);
|
873 |
break;
|
874 |
} |
875 |
} |
876 |
|
877 |
/*
|
878 |
* (non-Javadoc)
|
879 |
* @see org.gvsig.raster.cache.buffer.Buffer#getBandCopy(int)
|
880 |
*/
|
881 |
public Band getBandCopy(int band) { |
882 |
switch (getDataType()) {
|
883 |
case RasterBuffer.TYPE_BYTE:
|
884 |
return (ByteBand)((ByteBand)bandList.get(band)).clone();
|
885 |
case RasterBuffer.TYPE_SHORT:
|
886 |
return (ShortBand)((ShortBand)bandList.get(band)).clone();
|
887 |
case RasterBuffer.TYPE_INT:
|
888 |
return (IntBand)((IntBand)bandList.get(band)).clone();
|
889 |
case RasterBuffer.TYPE_FLOAT:
|
890 |
return (FloatBand)((FloatBand)bandList.get(band)).clone();
|
891 |
case RasterBuffer.TYPE_DOUBLE:
|
892 |
return (DoubleBand)((DoubleBand)bandList.get(band)).clone();
|
893 |
} |
894 |
return null; |
895 |
} |
896 |
|
897 |
/*
|
898 |
* (non-Javadoc)
|
899 |
* @see org.gvsig.raster.cache.buffer.Buffer#replicateBand(int, int)
|
900 |
*/
|
901 |
public void replicateBand(int orig, int dest) throws IOException { |
902 |
Band origBand = getBandCopy(orig); |
903 |
try {
|
904 |
assignBand(dest, origBand); |
905 |
} catch (BandNotCompatibleException e) {
|
906 |
//It can't be throwed
|
907 |
} |
908 |
} |
909 |
|
910 |
/*
|
911 |
* (non-Javadoc)
|
912 |
* @see org.gvsig.raster.cache.buffer.Buffer#createBand(double)
|
913 |
*/
|
914 |
public Band createBand(double defaultValue) throws OperationNotSupportedException { |
915 |
throw new OperationNotSupportedException("RasterReadOnlyBuffer doesn't support this operation"); |
916 |
} |
917 |
|
918 |
/*
|
919 |
* (non-Javadoc)
|
920 |
* @see org.gvsig.raster.cache.buffer.Buffer#free()
|
921 |
*/
|
922 |
public void free() throws IOException { |
923 |
for (int i = 0; i < bandList.size() ; i++) { |
924 |
bandList.get(i).page.free(); |
925 |
bandList.get(i).secondPage.free(); |
926 |
} |
927 |
if(dataSource != null) |
928 |
dataSource.close(); |
929 |
} |
930 |
|
931 |
/*
|
932 |
* (non-Javadoc)
|
933 |
* @see org.gvsig.raster.cache.buffer.impl.RasterBuffer#cloneBuffer()
|
934 |
*/
|
935 |
public Buffer cloneBuffer(){ |
936 |
return null; |
937 |
} |
938 |
|
939 |
} |