Revision 11472 trunk/libraries/libRaster/src/org/gvsig/raster/buffer/RasterBuffer.java
RasterBuffer.java | ||
---|---|---|
40 | 40 |
* |
41 | 41 |
*/ |
42 | 42 |
public abstract class RasterBuffer implements IBuffer { |
43 |
public static final int CANCEL_HISTOGRAM = IHistogramable.CANCEL_HISTOGRAM;
|
|
44 |
protected boolean[] cancel = new boolean[1];
|
|
45 |
|
|
43 |
public static final int CANCEL_HISTOGRAM = IHistogramable.CANCEL_HISTOGRAM; |
|
44 |
protected boolean[] cancel = new boolean[1]; |
|
45 |
|
|
46 | 46 |
//Espacio en memoria (en Megas) que hay que sobrepasar para empezar a cachear. |
47 | 47 |
private static int cacheMemorySize = 25; |
48 | 48 |
//Espacio en memoria (en Megas) que hay que sobrepasar para empezar a cachear en multipagina. |
49 | 49 |
private static int multicacheMemorySize = 100; |
50 |
|
|
51 |
public double noDataValue = -99999; |
|
52 | 50 |
|
53 |
protected int percent = 0; |
|
51 |
public double noDataValue = -99999; |
|
52 |
|
|
53 |
protected int percent = 0; |
|
54 | 54 |
protected boolean canceled = false; |
55 |
|
|
56 |
protected int width;
|
|
57 |
protected int height;
|
|
58 |
protected int nBands;
|
|
59 |
protected int dataType;
|
|
55 |
|
|
56 |
protected int width;
|
|
57 |
protected int height;
|
|
58 |
protected int nBands;
|
|
59 |
protected int dataType;
|
|
60 | 60 |
|
61 | 61 |
/** |
62 | 62 |
* Variable est?tica que si est? a false desactiva el uso de cach?. Puede ser usada por un cliente |
63 | 63 |
* para cargar siempre los datos en memoria. independientemente de su tama?o. |
64 | 64 |
*/ |
65 |
public static boolean cacheOn = true; |
|
65 |
public static boolean cacheOn = true;
|
|
66 | 66 |
/** |
67 | 67 |
* Fuerza la carga de los datos en cach? independientemente de su tama?o. Su |
68 | 68 |
* uso suele ser util solo para depuraci?n. Su valor por defecto y recomendado |
... | ... | |
80 | 80 |
* no tiene datos asignados y tampoco puede ser null. Todas las bandas no validas de un buffer |
81 | 81 |
* apuntan por referencia a la misma banda. |
82 | 82 |
*/ |
83 |
protected double notValidValue = 0D; |
|
83 |
protected double notValidValue = 0D; |
|
84 |
|
|
85 |
private BufferInterpolation interp = null; |
|
84 | 86 |
|
85 | 87 |
/** |
86 | 88 |
* Genera instancias del buffer de datos adecuado al tama?o del raster. Si no hay muchos datos |
... | ... | |
270 | 272 |
return null; |
271 | 273 |
} |
272 | 274 |
|
273 |
/** |
|
274 |
* Ajusta el raster al ancho y alto solicitado por el vecino m?s cercano. Promedia el valor de dos |
|
275 |
* pixeles contiguos. |
|
276 |
* @param w Nuevo ancho |
|
277 |
* @param h Nuevo alto |
|
275 |
/* |
|
276 |
* (non-Javadoc) |
|
277 |
* @see org.gvsig.raster.dataset.IBuffer#isInside(int, int) |
|
278 | 278 |
*/ |
279 |
private RasterBuffer adjustRasterNearestNeighbourInterpolation(int w, int h) { |
|
280 |
double stepX = (double)w / (double)width; |
|
281 |
double stepY = (double)h / (double)height; |
|
282 |
RasterBuffer rasterBuf = new RasterMemoryBuffer(getDataType(), w, h, getBandCount(), true); |
|
283 |
|
|
284 |
int[] bands = new int[rasterBuf.getBandCount()]; |
|
285 |
for(int iBand = 0; iBand < rasterBuf.getBandCount(); iBand ++) |
|
286 |
bands[iBand] = iBand; |
|
287 |
|
|
288 |
|
|
289 |
switch (dataType) { |
|
290 |
case RasterBuffer.TYPE_BYTE: |
|
291 |
for(int iBand = 0; iBand < bands.length; iBand ++) { |
|
292 |
if(w <= width) { //submuestreo |
|
293 |
for(int iRow = 0; iRow < height; iRow ++) |
|
294 |
for(int iCol = 0; iCol < width; iCol ++) |
|
295 |
rasterBuf.setElem((int)(iRow * stepY), (int)(iCol * stepX), bands[iBand], getElemByte(iRow, iCol, iBand)); |
|
296 |
}else{ //supermuestreo |
|
297 |
for(int iRow = 0; iRow < h; iRow ++) |
|
298 |
for(int iCol = 0; iCol < w; iCol ++) |
|
299 |
rasterBuf.setElem(iRow, iCol, bands[iBand], getElemByte((int)(iRow / stepY), (int)(iCol / stepX), iBand)); |
|
300 |
} |
|
301 |
} |
|
302 |
break; |
|
303 |
case RasterBuffer.TYPE_DOUBLE: |
|
304 |
for(int iBand = 0; iBand < bands.length; iBand ++) { |
|
305 |
if(w <= width) { //submuestreo |
|
306 |
for(int iRow = 0; iRow < height; iRow ++) |
|
307 |
for(int iCol = 0; iCol < width; iCol ++) |
|
308 |
rasterBuf.setElem((int)(iRow * stepY), (int)(iCol * stepX), bands[iBand], getElemDouble(iRow, iCol, iBand)); |
|
309 |
}else{ //supermuestreo |
|
310 |
for(int iRow = 0; iRow < h; iRow ++) |
|
311 |
for(int iCol = 0; iCol < w; iCol ++) |
|
312 |
rasterBuf.setElem(iRow, iCol, bands[iBand], getElemDouble((int)(iRow / stepY), (int)(iCol / stepX), iBand)); |
|
313 |
} |
|
314 |
} |
|
315 |
break; |
|
316 |
case RasterBuffer.TYPE_FLOAT: |
|
317 |
for(int iBand = 0; iBand < bands.length; iBand ++) { |
|
318 |
if(w <= width) { //submuestreo |
|
319 |
for(int iRow = 0; iRow < height; iRow ++) |
|
320 |
for(int iCol = 0; iCol < width; iCol ++) |
|
321 |
rasterBuf.setElem((int)(iRow * stepY), (int)(iCol * stepX), bands[iBand], getElemFloat(iRow, iCol, iBand)); |
|
322 |
}else{ //supermuestreo |
|
323 |
for(int iRow = 0; iRow < h; iRow ++) |
|
324 |
for(int iCol = 0; iCol < w; iCol ++) |
|
325 |
rasterBuf.setElem(iRow, iCol, bands[iBand], getElemFloat((int)(iRow / stepY), (int)(iCol / stepX), iBand)); |
|
326 |
} |
|
327 |
} |
|
328 |
break; |
|
329 |
case RasterBuffer.TYPE_INT: |
|
330 |
for(int iBand = 0; iBand < bands.length; iBand ++) { |
|
331 |
if(w <= width) { //submuestreo |
|
332 |
for(int iRow = 0; iRow < height; iRow ++) |
|
333 |
for(int iCol = 0; iCol < width; iCol ++) |
|
334 |
rasterBuf.setElem((int)(iRow * stepY), (int)(iCol * stepX), bands[iBand], getElemInt(iRow, iCol, iBand)); |
|
335 |
}else{ //supermuestreo |
|
336 |
for(int iRow = 0; iRow < h; iRow ++) |
|
337 |
for(int iCol = 0; iCol < w; iCol ++) |
|
338 |
rasterBuf.setElem(iRow, iCol, bands[iBand], getElemInt((int)(iRow / stepY), (int)(iCol / stepX), iBand)); |
|
339 |
} |
|
340 |
} |
|
341 |
break; |
|
342 |
case RasterBuffer.TYPE_USHORT: |
|
343 |
case RasterBuffer.TYPE_SHORT: |
|
344 |
for(int iBand = 0; iBand < bands.length; iBand ++) { |
|
345 |
if(w <= width) { //submuestreo |
|
346 |
for(int iRow = 0; iRow < height; iRow ++) |
|
347 |
for(int iCol = 0; iCol < width; iCol ++) |
|
348 |
rasterBuf.setElem((int)(iRow * stepY), (int)(iCol * stepX), bands[iBand], getElemShort(iRow, iCol, iBand)); |
|
349 |
}else{ //supermuestreo |
|
350 |
for(int iRow = 0; iRow < h; iRow ++) |
|
351 |
for(int iCol = 0; iCol < w; iCol ++) |
|
352 |
rasterBuf.setElem(iRow, iCol, bands[iBand], getElemShort((int)(iRow / stepY), (int)(iCol / stepX), iBand)); |
|
353 |
} |
|
354 |
} |
|
355 |
break; |
|
356 |
} |
|
357 |
return rasterBuf; |
|
279 |
public boolean isInside(int x, int y) { |
|
280 |
if (x < 0 || y < 0 || x >= getWidth() || y >= getHeight()) |
|
281 |
return false; |
|
282 |
return true; |
|
358 | 283 |
} |
359 |
|
|
360 |
/** |
|
361 |
* Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n bilineal. Promedia |
|
362 |
* el valor de cuatro pixeles adyacentes. |
|
363 |
* @param w Nuevo ancho |
|
364 |
* @param h Nuevo alto |
|
365 |
*/ |
|
366 |
private RasterBuffer adjustRasterBilinearInterpolation(int w, int h) { |
|
367 |
double pxSize = (double)width / (double)w; |
|
368 |
RasterBuffer rasterBuf = new RasterMemoryBuffer(getDataType(), w, h, getBandCount(), true); |
|
369 |
|
|
370 |
double posX = pxSize / 2D; |
|
371 |
double posY = posX; |
|
372 |
double dx = 0D, dy = 0D; |
|
373 |
|
|
374 |
for(int iBand = 0; iBand < getBandCount(); iBand ++) { |
|
375 |
posY = pxSize / 2D; |
|
376 |
switch (dataType) { |
|
377 |
case RasterBuffer.TYPE_BYTE: |
|
378 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
379 |
dy = posY - ((int)posY); |
|
380 |
posX = pxSize / 2D; |
|
381 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
382 |
dx = posX - ((int)posX); |
|
383 |
double[] kernel = getKernelByte(((int)posX), ((int)posY), iBand); |
|
384 |
double[] nz = getBilinearNZ(dx, dy, kernel); |
|
385 |
double b = 0; |
|
386 |
if(nz[0] > 0.0) |
|
387 |
b = (nz[1] / nz[0]); |
|
388 |
rasterBuf.setElem(iRow, iCol, iBand, (byte)((byte)b & 0xff)); |
|
389 |
posX += pxSize; |
|
390 |
} |
|
391 |
posY += pxSize; |
|
392 |
} |
|
393 |
break; |
|
394 |
case RasterBuffer.TYPE_SHORT: |
|
395 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
396 |
dy = posY - ((int)posY); |
|
397 |
posX = pxSize / 2D; |
|
398 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
399 |
dx = posX - ((int)posX); |
|
400 |
double[] kernel = getKernelShort(((int)posX), ((int)posY), iBand); |
|
401 |
double[] nz = getBilinearNZ(dx, dy, kernel); |
|
402 |
double b = 0; |
|
403 |
if(nz[0] > 0.0) |
|
404 |
b = (nz[1] / nz[0]); |
|
405 |
rasterBuf.setElem(iRow, iCol, iBand, (short)((short)b & 0xffff)); |
|
406 |
posX += pxSize; |
|
407 |
} |
|
408 |
posY += pxSize; |
|
409 |
} |
|
410 |
break; |
|
411 |
case RasterBuffer.TYPE_INT: |
|
412 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
413 |
dy = posY - ((int)posY); |
|
414 |
posX = pxSize / 2D; |
|
415 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
416 |
dx = posX - ((int)posX); |
|
417 |
double[] kernel = getKernelInt(((int)posX), ((int)posY), iBand); |
|
418 |
double[] nz = getBilinearNZ(dx, dy, kernel); |
|
419 |
double b = 0; |
|
420 |
if(nz[0] > 0.0) |
|
421 |
b = (nz[1] / nz[0]); |
|
422 |
rasterBuf.setElem(iRow, iCol, iBand, (int)((int)b & 0xff)); |
|
423 |
posX += pxSize; |
|
424 |
} |
|
425 |
posY += pxSize; |
|
426 |
} |
|
427 |
break; |
|
428 |
case RasterBuffer.TYPE_FLOAT: |
|
429 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
430 |
dy = posY - ((int)posY); |
|
431 |
posX = pxSize / 2D; |
|
432 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
433 |
dx = posX - ((int)posX); |
|
434 |
double[] kernel = getKernelFloat(((int)posX), ((int)posY), iBand); |
|
435 |
double[] nz = getBilinearNZ(dx, dy, kernel); |
|
436 |
double b = 0; |
|
437 |
if(nz[0] > 0.0) |
|
438 |
b = (nz[1] / nz[0]); |
|
439 |
rasterBuf.setElem(iRow, iCol, iBand, (float)b); |
|
440 |
posX += pxSize; |
|
441 |
} |
|
442 |
posY += pxSize; |
|
443 |
} |
|
444 |
break; |
|
445 |
case RasterBuffer.TYPE_DOUBLE: |
|
446 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
447 |
dy = posY - ((int)posY); |
|
448 |
posX = pxSize / 2D; |
|
449 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
450 |
dx = posX - ((int)posX); |
|
451 |
double[] kernel = getKernelDouble(((int)posX), ((int)posY), iBand); |
|
452 |
double[] nz = getBilinearNZ(dx, dy, kernel); |
|
453 |
double b = 0; |
|
454 |
if(nz[0] > 0.0) |
|
455 |
b = (nz[1] / nz[0]); |
|
456 |
rasterBuf.setElem(iRow, iCol, iBand, (double)b); |
|
457 |
posX += pxSize; |
|
458 |
} |
|
459 |
posY += pxSize; |
|
460 |
} |
|
461 |
break; |
|
462 |
} |
|
463 |
|
|
464 |
} |
|
465 |
|
|
466 |
return rasterBuf; |
|
467 |
} |
|
468 |
|
|
469 |
/** |
|
470 |
* Calcula los valores N y Z para el m?todo bilinear |
|
471 |
* @param dx distancia en X desde el centro del pixel hasta el punto. Es un valor entre 0 y 1 |
|
472 |
* @param dy distancia en Y desde el centro del pixel hasta el punto. Es un valor entre 0 y 1 |
|
473 |
* @param kernel valor del pixel y alrededor |
|
474 |
* @return valore de N y Z |
|
475 |
*/ |
|
476 |
private double[] getBilinearNZ(double dx, double dy, double[] kernel) { |
|
477 |
double z = 0.0, n = 0.0, d; |
|
478 |
d = (1.0 - dx) * (1.0 - dy); |
|
479 |
z += d * kernel[0]; |
|
480 |
n += d; |
|
481 |
|
|
482 |
d = dx * (1.0 - dy); |
|
483 |
z += d * kernel[1]; |
|
484 |
n += d; |
|
485 |
|
|
486 |
d = (1.0 - dx) * dy; |
|
487 |
z += d * kernel[2]; |
|
488 |
n += d; |
|
489 |
|
|
490 |
d = dx * dy; |
|
491 |
z += d * kernel[3]; |
|
492 |
n += d; |
|
493 |
return new double[]{n, z}; |
|
494 |
} |
|
495 |
|
|
496 |
/** |
|
497 |
* Calcula los valores N y Z para el m?todo bilinear |
|
498 |
* @param dx distancia en X desde el centro del pixel hasta el punto. Es un valor entre 0 y 1 |
|
499 |
* @param dy distancia en Y desde el centro del pixel hasta el punto. Es un valor entre 0 y 1 |
|
500 |
* @param kernel valor del pixel y alrededor |
|
501 |
* @return valore de N y Z |
|
502 |
*/ |
|
503 |
private double[] getInverseDistanceNZ(double dx, double dy, double[] kernel) { |
|
504 |
double z = 0.0, n = 0.0, d; |
|
505 |
d = 1.0 / Math.sqrt(dx * dx + dy * dy); |
|
506 |
z += d * kernel[0]; |
|
507 |
n += d; |
|
508 |
|
|
509 |
d = 1.0 / Math.sqrt((1.0 - dx) * ( 1.0 - dx) + dy * dy); |
|
510 |
z += d * kernel[1]; |
|
511 |
n += d; |
|
512 |
|
|
513 |
d = 1.0 / Math.sqrt(dx*dx + (1.0-dy)*(1.0-dy)); |
|
514 |
z += d * kernel[2]; |
|
515 |
n += d; |
|
516 |
|
|
517 |
d = 1.0 / Math.sqrt((1.0 - dx) *( 1.0 - dx) + (1.0 - dy) * (1.0 - dy)); |
|
518 |
z += d * kernel[3]; |
|
519 |
n += d; |
|
520 |
return new double[]{n, z}; |
|
521 |
} |
|
522 |
|
|
523 |
|
|
524 |
/** |
|
525 |
* Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y), |
|
526 |
* (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen |
|
527 |
* se tomar? x e y. |
|
528 |
* @param x Coordenada X del pixel inicial |
|
529 |
* @param y Coordenada Y del pixel inicial |
|
530 |
* @param band N?mero de banda. |
|
531 |
* @return Kernel solicitado en forma de array. |
|
532 |
*/ |
|
533 |
private double[] getKernelByte(int x, int y, int band) { |
|
534 |
double[] d = new double[4]; |
|
535 |
d[0] = (getElemByte(y, x, band) & 0xff); |
|
536 |
int nextX = ((x + 1) >= getWidth()) ? x : (x + 1); |
|
537 |
int nextY = ((y + 1) >= getHeight()) ? y : (y + 1); |
|
538 |
d[1] = (getElemByte(y, nextX, band) & 0xff); |
|
539 |
d[2] = (getElemByte(nextY, x, band) & 0xff); |
|
540 |
d[3] = (getElemByte(nextY, nextX, band) & 0xff); |
|
541 |
return d; |
|
542 |
} |
|
543 |
|
|
544 |
/** |
|
545 |
* Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y), |
|
546 |
* (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen |
|
547 |
* se tomar? x e y. |
|
548 |
* @param x Coordenada X del pixel inicial |
|
549 |
* @param y Coordenada Y del pixel inicial |
|
550 |
* @param band N?mero de banda. |
|
551 |
* @return Kernel solicitado en forma de array. |
|
552 |
*/ |
|
553 |
private double[] getKernelShort(int x, int y, int band) { |
|
554 |
double[] d = new double[4]; |
|
555 |
d[0] = (getElemShort(y, x, band) & 0xffff); |
|
556 |
int nextX = ((x + 1) >= getWidth()) ? x : (x + 1); |
|
557 |
int nextY = ((y + 1) >= getHeight()) ? y : (y + 1); |
|
558 |
d[1] = (getElemShort(y, nextX, band) & 0xffff); |
|
559 |
d[2] = (getElemShort(nextY, x, band) & 0xffff); |
|
560 |
d[3] = (getElemShort(nextY, nextX, band) & 0xffff); |
|
561 |
return d; |
|
562 |
} |
|
563 |
|
|
564 |
/** |
|
565 |
* Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y), |
|
566 |
* (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen |
|
567 |
* se tomar? x e y. |
|
568 |
* @param x Coordenada X del pixel inicial |
|
569 |
* @param y Coordenada Y del pixel inicial |
|
570 |
* @param band N?mero de banda. |
|
571 |
* @return Kernel solicitado en forma de array. |
|
572 |
*/ |
|
573 |
private double[] getKernelInt(int x, int y, int band) { |
|
574 |
double[] d = new double[4]; |
|
575 |
d[0] = (getElemInt(y, x, band) & 0xffffffff); |
|
576 |
int nextX = ((x + 1) >= getWidth()) ? x : (x + 1); |
|
577 |
int nextY = ((y + 1) >= getHeight()) ? y : (y + 1); |
|
578 |
d[1] = (getElemInt(y, nextX, band) & 0xffffffff); |
|
579 |
d[2] = (getElemInt(nextY, x, band) & 0xffffffff); |
|
580 |
d[3] = (getElemInt(nextY, nextX, band) & 0xffffffff); |
|
581 |
return d; |
|
582 |
} |
|
583 |
|
|
584 |
/** |
|
585 |
* Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y), |
|
586 |
* (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen |
|
587 |
* se tomar? x e y. |
|
588 |
* @param x Coordenada X del pixel inicial |
|
589 |
* @param y Coordenada Y del pixel inicial |
|
590 |
* @param band N?mero de banda. |
|
591 |
* @return Kernel solicitado en forma de array. |
|
592 |
*/ |
|
593 |
private double[] getKernelFloat(int x, int y, int band) { |
|
594 |
double[] d = new double[4]; |
|
595 |
d[0] = getElemFloat(y, x, band); |
|
596 |
int nextX = ((x + 1) >= getWidth()) ? x : (x + 1); |
|
597 |
int nextY = ((y + 1) >= getHeight()) ? y : (y + 1); |
|
598 |
d[1] = getElemFloat(y, nextX, band); |
|
599 |
d[2] = getElemFloat(nextY, x, band); |
|
600 |
d[3] = getElemFloat(nextY, nextX, band); |
|
601 |
return d; |
|
602 |
} |
|
603 |
|
|
604 |
/** |
|
605 |
* Obtiene un kernel de cuatro elemento que corresponden a los pixeles (x, y), (x + 1, y), |
|
606 |
* (x, y + 1), (x + 1, y + 1). Si los pixeles x + 1 o y + 1 se salen del raster de origen |
|
607 |
* se tomar? x e y. |
|
608 |
* @param x Coordenada X del pixel inicial |
|
609 |
* @param y Coordenada Y del pixel inicial |
|
610 |
* @param band N?mero de banda. |
|
611 |
* @return Kernel solicitado en forma de array. |
|
612 |
*/ |
|
613 |
private double[] getKernelDouble(int x, int y, int band) { |
|
614 |
double[] d = new double[4]; |
|
615 |
d[0] = getElemDouble(y, x, band); |
|
616 |
int nextX = ((x + 1) >= getWidth()) ? x : (x + 1); |
|
617 |
int nextY = ((y + 1) >= getHeight()) ? y : (y + 1); |
|
618 |
d[1] = getElemDouble(y, nextX, band); |
|
619 |
d[2] = getElemDouble(nextY, x, band); |
|
620 |
d[3] = getElemDouble(nextY, nextX, band); |
|
621 |
return d; |
|
622 |
} |
|
623 |
|
|
624 |
/** |
|
625 |
* Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n de distancia inversa. |
|
626 |
* Asigna el valor de un pixel en funci?n inversa de la distancia. |
|
627 |
* |
|
628 |
* @param w Nuevo ancho |
|
629 |
* @param h Nuevo alto |
|
630 |
*/ |
|
631 |
private RasterBuffer adjustRasterInverseDistanceInterpolation(int w, int h) { |
|
632 |
double pxSize = (double)width / (double)w; |
|
633 |
RasterBuffer rasterBuf = new RasterMemoryBuffer(getDataType(), w, h, getBandCount(), true); |
|
634 |
|
|
635 |
double posX = pxSize / 2D; |
|
636 |
double posY = posX; |
|
637 |
double dx = 0D, dy = 0D; |
|
638 |
|
|
639 |
for(int iBand = 0; iBand < getBandCount(); iBand ++) { |
|
640 |
posY = pxSize / 2D; |
|
641 |
switch (dataType) { |
|
642 |
case RasterBuffer.TYPE_BYTE: |
|
643 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
644 |
dy = posY - ((int)posY); |
|
645 |
posX = pxSize / 2D; |
|
646 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
647 |
dx = posX - ((int)posX); |
|
648 |
double[] kernel = getKernelByte(((int)posX), ((int)posY), iBand); |
|
649 |
double[] nz = getInverseDistanceNZ(dx, dy, kernel); |
|
650 |
double b = 0; |
|
651 |
if(nz[0] > 0.0) |
|
652 |
b = (nz[1] / nz[0]); |
|
653 |
rasterBuf.setElem(iRow, iCol, iBand, (byte)((byte)b & 0xff)); |
|
654 |
posX += pxSize; |
|
655 |
} |
|
656 |
posY += pxSize; |
|
657 |
} |
|
658 |
break; |
|
659 |
case RasterBuffer.TYPE_SHORT: |
|
660 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
661 |
dy = posY - ((int)posY); |
|
662 |
posX = pxSize / 2D; |
|
663 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
664 |
dx = posX - ((int)posX); |
|
665 |
double[] kernel = getKernelShort(((int)posX), ((int)posY), iBand); |
|
666 |
double[] nz = getInverseDistanceNZ(dx, dy, kernel); |
|
667 |
double b = 0; |
|
668 |
if(nz[0] > 0.0) |
|
669 |
b = (nz[1] / nz[0]); |
|
670 |
rasterBuf.setElem(iRow, iCol, iBand, (short)((short)b & 0xffff)); |
|
671 |
posX += pxSize; |
|
672 |
} |
|
673 |
posY += pxSize; |
|
674 |
} |
|
675 |
break; |
|
676 |
case RasterBuffer.TYPE_INT: |
|
677 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
678 |
dy = posY - ((int)posY); |
|
679 |
posX = pxSize / 2D; |
|
680 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
681 |
dx = posX - ((int)posX); |
|
682 |
double[] kernel = getKernelInt(((int)posX), ((int)posY), iBand); |
|
683 |
double[] nz = getInverseDistanceNZ(dx, dy, kernel); |
|
684 |
double b = 0; |
|
685 |
if(nz[0] > 0.0) |
|
686 |
b = (nz[1] / nz[0]); |
|
687 |
rasterBuf.setElem(iRow, iCol, iBand, (int)((int)b & 0xff)); |
|
688 |
posX += pxSize; |
|
689 |
} |
|
690 |
posY += pxSize; |
|
691 |
} |
|
692 |
break; |
|
693 |
case RasterBuffer.TYPE_FLOAT: |
|
694 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
695 |
dy = posY - ((int)posY); |
|
696 |
posX = pxSize / 2D; |
|
697 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
698 |
dx = posX - ((int)posX); |
|
699 |
double[] kernel = getKernelFloat(((int)posX), ((int)posY), iBand); |
|
700 |
double[] nz = getInverseDistanceNZ(dx, dy, kernel); |
|
701 |
double b = 0; |
|
702 |
if(nz[0] > 0.0) |
|
703 |
b = (nz[1] / nz[0]); |
|
704 |
rasterBuf.setElem(iRow, iCol, iBand, (float)b); |
|
705 |
posX += pxSize; |
|
706 |
} |
|
707 |
posY += pxSize; |
|
708 |
} |
|
709 |
break; |
|
710 |
case RasterBuffer.TYPE_DOUBLE: |
|
711 |
for(int iRow = 0; iRow < h; iRow ++) { |
|
712 |
dy = posY - ((int)posY); |
|
713 |
posX = pxSize / 2D; |
|
714 |
for(int iCol = 0; iCol < w; iCol ++) { |
|
715 |
dx = posX - ((int)posX); |
|
716 |
double[] kernel = getKernelDouble(((int)posX), ((int)posY), iBand); |
|
717 |
double[] nz = getInverseDistanceNZ(dx, dy, kernel); |
|
718 |
double b = 0; |
|
719 |
if(nz[0] > 0.0) |
|
720 |
b = (nz[1] / nz[0]); |
|
721 |
rasterBuf.setElem(iRow, iCol, iBand, (double)b); |
|
722 |
posX += pxSize; |
|
723 |
} |
|
724 |
posY += pxSize; |
|
725 |
} |
|
726 |
break; |
|
727 |
} |
|
728 |
|
|
729 |
} |
|
730 |
|
|
731 |
return rasterBuf; |
|
732 |
} |
|
733 |
|
|
734 |
/** |
|
735 |
* Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n de spline bicubica. |
|
736 |
* @param w Nuevo ancho |
|
737 |
* @param h Nuevo alto |
|
738 |
*/ |
|
739 |
private RasterBuffer adjustRasterBicubicSplineInterpolation(int w, int h) { |
|
740 |
return this; |
|
741 |
} |
|
742 |
|
|
743 |
/** |
|
744 |
* Ajusta el raster al ancho y alto solicitado ajustando con una interpolaci?n BSpline. |
|
745 |
* @param w Nuevo ancho |
|
746 |
* @param h Nuevo alto |
|
747 |
*/ |
|
748 |
private RasterBuffer adjustRasterBSplineInterpolation(int w, int h) { |
|
749 |
return this; |
|
750 |
} |
|
751 |
|
|
284 |
|
|
752 | 285 |
/* |
753 | 286 |
* (non-Javadoc) |
754 | 287 |
* @see org.gvsig.fmap.driver.IBuffer#getNoDataValue() |
... | ... | |
827 | 360 |
* @param interpolation M?todo de interpolaci?n que se usar? en el ajuste. |
828 | 361 |
*/ |
829 | 362 |
public RasterBuffer getAdjustedWindow(int w, int h, int interpolationMethod) { |
363 |
if(interp == null) |
|
364 |
interp = new BufferInterpolation(this); |
|
365 |
|
|
830 | 366 |
if(w == getWidth() && h == getHeight()) |
831 | 367 |
return this; |
832 | 368 |
RasterBuffer rasterBuf = null; |
833 | 369 |
switch(interpolationMethod) { |
834 |
case IQueryableRaster.INTERPOLATION_NearestNeighbour:
|
|
835 |
rasterBuf = adjustRasterNearestNeighbourInterpolation(w, h); |
|
370 |
case BufferInterpolation.INTERPOLATION_NearestNeighbour:
|
|
371 |
rasterBuf = interp.adjustRasterNearestNeighbourInterpolation(w, h);
|
|
836 | 372 |
break; |
837 |
case IQueryableRaster.INTERPOLATION_Bilinear:
|
|
838 |
rasterBuf = adjustRasterBilinearInterpolation(w, h); |
|
373 |
case BufferInterpolation.INTERPOLATION_Bilinear:
|
|
374 |
rasterBuf = interp.adjustRasterBilinearInterpolation(w, h);
|
|
839 | 375 |
break; |
840 |
case IQueryableRaster.INTERPOLATION_InverseDistance:
|
|
841 |
rasterBuf = adjustRasterInverseDistanceInterpolation(w, h); |
|
376 |
case BufferInterpolation.INTERPOLATION_InverseDistance:
|
|
377 |
rasterBuf = interp.adjustRasterInverseDistanceInterpolation(w, h);
|
|
842 | 378 |
break; |
843 |
case IQueryableRaster.INTERPOLATION_BicubicSpline:
|
|
844 |
rasterBuf = adjustRasterBicubicSplineInterpolation(w, h); |
|
379 |
case BufferInterpolation.INTERPOLATION_BicubicSpline:
|
|
380 |
rasterBuf = interp.adjustRasterBicubicSplineInterpolation(w, h);
|
|
845 | 381 |
break; |
846 |
case IQueryableRaster.INTERPOLATION_BSpline:
|
|
847 |
rasterBuf = adjustRasterBSplineInterpolation(w, h); |
|
382 |
case BufferInterpolation.INTERPOLATION_BSpline:
|
|
383 |
rasterBuf = interp.adjustRasterBSplineInterpolation(w, h);
|
|
848 | 384 |
break; |
849 | 385 |
} |
850 | 386 |
return rasterBuf; |
Also available in: Unified diff