GRASS GIS 8 Programmer's Manual  8.2.2dev(2023)-3d2c704037
gpd.c
Go to the documentation of this file.
1 /*!
2  \file lib/ogsf/gpd.c
3 
4  \brief OGSF library - loading and manipulating point sets (lower level)
5 
6  (C) 1999-2008, 2011 by the GRASS Development Team
7 
8  This program is free software under the GNU General Public License
9  (>=v2). Read the file COPYING that comes with GRASS for details.
10 
11  \author Bill Brown USACERL, GMSL/University of Illinois (December 1993)
12  \author Doxygenized by Martin Landa <landa.martin gmail.com> (May 2008)
13 */
14 
15 #include <stdlib.h>
16 #include <math.h>
17 
18 #include <grass/ogsf.h>
19 
20 #include "rowcol.h"
21 
22 #define CHK_FREQ 50
23 
24 /* BOB -- border allowed outside of viewport */
25 #define v_border 50
26 
27 /*!
28  \brief Check if point is in region
29 
30  Check for cancel every CHK_FREQ points
31 
32  \param gs surface (geosurf)
33  \param pt point (array(X,Y,Z))
34  \param region region settings (array (top,bottom,left,right))
35 
36  \return 0 point outside of region
37  \return 1 point inside region
38 */
39 int gs_point_in_region(geosurf * gs, float *pt, float *region)
40 {
41  float top, bottom, left, right;
42 
43  if (!region) {
44  top = gs->yrange;
45  bottom = VROW2Y(gs, VROWS(gs));
46  left = 0.0;
47  right = VCOL2X(gs, VCOLS(gs));
48  }
49  else {
50  top = region[0];
51  bottom = region[1];
52  left = region[2];
53  right = region[3];
54  }
55 
56  return (pt[X] >= left && pt[X] <= right &&
57  pt[Y] >= bottom && pt[Y] <= top);
58 }
59 
60 /*!
61  \brief Draw point representing object
62 
63  Do normal transforms before calling
64 
65  Note gs: NULL if 3d obj or const elev surface
66 
67  \param gs surface (geosurf)
68  \param style object displaying style (highlighted or not)
69  \param pt 3d point (Point3)
70  */
71 void gpd_obj(geosurf * gs, gvstyle * style, Point3 pt)
72 {
73  float sz, lpt[3];
74  float siz[3];
75 
76  gsd_color_func(style->color);
77  sz = GS_global_exag();
78  GS_v3eq(lpt, pt); /* CHANGING Z OF POINT PASSED, so use copy */
79 
80  switch (style->symbol) {
81  case ST_HISTOGRAM:
84 
85  if (sz) {
86  lpt[Z] *= sz;
87  gsd_scale(1.0, 1.0, 1. / sz);
88  }
89 
90  siz[0] = style->size; /*TODO: Fix historgam drawing */
91  siz[1] = style->size;
92  siz[2] = style->size;
93 
94  gsd_box(lpt, style->color, siz);
95 
96  gsd_popmatrix();
98 
99  break;
100  case ST_DIAMOND:
101  /*
102  gsd_colormode(CM_AD);
103  */
105  gsd_pushmatrix();
106 
107  if (sz) {
108  lpt[Z] *= sz;
109  gsd_scale(1.0, 1.0, 1. / sz);
110  }
111 
112  gsd_diamond(lpt, style->color, style->size);
113  gsd_popmatrix();
115 
116  break;
117  case ST_BOX:
119  gsd_pushmatrix();
120 
121  if (sz) {
122  lpt[Z] *= sz;
123  gsd_scale(1.0, 1.0, 1. / sz);
124  }
125 
126  gsd_draw_box(lpt, style->color, style->size);
127  gsd_popmatrix();
128 
129  break;
130  case ST_SPHERE:
131  /*
132  gsd_colormode(CM_AD);
133  */
135  gsd_pushmatrix();
136 
137  if (sz) {
138  lpt[Z] *= sz;
139  gsd_scale(1.0, 1.0, 1. / sz);
140  }
141 
142  gsd_sphere(lpt, style->size);
143  gsd_popmatrix();
145 
146  break;
147  case ST_GYRO:
149  gsd_pushmatrix();
150 
151  if (sz) {
152  lpt[Z] *= sz;
153  gsd_scale(1.0, 1.0, 1. / sz);
154  }
155 
156  gsd_draw_gyro(lpt, style->color, style->size);
157  gsd_popmatrix();
158 
159  break;
160  case ST_ASTER:
162  gsd_pushmatrix();
163 
164  if (sz) {
165  lpt[Z] *= sz;
166  gsd_scale(1.0, 1.0, 1. / sz);
167  }
168 
169  gsd_draw_asterisk(lpt, style->color, style->size);
170  gsd_popmatrix();
171 
172  break;
173  case ST_CUBE:
175  gsd_pushmatrix();
176 
177  if (sz) {
178  lpt[Z] *= sz;
179  gsd_scale(1.0, 1.0, 1. / sz);
180  }
181 
182  gsd_cube(lpt, style->color, style->size);
183  gsd_popmatrix();
185 
186  break;
187  default:
188  case ST_X:
190  gsd_x(gs, lpt, style->color, style->size);
191 
192  break;
193  }
194 
195  return;
196 }
197 
198 /*!
199  \brief Draw 2D point set
200 
201  Need to think about translations - If user translates surface,
202  sites should automatically go with it, but translating sites should
203  translate it relative to surface on which it's displayed
204 
205  Handling mask checking here
206 
207  \todo prevent scaling by 0
208 
209  \param gp site (geosite)
210  \param gs surface (geosurf)
211  \param do_fast (unused)
212 
213  \return 0 on failure
214  \return 1 on success
215 */
216 int gpd_2dsite(geosite * gp, geosurf * gs, int do_fast)
217 {
218  float site[3], konst;
219  int src, check;
220  geopoint *gpt;
221  typbuff *buf;
222  GLdouble modelMatrix[16], projMatrix[16];
223  GLint viewport[4];
224  GLint window[4];
225 
226  if (GS_check_cancel()) {
227  return 0;
228  }
229 
230  if (!gs)
231  return 1;
232 
233  gs_update_curmask(gs);
234 
235  src = gs_get_att_src(gs, ATT_TOPO);
236 
237  if (src == CONST_ATT) {
238  konst = gs->att[ATT_TOPO].constant;
239  }
240  else {
241  buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
242  }
243 
244  /* Get viewport parameters for view check */
245  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
246 
247  gsd_pushmatrix();
248  gsd_do_scale(1);
249  gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
250  gsd_linewidth(gp->style->width);
251  check = 0;
252 
253  for (gpt = gp->points; gpt; gpt = gpt->next) {
254  if (!(++check % CHK_FREQ)) {
255  if (GS_check_cancel()) {
256  gsd_linewidth(1);
257  gsd_popmatrix();
258 
259  return 0;
260  }
261  }
262 
263  site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
264  site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
265 
266  if (gs_point_is_masked(gs, site)) {
267  continue;
268  }
269 
270  if (src == MAP_ATT) {
271  if (viewcell_tri_interp(gs, buf, site, 1)) {
272  /* returns 0 if outside or masked */
273  site[Z] += gp->z_trans;
274 
275  if (gsd_checkpoint(site, window,
276  viewport, modelMatrix, projMatrix))
277  continue;
278  }
279  }
280  else if (src == CONST_ATT) {
281  if (gs_point_in_region(gs, site, NULL)) {
282  site[Z] = konst + gp->z_trans;
283  if (gsd_checkpoint(site, window,
284  viewport, modelMatrix, projMatrix))
285  continue;
286  }
287  }
288 
289  if (gpt->highlighted > 0)
290  gpd_obj(gs, gp->hstyle, site);
291  else if (gp->tstyle && gp->tstyle->active)
292  gpd_obj(gs, gpt->style, site);
293  else
294  gpd_obj(gs, gp->style, site);
295  }
296 
297  gsd_linewidth(1);
298  gsd_popmatrix();
299 
300  return 1;
301 }
302 
303 /*!
304  \brief Draw 3D point set
305 
306  \param gp site (geosite)
307  \param xo,yo
308  \param do_fast (unused)
309 
310  \return 0 on success
311  \return 1 on failure
312 */
313 int gpd_3dsite(geosite * gp, float xo, float yo, int do_fast)
314 {
315  float site[3], tz;
316  int check;
317  geopoint *gpt;
318  GLdouble modelMatrix[16], projMatrix[16];
319  GLint viewport[4];
320  GLint window[4];
321 
322  if (GS_check_cancel()) {
323  return 0;
324  }
325 
326  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
327 
328  gsd_pushmatrix();
329 
330  gsd_do_scale(1);
331 
332  tz = GS_global_exag();
333  site[Z] = 0.0;
334 
335  check = 0;
336 
337  gsd_linewidth(gp->style->width);
338 
339  for (gpt = gp->points; gpt; gpt = gpt->next) {
340  if (!(++check % CHK_FREQ)) {
341  if (GS_check_cancel()) {
342  gsd_linewidth(1);
343  gsd_popmatrix();
344 
345  return (0);
346  }
347  }
348 
349  site[X] = gpt->p3[X] + gp->x_trans - xo;
350  site[Y] = gpt->p3[Y] + gp->y_trans - yo;
351 
352  if (tz) {
353  site[Z] = gpt->p3[Z] + gp->z_trans;
354  }
355 
356  if (gsd_checkpoint(site, window, viewport, modelMatrix, projMatrix))
357  continue;
358  else
359  /* clip points outside default region? */
360  {
361  if (gpt->highlighted > 0)
362  gpd_obj(NULL, gp->hstyle, site);
363  else if (gp->tstyle && gp->tstyle->active)
364  gpd_obj(NULL, gpt->style, site);
365  else
366  gpd_obj(NULL, gp->style, site);
367  }
368  }
369 
370  gsd_linewidth(1);
371  gsd_popmatrix();
372 
373  return 1;
374 }
signed char highlighted
Definition: ogsf.h:359
Definition: ogsf.h:352
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast)
Draw 3D point set.
Definition: gpd.c:313
#define CM_DIFFUSE
Definition: ogsf.h:148
#define VCOL2X(gs, vcol)
Definition: rowcol.h:40
float size
Definition: ogsf.h:290
void gsd_box(float *, int, float *)
Draw box.
Definition: gsd_objs.c:1440
double ox
Definition: ogsf.h:264
#define VROWS(gs)
Definition: rowcol.h:13
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition: gsd_prim.c:500
#define VCOLS(gs)
Definition: rowcol.h:14
#define ATT_TOPO
Definition: ogsf.h:73
int gs_get_att_src(geosurf *, int)
Get attribute source.
Definition: gs.c:656
Definition: ogsf.h:365
int color
Definition: ogsf.h:288
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast)
Draw 2D point set.
Definition: gpd.c:216
float Point3[3]
Definition: ogsf.h:201
#define NULL
Definition: ccmath.h:32
gvstyle * style
Definition: ogsf.h:358
gvstyle_thematic * tstyle
Definition: ogsf.h:381
#define VROW2Y(gs, vrow)
Definition: rowcol.h:39
float yrange
Definition: ogsf.h:269
void gsd_colormode(int)
Set color mode.
Definition: gsd_prim.c:97
#define ST_DIAMOND
Definition: ogsf.h:93
int width
Definition: ogsf.h:291
void gsd_diamond(float *, unsigned long, float)
Draw diamond symbol.
Definition: gsd_objs.c:327
float x_trans
Definition: ogsf.h:375
#define ST_GYRO
Definition: ogsf.h:97
int gsd_checkpoint(float *, int *, int *, double *, double *)
float x_trans
Definition: ogsf.h:267
#define CM_COLOR
Definition: ogsf.h:145
void gsd_color_func(unsigned int)
Set current color.
Definition: gsd_prim.c:701
int gs_update_curmask(geosurf *)
Update current maps.
Definition: gs_bm.c:232
struct g_point * next
Definition: ogsf.h:361
#define MAP_ATT
Definition: ogsf.h:83
void gsd_translate(float, float, float)
Multiply the current matrix by a translation matrix.
Definition: gsd_prim.c:538
#define ST_X
Definition: ogsf.h:89
void gsd_x(geosurf *, float *, int, float)
Draw X symbol.
Definition: gsd_objs.c:278
float y_trans
Definition: ogsf.h:375
int gs_point_in_region(geosurf *gs, float *pt, float *region)
Check if point is in region.
Definition: gpd.c:39
void gsd_cube(float *, unsigned long, float)
Draw cube.
Definition: gsd_objs.c:429
#define Z
Definition: ogsf.h:139
void gsd_sphere(float *, float)
ADD.
Definition: gsd_prim.c:206
double oy
Definition: ogsf.h:264
int viewcell_tri_interp(geosurf *, typbuff *, Point3, int)
ADD.
Definition: gsdrape.c:507
float GS_global_exag(void)
Get global z-exag value.
Definition: gs2.c:1999
gsurf_att att[MAX_ATTS]
Definition: ogsf.h:261
Point3 p3
Definition: ogsf.h:355
void gsd_draw_asterisk(float *, unsigned long, float)
Draw asterisk.
Definition: gsd_objs.c:604
gvstyle * hstyle
Definition: ogsf.h:383
float y_trans
Definition: ogsf.h:267
typbuff * gs_get_att_typbuff(geosurf *, int, int)
Get attribute data buffer.
Definition: gs.c:681
#define Y
Definition: ogsf.h:138
void GS_v3eq(float *, float *)
Copy vector values.
Definition: gs_util.c:178
int gs_point_is_masked(geosurf *, float *)
Check if point is masked.
Definition: gs.c:1317
void gsd_linewidth(short)
Set width of rasterized lines.
Definition: gsd_prim.c:266
#define CHK_FREQ
Definition: gpd.c:22
void gsd_getwindow(int *, int *, double *, double *)
Get viewport.
Definition: gsd_prim.c:553
geopoint * points
Definition: ogsf.h:376
Definition: ogsf.h:204
#define ST_HISTOGRAM
Definition: ogsf.h:98
float z_trans
Definition: ogsf.h:375
int GS_check_cancel(void)
Check for cancel.
Definition: gsx.c:30
void gsd_draw_box(float *, unsigned long, float)
Draw box.
Definition: gsd_objs.c:506
void gpd_obj(geosurf *gs, gvstyle *style, Point3 pt)
Draw point representing object.
Definition: gpd.c:71
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition: gsd_prim.c:510
#define ST_SPHERE
Definition: ogsf.h:91
#define X
Definition: ogsf.h:137
void gsd_draw_gyro(float *, unsigned long, float)
Draw gyro.
Definition: gsd_objs.c:659
#define ST_ASTER
Definition: ogsf.h:96
int symbol
Definition: ogsf.h:289
#define ST_BOX
Definition: ogsf.h:90
float z_trans
Definition: ogsf.h:267
#define CONST_ATT
Definition: ogsf.h:84
void gsd_do_scale(int)
Set current scale.
Definition: gsd_views.c:355
void gsd_scale(float, float, float)
Multiply the current matrix by a general scaling matrix.
Definition: gsd_prim.c:524
Definition: ogsf.h:257
float constant
Definition: ogsf.h:251
gvstyle * style
Definition: ogsf.h:382
#define ST_CUBE
Definition: ogsf.h:92