GRASS GIS 7 Programmer's Manual  7.0.4(2016)-r00000
gpd.c
Go to the documentation of this file.
1 
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 
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 
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:
82  gsd_colormode(CM_DIFFUSE);
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();
97  gsd_colormode(CM_COLOR);
98 
99  break;
100  case ST_DIAMOND:
101  /*
102  gsd_colormode(CM_AD);
103  */
104  gsd_colormode(CM_DIFFUSE);
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();
114  gsd_colormode(CM_COLOR);
115 
116  break;
117  case ST_BOX:
118  gsd_colormode(CM_COLOR);
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  */
134  gsd_colormode(CM_DIFFUSE);
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();
144  gsd_colormode(CM_COLOR);
145 
146  break;
147  case ST_GYRO:
148  gsd_colormode(CM_COLOR);
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:
161  gsd_colormode(CM_COLOR);
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:
174  gsd_colormode(CM_DIFFUSE);
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();
184  gsd_colormode(CM_COLOR);
185 
186  break;
187  default:
188  case ST_X:
189  gsd_colormode(CM_COLOR);
190  gsd_x(gs, lpt, style->color, style->size);
191 
192  break;
193  }
194 
195  return;
196 }
197 
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 
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 }
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast)
Draw 3D point set.
Definition: gpd.c:313
#define VCOL2X(gs, vcol)
Definition: rowcol.h:40
int GS_check_cancel(void)
Check for cancel.
Definition: gsx.c:31
int gs_point_is_masked(geosurf *gs, float *pt)
Check if point is masked.
Definition: gs.c:1317
void gsd_do_scale(int doexag)
Set current scale.
Definition: gsd_views.c:355
#define VROWS(gs)
Definition: rowcol.h:13
void gsd_sphere(float *center, float siz)
ADD.
Definition: gsd_prim.c:197
#define VCOLS(gs)
Definition: rowcol.h:14
void gsd_draw_box(float *center, unsigned long colr, float siz)
Draw box.
Definition: gsd_objs.c:506
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast)
Draw 2D point set.
Definition: gpd.c:216
int viewcell_tri_interp(geosurf *gs, typbuff *buf, Point3 pt, int check_mask)
ADD.
Definition: gsdrape.c:507
void gsd_colormode(int cm)
Set color mode.
Definition: gsd_prim.c:88
void gsd_color_func(unsigned int col)
Set current color.
Definition: gsd_prim.c:689
#define NULL
Definition: ccmath.h:32
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition: gsd_prim.c:526
#define Y(n)
Definition: plot.c:141
void gsd_x(geosurf *gs, float *center, int colr, float siz)
Draw X symbol.
Definition: gsd_objs.c:278
#define VROW2Y(gs, vrow)
Definition: rowcol.h:39
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition: gsd_prim.c:498
void gsd_cube(float *center, unsigned long colr, float siz)
Draw cube.
Definition: gsd_objs.c:429
void gsd_diamond(float *center, unsigned long colr, float siz)
Draw diamond symbol.
Definition: gsd_objs.c:327
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
Definition: gs.c:681
int gsd_checkpoint(float pt[4], int window[4], int viewport[4], double modelMatrix[16], double projMatrix[16])
ADD.
Definition: gsd_prim.c:573
void gsd_getwindow(int *window, int *viewport, double *modelMatrix, double *projMatrix)
Get viewport.
Definition: gsd_prim.c:541
int gs_point_in_region(geosurf *gs, float *pt, float *region)
Check if point is in region.
Definition: gpd.c:39
void gsd_draw_asterisk(float *center, unsigned long colr, float siz)
Draw asterisk.
Definition: gsd_objs.c:604
float GS_global_exag(void)
Get global z-exag value.
Definition: gs2.c:2000
#define CHK_FREQ
Definition: gpd.c:22
void GS_v3eq(float *v1, float *v2)
Copy vector values.
Definition: gs_util.c:178
int gs_get_att_src(geosurf *gs, int desc)
Get attribute source.
Definition: gs.c:656
void gsd_linewidth(short n)
Set width of rasterized lines.
Definition: gsd_prim.c:257
void gpd_obj(geosurf *gs, gvstyle *style, Point3 pt)
Draw point representing object.
Definition: gpd.c:71
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition: gsd_prim.c:488
void gsd_box(float *center, int colr, float *siz)
Draw box.
Definition: gsd_objs.c:1440
#define X(e)
Definition: plot.c:140
void gsd_draw_gyro(float *center, unsigned long colr, float siz)
Draw gyro.
Definition: gsd_objs.c:659
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
Definition: gsd_prim.c:512
int gs_update_curmask(geosurf *surf)
Update current maps.
Definition: gs_bm.c:232