GRASS Programmer's Manual  6.4.2(2012)
 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 */
40  for (i = 0; i < MAX_LIGHTS; i++) {
41  Nviz_new_light(data);
42  }
43 
44  /* fringe */
45  data->num_fringes = 0;
46  data->fringe = NULL;
47 
48  return;
49 }
50 
55 void Nviz_destroy_data(nv_data *data)
56 {
57  int i;
58  for (i = 0; data->num_fringes; i++) {
59  G_free(data->fringe[i]);
60  data->fringe[i] = NULL;
61  }
62  data->num_fringes = 0;
63  data->fringe = NULL;
64 }
65 
72 void Nviz_set_bgcolor(nv_data * data, int color)
73 {
74  data->bgcolor = color;
75 
76  return;
77 }
78 
86 int Nviz_get_bgcolor(nv_data * data)
87 {
88  return data->bgcolor;
89 }
90 
98 int Nviz_color_from_str(const char *color_str)
99 {
100  int red, grn, blu;
101 
102  if (G_str_to_color(color_str, &red, &grn, &blu) != 1) {
103  G_warning(_("Invalid color (%s), using \"white\" as default"),
104  color_str);
105  red = grn = blu = 255;
106  }
107 
108  return (red & RED_MASK) + ((int)((grn) << 8) & GRN_MASK) +
109  ((int)((blu) << 16) & BLU_MASK);
110 }
111 
123 struct fringe_data *Nviz_new_fringe(nv_data *data,
124  int id, unsigned long color,
125  double elev, int nw, int ne, int sw, int se)
126 {
127  int num;
128  int *surf;
129  struct fringe_data *f;
130 
131  if (!GS_surf_exists(id)) {
132  /* select first surface from the list */
133  surf = GS_get_surf_list(&num);
134  if (num < 1)
135  return NULL;
136  id = surf[0];
137  }
138 
139 
140  f = (struct fringe_data *) G_malloc(sizeof(struct fringe_data));
141  f->id = id;
142  f->color = color;
143  f->elev = elev;
144  f->where[0] = nw;
145  f->where[1] = ne;
146  f->where[2] = sw;
147  f->where[3] = se;
148 
149  data->fringe = (struct fringe_data **) G_realloc(data->fringe, data->num_fringes + 1 * sizeof(struct fringe_data *));
150  data->fringe[data->num_fringes++] = f;
151 
152  return f;
153 }
154 
166 struct fringe_data *Nviz_set_fringe(nv_data *data,
167  int id, unsigned long color,
168  double elev, int nw, int ne, int sw, int se)
169 {
170  int i, num;
171  int *surf;
172  struct fringe_data *f;
173 
174  if (!GS_surf_exists(id)) {
175  /* select first surface from the list */
176  surf = GS_get_surf_list(&num);
177  if (num < 1)
178  return NULL;
179  id = surf[0];
180  }
181 
182  for (i = 0; i < data->num_fringes; i++) {
183  f = data->fringe[i];
184  if (f->id == id) {
185  f->color = color;
186  f->elev = elev;
187  f->where[0] = nw;
188  f->where[1] = ne;
189  f->where[2] = sw;
190  f->where[3] = se;
191 
192  return f;
193  }
194  }
195 
196  f = Nviz_new_fringe(data,
197  id, color,
198  elev, nw, ne, sw, se);
199 
200  return f;
201 }