GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
nviz.c
Go to the documentation of this file.
1 
15 #include <grass/glocale.h>
16 #include <grass/nviz.h>
17 
23 void Nviz_init_data(nv_data * data)
24 {
25  unsigned int i;
26 
27  /* data range */
28  data->zrange = 0;
29  data->xyrange = 0;
30 
31  /* clip planes, turn off by default */
32  data->num_cplanes = 0;
33  data->cur_cplane = 0;
34  for (i = 0; i < MAX_CPLANES; i++) {
35  Nviz_new_cplane(data, i);
36  Nviz_off_cplane(data, i);
37  }
38 
39  /* lights */
41 
42  for (i = 0; i < MAX_LIGHTS - 1; i++) {
43  Nviz_new_light(data);
44  }
45 
46  /* fringe */
47  data->num_fringes = 0;
48  data->fringe = NULL;
49 
50  /* north arrow */
51  data->draw_arrow = 0;
52  data->arrow = NULL;
53 
54  /* scale bar*/
55  data->num_scalebars = 0;
56  data->scalebar = NULL;
57 
58  return;
59 }
60 
65 void Nviz_destroy_data(nv_data *data)
66 {
67  int i;
68  for (i = 0; data->num_fringes; i++) {
69  G_free(data->fringe[i]);
70  data->fringe[i] = NULL;
71  }
72  data->num_fringes = 0;
73  data->fringe = NULL;
74 
75  if (data->arrow) {
76  G_free(data->arrow);
77  data->arrow = NULL;
78  data->draw_arrow = 0;
79  }
80 
81  for (i = 0; data->num_scalebars; i++) {
82  G_free(data->scalebar[i]);
83  data->scalebar[i] = NULL;
84  }
85  data->num_scalebars = 0;
86  data->scalebar = NULL;
87 }
88 
95 void Nviz_set_bgcolor(nv_data * data, int color)
96 {
97  data->bgcolor = color;
98 
99  return;
100 }
101 
109 int Nviz_get_bgcolor(nv_data * data)
110 {
111  return data->bgcolor;
112 }
113 
121 int Nviz_color_from_str(const char *color_str)
122 {
123  int red, grn, blu;
124 
125  if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
126  G_warning(_("Invalid color (%s), using \"white\" as default"),
127  color_str);
128  red = grn = blu = 255;
129  }
130 
131  return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
132  ((int)((blu) << 16) & BLU_MASK);
133 }
134 
146 struct fringe_data *Nviz_new_fringe(nv_data *data,
147  int id, unsigned long color,
148  double elev, int nw, int ne, int sw, int se)
149 {
150  int num;
151  int *surf;
152  struct fringe_data *f;
153 
154  if (!GS_surf_exists(id)) {
155  /* select first surface from the list */
156  surf = GS_get_surf_list(&num);
157  if (num < 1)
158  return NULL;
159  id = surf[0];
160  G_free(surf);
161  }
162 
163 
164  f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data));
165  f->id = id;
166  f->color = color;
167  f->elev = elev;
168  f->where[0] = nw;
169  f->where[1] = ne;
170  f->where[2] = sw;
171  f->where[3] = se;
172 
173  data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *));
174  data->fringe[data->num_fringes++] = f;
175 
176  return f;
177 }
178 
190 struct fringe_data *Nviz_set_fringe(nv_data *data,
191  int id, unsigned long color,
192  double elev, int nw, int ne, int sw, int se)
193 {
194  int i, num;
195  int *surf;
196  struct fringe_data *f;
197 
198  if (!GS_surf_exists(id)) {
199  /* select first surface from the list */
200  surf = GS_get_surf_list(&num);
201  if (num < 1)
202  return NULL;
203  id = surf[0];
204  G_free(surf);
205  }
206 
207  for (i = 0; i < data->num_fringes; i++) {
208  f = data->fringe[i];
209  if (f->id == id) {
210  f->color = color;
211  f->elev = elev;
212  f->where[0] = nw;
213  f->where[1] = ne;
214  f->where[2] = sw;
215  f->where[3] = se;
216 
217  return f;
218  }
219  }
220 
221  f = Nviz_new_fringe(data,
222  id, color,
223  elev, nw, ne, sw, se);
224 
225  return f;
226 }
231 void Nviz_draw_fringe(nv_data *data)
232 {
233  int i;
234 
235  for (i = 0; i < data->num_fringes; i++) {
236  struct fringe_data *f = data->fringe[i];
237 
238  GS_draw_fringe(f->id, f->color, f->elev, f->where);
239  }
240 }
249 int Nviz_set_arrow(nv_data *data,
250  int sx, int sy, float size,
251  unsigned int color)
252 {
253  int id, pt[2];
254  int *surf_list, num_surfs;
255  float coords[3];
256  struct arrow_data *arw;
257 
258  if (GS_num_surfs() > 0) {
259  surf_list = GS_get_surf_list(&num_surfs);
260  id = surf_list[0];
261  G_free(surf_list);
262 
263  pt[0] = sx;
264  pt[1] = sy;
265 
266  GS_set_Narrow(pt, id, coords);
267 
268  if (data->arrow) {
269  data->arrow->color = color;
270  data->arrow->size = size;
271  data->arrow->where[0] = coords[0];
272  data->arrow->where[1] = coords[1];
273  data->arrow->where[2] = coords[2];
274  }
275  else {
276  arw = (struct arrow_data *) G_malloc(sizeof(struct arrow_data));
277  arw->color = color;
278  arw->size = size;
279  arw->where[0] = coords[0];
280  arw->where[1] = coords[1];
281  arw->where[2] = coords[2];
282 
283  data->arrow = arw;
284  }
285  return 1;
286  }
287  return 0;
288 }
289 
290 
296 int Nviz_draw_arrow(nv_data *data)
297 {
298 
299  struct arrow_data *arw = data->arrow;
300  GLuint FontBase = 0; /* don't know how to get fontbase*/
301 
302  data->draw_arrow = 1;
303  gsd_north_arrow(arw->where, arw->size, FontBase, arw->color, arw->color);
304 
305  return 1;
306 }
307 
313 void Nviz_delete_arrow(nv_data *data)
314 {
315  data->draw_arrow = 0;
316 
317  return;
318 }
319 
332 struct scalebar_data *Nviz_new_scalebar(nv_data *data,
333  int bar_id, float *coords, float size,
334  unsigned int color)
335 {
336  struct scalebar_data *s;
337 
338 
339  s = (struct scalebar_data *) G_malloc(sizeof(struct scalebar_data));
340  s->id = bar_id;
341  s->color = color;
342  s->size = size;
343  s->where[0] = coords[0];
344  s->where[1] = coords[1];
345  s->where[2] = coords[2];
346 
347  data->scalebar = (struct scalebar_data **) G_realloc(data->scalebar,
348  data->num_scalebars + 1 * sizeof(struct scalebar_data *));
349  data->scalebar[data->num_scalebars++] = s;
350 
351  return s;
352 
353 }
366 struct scalebar_data *Nviz_set_scalebar(nv_data *data, int bar_id,
367  int sx, int sy, float size,
368  unsigned int color)
369 {
370  int i, id, pt[2];
371  int *surf_list, num_surfs;
372  float coords[3];
373  struct scalebar_data *s;
374 
375  if (GS_num_surfs() > 0) {
376  surf_list = GS_get_surf_list(&num_surfs);
377  id = surf_list[0];
378  G_free(surf_list);
379 
380  pt[0] = sx;
381  pt[1] = sy;
382 
383  GS_set_Narrow(pt, id, coords); /* the same like arrow */
384 
385  for (i = 0; i < data->num_scalebars; i++) {
386  s = data->scalebar[i];
387  if (s->id == bar_id) {
388  s->color = color;
389  s->size = size;
390  s->where[0] = coords[0];
391  s->where[1] = coords[1];
392  s->where[2] = coords[2];
393 
394  return s;
395  }
396  }
397 
398  s = Nviz_new_scalebar(data, bar_id, coords, size, color);
399 
400  return s;
401  }
402  return NULL;
403 }
409 void Nviz_draw_scalebar(nv_data *data)
410 {
411  int i;
412 
413  GLuint FontBase = 0; /* don't know how to get fontbase*/
414 
415  for (i = 0; i < data->num_scalebars; i++) {
416  struct scalebar_data *s = data->scalebar[i];
417 
418  gsd_scalebar_v2(s->where, s->size, FontBase, s->color, s->color);
419  }
420 }
421 
427 void Nviz_delete_scalebar(nv_data *data, int bar_id)
428 {
429  if (bar_id < data->num_scalebars) {
430  G_free(data->scalebar[bar_id]);
431  data->scalebar[bar_id] = NULL;
432  data->num_scalebars--;
433  }
434 }
void G_free(void *buf)
Free allocated memory.
Definition: gis/alloc.c:142
int Nviz_color_from_str(const char *color_str)
Get color value from color string (name or RGB triplet)
Definition: nviz.c:121
#define RED_MASK
Definition: gsd_prim.c:38
void Nviz_delete_arrow(nv_data *data)
Deletes the North Arrow.
Definition: nviz.c:313
int GS_surf_exists(int id)
Definition: GS2.c:194
long num
Definition: g3dcats.c:93
#define BLU_MASK
Definition: gsd_prim.c:40
#define GRN_MASK
Definition: gsd_prim.c:39
int gsd_north_arrow(float *pos2, float len, GLuint fontbase, unsigned long arw_clr, unsigned long text_clr)
Draw North Arrow takes OpenGL coords and size.
Definition: gsd_objs.c:826
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
void Nviz_init_data(nv_data *data)
Initialize Nviz data.
Definition: nviz.c:23
void GS_draw_fringe(int id, unsigned long clr, float elev, int *where)
Draw fringe around data (surface) at selected corners.
Definition: GS2.c:820
int Nviz_get_bgcolor(nv_data *data)
Get background color.
Definition: nviz.c:109
tuple data
void GS_set_Narrow(int *pt, int id, float *pos2)
Set decoration, north arrow ??
Definition: GS2.c:568
tuple id
self.OnVectorSurface(event)
Definition: tools.py:3426
int Nviz_off_cplane(nv_data *data, int id)
Turn off (make inactive) the given clip plane.
Definition: cplanes_obj.c:60
tuple color
Definition: tools.py:1703
void Nviz_draw_scalebar(nv_data *data)
Draws the Scale bar.
Definition: nviz.c:409
void GS_set_light_reset(int i)
Definition: GS2.c:252
int
Definition: g3dcolor.c:48
struct fringe_data * Nviz_new_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se)
Definition: nviz.c:146
struct scalebar_data * Nviz_new_scalebar(nv_data *data, int bar_id, float *coords, float size, unsigned int color)
Definition: nviz.c:332
int GS_num_surfs(void)
Get number of surfaces.
Definition: GS2.c:1521
return NULL
Definition: dbfopen.c:1394
G_warning("category support for [%s] in mapset [%s] %s", name, mapset, type)
void Nviz_destroy_data(nv_data *data)
Free allocated space by nv_data struct.
Definition: nviz.c:65
int Nviz_draw_arrow(nv_data *data)
Draws the North Arrow.
Definition: nviz.c:296
int Nviz_new_cplane(nv_data *data, int id)
Creates a clip plane object.
Definition: cplanes_obj.c:27
struct fringe_data * Nviz_set_fringe(nv_data *data, int id, unsigned long color, double elev, int nw, int ne, int sw, int se)
Definition: nviz.c:190
int * GS_get_surf_list(int *numsurfs)
Get surface list.
Definition: GS2.c:1536
void Nviz_set_bgcolor(nv_data *data, int color)
Set background color.
Definition: nviz.c:95
int G_str_to_color(const char *str, int *red, int *grn, int *blu)
Parse color string and set red,green,blue.
Definition: color_str.c:112
int gsd_scalebar_v2(float *pos, float len, GLuint fontbase, unsigned long bar_clr, unsigned long text_clr)
Draw Scalebar (as lines)
Definition: gsd_objs.c:1248
void Nviz_draw_fringe(nv_data *data)
Definition: nviz.c:231
void Nviz_delete_scalebar(nv_data *data, int bar_id)
Deletes scale bar.
Definition: nviz.c:427
int Nviz_new_light(nv_data *data)
Define new light.
Definition: lights.c:164
struct scalebar_data * Nviz_set_scalebar(nv_data *data, int bar_id, int sx, int sy, float size, unsigned int color)
Sets the scale bar position and return world coords.
Definition: nviz.c:366
int Nviz_set_arrow(nv_data *data, int sx, int sy, float size, unsigned int color)
Sets the North Arrow position and return world coords.
Definition: nviz.c:249