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