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