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