misc.c 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include <string.h>
  4. #include <sys/types.h>
  5. #include <unistd.h>
  6. #include <grass/raster.h>
  7. #include "raster3d_intern.h"
  8. /*---------------------------------------------------------------------------*/
  9. int Rast3d_g3d_type2cell_type(int g3dType)
  10. {
  11. if (g3dType == FCELL_TYPE)
  12. return FCELL_TYPE;
  13. return DCELL_TYPE;
  14. }
  15. /*---------------------------------------------------------------------------*/
  16. void
  17. Rast3d_copy_float2Double(const float *src, int offsSrc, double *dst, int offsDst,
  18. int nElts)
  19. {
  20. int i;
  21. src += offsSrc;
  22. dst += offsDst;
  23. for (i = 0; i < nElts; i++)
  24. dst[i] = (double)src[i];
  25. }
  26. /*---------------------------------------------------------------------------*/
  27. void
  28. Rast3d_copy_double2Float(const double *src, int offsSrc, float *dst, int offsDst,
  29. int nElts)
  30. {
  31. int i;
  32. src += offsSrc;
  33. dst += offsDst;
  34. for (i = 0; i < nElts; i++)
  35. dst[i] = (float)src[i];
  36. }
  37. /*---------------------------------------------------------------------------*/
  38. void
  39. Rast3d_copy_values(const void *src, int offsSrc, int typeSrc, void *dst,
  40. int offsDst, int typeDst, int nElts)
  41. {
  42. int eltLength;
  43. if ((typeSrc == FCELL_TYPE) && (typeDst == DCELL_TYPE)) {
  44. Rast3d_copy_float2Double(src, offsSrc, dst, offsDst, nElts);
  45. return;
  46. }
  47. if ((typeSrc == DCELL_TYPE) && (typeDst == FCELL_TYPE)) {
  48. Rast3d_copy_double2Float(src, offsSrc, dst, offsDst, nElts);
  49. return;
  50. }
  51. eltLength = Rast3d_length(typeSrc);
  52. src = G_incr_void_ptr(src, eltLength * offsSrc);
  53. dst = G_incr_void_ptr(dst, eltLength * offsDst);
  54. memcpy(dst, src, nElts * eltLength);
  55. }
  56. /*---------------------------------------------------------------------------*/
  57. int Rast3d_length(int t)
  58. {
  59. if (!RASTER3D_IS_CORRECT_TYPE(t))
  60. Rast3d_fatal_error("Rast3d_length: invalid type");
  61. if (t == FCELL_TYPE)
  62. return sizeof(FCELL);
  63. if (t == DCELL_TYPE)
  64. return sizeof(DCELL);
  65. return 0;
  66. }
  67. int Rast3d_extern_length(int t)
  68. {
  69. if (!RASTER3D_IS_CORRECT_TYPE(t))
  70. Rast3d_fatal_error("Rast3d_extern_length: invalid type");
  71. if (t == FCELL_TYPE)
  72. return RASTER3D_XDR_FLOAT_LENGTH;
  73. if (t == DCELL_TYPE)
  74. return RASTER3D_XDR_DOUBLE_LENGTH;
  75. return 0;
  76. }