Loading...
Searching...
No Matches
gpd.c
Go to the documentation of this file.
/*!
\file lib/ogsf/gpd.c
\brief OGSF library - loading and manipulating point sets (lower level)
(C) 1999-2008, 2011 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 (December 1993)
\author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
*/
#include <stdlib.h>
#include <math.h>
#include <grass/ogsf.h>
#include "rowcol.h"
#define CHK_FREQ 50
/* BOB -- border allowed outside of viewport */
#define v_border 50
/*!
\brief Check if point is in region
Check for cancel every CHK_FREQ points
\param gs surface (geosurf)
\param pt point (array(X,Y,Z))
\param region region settings (array (top,bottom,left,right))
\return 0 point outside of region
\return 1 point inside region
*/
int gs_point_in_region(geosurf *gs, float *pt, float *region)
{
float top, bottom, left, right;
if (!region) {
top = gs->yrange;
bottom = VROW2Y(gs, VROWS(gs));
left = 0.0;
right = VCOL2X(gs, VCOLS(gs));
}
else {
top = region[0];
bottom = region[1];
left = region[2];
right = region[3];
}
return (pt[X] >= left && pt[X] <= right && pt[Y] >= bottom && pt[Y] <= top);
}
/*!
\brief Draw point representing object
Do normal transforms before calling
Note gs: NULL if 3d obj or const elev surface
\param gs surface (geosurf)
\param style object displaying style (highlighted or not)
\param pt 3d point (Point3)
*/
void gpd_obj(geosurf *gs, gvstyle *style, Point3 pt)
{
float sz, lpt[3];
float siz[3];
gsd_color_func(style->color);
sz = GS_global_exag();
GS_v3eq(lpt, pt); /* CHANGING Z OF POINT PASSED, so use copy */
switch (style->symbol) {
case ST_HISTOGRAM:
gsd_colormode(CM_DIFFUSE);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
siz[0] = style->size; /*TODO: Fix historgam drawing */
siz[1] = style->size;
siz[2] = style->size;
gsd_box(lpt, style->color, siz);
gsd_popmatrix();
gsd_colormode(CM_COLOR);
break;
case ST_DIAMOND:
/*
gsd_colormode(CM_AD);
*/
gsd_colormode(CM_DIFFUSE);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_diamond(lpt, style->color, style->size);
gsd_popmatrix();
gsd_colormode(CM_COLOR);
break;
case ST_BOX:
gsd_colormode(CM_COLOR);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_draw_box(lpt, style->color, style->size);
gsd_popmatrix();
break;
case ST_SPHERE:
/*
gsd_colormode(CM_AD);
*/
gsd_colormode(CM_DIFFUSE);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_sphere(lpt, style->size);
gsd_popmatrix();
gsd_colormode(CM_COLOR);
break;
case ST_GYRO:
gsd_colormode(CM_COLOR);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_draw_gyro(lpt, style->color, style->size);
gsd_popmatrix();
break;
case ST_ASTER:
gsd_colormode(CM_COLOR);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_draw_asterisk(lpt, style->color, style->size);
gsd_popmatrix();
break;
case ST_CUBE:
gsd_colormode(CM_DIFFUSE);
gsd_pushmatrix();
if (sz) {
lpt[Z] *= sz;
gsd_scale(1.0, 1.0, 1. / sz);
}
gsd_cube(lpt, style->color, style->size);
gsd_popmatrix();
gsd_colormode(CM_COLOR);
break;
default:
case ST_X:
gsd_colormode(CM_COLOR);
gsd_x(gs, lpt, style->color, style->size);
break;
}
return;
}
/*!
\brief Draw 2D point set
Need to think about translations - If user translates surface,
sites should automatically go with it, but translating sites should
translate it relative to surface on which it's displayed
Handling mask checking here
\todo prevent scaling by 0
\param gp site (geosite)
\param gs surface (geosurf)
\param do_fast (unused)
\return 0 on failure
\return 1 on success
*/
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast G_UNUSED)
{
float site[4], konst;
int src, check;
geopoint *gpt;
typbuff *buf;
GLdouble modelMatrix[16], projMatrix[16];
GLint viewport[4];
GLint window[4];
if (GS_check_cancel()) {
return 0;
}
if (!gs)
return 1;
gs_update_curmask(gs);
src = gs_get_att_src(gs, ATT_TOPO);
if (src == CONST_ATT) {
konst = gs->att[ATT_TOPO].constant;
}
else {
buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
}
/* Get viewport parameters for view check */
gsd_getwindow(window, viewport, modelMatrix, projMatrix);
gsd_pushmatrix();
gsd_do_scale(1);
gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
gsd_linewidth(gp->style->width);
check = 0;
for (gpt = gp->points; gpt; gpt = gpt->next) {
if (!(++check % CHK_FREQ)) {
if (GS_check_cancel()) {
gsd_linewidth(1);
gsd_popmatrix();
return 0;
}
}
site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
if (gs_point_is_masked(gs, site)) {
continue;
}
if (src == MAP_ATT) {
if (viewcell_tri_interp(gs, buf, site, 1)) {
/* returns 0 if outside or masked */
site[Z] += gp->z_trans;
if (gsd_checkpoint(site, window, viewport, modelMatrix,
projMatrix))
continue;
}
}
else if (src == CONST_ATT) {
if (gs_point_in_region(gs, site, NULL)) {
site[Z] = konst + gp->z_trans;
if (gsd_checkpoint(site, window, viewport, modelMatrix,
projMatrix))
continue;
}
}
if (gpt->highlighted > 0)
gpd_obj(gs, gp->hstyle, site);
else if (gp->tstyle && gp->tstyle->active)
gpd_obj(gs, gpt->style, site);
else
gpd_obj(gs, gp->style, site);
}
gsd_linewidth(1);
gsd_popmatrix();
return 1;
}
/*!
\brief Draw 3D point set
\param gp site (geosite)
\param xo,yo
\param do_fast (unused)
\return 0 on success
\return 1 on failure
*/
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast G_UNUSED)
{
float site[4], tz;
int check;
geopoint *gpt;
GLdouble modelMatrix[16], projMatrix[16];
GLint viewport[4];
GLint window[4];
if (GS_check_cancel()) {
return 0;
}
gsd_getwindow(window, viewport, modelMatrix, projMatrix);
gsd_pushmatrix();
gsd_do_scale(1);
tz = GS_global_exag();
site[Z] = 0.0;
check = 0;
gsd_linewidth(gp->style->width);
for (gpt = gp->points; gpt; gpt = gpt->next) {
if (!(++check % CHK_FREQ)) {
if (GS_check_cancel()) {
gsd_linewidth(1);
gsd_popmatrix();
return (0);
}
}
site[X] = gpt->p3[X] + gp->x_trans - xo;
site[Y] = gpt->p3[Y] + gp->y_trans - yo;
if (tz) {
site[Z] = gpt->p3[Z] + gp->z_trans;
}
if (gsd_checkpoint(site, window, viewport, modelMatrix, projMatrix))
continue;
else
/* clip points outside default region? */
{
if (gpt->highlighted > 0)
gpd_obj(NULL, gp->hstyle, site);
else if (gp->tstyle && gp->tstyle->active)
gpd_obj(NULL, gpt->style, site);
else
gpd_obj(NULL, gp->style, site);
}
}
gsd_linewidth(1);
gsd_popmatrix();
return 1;
}
NULL
#define NULL
Definition ccmath.h:32
CHK_FREQ
#define CHK_FREQ
Definition gpd.c:22
gpd_obj
void gpd_obj(geosurf *gs, gvstyle *style, Point3 pt)
Draw point representing object.
Definition gpd.c:70
gpd_3dsite
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast)
Draw 3D point set.
Definition gpd.c:312
gs_point_in_region
int gs_point_in_region(geosurf *gs, float *pt, float *region)
Check if point is in region.
Definition gpd.c:39
gpd_2dsite
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast)
Draw 2D point set.
Definition gpd.c:215
GS_global_exag
float GS_global_exag(void)
Get global z-exag value.
Definition gs2.c:2000
gs_get_att_typbuff
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
Definition gs.c:681
gs_point_is_masked
int gs_point_is_masked(geosurf *gs, float *pt)
Check if point is masked.
Definition gs.c:1314
gs_get_att_src
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
Definition gs.c:656
gs_update_curmask
int gs_update_curmask(geosurf *surf)
Update current maps.
Definition gs_bm.c:228
GS_v3eq
void GS_v3eq(float *v1, float *v2)
Copy vector values.
Definition gs_util.c:178
gsd_diamond
void gsd_diamond(float *center, unsigned long colr, float siz)
Draws a diamond symbol at the specified center location.
Definition gsd_objs.c:316
gsd_draw_box
void gsd_draw_box(float *center, unsigned long colr, float siz)
Draws a box symbol at the specified center location.
Definition gsd_objs.c:502
gsd_x
void gsd_x(geosurf *gs, float *center, int colr, float siz)
Draws a X symbol at the specified center location.
Definition gsd_objs.c:263
gsd_cube
void gsd_cube(float *center, unsigned long colr, float siz)
Draws a cube symbol at the specified center location.
Definition gsd_objs.c:422
gsd_draw_asterisk
void gsd_draw_asterisk(float *center, unsigned long colr, float siz)
Draws an asterisk symbol at the specified center location.
Definition gsd_objs.c:608
gsd_box
void gsd_box(float *center, int colr, float *siz)
Draws a box at the specified center location.
Definition gsd_objs.c:1475
gsd_draw_gyro
void gsd_draw_gyro(float *center, unsigned long colr, float siz)
Draws a gyro symbol at the specified center location.
Definition gsd_objs.c:667
gsd_pushmatrix
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition gsd_prim.c:511
gsd_colormode
void gsd_colormode(int cm)
Set color mode.
Definition gsd_prim.c:98
gsd_sphere
void gsd_sphere(float *center, float siz)
ADD.
Definition gsd_prim.c:207
gsd_popmatrix
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition gsd_prim.c:501
gsd_checkpoint
int gsd_checkpoint(float pt[4], int window[4], int viewport[4], double modelMatrix[16], double projMatrix[16])
ADD.
Definition gsd_prim.c:585
gsd_scale
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
Definition gsd_prim.c:525
gsd_translate
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition gsd_prim.c:539
gsd_getwindow
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
Definition gsd_prim.c:554
gsd_color_func
void gsd_color_func(unsigned int col)
Set current color.
Definition gsd_prim.c:698
gsd_linewidth
void gsd_linewidth(short n)
Set width of rasterized lines.
Definition gsd_prim.c:267
gsd_do_scale
void gsd_do_scale(int doexag)
Set current scale.
Definition gsd_views.c:355
viewcell_tri_interp
int viewcell_tri_interp(geosurf *gs, typbuff *buf, Point3 pt, int check_mask)
ADD.
Definition gsdrape.c:509
GS_check_cancel
int GS_check_cancel(void)
Check for cancel.
Definition gsx.c:30
rowcol.h
VCOL2X
#define VCOL2X(gs, vcol)
Definition rowcol.h:40
VCOLS
#define VCOLS(gs)
Definition rowcol.h:14
VROWS
#define VROWS(gs)
Definition rowcol.h:13
VROW2Y
#define VROW2Y(gs, vrow)
Definition rowcol.h:39
X
#define X(j)
Y
#define Y(j)