cubic_f.c 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. /*
  2. * Name
  3. * cubic_f.c -- use cubic interpolation with fallback for given row, col
  4. *
  5. * Description
  6. * cubic interpolation for the given row, column indices.
  7. * If the interpolated value (but not the nearest) is null,
  8. * it falls back to bilinear. If that interp value is null,
  9. * it falls back to nearest neighbor.
  10. */
  11. #include <grass/gis.h>
  12. #include <grass/raster.h>
  13. #include "r.proj.h"
  14. void p_cubic_f(struct cache *ibuffer, /* input buffer */
  15. void *obufptr, /* ptr in output buffer */
  16. int cell_type, /* raster map type of obufptr */
  17. double col_idx, /* column index */
  18. double row_idx, /* row index */
  19. struct Cell_head *cellhd /* cell header of input layer */
  20. )
  21. {
  22. /* start nearest neighbor to do some basic tests */
  23. int row, col; /* row/col of nearest neighbor */
  24. FCELL cell;
  25. /* cut indices to integer */
  26. row = (int)floor(row_idx);
  27. col = (int)floor(col_idx);
  28. /* check for out of bounds - if out of bounds set NULL value */
  29. if (row < 0 || row >= cellhd->rows || col < 0 || col >= cellhd->cols) {
  30. Rast_set_null_value(obufptr, 1, cell_type);
  31. return;
  32. }
  33. cell = CVAL(ibuffer, row, col);
  34. /* if nearest is null, all the other interps will be null */
  35. if (Rast_is_f_null_value(&cell)) {
  36. Rast_set_null_value(obufptr, 1, cell_type);
  37. return;
  38. }
  39. p_cubic(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
  40. /* fallback to bilinear if cubic is null */
  41. if (Rast_is_f_null_value(obufptr)) {
  42. p_bilinear(ibuffer, obufptr, cell_type, col_idx, row_idx, cellhd);
  43. /* fallback to nearest if bilinear is null */
  44. if (Rast_is_f_null_value(obufptr))
  45. Rast_set_f_value(obufptr, cell, cell_type);
  46. }
  47. }