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

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

#define FIRST_SURF_ID   110658

Definition at line 28 of file gs.c.

Referenced by gs_get_new_surface(), and gs_init_surf().

Function Documentation

int gs_att_is_set ( geosurf surf,
IFLAG  att 
)

Check if attribute is set.

Parameters
surfpointer to gsurf or NULL to look at all geosurfs
attattribute id
Returns
1 attribute is set up
0 attribute is not set up

Definition at line 149 of file gs.c.

References g_surf::att, gsurf_att::att_src, g_surf::next, and NOTSET_ATT.

Referenced by GS_transp_is_set().

void gs_delete_surf ( int  id)

Remove geosurf struct from list.

Parameters
idsurface id

Definition at line 463 of file gs.c.

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

Referenced by GS_delete_surface().

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

Calculate distance on surface.

Parameters
gspointer to geosurf struct
p1from point
p2to point
[out]distdistnace
use_exaguse exag for calculation
Returns
0 on error (points not in region)
1 on success

Definition at line 1417 of file gs.c.

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

Referenced by GS_get_distance_alongsurf().

void gs_err ( const char *  msg)

Definition at line 34 of file gs.c.

References G_warning().

int gs_free_surf ( geosurf fs)

Free geosurf struct.

Parameters
fspointer to geosurf struct
Returns
1 found
0 not found
-1 on error

Definition at line 487 of file gs.c.

References g_surf::curmask, G_debug(), G_free(), gs_free_unshared_buffs(), g_surf::next, g_surf::norms, and NULL.

Referenced by gs_delete_surf().

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 datsets work

Parameters
fspointer to geosurf struct

Definition at line 557 of file gs.c.

References g_surf::att, G_debug(), gsds_free_datah(), gsurf_att::hdata, MAX_ATTS, and g_surf::next.

Referenced by gs_free_surf().

int gs_get_att_src ( geosurf gs,
int  desc 
)

Get attribute source.

Parameters
gspointer to geosurf struct
descattribute id (descriptor)
Returns
-1 on error
attribute source id

Definition at line 656 of file gs.c.

References g_surf::att, gsurf_att::att_src, G_debug(), g_surf::gsurf_id, and LEGAL_ATT.

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

int gs_get_att_type ( geosurf gs,
int  desc 
)

Get attribute type.

Parameters
gspointer to geosurf struct
descattribute id
Returns
-1 on error
attribute type

Definition at line 630 of file gs.c.

References g_surf::att, gsurf_att::att_src, gsurf_att::att_type, G_debug(), LEGAL_ATT, and NOTSET_ATT.

int gs_get_data_avg_zmax ( float *  azmax)

Get average z-max value.

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

Parameters
[out]azmaxaverage z-max value
Returns
-1 on error
1 on success

Definition at line 1203 of file gs.c.

References g_surf::next.

Referenced by GS_get_modelposition1().

int gs_get_datacenter ( float *  cen)

Get data center point.

Parameters
[out]center(array X,Y,Z)
Returns
-1 on error
1 on success

Definition at line 1232 of file gs.c.

References g_surf::next, X, g_surf::xmax, g_surf::xmin, Y, g_surf::ymax, g_surf::ymin, Z, g_surf::zmax, and g_surf::zmin.

Referenced by GS_get_modelposition1(), and gsd_set_view().

geosurf* gs_get_last_surface ( void  )

Get last allocated geosurf struct from list.

Returns
pointer to geosurf struct

Definition at line 172 of file gs.c.

References G_debug(), g_surf::gsurf_id, g_surf::next, and NULL.

Referenced by gs_get_new_surface().

geosurf* gs_get_new_surface ( void  )

Allocate new geosurf struct.

Returns
pointer to geosurf struct

Definition at line 193 of file gs.c.

References FIRST_SURF_ID, G_debug(), gs_get_last_surface(), g_surf::gsurf_id, g_surf::next, and NULL.

Referenced by GS_new_surface().

geosurf* gs_get_prev_surface ( int  id)

Get previous geosurf struct.

Parameters
idcurrent surface id
Returns
pointer to geosurf struct
NULL if not found

Definition at line 86 of file gs.c.

References G_debug(), g_surf::gsurf_id, g_surf::next, NULL, and ps.

Referenced by gs_init_surf().

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

Get x-extent values.

Parameters
gspointer to geosurf struct
[out]minx-min value
[out]maxx-max value
Returns
1

Definition at line 1016 of file gs.c.

