resample.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <stdio.h>
  2. #include <grass/gis.h>
  3. #include "G3d_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. G3d_nearestNeighbor(G3D_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. G3d_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. G3d_location2coord(&(map->region), north, east, top, &col, &row, &depth);
  30. /* if (row, col, depth) outside map region return NULL value */
  31. if ((row < 0) || (row >= map->region.rows) ||
  32. (col < 0) || (col >= map->region.cols) ||
  33. (depth < 0) || (depth >= map->region.depths)) {
  34. G3d_setNullValue(value, 1, type);
  35. return;
  36. }
  37. /* Get the value from the map in map-region resolution */
  38. G3d_getValueRegion(map, col, row, depth, value, type);
  39. }
  40. /*--------------------------------------------------------------------------*/
  41. /*!
  42. * \brief
  43. *
  44. * Sets the resampling function to be used by
  45. * G3d_getValue () (cf.{g3d:G3d.getValue}). This function is defined
  46. * as follows:
  47. *
  48. * \return void
  49. */
  50. void G3d_setResamplingFun(G3D_Map * map, void (*resampleFun) ())
  51. {
  52. map->resampleFun = resampleFun;
  53. }
  54. /*--------------------------------------------------------------------------*/
  55. /*!
  56. * \brief
  57. *
  58. *
  59. * Returns in <em>resampleFun</em> a pointer to the resampling function used by
  60. * <em>map</em>.
  61. *
  62. * \return void
  63. */
  64. void G3d_getResamplingFun(G3D_Map * map, void (**resampleFun) ())
  65. {
  66. *resampleFun = map->resampleFun;
  67. }
  68. /*--------------------------------------------------------------------------*/
  69. /*!
  70. * \brief
  71. *
  72. * Returns
  73. * in <em>nnFunPtr</em> a pointer to G3d_nearestNeighbor () (cf.{g3d:G3d.nearestNeighbor}).
  74. *
  75. * \return void
  76. */
  77. void G3d_getNearestNeighborFunPtr(void (**nnFunPtr) ())
  78. {
  79. *nnFunPtr = G3d_nearestNeighbor;
  80. }