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

## 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

## LUCKY

#define LUCKY 33

Definition at line 28 of file gvl_file.c.

## MODE_DEFAULT

#define MODE_DEFAULT 0

Definition at line 35 of file gvl_file.c.

Referenced by gvl_file_newh().

## MODE_DIRECT

#define MODE_DIRECT 0

Definition at line 30 of file gvl_file.c.

Referenced by gvl_file_get_value().

## MODE_FULL

#define MODE_FULL 2

Definition at line 32 of file gvl_file.c.

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

## MODE_PRELOAD

#define MODE_PRELOAD 3

Definition at line 33 of file gvl_file.c.

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

## MODE_SLICE

#define MODE_SLICE 1

Definition at line 31 of file gvl_file.c.

Referenced by free_volfile_buffs(), gvl_file_end_read(), gvl_file_get_value(), gvl_file_set_mode(), gvl_file_set_slices_param(), and gvl_file_start_read().

## STATUS_BUSY

#define STATUS_BUSY 1

Definition at line 38 of file gvl_file.c.

Referenced by gvl_file_get_value(), gvl_file_set_mode(), gvl_file_set_slices_param(), and gvl_file_start_read().

## STATUS_READY

#define STATUS_READY 0

Definition at line 37 of file gvl_file.c.

Referenced by gvl_file_end_read(), and gvl_file_newh().

## Function Documentation

## alloc_slice_buff()

int alloc_slice_buff | ( | geovol_file * | vf | ) |

Allocate buffer for slice mode reading.

Parameters

  vf | pointer to geovol_file struct

Returns
  -1 on failure
  1 on success

Definition at line 809 of file gvl_file.c.

References Cols, NULL, and Rows.

Referenced by gvl_file_start_read().

## alloc_vol_buff()

int alloc_vol_buff | ( | geovol_file * | vf | ) |

Allocate buffer memory for full mode reading.

Parameters

  vf | pointer to geovol_file

Returns
  -1 on failure
  1 on success

Definition at line 716 of file gvl_file.c.

References Cols, Depths, NULL, and Rows.

Referenced by gvl_file_set_mode(), and gvl_file_start_read().

## close_g3d_file()

int close_g3d_file | ( | void * | map | ) |

Close g3d file.

Parameters

  map | 3d raster map

Returns
  -1 on failure
  1 on success

Definition at line 465 of file gvl_file.c.

References G_warning().

Referenced by close_volfile().

## close_volfile()

int close_volfile | ( | void * | map,
|  | IFLAG | type )

Close volume file.

Parameters

  map | volume filename
  type | file type

Returns
  -1 on failure

Definition at line 251 of file gvl_file.c.

References close_g3d_file().

Referenced by gvl_file_free_datah().

## find_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

  name | file name
  begin |
  data | id
  -1 | not found

Definition at line 139 of file gvl_file.c.

References name.

Referenced by gvl_file_newh().

## free_slice_buff()

int free_slice_buff | ( | geovol_file * | vf | ) |

Free buffer for slice mode reading.

Parameters

  vf | pointer to geovol_file struct

Returns
  1

Definition at line 848 of file gvl_file.c.

References G_free().

Referenced by gvl_file_end_read().

## free_vol_buff()

int free_vol_buff | ( | geovol_file * | vf | ) |

Free memory buffer memory.

Parameters

  vf | pointer to geovol_file struct

Returns
  1

Definition at line 748 of file gvl_file.c.

References G_free().

Referenced by gvl_file_end_read().

## free_volfile_buffs()

int free_volfile_buffs | ( | geovol_file * | vf | ) |

Free allocated buffers.

Parameters

  vf | pointer to geovol_file struct

Returns
  1

Definition at line 342 of file gvl_file.c.

References G_free(), MODE_PRELOAD, MODE_SLICE, and NULL.

Referenced by gvl_file_free_datah().

## get_buff_value()

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

Get value from buffer.

Parameters

  type | data type
  data | data buffer
  offset |
  value |

Returns
  -1 on failure (unsupported data type)
  1 on success

Definition at line 651 of file gvl_file.c.

Referenced by get_slice_value(), and get_vol_value().

## get_direct_value()

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

