GRASS 8 Programmer's Manual  8.5.0dev(2025)-2b20964244
All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
gsd_objs.c File Reference

OGSF library - objects management (lower level functions) More...

#include <stdlib.h>
#include <string.h>
#include <grass/gis.h>
#include <grass/ogsf.h>
#include "gsget.h"
#include "math.h"
#include "rowcol.h"
Include dependency graph for gsd_objs.c:

Go to the source code of this file.

Macros

#define ONORM   .57445626
 
#define UP_NORM   Octo[2]
 
#define DOWN_NORM   Octo[5]
 
#define ORIGIN   origin
 

Functions

void gsd_plus (float *center, int colr, float siz)
 Draws a plus sign symbol at the specified center location. More...
 
void gsd_line_onsurf (geosurf *gs, float *v1, float *v2)
 Line on surface, fix z-values. More...
 
int gsd_nline_onsurf (geosurf *gs, float *v1, float *v2, float *pt, int n)
 Multiline on surface, fix z-values. More...
 
void gsd_x (geosurf *gs, float *center, int colr, float siz)
 Draws a X symbol at the specified center location. More...
 
void gsd_diamond (float *center, unsigned long colr, float siz)
 Draws a diamond symbol at the specified center location. More...
 
void gsd_cube (float *center, unsigned long colr, float siz)
 Draws a cube symbol at the specified center location. More...
 
void gsd_draw_box (float *center, unsigned long colr, float siz)
 Draws a box symbol at the specified center location. More...
 
void gsd_drawsphere (float *center, unsigned long colr, float siz)
 Draws a sphere at the specified center location. More...
 
void gsd_diamond_lines (void)
 Draw diamond lines. More...
 
void gsd_draw_asterisk (float *center, unsigned long colr, float siz)
 Draws an asterisk symbol at the specified center location. More...
 
void gsd_draw_gyro (float *center, unsigned long colr, float siz)
 Draws a gyro symbol at the specified center location. More...
 
void gsd_3dcursor (float *pt)
 Draw 3d cursor. More...
 
void dir_to_slope_aspect (float *dir, float *slope, float *aspect, int degrees)
 Converts a direction vector to slope and aspect angles. More...
 
int gsd_north_arrow (float *pos2, float len, GLuint fontbase, unsigned long arw_clr, unsigned long text_clr)
 Draw North Arrow. More...
 
int gsd_arrow (float *center, unsigned long colr, float siz, float *dir, float sz, geosurf *onsurf)
 Draws an arrow. More...
 
int gsd_arrow_onsurf (float *base, float *tip, unsigned long colr, int wid, geosurf *gs)
 Draw north arrow on surface. More...
 
void gsd_3darrow (float *center, unsigned long colr, float siz1, float siz2, float *dir, float sz)
 Draw 3d north arrow. More...
 
int gsd_scalebar (float *pos2, float len, GLuint fontbase, unsigned long bar_clr, unsigned long text_clr)
 Draw Scalebar takes OpenGL coords and size. More...
 
int gsd_scalebar_v2 (float *pos, float len, GLuint fontbase, unsigned long bar_clr, unsigned long text_clr)
 Draw Scalebar (as lines) More...
 
void primitive_cone (unsigned long colr)
 Primitives only called after transforms. More...
 
void primitive_cylinder (unsigned long colr, int caps)
 Primitives only called after transforms. More...
 
void gsd_box (float *center, int colr, float *siz)
 Draws a box at the specified center location. More...
 

Variables

float Octo [6][3]
 vertices for octahedron More...
 
float OctoN [8][3]
 normals for flat-shaded octahedron More...
 
float CubeNormals [3][3] = {{0, - .57445626 , 0}, {0, 0, .57445626 }, { .57445626 , 0, 0}}
 
float CubeVertices [8][3]
 
float origin [3] = {0.0, 0.0, 0.0}
 
float ogverts [8][3]
 vertices & normals for octagon in xy plane More...
 
float ogvertsplus [8][3]
 vertices for octagon in xy plane, z=1 More...
 
float Pi
 
float Box [8][3]
 Vertices for box. More...
 
float BoxN [6][3]
 

Detailed Description

OGSF library - objects management (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 (October 1993)
Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)

Definition in file gsd_objs.c.

Macro Definition Documentation

