GRASS GIS 7 Programmer's Manual  7.7.svn(2018)-r73373
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gvl_file.c File Reference

OGSF library - loading and manipulating volumes (lower level functions) More...

#include <string.h>
#include <stdlib.h>
#include <grass/gis.h>
#include <grass/ogsf.h>
#include <grass/raster3d.h>
#include <grass/glocale.h>
Include dependency graph for gvl_file.c:

Go to the source code of this file.

Macros

#define LUCKY   33
 
#define MODE_DIRECT   0
 
#define MODE_SLICE   1
 
#define MODE_FULL   2
 
#define MODE_PRELOAD   3
 
#define MODE_DEFAULT   0
 
#define STATUS_READY   0
 
#define STATUS_BUSY   1
 

Functions

void * open_g3d_file (const char *filename, IFLAG *type, double *min, double *max)
 Open 3d raster file. More...
 
int close_g3d_file (void *map)
 Close g3d file. More...
 
geovol_filegvl_file_get_volfile (int id)
 Get geovol_file structure for given handle. More...
 
int find_datah (const char *name, IFLAG type, int begin)
 Find file with name and type in geovol_file array an return handle. More...
 
char * gvl_file_get_name (int id)
 Get file name for given handle. More...
 
int gvl_file_get_file_type (geovol_file *vf)
 Get file type for given handle. More...
 
int gvl_file_get_data_type (geovol_file *vf)
 Get data type for given handle. More...
 
void gvl_file_get_min_max (geovol_file *vf, double *min, double *max)
 Get minimum and maximum value in volume file. More...
 
void * open_volfile (const char *name, IFLAG file_type, IFLAG *data_type, double *min, double *max)
 Open 3d raster file. More...
 
int close_volfile (void *map, IFLAG type)
 Close volume file. More...
 
int gvl_file_newh (const char *name, IFLAG file_type)
 Get handle for given file name and type. More...
 
int free_volfile_buffs (geovol_file *vf)
 Free allocated buffers. More...
 
int gvl_file_free_datah (int id)
 Free geovol_file structure for given handle. More...
 
int read_g3d_value (IFLAG type, void *map, int x, int y, int z, void *value)
 Eead value from g3d file. More...
 
int read_g3d_slice (IFLAG type, void *map, int level, void *data)
 Read slice of values at level from g3d file. More...
 
int read_g3d_vol (IFLAG type, void *map, void *data)
 Read all values from g3d file. More...
 
int is_null_g3d_value (IFLAG type, void *value)
 Check for null value. More...
 
int get_buff_value (IFLAG type, void *data, int offset, void *value)
 Get value from buffer. More...
 
int get_direct_value (geovol_file *vf, int x, int y, int z, void *value)
 Read value direct from volume file. More...
 
int alloc_vol_buff (geovol_file *vf)
 Allocate buffer memory for full mode reading. More...
 
int free_vol_buff (geovol_file *vf)
 Free memory buffer memory. More...
 
int read_vol (geovol_file *vf)
 Read all values from volume file. More...
 
int get_vol_value (geovol_file *vf, int x, int y, int z, void *value)
 Get value from volume buffer. More...
 
int alloc_slice_buff (geovol_file *vf)
 Allocate buffer for slice mode reading. More...
 
int free_slice_buff (geovol_file *vf)
 Free buffer for slice mode reading. More...
 
int read_slice (geovol_file *vf, int s, int l)
 Read slice of values at level from volume file. More...
 
void shift_slices (geovol_file *vf)
 Read new slice into buffer. More...
 
int get_slice_value (geovol_file *vf, int x, int y, int z, void *value)
 Get value from slice buffer. More...
 
int gvl_file_start_read (geovol_file *vf)
 Start read - allocate memory buffer a read first data into buffer. More...
 
int gvl_file_end_read (geovol_file *vf)
 End read - free buffer memory. More...
 
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. More...
 
int gvl_file_is_null_value (geovol_file *vf, void *value)
 Check for null value. More...
 
int gvl_file_set_mode (geovol_file *vf, IFLAG mode)
 Set read mode. More...
 
int gvl_file_set_slices_param (geovol_file *vf, int n, int b)
 Set parameters for slice reading. More...
 

Detailed Description

OGSF library - loading and manipulating volumes (lower level functions)

GRASS OpenGL gsurf OGSF Library

(C) 1999-2008 by the GRASS Development Team

This program is free software under the GNU General Public License (>=v2). Read the file COPYING that comes with GRASS for details.

Author
Tomas Paudits (February 2004)
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gvl_file.c.

Macro Definition Documentation

#define LUCKY   33

Definition at line 27 of file gvl_file.c.

#define MODE_DEFAULT   0

