raster3d.h 8.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. #ifndef GRASS_RASTER3D_H
  2. #define GRASS_RASTER3D_H
  3. #include <grass/gis.h>
  4. #include <grass/raster.h>
  5. #define RASTER3D_MAP_VERSION 2 /* Second version of the raster 3D map layout.
  6. * Old maps withput version information are
  7. * defined as version == 1 when reading the header.
  8. */
  9. #define RASTER3D_TILE_SAME_AS_FILE 2
  10. #define RASTER3D_NO_COMPRESSION 0
  11. #define RASTER3D_COMPRESSION 1
  12. #define RASTER3D_MAX_PRECISION -1
  13. #define RASTER3D_NO_CACHE 0
  14. #define RASTER3D_USE_CACHE_DEFAULT -1
  15. #define RASTER3D_USE_CACHE_X -2
  16. #define RASTER3D_USE_CACHE_Y -3
  17. #define RASTER3D_USE_CACHE_Z -4
  18. #define RASTER3D_USE_CACHE_XY -5
  19. #define RASTER3D_USE_CACHE_XZ -6
  20. #define RASTER3D_USE_CACHE_YZ -7
  21. #define RASTER3D_USE_CACHE_XYZ -8
  22. #define RASTER3D_DEFAULT_WINDOW 0 /* NULL pointer, now (int)0 because issues with ctypesgen */
  23. #define RASTER3D_DIRECTORY "grid3"
  24. #define RASTER3D_CELL_ELEMENT "cell"
  25. #define RASTER3D_CATS_ELEMENT "cats"
  26. #define RASTER3D_RANGE_ELEMENT "range"
  27. #define RASTER3D_HEADER_ELEMENT "cellhd"
  28. #define RASTER3D_HISTORY_ELEMENT "hist"
  29. #define RASTER3D_COLOR_ELEMENT "color"
  30. #define RASTER3D_COLOR2_DIRECTORY "colr2"
  31. #define RASTER3D_MASK_MAP "RASTER3D_MASK"
  32. #define RASTER3D_WINDOW_ELEMENT "WIND3"
  33. #define RASTER3D_DEFAULT_WINDOW_ELEMENT "DEFAULT_WIND3"
  34. #define RASTER3D_WINDOW_DATABASE "windows3d"
  35. #define RASTER3D_PERMANENT_MAPSET "PERMANENT"
  36. /*---------------------------------------------------------------------------*/
  37. typedef struct
  38. {
  39. double north, south;
  40. double east, west;
  41. double top, bottom;
  42. /* dimension of data in "cells"; rows == #x; cols == #y; depths == #z */
  43. int rows, cols, depths;
  44. double ns_res, ew_res, tb_res;
  45. int proj; /* Projection (see gis.h) */
  46. int zone; /* Projection zone (see gis.h) */
  47. } RASTER3D_Region;
  48. /*---------------------------------------------------------------------------*/
  49. struct RASTER3D_Map;
  50. typedef void resample_fn(struct RASTER3D_Map *, int, int, int, void *, int);
  51. /*---------------------------------------------------------------------------*/
  52. typedef struct RASTER3D_Map
  53. {
  54. int version; /* The version of the raster 3D map layout */
  55. char *fileName;
  56. char *tempName;
  57. char *mapset;
  58. /* operation performed on map */
  59. int operation; /* RASTER3D_WRITE_DATA or RASTER3D_READ_DATA */
  60. /* region */
  61. RASTER3D_Region region;
  62. /* window for map */
  63. RASTER3D_Region window;
  64. /* resmapling function used for map. default is nearest neighbor */
  65. resample_fn *resampleFun;
  66. /* units */
  67. char* unit; /* space (U_METER, ...) */
  68. int vertical_unit; /* space or time (U_METER, ..., U_YEAR, ...) */
  69. /* dimension of a single tile in "cells" */
  70. int tileX, tileY, tileZ;
  71. /* # of tiles in x, y, and z direction */
  72. int nx, ny, nz;
  73. /* data file specific information */
  74. /* file descriptor */
  75. int data_fd; /* file descriptor */
  76. /* type in which data is stored on file */
  77. int type; /* DCELL_TYPE or FCELL_TYPE */
  78. /* data concering the compression */
  79. int precision; /* RASTER3D_MAX_PRECISION or, 0 .. 23 for float,
  80. 0 .. 52 for double */
  81. int compression; /* RASTER3D_NO_COMPRESSION or RASTER3D_COMPRESSION */
  82. int useLzw; /* RASTER3D_USE_LZW or RASTER3D_NO_LZW !!! only kept for backward compatibility */
  83. int useRle; /* RASTER3D_USE_RLE or RASTER3D_NO_RLE !!! only kept for backward compatibility */
  84. int useXdr; /* RASTER3D_USE_XDR or RASTER3D_NO_XDR !!! only kept for backward compatibility */
  85. /* pointer to first tile in file */
  86. int offset;
  87. /* pointer to the first index entry in file */
  88. long indexOffset;
  89. /* sizeof (long) of the system on which the file is/was written */
  90. int indexLongNbytes;
  91. /* max # bytes used in the representation of indices; this is equal to */
  92. /* # bytes used in the representation of "indexOffset" */
  93. int indexNbytesUsed;
  94. /* pointer to the last entry in the file */
  95. int fileEndPtr;
  96. /* indicates if index is stored in file; used for RASTER3D_READ_DATA only */
  97. int hasIndex; /* RASTER3D_HAS_INDEX or RASTER3D_NO_INDEX */
  98. /* information concerning internal storage of data */
  99. /* index specific information */
  100. /* index[i] == the offset of tile "i" in the data file */
  101. long *index;
  102. /* tileLength[i] == # bytes used to store tile "i" */
  103. int *tileLength;
  104. /* tile specific information */
  105. /* type in which data is stored in memory */
  106. int typeIntern; /* DCELL_TYPE or FCELL_TYPE */
  107. /* in non-cache mode the "data" array is used to store one tile */
  108. char *data;
  109. /* index of tile currently stored in "data"; -1 if none */
  110. int currentIndex;
  111. /* cache related variables */
  112. int useCache; /* 1 if cache is used */
  113. void *cache; /* pointer to cache structure */
  114. int cacheFD; /* file descriptor of cache file -- write mode only */
  115. char *cacheFileName; /* filename of cache file -- write mode only */
  116. long cachePosLast; /* position of last entry in cache file -- write */
  117. /* mode only */
  118. /* range info */
  119. struct FPRange range;
  120. /* some constants stored for efficiency */
  121. /* number of bytes required to store a single value of "type" */
  122. int numLengthExtern;
  123. /* number of bytes required to store a single value of "typeIntern" */
  124. int numLengthIntern;
  125. /* see header.c for details */
  126. int clipX, clipY, clipZ;
  127. int tileXY, tileSize;
  128. int nxy, nTiles;
  129. /* mask related information */
  130. int useMask; /* 1 if mask is used; 0 otherwise */
  131. } RASTER3D_Map;
  132. /*---------------------------------------------------------------------------*/
  133. typedef struct
  134. {
  135. char *elts; /* ptr to array of elts */
  136. int nofElts; /* size of "elts" */
  137. int eltSize; /* size of elt in "elts" */
  138. int *names; /* name[i] is the name of elts[i] */
  139. char *locks; /* lock[i] == 1 iff elts[i] is locked
  140. lock[i] == 0 iff elts[i] is unlocked but active
  141. lock[i] == 2 iff elts[i] doesn't contain valid data */
  142. int autoLock; /* 1 if auto locking is turned on */
  143. int nofUnlocked; /* nof tiles which are unlocked */
  144. int minUnlocked; /* min nof elts which have to remain unlocked. min = 1 */
  145. int *next, *prev; /* prev/next pointers for fifo */
  146. int first, last; /* index (into next) of first and last elt in fifo */
  147. /* first == -1 iff fifo is empty */
  148. int (*eltRemoveFun) (); /* callback activated if the contents of an
  149. elt needs to be removed */
  150. void *eltRemoveFunData; /* pointer to user data passed along with
  151. eltRemoveFun */
  152. int (*eltLoadFun) (); /* callback activated to load contents of an elt */
  153. void *eltLoadFunData; /* pointer to user data passed along with
  154. eltLoadFun */
  155. void *hash; /* ptr to hashTable used to relate external names to
  156. internal indices (elts) */
  157. } RASTER3D_cache;
  158. /*---------------------------------------------------------------------------*/
  159. typedef struct
  160. {
  161. int nofNames;
  162. int *index;
  163. char *active;
  164. int lastName;
  165. int lastIndex;
  166. int lastIndexActive;
  167. } Rast3d_cache_hash;
  168. /*---------------------------------------------------------------------------*/
  169. /*Structures */
  170. typedef struct _d_interval
  171. {
  172. double low, high;
  173. int inf;
  174. struct _d_interval *next;
  175. } d_Interval;
  176. typedef struct _d_mask
  177. {
  178. d_Interval *list;
  179. } d_Mask;
  180. /*---------------------------------------------------------------------------*/
  181. typedef int write_fn(int, const void *, void *);
  182. typedef int read_fn(int, void *, void *);
  183. /*---------------------------------------------------------------------------*/
  184. /* for storing values of 3D raster block in a flat array */
  185. typedef struct
  186. {
  187. DCELL *array;
  188. int sx;
  189. int sy;
  190. int sz;
  191. } RASTER3D_Array_double;
  192. #define RASTER3D_ARRAY_ACCESS(arr, x, y, z) \
  193. ((arr)->array[(arr)->sx * (arr)->sy * (z) + (arr)->sx * (y) + (x)])
  194. /*============================== Prototypes ================================*/
  195. #include <grass/defs/raster3d.h>
  196. #endif /* #ifndef GRASS_RASTER3D_H */