◆ DOWN_NORM

#define DOWN_NORM   Octo[5]

Definition at line 69 of file gsd_objs.c.

◆ ONORM

#define ONORM   .57445626

Definition at line 37 of file gsd_objs.c.

◆ ORIGIN

#define ORIGIN   origin

Definition at line 70 of file gsd_objs.c.

◆ UP_NORM

#define UP_NORM   Octo[2]

Definition at line 68 of file gsd_objs.c.

Function Documentation

◆ dir_to_slope_aspect()

void dir_to_slope_aspect ( float *  dir,
float *  slope,
float *  aspect,
int  degrees 
)

Converts a direction vector to slope and aspect angles.

Given a 3D direction vector, this function computes the slope and aspect angles corresponding to the vector. The aspect is the compass direction (azimuth) of the projection of the vector onto the XY plane, and the slope is the angle between the vector and the vertical axis (Z).

Parameters
[in]dirPointer to an array of 3 floats representing the direction vector [dx, dy, dz].
[out]slopePointer to a float where the computed slope angle will be stored (in radians or degrees).
[out]aspectPointer to a float where the computed aspect angle will be stored (in radians or degrees).
[in]degreesIf non-zero, the output angles are converted to degrees; otherwise, they are in radians.

The function handles edge cases where the direction vector is vertical or horizontal. Aspect is set to 0 if the vector has no horizontal component. Slope is negative for upward-pointing vectors, positive for downward.

Definition at line 776 of file gsd_objs.c.

References Pi, X, Y, and Z.

◆ gsd_3darrow()

void gsd_3darrow ( float *  center,
unsigned long  colr,
float  siz1,
float  siz2,
float *  dir,
float  sz 
)

Draw 3d north arrow.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the arrow.
siz1size
siz2size
dirDirection of the arrow. Pointer to a float array representing the 3D vector (X,Y,Z).
szheight

Definition at line 1111 of file gsd_objs.c.

◆ gsd_3dcursor()

void gsd_3dcursor ( float *  pt)

Draw 3d cursor.

Parameters
[in]ptpoint

Definition at line 719 of file gsd_objs.c.

References gsd_bgnline(), gsd_endline(), gsd_vert_func(), X, Y, and Z.

◆ gsd_arrow()

int gsd_arrow ( float *  center,
unsigned long  colr,
float  siz,
float *  dir,
float  sz,
geosurf onsurf 
)

Draws an arrow.

siz is height, sz is global exag to correct for.

If onsurf in non-null, z component of dir is dropped and line-on-suf is used, resulting in length of arrow being proportional to slope.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the arrow.
sizSize of the arrow.
dirDirection of the arrow. Pointer to a float array representing the 3D vector (X,Y,Z).
szheight, sz is global exag to correct for.
onsurfsurface (geosurf).
Returns
1 no surface given
0 on surface

Definition at line 948 of file gsd_objs.c.

Referenced by gsd_wire_arrows().

◆ gsd_arrow_onsurf()

int gsd_arrow_onsurf ( float *  base,
float *  tip,
unsigned long  colr,
int  wid,
geosurf gs 
)

Draw north arrow on surface.

Parameters
basePointer to a float array representing the base as a 2D vector (X,Y).
tipPointer to a float array representing the tip as a 2D vector (X,Y).
colrInteger representing the color to use for drawing the arrow.
widLine width (see gsd_linewidth)
gssurface (geosurf)
Returns
0

Definition at line 1022 of file gsd_objs.c.

◆ gsd_box()

void gsd_box ( float *  center,
int  colr,
float *  siz 
)

Draws a box at the specified center location.

This function renders a box at the given center coordinates with the specified color and size.

Warning
siz is an array (we need it for scale only Z in histograms)
Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 1475 of file gsd_objs.c.

References Box, BoxN, gsd_bgnpolygon(), gsd_endpolygon(), gsd_getshademodel(), gsd_litvert_func(), gsd_popmatrix(), gsd_pushmatrix(), gsd_scale(), gsd_shademodel(), gsd_translate(), X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_cube()

void gsd_cube ( float *  center,
unsigned long  colr,
float  siz 
)

Draws a cube symbol at the specified center location.

This function renders a cube symbol at the given center coordinates with the specified color and size.

Added by Hamish Bowman Nov 2005

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 422 of file gsd_objs.c.