Definition at line 34 of file gvl_file.c.

Referenced by gvl_file_newh().

#define MODE_DIRECT   0

Definition at line 29 of file gvl_file.c.

Referenced by gvl_file_get_value().

#define MODE_FULL   2

Definition at line 31 of file gvl_file.c.

Referenced by gvl_file_end_read(), gvl_file_get_value(), and gvl_file_start_read().

#define MODE_PRELOAD   3

Definition at line 32 of file gvl_file.c.

Referenced by free_volfile_buffs(), gvl_file_get_value(), and gvl_file_set_mode().

#define STATUS_BUSY   1
#define STATUS_READY   0

Definition at line 36 of file gvl_file.c.

Referenced by gvl_file_end_read(), and gvl_file_newh().

Function Documentation

int alloc_slice_buff ( geovol_file vf)

Allocate buffer for slice mode reading.

Parameters
vfpointer to geovol_file struct
Returns
-1 on failure
1 on success

Definition at line 811 of file gvl_file.c.

References geovol_file::buff, Cols, geovol_file::data_type, NULL, Rows, switch(), VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by gvl_file_start_read().

int alloc_vol_buff ( geovol_file vf)

Allocate buffer memory for full mode reading.

Parameters
vfpointer to geovol_file
Returns
-1 on failure
1 on success

Definition at line 717 of file gvl_file.c.

References geovol_file::buff, Cols, geovol_file::data_type, Depths, NULL, Rows, VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by gvl_file_set_mode(), and gvl_file_start_read().

int close_g3d_file ( void *  map)

Close g3d file.

Parameters
map3d raster map
Returns
-1 on failure
1 on success

Definition at line 466 of file gvl_file.c.

References _, G_warning(), and Rast3d_close().

Referenced by close_volfile().

int close_volfile ( void *  map,
IFLAG  type 
)

Close volume file.

Parameters
mapvolume filename
typefile type
Returns
-1 on failure

Definition at line 251 of file gvl_file.c.

References close_g3d_file(), and VOL_FTYPE_RASTER3D.

Referenced by gvl_file_free_datah().

int find_datah ( const char *  name,
IFLAG  type,
int  begin 
)

Find file with name and type in geovol_file array an return handle.

Parameters
namefile name
begin
dataid
-1not found

Definition at line 139 of file gvl_file.c.

Referenced by gvl_file_newh().

int free_slice_buff ( geovol_file vf)

Free buffer for slice mode reading.

Parameters
vfpointer to geovol_file struct
Returns
1

Definition at line 850 of file gvl_file.c.

References geovol_file::buff, for(), and G_free().

Referenced by gvl_file_end_read().

int free_vol_buff ( geovol_file vf)

Free memory buffer memory.

Parameters
vfpointer to geovol_file struct
Returns
1

Definition at line 750 of file gvl_file.c.

References geovol_file::buff, and G_free().

Referenced by gvl_file_end_read().

int free_volfile_buffs ( geovol_file vf)

Free allocated buffers.

Parameters
vfpointer to geovol_file struct
Returns
1

Definition at line 342 of file gvl_file.c.

References geovol_file::buff, G_free(), geovol_file::mode, MODE_PRELOAD, MODE_SLICE, and NULL.

Referenced by gvl_file_free_datah().

int get_buff_value ( IFLAG  type,
void *  data,
int  offset,
void *  value 
)

Get value from buffer.

Parameters
typedata type
datadata buffer
offset
value
Returns
-1 on failure (unsupported data type)
1 on success

Definition at line 652 of file gvl_file.c.

References VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by get_slice_value(), and get_vol_value().

int get_direct_value ( geovol_file vf,
int  x,
int  y,
int  z,
void *  value 
)

Read value direct from volume file.

Parameters
vfpointer to geovol_file struct
x,y,zreal point
[out]valuedata value
Returns
-1 on failure
1 on success

Definition at line 688 of file gvl_file.c.

References geovol_file::data_type, geovol_file::file_type, geovol_file::map, read_g3d_value(), and VOL_FTYPE_RASTER3D.

Referenced by gvl_file_get_value().

int get_slice_value ( geovol_file vf,
int  x,
int  y,
int  z,
void *  value 
)

Get value from slice buffer.

Parameters
vfpointer to geovol_file struct
x,y,zreal point
[out]valuedata value
Returns
-1 on failure
1 on success

Definition at line 927 of file gvl_file.c.

References geovol_file::buff, Cols, geovol_file::data_type, get_buff_value(), if(), and shift_slices().

Referenced by gvl_file_get_value().

int get_vol_value ( geovol_file vf,
int  x,
int  y,
int  z,
void *  value 
)

Get value from volume buffer.

