BRL-CAD
nmg_pr.c
Go to the documentation of this file.
1 /* N M G _ P R . C
2  * BRL-CAD
3  *
4  * Copyright (c) 1993-2014 United States Government as represented by
5  * the U.S. Army Research Laboratory.
6  *
7  * This library is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU Lesser General Public License
9  * version 2.1 as published by the Free Software Foundation.
10  *
11  * This library is distributed in the hope that it will be useful, but
12  * WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with this file; see the file named COPYING for more
18  * information.
19  */
20 /** @addtogroup nmg */
21 /** @{ */
22 /** @file primitives/nmg/nmg_pr.c
23  *
24  * Contains routines to print or describe NMG data structures.
25  * These routines are always available (not conditionally compiled)
26  * so that NMG programmers can always format and print
27  * their data structures.
28  *
29  */
30 /** @} */
31 
32 #include "common.h"
33 
34 #include <string.h>
35 #include "bio.h"
36 
37 #include "vmath.h"
38 #include "nmg.h"
39 #include "raytrace.h"
40 #include "nurb.h"
41 
42 
43 static char nmg_pr_padstr[128];
44 
45 
46 /**
47  * Convert orientation code to string.
48  */
49 char *
51 {
52  switch (orientation) {
53  case OT_SAME:
54  return "OT_SAME";
55  case OT_OPPOSITE:
56  return "OT_OPPOSITE";
57  case OT_NONE:
58  return "OT_NONE";
59  case OT_UNSPEC:
60  return "OT_UNSPEC";
61  case OT_BOOLPLACE:
62  return "OT_BOOLPLACE";
63  }
64  return "OT_IS_BOGUS!!";
65 }
66 
67 
68 /**
69  * Print the orientation in a nice, English form
70  */
71 void
72 nmg_pr_orient(int orientation, const char *h)
73 {
74  switch (orientation) {
75  case OT_SAME : bu_log("%s%8s orientation\n", h, "SAME"); break;
76  case OT_OPPOSITE : bu_log("%s%8s orientation\n", h, "OPPOSITE"); break;
77  case OT_NONE : bu_log("%s%8s orientation\n", h, "NONE"); break;
78  case OT_UNSPEC : bu_log("%s%8s orientation\n", h, "UNSPEC"); break;
79  case OT_BOOLPLACE : bu_log("%s%8s orientation\n", h, "BOOLPLACE"); break;
80  default : bu_log("%s%8s orientation\n", h, "BOGUS!!!"); break;
81  }
82 }
83 
84 
85 void
86 nmg_pr_m(const struct model *m)
87 {
88  const struct nmgregion *r;
89 
90  bu_log("MODEL %p\n", (void *)m);
91  if (!m || m->magic != NMG_MODEL_MAGIC) {
92  bu_log("bad model magic\n");
93  return;
94  }
95  bu_log("%ld maxindex\n", m->maxindex);
96 
97  for (BU_LIST_FOR(r, nmgregion, &m->r_hd)) {
98  nmg_pr_r(r, (char *)NULL);
99  }
100 }
101 
102 
103 /**
104  * NOTE: All the nmg_pr_*() routines take an "h" (header string) pointer.
105  * This can be an arbitrary caller-provided string, as long as it is kept
106  * short. The string will be copied over into nmg_pr_padstr[], and
107  * "h" will be changed to point there, so spaces can be added to the end.
108  */
109 #define MKPAD(_h) { \
110  if (!_h) { _h = nmg_pr_padstr; nmg_pr_padstr[0] = '\0'; } \
111  else if ((_h) < nmg_pr_padstr || (_h) >= nmg_pr_padstr+sizeof(nmg_pr_padstr)) { \
112  bu_strlcpy(nmg_pr_padstr, (_h), sizeof(nmg_pr_padstr)/2); \
113  _h = nmg_pr_padstr; \
114  } else { if (strlen(_h) < sizeof(nmg_pr_padstr)-4) bu_strlcat(_h, " ", sizeof(nmg_pr_padstr)); } }
115 
116 #define Return { h[strlen(h)-3] = '\0'; return; }
117 
118 void
119 nmg_pr_r(const struct nmgregion *r, char *h)
120 {
121  struct shell *s;
122 
123  bu_log("REGION %p\n", (void *)r);
124 
125  MKPAD(h);
126 
127  if (!r || r->l.magic != NMG_REGION_MAGIC) {
128  bu_log("bad region magic\n");
129  Return;
130  }
131 
132  bu_log("%p m_p\n", (void *)r->m_p);
133  bu_log("%p l.forw\n", (void *)r->l.forw);
134  bu_log("%p l.back\n", (void *)r->l.back);
135  bu_log("%p ra_p\n", (void *)r->ra_p);
136 
137  for (BU_LIST_FOR(s, shell, &r->s_hd)) {
138  nmg_pr_s(s, h);
139  }
140  Return;
141 }
142 
143 
144 void
145 nmg_pr_sa(const struct shell_a *sa, char *h)
146 {
147  MKPAD(h);
148 
149  bu_log("%sSHELL_A %p\n", h, (void *)sa);
150  if (!sa || sa->magic != NMG_SHELL_A_MAGIC) {
151  bu_log("bad shell_a magic\n");
152  Return;
153  }
154 
155  bu_log("%s%f %f %f Min\n", h, sa->min_pt[X], sa->min_pt[Y],
156  sa->min_pt[Z]);
157  bu_log("%s%f %f %f Max\n", h, sa->max_pt[X], sa->max_pt[Y],
158  sa->max_pt[Z]);
159 
160  Return;
161 }
162 
163 
164 void
165 nmg_pr_lg(const struct loop_g *lg, char *h)
166 {
167  MKPAD(h);
168  NMG_CK_LOOP_G(lg);
169 
170  bu_log("%sLOOP_G %p\n", h, (void *)lg);
171  bu_log("%s%f %f %f Min\n", h, lg->min_pt[X], lg->min_pt[Y],
172  lg->min_pt[Z]);
173  bu_log("%s%f %f %f Max\n", h, lg->max_pt[X], lg->max_pt[Y],
174  lg->max_pt[Z]);
175 
176  Return;
177 }
178 
179 
180 void
181 nmg_pr_fg(const uint32_t *magic, char *h)
182 {
183  const struct face_g_snurb *fgs;
184  int ncoords;
185  int i, j, k, l;
186 
187  MKPAD(h);
188 
189  switch (*magic) {
191  bu_log("%sFACE_G_PLANE %p\n", h, (void *)magic);
192 
193  bu_log("%s%fX + %fY + %fZ = %f\n", h,
194  V4ARGS(((struct face_g_plane *)magic)->N));
195  break;
197  fgs = (struct face_g_snurb *)magic;
198  bu_log("%sFACE_G_SNURB %p\n", h, (void *)magic);
199  bu_log("%s order (%d, %d)\n", h, fgs->order[0], fgs->order[1]);
200  bu_log("%s U knots: size=%d", h, fgs->u.k_size);
201  for (i=0; i<fgs->u.k_size; i++)
202  bu_log(" %f", fgs->u.knots[i]);
203  bu_log("\n%s V knots: size=%d", h, fgs->v.k_size);
204  for (i=0; i<fgs->v.k_size; i++)
205  bu_log(" %f", fgs->v.knots[i]);
206  bu_log("\n%s Mesh size = (%d X %d), pt_type = %d\n", h, fgs->s_size[0], fgs->s_size[1], fgs->pt_type);
207  ncoords = RT_NURB_EXTRACT_COORDS(fgs->pt_type);
208  l = 0;
209  for (i=0; i<fgs->s_size[0]; i++) {
210  bu_log("%s ", h);
211  for (j=0; j<fgs->s_size[1]; j++) {
212  bu_log(" (%s ", h);
213  for (k=0; k<ncoords; k++)
214  bu_log("%f ", fgs->ctl_points[l+k]);
215  bu_log(")");
216  l += ncoords;
217  }
218  bu_log("\n");
219  }
220  break;
221  default:
222  bu_bomb("nmg_pr_fg() bad magic\n");
223  }
224 
225  Return;
226 }
227 
228 
229 void
230 nmg_pr_s(const struct shell *s, char *h)
231 {
232  const struct faceuse *fu;
233  const struct loopuse *lu;
234  const struct edgeuse *eu;
235 
236  MKPAD(h);
237 
238  bu_log("%sSHELL %p\n", h, (void *)s);
239  if (!s || s->l.magic != NMG_SHELL_MAGIC) {
240  bu_log("bad shell magic\n");
241  Return;
242  }
243 
244  bu_log("%s%p r_p\n", h, (void *)s->r_p);
245  bu_log("%s%p l.forw\n", h, (void *)s->l.forw);
246  bu_log("%s%p l.back\n", h, (void *)s->l.back);
247  bu_log("%s%p sa_p\n", h, (void *)s->sa_p);
248  if (s->sa_p)
249  nmg_pr_sa(s->sa_p, h);
250 
251  for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
252  nmg_pr_fu(fu, h);
253  }
254 
255  for (BU_LIST_FOR(lu, loopuse, &s->lu_hd)) {
256  nmg_pr_lu(lu, h);
257  }
258 
259  for (BU_LIST_FOR(eu, edgeuse, &s->eu_hd)) {
260  nmg_pr_eu(eu, h);
261  }
262  if (s->vu_p)
263  nmg_pr_vu(s->vu_p, h);
264 
265  Return;
266 }
267 
268 
269 void
270 nmg_pr_s_briefly(const struct shell *s, char *h)
271 {
272  const struct faceuse *fu;
273  const struct loopuse *lu;
274  const struct edgeuse *eu;
275 
276  MKPAD(h);
277 
278  bu_log("%sSHELL %p\n", h, (void *)s);
279  if (!s || s->l.magic != NMG_SHELL_MAGIC) {
280  bu_log("bad shell magic\n");
281  Return;
282  }
283 
284  for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
285  nmg_pr_fu_briefly(fu, h);
286  }
287 
288  for (BU_LIST_FOR(lu, loopuse, &s->lu_hd)) {
289  nmg_pr_lu_briefly(lu, h);
290  }
291 
292  for (BU_LIST_FOR(eu, edgeuse, &s->eu_hd)) {
293  nmg_pr_eu_briefly(eu, h);
294  }
295  if (s->vu_p)
296  nmg_pr_vu_briefly(s->vu_p, h);
297 
298  Return;
299 }
300 
301 
302 void
303 nmg_pr_f(const struct face *f, char *h)
304 {
305  MKPAD(h);
306  NMG_CK_FACE(f);
307 
308  bu_log("%sFACE %p\n", h, (void *)f);
309  bu_log("%s%p fu_p\n", h, (void *)f->fu_p);
310  bu_log("%s%p g.magic_p\n", h, (void *)f->g.magic_p);
311 
312  bu_log("%s%f %f %f Min\n", h, f->min_pt[X], f->min_pt[Y],
313  f->min_pt[Z]);
314  bu_log("%s%f %f %f Max\n", h, f->max_pt[X], f->max_pt[Y],
315  f->max_pt[Z]);
316 
317  bu_log("%s%d Flip\n", h, f->flip);
318 
319  if (f->g.plane_p)
320  nmg_pr_fg(f->g.magic_p, h);
321 
322  Return;
323 }
324 
325 
326 void
327 nmg_pr_fu(const struct faceuse *fu, char *h)
328 {
329  const struct loopuse *lu;
330 
331  MKPAD(h);
332  NMG_CK_FACEUSE(fu);
333 
334  bu_log("%sFACEUSE %p\n", h, (void *)fu);
335 
336  if (!fu || fu->l.magic != NMG_FACEUSE_MAGIC) {
337  bu_log("bad faceuse magic\n");
338  Return;
339  }
340 
341  bu_log("%s%p s_p\n", h, (void *)fu->s_p);
342  bu_log("%s%p l.forw\n", h, (void *)fu->l.forw);
343  bu_log("%s%p l.back\n", h, (void *)fu->l.back);
344  bu_log("%s%p fumate_p\n", h, (void *)fu->fumate_p);
345  nmg_pr_orient(fu->orientation, h);
346 
347  bu_log("%s%p f_p\n", h, (void *)fu->f_p);
348  if (fu->f_p)
349  nmg_pr_f(fu->f_p, h);
350 
351  for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) {
352  nmg_pr_lu(lu, h);
353  }
354  Return;
355 }
356 
357 
358 void
359 nmg_pr_fu_briefly(const struct faceuse *fu, char *h)
360 {
361  const struct loopuse *lu;
362  struct face *f;
363 
364  MKPAD(h);
365  NMG_CK_FACEUSE(fu);
366  f = fu->f_p;
367 
368  if (f->g.magic_p && *f->g.magic_p == NMG_FACE_G_PLANE_MAGIC) {
369  bu_log("%sFACEUSE %p (%s) f_p=%p fg=%p flip=%d pl= %f %f %f %f\n",
370  h,
371  (void *)fu, nmg_orientation(fu->orientation),
372  (void *)fu->f_p, (void *)f->g.magic_p, fu->f_p->flip, V4ARGS(f->g.plane_p->N));
373  } else
374  bu_log("%sFACEUSE %p (%s) f_p=%p\n",
375  h, (void *)fu, nmg_orientation(fu->orientation), (void *)fu->f_p);
376 
377  for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) {
378  nmg_pr_lu_briefly(lu, h);
379  }
380  Return;
381 }
382 
383 
384 void
385 nmg_pr_l(const struct loop *l, char *h)
386 {
387  MKPAD(h);
388  NMG_CK_LOOP(l);
389 
390  bu_log("%sLOOP %p\n", h, (void *)l);
391  if (!l || l->magic != NMG_LOOP_MAGIC) {
392  bu_log("bad loop magic\n");
393  Return;
394  }
395  bu_log("%s%p lu_p\n", h, (void *)l->lu_p);
396  bu_log("%s%p lg_p\n", h, (void *)l->lg_p);
397  if (l->lg_p)
398  nmg_pr_lg(l->lg_p, h);
399 
400  Return;
401 }
402 
403 
404 void
405 nmg_pr_lu(const struct loopuse *lu, char *h)
406 {
407  const struct edgeuse *eu;
408  const struct vertexuse *vu;
409  uint32_t magic1;
410 
411  MKPAD(h);
412  NMG_CK_LOOPUSE(lu);
413 
414  bu_log("%sLOOPUSE %p\n", h, (void *)lu);
415 
416  switch (*lu->up.magic_p) {
417  case NMG_SHELL_MAGIC : bu_log("%s%p up.s_p\n", h, (void *)lu->up.s_p);
418  break;
419  case NMG_FACEUSE_MAGIC : bu_log("%s%p up.fu_p\n", h, (void *)lu->up.fu_p);
420  break;
421  default : bu_log("Bad loopuse parent magic\n");
422  Return;
423  }
424 
425  bu_log("%s%p l.forw\n", h, (void *)lu->l.forw);
426  bu_log("%s%p l.back\n", h, (void *)lu->l.back);
427  bu_log("%s%p lumate_p\n", h, (void *)lu->lumate_p);
428  nmg_pr_orient(lu->orientation, h);
429  bu_log("%s%p l_p\n", h, (void *)lu->l_p);
430  if (lu->l_p)
431  nmg_pr_l(lu->l_p, h);
432 
433 
434  bu_log("%s%8x down_hd.magic\n", h, lu->down_hd.magic);
435  bu_log("%s%p down_hd.forw\n", h, (void *)lu->down_hd.forw);
436  bu_log("%s%p down_hd.back\n", h, (void *)lu->down_hd.back);
437 
438  magic1 = BU_LIST_FIRST_MAGIC(&lu->down_hd);
439  if (magic1 == NMG_VERTEXUSE_MAGIC) {
440  vu = BU_LIST_PNEXT(vertexuse, &lu->down_hd);
441  bu_log("%s%p down_hd->forw (vu)\n", h, (void *)vu);
442  nmg_pr_vu(vu, h);
443  } else if (magic1 == NMG_EDGEUSE_MAGIC) {
444  for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
445  nmg_pr_eu(eu, h);
446  }
447  } else
448  bu_log("bad loopuse child magic\n");
449 
450  Return;
451 }
452 
453 
454 void
455 nmg_pr_lu_briefly(const struct loopuse *lu, char *h)
456 {
457  const struct edgeuse *eu;
458  const struct vertexuse *vu;
459  uint32_t magic1;
460 
461  MKPAD(h);
462  NMG_CK_LOOPUSE(lu);
463 
464  bu_log("%sLOOPUSE %p, lumate_p=%p (%s) \n",
465  h, (void *)lu, (void *)lu->lumate_p, nmg_orientation(lu->orientation));
466 
467  magic1 = BU_LIST_FIRST_MAGIC(&lu->down_hd);
468  if (magic1 == NMG_VERTEXUSE_MAGIC) {
469  vu = BU_LIST_PNEXT(vertexuse, &lu->down_hd);
470  bu_log("%s%p down_hd->forw (vu)\n", h, (void *)vu);
471  nmg_pr_vu_briefly(vu, h);
472  } else if (magic1 == NMG_EDGEUSE_MAGIC) {
473  for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
474  nmg_pr_eu_briefly(eu, h);
475  }
476  } else
477  bu_log("bad loopuse child magic\n");
478 
479  Return;
480 }
481 
482 
483 /**
484  * Expects a pointer to the magic number of an edge geometry structure
485  * either edge_g_lseg or edge_g_cnurb structures.
486  */
487 void
488 nmg_pr_eg(const uint32_t *eg_magic_p, char *h)
489 {
490  MKPAD(h);
491  NMG_CK_EDGE_G_EITHER(eg_magic_p);
492 
493  switch (*eg_magic_p) {
494  case NMG_EDGE_G_LSEG_MAGIC: {
495  struct edge_g_lseg *eg_l=(struct edge_g_lseg *)eg_magic_p;
496 
497  bu_log("%sEDGE_G_LSEG %p pt:(%f %f %f)\n",
498  h, (void *)eg_l, V3ARGS(eg_l->e_pt));
499  bu_log("%s eu uses=%d dir:(%f %f %f)\n",
500  h, bu_list_len(&eg_l->eu_hd2), V3ARGS(eg_l->e_dir));
501  break;
502  }
503  case NMG_EDGE_G_CNURB_MAGIC: {
504  struct edge_g_cnurb *eg_c=(struct edge_g_cnurb *)eg_magic_p;
505  int i, j, l;
506  int ncoords;
507 
508  bu_log("%sEDGE_G_CNURB %p\n", h, (void *)eg_c);
509  bu_log("%s order=%d, %d ctl pts, pt_type=%d\n",
510  h, eg_c->order, eg_c->c_size, eg_c->pt_type);
511  bu_log("%s knot vector (len=%d):", h, eg_c->k.k_size);
512  for (i = 0; i < eg_c->k.k_size; i++)
513  bu_log(" %f", eg_c->k.knots[i]);
514  bu_log("\n");
515  ncoords = RT_NURB_EXTRACT_COORDS(eg_c->pt_type);
516  l = 0;
517  bu_log("%s control points: ", h);
518  for (i = 0; i < eg_c->c_size; i++) {
519  bu_log("(");
520  for (j = 0; j < ncoords; j++)
521  bu_log("%f ", eg_c->ctl_points[l+j]);
522  bu_log(")");
523  l += ncoords;
524  }
525  bu_log("\n");
526  break;
527  }
528  }
529 
530  Return;
531 }
532 
533 
534 void
535 nmg_pr_e(const struct edge *e, char *h)
536 {
537  MKPAD(h);
538  NMG_CK_EDGE(e);
539 
540  bu_log("%sEDGE %p\n", h, (void *)e);
541  if (!e || e->magic != NMG_EDGE_MAGIC) {
542  bu_log("bad edge magic\n");
543  Return;
544  }
545  bu_log("%s%p eu_p\n", h, (void *)e->eu_p);
546 
547  Return;
548 }
549 
550 
551 void
552 nmg_pr_eu(const struct edgeuse *eu, char *h)
553 {
554  MKPAD(h);
555  NMG_CK_EDGEUSE(eu);
556 
557  bu_log("%sEDGEUSE %p\n", h, (void *)eu);
558 
559  switch (*eu->up.magic_p) {
560  case NMG_SHELL_MAGIC : bu_log("%s%p up.s_p\n", h, (void *)eu->up.s_p);
561  break;
562  case NMG_LOOPUSE_MAGIC : bu_log("%s%p up.lu_p\n", h, (void *)eu->up.lu_p);
563  break;
564  default : bu_log("bad edgeuse parent magic\n");
565  Return;
566  }
567  bu_log("%s%p l.forw\n", h, (void *)eu->l.forw);
568  bu_log("%s%p l.back\n", h, (void *)eu->l.back);
569  bu_log("%s%p eumate_p\n", h, (void *)eu->eumate_p);
570  bu_log("%s%p radial_p\n", h, (void *)eu->radial_p);
571  nmg_pr_orient(eu->orientation, h);
572  bu_log("%s%p e_p\n", h, (void *)eu->e_p);
573  bu_log("%s%p vu_p\n", h, (void *)eu->vu_p);
574  bu_log("%s%p g.magic_p\n", h, (void *)eu->g.magic_p);
575  nmg_pr_e(eu->e_p, h);
576  nmg_pr_vu(eu->vu_p, h);
577 
578  if (eu->g.magic_p)
579  nmg_pr_eg(eu->g.magic_p, h);
580 
581  Return;
582 }
583 
584 
585 void
586 nmg_pr_eu_briefly(const struct edgeuse *eu, char *h)
587 {
588  MKPAD(h);
589  NMG_CK_EDGEUSE(eu);
590 
591  bu_log("%sEDGEUSE %p, g=%p, e_p=%p\n",
592  h, (void *)eu, (void *)eu->g.magic_p, (void *)eu->e_p);
593  nmg_pr_vu_briefly(eu->vu_p, h);
594 
595  Return;
596 }
597 
598 
599 void
600 nmg_pr_eu_endpoints(const struct edgeuse *eu, char *h)
601 {
602  struct vertex_g *vg1, *vg2;
603 
604  MKPAD(h);
605  NMG_CK_EDGEUSE(eu);
606 
607  vg1 = eu->vu_p->v_p->vg_p;
608  vg2 = eu->eumate_p->vu_p->v_p->vg_p;
609  NMG_CK_VERTEX_G(vg1);
610  NMG_CK_VERTEX_G(vg2);
611 
612  bu_log("%sEDGEUSE %p\n%s (%g, %g, %g) -- (%g, %g, %g)\n",
613  h, (void *)eu, h,
614  V3ARGS(vg1->coord),
615  V3ARGS(vg2->coord));
616 
617  Return;
618 }
619 
620 
621 void
622 nmg_pr_vg(const struct vertex_g *vg, char *h)
623 {
624  MKPAD(h);
625  NMG_CK_VERTEX_G(vg);
626 
627  if (!vg || vg->magic != NMG_VERTEX_G_MAGIC) {
628  bu_log("%sVERTEX_G %p\n", h, (void *)vg);
629  bu_log("bad vertex_g magic\n");
630  Return;
631  }
632  bu_log("%sVERTEX_G %p %f %f %f = XYZ coord\n",
633  h, (void *)vg, V3ARGS(vg->coord));
634  Return;
635 }
636 
637 
638 void
639 nmg_pr_v(const struct vertex *v, char *h)
640 {
641  MKPAD(h);
642  NMG_CK_VERTEX(v);
643 
644  bu_log("%sVERTEX %p\n", h, (void *)v);
645  if (!v || v->magic != NMG_VERTEX_MAGIC) {
646  bu_log("bad vertex magic\n");
647  Return;
648  }
649  /* vu_hd ? */
650  bu_log("%s vu_hd %p\n", h, (void *)&v->vu_hd);
651  bu_log("%s%p vu_hd.forw\n", h, (void *)v->vu_hd.forw);
652  bu_log("%s%p vu_hd.back\n", h, (void *)v->vu_hd.back);
653 
654 
655  bu_log("%s%p vg_p\n", h, (void *)v->vg_p);
656  if (v->vg_p)
657  nmg_pr_vg(v->vg_p, h);
658 
659  Return;
660 }
661 
662 
663 void
664 nmg_pr_vu(const struct vertexuse *vu, char *h)
665 {
666  MKPAD(h);
667  NMG_CK_VERTEXUSE(vu);
668 
669  bu_log("%sVERTEXUSE %p\n", h, (void *)vu);
670  if (!vu || vu->l.magic != NMG_VERTEXUSE_MAGIC) {
671  bu_log("bad vertexuse magic\n");
672  Return;
673  }
674 
675  switch (*vu->up.magic_p) {
676  case NMG_SHELL_MAGIC : bu_log("%s%p up.s_p\n", h, (void *)vu->up.s_p); break;
677  case NMG_LOOPUSE_MAGIC : bu_log("%s%p up.lu_p\n", h, (void *)vu->up.lu_p); break;
678  case NMG_EDGEUSE_MAGIC : bu_log("%s%p up.eu_p\n", h, (void *)vu->up.eu_p); break;
679  default : bu_log("bad vertexuse parent magic\n");
680  Return;
681  }
682  bu_log("%s%p l.forw\n", h, (void *)vu->l.forw);
683  bu_log("%s%p l.back\n", h, (void *)vu->l.back);
684  if (vu->a.magic_p) switch (*vu->a.magic_p) {
686  bu_log("%s%p a.plane_p\n", h, (void *)vu->a.plane_p);
687  bu_log("%s normal: %f %f %f\n", h, V3ARGS(vu->a.plane_p->N));
688  break;
690  bu_log("%s%p a.cnurb_p\n", h, (void *)vu->a.cnurb_p);
691  break;
692  }
693  bu_log("%s%p v_p\n", h, (void *)vu->v_p);
694  nmg_pr_v(vu->v_p, h);
695  if (vu->a.magic_p) nmg_pr_vua(vu->a.magic_p, h);
696 
697  Return;
698 }
699 
700 
701 void
702 nmg_pr_vu_briefly(const struct vertexuse *vu, char *h)
703 {
704  const struct vertex_g *vg;
705 
706  MKPAD(h);
707  NMG_CK_VERTEXUSE(vu);
708  NMG_CK_VERTEX(vu->v_p);
709 
710  vg = vu->v_p->vg_p;
711  if (vg) {
712  NMG_CK_VERTEX_G(vg);
713  bu_log("%sVERTEXUSE %p, v=%p, %f %f %f\n", h,
714  (void *)vu, (void *)vu->v_p,
715  V3ARGS(vg->coord));
716  } else {
717  bu_log("%sVERTEXUSE %p, v=%p\n", h, (void *)vu, (void *)vu->v_p);
718  }
719 
720  Return;
721 }
722 
723 
724 void
725 nmg_pr_vua(const uint32_t *magic_p, char *h)
726 {
727  MKPAD(h);
728 
729  bu_log("%sVERTEXUSE_A %p\n", h, (void *)magic_p);
730  if (!magic_p) {
731  bu_log("bad vertexuse_a magic\n");
732  Return;
733  }
734 
735  switch (*magic_p) {
737  bu_log("%s N=(%g, %g, %g)\n", h,
738  V3ARGS(((struct vertexuse_a_plane *)magic_p)->N));
739  break;
741  bu_log("%s param=(%g, %g, %g)\n", h,
742  V3ARGS(((struct vertexuse_a_cnurb *)magic_p)->param));
743  break;
744  }
745 
746  Return;
747 }
748 
749 
750 void
751 nmg_euprint(const char *str, const struct edgeuse *eu)
752 {
753  const fastf_t *eup;
754  const fastf_t *matep;
755 
756  NMG_CK_EDGEUSE(eu);
757  NMG_CK_VERTEXUSE(eu->vu_p);
758  NMG_CK_VERTEX(eu->vu_p->v_p);
759  NMG_CK_VERTEX_G(eu->vu_p->v_p->vg_p);
760 
761  NMG_CK_EDGEUSE(eu->eumate_p);
762  NMG_CK_VERTEXUSE(eu->eumate_p->vu_p);
763  NMG_CK_VERTEX(eu->eumate_p->vu_p->v_p);
764  NMG_CK_VERTEX_G(eu->eumate_p->vu_p->v_p->vg_p);
765 
766  eup = eu->vu_p->v_p->vg_p->coord;
767  matep = eu->eumate_p->vu_p->v_p->vg_p->coord;
768 
769  bu_log("%s (%g, %g, %g -> %g, %g, %g)\n", str, eup[0], eup[1], eup[2],
770  matep[0], matep[1], matep[2]);
771 }
772 /**
773  * Print an bu_ptbl array for inspection.
774  */
775 void
776 nmg_pr_ptbl(const char *title, const struct bu_ptbl *tbl, int verbose)
777 {
778  register long **lp;
779 
780  BU_CK_PTBL(tbl);
781  bu_log("%s: bu_ptbl array with %ld entries\n",
782  title, tbl->end);
783 
784  if (!verbose) return;
785 
786  for (lp = (long **)BU_PTBL_BASEADDR(tbl);
787  lp <= (long **)BU_PTBL_LASTADDR(tbl); lp++
788  ) {
789  if (*lp == 0) {
790  bu_log(" %p NULL entry\n", (void *)*lp);
791  continue;
792  }
793  switch (**lp) {
794  default:
795  bu_log(" %p %s\n", (void *)*lp, bu_identify_magic(**lp));
796  break;
797  case NMG_EDGEUSE_MAGIC:
798  bu_log(" %p edgeuse vu=%p, far vu=%p\n",
799  (void *)*lp,
800  (void *)((struct edgeuse *)*lp)->vu_p,
801  (void *)BU_LIST_PNEXT_CIRC(edgeuse, *lp)->vu_p);
802  break;
803  case NMG_VERTEXUSE_MAGIC:
804  bu_log(" %p vertexuse v=%p\n",
805  (void *)*lp,
806  (void *)((struct vertexuse *)*lp)->v_p);
807  break;
808  }
809  }
810 }
811 
812 
813 /**
814  * Print a ptbl array as a vertex list.
815  */
816 void
817 nmg_pr_ptbl_vert_list(const char *str, const struct bu_ptbl *tbl, const fastf_t *mag)
818 {
819  int i;
820  const struct vertexuse **vup;
821  const struct vertexuse *vu;
822  const struct vertex *v;
823  const struct vertex_g *vg;
824 
825  bu_log("nmg_pr_ptbl_vert_list(%s):\n", str);
826 
827  vup = (const struct vertexuse **)tbl->buffer;
828  for (i = 0; i < tbl->end; ++i) {
829  vu = vup[i];
830  if (vu->l.magic != NMG_VERTEXUSE_MAGIC) {
831  bu_log("\tWARNING: vertexuse #%d has bad MAGIC (%u)\n",
832  i, vu->l.magic);
833  continue;
834  }
835  NMG_CK_VERTEXUSE(vu);
836  v = vu->v_p;
837  NMG_CK_VERTEX(v);
838  vg = v->vg_p;
839  NMG_CK_VERTEX_G(vg);
840  bu_log("%d\t%g, %g, %g\t", i, V3ARGS(vg->coord));
841  if (*vu->up.magic_p == NMG_EDGEUSE_MAGIC) {
842  bu_log("EDGEUSE");
843  } else if (*vu->up.magic_p == NMG_LOOPUSE_MAGIC) {
844  bu_log("LOOPUSE");
845  if ((struct vertexuse *)vu->up.lu_p->down_hd.forw != vu) {
846  bu_log("ERROR vertexuse's parent disowns us!\n");
847  if (((struct vertexuse *)(vu->up.lu_p->lumate_p->down_hd.forw))->l.magic == NMG_VERTEXUSE_MAGIC)
848  bu_bomb("lumate has vertexuse\n");
849  bu_bomb("lumate has garbage\n");
850  }
851  } else {
852  bu_log("vu up UNKNOWN");
853  }
854  bu_log("\tv=%p, vu=%p, dist=%g\n", (void *)v, (void *)vu, mag[i]);
855  }
856 }
857 
858 
859 /**
860  * Common formatting code for edgeuses and edgeuse mates.
861  * Does not mind wire edges.
862  */
863 void
864 nmg_pr_one_eu_vecs(const struct edgeuse *eu, const fastf_t *xvec, const fastf_t *yvec,
865  const fastf_t *zvec, const struct bn_tol *UNUSED(tol))
866 {
867  const struct loopuse *lu;
868  const struct faceuse *fu;
869  const struct face *f;
870  const struct shell *s;
871  char *lu_orient;
872  char *fu_orient;
873 
874  NMG_CK_EDGEUSE(eu);
875  lu = (struct loopuse *)NULL;
876  lu_orient = "W";
877  fu = (struct faceuse *)NULL;
878  fu_orient = "W";
879  f = (struct face *)NULL;
880  if (*eu->up.magic_p == NMG_LOOPUSE_MAGIC) {
881  lu = eu->up.lu_p;
882  NMG_CK_LOOPUSE(lu);
883  /* +3 is to skip the "OT_" prefix */
884  lu_orient = nmg_orientation(lu->orientation)+3;
885  if (*lu->up.magic_p == NMG_FACEUSE_MAGIC) {
886  fu = lu->up.fu_p;
887  NMG_CK_FACEUSE(fu);
888  fu_orient = nmg_orientation(fu->orientation)+3;
889  f = fu->f_p;
890  s = fu->s_p;
891  } else {
892  s = lu->up.s_p;
893  }
894  } else {
895  s = eu->up.s_p;
896  }
897  NMG_CK_SHELL(s);
898  if (f && *f->g.magic_p == NMG_FACE_G_SNURB_MAGIC) {
899  bu_log(" %p, lu=%p=%1.1s, f=%p, fu=%p=%1.1s, s=%p SNURB\n",
900  (void *)eu,
901  (void *)lu, lu_orient,
902  (void *)f,
903  (void *)fu, fu_orient,
904  (void *)s);
905  } else {
906  bu_log(" %p, lu=%p=%1.1s, f=%p, fu=%p=%1.1s, s=%p %g deg\n",
907  (void *)eu,
908  (void *)lu, lu_orient,
909  (void *)f,
910  (void *)fu, fu_orient,
911  (void *)s,
912  nmg_measure_fu_angle(eu, xvec, yvec, zvec) * RAD2DEG);
913  }
914 }
915 
916 
917 void
918 nmg_pr_fu_around_eu_vecs(const struct edgeuse *eu, const fastf_t *xvec, const fastf_t *yvec, const fastf_t *zvec, const struct bn_tol *tol)
919 {
920  const struct edgeuse *eu1;
921 
922  NMG_CK_EDGEUSE(eu);
923  BN_CK_TOL(tol);
924  bu_log("nmg_pr_fu_around_eu_vecs(eu=%p) e=%p\n", (void *)eu, (void *)eu->e_p);
925 
926  /* To go correct way around, start with arg's mate,
927  * so that arg, then radial, will follow.
928  */
929  eu = eu->eumate_p;
930 
931  eu1 = eu;
932  do {
933  /* First, the edgeuse mate */
934  nmg_pr_one_eu_vecs(eu1, xvec, yvec, zvec, tol);
935 
936  /* Second, the edgeuse itself (mate's mate) */
937  eu1 = eu1->eumate_p;
938  nmg_pr_one_eu_vecs(eu1, xvec, yvec, zvec, tol);
939 
940  /* Now back around to the radial edgeuse */
941  eu1 = eu1->radial_p;
942  } while (eu1 != eu);
943 }
944 
945 
946 /**
947  * A debugging routine to print all the faceuses around a given edge,
948  * starting with the given edgeuse.
949  * The normal of the first face is considered to be "0 degrees",
950  * and the rest are measured from there.
951  */
952 void
953 nmg_pr_fu_around_eu(const struct edgeuse *eu, const struct bn_tol *tol)
954 {
955  vect_t xvec, yvec, zvec;
956 
957  NMG_CK_EDGEUSE(eu);
958  BN_CK_TOL(tol);
959  bu_log("nmg_pr_fu_around_eu(%p)\n", (void *)eu);
960 
961  if (eu->vu_p->v_p == eu->eumate_p->vu_p->v_p || *eu->g.magic_p == NMG_EDGE_G_CNURB_MAGIC) {
962  VSET(xvec, 1, 0, 0);
963  VSET(yvec, 0, 1, 0);
964  VSET(zvec, 0, 0, 1);
965  } else {
966  /* Erect coordinate system around eu */
967  nmg_eu_2vecs_perp(xvec, yvec, zvec, eu, tol);
968  }
969 
970  nmg_pr_fu_around_eu_vecs(eu, xvec, yvec, zvec, tol);
971 }
972 
973 
974 /**
975  * Plot all the loopuses around an edgeuse.
976  * Don't bother drawing the loopuse mates.
977  */
978 void
979 nmg_pl_lu_around_eu(const struct edgeuse *eu)
980 {
981  FILE *fp;
982  const struct edgeuse *eu1;
983  const struct loopuse *lu1;
984  long *b;
985  static int num;
986  char buf[128];
987 
988  NMG_CK_EDGEUSE(eu);
989 
990  sprintf(buf, "eu_vicinity%d.plot3", num++);
991  fp = fopen(buf, "wb");
992  if (fp == NULL) {
993  perror(buf);
994  return;
995  }
996 
997  b = (long *)bu_calloc(nmg_find_model((uint32_t *)eu)->maxindex, sizeof(long),
998  "nmg_pl_lu_around_eu flag[]");
999 
1000  /* To go correct way around, start with arg's mate,
1001  * so that arg, then radial, will follow.
1002  */
1003  eu = eu->eumate_p;
1004 
1005  eu1 = eu;
1006  do {
1007  /* First, the edgeuse mate */
1008  /* Second, the edgeuse itself (mate's mate) */
1009  eu1 = eu1->eumate_p;
1010 
1011  if (*eu1->up.magic_p == NMG_LOOPUSE_MAGIC) {
1012  lu1 = eu1->up.lu_p;
1013  nmg_pl_lu(fp, lu1, b, 80, 100, 170);
1014  }
1015 
1016  /* Now back around to the radial edgeuse */
1017  eu1 = eu1->radial_p;
1018  } while (eu1 != eu);
1019 
1020  bu_free((char *)b, "nmg_pl_lu_around_eu flag[]");
1021  fclose(fp);
1022  bu_log("Wrote %s\n", buf);
1023 }
1024 
1025 
1026 /**
1027  * For either kind of face geometry, print the list of all faces & faceuses
1028  * that share this geometry.
1029  */
1030 void
1031 nmg_pr_fus_in_fg(const uint32_t *fg_magic)
1032 {
1033  struct face *f;
1034 
1035  NMG_CK_FACE_G_EITHER(fg_magic);
1036  bu_log("nmg_pr_fus_in_fg(%p):\n", (void *)fg_magic);
1037  for (BU_LIST_FOR(f, face, &(((struct face_g_plane *)fg_magic)->f_hd))) {
1038  NMG_CK_FACE(f);
1039  NMG_CK_FACEUSE(f->fu_p);
1040  bu_log(" f=%p, fu=%p, fumate=%p\n",
1041  (void *)f, (void *)f->fu_p, (void *)f->fu_p->fumate_p);
1042  }
1043 }
1044 
1045 
1046 /*
1047  * Local Variables:
1048  * mode: C
1049  * tab-width: 8
1050  * indent-tabs-mode: t
1051  * c-file-style: "stroustrup"
1052  * End:
1053  * ex: shiftwidth=4 tabstop=8
1054  */
void nmg_pr_vu_briefly(const struct vertexuse *vu, char *h)
Definition: nmg_pr.c:702
#define NMG_MODEL_MAGIC
Definition: magic.h:133
#define BU_LIST_PNEXT_CIRC(structure, p)
Definition: list.h:442
#define BU_LIST_FOR(p, structure, hp)
Definition: list.h:365
long ** buffer
Definition: ptbl.h:66
#define NMG_EDGEUSE_MAGIC
Definition: magic.h:120
void bu_log(const char *,...) _BU_ATTR_PRINTF12
Definition: log.c:176
void nmg_pr_sa(const struct shell_a *sa, char *h)
Definition: nmg_pr.c:145
void nmg_pr_r(const struct nmgregion *r, char *h)
Definition: nmg_pr.c:119
#define NMG_EDGE_MAGIC
Definition: magic.h:123
void nmg_pr_vg(const struct vertex_g *vg, char *h)
Definition: nmg_pr.c:622
#define NMG_SHELL_MAGIC
Definition: magic.h:142
void nmg_euprint(const char *str, const struct edgeuse *eu)
Definition: nmg_pr.c:751
#define NMG_VERTEX_MAGIC
Definition: magic.h:147
#define NMG_FACE_G_SNURB_MAGIC
Definition: magic.h:126
void nmg_pr_e(const struct edge *e, char *h)
Definition: nmg_pr.c:535
if lu s
Definition: nmg_mod.c:3860
lu
Definition: nmg_mod.c:3855
#define VSET(a, b, c, d)
Definition: color.c:53
#define N
Definition: randmt.c:39
void nmg_pr_one_eu_vecs(const struct edgeuse *eu, const fastf_t *xvec, const fastf_t *yvec, const fastf_t *zvec, const struct bn_tol *tol)
Definition: nmg_pr.c:864
void nmg_pr_m(const struct model *m)
Definition: nmg_pr.c:86
void nmg_pr_eg(const uint32_t *eg_magic_p, char *h)
Definition: nmg_pr.c:488
Header file for the BRL-CAD common definitions.
#define BU_CK_PTBL(_p)
Definition: ptbl.h:74
#define NMG_LOOPUSE_MAGIC
Definition: magic.h:130
void nmg_pr_eu_briefly(const struct edgeuse *eu, char *h)
Definition: nmg_pr.c:586
NMG_CK_LOOPUSE(lu)
BU_LIST_DEQUEUE & eu1
Definition: nmg_mod.c:3839
Definition: ptbl.h:62
void nmg_pr_f(const struct face *f, char *h)
Definition: nmg_pr.c:303
void nmg_eu_2vecs_perp(fastf_t *xvec, fastf_t *yvec, fastf_t *zvec, const struct edgeuse *eu, const struct bn_tol *tol)
Definition: nmg_info.c:1237
#define MKPAD(_h)
Definition: nmg_pr.c:109
Definition: color.c:49
void nmg_pr_v(const struct vertex *v, char *h)
Definition: nmg_pr.c:639
#define NMG_LOOP_MAGIC
Definition: magic.h:132
void nmg_pr_l(const struct loop *l, char *h)
Definition: nmg_pr.c:385
void * bu_calloc(size_t nelem, size_t elsize, const char *str)
Definition: malloc.c:321
#define BU_PTBL_LASTADDR(ptbl)
Definition: ptbl.h:105
void nmg_pr_orient(int orientation, const char *h)
Definition: nmg_pr.c:72
#define V3ARGS(a)
Definition: color.c:56
void nmg_pr_lu_briefly(const struct loopuse *lu, char *h)
Definition: nmg_pr.c:455
void nmg_pr_fu_around_eu_vecs(const struct edgeuse *eu, const fastf_t *xvec, const fastf_t *yvec, const fastf_t *zvec, const struct bn_tol *tol)
Definition: nmg_pr.c:918
#define NMG_SHELL_A_MAGIC
Definition: magic.h:141
void nmg_pr_ptbl_vert_list(const char *str, const struct bu_ptbl *tbl, const fastf_t *mag)
Definition: nmg_pr.c:817
#define BU_LIST_PNEXT(structure, p)
Definition: list.h:422
double nmg_measure_fu_angle(const struct edgeuse *eu, const fastf_t *xvec, const fastf_t *yvec, const fastf_t *zvec)
Definition: nmg_info.c:391
oldeumate l2 magic
Definition: nmg_mod.c:3843
#define Return
Definition: nmg_pr.c:116
#define UNUSED(parameter)
Definition: common.h:239
#define NMG_REGION_MAGIC
Definition: magic.h:137
Support for uniform tolerances.
Definition: tol.h:71
#define BN_CK_TOL(_p)
Definition: tol.h:82
#define BU_LIST_FIRST_MAGIC(hp)
Definition: list.h:416
#define NMG_VERTEXUSE_MAGIC
Definition: magic.h:145
#define NMG_VERTEXUSE_A_CNURB_MAGIC
Definition: magic.h:143
void nmg_pl_lu(FILE *fp, const struct loopuse *lu, long *b, int red, int green, int blue)
Definition: nmg_plot.c:710
#define NMG_FACE_G_PLANE_MAGIC
Definition: magic.h:125
void nmg_pr_fus_in_fg(const uint32_t *fg_magic)
Definition: nmg_pr.c:1031
void nmg_pr_s(const struct shell *s, char *h)
Definition: nmg_pr.c:230
#define NMG_EDGE_G_LSEG_MAGIC
Definition: magic.h:122
void nmg_pr_vua(const uint32_t *magic_p, char *h)
Definition: nmg_pr.c:725
void nmg_pl_lu_around_eu(const struct edgeuse *eu)
Definition: nmg_pr.c:979
#define NMG_EDGE_G_CNURB_MAGIC
Definition: magic.h:121
void nmg_pr_lu(const struct loopuse *lu, char *h)
Definition: nmg_pr.c:405
eu1 up magic_p
Definition: nmg_mod.c:3915
#define NMG_VERTEXUSE_A_PLANE_MAGIC
Definition: magic.h:144
void nmg_pr_fu_around_eu(const struct edgeuse *eu, const struct bn_tol *tol)
Definition: nmg_pr.c:953
void nmg_pr_vu(const struct vertexuse *vu, char *h)
Definition: nmg_pr.c:664
#define BU_PTBL_BASEADDR(ptbl)
Definition: ptbl.h:104
int bu_list_len(const struct bu_list *hd)
void nmg_pr_lg(const struct loop_g *lg, char *h)
Definition: nmg_pr.c:165
Definition: color.c:51
void nmg_pr_ptbl(const char *title, const struct bu_ptbl *tbl, int verbose)
Definition: nmg_pr.c:776
void nmg_pr_eu(const struct edgeuse *eu, char *h)
Definition: nmg_pr.c:552
void bu_free(void *ptr, const char *str)
Definition: malloc.c:328
void nmg_pr_fg(const uint32_t *magic, char *h)
Definition: nmg_pr.c:181
#define NMG_VERTEX_G_MAGIC
Definition: magic.h:146
void nmg_pr_eu_endpoints(const struct edgeuse *eu, char *h)
Definition: nmg_pr.c:600
void nmg_pr_fu_briefly(const struct faceuse *fu, char *h)
Definition: nmg_pr.c:359
off_t end
Definition: ptbl.h:64
NMG_CK_SHELL(s)
void nmg_pr_fu(const struct faceuse *fu, char *h)
Definition: nmg_pr.c:327
void nmg_pr_s_briefly(const struct shell *s, char *h)
Definition: nmg_pr.c:270
#define NMG_FACEUSE_MAGIC
Definition: magic.h:124
HIDDEN void verbose(struct human_data_t *dude)
Definition: human.c:2008
void bu_bomb(const char *str) _BU_ATTR_NORETURN
Definition: bomb.c:91
double fastf_t
Definition: defines.h:300
const char * bu_identify_magic(uint32_t magic)
char * nmg_orientation(int orientation)
Definition: nmg_pr.c:50
Definition: color.c:50
eu1 orientation
Definition: nmg_mod.c:3916
struct model * nmg_find_model(const uint32_t *magic_p_arg)
Definition: nmg_info.c:57