GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
cplanes_obj.c
Go to the documentation of this file.
1 
15 #include <grass/nviz.h>
16 
17 static void cp_draw(nv_data *, int, int, int);
18 static geoview Gv;
19 
27 int Nviz_new_cplane(nv_data * data, int id)
28 {
29  data->num_cplanes++;
30  /* Initialize internal attributes for this cutplane */
31  data->cp_rot[id][X] = data->cp_rot[id][Y] = data->cp_rot[id][Z] = 0.0;
32  data->cp_trans[id][X] = data->cp_trans[id][Y] = data->cp_trans[id][Z] =
33  0.0;
34  data->cp_on[id] = 0;
35 
36  return 1;
37 }
38 
45 int Nviz_on_cplane(nv_data * data, int id)
46 {
47  data->cur_cplane = id;
48  data->cp_on[id] = 1;
49  GS_set_cplane(id);
50 
51  return 1;
52 }
53 
60 int Nviz_off_cplane(nv_data * data, int id)
61 {
62  data->cp_on[id] = 0;
63  GS_unset_cplane(id);
64 
65  return 1;
66 }
67 
74 int Nviz_draw_cplane(nv_data * data, int bound1, int bound2)
75 {
76  cp_draw(data, data->cur_cplane, bound1, bound2);
77 
78  return 1;
79 }
80 
89 void cp_draw(nv_data * data, int current, int surf1, int surf2)
90 {
91  int i, nsurfs;
92  int surf_min = 0, surf_max = 0, temp;
93  int *surf_list;
94 
95  GS_set_draw(GSD_BACK);
96  GS_clear(data->bgcolor);
97  GS_ready_draw();
98 
99  /* If surf boundaries present then find them */
100  surf_list = GS_get_surf_list(&nsurfs);
101  if ((surf1 != -1) && (surf2 != -1)) {
102  for (i = 0; i < nsurfs; i++) {
103  if (surf_list[i] == surf1)
104  surf_min = i;
105  if (surf_list[i] == surf2)
106  surf_max = i;
107  }
108 
109  if (surf_max < surf_min) {
110  temp = surf_min;
111  surf_min = surf_max;
112  surf_max = temp;
113  }
114 
115  surf_max++;
116  }
117  else {
118  surf_min = 0;
119  surf_max = nsurfs;
120  }
121 
122  if (nsurfs > 1) {
123  for (i = 0; i < MAX_CPLANES; i++) {
124  if (data->cp_on[i])
125  GS_draw_cplane_fence(surf_list[0], surf_list[1], i);
126  }
127  }
128 
129  for (i = surf_min; i < surf_max; i++) {
130  GS_draw_wire(surf_list[i]);
131  }
132 
133  GS_done_draw();
134 
135  return;
136 }
142 int Nviz_num_cplanes(nv_data * data)
143 {
144  return data->num_cplanes;
145 }
146 
152 int Nviz_get_current_cplane(nv_data * data)
153 {
154  return data->cur_cplane;
155 }
156 
167 int Nviz_set_cplane_rotation(nv_data * data, int id, float dx, float dy, float dz)
168 {
169  data->cp_rot[id][X] = dx;
170  data->cp_rot[id][Y] = dy;
171  data->cp_rot[id][Z] = dz;
172  GS_set_cplane_rot(id, data->cp_rot[id][X], data->cp_rot[id][Y],
173  data->cp_rot[id][Z]);
174 
175  cp_draw(data, data->cur_cplane, -1, -1);
176 
177  return 1;
178 }
189 int Nviz_get_cplane_rotation(nv_data * data, int id, float *dx, float *dy, float *dz)
190 {
191  *dx = data->cp_rot[id][X];
192  *dy = data->cp_rot[id][Y];
193  *dz = data->cp_rot[id][Z];
194 
195  return 1;
196 }
197 
207 int Nviz_set_cplane_translation(nv_data * data, int id, float dx, float dy, float dz)
208 {
209  data->cp_trans[id][X] = dx;
210  data->cp_trans[id][Y] = dy;
211  data->cp_trans[id][Z] = dz;
212  GS_set_cplane_trans(id, data->cp_trans[id][X], data->cp_trans[id][Y],
213  data->cp_trans[id][Z]);
214 
215  cp_draw(data, data->cur_cplane, -1, -1);
216 
217  return 1;
218 }
226 int Nviz_get_cplane_translation(nv_data * data, int id, float *dx, float *dy, float *dz)
227 {
228  *dx = data->cp_trans[id][X];
229  *dy = data->cp_trans[id][Y];
230  *dz = data->cp_trans[id][Z];
231 
232  return 1;
233 }
239 int Nviz_set_fence_color(nv_data * data, int type)
240 {
241  GS_set_fencecolor(type);
242 
243  return 1;
244 
245 }
246 int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
247 {
248  float x, y, z, len, los[2][3];
249  float dx, dy, dz;
250  float n, s, w, e;
251  Point3 realto, dir;
252  int id;
253  geosurf *gs;
254 
255  if (GS_get_selected_point_on_surface(sx, sy, &id, &x, &y, &z)) {
256  gs = gs_get_surf(id);
257  if (gs) {
258  realto[X] = x - gs->ox + gs->x_trans;
259  realto[Y] = y - gs->oy + gs->y_trans;
260  realto[Z] = z + gs->z_trans;
261  }
262  else
263  return 0;
264  }
265  else {
266  if (gsd_get_los(los, (short)sx, (short)sy)) {
267  len = GS_distance(Gv.from_to[FROM], Gv.real_to);
268  GS_v3dir(los[FROM], los[TO], dir);
269  GS_v3mult(dir, len);
270  realto[X] = Gv.from_to[FROM][X] + dir[X];
271  realto[Y] = Gv.from_to[FROM][Y] + dir[Y];
272  realto[Z] = Gv.from_to[FROM][Z] + dir[Z];
273  }
274  else
275  return 0;
276  }
277  Nviz_get_cplane_translation(data, cplane, &dx, &dy, &dz);
278 
279  GS_get_region(&n, &s, &w, &e);
280  dx = realto[X] - (e - w) / 2.;
281  dy = realto[Y] - (n - s) / 2.;
282 
283  Nviz_set_cplane_translation(data, cplane, dx, dy, dz);
284 
285  return 1;
286 }
int GS_get_selected_point_on_surface(int sx, int sy, int *id, float *x, float *y, float *z)
Get selected point of surface.
Definition: GS2.c:3052
int Nviz_draw_cplane(nv_data *data, int bound1, int bound2)
Draw the clip plane.
Definition: cplanes_obj.c:74
void GS_done_draw(void)
Draw done, swap buffers.
Definition: GS2.c:2499
int Nviz_set_fence_color(nv_data *data, int type)
Set appropriate fence color.
Definition: cplanes_obj.c:239
#define Y(x)
Definition: display/draw.c:246
int GS_v3dir(float *v1, float *v2, float *v3)
Get a normalized direction from v1 to v2, store in v3.
Definition: GS_util.c:353
#define X(y)
Definition: display/draw.c:248
int y
Definition: plot.c:34
int Nviz_set_cplane_rotation(nv_data *data, int id, float dx, float dy, float dz)
Set the rotation for the current clip plane.
Definition: cplanes_obj.c:167
int GS_get_region(float *n, float *s, float *w, float *e)
Get 2D region extent.
Definition: GS2.c:156
void GS_clear(int col)
Clear view.
Definition: GS2.c:3416
int Nviz_get_cplane_rotation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the rotation values for the current clip plane.
Definition: cplanes_obj.c:189
int GS_draw_cplane_fence(int hs1, int hs2, int num)
Draw cplace fence ?
Definition: GS2.c:3173
void GS_set_cplane_trans(int num, float dx, float dy, float dz)
Set cplace trans.
Definition: GS2.c:3133
void GS_set_cplane_rot(int num, float dx, float dy, float dz)
Set cplace rotation.
Definition: GS2.c:3120
void GS_set_fencecolor(int mode)
Set fence color.
Definition: GS2.c:3254
tuple data
void GS_v3mult(float *v1, float k)
Multiple vectors.
Definition: GS_util.c:229
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
void GS_unset_cplane(int num)
Unset clip place (turn off)
Definition: GS2.c:3225
int Nviz_set_cplane_translation(nv_data *data, int id, float dx, float dy, float dz)
Set the translation for the current clip plane.
Definition: cplanes_obj.c:207
int Nviz_get_current_cplane(nv_data *data)
Get the current active cutplane.
Definition: cplanes_obj.c:152
void GS_set_cplane(int num)
Set cplace.
Definition: GS2.c:3213
int Nviz_on_cplane(nv_data *data, int id)
Turn on (make current) the given clip plane.
Definition: cplanes_obj.c:45
int Nviz_num_cplanes(nv_data *data)
Return the number of clip planes objects currently allocated.
Definition: cplanes_obj.c:142
geosurf * gs_get_surf(int id)
Get geosurf struct.
Definition: gs.c:62
int Nviz_set_cplane_here(nv_data *data, int cplane, float sx, float sy)
Definition: cplanes_obj.c:246
int Nviz_new_cplane(nv_data *data, int id)
Creates a clip plane object.
Definition: cplanes_obj.c:27
int * GS_get_surf_list(int *numsurfs)
Get surface list.
Definition: GS2.c:1536
float GS_distance(float *from, float *to)
Calculate distance.
Definition: GS_util.c:141
#define FROM
Definition: y.tab.c:161
void GS_ready_draw(void)
Definition: GS2.c:2486
int Nviz_get_cplane_translation(nv_data *data, int id, float *dx, float *dy, float *dz)
Get the translation values for the current clip plane.
Definition: cplanes_obj.c:226
void GS_draw_wire(int id)
Draw surface wire.
Definition: GS2.c:1896
int n
Definition: dataquad.c:291
int gsd_get_los(float(*vect)[3], short sx, short sy)
ADD.
Definition: gsd_views.c:40
void GS_set_draw(int where)
Sets which buffer to draw to.
Definition: GS2.c:2457