Loading...
Searching...
No Matches
gs.c File Reference

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

`#include <stdlib.h>`
`#include <stdio.h>`
`#include <grass/ogsf.h>`
`#include <grass/glocale.h>`
`#include "gsget.h"`
`#include "rowcol.h"`
Include dependency graph for gs.c:

Go to the source code of this file.

## Macros

#define | FIRST_SURF_ID 110658

## Functions

void | gs_err (const char *msg)
void | gs_init (void)
| Initialize library.
geosurf * | gs_get_surf (int id)
| Get geosurf struct.
geosurf * | gs_get_prev_surface (int id)
| Get previous geosurf struct.
int | gs_getall_surfaces (geosurf **gsurfs)
| Get array of geosurf structs.
int | gs_num_surfaces (void)
| Get number of surfaces.
int | gs_att_is_set (geosurf *surf, IFLAG att)
| Check if attribute is set.
geosurf * | gs_get_last_surface (void)
| Get last allocated geosurf struct from list.
geosurf * | gs_get_new_surface (void)
| Allocate new geosurf struct.
int | gs_init_surf (geosurf *gs, double ox, double oy, int rows, int cols, double xres, double yres)
| Initialize allocated geosurf struct.
int | gs_init_normbuff (geosurf *gs)
| Init geosurf normbuff.
void | print_frto (float(*ft)[4])
| Debugging, print 'from/to' model coordinates to stderr.
void | print_realto (float *rt)
| Debugging, print 'to' real coordinates to stderr.
void | print_256lookup (int *buff)
| Debugging, 256 integer values from buffer.
void | print_surf_fields (geosurf *s)
| Debugging, print geosurf fields to stderr.
void | print_view_fields (geoview *gv)
| Debugging, print geoview fields to stderr.
void | gs_set_defaults (geosurf *gs, float *defs, float *null_defs)
| Set default attribute values.
void | gs_delete_surf (int id)
| Remove geosurf struct from list.
int | gs_free_surf (geosurf *fs)
| Free geosurf struct.
void | gs_free_unshared_buffs (geosurf *fs)
| Free unshared buffers of geosurf struct.
int | gs_num_datah_reused (int dh)
| Get number of reused values.
int | gs_get_att_type (geosurf *gs, int desc)
| Get attribute type.
int | gs_get_att_src (geosurf *gs, int desc)
| Get attribute source.
typbuff * | gs_get_att_typbuff (geosurf *gs, int desc, int to_write)
| Get attribute data buffer.
size_t | gs_malloc_att_buff (geosurf *gs, int desc, int type)
| Allocate attribute buffer.
int | gs_malloc_lookup (geosurf *gs, int desc)
| Allocate attribute lookup.
int | gs_set_att_type (geosurf *gs, int desc, int type)
| Set attribute type.
int | gs_set_att_src (geosurf *gs, int desc, int src)
| Set attribute source.
int | gs_set_att_const (geosurf *gs, int desc, float constant)
| Set attribute constant value.
void | gs_set_maskmode (int invert)
| Set geosurf mask mode.
int | gs_mask_defined (geosurf *gs)
| Check if mask is defined.
int | gs_masked (typbuff *tb, int col, int row, int offset)
| Should only be called when setting up the current mask (gs_bm.c).
int | gs_mapcolor (typbuff *cobuff, gsurf_att *coloratt, int offset)
| Call this one when you already know att_src is MAP_ATT.
int | gs_get_zextents (geosurf *gs, float *min, float *max, float *mid)
| Get z-extent values.
int | gs_get_xextents (geosurf *gs, float *min, float *max)
| Get x-extent values.
int | gs_get_yextents (geosurf *gs, float *min, float *max)
| Get y-extent values.
int | gs_get_zrange0 (float *min, float *max)
| Get z-range.
int | gs_get_zrange (float *min, float *max)
| Get z-range.
int | gs_get_xrange (float *min, float *max)
| Get x-range.
int | gs_get_yrange (float *min, float *max)
| Get y-range.
int | gs_get_data_avg_zmax (float *azmax)
| Get average z-max value.
int | gs_get_datacenter (float *cen)
| Get data center point.
int | gs_setall_norm_needupdate (void)
| Set for geosurf need-to-update mark.
int | gs_point_is_masked (geosurf *gs, float *pt)
| Check if point is masked.
int | gs_distance_onsurf (geosurf *gs, float *p1, float *p2, float *dist, int use_exag)
| Calculate distance on surface.

