putvalue.c 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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 int
  14. */
  15. int Rast3d_put_float(RASTER3D_Map * map, int x, int y, int z, float value)
  16. {
  17. int tileIndex, offs;
  18. float *tile;
  19. if (map->typeIntern == DCELL_TYPE) {
  20. if (!Rast3d_put_double(map, x, y, z, (double)value)) {
  21. Rast3d_error("Rast3d_put_float: error in Rast3d_put_double");
  22. return 0;
  23. }
  24. return 1;
  25. }
  26. Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
  27. tile = (float *)Rast3d_get_tile_ptr(map, tileIndex);
  28. if (tile == NULL) {
  29. Rast3d_error("Rast3d_put_float: error in Rast3d_get_tile_ptr");
  30. return 0;
  31. }
  32. tile[offs] = value;
  33. return 1;
  34. }
  35. /*---------------------------------------------------------------------------*/
  36. /*!
  37. * \brief
  38. *
  39. * Is equivalent to Rast3d_put_value (map, x, y, z, &value, DCELL_TYPE).
  40. *
  41. * \param map
  42. * \param x
  43. * \param y
  44. * \param z
  45. * \param value
  46. * \return int
  47. */
  48. int Rast3d_put_double(RASTER3D_Map * map, int x, int y, int z, double value)
  49. {
  50. int tileIndex, offs;
  51. double *tile;
  52. if (map->typeIntern == FCELL_TYPE) {
  53. if (!Rast3d_put_float(map, x, y, z, (float)value)) {
  54. Rast3d_error("Rast3d_put_double: error in Rast3d_put_float");
  55. return 0;
  56. }
  57. return 1;
  58. }
  59. Rast3d_coord2tile_index(map, x, y, z, &tileIndex, &offs);
  60. tile = (double *)Rast3d_get_tile_ptr(map, tileIndex);
  61. if (tile == NULL) {
  62. Rast3d_error("Rast3d_put_double: error in Rast3d_get_tile_ptr");
  63. return 0;
  64. }
  65. tile[offs] = value;
  66. return 1;
  67. }
  68. /*---------------------------------------------------------------------------*/
  69. /*!
  70. * \brief
  71. *
  72. * After converting <em>*value</em> of <em>type</em> into the type specified
  73. * at the initialization time (i.e. <em>typeIntern</em>) this function writes the
  74. * value into the tile buffer corresponding to cell-coordinate <em>(x, y, z)</em>.
  75. *
  76. * \param map
  77. * \param x
  78. * \param y
  79. * \param z
  80. * \param value
  81. * \param type
  82. * \return 1 ... if successful,
  83. * 0 ... otherwise.
  84. */
  85. int
  86. Rast3d_put_value(RASTER3D_Map * map, int x, int y, int z, const void *value, int type)
  87. {
  88. if (type == FCELL_TYPE) {
  89. if (!Rast3d_put_float(map, x, y, z, *((float *)value))) {
  90. Rast3d_error("Rast3d_put_value: error in Rast3d_put_float");
  91. return 0;
  92. }
  93. return 1;
  94. }
  95. if (!Rast3d_put_double(map, x, y, z, *((double *)value))) {
  96. Rast3d_error("Rast3d_put_value: error in Rast3d_put_double");
  97. return 0;
  98. }
  99. return 1;
  100. }