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