22 #include <grass/gis.h>
23 #include <grass/gstypes.h>
24 #include <grass/gsurf.h>
25 #include <grass/G3d.h>
26 #include <grass/glocale.h>
33 #define MODE_PRELOAD 3
35 #define MODE_DEFAULT 0
37 #define STATUS_READY 0
48 void *slice[MAX_VOL_SLICES];
51 static geovol_file *Data[MAX_VOL_FILES];
52 static geovol_file Df[MAX_VOL_FILES];
54 static int Numfiles = 0;
56 static int Cur_id =
LUCKY;
62 void *
open_g3d_file(
const char *, IFLAG *,
double *,
double *);
70 static int init_volfiles(
void)
75 for (i = 0; i < MAX_VOL_FILES; i++) {
80 Cur_max = MAX_VOL_FILES;
98 static int check_num_volfiles(
void)
100 if (Numfiles < Cur_max) {
122 for (i = 0; i < Numfiles; i++) {
123 if (Data[i]->data_id ==
id) {
145 start = begin ? 0 : i + 1;
147 for (i = start; i < Numfiles; i++) {
150 return (Data[i]->data_id);
170 static char retstr[GPATH_MAX];
172 for (i = 0; i < Numfiles; i++) {
173 if (Data[i]->data_id ==
id) {
175 strcpy(retstr, fvf->file_name);
193 return (vf->file_type);
205 return (vf->data_type);
236 if (file_type == VOL_FTYPE_G3D) {
254 if (type == VOL_FTYPE_G3D) {
273 static int first = 1;
280 if (0 > init_volfiles()) {
287 if (0 <= (
id =
find_datah(name, file_type, 1))) {
288 for (i = 0; i < Numfiles; i++) {
289 if (Data[i]->data_id ==
id) {
298 if (0 > check_num_volfiles()) {
310 new = Data[Numfiles];
314 new->data_id = Cur_id++;
316 new->file_name =
G_store(name);
322 new->data_type = data_type;
330 return (new->data_id);
367 int i, j, found = -1;
370 G_debug(5,
"gvl_file_free_datah(): id=%d",
id);
372 for (i = 0; i < Numfiles; i++) {
373 if (Data[i]->data_id ==
id) {
377 if (fvf->count > 1) {
385 fvf->file_name =
NULL;
389 for (j = i; j < (Numfiles - 1); j++) {
390 Data[j] = Data[j + 1];
428 G_warning(_(
"3D raster map <%s> not found"), filename);
435 G3D_TILE_SAME_AS_FILE, G3D_USE_CACHE_DEFAULT);
437 G_warning(_(
"Unable to open 3D raster map <%s>"), filename);
443 G_warning(_(
"Unable to read range of 3D raster map <%s>"), filename);
451 if (itype == FCELL_TYPE)
452 *type = VOL_DTYPE_FLOAT;
453 if (itype == DCELL_TYPE)
454 *type = VOL_DTYPE_DOUBLE;
471 G_warning(_(
"Unable to close 3D raster map <%s>"),
472 ((G3D_Map *) map)->fileName);
494 case (VOL_DTYPE_FLOAT):
499 case (VOL_DTYPE_DOUBLE):
528 case (VOL_DTYPE_FLOAT):
529 for (x = 0; x <
Cols; x++) {
530 for (y = 0; y <
Rows; y++) {
531 ((
float *)data)[x + y *
Cols] =
539 case (VOL_DTYPE_DOUBLE):
540 for (x = 0; x <
Cols; x++) {
541 for (y = 0; y <
Rows; y++) {
542 ((
double *)data)[x + y *
Cols] =
573 case (VOL_DTYPE_FLOAT):
574 for (x = 0; x <
Cols; x++) {
575 for (y = 0; y <
Rows; y++) {
576 for (z = 0; z <
Depths; z++) {
577 ((
float *)data)[x + y * Cols + z * Rows *
Cols] =
586 case (VOL_DTYPE_DOUBLE):
587 for (x = 0; x <
Cols; x++) {
588 for (y = 0; y <
Rows; y++) {
589 for (z = 0; z <
Depths; z++) {
590 ((
double *)data)[x + y * Cols + z * Rows *
Cols] =
620 case (VOL_DTYPE_FLOAT):
625 case (VOL_DTYPE_DOUBLE):
657 case (VOL_DTYPE_FLOAT):
658 *((
float *)value) = ((
float *)data)[offset];
662 case (VOL_DTYPE_DOUBLE):
663 *((
double *)value) = ((
double *)data)[offset];
691 switch (vf->file_type) {
693 case (VOL_FTYPE_G3D):
720 switch (vf->data_type) {
722 case (VOL_DTYPE_FLOAT):
729 case (VOL_DTYPE_DOUBLE):
731 (
double *)G_malloc(
sizeof(
double) *
Cols *
Rows * Depths)) ==
768 switch (vf->file_type) {
770 case (VOL_FTYPE_G3D):
819 case (VOL_DTYPE_FLOAT):
820 for (i = 0; i < sd->
num; i++) {
822 (
float *)G_malloc(
sizeof(
float) *
Cols *
Rows)) ==
NULL)
828 case (VOL_DTYPE_DOUBLE):
829 for (i = 0; i < sd->
num; i++) {
831 (
double *)G_malloc(
sizeof(
double) *
Cols *
Rows)) ==
NULL)
856 for (i = 0; i < sd->
num; i++) {
880 case (VOL_FTYPE_G3D):
906 for (i = 0; i < sd->
num - 1; i++) {
941 else if (z == sd->
crnt - (sd->
base - 1) + 1) {
1000 for (i = 0; i < (sd->
num - sd->
base + 1); i++)
1090 switch (vf->file_type) {
1092 case (VOL_FTYPE_G3D):
1124 if (vf->mode == mode)
int is_null_g3d_value(IFLAG type, void *value)
Check for null value.
void G_free(void *buf)
Free allocated memory.
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.
geovol_file * gvl_file_get_volfile(int id)
Get geovol_file structure for given handle.
double G3d_getDouble(G3D_Map *map, int x, int y, int z)
Is equivalent to G3d_getValue (map, x, y, z, &value, DCELL_TYPE); return value.
void * slice[MAX_VOL_SLICES]
int G3d_isNullValueNum(const void *n, int type)
int gvl_file_get_data_type(geovol_file *vf)
Get data type for given handle.
structure for slice mode reading from volume file
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.
int gvl_file_get_file_type(geovol_file *vf)
Get file type for given handle.
int get_buff_value(IFLAG type, void *data, int offset, void *value)
Get value from buffer.
int close_volfile(void *map, IFLAG type)
Close volume file.
switch(read_cats(name, mapset, pcats))
int read_g3d_value(IFLAG type, void *map, int x, int y, int z, void *value)
Eead value from g3d file.
int gvl_file_set_slices_param(geovol_file *vf, int n, int b)
Set parameters for slice reading.
int get_slice_value(geovol_file *vf, int x, int y, int z, void *value)
Get value from slice buffer.
void G3d_range_min_max(G3D_Map *map, double *min, double *max)
Returns in min and max the minimum and maximum values of the range.
int free_volfile_buffs(geovol_file *vf)
Free allocated buffers.
int G3d_range_load(G3D_Map *map)
Loads the range into the range structure of map.
int gvl_file_newh(const char *name, IFLAG file_type)
Get handle for given file name and type.
int alloc_slice_buff(geovol_file *vf)
Allocate buffer for slice mode reading.
void shift_slices(geovol_file *vf)
Read new slice into buffer.
int gvl_file_start_read(geovol_file *vf)
Start read - allocate memory buffer a read first data into buffer.
int G3d_closeCell(G3D_Map *map)
Closes g3d-file. If map is new and cache-mode is used for map then every tile which is not flushed be...
int get_direct_value(geovol_file *vf, int x, int y, int z, void *value)
Read value direct from volume file.
int gvl_file_free_datah(int id)
Free geovol_file structure for given handle.
int get_vol_value(geovol_file *vf, int x, int y, int z, void *value)
Get value from volume buffer.
void * open_g3d_file(const char *, IFLAG *, double *, double *)
Open 3d raster file.
int gvl_file_end_read(geovol_file *vf)
End read - free buffer memory.
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
void * G3d_openCellOld(const char *name, const char *mapset, G3D_Region *window, int typeIntern, int cache)
Opens existing g3d-file name in mapset. Tiles are stored in memory with type which must be any of FCE...
int G_debug(int level, const char *msg,...)
Print debugging message.
void * GVL_get_window()
Get window.
int read_g3d_vol(IFLAG type, void *map, void *data)
Read all values from g3d file.
int gvl_file_is_null_value(geovol_file *vf, void *value)
Check for null value.
void gvl_file_get_min_max(geovol_file *vf, double *min, double *max)
Get minimum and maximum value in volume file.
char * G_find_grid3(const char *name, const char *mapset)
int free_slice_buff(geovol_file *vf)
Free buffer for slice mode reading.
int G_fatal_error(const char *msg,...)
Print a fatal error message to stderr.
void * open_volfile(const char *name, IFLAG file_type, IFLAG *data_type, double *min, double *max)
Open 3d raster file.
int free_vol_buff(geovol_file *vf)
Free memory buffer memory.
int find_datah(const char *name, IFLAG type, int begin)
Find file with name and type in geovol_file array an return handle.
int gvl_file_set_mode(geovol_file *vf, IFLAG mode)
Set read mode.
int read_g3d_slice(IFLAG type, void *map, int level, void *data)
Read slice of values at level from g3d file.
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.
float G3d_getFloat(G3D_Map *map, int x, int y, int z)
Is equivalent to G3d_getValue (map, x, y, z, &value, FCELL_TYPE); return value.
int read_slice(geovol_file *vf, int s, int l)
Read slice of values at level from volume file.