GRASS GIS 7 Programmer's Manual
7.8.4(2020)-exported
|
Go to the documentation of this file.
22 #include <grass/gis.h>
23 #include <grass/ogsf.h>
24 #include <grass/raster3d.h>
25 #include <grass/glocale.h>
32 #define MODE_PRELOAD 3
34 #define MODE_DEFAULT 0
36 #define STATUS_READY 0
47 void *slice[MAX_VOL_SLICES];
50 static geovol_file *Data[MAX_VOL_FILES];
51 static geovol_file Df[MAX_VOL_FILES];
53 static int Numfiles = 0;
55 static int Cur_id =
LUCKY;
61 void *
open_g3d_file(
const char *, IFLAG *,
double *,
double *);
69 static int init_volfiles(
void)
74 for (i = 0; i < MAX_VOL_FILES; i++) {
79 Cur_max = MAX_VOL_FILES;
97 static int check_num_volfiles(
void)
99 if (Numfiles < Cur_max) {
121 for (i = 0; i < Numfiles; i++) {
122 if (Data[i]->data_id ==
id) {
144 start = begin ? 0 : i + 1;
146 for (i = start; i < Numfiles; i++) {
147 if (!strcmp(Data[i]->file_name,
name)) {
148 if (Data[i]->file_type == type) {
149 return (Data[i]->data_id);
169 static char retstr[GPATH_MAX];
171 for (i = 0; i < Numfiles; i++) {
172 if (Data[i]->data_id ==
id) {
174 strcpy(retstr, fvf->file_name);
192 return (vf->file_type);
204 return (vf->data_type);
235 if (file_type == VOL_FTYPE_RASTER3D) {
253 if (type == VOL_FTYPE_RASTER3D) {
272 static int first = 1;
279 if (0 > init_volfiles()) {
287 for (i = 0; i < Numfiles; i++) {
288 if (Data[i]->data_id ==
id) {
297 if (0 > check_num_volfiles()) {
309 new = Data[Numfiles];
313 new->data_id = Cur_id++;
316 new->file_type = file_type;
321 new->data_type = data_type;
329 return (new->data_id);
366 int i, j, found = -1;
369 G_debug(5,
"gvl_file_free_datah(): id=%d",
id);
371 for (i = 0; i < Numfiles; i++) {
372 if (Data[i]->data_id ==
id) {
376 if (fvf->count > 1) {
384 fvf->file_name =
NULL;
388 for (j = i; j < (Numfiles - 1); j++) {
389 Data[j] = Data[j + 1];
427 G_warning(_(
"3D raster map <%s> not found"), filename);
433 Rast3d_open_cell_old(filename, mapset, RASTER3D_DEFAULT_WINDOW,
434 RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_DEFAULT);
436 G_warning(_(
"Unable to open 3D raster map <%s>"), filename);
441 if (!Rast3d_range_load(map)) {
442 G_warning(_(
"Unable to read range of 3D raster map <%s>"), filename);
446 Rast3d_range_min_max(map,
min,
max);
449 itype = Rast3d_file_type_map(map);
450 if (itype == FCELL_TYPE)
451 *type = VOL_DTYPE_FLOAT;
452 if (itype == DCELL_TYPE)
453 *type = VOL_DTYPE_DOUBLE;
469 if (Rast3d_close((RASTER3D_Map *) map) != 1) {
470 G_warning(_(
"Unable to close 3D raster map <%s>"),
471 ((RASTER3D_Map *) map)->fileName);
493 case (VOL_DTYPE_FLOAT):
494 *((
float *)value) = Rast3d_get_float(map,
x, y, z);
498 case (VOL_DTYPE_DOUBLE):
499 *((
double *)value) = Rast3d_get_double(map,
x, y, z);
527 case (VOL_DTYPE_FLOAT):
529 for (y = 0; y <
Rows; y++) {
530 ((
float *)data)[
x + y *
Cols] =
531 Rast3d_get_float(map,
x, y, level);
538 case (VOL_DTYPE_DOUBLE):
540 for (y = 0; y <
Rows; y++) {
541 ((
double *)data)[
x + y *
Cols] =
542 Rast3d_get_double(map,
x, y, level);
572 case (VOL_DTYPE_FLOAT):
574 for (y = 0; y <
Rows; y++) {
575 for (z = 0; z <
Depths; z++) {
577 Rast3d_get_float(map,
x, y, z);
585 case (VOL_DTYPE_DOUBLE):
587 for (y = 0; y <
Rows; y++) {
588 for (z = 0; z <
Depths; z++) {
590 Rast3d_get_double(map,
x, y, z);
619 case (VOL_DTYPE_FLOAT):
620 return Rast3d_is_null_value_num(value, FCELL_TYPE);
624 case (VOL_DTYPE_DOUBLE):
625 return Rast3d_is_null_value_num(value, DCELL_TYPE);
656 case (VOL_DTYPE_FLOAT):
657 *((
float *)value) = ((
float *)data)[offset];
661 case (VOL_DTYPE_DOUBLE):
662 *((
double *)value) = ((
double *)data)[offset];
690 switch (vf->file_type) {
692 case (VOL_FTYPE_RASTER3D):
719 switch (vf->data_type) {
721 case (VOL_DTYPE_FLOAT):
728 case (VOL_DTYPE_DOUBLE):
767 switch (vf->file_type) {
769 case (VOL_FTYPE_RASTER3D):
814 slice_data *sd = (slice_data *) vf->buff;
816 switch (vf->data_type) {
818 case (VOL_DTYPE_FLOAT):
819 for (i = 0; i < sd->num; i++) {
821 (
float *)G_malloc(
sizeof(
float) *
Cols *
Rows)) ==
NULL)
827 case (VOL_DTYPE_DOUBLE):
828 for (i = 0; i < sd->num; i++) {
830 (
double *)G_malloc(
sizeof(
double) *
Cols *
Rows)) ==
NULL)
853 slice_data *sd = (slice_data *) vf->buff;
855 for (i = 0; i < sd->num; i++) {
875 slice_data *sd = (slice_data *) vf->buff;
877 switch (vf->file_type) {
879 case (VOL_FTYPE_RASTER3D):
901 slice_data *sd = (slice_data *) vf->buff;
905 for (i = 0; i < sd->num - 1; i++) {
906 sd->slice[i] = sd->slice[i + 1];
908 sd->slice[sd->num - 1] = tmp;
911 read_slice(vf, sd->num, sd->crnt + 1 + (sd->num - sd->base));
929 slice_data *sd = (slice_data *) vf->buff;
932 if ((z >= sd->crnt - (sd->base - 1)) &&
933 (z <= sd->crnt + sd->num - sd->base)) {
940 else if (z == sd->crnt - (sd->base - 1) + 1) {
994 sd = (slice_data *) vf->buff;
999 for (i = 0; i < (sd->num - sd->base + 1); i++)
1089 switch (vf->file_type) {
1091 case (VOL_FTYPE_RASTER3D):
1123 if (vf->mode == mode)
1133 if ((vf->buff = (slice_data *) G_malloc(
sizeof(slice_data))) ==
NULL)
1136 sd = (slice_data *) vf->buff;
1176 sd = (slice_data *) vf->buff;
geovol_file * gvl_file_get_volfile(int id)
Get geovol_file structure for given handle.
void * open_volfile(const char *name, IFLAG file_type, IFLAG *data_type, double *min, double *max)
Open 3d raster file.
void * GVL_get_window()
Get window.
int gvl_file_start_read(geovol_file *vf)
Start read - allocate memory buffer a read first data into buffer.
int gvl_file_get_value(geovol_file *vf, int x, int y, int z, void *value)
Get value for volume file at x, y, z.
int free_slice_buff(geovol_file *vf)
Free buffer for slice mode reading.
int close_g3d_file(void *)
Close g3d file.
char * G_store(const char *s)
Copy string to allocated memory.
int alloc_vol_buff(geovol_file *vf)
Allocate buffer memory for full mode reading.
int find_datah(const char *name, IFLAG type, int begin)
Find file with name and type in geovol_file array an return handle.
int read_vol(geovol_file *vf)
Read all values from volume file.
char * gvl_file_get_name(int id)
Get file name for given handle.
void G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
int gvl_file_newh(const char *name, IFLAG file_type)
Get handle for given file name and type.
int gvl_file_end_read(geovol_file *vf)
End read - free buffer memory.
int is_null_g3d_value(IFLAG type, void *value)
Check for null value.
int gvl_file_free_datah(int id)
Free geovol_file structure for given handle.
int free_volfile_buffs(geovol_file *vf)
Free allocated buffers.
int get_buff_value(IFLAG type, void *data, int offset, void *value)
Get value from buffer.
int gvl_file_set_mode(geovol_file *vf, IFLAG mode)
Set read mode.
int gvl_file_get_file_type(geovol_file *vf)
Get file type for given handle.
int read_g3d_value(IFLAG type, void *map, int x, int y, int z, void *value)
Eead value from g3d file.
void G_free(void *buf)
Free allocated memory.
int free_vol_buff(geovol_file *vf)
Free memory buffer memory.
int gvl_file_get_data_type(geovol_file *vf)
Get data type for given handle.
int get_direct_value(geovol_file *vf, int x, int y, int z, void *value)
Read value direct from volume file.
int gvl_file_set_slices_param(geovol_file *vf, int n, int b)
Set parameters for slice reading.
int alloc_slice_buff(geovol_file *vf)
Allocate buffer for slice mode reading.
int read_g3d_slice(IFLAG type, void *map, int level, void *data)
Read slice of values at level from g3d file.
int close_volfile(void *map, IFLAG type)
Close volume file.
int read_slice(geovol_file *vf, int s, int l)
Read slice of values at level from volume file.
void * open_g3d_file(const char *, IFLAG *, double *, double *)
Open 3d raster file.
if(!DBFLoadRecord(psDBF, hEntity)) return NULL
int G_debug(int level, const char *msg,...)
Print debugging message.
int get_slice_value(geovol_file *vf, int x, int y, int z, void *value)
Get value from slice buffer.
void shift_slices(geovol_file *vf)
Read new slice into buffer.
int get_vol_value(geovol_file *vf, int x, int y, int z, void *value)
Get value from volume buffer.
const char * G_find_raster3d(const char *name, const char *mapset)
Search for a 3D raster map in current search path or in a specified mapset.
void gvl_file_get_min_max(geovol_file *vf, double *min, double *max)
Get minimum and maximum value in volume file.
int gvl_file_is_null_value(geovol_file *vf, void *value)
Check for null value.
void G_warning(const char *msg,...)
Print a warning message to stderr.
int read_g3d_vol(IFLAG type, void *map, void *data)
Read all values from g3d file.