## Detailed Description

OGSF library - loading and manipulating surfaces (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
  Bill Brown USACERL, GMSL/University of Illinois (January 1993)
  Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gs.c.

## Macro Definition Documentation

## FIRST_SURF_ID

#define FIRST_SURF_ID 110658

Definition at line 29 of file gs.c.

Referenced by gs_get_new_surface(), and gs_init_surf().

## Function Documentation

## gs_att_is_set()

int gs_att_is_set | ( | geosurf * | surf,
|  | IFLAG | att )

Check if attribute is set.

Parameters

  surf | pointer to gsurf or NULL to look at all geosurfs
  att | attribute id

Returns
  1 attribute is set up
  0 attribute is not set up

Definition at line 150 of file gs.c.

Referenced by GS_transp_is_set().

## gs_delete_surf()

void gs_delete_surf | ( | int | id | ) |

Remove geosurf struct from list.

Parameters

  id | surface id

Definition at line 463 of file gs.c.

References G_debug(), gs_free_surf(), and gs_get_surf().

Referenced by GS_delete_surface().

## gs_distance_onsurf()

int gs_distance_onsurf | ( | geosurf * | gs,
|  | float * | p1,
|  | float * | p2,
|  | float * | dist,
|  | int | use_exag )

Calculate distance on surface.

Parameters

  | gs | pointer to geosurf struct
  | p1 | from point
  | p2 | to point
  [out] | dist | distance
  | use_exag | use exag for calculation

Returns
  0 on error (points not in region)
  1 on success

Definition at line 1414 of file gs.c.

References GS_distance(), GS_global_exag(), gsdrape_get_segments(), in_vregion(), and NULL.

Referenced by GS_get_distance_alongsurf().

## gs_err()

void gs_err | ( | const char * | msg | ) |

Definition at line 35 of file gs.c.

References G_warning().

## gs_free_surf()

int gs_free_surf | ( | geosurf * | fs | ) |

Free geosurf struct.

Parameters

  fs | pointer to geosurf struct

Returns
  1 found
  0 not found
  -1 on error

Definition at line 487 of file gs.c.

References G_debug(), G_free(), gs_free_unshared_buffs(), and NULL.

Referenced by gs_delete_surf().

## gs_free_unshared_buffs()

void gs_free_unshared_buffs | ( | geosurf * | fs | ) |

Free unshared buffers of geosurf struct.

fs has already been taken out of the list

This function is fairly revealing about how shared datasets work

Parameters

  fs | pointer to geosurf struct

Definition at line 557 of file gs.c.

References G_debug(), and gsds_free_datah().

Referenced by gs_free_surf().

## gs_get_att_src()

int gs_get_att_src | ( | geosurf * | gs,
|  | int | desc )

Get attribute source.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id (descriptor)

Returns
  -1 on error
  attribute source id

Definition at line 656 of file gs.c.

References G_debug().

Referenced by gpd_2dsite(), GS_draw_X(), GS_get_att(), GS_get_cat_at_xy(), GS_get_exag_guess(), GS_get_val_at_xy(), gs_set_att_src(), Gs_update_attrange(), gsd_surf(), gsd_wire_surf(), gsdrape_get_allsegments(), gsdrape_get_segments(), gvd_vect(), and viewcell_tri_interp().

## gs_get_att_typbuff()

typbuff * gs_get_att_typbuff | ( | geosurf * | gs,
|  | int | desc,
|  | int | to_write )

Get attribute data buffer.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id (descriptor)
  to_write | non-zero value for 'write'

Returns
  NULL on error
  pointer to typbuff

Definition at line 681 of file gs.c.

References G_debug(), gsdiff_do_SD(), gsdiff_get_SDref(), gsds_get_typbuff(), and NULL.

Referenced by _viewcell_tri_interp(), gpd_2dsite(), GS_get_cat_at_xy(), GS_get_val_at_xy(), GS_load_att_map(), gs_los_intersect(), gs_los_intersect1(), gs_update_curmask(), gsd_coarse_surf_map(), gsd_fringe_horiz_line(), gsd_fringe_horiz_line2(), gsd_fringe_horiz_poly(), gsd_fringe_vert_line(), gsd_fringe_vert_poly(), gsd_norm_arrows(), gsd_ortho_wall(), gsd_surf_const(), gsd_surf_map(), gsd_surf_map_old(), gsd_triangulated_wall(), gsd_wire_arrows(), gsd_wire_surf_const(), gsd_wire_surf_map(), gsdiff_set_SDref(), gsdrape_set_surface(), and init_vars().

## gs_get_att_type()

int gs_get_att_type | ( | geosurf * | gs,
|  | int | desc )

Get attribute type.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id

Returns
  -1 on error
  attribute type

Definition at line 630 of file gs.c.

References G_debug().

## gs_get_data_avg_zmax()

int gs_get_data_avg_zmax | ( | float * | azmax | ) |

Get average z-max value.

Useful for setting position of cplane, lighting ball, etc.

Parameters

  [out] | azmax | average z-max value

Returns
  -1 on error
  1 on success

Definition at line 1201 of file gs.c.

Referenced by GS_get_modelposition1().

## gs_get_datacenter()

int gs_get_datacenter | ( | float * | cen | ) |

Get data center point.

Parameters

  [out] | cen | center (array X,Y,Z)

Returns
  -1 on error
  1 on success

Definition at line 1230 of file gs.c.

References X, and Y.

Referenced by GS_get_modelposition1(), and gsd_set_view().

## gs_get_last_surface()

geosurf * gs_get_last_surface | ( | void |  | ) |

Get last allocated geosurf struct from list.

Returns
  pointer to geosurf struct

Definition at line 173 of file gs.c.

References G_debug(), and NULL.

Referenced by gs_get_new_surface().

## gs_get_new_surface()

geosurf * gs_get_new_surface | ( | void |  | ) |

Allocate new geosurf struct.

Returns
  pointer to geosurf struct

Definition at line 194 of file gs.c.

References FIRST_SURF_ID, G_debug(), gs_get_last_surface(), and NULL.

Referenced by GS_new_surface().

## gs_get_prev_surface()

geosurf * gs_get_prev_surface | ( | int | id | ) |

Get previous geosurf struct.

Parameters

  id | current surface id

Returns
  pointer to geosurf struct
  NULL if not found

Definition at line 87 of file gs.c.

References G_debug(), NULL, and ps.

Referenced by gs_init_surf().

## gs_get_surf()

geosurf * gs_get_surf | ( | int | id | ) |

Get geosurf struct.

Parameters

  id | surface id

Returns
  pointer to geosurf struct
  NULL if not found

Definition at line 63 of file gs.c.

References G_debug(), and NULL.

Referenced by GP_draw_site(), gp_update_drapesurfs(), GS_alldraw_wire(), gs_delete_surf(), GS_draw_cplane_fence(), GS_draw_flowline_at_xy(), GS_draw_fringe(), GS_draw_line_onsurf(), GS_draw_nline_onsurf(), GS_draw_surf(), GS_draw_wire(), GS_draw_X(), GS_get_att(), GS_get_cat_at_xy(), GS_Get_ClientData(), GS_get_dims(), GS_get_distance_alongsurf(), GS_get_drawmode(), GS_get_drawres(), GS_get_exag_guess(), GS_get_maskmode(), GS_get_norm_at_xy(), GS_get_nozero(), GS_get_selected_point_on_surface(), GS_get_trans(), GS_get_val_at_xy(), GS_get_wire_color(), GS_get_zextents(), GS_get_zrange_nz(), GS_is_masked(), GS_load_3dview(), GS_load_att_map(), GS_look_here(), gs_los_intersect(), gs_los_intersect1(), GS_save_3dview(), GS_set_att_const(), GS_Set_ClientData(), GS_set_drawmode(), GS_set_drawres(), GS_set_exag(), GS_set_focus_center_map(), GS_set_maskmode(), GS_set_Narrow(), GS_set_nozero(), GS_set_SDsurf(), GS_set_trans(), GS_set_wire_color(), GS_surf_exists(), GS_unset_att(), GS_update_curmask(), GS_update_normals(), GV_draw_fastvect(), GV_draw_vect(), gv_update_drapesurfs(), and Nviz_set_cplane_here().

## gs_get_xextents()

int gs_get_xextents | ( | geosurf * | gs,
|  | float * | min,
|  | float * | max )

Get x-extent values.

Parameters

  | gs | pointer to geosurf struct
  [out] | min | x-min value
  [out] | max | x-max value

Returns
  1

Definition at line 1015 of file gs.c.

References max, and min.

Referenced by gs_get_xrange().

## gs_get_xrange()

int gs_get_xrange | ( | float * | min,
|  | float * | max )

Get x-range.

Parameters

  [out] | min | x-min value
  [out] | max | x-max value

Returns
  -1 on error (no surface)
  1 on success

Definition at line 1124 of file gs.c.

References gs_get_xextents(), max, and min.

Referenced by gs_get_databounds_planes().

## gs_get_yextents()

int gs_get_yextents | ( | geosurf * | gs,
|  | float * | min,
|  | float * | max )

Get y-extent values.

Parameters

  | gs | pointer to geosurf struct
  [out] | min | y-min value
  [out] | max | y-max value

Returns
  1

Definition at line 1032 of file gs.c.

References max, and min.

Referenced by gs_get_yrange().

## gs_get_yrange()

int gs_get_yrange | ( | float * | min,
|  | float * | max )

Get y-range.

Parameters

  [out] | min | y-min value
  [out] | max | y-max value

Returns
  -1 on error (no surface)
  1 on success

Definition at line 1162 of file gs.c.

References gs_get_yextents(), max, and min.

Referenced by gs_get_databounds_planes().

## gs_get_zextents()

int gs_get_zextents | ( | geosurf * | gs,
|  | float * | min,
|  | float * | max,
|  | float * | mid )

Get z-extent values.

Todo
  pass flag to use zminmasked instead of zmin

Parameters

  | gs | pointer to geosurf struct
  [out] | min | z-min value
  [out] | max | z-max value
  [out] | mid | z-middle value

Returns
  1

Definition at line 997 of file gs.c.

References max, and min.

Referenced by GS_get_zextents(), and gs_get_zrange().

## gs_get_zrange()

int gs_get_zrange | ( | float * | min,
|  | float * | max )

Get z-range.

Parameters

  [out] | min | z-min value
  [out] | max | z-max value

Returns
  -1 on error (no surface)
  1 on success

Definition at line 1086 of file gs.c.

References gs_get_zextents(), max, and min.

Referenced by GS_get_zrange(), and gvd_vect().

## gs_get_zrange0()

int gs_get_zrange0 | ( | float * | min,
|  | float * | max )

Get z-range.

Todo
  pass flag to use zminmasked instead of zmin could also have this return a weighted average for vertical "centroid"

Parameters

  [out] | min | z-min value
  [out] | max | z-max value

Returns
  -1 on error (no surface)
  1 on success

Definition at line 1052 of file gs.c.

References max, and min.

## gs_getall_surfaces()

int gs_getall_surfaces | ( | geosurf ** | gsurfs | ) |

Get array of geosurf structs.

Parameters

  gsurfs | pointer to array

Returns
  number of geosurfs

Definition at line 109 of file gs.c.

References G_debug().

Referenced by GS_draw_cplane(), and gsd_wall().

## gs_init()

void gs_init | ( | void |  | ) |

Initialize library.

Still need to take care of library initialization, probably want to define a Surf_top of constant value (i.e., 0)

Definition at line 48 of file gs.c.

References NULL.

Referenced by GS_libinit().

## gs_init_normbuff()

int gs_init_normbuff | ( | geosurf * | gs | ) |

Init geosurf normbuff.

Parameters

  gs | pointer to geosurf struct

Returns
  0 on error
  1 on success

Definition at line 308 of file gs.c.

References G_free().

Referenced by GS_load_att_map().

## gs_init_surf()

int gs_init_surf | ( | geosurf * | gs,
|  | double | ox,
|  | double | oy,
|  | int | rows,
|  | int | cols,
|  | double | xres,
|  | double | yres )

Initialize allocated geosurf struct.

Todo
  Now xmin & ox are the same, right? - get rid of ox, oy in geosurf struct?

Parameters

  gs | pointer to geosurf struct
  ox,oy | x/y origin coordinates
  rows | number of rows
  cols | number of cols
  xres,yres | x/y resolution value

Returns
  -1 on error
  0 on success

Definition at line 234 of file gs.c.

References FIRST_SURF_ID, G_debug(), gs_get_prev_surface(), NULL, and ps.

Referenced by GS_new_surface().

## gs_malloc_att_buff()

size_t gs_malloc_att_buff | ( | geosurf * | gs,
|  | int | desc,
|  | int | type )

Allocate attribute buffer.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id (descriptor)
  type | buffer type (based on raster map type)

Returns
  -1 on error
  amount of allocated memory

Definition at line 717 of file gs.c.

References G_debug(), gs_set_att_type(), and gsds_alloc_typbuff().

Referenced by GS_load_att_map().

## gs_malloc_lookup()

int gs_malloc_lookup | ( | geosurf * | gs,
|  | int | desc )

Allocate attribute lookup.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id

Returns
  -1 on error
  pointer to typbuff (casted)

Definition at line 746 of file gs.c.

References G_debug(), G_free(), G_warning(), and NULL.

Referenced by GS_load_att_map().

## gs_mapcolor()

int gs_mapcolor | ( | typbuff * | cobuff,
|  | gsurf_att * | coloratt,
|  | int | offset )

Call this one when you already know att_src is MAP_ATT.

Parameters

  cobuff |
  coloratt | color attribute
  offset | offset value

Returns
  packed color for category at offset

Definition at line 968 of file gs.c.

Referenced by GS_get_val_at_xy(), gs_update_curmask(), gsd_coarse_surf_map(), gsd_norm_arrows(), gsd_surf_const(), gsd_surf_map(), gsd_surf_map_old(), gsd_triangulated_wall(), gsd_wire_arrows(), gsd_wire_surf_const(), and gsd_wire_surf_map().

## gs_mask_defined()

int gs_mask_defined | ( | geosurf * | gs | ) |

Check if mask is defined.

Parameters

  gs | pointer to geosurf struct

Returns
  1 if defined
  0 not defined

Definition at line 914 of file gs.c.

Referenced by gs_update_curmask().

## gs_masked()

int gs_masked | ( | typbuff * | tb,
|  | int | col,
|  | int | row,
|  | int | offset )

Should only be called when setting up the current mask (gs_bm.c).

Parameters

  tb | pointer to typbuff
  col | number of cols
  row | number of rows
  offset | offset value

Returns
  1
  0

Definition at line 932 of file gs.c.

References BM_get().

Referenced by gs_update_curmask().

## gs_num_datah_reused()

int gs_num_datah_reused | ( | int | dh | ) |

Get number of reused values.

Parameters

  dh | value

Returns
  number of reused values

Definition at line 597 of file gs.c.

References G_debug().

Referenced by gs_set_att_src().

## gs_num_surfaces()

int gs_num_surfaces | ( | void |  | ) |

Get number of surfaces.

Returns
  number of surfaces

Definition at line 128 of file gs.c.

References G_debug().

Referenced by GS_draw_cplane(), and GS_num_surfs().

## gs_point_is_masked()

int gs_point_is_masked | ( | geosurf * | gs,
|  | float * | pt )

Check if point is masked.

Parameters

  | gs | pointer to geosurf struct
  [in] | pt | point coordinates (X,Y,Z)

Returns
  1 masked
  0 not masked

Definition at line 1314 of file gs.c.

References BM_get(), VCOL2DCOL, VCOL2X, VCOLS, VROW2DROW, VROW2Y, VROWS, VXRES, VYRES, X, X2VCOL, Y, and Y2VROW.

Referenced by gpd_2dsite(), GS_get_cat_at_xy(), GS_get_norm_at_xy(), GS_get_selected_point_on_surface(), GS_get_val_at_xy(), GS_is_masked(), gvd_draw_lineonsurf(), gvd_vect(), and viewcell_tri_interp().

## gs_set_att_const()

int gs_set_att_const | ( | geosurf * | gs,
|  | int | desc,
|  | float | constant )

Set attribute constant value.

Todo
  set typbuf constant

Parameters

  gs | pointer to geosurf struct
  desc | attribute id
  constant | constant value

Returns
  0 on success
  -1 on error

Definition at line 871 of file gs.c.

References G_debug(), gs_set_att_src(), and Gs_update_attrange().

Referenced by GS_set_att_const().

## gs_set_att_src()

int gs_set_att_src | ( | geosurf * | gs,
|  | int | desc,
|  | int | src )

Set attribute source.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id (descriptor)
  src | source id

Returns
  -1 on error
  0 on success

Definition at line 826 of file gs.c.

References G_debug(), G_free(), gs_get_att_src(), gs_num_datah_reused(), gsds_free_datah(), and NULL.

Referenced by GS_load_att_map(), GS_new_surface(), gs_set_att_const(), and GS_unset_att().

## gs_set_att_type()

int gs_set_att_type | ( | geosurf * | gs,
|  | int | desc,
|  | int | type )

Set attribute type.

Parameters

  gs | pointer to geosurf struct
  desc | attribute id
  type | attribute type

Returns
  -1 on error
  0 on success

Definition at line 802 of file gs.c.

References G_debug().

Referenced by GS_load_att_map(), and gs_malloc_att_buff().

## gs_set_defaults()

void gs_set_defaults | ( | geosurf * | gs,
|  | float * | defs,
|  | float * | null_defs )

Set default attribute values.

Parameters

  gs | pointer to geosurf struct
  defs | array of default values (dim MAX_ATTRS)
  null_defs | array of null default values (dim MAX_ATTRS)

Definition at line 441 of file gs.c.

References G_debug(), and NULL.

Referenced by GS_new_surface().

## gs_set_maskmode()

void gs_set_maskmode | ( | int | invert | ) |

Set geosurf mask mode.

Parameters

  invert | invert mask

Definition at line 899 of file gs.c.

Referenced by gs_update_curmask().

## gs_setall_norm_needupdate()

int gs_setall_norm_needupdate | ( | void |  | ) |

Set for geosurf need-to-update mark.

Returns
  -1 no surface available
  1 on success

Definition at line 1287 of file gs.c.

## print_256lookup()

void print_256lookup | ( | int * | buff | ) |

Debugging, 256 integer values from buffer.

Todo
  G_debug ?

Parameters

  buff | pointer to buffer

Definition at line 369 of file gs.c.

## print_frto()

void print_frto | ( | float(*) | ft[4] | ) |

Debugging, print 'from/to' model coordinates to stderr.

Todo
  G_debug ?

Parameters

  ft | pointer to coordinates

Definition at line 339 of file gs.c.

References X, and Y.

Referenced by print_view_fields().

## print_realto()

void print_realto | ( | float * | rt | ) |

Debugging, print 'to' real coordinates to stderr.

Todo
  G_debug ?

Parameters

  rt | pointer to coordinates

Definition at line 355 of file gs.c.

References X, and Y.

## print_surf_fields()

void print_surf_fields | ( | geosurf * | s | ) |

Debugging, print geosurf fields to stderr.

Todo
  G_debug ?

Parameters

  s | pointer to geosurf struct

Definition at line 393 of file gs.c.

## print_view_fields()

void print_view_fields | ( | geoview * | gv | ) |

Debugging, print geoview fields to stderr.

Todo
  G_debug ?

Parameters

  gv | pointer to geoview struct

Definition at line 419 of file gs.c.

References print_frto(), X, and Y.