Read value direct from volume file.

Parameters

  | vf | pointer to geovol_file struct
  | x,y,z | real point
  [out] | value | data value

Returns
  -1 on failure
  1 on success

Definition at line 687 of file gvl_file.c.

References read_g3d_value(), and x.

Referenced by gvl_file_get_value().

## get_slice_value()

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

Get value from slice buffer.

Parameters

  | vf | pointer to geovol_file struct
  | x,y,z | real point
  [out] | value | data value

Returns
  -1 on failure
  1 on success

Definition at line 925 of file gvl_file.c.

References Cols, get_buff_value(), shift_slices(), and x.

Referenced by gvl_file_get_value().

## get_vol_value()

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

Get value from volume buffer.

Parameters

  | vf | pointer to geovol_file struct
  | x,y,z | real point
  [out] | value | data value

Returns
  1

Definition at line 788 of file gvl_file.c.

References Cols, get_buff_value(), Rows, and x.

Referenced by gvl_file_get_value().

## gvl_file_end_read()

int gvl_file_end_read | ( | geovol_file * | vf | ) |

End read - free buffer memory.

Parameters

  vf | pointer to geovol_file struct

Returns
  -1 on failure
  1 on success

Definition at line 1016 of file gvl_file.c.

References free_slice_buff(), free_vol_buff(), MODE_FULL, MODE_SLICE, and STATUS_READY.

Referenced by gvl_isosurf_calc(), and slice_calc().

## gvl_file_free_datah()

int gvl_file_free_datah | ( | int | id | ) |

Free geovol_file structure for given handle.

Parameters

  id |

Returns

Definition at line 364 of file gvl_file.c.

References close_volfile(), free_volfile_buffs(), G_debug(), G_free(), and NULL.

Referenced by gvl_free_volmem(), and gvl_isosurf_set_att_src().

## gvl_file_get_data_type()

int gvl_file_get_data_type | ( | geovol_file * | vf | ) |

Get data type for given handle.

Parameters

  vf | pointer to geovol_file struct

Returns
  data type

Definition at line 202 of file gvl_file.c.

Referenced by iso_get_cube_value(), and slice_get_value().

## gvl_file_get_file_type()

int gvl_file_get_file_type | ( | geovol_file * | vf | ) |

Get file type for given handle.

Parameters

  vf | pointer to geovol_file struct

Returns
  file type

Definition at line 190 of file gvl_file.c.

## gvl_file_get_min_max()

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

Get minimum and maximum value in volume file.

Parameters

  | vf | pointer to geovol_file struct
  [out] | min | min value
  [out] | max | max value

Definition at line 214 of file gvl_file.c.

References max, and min.

Referenced by iso_get_range().

## gvl_file_get_name()

char * gvl_file_get_name | ( | int | id | ) |

Get file name for given handle.

Parameters

  id | handle id

Returns
  file name
  NULL on failure

Definition at line 165 of file gvl_file.c.

References NULL, and strcpy.

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

## gvl_file_get_value()

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

  | vf | pointer to geovol_file struct
  | x,y,z |
  [out] | value |

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(), MODE_DIRECT, MODE_FULL, MODE_PRELOAD, MODE_SLICE, STATUS_BUSY, and x.

Referenced by iso_get_cube_value(), and slice_get_value().

## gvl_file_get_volfile()

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().

## gvl_file_is_null_value()

int gvl_file_is_null_value | ( | geovol_file * | vf,
|  | void * | value )

Check for null value.

Parameters

  vf | pointer to geovol_file struct
  value | data value

Returns
  -1 on failure
  1 on success

Definition at line 1087 of file gvl_file.c.

References is_null_g3d_value().

Referenced by iso_get_cube_value().

## gvl_file_newh()

int gvl_file_newh | ( | const char * | name,
|  | IFLAG | file_type )

Get handle for given file name and type.

Parameters

  name | volume filename
  file_type | file type

Returns
  data id
  -1 on failure

Definition at line 269 of file gvl_file.c.

References find_datah(), G_store(), gvl_file_set_mode(), max, min, MODE_DEFAULT, name, NULL, open_volfile(), and STATUS_READY.

