resample.c 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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,
  28. (double)z + 0.5, &north, &east, &top);
  29. /* convert (north, east, top) into map region coordinates (row, col, depth) */
  30. Rast3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
  31. /* Get the value from the map in map-region resolution */
  32. Rast3d_get_value_region(map, col, row, depth, value, type);
  33. }
  34. /*--------------------------------------------------------------------------*/
  35. /*!
  36. * \brief
  37. *
  38. * Sets the resampling function to be used by
  39. * Rast3d_get_value () (cf.{g3d:G3d.getValue}). This function is defined
  40. * as follows:
  41. *
  42. * \return void
  43. */
  44. void Rast3d_set_resampling_fun(RASTER3D_Map * map, void (*resampleFun) ())
  45. {
  46. map->resampleFun = resampleFun;
  47. }
  48. /*--------------------------------------------------------------------------*/
  49. /*!
  50. * \brief
  51. *
  52. *
  53. * Returns in <em>resampleFun</em> a pointer to the resampling function used by
  54. * <em>map</em>.
  55. *
  56. * \return void
  57. */
  58. void Rast3d_get_resampling_fun(RASTER3D_Map * map, void (**resampleFun) ())
  59. {
  60. *resampleFun = map->resampleFun;
  61. }
  62. /*--------------------------------------------------------------------------*/
  63. /*!
  64. * \brief
  65. *
  66. * Returns
  67. * in <em>nnFunPtr</em> a pointer to Rast3d_nearest_neighbor () (cf.{g3d:G3d.nearestNeighbor}).
  68. *
  69. * \return void
  70. */
  71. void Rast3d_get_nearest_neighbor_fun_ptr(void (**nnFunPtr) ())
  72. {
  73. *nnFunPtr = Rast3d_nearest_neighbor;
  74. }