resample.c 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include "raster3d_intern.h"
  4. /*--------------------------------------------------------------------------*/
  5. /*!
  6. * \brief
  7. *
  8. * The default resampling function which uses nearest
  9. * neighbor resampling. This method converts the window coordinates
  10. * x, y, and z into region coordinates and returned the nearest neighbor.
  11. *
  12. * \param map
  13. * \param col
  14. * \param row
  15. * \param depth
  16. * \param value
  17. * \param type
  18. * \return void
  19. */
  20. void
  21. Rast3d_nearest_neighbor(RASTER3D_Map * map, int x, int y, int z, void *value,
  22. int type)
  23. {
  24. double north, east, top;
  25. int row, col, depth;
  26. /* convert (x, y, z) window coordinates into (north, east, top) */
  27. Rast3d_coord2location(&(map->window), (double)x + 0.5, (double)y + 0.5, (double)z + 0.5, &north, &east, &top);
  28. /* convert (north, east, top) into map region coordinates (row, col, depth) */
  29. Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
  30. /* Get the value from the map in map-region resolution */
  31. Rast3d_get_value_region(map, col, row, depth, value, type);
  32. }
  33. /*--------------------------------------------------------------------------*/
  34. /*!
  35. * \brief
  36. *
  37. * Sets the resampling function to be used by
  38. * Rast3d_get_value () (cf.{g3d:G3d.getValue}). This function is defined
  39. * as follows:
  40. *
  41. * \return void
  42. */
  43. void Rast3d_set_resampling_fun(RASTER3D_Map * map, void (*resampleFun) ())
  44. {
  45. map->resampleFun = resampleFun;
  46. }
  47. /*--------------------------------------------------------------------------*/
  48. /*!
  49. * \brief
  50. *
  51. *
  52. * Returns in <em>resampleFun</em> a pointer to the resampling function used by
  53. * <em>map</em>.
  54. *
  55. * \return void
  56. */
  57. void Rast3d_get_resampling_fun(RASTER3D_Map * map, void (**resampleFun) ())
  58. {
  59. *resampleFun = map->resampleFun;
  60. }
  61. /*--------------------------------------------------------------------------*/
  62. /*!
  63. * \brief
  64. *
  65. * Returns
  66. * in <em>nnFunPtr</em> a pointer to Rast3d_nearest_neighbor () (cf.{g3d:G3d.nearestNeighbor}).
  67. *
  68. * \return void
  69. */
  70. void Rast3d_get_nearest_neighbor_fun_ptr(void (**nnFunPtr) ())
  71. {
  72. *nnFunPtr = Rast3d_nearest_neighbor;
  73. }