Parameters
vfpointer to geovol_file struct
x,y,zreal point
[out]valuedata value
Returns
1

Definition at line 790 of file gvl_file.c.

References geovol_file::buff, Cols, geovol_file::data_type, get_buff_value(), and Rows.

Referenced by gvl_file_get_value().

int gvl_file_end_read ( geovol_file vf)

End read - free buffer memory.

Parameters
vfpointer to geovol_file struct
Returns
-1 on failure
1 on success

Definition at line 1018 of file gvl_file.c.

References free_slice_buff(), free_vol_buff(), geovol_file::mode, MODE_FULL, MODE_SLICE, geovol_file::status, and STATUS_READY.

Referenced by gvl_isosurf_calc(), and slice_calc().

int gvl_file_free_datah ( int  id)
int gvl_file_get_data_type ( geovol_file vf)

Get data type for given handle.

Parameters
vfpointer to geovol_file struct
Returns
data type

Definition at line 202 of file gvl_file.c.

References geovol_file::data_type.

Referenced by iso_get_cube_value(), and slice_get_value().

int gvl_file_get_file_type ( geovol_file vf)

Get file type for given handle.

Parameters
vfpointer to geovol_file struct
Returns
file type

Definition at line 190 of file gvl_file.c.

References geovol_file::file_type.

void gvl_file_get_min_max ( geovol_file vf,
double *  min,
double *  max 
)

Get minimum and maximum value in volume file.

Parameters
vfpointer to geovol_file struct
[out]minmin value
[out]maxmax value

Definition at line 214 of file gvl_file.c.

References geovol_file::max, and geovol_file::min.

Referenced by iso_get_range().

char* gvl_file_get_name ( int  id)

Get file name for given handle.

Parameters
idhandle id
Returns
file name
NULL on failure

Definition at line 165 of file gvl_file.c.

References geovol_file::file_name, GPATH_MAX, and NULL.

Referenced by GVL_get_volname(), GVL_isosurf_get_att(), gvl_slices_calc(), and gvld_isosurf().

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.

Parameters
vfpointer to geovol_file struct
Returns
-1 on failure
1 on success

Definition at line 1050 of file gvl_file.c.

References get_direct_value(), get_slice_value(), get_vol_value(), geovol_file::mode, MODE_DIRECT, MODE_FULL, MODE_PRELOAD, MODE_SLICE, geovol_file::status, and STATUS_BUSY.

Referenced by iso_get_cube_value(), and slice_get_value().

geovol_file* gvl_file_get_volfile ( int  id)

Get geovol_file structure for given handle.

Parameters
id
Returns
pointer to geovol_file struct
NULL on failure

Definition at line 117 of file gvl_file.c.

References NULL.

Referenced by gvl_isosurf_calc(), iso_get_cube_value(), iso_get_range(), slice_calc(), and slice_get_value().

int gvl_file_is_null_value ( geovol_file vf,
void *  value 
)

Check for null value.

Parameters
vfpointer to geovol_file struct
valuedata value
Returns
-1 on failure
1 on success

Definition at line 1087 of file gvl_file.c.

References geovol_file::file_type, is_null_g3d_value(), and VOL_FTYPE_RASTER3D.

Referenced by iso_get_cube_value().

int gvl_file_newh ( const char *  name,
IFLAG  file_type 
)

Get handle for given file name and type.

Parameters
namevolume filename
file_typefile type
Returns
data id
-1 on failure

Definition at line 269 of file gvl_file.c.

References geovol_file::count, find_datah(), G_store(), gvl_file_set_mode(), IFLAG, max, min, MODE_DEFAULT, NULL, open_volfile(), and STATUS_READY.

Referenced by gvl_isosurf_set_att_map(), and GVL_load_vol().

int gvl_file_set_mode ( geovol_file vf,
IFLAG  mode 
)

Set read mode.

Parameters
vfpointer to geovol_file struct
moderead mode
Returns
-1 on failure
1 on success

Definition at line 1116 of file gvl_file.c.

References alloc_vol_buff(), geovol_file::buff, G_free(), geovol_file::mode, MODE_PRELOAD, MODE_SLICE, NULL, read_vol(), geovol_file::status, and STATUS_BUSY.

Referenced by gvl_file_newh(), gvl_isosurf_calc(), and slice_calc().

int gvl_file_set_slices_param ( geovol_file vf,
int  n,
int  b 
)

Set parameters for slice reading.

Parameters
vfpointer to geovol_file struct
n
b
Returns
-1 on failure
1 on success

Definition at line 1166 of file gvl_file.c.

References geovol_file::buff, geovol_file::mode, MODE_SLICE, return, geovol_file::status, and STATUS_BUSY.

int gvl_file_start_read ( geovol_file vf)