Referenced by gvl_isosurf_set_att_map(), and GVL_load_vol().

## gvl_file_set_mode()

int gvl_file_set_mode | ( | geovol_file * | vf,
|  | IFLAG | mode )

Set read mode.

Parameters

  vf | pointer to geovol_file struct
  mode | read mode

Returns
  -1 on failure
  1 on success

Definition at line 1116 of file gvl_file.c.

References alloc_vol_buff(), G_free(), MODE_PRELOAD, MODE_SLICE, NULL, read_vol(), and STATUS_BUSY.

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

## gvl_file_set_slices_param()

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

Set parameters for slice reading.

Parameters

  vf | pointer to geovol_file struct
  n |
  b |

Returns
  -1 on failure
  1 on success

Definition at line 1166 of file gvl_file.c.

References b, MODE_SLICE, and STATUS_BUSY.

## gvl_file_start_read()

int gvl_file_start_read | ( | geovol_file * | vf | ) |

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

Parameters

  vf | pointer to geovol_file struct

Returns
  -1 on failure
  1 on success

Definition at line 965 of file gvl_file.c.

References alloc_slice_buff(), alloc_vol_buff(), MODE_FULL, MODE_SLICE, read_slice(), read_vol(), and STATUS_BUSY.

Referenced by gvl_isosurf_calc(), and slice_calc().

## is_null_g3d_value()

int is_null_g3d_value | ( | IFLAG | type,
|  | void * | value )

Check for null value.

Parameters

  type | data type
  value |

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

Definition at line 614 of file gvl_file.c.

Referenced by gvl_file_is_null_value().

## open_g3d_file()

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

Open 3d raster file.

Parameters

  | filename | file name
  | type | data type
  [out] | min | min value
  [out] | max | max value

Returns
  pointer to data

Definition at line 417 of file gvl_file.c.

References G_find_raster3d(), G_warning(), max, min, and NULL.

Referenced by open_volfile().

## open_volfile()

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

Open 3d raster file.

Parameters

  | name | file name
  | file_type | file type
  | data_type | data type
  [out] | min | min value
  [out] | max | max value

Returns
  pointer to file
  NULL on failure

Definition at line 232 of file gvl_file.c.

References max, min, name, NULL, and open_g3d_file().

Referenced by gvl_file_newh().

## read_g3d_slice()

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

Read slice of values at level from g3d file.

Parameters

  | type | data type
  | map | 3D raster map
  | level |
  [out] | data |

Returns
  -1 on failure
  0 on success

Definition at line 520 of file gvl_file.c.

References Cols, Rows, and x.

Referenced by read_slice().

## read_g3d_value()

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

Eead value from g3d file.

Parameters

  | type | data type
  | map | 3D raster map
  | x,y,z | real coordinates
  [out] | value | data value

Returns
  -1 on failure
  1 on success

Definition at line 488 of file gvl_file.c.

References x.

Referenced by get_direct_value().

## read_g3d_vol()

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

Read all values from g3d file.

Parameters

  | type | data type
  | map | 3D raster map
  [out] | data | data buffer

Returns
  -1 on failure
  1 on success

Definition at line 565 of file gvl_file.c.

References Cols, Depths, Rows, and x.

Referenced by read_vol().

## read_slice()

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

Read slice of values at level from volume file.

Parameters

  vf | pointer to geovol_file struct
  s |
  l |

Returns
  -1 on failure
  1 on success

Definition at line 870 of file gvl_file.c.

References l, and read_g3d_slice().

Referenced by gvl_file_start_read(), and shift_slices().

## read_vol()

int read_vol | ( | geovol_file * | vf | ) |

Read all values from volume file.

Parameters

  vf | pointer to geovol_file struct

Returns
  -1 on failure
  1 on success

Definition at line 763 of file gvl_file.c.

References read_g3d_vol().

Referenced by gvl_file_set_mode(), and gvl_file_start_read().

## shift_slices()

void shift_slices | ( | geovol_file * | vf | ) |

Read new slice into buffer.

Parameters

  vf | pointer to geovol_file struct

Definition at line 894 of file gvl_file.c.

References read_slice().

Referenced by get_slice_value().