GRASS Programmer's Manual  6.5.svn(2014)-r66266
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
gsd_cplane.c
Go to the documentation of this file.
1 
19 #include <grass/gstypes.h>
20 #include "rowcol.h"
21 
22 static void init_cplane(void);
23 
24 static float Cp_pt[4], Cp_norm[MAX_CPLANES][4];
25 static float Cp_trans[MAX_CPLANES][3], Cp_rot[MAX_CPLANES][3];
26 static int Cp_ison[MAX_CPLANES]; /* also need isdef? */
27 
28 static void init_cplane(void)
29 {
30  int i;
31 
32  gs_get_datacenter(Cp_pt);
33  gs_get_data_avg_zmax(&(Cp_pt[Z]));
34 
35  for (i = 0; i < MAX_CPLANES; i++) {
36  Cp_ison[i] = 0;
37  Cp_norm[i][X] = 1.0;
38  Cp_norm[i][Y] = Cp_norm[i][Z] = 0.0;
39  Cp_norm[i][W] = 1.;
40  Cp_rot[i][X] = Cp_trans[i][X] = 0.0;
41  Cp_rot[i][Y] = Cp_trans[i][Y] = 0.0;
42  Cp_rot[i][Z] = Cp_trans[i][Z] = 0.0;
43  }
44 
45  return;
46 }
47 
55 void gsd_def_cplane(int num, float *pt, float *norm)
56 {
57  float sx, sy, sz, ppt[3];
58  double params[4];
59  float zmin, zmax;
60 
61  GS_get_scale(&sx, &sy, &sz, 1);
62 
63  /* Something's still wrong with the zexag - DONT USE TILT */
64  GS_get_zrange(&zmin, &zmax, 0);
65 
66  ppt[0] = (pt[0] + Cp_pt[0]) * sx;
67  ppt[1] = (pt[1] + Cp_pt[1]) * sy;
68  ppt[2] = (pt[2] + Cp_pt[2] - zmin) * sz;
69 
70  params[0] = norm[0] * sx;
71  params[1] = norm[1] * sy;
72  params[2] = norm[2] * sz;
73  GS_dv3norm(params);
74  params[3] = -ppt[0] * params[0] - ppt[1] * params[1] - ppt[2] * params[2];
75 
76  gsd_def_clipplane(num, params);
77 
78  return;
79 }
80 
87 {
88  int i;
89 
90  for (i = 0; i < MAX_CPLANES; i++) {
91  if (Cp_ison[i]) {
92  gsd_def_cplane(i, Cp_trans[i], Cp_norm[i]);
93  }
94  }
95 
96  return;
97 }
98 
105 {
106  static int first = 1;
107 
108  if (first) {
109  first = 0;
110  init_cplane();
111  gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
112  }
113 
114  gsd_set_clipplane(num, 1);
115 
116  Cp_ison[num] = 1;
117 
118  return;
119 }
120 
127 {
128 
129  gsd_set_clipplane(num, 0);
130  Cp_ison[num] = 0;
131 
132  return;
133 }
134 
142 void gsd_get_cplanes_state(int *onstate)
143 {
144  int i;
145 
146  for (i = 0; i < MAX_CPLANES; i++) {
147  onstate[i] = Cp_ison[i];
148  }
149 
150  return;
151 }
152 
162 int gsd_get_cplanes(Point4 * planes)
163 {
164  int i, ons;
165  Point3 thru;
166 
167  for (ons = i = 0; i < MAX_CPLANES; i++) {
168  if (Cp_ison[i]) {
169  thru[X] = Cp_pt[X] + Cp_trans[ons][X];
170  thru[Y] = Cp_pt[Y] + Cp_trans[ons][Y];
171  thru[Z] = Cp_pt[Z] + Cp_trans[ons][Z];
172  planes[ons][X] = -Cp_norm[ons][X];
173  planes[ons][Y] = -Cp_norm[ons][Y];
174  planes[ons][Z] = -Cp_norm[ons][Z];
175  planes[ons][W] = -(DOT3(planes[ons], thru));
176  ons++;
177  }
178  }
179 
180  return (ons);
181 }
182 
189 {
190  float v[1][4];
191 
192  v[0][X] = v[0][W] = 1.0;
193  v[0][Y] = v[0][Z] = 0.0;
194 
195  P_pushmatrix();
196  P_rot(Cp_rot[num][Z], 'z');
197  P_rot(Cp_rot[num][Y], 'y');
198  P_rot(Cp_rot[num][X], 'x');
199  P_transform(1, v, &Cp_norm[num]);
200  P_popmatrix();
201 
202  return;
203 }
204 
211 void gsd_cplane_setrot(int num, float rx, float ry, float rz)
212 {
213  Cp_rot[num][X] = rx;
214  Cp_rot[num][Y] = ry;
215  Cp_rot[num][Z] = rz;
216 
217  gsd_update_cpnorm(num);
218  gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
219 
220  return;
221 }
222 
229 void gsd_cplane_settrans(int num, float tx, float ty, float tz)
230 {
231  Cp_trans[num][X] = tx;
232  Cp_trans[num][Y] = ty;
233  Cp_trans[num][Z] = tz;
234 
235  gsd_def_cplane(num, Cp_trans[num], Cp_norm[num]);
236 
237  return;
238 }
239 
247 void gsd_draw_cplane_fence(geosurf * surf1, geosurf * surf2, int cpnum)
248 {
249  int was_on;
250  float len, dir[3], bgn[2], end[2], px, py, fencenorm[3];
251 
252  /* temporarily turn this plane off */
253  if ((was_on = Cp_ison[cpnum])) {
254  gsd_set_clipplane(cpnum, 0);
255  }
256 
257  /* line on surface (asuming NO TILT) is (-A,B)->(A,-B),
258  extended thru Cp_pt */
259  dir[X] = -Cp_norm[cpnum][Y];
260  dir[Y] = Cp_norm[cpnum][X];
261  dir[Z] = 0.0;
262  GS_v3norm(dir);
263  px = Cp_trans[cpnum][X] + Cp_pt[X];
264  py = Cp_trans[cpnum][Y] + Cp_pt[Y];
265 
266  /* TODO: make line from point & direction, clip to region */
267  /* for now, to test: */
268  bgn[X] = px;
269  bgn[Y] = py;
270  end[X] = px;
271  end[Y] = 3 * VROW2Y(surf1, 0);
272  len = GS_P2distance(bgn, end) - 1;
273  bgn[X] = px + len * dir[X];
274  bgn[Y] = py + len * dir[Y];
275  end[X] = px - len * dir[X];
276  end[Y] = py - len * dir[Y];
277 
278  fencenorm[X] = -Cp_norm[cpnum][X];
279  fencenorm[Y] = -Cp_norm[cpnum][Y];
280  fencenorm[Z] = -Cp_norm[cpnum][Z];
281  gsd_wall(bgn, end, fencenorm);
282 
283  /* turn this plane back on */
284  if (was_on) {
285  gsd_set_clipplane(cpnum, 1);
286  }
287 
288  return;
289 }
290 
297 {
298  float size, cpv[3];
299  int i;
300  float scalez;
301  unsigned long colr;
302 
303  /* turn off all clipping planes */
304  for (i = 0; i < MAX_CPLANES; i++) {
305  if (Cp_ison[i]) {
306  gsd_set_clipplane(i, 0);
307  }
308  }
309 
310  GS_get_longdim(&size);
311  size /= 2.;
312  cpv[X] = 0.0;
313 
314  gsd_blend(1);
315 
316  gsd_zwritemask(0x0);
317 
318  gsd_pushmatrix();
319 
320  gsd_do_scale(1);
321 
322  gsd_translate(Cp_pt[X] + Cp_trans[num][X],
323  Cp_pt[Y] + Cp_trans[num][Y], Cp_pt[Z] + Cp_trans[num][Z]);
324 
325  gsd_rot(Cp_rot[num][Z], 'z');
326  gsd_rot(Cp_rot[num][Y], 'y');
327  gsd_rot(Cp_rot[num][X], 'x');
328 
329  if ((scalez = GS_global_exag())) {
330  gsd_scale(1.0, 1.0, 1. / scalez);
331  }
332 
333  colr = (GS_default_draw_color() | 0xff000000) & 0x33ffffff;
334  gsd_color_func(colr);
335  gsd_bgnpolygon();
336  cpv[Y] = size;
337  cpv[Z] = size;
338  gsd_vert_func(cpv);
339  cpv[Y] = -size;
340  gsd_vert_func(cpv);
341  cpv[Z] = -size;
342  gsd_vert_func(cpv);
343  cpv[Y] = size;
344  gsd_vert_func(cpv);
345  gsd_endpolygon();
346 
347  gsd_popmatrix();
348  gsd_blend(0);
349  gsd_zwritemask(0xffffffff);
350 
351  /* turn on clipping planes */
352  for (i = 0; i < MAX_CPLANES; i++) {
353  if (Cp_ison[i]) {
354  gsd_set_clipplane(i, 1);
355  }
356  }
357 
358  return;
359 }
void gsd_zwritemask(unsigned long n)
Write out z-mask.
Definition: gsd_prim.c:231
void P_transform(int num_vert, float(*in)[4], float(*out)[4])
Transform array of vectors using current T matrix.
Definition: trans.c:117
void gsd_cplane_settrans(int num, float tx, float ty, float tz)
ADD.
Definition: gsd_cplane.c:229
int gs_get_datacenter(float *cen)
Get data center point.
Definition: gs.c:1232
int gs_get_data_avg_zmax(float *azmax)
Get average z-max value.
Definition: gs.c:1203
void gsd_def_clipplane(int num, double *params)
Define clip plane.
Definition: gsd_prim.c:994
void gsd_do_scale(int doexag)
Set current scale.
Definition: gsd_views.c:355
void gsd_cplane_off(int num)
Turn off clip plane.
Definition: gsd_cplane.c:126
int GS_v3norm(float *v1)
Change v1 so that it is a unit vector (2D)
Definition: GS_util.c:246
void gsd_bgnpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition: gsd_prim.c:362
long num
Definition: g3dcats.c:93
#define Y(x)
Definition: display/draw.c:246
void P_rot(float angle, char axis)
Rotate matrix.
Definition: trans.c:217
int P_popmatrix(void)
Pop top of matrix stack, placing it into the current transformation matrix.
Definition: trans.c:197
#define X(y)
Definition: display/draw.c:248
void gsd_color_func(unsigned int col)
Set current color.
Definition: gsd_prim.c:689
void gsd_get_cplanes_state(int *onstate)
Get cplane state.
Definition: gsd_cplane.c:142
void gsd_update_cpnorm(int num)
ADD.
Definition: gsd_cplane.c:188
void gsd_translate(float dx, float dy, float dz)
Multiply the current matrix by a translation matrix.
Definition: gsd_prim.c:526
int gsd_wall(float *bgn, float *end, float *norm)
ADD.
Definition: gsd_surf.c:1715
void gsd_update_cplanes(void)
Update cplaces.
Definition: gsd_cplane.c:86
tuple size
value.Bind(wx.EVT_TEXT, self.OnVolumeIsosurfMap)
Definition: tools.py:2334
int GS_get_zrange(float *min, float *max, int doexag)
Get z-extent for all loaded surfaces.
Definition: GS2.c:2687
#define VROW2Y(gs, vrow)
Definition: rowcol.h:37
void gsd_pushmatrix(void)
Push the current matrix stack.
Definition: gsd_prim.c:498
int P_pushmatrix(void)
Push current transformation matrix onto matrix stack.
Definition: trans.c:177
void gsd_rot(float angle, char axis)
ADD.
Definition: gsd_prim.c:597
void gsd_draw_cplane_fence(geosurf *surf1, geosurf *surf2, int cpnum)
ADD.
Definition: gsd_cplane.c:247
void gsd_blend(int yesno)
Specify pixel arithmetic.
Definition: gsd_prim.c:974
int first
Definition: form/open.c:25
void gsd_vert_func(float *pt)
ADD.
Definition: gsd_prim.c:677
void gsd_cplane_setrot(int num, float rx, float ry, float rz)
ADD.
Definition: gsd_cplane.c:211
void gsd_endpolygon(void)
Delimit the vertices of a primitive or a group of like primitives.
Definition: gsd_prim.c:377
int gsd_get_cplanes(Point4 *planes)
Get cplaces.
Definition: gsd_cplane.c:162
int GS_dv3norm(double *dv1)
Changes v1 so that it is a unit vector.
Definition: GS_util.c:295
void gsd_popmatrix(void)
Pop the current matrix stack.
Definition: gsd_prim.c:488
int GS_get_longdim(float *dim)
Get largest dimension.
Definition: GS2.c:140
void gsd_cplane_on(int num)
ADD.
Definition: gsd_cplane.c:104
float GS_P2distance(float *from, float *to)
Calculate distance in plane.
Definition: GS_util.c:160
unsigned int GS_default_draw_color(void)
Get default draw color.
Definition: GS2.c:2434
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
void gsd_set_clipplane(int num, int able)
Set clip plane.
Definition: gsd_prim.c:1021
void GS_get_scale(float *sx, float *sy, float *sz, int doexag)
Get axis scale.
Definition: GS2.c:3238
void gsd_def_cplane(int num, float *pt, float *norm)
Define cplace.
Definition: gsd_cplane.c:55
void gsd_draw_cplane(int num)
Draw cplane.
Definition: gsd_cplane.c:296