References CubeNormals, CubeVertices, gsd_bgnpolygon(), gsd_endpolygon(), gsd_getshademodel(), gsd_litvert_func(), gsd_popmatrix(), gsd_pushmatrix(), gsd_scale(), gsd_shademodel(), gsd_translate(), X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_diamond()

void gsd_diamond ( float *  center,
unsigned long  colr,
float  siz 
)

Draws a diamond symbol at the specified center location.

This function renders a diamond symbol at the given center coordinates with the specified color and size.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 316 of file gsd_objs.c.

References gsd_bgnpolygon(), gsd_bgntmesh(), gsd_endpolygon(), gsd_endtmesh(), gsd_getshademodel(), gsd_litvert_func(), gsd_popmatrix(), gsd_pushmatrix(), gsd_scale(), gsd_shademodel(), gsd_swaptmesh(), gsd_translate(), Octo, OctoN, X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_diamond_lines()

void gsd_diamond_lines ( void  )

Draw diamond lines.

Definition at line 577 of file gsd_objs.c.

References gsd_bgnline(), gsd_endline(), gsd_vert_func(), and Octo.

Referenced by gsd_draw_asterisk().

◆ gsd_draw_asterisk()

void gsd_draw_asterisk ( float *  center,
unsigned long  colr,
float  siz 
)

Draws an asterisk symbol at the specified center location.

This function renders an asterisk symbol at the given center coordinates with the specified color and size.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 608 of file gsd_objs.c.

References gsd_color_func(), gsd_diamond_lines(), gsd_popmatrix(), gsd_pushmatrix(), gsd_rot(), gsd_scale(), gsd_translate(), X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_draw_box()

void gsd_draw_box ( float *  center,
unsigned long  colr,
float  siz 
)

Draws a box symbol at the specified center location.

This function renders a box symbol at the given center coordinates with the specified color and size.

Added by Hamish Bowman Nov 2005

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 502 of file gsd_objs.c.

References CubeVertices, gsd_bgnline(), gsd_color_func(), gsd_endline(), gsd_popmatrix(), gsd_pushmatrix(), gsd_scale(), gsd_translate(), gsd_vert_func(), X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_draw_gyro()

void gsd_draw_gyro ( float *  center,
unsigned long  colr,
float  siz 
)

Draws a gyro symbol at the specified center location.

This function renders a gyro symbol at the given center coordinates with the specified color and size.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 667 of file gsd_objs.c.

References gsd_bgnline(), gsd_circ(), gsd_color_func(), gsd_endline(), gsd_popmatrix(), gsd_pushmatrix(), gsd_rot(), gsd_scale(), gsd_translate(), gsd_vert_func(), Octo, X, Y, and Z.

Referenced by gpd_obj().

◆ gsd_drawsphere()

void gsd_drawsphere ( float *  center,
unsigned long  colr,
float  siz 
)

Draws a sphere at the specified center location.

This function renders a sphere at the given center coordinates with the specified color and size.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the sphere.
sizSize of the sphere.

Definition at line 565 of file gsd_objs.c.

References gsd_color_func(), and gsd_sphere().

◆ gsd_line_onsurf()

void gsd_line_onsurf ( geosurf gs,
float *  v1,
float *  v2 
)

Line on surface, fix z-values.

Todo:
remove fudge, instead fudge the Z buffer
Parameters
gssurface (geosurf)
v1first point (X,Y)
v2second point (X,Y)

Definition at line 171 of file gsd_objs.c.

References FUDGE, gsd_bgnline(), gsd_endline(), gsd_vert_func(), gsdrape_get_segments(), and Z.

Referenced by gsd_x().

◆ gsd_nline_onsurf()

int gsd_nline_onsurf ( geosurf gs,
float *  v1,
float *  v2,
float *  pt,
int  n 
)

Multiline on surface, fix z-values.

Todo:
remove fudge, instead fudge the Z buffer

Like above, except only draws first n points of line, or np, whichever is less. Returns number of points used. Fills pt with last pt drawn.

Parameters
gssurface (geosurf)
v1Pointer to a float array representing the first point as a vector.
v2Pointer to a float array representing the second point as a vector.
[out]pt
[in]nnumber of segments
Returns
int

Definition at line 216 of file gsd_objs.c.

