svn-gvsig-desktop / trunk / libraries / libRaster / src / org / gvsig / raster / dataaccess / cache / PageBuffer.java @ 10939
History | View | Annotate | Download (12 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.dataaccess.cache; |
21 |
|
22 |
import java.io.IOException; |
23 |
|
24 |
import org.gvsig.raster.dataaccess.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 |
|
42 |
/**
|
43 |
* Constructor
|
44 |
* @param dataType
|
45 |
* @param width
|
46 |
* @param height
|
47 |
* @param bandNr
|
48 |
* @param malloc
|
49 |
*/
|
50 |
public PageBuffer(int dataType, int width, int height, int bandNr, boolean malloc, int nHddPags){ |
51 |
pageBandBuffer = new PageBandBuffer[bandNr];
|
52 |
for (int i = 0; i < pageBandBuffer.length; i++) |
53 |
pageBandBuffer[i] = new PageBandBuffer(dataType, width, height, 1, malloc, i); |
54 |
} |
55 |
|
56 |
/*
|
57 |
* (non-Javadoc)
|
58 |
* @see org.gvsig.raster.driver.IBuffer#isBandSwitchable()
|
59 |
*/
|
60 |
public boolean isBandSwitchable(){ |
61 |
return false; |
62 |
} |
63 |
|
64 |
/**
|
65 |
* Asigna la lista de paginas de disco
|
66 |
* @param hddList Lista de p?ginas de disco
|
67 |
*/
|
68 |
public void setHddPages(HddPage[] hddList){ |
69 |
for (int i = 0; i < pageBandBuffer.length; i++) |
70 |
pageBandBuffer[i].setHddPages(hddList); |
71 |
} |
72 |
|
73 |
/**
|
74 |
* Carga una p?gina especificada en el par?metro nPag con los datos necesarios.
|
75 |
* Para esto recorre todas las bandas de la p?gina llamando al load de cada una.
|
76 |
*
|
77 |
* @param nPag N?mero de p?gina a cargar
|
78 |
*/
|
79 |
public void loadPage(int nPag){ |
80 |
for (int i = 0; i < pageBandBuffer.length; i++) |
81 |
pageBandBuffer[i].loadPage(nPag); |
82 |
} |
83 |
|
84 |
/**
|
85 |
* Salva una p?gina especificada en el par?metro nPag a disco.
|
86 |
* Para esto recorre todas las bandas de la p?gina llamando al save de cada una.
|
87 |
*
|
88 |
* @param nPag N?mero de p?gina a salvar
|
89 |
* @throws IOException
|
90 |
*/
|
91 |
public void savePage(int nPag) throws IOException{ |
92 |
for (int i = 0; i < pageBandBuffer.length; i++) |
93 |
pageBandBuffer[i].savePage(nPag); |
94 |
} |
95 |
|
96 |
public void assign(int band, byte value) { |
97 |
pageBandBuffer[band].assign(0, value);
|
98 |
} |
99 |
|
100 |
public void assign(int band, short value) { |
101 |
pageBandBuffer[band].assign(0, value);
|
102 |
} |
103 |
|
104 |
public void assign(int band, int value) { |
105 |
pageBandBuffer[band].assign(0, value);
|
106 |
} |
107 |
|
108 |
public void assign(int band, float value) { |
109 |
pageBandBuffer[band].assign(0, value);
|
110 |
} |
111 |
|
112 |
public void assign(int band, double value) { |
113 |
pageBandBuffer[band].assign(0, value);
|
114 |
} |
115 |
|
116 |
public void assignBand(int nBand, IBand band) { |
117 |
} |
118 |
|
119 |
public void assignBandToNotValid(int iBand) { |
120 |
} |
121 |
|
122 |
public IBuffer cloneBuffer() {
|
123 |
return null; |
124 |
} |
125 |
|
126 |
public void copyBand(int nBand, IBand band) { |
127 |
} |
128 |
|
129 |
public IBand createBand(byte defaultValue) { |
130 |
return null; |
131 |
} |
132 |
|
133 |
public IBand getBand(int nBand) { |
134 |
return null; |
135 |
} |
136 |
|
137 |
public IBuffer getBandBuffer(int nBand) { |
138 |
return null; |
139 |
} |
140 |
|
141 |
public int getBandCount() { |
142 |
return pageBandBuffer[0].getBandCount(); |
143 |
} |
144 |
|
145 |
public int getDataType() { |
146 |
return pageBandBuffer[0].getDataType(); |
147 |
} |
148 |
|
149 |
public void setDataType(int dataType) { |
150 |
|
151 |
} |
152 |
|
153 |
public int getHeight() { |
154 |
return pageBandBuffer[0].getHeight(); |
155 |
} |
156 |
|
157 |
public int getWidth() { |
158 |
return pageBandBuffer[0].getWidth(); |
159 |
} |
160 |
|
161 |
|
162 |
|
163 |
public byte getByteNoDataValue() { |
164 |
return pageBandBuffer[0].getByteNoDataValue(); |
165 |
} |
166 |
|
167 |
public float getFloatNoDataValue() { |
168 |
return pageBandBuffer[0].getFloatNoDataValue(); |
169 |
} |
170 |
|
171 |
public int getIntNoDataValue() { |
172 |
return pageBandBuffer[0].getIntNoDataValue(); |
173 |
} |
174 |
|
175 |
public double getNoDataValue() { |
176 |
return pageBandBuffer[0].getNoDataValue(); |
177 |
} |
178 |
|
179 |
public double getNotValidValue() { |
180 |
return pageBandBuffer[0].getNotValidValue(); |
181 |
} |
182 |
|
183 |
public short getShortNoDataValue() { |
184 |
return pageBandBuffer[0].getShortNoDataValue(); |
185 |
} |
186 |
|
187 |
|
188 |
|
189 |
public byte getElemByte(int line, int col, int band) { |
190 |
return pageBandBuffer[band].getElemByte(line, col, 0); |
191 |
} |
192 |
|
193 |
public short getElemShort(int line, int col, int band) { |
194 |
return pageBandBuffer[band].getElemShort(line, col, 0); |
195 |
} |
196 |
|
197 |
public int getElemInt(int line, int col, int band) { |
198 |
return pageBandBuffer[band].getElemInt(line, col, 0); |
199 |
} |
200 |
|
201 |
public float getElemFloat(int line, int col, int band) { |
202 |
return pageBandBuffer[band].getElemFloat(line, col, 0); |
203 |
} |
204 |
|
205 |
public double getElemDouble(int line, int col, int band) { |
206 |
return pageBandBuffer[band].getElemDouble(line, col, 0); |
207 |
} |
208 |
|
209 |
|
210 |
|
211 |
|
212 |
public void getElemByte(int line, int col, byte[] data) { |
213 |
for (int i = 0; i < pageBandBuffer.length; i++) |
214 |
data[i] = pageBandBuffer[i].getElemByte(line, col, 0);
|
215 |
} |
216 |
|
217 |
public void getElemShort(int line, int col, short[] data) { |
218 |
for (int i = 0; i < pageBandBuffer.length; i++) |
219 |
data[i] = pageBandBuffer[i].getElemShort(line, col, 0);
|
220 |
} |
221 |
|
222 |
public void getElemInt(int line, int col, int[] data) { |
223 |
for (int i = 0; i < pageBandBuffer.length; i++) |
224 |
data[i] = pageBandBuffer[i].getElemInt(line, col, 0);
|
225 |
} |
226 |
|
227 |
public void getElemFloat(int line, int col, float[] data) { |
228 |
for (int i = 0; i < pageBandBuffer.length; i++) |
229 |
data[i] = pageBandBuffer[i].getElemFloat(line, col, 0);
|
230 |
} |
231 |
|
232 |
public void getElemDouble(int line, int col, double[] data) { |
233 |
for (int i = 0; i < pageBandBuffer.length; i++) |
234 |
data[i] = pageBandBuffer[i].getElemDouble(line, col, 0);
|
235 |
} |
236 |
|
237 |
|
238 |
public byte[][] getLineByte(int line) { |
239 |
byte[][] b = new byte[pageBandBuffer.length][]; |
240 |
for (int i = 0; i < pageBandBuffer.length; i++) |
241 |
b[i] = pageBandBuffer[i].getLineByte(line)[0];
|
242 |
return b;
|
243 |
} |
244 |
|
245 |
public double[][] getLineDouble(int line) { |
246 |
double[][] d = new double[pageBandBuffer.length][]; |
247 |
for (int i = 0; i < pageBandBuffer.length; i++) |
248 |
d[i] = pageBandBuffer[i].getLineDouble(line)[0];
|
249 |
return d;
|
250 |
} |
251 |
|
252 |
public float[][] getLineFloat(int line) { |
253 |
float[][] f = new float[pageBandBuffer.length][]; |
254 |
for (int i = 0; i < pageBandBuffer.length; i++) |
255 |
f[i] = pageBandBuffer[i].getLineFloat(line)[0];
|
256 |
return f;
|
257 |
} |
258 |
|
259 |
public int[][] getLineInt(int line) { |
260 |
int[][] in = new int[pageBandBuffer.length][]; |
261 |
for (int i = 0; i < pageBandBuffer.length; i++) |
262 |
in[i] = pageBandBuffer[i].getLineInt(line)[0];
|
263 |
return in;
|
264 |
} |
265 |
|
266 |
public short[][] getLineShort(int line) { |
267 |
short[][] s = new short[pageBandBuffer.length][]; |
268 |
for (int i = 0; i < pageBandBuffer.length; i++) |
269 |
s[i] = pageBandBuffer[i].getLineShort(line)[0];
|
270 |
return s;
|
271 |
} |
272 |
|
273 |
|
274 |
|
275 |
public byte[] getLineFromBandByte(int line, int band) { |
276 |
return pageBandBuffer[band].getLineFromBandByte(line, 0); |
277 |
} |
278 |
|
279 |
public double[] getLineFromBandDouble(int line, int band) { |
280 |
return pageBandBuffer[band].getLineFromBandDouble(line, 0); |
281 |
} |
282 |
|
283 |
public float[] getLineFromBandFloat(int line, int band) { |
284 |
return pageBandBuffer[band].getLineFromBandFloat(line, 0); |
285 |
} |
286 |
|
287 |
public int[] getLineFromBandInt(int line, int band) { |
288 |
return pageBandBuffer[band].getLineFromBandInt(line, 0); |
289 |
} |
290 |
|
291 |
public short[] getLineFromBandShort(int line, int band) { |
292 |
return pageBandBuffer[band].getLineFromBandShort(line, 0); |
293 |
} |
294 |
|
295 |
|
296 |
|
297 |
|
298 |
public void interchangeBands(int band1, int band2) { |
299 |
} |
300 |
|
301 |
public void mallocOneBand(int dataType, int width, int height, int band) { |
302 |
} |
303 |
|
304 |
public void replicateBand(int orig, int dest) { |
305 |
} |
306 |
|
307 |
|
308 |
|
309 |
public void setElem(int line, int col, int band, byte data) { |
310 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
311 |
} |
312 |
|
313 |
public void setElem(int line, int col, int band, short data) { |
314 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
315 |
} |
316 |
|
317 |
public void setElem(int line, int col, int band, int data) { |
318 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
319 |
} |
320 |
|
321 |
public void setElem(int line, int col, int band, float data) { |
322 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
323 |
} |
324 |
|
325 |
public void setElem(int line, int col, int band, double data) { |
326 |
pageBandBuffer[band].setElem(line, col, 0, data);
|
327 |
} |
328 |
|
329 |
|
330 |
|
331 |
public void setElemByte(int line, int col, byte[] data) { |
332 |
byte[] b = new byte[1]; |
333 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
334 |
b[0] = data[i];
|
335 |
pageBandBuffer[i].setElemByte(line, col, b); |
336 |
} |
337 |
} |
338 |
|
339 |
public void setElemDouble(int line, int col, double[] data) { |
340 |
double[] b = new double[1]; |
341 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
342 |
b[0] = data[i];
|
343 |
pageBandBuffer[i].setElemDouble(line, col, b); |
344 |
} |
345 |
} |
346 |
|
347 |
public void setElemFloat(int line, int col, float[] data) { |
348 |
float[] b = new float[1]; |
349 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
350 |
b[0] = data[i];
|
351 |
pageBandBuffer[i].setElemFloat(line, col, b); |
352 |
} |
353 |
} |
354 |
|
355 |
public void setElemInt(int line, int col, int[] data) { |
356 |
int[] b = new int[1]; |
357 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
358 |
b[0] = data[i];
|
359 |
pageBandBuffer[i].setElemInt(line, col, b); |
360 |
} |
361 |
} |
362 |
|
363 |
public void setElemShort(int line, int col, short[] data) { |
364 |
short[] b = new short[1]; |
365 |
for (int i = 0; i < pageBandBuffer.length; i++) { |
366 |
b[0] = data[i];
|
367 |
pageBandBuffer[i].setElemShort(line, col, b); |
368 |
} |
369 |
} |
370 |
|
371 |
|
372 |
|
373 |
public void setLineByte(byte[][] data, int line) { |
374 |
} |
375 |
|
376 |
public void setLineDouble(double[][] data, int line) { |
377 |
} |
378 |
|
379 |
public void setLineFloat(float[][] data, int line) { |
380 |
} |
381 |
|
382 |
public void setLineInBandByte(byte[] data, int line, int band) { |
383 |
} |
384 |
|
385 |
public void setLineInBandDouble(double[] data, int line, int band) { |
386 |
} |
387 |
|
388 |
public void setLineInBandFloat(float[] data, int line, int band) { |
389 |
} |
390 |
|
391 |
public void setLineInBandInt(int[] data, int line, int band) { |
392 |
} |
393 |
|
394 |
public void setLineInBandShort(short[] data, int line, int band) { |
395 |
} |
396 |
|
397 |
public void setLineInt(int[][] data, int line) { |
398 |
} |
399 |
|
400 |
public void setLineShort(short[][] data, int line) { |
401 |
} |
402 |
|
403 |
public void setNoDataValue(double nd) { |
404 |
} |
405 |
|
406 |
public void setNotValidValue(double value) { |
407 |
} |
408 |
|
409 |
public void switchBands(int[] bands) { |
410 |
} |
411 |
|
412 |
/*
|
413 |
* (non-Javadoc)
|
414 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogram()
|
415 |
*/
|
416 |
public Histogram getHistogram() throws HistogramException { |
417 |
if(getDataType() != IBuffer.TYPE_BYTE)
|
418 |
return null; |
419 |
Histogram hist = new Histogram(getBandCount(), 256); |
420 |
for (int iBand = 0; iBand < getBandCount(); iBand++) |
421 |
for (int col = 0; col < getHeight(); col++) |
422 |
for (int row = 0; row < getWidth(); row++) |
423 |
hist.incrementPxValue(iBand, getElemByte(row, col, iBand)); |
424 |
return hist;
|
425 |
} |
426 |
|
427 |
/*
|
428 |
* (non-Javadoc)
|
429 |
* @see org.gvsig.raster.driver.datasetproperties.IHistogramable#getHistogramUsingClasses(org.gvsig.raster.shared.DataClassList)
|
430 |
*/
|
431 |
public Histogram getHistogramUsingClasses(DataClassList classes) throws HistogramException { |
432 |
Histogram hist = new Histogram(getBandCount(), classes.length());
|
433 |
for (int iBand = 0; iBand < getBandCount(); iBand++) { |
434 |
for (int col = 0; col < getHeight(); col++) { |
435 |
for (int row = 0; row < getWidth(); row++) { |
436 |
int pixelValue = -1; |
437 |
switch(this.getDataType()){ |
438 |
case IBuffer.TYPE_BYTE: pixelValue = classes.getClassPosition((double)getElemByte(row, col, iBand)); break; |
439 |
case IBuffer.TYPE_SHORT: pixelValue = classes.getClassPosition((double)getElemShort(row, col, iBand)); break; |
440 |
case IBuffer.TYPE_INT: pixelValue = classes.getClassPosition((double)getElemInt(row, col, iBand)); break; |
441 |
case IBuffer.TYPE_FLOAT: pixelValue = classes.getClassPosition((double)getElemFloat(row, col, iBand)); break; |
442 |
case IBuffer.TYPE_DOUBLE: pixelValue = classes.getClassPosition((double)getElemDouble(row, col, iBand)); break; |
443 |
} |
444 |
if(pixelValue >= 0) |
445 |
hist.incrementPxValue(iBand, pixelValue); |
446 |
} |
447 |
} |
448 |
} |
449 |
return hist;
|
450 |
} |
451 |
} |