nmg_pr.c

Go to the documentation of this file.
00001 /*                        N M G _ P R . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1993-2006 United States Government as represented by
00005  * the U.S. Army Research Laboratory.
00006  *
00007  * This library is free software; you can redistribute it and/or
00008  * modify it under the terms of the GNU Lesser General Public License
00009  * as published by the Free Software Foundation; either version 2 of
00010  * the License, or (at your option) any later version.
00011  *
00012  * This library is distributed in the hope that it will be useful, but
00013  * WITHOUT ANY WARRANTY; without even the implied warranty of
00014  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015  * Library General Public License for more details.
00016  *
00017  * You should have received a copy of the GNU Lesser General Public
00018  * License along with this file; see the file named COPYING for more
00019  * information.
00020  */
00021 /** @addtogroup nmg */
00022 
00023 /*@{*/
00024 /** @file nmg_pr.c
00025  *      Contains routines to print or describe NMG data structures.
00026  *      These routines are always available (not conditionally compiled)
00027  *      so that NMG programmers can always format and print
00028  *      their data structures.
00029  *
00030  *  Authors -
00031  *      Lee A. Butler
00032  *      Michael John Muuss
00033  *
00034  *  Source -
00035  *      The U. S. Army Research Laboratory
00036  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00037  */
00038 /*@}*/
00039 
00040 #ifndef lint
00041 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/nmg_pr.c,v 14.12 2006/09/16 02:04:25 lbutler Exp $ (ARL)";
00042 #endif
00043 
00044 #include "common.h"
00045 
00046 
00047 #include <stdio.h>
00048 #ifdef HAVE_STRING_H
00049 # include <string.h>
00050 #else
00051 # include <strings.h>
00052 #endif
00053 #include "machine.h"
00054 #include "vmath.h"
00055 #include "nmg.h"
00056 #include "raytrace.h"
00057 #include "nurb.h"
00058 
00059 /**
00060  *                      N M G _ O R I E N T A T I O N
00061  *
00062  *  Convert orientation code to string.
00063  */
00064 char *
00065 nmg_orientation(int orientation)
00066 {
00067         switch (orientation) {
00068         case OT_SAME:
00069                 return "OT_SAME";
00070         case OT_OPPOSITE:
00071                 return "OT_OPPOSITE";
00072         case OT_NONE:
00073                 return "OT_NONE";
00074         case OT_UNSPEC:
00075                 return "OT_UNSPEC";
00076         case OT_BOOLPLACE:
00077                 return "OT_BOOLPLACE";
00078         }
00079         return "OT_IS_BOGUS!!";
00080 }
00081 
00082 /**
00083  *                      N M G _ P R _ O R I E N T
00084  *
00085  *      Print the orientation in a nice, english form
00086  */
00087 void
00088 nmg_pr_orient(int orientation, const char *h)
00089 {
00090         switch (orientation) {
00091         case OT_SAME : bu_log("%s%8s orientation\n", h, "SAME"); break;
00092         case OT_OPPOSITE : bu_log("%s%8s orientation\n", h, "OPPOSITE"); break;
00093         case OT_NONE : bu_log("%s%8s orientation\n", h, "NONE"); break;
00094         case OT_UNSPEC : bu_log("%s%8s orientation\n", h, "UNSPEC"); break;
00095         case OT_BOOLPLACE : bu_log("%s%8s orientation\n", h, "BOOLPLACE"); break;
00096         default : bu_log("%s%8s orientation\n", h, "BOGUS!!!"); break;
00097         }
00098 }
00099 
00100 /**
00101  *                      N M G _ P R _ M
00102  */
00103 void
00104 nmg_pr_m(const struct model *m)
00105 {
00106         const struct nmgregion *r;
00107 
00108         bu_log("MODEL %8x\n", m);
00109         if (!m || m->magic != NMG_MODEL_MAGIC) {
00110                 bu_log("bad model magic\n");
00111                 return;
00112         }
00113         bu_log("%ld maxindex\n", m->maxindex);
00114 
00115         for( BU_LIST_FOR( r, nmgregion, &m->r_hd ) )  {
00116                 nmg_pr_r(r, (char *)NULL);
00117         }
00118 }
00119 static char nmg_pr_padstr[128];
00120 
00121 /**
00122  *                      M K P A D
00123  *
00124  *  NOTE:  All the nmg_pr_*() routines take an "h" (header string) pointer.
00125  *  This can be an arbitrary caller-provided string, as long as it is kept
00126  *  short.  The string will be copied over into nmg_pr_padstr[], and
00127  *  "h" will be changed to point there, so spaces can be added to the end.
00128  */
00129 #define MKPAD(_h) { \
00130         if (!_h) { _h = nmg_pr_padstr; nmg_pr_padstr[0] = '\0'; } \
00131         else if( (_h) < nmg_pr_padstr || (_h) >= nmg_pr_padstr+sizeof(nmg_pr_padstr) )  { \
00132                 (void)strncpy(nmg_pr_padstr, (_h), sizeof(nmg_pr_padstr)/2); \
00133                 _h = nmg_pr_padstr; \
00134         } else { if (strlen(_h) < sizeof(nmg_pr_padstr)-4) (void)strcat(_h, "   "); } }
00135 
00136 #define Return  { h[strlen(h)-3] = '\0'; return; }
00137 
00138 /**
00139  *                      N M G _ P R _ R
00140  */
00141 void
00142 nmg_pr_r(const struct nmgregion *r, char *h)
00143 {
00144         struct shell *s;
00145 
00146         bu_log("REGION %8x\n", r);
00147 
00148         MKPAD(h);
00149 
00150         if (!r || r->l.magic != NMG_REGION_MAGIC) {
00151                 bu_log("bad region magic\n");
00152                 Return;
00153         }
00154 
00155         bu_log("%8x m_p\n", r->m_p);
00156         bu_log("%8x l.forw\n", r->l.forw);
00157         bu_log("%8x l.back\n", r->l.back);
00158         bu_log("%8x ra_p\n", r->ra_p);
00159 
00160         for( BU_LIST_FOR( s, shell, &r->s_hd ) )  {
00161                 nmg_pr_s(s, h);
00162         }
00163         Return;
00164 }
00165 
00166 /**
00167  *                      N M G _ P R _ S A
00168  */
00169 void
00170 nmg_pr_sa(const struct shell_a *sa, char *h)
00171 {
00172         MKPAD(h);
00173 
00174         bu_log("%sSHELL_A %8x\n", h, sa);
00175         if (!sa || sa->magic != NMG_SHELL_A_MAGIC) {
00176                 bu_log("bad shell_a magic\n");
00177                 Return;
00178         }
00179 
00180         bu_log("%s%f %f %f Min\n", h, sa->min_pt[X], sa->min_pt[Y],
00181                 sa->min_pt[Z]);
00182         bu_log("%s%f %f %f Max\n", h, sa->max_pt[X], sa->max_pt[Y],
00183                 sa->max_pt[Z]);
00184 
00185         Return;
00186 }
00187 
00188 /**
00189  *                      N M G _ P R _ L G
00190  */
00191 void
00192 nmg_pr_lg(const struct loop_g *lg, char *h)
00193 {
00194         MKPAD(h);
00195         NMG_CK_LOOP_G(lg);
00196 
00197         bu_log("%sLOOP_G %8x\n", h, lg);
00198         bu_log("%s%f %f %f Min\n", h, lg->min_pt[X], lg->min_pt[Y],
00199                 lg->min_pt[Z]);
00200         bu_log("%s%f %f %f Max\n", h, lg->max_pt[X], lg->max_pt[Y],
00201                 lg->max_pt[Z]);
00202 
00203         Return;
00204 }
00205 
00206 /**
00207  *                      N M G _ P R _ F G
00208  */
00209 void
00210 nmg_pr_fg(const long int *magic, char *h)
00211 {
00212         const struct face_g_snurb *fgs;
00213         int ncoords;
00214         int i,j,k,l;
00215 
00216         MKPAD(h);
00217 
00218         switch( *magic )  {
00219         case NMG_FACE_G_PLANE_MAGIC:
00220                 bu_log("%sFACE_G_PLANE %8x\n", h, magic);
00221 
00222                 bu_log("%s%fX + %fY + %fZ = %f\n", h,
00223                         V4ARGS( ((struct face_g_plane *)magic)->N ) );
00224                 break;
00225         case NMG_FACE_G_SNURB_MAGIC:
00226                 fgs = (struct face_g_snurb *)magic;
00227                 bu_log("%sFACE_G_SNURB %8x\n", h, magic);
00228                 bu_log( "%s  order (%d, %d)\n", h, fgs->order[0], fgs->order[1] );
00229                 bu_log( "%s  U knots: size=%d", h, fgs->u.k_size );
00230                 for( i=0 ; i<fgs->u.k_size ; i++ )
00231                         bu_log( " %f", fgs->u.knots[i] );
00232                 bu_log( "\n%s  V knots: size=%d", h, fgs->v.k_size );
00233                 for( i=0 ; i<fgs->v.k_size ; i++ )
00234                         bu_log( " %f", fgs->v.knots[i] );
00235                 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 );
00236                 ncoords = RT_NURB_EXTRACT_COORDS( fgs->pt_type );
00237                 l = 0;
00238                 for( i=0 ; i<fgs->s_size[0] ; i++ )
00239                 {
00240                         bu_log( "%s  ", h );
00241                         for( j=0 ; j<fgs->s_size[1] ; j++ )
00242                         {
00243                                 bu_log( " (", h );
00244                                 for( k=0 ; k<ncoords ; k++ )
00245                                         bu_log( "%f ", fgs->ctl_points[l+k] );
00246                                 bu_log( ")" );
00247                                 l += ncoords;
00248                         }
00249                         bu_log( "\n" );
00250                 }
00251                 break;
00252         default:
00253                 rt_bomb("nmg_pr_fg() bad magic\n");
00254         }
00255 
00256         Return;
00257 }
00258 
00259 /**
00260  *                      N M G _ P R _ S
00261  */
00262 void
00263 nmg_pr_s(const struct shell *s, char *h)
00264 {
00265         const struct faceuse    *fu;
00266         const struct loopuse    *lu;
00267         const struct edgeuse    *eu;
00268 
00269         MKPAD(h);
00270 
00271         bu_log("%sSHELL %8x\n", h, s);
00272         if (!s || s->l.magic != NMG_SHELL_MAGIC) {
00273                 bu_log("bad shell magic\n");
00274                 Return;
00275         }
00276 
00277         bu_log("%s%8x r_p\n", h, s->r_p);
00278         bu_log("%s%8x l.forw\n", h, s->l.forw );
00279         bu_log("%s%8x l.back\n", h, s->l.back );
00280         bu_log("%s%8x sa_p\n", h, s->sa_p );
00281         if (s->sa_p)
00282                 nmg_pr_sa(s->sa_p, h);
00283 
00284         for( BU_LIST_FOR( fu, faceuse, &s->fu_hd ) )  {
00285                 nmg_pr_fu(fu, h);
00286         }
00287 
00288         for( BU_LIST_FOR( lu, loopuse, &s->lu_hd ) )  {
00289                 nmg_pr_lu(lu, h);
00290         }
00291 
00292         for( BU_LIST_FOR( eu, edgeuse, &s->eu_hd ) )  {
00293                 nmg_pr_eu(eu, h);
00294         }
00295         if (s->vu_p)
00296                 nmg_pr_vu(s->vu_p, h);
00297 
00298         Return;
00299 }
00300 
00301 /**
00302  *                      N M G _ P R _ S _ B R I E F L Y
00303  */
00304 void
00305 nmg_pr_s_briefly(const struct shell *s, char *h)
00306 {
00307         const struct faceuse    *fu;
00308         const struct loopuse    *lu;
00309         const struct edgeuse    *eu;
00310 
00311         MKPAD(h);
00312 
00313         bu_log("%sSHELL %8x\n", h, s);
00314         if (!s || s->l.magic != NMG_SHELL_MAGIC) {
00315                 bu_log("bad shell magic\n");
00316                 Return;
00317         }
00318 
00319         for( BU_LIST_FOR( fu, faceuse, &s->fu_hd ) )  {
00320                 nmg_pr_fu_briefly(fu, h);
00321         }
00322 
00323         for( BU_LIST_FOR( lu, loopuse, &s->lu_hd ) )  {
00324                 nmg_pr_lu_briefly(lu, h);
00325         }
00326 
00327         for( BU_LIST_FOR( eu, edgeuse, &s->eu_hd ) )  {
00328                 nmg_pr_eu_briefly(eu, h);
00329         }
00330         if (s->vu_p)
00331                 nmg_pr_vu_briefly(s->vu_p, h);
00332 
00333         Return;
00334 }
00335 
00336 /**
00337  *                      N M G _ P R _ F
00338  */
00339 void
00340 nmg_pr_f(const struct face *f, char *h)
00341 {
00342         MKPAD(h);
00343         NMG_CK_FACE(f);
00344 
00345         bu_log("%sFACE %8x\n", h, f);
00346         bu_log("%s%8x fu_p\n", h, f->fu_p);
00347         bu_log("%s%8x g.magic_p\n", h, f->g.magic_p);
00348 
00349         bu_log("%s%f %f %f Min\n", h, f->min_pt[X], f->min_pt[Y],
00350                 f->min_pt[Z]);
00351         bu_log("%s%f %f %f Max\n", h, f->max_pt[X], f->max_pt[Y],
00352                 f->max_pt[Z]);
00353 
00354         bu_log("%s%d Flip\n", h, f->flip );
00355 
00356         if (f->g.plane_p)
00357                 nmg_pr_fg(f->g.magic_p, h);
00358 
00359         Return;
00360 }
00361 
00362 /**
00363  *                      N M G _ P R _ F U
00364  */
00365 void
00366 nmg_pr_fu(const struct faceuse *fu, char *h)
00367 {
00368         const struct loopuse *lu;
00369 
00370         MKPAD(h);
00371         NMG_CK_FACEUSE(fu);
00372 
00373         bu_log("%sFACEUSE %8x\n", h, fu);
00374 
00375         if (!fu || fu->l.magic != NMG_FACEUSE_MAGIC) {
00376                 bu_log("bad faceuse magic\n");
00377                 Return;
00378         }
00379 
00380         bu_log("%s%8x s_p\n", h, fu->s_p);
00381         bu_log("%s%8x l.forw\n", h, fu->l.forw);
00382         bu_log("%s%8x l.back\n", h, fu->l.back);
00383         bu_log("%s%8x fumate_p\n", h, fu->fumate_p);
00384         nmg_pr_orient(fu->orientation, h);
00385 
00386         bu_log("%s%8x f_p\n", h, fu->f_p);
00387         if (fu->f_p)
00388                 nmg_pr_f(fu->f_p, h);
00389 
00390         for( BU_LIST_FOR( lu, loopuse, &fu->lu_hd ) )  {
00391                 nmg_pr_lu(lu, h);
00392         }
00393         Return;
00394 }
00395 
00396 /**
00397  *                      N M G _ P R _ F U _ B R I E F L Y
00398  */
00399 void
00400 nmg_pr_fu_briefly(const struct faceuse *fu, char *h)
00401 {
00402         const struct loopuse *lu;
00403         struct face *f;
00404 
00405         MKPAD(h);
00406         NMG_CK_FACEUSE(fu);
00407         f = fu->f_p;
00408 
00409         if( f->g.magic_p && *f->g.magic_p == NMG_FACE_G_PLANE_MAGIC )
00410         {
00411                 bu_log("%sFACEUSE %8x (%s) f_p=x%x fg=x%x flip=%d pl= %f %f %f %f\n",
00412                         h, fu, nmg_orientation(fu->orientation), fu->f_p, f->g.magic_p, fu->f_p->flip, V4ARGS( f->g.plane_p->N ));
00413         }
00414         else
00415                 bu_log("%sFACEUSE %8x (%s) f_p=x%x\n",
00416                         h, fu, nmg_orientation(fu->orientation), fu->f_p);
00417 
00418         for( BU_LIST_FOR( lu, loopuse, &fu->lu_hd ) )  {
00419                 nmg_pr_lu_briefly(lu, h);
00420         }
00421         Return;
00422 }
00423 
00424 /**
00425  *                      N M G _ P R _ L
00426  */
00427 void
00428 nmg_pr_l(const struct loop *l, char *h)
00429 {
00430         MKPAD(h);
00431         NMG_CK_LOOP(l);
00432 
00433         bu_log("%sLOOP %8x\n", h, l);
00434         if (!l || l->magic != NMG_LOOP_MAGIC) {
00435                 bu_log("bad loop magic\n");
00436                 Return;
00437         }
00438         bu_log("%s%8x lu_p\n", h, l->lu_p);
00439         bu_log("%s%8x lg_p\n", h, l->lg_p);
00440         if (l->lg_p)
00441                 nmg_pr_lg(l->lg_p, h);
00442 
00443         Return;
00444 }
00445 
00446 /**
00447  *                      N M G _ P R _ L U
00448  */
00449 void
00450 nmg_pr_lu(const struct loopuse *lu, char *h)
00451 {
00452         const struct edgeuse    *eu;
00453         const struct vertexuse *vu;
00454         long            magic1;
00455 
00456         MKPAD(h);
00457         NMG_CK_LOOPUSE(lu);
00458 
00459         bu_log("%sLOOPUSE %8x\n", h, lu);
00460 
00461         switch (*lu->up.magic_p) {
00462         case NMG_SHELL_MAGIC    : bu_log("%s%8x up.s_p\n", h, lu->up.s_p);
00463                                         break;
00464         case NMG_FACEUSE_MAGIC  : bu_log("%s%8x up.fu_p\n", h, lu->up.fu_p);
00465                                         break;
00466         default                 : bu_log("Bad loopuse parent magic\n");
00467                                         Return;
00468         }
00469 
00470         bu_log("%s%8x l.forw\n", h, lu->l.forw);
00471         bu_log("%s%8x l.back\n", h, lu->l.back);
00472         bu_log("%s%8x lumate_p\n", h, lu->lumate_p);
00473         nmg_pr_orient(lu->orientation, h);
00474         bu_log("%s%8x l_p\n", h, lu->l_p);
00475         if (lu->l_p)
00476                 nmg_pr_l(lu->l_p, h);
00477 
00478 
00479         bu_log("%s%8x down_hd.magic\n", h, lu->down_hd.magic);
00480         bu_log("%s%8x down_hd.forw\n", h, lu->down_hd.forw);
00481         bu_log("%s%8x down_hd.back\n", h, lu->down_hd.back);
00482 
00483         magic1 = BU_LIST_FIRST_MAGIC( &lu->down_hd );
00484         if (magic1 == NMG_VERTEXUSE_MAGIC) {
00485                 vu = BU_LIST_PNEXT( vertexuse, &lu->down_hd );
00486                 bu_log("%s%8x down_hd->forw (vu)\n", h, vu);
00487                 nmg_pr_vu(vu, h);
00488         }
00489         else if (magic1 == NMG_EDGEUSE_MAGIC) {
00490                 for( BU_LIST_FOR( eu, edgeuse, &lu->down_hd ) )  {
00491                         nmg_pr_eu(eu, h);
00492                 }
00493         }
00494         else
00495                 bu_log("bad loopuse child magic\n");
00496 
00497         Return;
00498 }
00499 
00500 /**
00501  *                      N M G _ P R _ L U _ B R I E F L Y
00502  */
00503 void
00504 nmg_pr_lu_briefly(const struct loopuse *lu, char *h)
00505 {
00506         const struct edgeuse    *eu;
00507         const struct vertexuse *vu;
00508         long            magic1;
00509 
00510         MKPAD(h);
00511         NMG_CK_LOOPUSE(lu);
00512 
00513         bu_log("%sLOOPUSE %8x, lumate_p=x%x (%s) \n",
00514                 h, lu, lu->lumate_p, nmg_orientation(lu->orientation) );
00515 
00516         magic1 = BU_LIST_FIRST_MAGIC( &lu->down_hd );
00517         if (magic1 == NMG_VERTEXUSE_MAGIC) {
00518                 vu = BU_LIST_PNEXT( vertexuse, &lu->down_hd );
00519                 bu_log("%s%8x down_hd->forw (vu)\n", h, vu);
00520                 nmg_pr_vu_briefly(vu, h);
00521         }
00522         else if (magic1 == NMG_EDGEUSE_MAGIC) {
00523                 for( BU_LIST_FOR( eu, edgeuse, &lu->down_hd ) )  {
00524                         nmg_pr_eu_briefly(eu, h);
00525                 }
00526         }
00527         else
00528                 bu_log("bad loopuse child magic\n");
00529 
00530         Return;
00531 }
00532 
00533 /**
00534  *                      N M G _ P R _ E G
00535  *
00536  * Expects a pointer to the magic number of an edge geometry structure
00537  * either edge_g_lseg or edge_g_cnurb structures.
00538  */
00539 void
00540 nmg_pr_eg(const long int *eg_magic_p, char *h)
00541 {
00542         MKPAD(h);
00543         NMG_CK_EDGE_G_EITHER(eg_magic_p);
00544 
00545         switch( *eg_magic_p )
00546         {
00547                 case NMG_EDGE_G_LSEG_MAGIC:
00548                 {
00549                         struct edge_g_lseg *eg_l=(struct edge_g_lseg *)eg_magic_p;
00550 
00551                         bu_log("%sEDGE_G_LSEG %8x pt:(%f %f %f)\n",
00552                                 h, eg_l, V3ARGS(eg_l->e_pt));
00553                         bu_log("%s       eu uses=%d  dir:(%f %f %f)\n",
00554                                 h, bu_list_len( &eg_l->eu_hd2 ), V3ARGS(eg_l->e_dir));
00555                         break;
00556                 }
00557                 case NMG_EDGE_G_CNURB_MAGIC:
00558                 {
00559                         struct edge_g_cnurb *eg_c=(struct edge_g_cnurb *)eg_magic_p;
00560                         int i,j,l;
00561                         int ncoords;
00562 
00563                         bu_log( "%sEDGE_G_CNURB %8x\n" , h , eg_c );
00564                         bu_log( "%s  order=%d, %d ctl pts, pt_type=%d\n",
00565                                 h, eg_c->order, eg_c->c_size, eg_c->pt_type );
00566                         bu_log( "%s  knot vector (len=%d):", h, eg_c->k.k_size );
00567                         for( i=0 ; i<eg_c->k.k_size ; i++ )
00568                                 bu_log( " %f", eg_c->k.knots[i] );
00569                         bu_log( "\n" );
00570                         ncoords = RT_NURB_EXTRACT_COORDS( eg_c->pt_type );
00571                         l = 0;
00572                         bu_log( "%s  control points: ", h );
00573                         for( i=0 ; i<eg_c->c_size ; i++ )
00574                         {
00575                                 bu_log( "(" );
00576                                 for( j=0 ; j<ncoords ; j++ )
00577                                         bu_log( "%f ", eg_c->ctl_points[l+j] );
00578                                 bu_log( ")" );
00579                                 l += ncoords;
00580                         }
00581                         bu_log( "\n" );
00582                         break;
00583                 }
00584         }
00585 
00586         Return;
00587 }
00588 
00589 /**
00590  *                      N M G _ P R _ E
00591  */
00592 void
00593 nmg_pr_e(const struct edge *e, char *h)
00594 {
00595         MKPAD(h);
00596         NMG_CK_EDGE(e);
00597 
00598         bu_log("%sEDGE %8x\n", h, e);
00599         if (!e || e->magic != NMG_EDGE_MAGIC) {
00600                 bu_log("bad edge magic\n");
00601                 Return;
00602         }
00603         bu_log("%s%8x eu_p\n", h, e->eu_p);
00604 
00605         Return;
00606 }
00607 
00608 /**
00609  *                      N M G _ P R _ E U
00610  */
00611 void
00612 nmg_pr_eu(const struct edgeuse *eu, char *h)
00613 {
00614         MKPAD(h);
00615         NMG_CK_EDGEUSE(eu);
00616 
00617         bu_log("%sEDGEUSE %8x\n", h, eu);
00618 
00619         switch (*eu->up.magic_p) {
00620         case NMG_SHELL_MAGIC    : bu_log("%s%8x up.s_p\n", h, eu->up.s_p);
00621                                 break;
00622         case NMG_LOOPUSE_MAGIC  : bu_log("%s%8x up.lu_p\n", h, eu->up.lu_p);
00623                                 break;
00624         default                 : bu_log("bad edgeuse parent magic\n");
00625                                 Return;
00626         }
00627         bu_log("%s%8x l.forw\n", h, eu->l.forw);
00628         bu_log("%s%8x l.back\n", h, eu->l.back);
00629         bu_log("%s%8x eumate_p\n", h, eu->eumate_p);
00630         bu_log("%s%8x radial_p\n", h, eu->radial_p);
00631         nmg_pr_orient(eu->orientation, h);
00632         bu_log("%s%8x e_p\n", h, eu->e_p);
00633         bu_log("%s%8x vu_p\n", h, eu->vu_p);
00634         bu_log("%s%8x g.magic_p\n", h, eu->g.magic_p);
00635         nmg_pr_e(eu->e_p, h);
00636         nmg_pr_vu(eu->vu_p, h);
00637 
00638         if (eu->g.magic_p)
00639                 nmg_pr_eg(eu->g.magic_p, h);
00640 
00641         Return;
00642 }
00643 
00644 /**
00645  *                      N M G _ P R _ E U _ B R I E F L Y
00646  */
00647 void
00648 nmg_pr_eu_briefly(const struct edgeuse *eu, char *h)
00649 {
00650         MKPAD(h);
00651         NMG_CK_EDGEUSE(eu);
00652 
00653         bu_log("%sEDGEUSE %8x, g=%8x, e_p=%8x\n", h, eu, eu->g.magic_p, eu->e_p);
00654         nmg_pr_vu_briefly(eu->vu_p, h);
00655 
00656         Return;
00657 }
00658 
00659 /**
00660  *                      N M G _ P R _ E U _ E N D P O I N T S
00661  */
00662 void
00663 nmg_pr_eu_endpoints(const struct edgeuse *eu, char *h)
00664 {
00665         struct vertex_g *vg1, *vg2;
00666 
00667         MKPAD(h);
00668         NMG_CK_EDGEUSE(eu);
00669 
00670         vg1 = eu->vu_p->v_p->vg_p;
00671         vg2 = eu->eumate_p->vu_p->v_p->vg_p;
00672         NMG_CK_VERTEX_G(vg1);
00673         NMG_CK_VERTEX_G(vg2);
00674 
00675         bu_log("%sEDGEUSE %8x\n%s  (%g, %g, %g) -- (%g, %g, %g)\n", h, eu, h,
00676                 V3ARGS(vg1->coord),
00677                 V3ARGS(vg2->coord) );
00678 
00679         Return;
00680 }
00681 
00682 /**
00683  *                      N M G _ P R _ V G
00684  */
00685 void
00686 nmg_pr_vg(const struct vertex_g *vg, char *h)
00687 {
00688         MKPAD(h);
00689         NMG_CK_VERTEX_G(vg);
00690 
00691         if (!vg || vg->magic != NMG_VERTEX_G_MAGIC) {
00692                 bu_log("%sVERTEX_G %8x\n", h, vg);
00693                 bu_log("bad vertex_g magic\n");
00694                 Return;
00695         }
00696         bu_log("%sVERTEX_G %8x %f %f %f = XYZ coord\n",
00697                 h, vg, V3ARGS(vg->coord) );
00698         Return;
00699 }
00700 
00701 /**
00702  *                      N M G _ P R _ V
00703  */
00704 void
00705 nmg_pr_v(const struct vertex *v, char *h)
00706 {
00707         MKPAD(h);
00708         NMG_CK_VERTEX(v);
00709 
00710         bu_log("%sVERTEX %8x\n", h, v);
00711         if (!v || v->magic != NMG_VERTEX_MAGIC) {
00712                 bu_log("bad vertex magic\n");
00713                 Return;
00714         }
00715         /* vu_hd ? */
00716         bu_log("%s   vu_hd %8x\n", h, &v->vu_hd);
00717         bu_log("%s%8x vu_hd.forw\n", h, v->vu_hd.forw);
00718         bu_log("%s%8x vu_hd.back\n", h, v->vu_hd.back);
00719 
00720 
00721         bu_log("%s%8x vg_p\n", h, v->vg_p);
00722         if (v->vg_p)
00723                 nmg_pr_vg(v->vg_p, h);
00724 
00725         Return;
00726 }
00727 
00728 /**
00729  *                      N M G _ P R _ V U
00730  */
00731 void
00732 nmg_pr_vu(const struct vertexuse *vu, char *h)
00733 {
00734         MKPAD(h);
00735         NMG_CK_VERTEXUSE(vu);
00736 
00737         bu_log("%sVERTEXUSE %8x\n", h, vu);
00738         if (!vu || vu->l.magic != NMG_VERTEXUSE_MAGIC) {
00739                 bu_log("bad vertexuse magic\n");
00740                 Return;
00741         }
00742 
00743         switch (*vu->up.magic_p) {
00744         case NMG_SHELL_MAGIC    : bu_log("%s%8x up.s_p\n", h, vu->up.s_p); break;
00745         case NMG_LOOPUSE_MAGIC  : bu_log("%s%8x up.lu_p\n", h, vu->up.lu_p); break;
00746         case NMG_EDGEUSE_MAGIC  : bu_log("%s%8x up.eu_p\n", h, vu->up.eu_p); break;
00747         default                 : bu_log("bad vertexuse parent magic\n");
00748                                 Return;
00749         }
00750         bu_log("%s%8x l.forw\n", h, vu->l.forw);
00751         bu_log("%s%8x l.back\n", h, vu->l.back);
00752         if( vu->a.magic_p )  switch( *vu->a.magic_p )  {
00753         case NMG_VERTEXUSE_A_PLANE_MAGIC:
00754                 bu_log("%s%8x a.plane_p\n", h, vu->a.plane_p);
00755                 bu_log("%s normal: %f %f %f\n", h, V3ARGS( vu->a.plane_p->N ) );
00756                 break;
00757         case NMG_VERTEXUSE_A_CNURB_MAGIC:
00758                 bu_log("%s%8x a.cnurb_p\n", h, vu->a.cnurb_p);
00759                 break;
00760         }
00761         bu_log("%s%8x v_p\n", h, vu->v_p);
00762         nmg_pr_v(vu->v_p, h);
00763         if( vu->a.magic_p )  nmg_pr_vua( vu->a.magic_p, h );
00764 
00765         Return;
00766 }
00767 
00768 /**
00769  *                      N M G _ P R _ V U _ B R I E F L Y
00770  */
00771 void
00772 nmg_pr_vu_briefly(const struct vertexuse *vu, char *h)
00773 {
00774         const struct vertex_g   *vg;
00775 
00776         MKPAD(h);
00777         NMG_CK_VERTEXUSE(vu);
00778         NMG_CK_VERTEX(vu->v_p);
00779 
00780         if( (vg = vu->v_p->vg_p) )  {
00781                 NMG_CK_VERTEX_G(vg);
00782                 bu_log("%sVERTEXUSE %8x, v=x%x, %f %f %f\n", h, vu, vu->v_p,
00783                         V3ARGS(vg->coord) );
00784         } else {
00785                 bu_log("%sVERTEXUSE %8x, v=x%x\n", h, vu, vu->v_p);
00786         }
00787 
00788         Return;
00789 }
00790 
00791 /**
00792  *                      N M G _ P R _ V U A
00793  */
00794 void
00795 nmg_pr_vua(const long int *magic_p, char *h)
00796 {
00797         MKPAD(h);
00798 
00799         bu_log("%sVERTEXUSE_A %8x\n", h, magic_p);
00800         if (!magic_p)  {
00801                 bu_log("bad vertexuse_a magic\n");
00802                 Return;
00803         }
00804 
00805         switch( *magic_p )  {
00806         case NMG_VERTEXUSE_A_PLANE_MAGIC:
00807                 bu_log("%s N=(%g, %g, %g, %g)\n", h,
00808                         V3ARGS( ((struct vertexuse_a_plane *)magic_p)->N ) );
00809                 break;
00810         case NMG_VERTEXUSE_A_CNURB_MAGIC:
00811                 bu_log("%s param=(%g, %g, %g)\n", h,
00812                         V3ARGS( ((struct vertexuse_a_cnurb *)magic_p)->param ) );
00813                 break;
00814         }
00815 
00816         Return;
00817 }
00818 
00819 
00820 /**
00821  *                      N M G _ E U P R I N T
00822  */
00823 void
00824 nmg_euprint(const char *str, const struct edgeuse *eu)
00825 {
00826         const fastf_t   *eup;
00827         const fastf_t   *matep;
00828 
00829         NMG_CK_EDGEUSE(eu);
00830         NMG_CK_VERTEXUSE(eu->vu_p);
00831         NMG_CK_VERTEX(eu->vu_p->v_p);
00832         NMG_CK_VERTEX_G(eu->vu_p->v_p->vg_p);
00833 
00834         NMG_CK_EDGEUSE(eu->eumate_p);
00835         NMG_CK_VERTEXUSE(eu->eumate_p->vu_p);
00836         NMG_CK_VERTEX(eu->eumate_p->vu_p->v_p);
00837         NMG_CK_VERTEX_G(eu->eumate_p->vu_p->v_p->vg_p);
00838 
00839         eup = eu->vu_p->v_p->vg_p->coord;
00840         matep = eu->eumate_p->vu_p->v_p->vg_p->coord;
00841 
00842         bu_log("%s (%g, %g, %g -> %g, %g, %g)\n", str, eup[0], eup[1], eup[2],
00843                 matep[0], matep[1], matep[2]);
00844 }
00845 /**
00846  *                      N M G _ P R _ P T B L
00847  *
00848  *  Print an bu_ptbl array for inspection.
00849  */
00850 void
00851 nmg_pr_ptbl(const char *title, const struct bu_ptbl *tbl, int verbose)
00852 {
00853         register long   **lp;
00854 
00855         BU_CK_PTBL(tbl);
00856         bu_log("%s: bu_ptbl array with %d entries\n",
00857                 title, tbl->end );
00858 
00859         if( !verbose )  return;
00860 
00861         for( lp = (long **)BU_PTBL_BASEADDR(tbl);
00862              lp <= (long **)BU_PTBL_LASTADDR(tbl); lp++
00863         )  {
00864                 if( *lp == 0 )  {
00865                         bu_log("  %.8x NULL entry\n", *lp);
00866                         continue;
00867                 }
00868                 switch(**lp)  {
00869                 default:
00870                         bu_log("  %.8x %s\n", *lp, bu_identify_magic(**lp) );
00871                         break;
00872                 case NMG_EDGEUSE_MAGIC:
00873                         bu_log("  %.8x edgeuse vu=%x, far vu=%x\n",
00874                                 *lp,
00875                                 ((struct edgeuse *)*lp)->vu_p,
00876                                 BU_LIST_PNEXT_CIRC(edgeuse, *lp)->vu_p );
00877                         break;
00878                 case NMG_VERTEXUSE_MAGIC:
00879                         bu_log("  %.8x vertexuse v=%x\n",
00880                                 *lp,
00881                                 ((struct vertexuse *)*lp)->v_p );
00882                         break;
00883                 }
00884         }
00885 }
00886 
00887 /**
00888  *                      N M G _ P R _ P T B L _ V E R T _ L I S T
00889  *
00890  *  Print a ptbl array as a vertex list.
00891  */
00892 void
00893 nmg_pr_ptbl_vert_list(const char *str, const struct bu_ptbl *tbl, const fastf_t *mag)
00894 {
00895         int                     i;
00896         const struct vertexuse  **vup;
00897         const struct vertexuse  *vu;
00898         const struct vertex     *v;
00899         const struct vertex_g   *vg;
00900 
00901         bu_log("nmg_pr_ptbl_vert_list(%s):\n", str);
00902 
00903         vup = (const struct vertexuse **)tbl->buffer;
00904         for (i=0 ; i < tbl->end ; ++i) {
00905                 vu = vup[i];
00906                 if( vu->l.magic != NMG_VERTEXUSE_MAGIC )
00907                 {
00908                         bu_log( "\tWARNING: vertexuse #%d has bad MAGIC (%x)\n" , i, vu->l.magic );
00909                         continue;
00910                 }
00911                 NMG_CK_VERTEXUSE(vu);
00912                 v = vu->v_p;
00913                 NMG_CK_VERTEX(v);
00914                 vg = v->vg_p;
00915                 NMG_CK_VERTEX_G(vg);
00916                 bu_log("%d\t%g, %g, %g\t", i, V3ARGS(vg->coord) );
00917                 if (*vu->up.magic_p == NMG_EDGEUSE_MAGIC) {
00918                         bu_log("EDGEUSE");
00919                 } else if (*vu->up.magic_p == NMG_LOOPUSE_MAGIC) {
00920                         bu_log("LOOPUSE");
00921                         if ((struct vertexuse *)vu->up.lu_p->down_hd.forw != vu) {
00922                                 bu_log("ERROR vertexuse's parent disowns us!\n");
00923                                 if (((struct vertexuse *)(vu->up.lu_p->lumate_p->down_hd.forw))->l.magic == NMG_VERTEXUSE_MAGIC)
00924                                         rt_bomb("lumate has vertexuse\n");
00925                                 rt_bomb("lumate has garbage\n");
00926                         }
00927                 } else {
00928                         bu_log("vu up UNKNOWN");
00929                 }
00930                 bu_log("\tv=x%x, vu=x%x, dist=%g\n", v , vu, mag[i] );
00931         }
00932 }
00933 
00934 /**
00935  *                      N M G _ P R _ O N E _ E U _ V E C S
00936  *
00937  *  Common formatting code for edgeuses and edgeuse mates.
00938  *  Does not mind wire edges.
00939  */
00940 void
00941 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)
00942 {
00943         const struct loopuse    *lu;
00944         const struct faceuse    *fu;
00945         const struct face       *f;
00946         const struct shell      *s;
00947         char                    *lu_orient;
00948         char                    *fu_orient;
00949 
00950         NMG_CK_EDGEUSE(eu);
00951         lu = (struct loopuse *)NULL;
00952         lu_orient = "W";
00953         fu = (struct faceuse *)NULL;
00954         fu_orient = "W";
00955         f = (struct face *)NULL;
00956         if( *eu->up.magic_p == NMG_LOOPUSE_MAGIC )  {
00957                 lu = eu->up.lu_p;
00958                 NMG_CK_LOOPUSE(lu);
00959                 /* +3 is to skip the "OT_" prefix */
00960                 lu_orient = nmg_orientation(lu->orientation)+3;
00961                 if( *lu->up.magic_p == NMG_FACEUSE_MAGIC )  {
00962                         fu = lu->up.fu_p;
00963                         NMG_CK_FACEUSE(fu);
00964                         fu_orient = nmg_orientation(fu->orientation)+3;
00965                         f = fu->f_p;
00966                         s = fu->s_p;
00967                 } else {
00968                         s = lu->up.s_p;
00969                 }
00970         } else {
00971                 s = eu->up.s_p;
00972         }
00973         NMG_CK_SHELL(s);
00974         if( f && *f->g.magic_p == NMG_FACE_G_SNURB_MAGIC )
00975         {
00976                 bu_log(" %8.8x, lu=%8.8x=%1.1s, f=%8.8x, fu=%8.8x=%1.1s, s=%8.8x SNURB\n",
00977                         eu,
00978                         lu, lu_orient,
00979                         f,
00980                         fu, fu_orient,
00981                         s );
00982         }
00983         else
00984         {
00985                 bu_log(" %8.8x, lu=%8.8x=%1.1s, f=%8.8x, fu=%8.8x=%1.1s, s=%8.8x %g deg\n",
00986                         eu,
00987                         lu, lu_orient,
00988                         f,
00989                         fu, fu_orient,
00990                         s,
00991                         nmg_measure_fu_angle(eu, xvec, yvec, zvec) * bn_radtodeg );
00992         }
00993 }
00994 
00995 /**
00996  *                      N M G _ P R _ F U _ A R O U N D _ E U _ V E C S
00997  */
00998 void
00999 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)
01000 {
01001         const struct edgeuse    *eu1;
01002 
01003         NMG_CK_EDGEUSE(eu);
01004         BN_CK_TOL(tol);
01005         bu_log("nmg_pr_fu_around_eu_vecs(eu=x%x) e=x%x\n", eu, eu->e_p);
01006 
01007         /* To go correct way around, start with arg's mate,
01008          * so that arg, then radial, will follow.
01009          */
01010         eu = eu->eumate_p;
01011 
01012         eu1 = eu;
01013         do {
01014                 /* First, the edgeuse mate */
01015                 nmg_pr_one_eu_vecs( eu1, xvec, yvec, zvec, tol );
01016 
01017                 /* Second, the edgeuse itself (mate's mate) */
01018                 eu1 = eu1->eumate_p;
01019                 nmg_pr_one_eu_vecs( eu1, xvec, yvec, zvec, tol );
01020 
01021                 /* Now back around to the radial edgeuse */
01022                 eu1 = eu1->radial_p;
01023         } while( eu1 != eu );
01024 }
01025 
01026 /**
01027  *                      N M G _ P R _ F U _ A R O U N D _ E U
01028  *
01029  *  A debugging routine to print all the faceuses around a given edge,
01030  *  starting with the given edgeuse.
01031  *  The normal of the  first face is considered to be "0 degrees",
01032  *  and the rest are measured from there.
01033  */
01034 void
01035 nmg_pr_fu_around_eu(const struct edgeuse *eu, const struct bn_tol *tol)
01036 {
01037         vect_t                  xvec, yvec, zvec;
01038 
01039         NMG_CK_EDGEUSE(eu);
01040         BN_CK_TOL(tol);
01041         bu_log("nmg_pr_fu_around_eu(x%x)\n", eu);
01042 
01043         if( eu->vu_p->v_p == eu->eumate_p->vu_p->v_p || *eu->g.magic_p == NMG_EDGE_G_CNURB_MAGIC )
01044         {
01045                 VSET( xvec , 1 , 0 , 0 );
01046                 VSET( yvec , 0 , 1 , 0 );
01047                 VSET( zvec , 0 , 0 , 1 );
01048         }
01049         else
01050         {
01051                 /* Erect coordinate system around eu */
01052                 nmg_eu_2vecs_perp( xvec, yvec, zvec, eu, tol );
01053         }
01054 
01055         nmg_pr_fu_around_eu_vecs( eu, xvec, yvec, zvec, tol );
01056 }
01057 
01058 /**
01059  *                      N M G _ P L _ L U _ A R O U N D _ E U
01060  *
01061  *  Plot all the loopuses around an edgeuse.
01062  *  Don't bother drawing the loopuse mates.
01063  */
01064 void
01065 nmg_pl_lu_around_eu(const struct edgeuse *eu)
01066 {
01067         FILE                    *fp;
01068         const struct edgeuse    *eu1;
01069         const struct loopuse    *lu1;
01070         long                    *b;
01071         static int              num;
01072         char                    buf[128];
01073 
01074         NMG_CK_EDGEUSE(eu);
01075 
01076         sprintf(buf, "eu_vicinity%d.pl", num++);
01077         if( (fp = fopen(buf, "w")) == NULL )  {
01078                 perror(buf);
01079                 return;
01080         }
01081 
01082         b = (long *)bu_calloc( nmg_find_model((long *)eu)->maxindex, sizeof(long),
01083                 "nmg_pl_lu_around_eu flag[]" );
01084 
01085         /* To go correct way around, start with arg's mate,
01086          * so that arg, then radial, will follow.
01087          */
01088         eu = eu->eumate_p;
01089 
01090         eu1 = eu;
01091         do {
01092                 /* First, the edgeuse mate */
01093                 /* Second, the edgeuse itself (mate's mate) */
01094                 eu1 = eu1->eumate_p;
01095 
01096                 if (*eu1->up.magic_p == NMG_LOOPUSE_MAGIC )  {
01097                         lu1 = eu1->up.lu_p;
01098                         nmg_pl_lu(fp, lu1, b, 80, 100, 170);
01099                 }
01100 
01101                 /* Now back around to the radial edgeuse */
01102                 eu1 = eu1->radial_p;
01103         } while( eu1 != eu );
01104 
01105         bu_free( (char *)b, "nmg_pl_lu_around_eu flag[]" );
01106         fclose(fp);
01107         bu_log("Wrote %s\n", buf);
01108 }
01109 
01110 /**
01111  *                      N M G _ P R _ F U S _ I N _ F G
01112  *
01113  *  For either kind of face geometry, print the list of all faces & faceuses
01114  *  that share this geometry.
01115  */
01116 void
01117 nmg_pr_fus_in_fg(const long int *fg_magic)
01118 {
01119         struct face     *f;
01120 
01121         NMG_CK_FACE_G_EITHER(fg_magic);
01122         bu_log("nmg_pr_fus_in_fg(x%x):\n", fg_magic);
01123         for( BU_LIST_FOR( f, face, &(((struct face_g_plane *)fg_magic)->f_hd) ) )  {
01124                 NMG_CK_FACE(f);
01125                 NMG_CK_FACEUSE(f->fu_p);
01126                 bu_log(" f=x%x, fu=x%x, fumate=x%x\n",
01127                         f, f->fu_p, f->fu_p->fumate_p );
01128         }
01129 }
01130 
01131 /*
01132  * Local Variables:
01133  * mode: C
01134  * tab-width: 8
01135  * c-basic-offset: 4
01136  * indent-tabs-mode: t
01137  * End:
01138  * ex: shiftwidth=4 tabstop=8
01139  */

Generated on Mon Sep 18 01:24:55 2006 for BRL-CAD by  doxygen 1.4.6