Start read - allocate memory buffer a read first data into buffer.

Parameters
vfpointer to geovol_file struct
Returns
-1 on failure
1 on success

Definition at line 967 of file gvl_file.c.

References alloc_slice_buff(), alloc_vol_buff(), geovol_file::buff, for(), geovol_file::mode, MODE_FULL, MODE_SLICE, read_slice(), read_vol(), geovol_file::status, and STATUS_BUSY.

Referenced by gvl_isosurf_calc(), and slice_calc().

int is_null_g3d_value ( IFLAG  type,
void *  value 
)

Check for null value.

Parameters
typedata type
value
Returns
1 if value is null
0 if value is not null
-1 on failure (unsupported data type

Definition at line 615 of file gvl_file.c.

References DCELL_TYPE, FCELL_TYPE, Rast3d_is_null_value_num(), VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by gvl_file_is_null_value().

void * open_g3d_file ( const char *  filename,
IFLAG type,
double *  min,
double *  max 
)

Open 3d raster file.

Parameters
filenamefile name
typedata type
[out]minmin value
[out]maxmax value
Returns
pointer to data

Definition at line 417 of file gvl_file.c.

References _, DCELL_TYPE, FCELL_TYPE, G_find_raster3d(), G_warning(), NULL, Rast3d_file_type_map(), Rast3d_open_cell_old(), Rast3d_range_load(), Rast3d_range_min_max(), RASTER3D_DEFAULT_WINDOW, RASTER3D_TILE_SAME_AS_FILE, RASTER3D_USE_CACHE_DEFAULT, VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by open_volfile().

void* open_volfile ( const char *  name,
IFLAG  file_type,
IFLAG data_type,
double *  min,
double *  max 
)

Open 3d raster file.

Parameters
namefile name
file_typefile type
data_typedata type
[out]minmin value
[out]maxmax value
Returns
pointer to file
NULL on failure

Definition at line 232 of file gvl_file.c.

References NULL, open_g3d_file(), and VOL_FTYPE_RASTER3D.

Referenced by gvl_file_newh().

int read_g3d_slice ( IFLAG  type,
void *  map,
int  level,
void *  data 
)

Read slice of values at level from g3d file.

Parameters
typedata type
map3D raster map
level
[out]data
Returns
-1 on failure
0 on success

Definition at line 521 of file gvl_file.c.

References Cols, Rast3d_get_double(), Rast3d_get_float(), Rows, VOL_DTYPE_DOUBLE, VOL_DTYPE_FLOAT, and x.

Referenced by read_slice().

int read_g3d_value ( IFLAG  type,
void *  map,
int  x,
int  y,
int  z,
void *  value 
)

Eead value from g3d file.

Parameters
typedata type
map3D raster map
x,y,zreal coordinates
[out]valuedata value
Returns
-1 on failure
1 on success

Definition at line 489 of file gvl_file.c.

References Rast3d_get_double(), Rast3d_get_float(), VOL_DTYPE_DOUBLE, and VOL_DTYPE_FLOAT.

Referenced by get_direct_value().

int read_g3d_vol ( IFLAG  type,
void *  map,
void *  data 
)

Read all values from g3d file.

Parameters
typedata type
map3D raster map
[out]datadata buffer
Returns
-1 on failure
1 on success

Definition at line 566 of file gvl_file.c.

References Cols, Depths, Rast3d_get_double(), Rast3d_get_float(), Rows, VOL_DTYPE_DOUBLE, VOL_DTYPE_FLOAT, and x.

Referenced by read_vol().

int read_slice ( geovol_file vf,
int  s,
int  l 
)

Read slice of values at level from volume file.

Parameters
vfpointer to geovol_file struct
s
l
Returns
-1 on failure
1 on success

Definition at line 872 of file gvl_file.c.

References geovol_file::buff, geovol_file::data_type, geovol_file::file_type, geovol_file::map, read_g3d_slice(), switch(), and VOL_FTYPE_RASTER3D.

Referenced by gvl_file_start_read(), and shift_slices().

int read_vol ( geovol_file vf)

Read all values from volume file.

Parameters
vfpointer to geovol_file struct
Returns
-1 on failure
1 on success

Definition at line 765 of file gvl_file.c.

References geovol_file::buff, geovol_file::data_type, geovol_file::file_type, geovol_file::map, read_g3d_vol(), and VOL_FTYPE_RASTER3D.

Referenced by gvl_file_set_mode(), and gvl_file_start_read().

void shift_slices ( geovol_file vf)

Read new slice into buffer.

Parameters
vfpointer to geovol_file struct

Definition at line 896 of file gvl_file.c.

References geovol_file::buff, for(), and read_slice().

Referenced by get_slice_value().