References g_surf::x_trans, g_surf::xmax, and g_surf::xmin.

Referenced by gs_get_xrange().

int gs_get_xrange ( float *  min,
float *  max 
)

Get x-range.

Parameters
[out]minx-min value
[out]maxx-max value
Returns
-1 on error (no surface)
1 on success

Definition at line 1126 of file gs.c.

References gs_get_xextents(), and g_surf::next.

Referenced by gs_get_databounds_planes().

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

Get y-extent values.

Parameters
gspointer to geosurf struct
[out]miny-min value
[out]maxy-max value
Returns
1

Definition at line 1033 of file gs.c.

References g_surf::y_trans, g_surf::ymax, and g_surf::ymin.

Referenced by gs_get_yrange().

int gs_get_yrange ( float *  min,
float *  max 
)

Get y-range.

Parameters
[out]miny-min value
[out]maxy-max value
Returns
-1 on error (no surface)
1 on success

Definition at line 1164 of file gs.c.

References gs_get_yextents(), and g_surf::next.

Referenced by gs_get_databounds_planes().

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
gspointer to geosurf struct
[out]minz-min value
[out]maxz-max value
[out]midz-middle value
Returns
1

Definition at line 998 of file gs.c.

References min, g_surf::z_trans, g_surf::zmax, and g_surf::zmin.

Referenced by GS_get_zextents(), and gs_get_zrange().

int gs_get_zrange ( float *  min,
float *  max 
)

Get z-range.

Parameters
[out]minz-min value
[out]maxz-max value
Returns
-1 on error (no surface)
1 on success

Definition at line 1088 of file gs.c.

References gs_get_zextents(), and g_surf::next.

Referenced by GS_get_zrange(), and gvd_vect().

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]minz-min value
[out]maxz-max value
Returns
-1 on error (no surface)
1 on success

Definition at line 1054 of file gs.c.

References g_surf::next, g_surf::zmax, and g_surf::zmin.

int gs_getall_surfaces ( geosurf **  gsurfs)

Get array of geosurf structs.

Parameters
gsurfspointer to array
Returns
number of geosurfs

Definition at line 108 of file gs.c.

References G_debug(), and g_surf::next.

Referenced by GS_draw_cplane(), and gsd_wall().

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 47 of file gs.c.

References NULL.

Referenced by GS_libinit().

int gs_init_normbuff ( geosurf gs)

Init geosurf normbuff.

Parameters
gspointer to geosurf struct
Returns
0 on error
1 on success

Definition at line 306 of file gs.c.

References g_surf::cols, G_free(), g_surf::norm_needupdate, g_surf::norms, and g_surf::rows.

Referenced by GS_load_att_map().

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

Allocate attribute buffer.

Parameters
gspointer to geosurf struct
descattribute id (descriptor)
typebuffer type (based on raster map type)
Returns
-1 on error
amount of allocated memory

Definition at line 717 of file gs.c.

References g_surf::att, g_surf::cols, G_debug(), gs_set_att_type(), gsds_alloc_typbuff(), gsurf_att::hdata, and g_surf::rows.

Referenced by GS_load_att_map().

int gs_malloc_lookup ( geosurf gs,
int  desc 
)

Allocate attribute lookup.

Parameters
gspointer to geosurf struct
descattribute id
Returns
-1 on error
pointer to typbuff (casted)

Definition at line 746 of file gs.c.

References g_surf::att, gsurf_att::att_type, ATTY_CHAR, ATTY_SHORT, G_debug(), G_free(), G_warning(), int, gsurf_att::lookup, and NULL.

Referenced by GS_load_att_map().

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

Call this one when you already know att_src is MAP_ATT.

Parameters
cobuff
colorattcolor attribute
offsetoffset value
Returns
packed color for catagory at offset

Definition at line 969 of file gs.c.

References typbuff::cb, typbuff::ib, and gsurf_att::lookup.

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

int gs_mask_defined ( geosurf gs)

Check if mask is defined.

Parameters
gspointer to geosurf struct
Returns
1 if defined
0 not defined

Definition at line 915 of file gs.c.

References g_surf::att, ATT_MASK, gsurf_att::att_src, and NOTSET_ATT.

Referenced by gs_update_curmask().

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
tbpointer to typbuff
colnumber of cols
rownumber of rows
offsetoffset value
Returns
1
0

Definition at line 933 of file gs.c.

References typbuff::bm, BM_get(), typbuff::cb, typbuff::fb, typbuff::ib, and typbuff::sb.

