putvalue.c 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104
  1. #include <grass/raster.h>
  2. #include "raster3d_intern.h"
  3. /*!
  4. * \brief
  5. *
  6. * Is equivalent to Rast3d_put_value (map, x, y, z, &value, FCELL_TYPE).
  7. *
  8. * \param map
  9. * \param x
  10. * \param y
  11. * \param z
  12. * \param value
  13. * \return 1 ... if successful,
  14. * 0 ... otherwise.
  15. */
  16. int Rast3d_put_float(RASTER3D_Map * map, int x, int y, int z, float value)
  17. {
  18. int tileIndex, offs;
  19. float *tile;
  20. if (map->typeIntern == DCELL_TYPE)
  21. return (Rast3d_put_double(map, x, y, z, (double)value));
  22. Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
  23. tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
  24. if (tile == NULL) {
  25. Rast3d_error("Rast3d_put_float: error in Rast3d_get_tile_ptr");
  26. return 0;
  27. }
  28. tile[offs] = value;
  29. return 1;
  30. }
  31. /*---------------------------------------------------------------------------*/
  32. /*!
  33. * \brief
  34. *
  35. * Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
  36. *
  37. * \param map
  38. * \param x
  39. * \param y
  40. * \param z
  41. * \param value
  42. * \return 1 ... if successful,
  43. * 0 ... otherwise.
  44. */
  45. int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value)
  46. {
  47. int tileIndex, offs;
  48. double *tile;
  49. if (map->typeIntern == FCELL_TYPE)
  50. return (Rast3d_put_float(map, x, y, z, (float)value));
  51. Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
  52. tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
  53. if (tile == NULL) {
  54. Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr");
  55. return 0;
  56. }
  57. tile[offs] = value;
  58. return 1;
  59. }
  60. /*---------------------------------------------------------------------------*/
  61. /*!
  62. * \brief
  63. *
  64. * After converting <em>*value</em> of <em>type</em> into the type specified
  65. * at the initialization time (i.e. <em>typeIntern</em>) this function writes the
  66. * value into the tile buffer corresponding to cell-coordinate <em>(x, y, z)</em>.
  67. *
  68. * \param map
  69. * \param x
  70. * \param y
  71. * \param z
  72. * \param value
  73. * \param type
  74. * \return 1 ... if successful,
  75. * 0 ... otherwise.
  76. */
  77. int
  78. Rast3d_put_value(RASTER3D_Map * map, int x, int y, int z, const void *value, int type)
  79. {
  80. if (type == FCELL_TYPE)
  81. return (Rast3d_put_float(map, x, y, z, *((float *)value)));
  82. return (Rast3d_put_double(map, x, y, z, *((double *)value)));
  83. }