References FUDGE, gsd_bgnline(), gsd_endline(), gsd_vert_func(), gsdrape_get_segments(), X, Y, and Z.

◆ gsd_north_arrow()

int gsd_north_arrow ( float *  pos2,
float  len,
GLuint  fontbase,
unsigned long  arw_clr,
unsigned long  text_clr 
)

Draw North Arrow.

Takes OpenGL coords and size

Parameters
pos2Pointer to a float array representing the position as a 3D vector (X,Y,Z).
len
fontbase
arw_clrnorth arrow color
text_clrtext color
Returns
1
Todo:

Store arrow somewhere to enable it's removal/change.

Add option to specify north text and font.

Definition at line 851 of file gsd_objs.c.

References GS_done_draw(), GS_set_draw(), gsd_bgnpolygon(), gsd_color_func(), gsd_do_scale(), gsd_endpolygon(), gsd_flush(), GSD_FRONT, gsd_get_txtheight(), gsd_get_txtwidth(), gsd_popmatrix(), gsd_pushmatrix(), Ntop, X, Y, and Z.

◆ gsd_plus()

void gsd_plus ( float *  center,
int  colr,
float  siz 
)

Draws a plus sign symbol at the specified center location.

This function renders a plus sign ('+') symbol at the given center coordinates with the specified color and size.

Parameters
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 134 of file gsd_objs.c.

References gsd_bgnline(), gsd_color_func(), gsd_endline(), gsd_vert_func(), X, Y, and Z.

◆ gsd_scalebar()

int gsd_scalebar ( float *  pos2,
float  len,
GLuint  fontbase,
unsigned long  bar_clr,
unsigned long  text_clr 
)

Draw Scalebar takes OpenGL coords and size.

Adapted from gsd_north_arrow Hamish Bowman Dec 2006

Parameters
pos2Pointer to a float array representing the scalebar position as a 3D vector (X,Y,Z).
len
fontbasefont-base
bar_clrbarscale color. Integer representing the color to use for the barscale.
text_clrtest color. Integer representing the color to use for the text.
Returns
1

Definition at line 1193 of file gsd_objs.c.

References G_database_unit_name(), GS_done_draw(), GS_set_draw(), gsd_bgnpolygon(), gsd_color_func(), gsd_do_scale(), gsd_endpolygon(), gsd_flush(), GSD_FRONT, gsd_get_txtheight(), gsd_get_txtwidth(), gsd_popmatrix(), gsd_pushmatrix(), Ntop, TRUE, X, Y, and Z.

◆ gsd_scalebar_v2()

int gsd_scalebar_v2 ( float *  pos,
float  len,
GLuint  fontbase,
unsigned long  bar_clr,
unsigned long  text_clr 
)

Draw Scalebar (as lines)

Adapted from gsd_scalebar A.Kratochvilova 2011

Parameters
posPointer to a float array representing the scalebar position as a 3D vector (X,Y,Z).
len
fontbasefont-base (unused)
bar_clrbarscale color. Integer representing the color to use for the barscale.
text_clrText color (unused). Integer representing the color to use for the text.
Returns
1

Definition at line 1282 of file gsd_objs.c.

References GS_done_draw(), GS_set_draw(), gsd_bgnline(), gsd_color_func(), gsd_do_scale(), gsd_endline(), gsd_flush(), GSD_FRONT, gsd_linewidth(), gsd_popmatrix(), gsd_pushmatrix(), gsd_vert_func(), Ntop, X, Y, and Z.

◆ gsd_x()

void gsd_x ( geosurf gs,
float *  center,
int  colr,
float  siz 
)

Draws a X symbol at the specified center location.

This function renders a x ('X') symbol at the given center coordinates with the specified color and size.

Note gs: NULL if flat

Parameters
gssurface (geosurf)
centerPointer to a float array representing the (x, y, z) coordinates of the center point.
colrInteger representing the color to use for drawing the symbol.
sizSize of the symbol.

Definition at line 263 of file gsd_objs.c.

References gsd_bgnline(), gsd_color_func(), gsd_endline(), gsd_line_onsurf(), gsd_vert_func(), X, Y, and Z.

Referenced by gpd_obj().

◆ primitive_cone()

void primitive_cone ( unsigned long  colr)

Primitives only called after transforms.