Referenced by gs_update_curmask().

int gs_num_datah_reused ( int  dh)

Get number of reused values.

Parameters
dhvalue
Returns
number of reused values

Definition at line 597 of file gs.c.

References g_surf::att, G_debug(), gsurf_att::hdata, MAX_ATTS, and g_surf::next.

Referenced by gs_set_att_src().

int gs_num_surfaces ( void  )

Get number of surfaces.

Returns
number of surfaces

Definition at line 127 of file gs.c.

References G_debug(), and g_surf::next.

Referenced by GS_draw_cplane(), and GS_num_surfs().

int gs_point_is_masked ( geosurf gs,
float *  pt 
)

Check if point is masked.

Parameters
gspointer to geosurf struct
ptpoint coordinates (X,Y,Z)
Returns
1 masked
0 not masked

Definition at line 1317 of file gs.c.

References BM_get(), g_surf::curmask, MASK_BL, MASK_BR, MASK_TL, MASK_TR, 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().

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

Set attribute constant value.

Todo:
set typbuf constant
Parameters
gspointer to geosurf struct
descattribute id
constantconstant value
Returns
0 on success
-1 on error

Definition at line 872 of file gs.c.

References g_surf::att, ATT_MASK, CONST_ATT, gsurf_att::constant, G_debug(), gs_set_att_src(), Gs_update_attrange(), g_surf::gsurf_id, and g_surf::mask_needupdate.

Referenced by GS_set_att_const().

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

Set attribute source.

Parameters
gspointer to geosurf struct
descattribute id (descriptor)
srcsource id
Returns
-1 on error
0 on success

Definition at line 827 of file gs.c.

References g_surf::att, gsurf_att::att_src, ATT_TOPO, G_debug(), G_free(), gs_get_att_src(), gs_num_datah_reused(), gsds_free_datah(), g_surf::gsurf_id, gsurf_att::hdata, LEGAL_SRC, MAP_ATT, g_surf::norm_needupdate, g_surf::norms, and NULL.

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

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

Set attribute type.

Parameters
gspointer to geosurf struct
descattribute id
typeattribute type
Returns
-1 on error
0 on success

Definition at line 803 of file gs.c.

References g_surf::att, gsurf_att::att_type, G_debug(), and LEGAL_TYPE.

Referenced by GS_load_att_map(), and gs_malloc_att_buff().

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

Set default attribute values.

Parameters
gspointer to geosurf struct
defsarray of default values (dim MAX_ATTRS)
null_defsarray of null default values (dim MAX_ATTRS)

Definition at line 441 of file gs.c.

References g_surf::att, gsurf_att::att_src, gsurf_att::constant, gsurf_att::default_null, G_debug(), g_surf::gsurf_id, gsurf_att::hdata, gsurf_att::lookup, MAX_ATTS, NOTSET_ATT, and NULL.

Referenced by GS_new_surface().

void gs_set_maskmode ( int  invert)

Set geosurf mask mode.

Parameters
invertinvert mask

Definition at line 900 of file gs.c.

Referenced by gs_update_curmask().

int gs_setall_norm_needupdate ( void  )

Set for geosurf need-to-update mark.

Returns
-1 no surface available
1 on success

Definition at line 1290 of file gs.c.

References g_surf::next, and g_surf::norm_needupdate.

void print_256lookup ( int buff)

Debugging, 256 integer values from buffer.

Todo:
G_debug ?
Parameters
ftpointer to buffer

Definition at line 367 of file gs.c.

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

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

Todo:
G_debug ?
Parameters
ftpointer to coordinates

Definition at line 337 of file gs.c.

References FROM, TO, X, Y, and Z.

Referenced by print_view_fields().

void print_realto ( float *  rt)

Debugging, print 'to' real coordinates to stderr.

Todo:
G_debug ?
Parameters
ftpointer to coordinates

Definition at line 353 of file gs.c.

References X, Y, and Z.

void print_surf_fields ( geosurf s)
void print_view_fields ( geoview gv)

Debugging, print geoview fields to stderr.

Todo:
G_debug ?
Parameters
gvpointer to geoview struct

Definition at line 419 of file gs.c.

References geoview::coord_sys, geoview::fov, geoview::from_to, geoview::incl, geoview::infocus, geoview::look, print_frto(), geoview::real_to, geoview::scale, geoview::twist, geoview::vert_exag, geoview::view_proj, X, Y, and Z.