GRASS 8 Programmer's Manual
8.5.0dev(2025)-2b20964244
|
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"
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] |
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.
Definition in file gsd_objs.c.
#define DOWN_NORM Octo[5] |
Definition at line 69 of file gsd_objs.c.
#define ONORM .57445626 |
Definition at line 37 of file gsd_objs.c.
#define ORIGIN origin |
Definition at line 70 of file gsd_objs.c.
#define UP_NORM Octo[2] |
Definition at line 68 of file gsd_objs.c.
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).
[in] | dir | Pointer to an array of 3 floats representing the direction vector [dx, dy, dz]. |
[out] | slope | Pointer to a float where the computed slope angle will be stored (in radians or degrees). |
[out] | aspect | Pointer to a float where the computed aspect angle will be stored (in radians or degrees). |
[in] | degrees | If 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.
void gsd_3darrow | ( | float * | center, |
unsigned long | colr, | ||
float | siz1, | ||
float | siz2, | ||
float * | dir, | ||
float | sz | ||
) |
Draw 3d north arrow.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the arrow. |
siz1 | size |
siz2 | size |
dir | Direction of the arrow. Pointer to a float array representing the 3D vector (X,Y,Z). |
sz | height |
Definition at line 1111 of file gsd_objs.c.
void gsd_3dcursor | ( | float * | pt | ) |
Draw 3d cursor.
[in] | pt | point |
Definition at line 719 of file gsd_objs.c.
References gsd_bgnline(), gsd_endline(), gsd_vert_func(), X, Y, and Z.
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the arrow. |
siz | Size of the arrow. |
dir | Direction of the arrow. Pointer to a float array representing the 3D vector (X,Y,Z). |
sz | height, sz is global exag to correct for. |
onsurf | surface (geosurf). |
Definition at line 948 of file gsd_objs.c.
Referenced by gsd_wire_arrows().
int gsd_arrow_onsurf | ( | float * | base, |
float * | tip, | ||
unsigned long | colr, | ||
int | wid, | ||
geosurf * | gs | ||
) |
Draw north arrow on surface.
base | Pointer to a float array representing the base as a 2D vector (X,Y). |
tip | Pointer to a float array representing the tip as a 2D vector (X,Y). |
colr | Integer representing the color to use for drawing the arrow. |
wid | Line width (see gsd_linewidth) |
gs | surface (geosurf) |
Definition at line 1022 of file gsd_objs.c.
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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().
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the sphere. |
siz | Size of the sphere. |
Definition at line 565 of file gsd_objs.c.
References gsd_color_func(), and gsd_sphere().
void gsd_line_onsurf | ( | geosurf * | gs, |
float * | v1, | ||
float * | v2 | ||
) |
Line on surface, fix z-values.
gs | surface (geosurf) |
v1 | first point (X,Y) |
v2 | second 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().
int gsd_nline_onsurf | ( | geosurf * | gs, |
float * | v1, | ||
float * | v2, | ||
float * | pt, | ||
int | n | ||
) |
Multiline on surface, fix z-values.
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.
gs | surface (geosurf) | |
v1 | Pointer to a float array representing the first point as a vector. | |
v2 | Pointer to a float array representing the second point as a vector. | |
[out] | pt | |
[in] | n | number of segments |
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.
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
pos2 | Pointer to a float array representing the position as a 3D vector (X,Y,Z). |
len | |
fontbase | |
arw_clr | north arrow color |
text_clr | text color |
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.
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.
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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.
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
pos2 | Pointer to a float array representing the scalebar position as a 3D vector (X,Y,Z). |
len | |
fontbase | font-base |
bar_clr | barscale color. Integer representing the color to use for the barscale. |
text_clr | test color. Integer representing the color to use for the text. |
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.
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
pos | Pointer to a float array representing the scalebar position as a 3D vector (X,Y,Z). |
len | |
fontbase | font-base (unused) |
bar_clr | barscale color. Integer representing the color to use for the barscale. |
text_clr | Text color (unused). Integer representing the color to use for the text. |
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.
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
gs | surface (geosurf) |
center | Pointer to a float array representing the (x, y, z) coordinates of the center point. |
colr | Integer representing the color to use for drawing the symbol. |
siz | Size 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().
void primitive_cone | ( | unsigned long | colr | ) |
Primitives only called after transforms.
Center is actually center at base of 8 sided cone
colr | Integer representing the color to use for drawing the cone. |
Definition at line 1345 of file gsd_objs.c.
void primitive_cylinder | ( | unsigned long | colr, |
int | caps | ||
) |
Primitives only called after transforms.
Center is actually center at base of 8 sided cylinder
colr | Integer representing the color to use for drawing the cylinder. |
caps | If non zero, draw caps at the bottom and top of the cylinder. |
Definition at line 1382 of file gsd_objs.c.
float Box[8][3] |
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().
float BoxN[6][3] |
Definition at line 1459 of file gsd_objs.c.
Referenced by gsd_box().
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().
float CubeVertices[8][3] |
Definition at line 62 of file gsd_objs.c.
Referenced by gsd_cube(), and gsd_draw_box().
float Octo[6][3] |
vertices for octahedron
Definition at line 34 of file gsd_objs.c.
Referenced by gsd_diamond(), gsd_diamond_lines(), and gsd_draw_gyro().
float OctoN[8][3] |
normals for flat-shaded octahedron
Definition at line 42 of file gsd_objs.c.
Referenced by gsd_diamond().
float ogverts[8][3] |
vertices & normals for octagon in xy plane
Definition at line 75 of file gsd_objs.c.
float ogvertsplus[8][3] |
vertices for octagon in xy plane, z=1
Definition at line 80 of file gsd_objs.c.
float origin[3] = {0.0, 0.0, 0.0} |
Definition at line 66 of file gsd_objs.c.
float Pi |
Definition at line 82 of file gsd_objs.c.
Referenced by dir_to_slope_aspect().