raster3d_intern.h 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. #ifndef RASTER3D_INTERN_H
  2. #define RASTER3D_INTERN_H
  3. #include <grass/raster3d.h>
  4. #include <grass/gis.h>
  5. /*---------------------------------------------------------------------------*/
  6. #define RASTER3D_LONG_LENGTH sizeof (long)
  7. #define RASTER3D_XDR_INT_LENGTH 4 /* Only kept for backward compatibility */
  8. #define RASTER3D_XDR_DOUBLE_LENGTH 8 /* Only kept for backward compatibility */
  9. #define RASTER3D_XDR_FLOAT_LENGTH 4 /* Only kept for backward compatibility */
  10. #define RASTER3D_IS_CORRECT_TYPE(t) (((t) == FCELL_TYPE) || ((t) == DCELL_TYPE))
  11. #define RASTER3D_WRITE_DATA 1
  12. #define RASTER3D_READ_DATA 0
  13. #define RASTER3D_VALID_OPERATION(o) \
  14. (((o) == RASTER3D_WRITE_DATA) || ((o) == RASTER3D_READ_DATA))
  15. #define RASTER3D_MIN(a,b) ((a) <= (b) ? (a) : (b))
  16. #define RASTER3D_MAX(a,b) ((a) >= (b) ? (a) : (b))
  17. #define RASTER3D_HAS_INDEX 1
  18. #define RASTER3D_NO_INDEX 0
  19. #define RASTER3D_USE_XDR 1 /* Only kept for backward compatibility */
  20. #define RASTER3D_NO_XDR 0 /* Only kept for backward compatibility */
  21. /* Only kept for backward compatibility */
  22. #define RASTER3D_VALID_XDR_OPTION(o) (((o) == RASTER3D_USE_XDR) || ((o) == RASTER3D_NO_XDR))
  23. /*---------------------------------------------------------------------------*/
  24. /* global arrays */
  25. extern void *tmpCompress; /* compression support array */
  26. extern int tmpCompressLength; /* in bytes */
  27. extern void *xdr; /* xdr support array */
  28. extern int xdrLength; /* in bytes */
  29. /*---------------------------------------------------------------------------*/
  30. /* global variables */
  31. extern int g3d_version; /* RASTER3D_MAP_VERSION */
  32. extern int g3d_do_compression; /* RASTER3D_NO_COMPRESSION or RASTER3D_COMPRESSION */
  33. extern int g3d_precision; /* RASTER3D_ALLOW_PRECISION or RASTER3D_NO_PRECISION */
  34. extern int g3d_cache_default; /* in number of tiles; 0 ==> no cache */
  35. extern int g3d_cache_max; /* in bytes */
  36. extern int g3d_file_type; /* FCELL_TYPE or DCELL_TYPE */
  37. extern int g3d_tile_dimension[3];
  38. extern void (*g3d_error_fun) (const char *);
  39. extern char *g3d_unit_default; /* The unit description of the map data */
  40. extern int g3d_vertical_unit_default; /* spatial or temporal units from gis.h, U_METERS; ..., U_YEARS, ... */
  41. extern RASTER3D_Region g3d_window;
  42. /*---------------------------------------------------------------------------*/
  43. extern void Rast3d_fatal_error(const char * /* msg */ , ...);
  44. extern void Rast3d_fatal_error_noargs(const char * /* msg */ );
  45. /*---------------------------------------------------------------------------*/
  46. /*---------------------------------------------------------------------------*/
  47. #define RASTER3D_REGION_NORTH "North"
  48. #define RASTER3D_REGION_SOUTH "South"
  49. #define RASTER3D_REGION_EAST "East"
  50. #define RASTER3D_REGION_WEST "West"
  51. #define RASTER3D_REGION_TOP "Top"
  52. #define RASTER3D_REGION_BOTTOM "Bottom"
  53. #define RASTER3D_REGION_ROWS "nofRows"
  54. #define RASTER3D_REGION_COLS "nofCols"
  55. #define RASTER3D_REGION_DEPTHS "nofDepths"
  56. #define RASTER3D_REGION_PROJ "Proj"
  57. #define RASTER3D_REGION_ZONE "Zone"
  58. #define RASTER3D_REGION_EWRES "e-w resol"
  59. #define RASTER3D_REGION_NSRES "n-s resol"
  60. #define RASTER3D_REGION_TBRES "t-b resol"
  61. /* Coordinates to index conversion will return double.
  62. * Use floor() and integer casting to receive col,row and depth
  63. *
  64. * double cold = EASTERN_TO_COL(east, region)
  65. * int col = (int)floor(cold)
  66. *
  67. */
  68. #define EASTERN_TO_COL(east, region) (east - region->west) / (region->ew_res);
  69. #define NORTHERN_TO_ROW(north, region) (region->north - north) / (region->ns_res);
  70. #define TOP_TO_DEPTH(top, region) (top - region->bottom) / (region->tb_res);
  71. /* Location coordinates to index coordinates
  72. * region is a pointer to the RASTER3D_Region structure
  73. * north, east and top are double values
  74. * x, y, and z are pointer to double values
  75. */
  76. #define LOCATION_TO_COORD(region, north, east, top, x, y, z) \
  77. { \
  78. *x = EASTERN_TO_COL(east, region) \
  79. *y = NORTHERN_TO_ROW(north, region) \
  80. *z = TOP_TO_DEPTH(top, region) \
  81. }
  82. /* Row to north, col to east and depth to top macros
  83. * region is a pointer to the RASTER3D_Region structure
  84. * north, east and top are pointer to double values,
  85. * x, y and z are double values
  86. */
  87. #define COL_TO_EASTERN(region, x) region->west + x * region->ew_res;
  88. #define ROW_TO_NORTHERN(region, y) region->north - y * region->ns_res;
  89. #define DEPTH_TO_TOP(region, z) region->bottom + z * region->tb_res;
  90. #define COORD_TO_LOCATION(region, x, y, z, north, east, top) \
  91. { \
  92. *east = COL_TO_EASTERN(region, x) \
  93. *north = ROW_TO_NORTHERN(region, y) \
  94. *top = DEPTH_TO_TOP(region, z) \
  95. }
  96. #endif