GRASS Programmer's Manual  6.4.2(2012)
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gpd.c
Go to the documentation of this file.
1 
19 #include <stdlib.h>
20 #include <math.h>
21 
22 #include <grass/gstypes.h>
23 
24 #include "rowcol.h"
25 
26 #define CHK_FREQ 50
27 
28 /* BOB -- border allowed outside of viewport */
29 #define v_border 50
30 
31 /* ACS_MODIFY_BEGIN site_attr management ************************************** */
32 static float _cur_size_;
33 
44 int gpd_obj_site_attr(geosurf * gs, geosite * gp, geopoint * gpt, Point3 site)
45 {
46  float size, z, y, x, z_scale, z_offset;
47  int marker, color, i, ii, iii;
48  int use_attr, has_drawn;
49  int _put_aside_;
50 
51  _put_aside_ = 0;
52  _cur_size_ = gp->size;
53 
54  z_scale = GS_global_exag();
55  z_offset = 0.0;
56 
57  has_drawn = 0;
58 
59  for (i = 0; i < GPT_MAX_ATTR; i++) {
60  color = gp->color;
61  marker = gp->marker;
62  size = gp->size;
63  use_attr = 0;
64 
65  if (gp->use_attr[i] & ST_ATT_COLOR) {
66  use_attr = 1;
67  color = gpt->color[i];
68  }
69 
70  if (gp->use_attr[i] & ST_ATT_MARKER) {
71  use_attr = 1;
72  marker = gpt->marker[i];
73  }
74 
75  if (gp->use_attr[i] & ST_ATT_SIZE) {
76  use_attr = 1;
77  size = gpt->size[i] * gp->size;
78  if (gp->marker == ST_HISTOGRAM)
79  _put_aside_ = 1;
80  }
81 
82  /* ACS_MODIFY_BEGIN site_highlight management ********************************* */
83  if (gpt->highlight_color)
84  color = gpt->highlight_color_value;
85  if (gpt->highlight_marker)
86  marker = gpt->highlight_marker_value;
87  if (gpt->highlight_size)
88  size *= gpt->highlight_size_value;
89  /* ACS_MODIFY_END site_highlight management *********************************** */
90 
91  if (_put_aside_) {
92  if (use_attr == 1) {
93  has_drawn = 1;
94 
95 /*******************************************************************************
96  fixed size = gp->size
97  this is mailny intended for "histograms" that grow in z, but not in xy
98 
99  square filling to right and then up
100 
101  15 14 13 12
102  8 7 6 11
103  3 2 5 10
104  0 1 4 9
105 
106 *******************************************************************************/
107  x = site[X];
108  y = site[Y];
109 
110  ii = (int)(sqrt(i));
111  iii = ii * ii + ii;
112 
113  if (i <= iii) {
114  site[X] += ii * 2.2 * gp->size;
115  site[Y] += (i - ii) * 2.2 * gp->size;
116  }
117  else {
118  site[X] += (ii - (i - iii)) * 2.2 * gp->size;
119  site[Y] += ii * 2.2 * gp->size;
120 
121  }
122 
123  gpd_obj(gs, color, size, marker, site);
124 
125  site[X] = x;
126  site[Y] = y;
127  }
128  }
129  else {
130  if (i > 0)
131  z_offset += size;
132  if (use_attr == 1) {
133  has_drawn = 1;
134 
135  z = site[Z];
136  site[Z] += z_offset / z_scale;
137 
138  gpd_obj(gs, color, size, marker, site);
139 
140  site[Z] = z;
141  }
142 
143  z_offset += size;
144  }
145  }
146 
147  if (has_drawn == 0)
148  gpd_obj(gs, color, size, marker, site);
149 
150  return (0);
151 }
152 
153 /* ACS_MODIFY_END site_attr management **************************************** */
154 
167 int gs_point_in_region(geosurf * gs, float *pt, float *region)
168 {
169  float top, bottom, left, right;
170 
171  if (!region) {
172  top = gs->yrange;
173  bottom = VROW2Y(gs, VROWS(gs));
174  left = 0.0;
175  right = VCOL2X(gs, VCOLS(gs));
176  }
177  else {
178  top = region[0];
179  bottom = region[1];
180  left = region[2];
181  right = region[3];
182  }
183 
184  return (pt[X] >= left && pt[X] <= right &&
185  pt[Y] >= bottom && pt[Y] <= top);
186 }
187 
202 void gpd_obj(geosurf * gs, int color, float size, int marker, Point3 pt)
203 {
204  float sz, lpt[3];
205  float siz[3];
206 
207  gsd_color_func(color);
208  sz = GS_global_exag();
209  GS_v3eq(lpt, pt); /* CHANGING Z OF POINT PASSED, so use copy */
210 
211  switch (marker) {
212  /* ACS_MODIFY_BEGIN site_attr management ************************************** */
213  case ST_HISTOGRAM:
214  gsd_colormode(CM_DIFFUSE);
215  gsd_pushmatrix();
216 
217  if (sz) {
218  lpt[Z] *= sz;
219  gsd_scale(1.0, 1.0, 1. / sz);
220  }
221 
222  siz[0] = _cur_size_;
223  siz[1] = _cur_size_;
224  siz[2] = size;
225 
226  gsd_box(lpt, color, siz);
227 
228  gsd_popmatrix();
229  gsd_colormode(CM_COLOR);
230 
231  break;
232  /* ACS_MODIFY_END site_attr management ************************************** */
233  case ST_DIAMOND:
234  /*
235  gsd_colormode(CM_AD);
236  */
237  gsd_colormode(CM_DIFFUSE);
238  gsd_pushmatrix();
239 
240  if (sz) {
241  lpt[Z] *= sz;
242  gsd_scale(1.0, 1.0, 1. / sz);
243  }
244 
245  gsd_diamond(lpt, color, size);
246  gsd_popmatrix();
247  gsd_colormode(CM_COLOR);
248 
249  break;
250  case ST_BOX:
251  gsd_colormode(CM_COLOR);
252  gsd_pushmatrix();
253 
254  if (sz) {
255  lpt[Z] *= sz;
256  gsd_scale(1.0, 1.0, 1. / sz);
257  }
258 
259  gsd_draw_box(lpt, color, size);
260  gsd_popmatrix();
261 
262  break;
263  case ST_SPHERE:
264  /*
265  gsd_colormode(CM_AD);
266  */
267  gsd_colormode(CM_DIFFUSE);
268  gsd_pushmatrix();
269 
270  if (sz) {
271  lpt[Z] *= sz;
272  gsd_scale(1.0, 1.0, 1. / sz);
273  }
274 
275  gsd_sphere(lpt, size);
276  gsd_popmatrix();
277  gsd_colormode(CM_COLOR);
278 
279  break;
280  case ST_GYRO:
281  gsd_colormode(CM_COLOR);
282  gsd_pushmatrix();
283 
284  if (sz) {
285  lpt[Z] *= sz;
286  gsd_scale(1.0, 1.0, 1. / sz);
287  }
288 
289  gsd_draw_gyro(lpt, color, size);
290  gsd_popmatrix();
291 
292  break;
293  case ST_ASTER:
294  gsd_colormode(CM_COLOR);
295  gsd_pushmatrix();
296 
297  if (sz) {
298  lpt[Z] *= sz;
299  gsd_scale(1.0, 1.0, 1. / sz);
300  }
301 
302  gsd_draw_asterisk(lpt, color, size);
303  gsd_popmatrix();
304 
305  break;
306  case ST_CUBE:
307  gsd_colormode(CM_DIFFUSE);
308  gsd_pushmatrix();
309 
310  if (sz) {
311  lpt[Z] *= sz;
312  gsd_scale(1.0, 1.0, 1. / sz);
313  }
314 
315  gsd_cube(lpt, color, size);
316  gsd_popmatrix();
317  gsd_colormode(CM_COLOR);
318 
319  break;
320  default:
321  case ST_X:
322  gsd_colormode(CM_COLOR);
323  gsd_x(gs, lpt, color, size);
324 
325  break;
326  }
327 
328  return;
329 }
330 
349 int gpd_2dsite(geosite * gp, geosurf * gs, int do_fast)
350 {
351  float site[3], konst;
352  float size;
353  int src, check, marker, color;
354  geopoint *gpt;
355  typbuff *buf;
356  GLdouble modelMatrix[16], projMatrix[16];
357  GLint viewport[4];
358  GLint window[4];
359 
360 
361  if (GS_check_cancel()) {
362  return (0);
363  }
364 
365  if (gs) {
366  gs_update_curmask(gs);
367 
368  src = gs_get_att_src(gs, ATT_TOPO);
369 
370  if (src == CONST_ATT) {
371  konst = gs->att[ATT_TOPO].constant;
372  site[Z] = konst;
373  }
374  else {
375  buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
376  }
377 
378  /* Get viewport parameters for view check */
379  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
380 
381  gsd_pushmatrix();
382 
383  gsd_do_scale(1);
384 
385  gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
386 
387  gsd_linewidth(gp->width);
388 
389  check = 0;
390  color = gp->color;
391  marker = gp->marker;
392  size = gp->size;
393 
394  for (gpt = gp->points; gpt; gpt = gpt->next) {
395  if (!(++check % CHK_FREQ)) {
396  if (GS_check_cancel()) {
397  gsd_linewidth(1);
398  gsd_popmatrix();
399 
400  return (0);
401  }
402  }
403 
404  site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
405  site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
406 
407  if (gs_point_is_masked(gs, site)) {
408  continue;
409  }
410 
411  /* TODO: set other dynamic attributes */
412  if (gp->attr_mode & ST_ATT_COLOR) {
413  color = gpt->iattr;
414  }
415 
416  if (src == MAP_ATT) {
417  if (viewcell_tri_interp(gs, buf, site, 1)) {
418  /* returns 0 if outside or masked */
419  site[Z] += gp->z_trans;
420 
421  if (gsd_checkpoint
422  (site, window, viewport, modelMatrix, projMatrix))
423  continue;
424  else
425  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(gs, color, size, marker, site); */
426  gpd_obj_site_attr(gs, gp, gpt, site);
427  }
428  }
429  else if (src == CONST_ATT) {
430  if (gs_point_in_region(gs, site, NULL)) {
431  site[Z] += gp->z_trans;
432  if (gsd_checkpoint
433  (site, window, viewport, modelMatrix, projMatrix))
434  continue;
435  else
436  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(NULL, color, size, marker, site); */
437  gpd_obj_site_attr(NULL, gp, gpt, site);
438  }
439  }
440  }
441 
442  gsd_linewidth(1);
443  gsd_popmatrix();
444  }
445 
446  return (1);
447 }
448 
459 int gpd_3dsite(geosite * gp, float xo, float yo, int do_fast)
460 {
461  float site[3], tz;
462  float size;
463  int check, color, marker;
464  geopoint *gpt;
465  GLdouble modelMatrix[16], projMatrix[16];
466  GLint viewport[4];
467  GLint window[4];
468 
469  if (GS_check_cancel()) {
470  return (0);
471  }
472 
473  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
474 
475  gsd_pushmatrix();
476 
477  gsd_do_scale(1);
478 
479  tz = GS_global_exag();
480  site[Z] = 0.0;
481 
482  check = 0;
483  color = gp->color;
484  marker = gp->marker;
485  size = gp->size;
486 
487  gsd_linewidth(gp->width);
488 
489  for (gpt = gp->points; gpt; gpt = gpt->next) {
490  if (!(++check % CHK_FREQ)) {
491  if (GS_check_cancel()) {
492  gsd_linewidth(1);
493  gsd_popmatrix();
494 
495  return (0);
496  }
497  }
498 
499  site[X] = gpt->p3[X] + gp->x_trans - xo;
500  site[Y] = gpt->p3[Y] + gp->y_trans - yo;
501 
502  if (tz) {
503  site[Z] = gpt->p3[Z] + gp->z_trans;
504  }
505 
506  /* TODO: set other dynamic attributes */
507  if (gp->attr_mode & ST_ATT_COLOR) {
508  color = gpt->iattr;
509  }
510 
511  if (gsd_checkpoint(site, window, viewport, modelMatrix, projMatrix))
512  continue;
513  else
514  /* clip points outside default region? */
515  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(NULL, color, size, marker, site); */
516  gpd_obj_site_attr(NULL, gp, gpt, site);
517  }
518 
519  gsd_linewidth(1);
520  gsd_popmatrix();
521 
522  return (1);
523 }