GRASS Programmer's Manual  6.5.svn(2014)-r66266
 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  }
373  else {
374  buf = gs_get_att_typbuff(gs, ATT_TOPO, 0);
375  }
376 
377  /* Get viewport parameters for view check */
378  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
379 
380  gsd_pushmatrix();
381 
382  gsd_do_scale(1);
383 
384  gsd_translate(gs->x_trans, gs->y_trans, gs->z_trans);
385 
386  gsd_linewidth(gp->width);
387 
388  check = 0;
389  color = gp->color;
390  marker = gp->marker;
391  size = gp->size;
392 
393  for (gpt = gp->points; gpt; gpt = gpt->next) {
394  if (!(++check % CHK_FREQ)) {
395  if (GS_check_cancel()) {
396  gsd_linewidth(1);
397  gsd_popmatrix();
398 
399  return (0);
400  }
401  }
402 
403  site[X] = gpt->p3[X] + gp->x_trans - gs->ox;
404  site[Y] = gpt->p3[Y] + gp->y_trans - gs->oy;
405 
406  if (gs_point_is_masked(gs, site)) {
407  continue;
408  }
409 
410  /* TODO: set other dynamic attributes */
411  if (gp->attr_mode & ST_ATT_COLOR) {
412  color = gpt->iattr;
413  }
414 
415  if (src == MAP_ATT) {
416  if (viewcell_tri_interp(gs, buf, site, 1)) {
417  /* returns 0 if outside or masked */
418  site[Z] += gp->z_trans;
419 
420  if (gsd_checkpoint
421  (site, window, viewport, modelMatrix, projMatrix))
422  continue;
423  else
424  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(gs, color, size, marker, site); */
425  gpd_obj_site_attr(gs, gp, gpt, site);
426  }
427  }
428  else if (src == CONST_ATT) {
429  if (gs_point_in_region(gs, site, NULL)) {
430  site[Z] = konst + gp->z_trans;
431  if (gsd_checkpoint
432  (site, window, viewport, modelMatrix, projMatrix))
433  continue;
434  else
435  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(NULL, color, size, marker, site); */
436  gpd_obj_site_attr(NULL, gp, gpt, site);
437  }
438  }
439  }
440 
441  gsd_linewidth(1);
442  gsd_popmatrix();
443  }
444 
445  return (1);
446 }
447 
458 int gpd_3dsite(geosite * gp, float xo, float yo, int do_fast)
459 {
460  float site[3], tz;
461  float size;
462  int check, color, marker;
463  geopoint *gpt;
464  GLdouble modelMatrix[16], projMatrix[16];
465  GLint viewport[4];
466  GLint window[4];
467 
468  if (GS_check_cancel()) {
469  return (0);
470  }
471 
472  gsd_getwindow(window, viewport, modelMatrix, projMatrix);
473 
474  gsd_pushmatrix();
475 
476  gsd_do_scale(1);
477 
478  tz = GS_global_exag();
479  site[Z] = 0.0;
480 
481  check = 0;
482  color = gp->color;
483  marker = gp->marker;
484  size = gp->size;
485 
486  gsd_linewidth(gp->width);
487 
488  for (gpt = gp->points; gpt; gpt = gpt->next) {
489  if (!(++check % CHK_FREQ)) {
490  if (GS_check_cancel()) {
491  gsd_linewidth(1);
492  gsd_popmatrix();
493 
494  return (0);
495  }
496  }
497 
498  site[X] = gpt->p3[X] + gp->x_trans - xo;
499  site[Y] = gpt->p3[Y] + gp->y_trans - yo;
500 
501  if (tz) {
502  site[Z] = gpt->p3[Z] + gp->z_trans;
503  }
504 
505  /* TODO: set other dynamic attributes */
506  if (gp->attr_mode & ST_ATT_COLOR) {
507  color = gpt->iattr;
508  }
509 
510  if (gsd_checkpoint(site, window, viewport, modelMatrix, projMatrix))
511  continue;
512  else
513  /* clip points outside default region? */
514  /* ACS_MODIFY_OneLine site_attr management - was: gpd_obj(NULL, color, size, marker, site); */
515  gpd_obj_site_attr(NULL, gp, gpt, site);
516  }
517 
518  gsd_linewidth(1);
519  gsd_popmatrix();
520 
521  return (1);
522 }
int gpd_3dsite(geosite *gp, float xo, float yo, int do_fast)
ADD.
Definition: gpd.c:458
#define VCOL2X(gs, vcol)
Definition: rowcol.h:38
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:11
void gsd_sphere(float *center, float siz)
ADD.
Definition: gsd_prim.c:197
#define VCOLS(gs)
Definition: rowcol.h:12
void gsd_draw_box(float *center, unsigned long colr, float siz)
Draw box.
Definition: gsd_objs.c:507
void gpd_obj(geosurf *gs, int color, float size, int marker, Point3 pt)
ADD.
Definition: gpd.c:202
int gpd_2dsite(geosite *gp, geosurf *gs, int do_fast)
ADD.
Definition: gpd.c:349
#define Y(x)
Definition: display/draw.c:246
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
int GS_check_cancel(void)
Check for cancel.
Definition: GSX.c:31
#define X(y)
Definition: display/draw.c:248
void gsd_color_func(unsigned int col)
Set current color.
Definition: gsd_prim.c:689
int y
Definition: plot.c:34
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition: gsd_prim.c:526
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
void gsd_x(geosurf *gs, float *center, int colr, float siz)
ADD.
Definition: gsd_objs.c:279
#define VROW2Y(gs, vrow)
Definition: rowcol.h:37
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:430
void gsd_diamond(float *center, unsigned long colr, float siz)
Draw diamond symbol.
Definition: gsd_objs.c:328
typbuff * gs_get_att_typbuff(geosurf *gs, int desc, int to_write)
Get attribute data buffer.
Definition: gs.c:681
tuple color
Definition: tools.py:1703
tuple window
Definition: tools.py:543
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:167
int
Definition: g3dcolor.c:48
void gsd_draw_asterisk(float *center, unsigned long colr, float siz)
Draw asterisk.
Definition: gsd_objs.c:605
char buf[GNAME_MAX+sizeof(G3D_DIRECTORY)+2]
Definition: g3drange.c:62
return NULL
Definition: dbfopen.c:1394
#define CHK_FREQ
Definition: gpd.c:26
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 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
void gsd_draw_gyro(float *center, unsigned long colr, float siz)
Draw gyro.
Definition: gsd_objs.c:660
void gsd_scale(float xs, float ys, float zs)
Multiply the current matrix by a general scaling matrix.
Definition: gsd_prim.c:512
float GS_global_exag(void)
Get global z-exag value.
Definition: GS2.c:1996
int gpd_obj_site_attr(geosurf *gs, geosite *gp, geopoint *gpt, Point3 site)
Substitutes gpd_obj()
Definition: gpd.c:44
int gs_update_curmask(geosurf *surf)
Update current maps.
Definition: gs_bm.c:232