Center is actually center at base of 8 sided cone

Parameters
colrInteger representing the color to use for drawing the cone.

Definition at line 1345 of file gsd_objs.c.

◆ primitive_cylinder()

void primitive_cylinder ( unsigned long  colr,
int  caps 
)

Primitives only called after transforms.

Center is actually center at base of 8 sided cylinder

Parameters
colrInteger representing the color to use for drawing the cylinder.
capsIf non zero, draw caps at the bottom and top of the cylinder.

Definition at line 1382 of file gsd_objs.c.

Variable Documentation

◆ Box

float Box[8][3]
Initial value:
= {{1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0}, {-1.0, 1.0, 1.0},
{1.0, 1.0, 1.0}, {1.0, -1.0, -1.0}, {-1.0, -1.0, -1.0},
{-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}}

Vertices for box.

Definition at line 1455 of file gsd_objs.c.

Referenced by gsd_box(), Vect_box_clip(), Vect_get_area_box(), Vect_get_constraint_box(), Vect_get_isle_box(), Vect_get_map_box(), Vect_point_in_box(), Vect_point_in_box_2d(), Vect_region_box(), Vect_select_isles_by_box(), and Vect_select_nodes_by_box().

◆ BoxN

float BoxN[6][3]
Initial value:
= {{0, 0, - .57445626 }, {0, 0, .57445626 }, {0, .57445626 , 0},
{0, - .57445626 , 0}, { .57445626 , 0, 0}, {- .57445626 , 0, 0}}

Definition at line 1459 of file gsd_objs.c.

Referenced by gsd_box().

◆ CubeNormals

float CubeNormals[3][3] = {{0, - .57445626 , 0}, {0, 0, .57445626 }, { .57445626 , 0, 0}}

???? not sure if any of these are needed for correct lighting. float CubeNormals[6][3] = { {ONORM, 0, 0}, {-ONORM, 0, 0}, {0, ONORM, 0}, {0, -ONORM, 0}, {0, 0, ONORM}, {0, 0, -ONORM} };

Definition at line 60 of file gsd_objs.c.

Referenced by gsd_cube().

◆ CubeVertices

float CubeVertices[8][3]
Initial value:
= {
{-1.0, -1.0, -1.0}, {1.0, -1.0, -1.0}, {1.0, 1.0, -1.0}, {-1.0, 1.0, -1.0},
{-1.0, -1.0, 1.0}, {1.0, -1.0, 1.0}, {1.0, 1.0, 1.0}, {-1.0, 1.0, 1.0}}

Definition at line 62 of file gsd_objs.c.

Referenced by gsd_cube(), and gsd_draw_box().

◆ Octo

float Octo[6][3]
Initial value:
= {{1.0, 0.0, 0.0}, {0.0, 1.0, 0.0}, {0.0, 0.0, 1.0},
{-1.0, 0.0, 0.0}, {0.0, -1.0, 0.0}, {0.0, 0.0, -1.0}}

vertices for octahedron

Definition at line 34 of file gsd_objs.c.

Referenced by gsd_diamond(), gsd_diamond_lines(), and gsd_draw_gyro().

◆ OctoN

float OctoN[8][3]
Initial value:
= {
{ .57445626 , .57445626 , .57445626 }, {- .57445626 , .57445626 , .57445626 }, { .57445626 , - .57445626 , .57445626 },
{- .57445626 , - .57445626 , .57445626 }, { .57445626 , .57445626 , - .57445626 }, {- .57445626 , .57445626 , - .57445626 },
{ .57445626 , - .57445626 , - .57445626 }, {- .57445626 , - .57445626 , - .57445626 },
}

normals for flat-shaded octahedron

Definition at line 42 of file gsd_objs.c.

Referenced by gsd_diamond().

◆ ogverts

float ogverts[8][3]

vertices & normals for octagon in xy plane

Definition at line 75 of file gsd_objs.c.

◆ ogvertsplus

float ogvertsplus[8][3]

vertices for octagon in xy plane, z=1

Definition at line 80 of file gsd_objs.c.

◆ origin

float origin[3] = {0.0, 0.0, 0.0}

Definition at line 66 of file gsd_objs.c.

◆ Pi

float Pi

Definition at line 82 of file gsd_objs.c.

Referenced by dir_to_slope_aspect().