pr.c

Go to the documentation of this file.
00001 /*                            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 
00022 /** @addtogroup librt */
00023 /*@{*/
00024 
00025 /** @file pr.c
00026  *  Routines to print LIBRT data structures using bu_log().
00027  *
00028  *  Author -
00029  *      Michael John Muuss
00030  *
00031  *  Source -
00032  *      The U. S. Army Research Laboratory
00033  *      Aberdeen Proving Ground, Maryland  21005-5068  USA
00034  */
00035 /*@}*/
00036 
00037 #ifndef lint
00038 static const char RCSid[] = "@(#)$Header: /cvsroot/brlcad/brlcad/src/librt/pr.c,v 14.14 2006/09/16 02:04:25 lbutler Exp $ (ARL)";
00039 #endif
00040 
00041 #include "common.h"
00042 
00043 
00044 
00045 #include <stdio.h>
00046 #include <math.h>
00047 #include <string.h>
00048 #include "machine.h"
00049 #include "vmath.h"
00050 #include "bu.h"
00051 #include "raytrace.h"
00052 #include "./debug.h"
00053 
00054 
00055 /*
00056  *                      R T _ P R _ S O L T A B
00057  */
00058 void
00059 rt_pr_soltab(register const struct soltab *stp)
00060 {
00061         register int    id = stp->st_id;
00062 
00063         if( id <= 0 || id > ID_MAX_SOLID )  {
00064                 bu_log("stp=x%x, id=%d.\n", stp, id);
00065                 rt_bomb("rt_pr_soltab:  bad st_id");
00066         }
00067         bu_log("------------ %s (bit %d) %s ------------\n",
00068                 stp->st_dp->d_namep, stp->st_bit,
00069                 rt_functab[id].ft_name );
00070         VPRINT("Bound Sph CENTER", stp->st_center);
00071         bu_log("Approx Sph Radius = %g\n", INTCLAMP(stp->st_aradius));
00072         bu_log("Bounding Sph Radius = %g\n", INTCLAMP(stp->st_bradius));
00073         VPRINT("Bound RPP min", stp->st_min);
00074         VPRINT("Bound RPP max", stp->st_max);
00075         bu_pr_ptbl( "st_regions", &stp->st_regions, 1 );
00076         rt_functab[id].ft_print( stp );
00077 }
00078 
00079 /*
00080  *                      R T _ P R _ R E G I O N
00081  */
00082 void
00083 rt_pr_region(register const struct region *rp)
00084 {
00085         struct bu_vls   v;
00086 
00087         RT_CK_REGION(rp);
00088 
00089         bu_log("REGION %s (bit %d)\n", rp->reg_name, rp->reg_bit );
00090         bu_log("instnum=%d, id=%d, air=%d, gift_material=%d, los=%d\n",
00091                 rp->reg_instnum,
00092                 rp->reg_regionid, rp->reg_aircode,
00093                 rp->reg_gmater, rp->reg_los );
00094         if( rp->reg_is_fastgen != REGION_NON_FASTGEN )  {
00095                 bu_log("reg_is_fastgen = %s mode\n",
00096                         rp->reg_is_fastgen == REGION_FASTGEN_PLATE ?
00097                                 "plate" : "volume" );
00098         }
00099         if( rp->reg_mater.ma_color_valid )
00100                 bu_log("Color %d %d %d\n",
00101                         (int)rp->reg_mater.ma_color[0]*255.,
00102                         (int)rp->reg_mater.ma_color[1]*255.,
00103                         (int)rp->reg_mater.ma_color[2]*255. );
00104         if( rp->reg_mater.ma_temperature > 0 )
00105                 bu_log("Temperature %g degrees K\n", INTCLAMP(rp->reg_mater.ma_temperature) );
00106         if( rp->reg_mater.ma_shader && rp->reg_mater.ma_shader[0] != '\0' )
00107                 bu_log("Shader '%s'\n", rp->reg_mater.ma_shader );
00108 
00109         bu_vls_init(&v);
00110         rt_pr_tree_vls(&v, rp->reg_treetop);
00111         bu_log("%s %d %s\n", rp->reg_name,
00112                 rp->reg_instnum, bu_vls_addr(&v) );
00113         bu_vls_free(&v);
00114 }
00115 
00116 /*
00117  *                      R T _ P R _ P A R T I T I O N S
00118  *
00119  */
00120 void
00121 rt_pr_partitions(const struct rt_i *rtip, register const struct partition *phead, const char *title)
00122 {
00123         register const struct partition *pp;
00124         struct bu_vls           v;
00125 
00126         RT_CHECK_RTI(rtip);
00127 
00128         bu_vls_init( &v );
00129         bu_log_indent_vls( &v );
00130         bu_vls_strcat( &v, "------" );
00131         bu_vls_strcat( &v, title );
00132         bu_vls_strcat( &v, "\n" );
00133         bu_log_indent_delta( 2 );
00134 
00135         for( pp = phead->pt_forw; pp != phead; pp = pp->pt_forw ) {
00136                 RT_CHECK_PT(pp);
00137                 rt_pr_pt_vls( &v, rtip, pp );
00138         }
00139         bu_log_indent_delta( -2 );
00140         bu_log_indent_vls( &v );
00141         bu_vls_strcat( &v, "------\n");
00142 
00143         bu_log("%s", bu_vls_addr( &v ) );
00144         bu_vls_free( &v );
00145 }
00146 
00147 /*
00148  *                      R T _ P R _ P T _ V L S
00149  */
00150 void
00151 rt_pr_pt_vls(struct bu_vls *v, const struct rt_i *rtip, register const struct partition *pp)
00152 {
00153         register const struct soltab    *stp;
00154         register struct seg             **segpp;
00155 
00156         RT_CHECK_RTI(rtip);
00157         RT_CHECK_PT(pp);
00158         BU_CK_VLS(v);
00159 
00160         bu_log_indent_vls( v );
00161         bu_vls_printf( v, "%.8lx: PT ", (long)pp );
00162 
00163         stp = pp->pt_inseg->seg_stp;
00164         bu_vls_printf(v, "%s (%s#%ld) ",
00165                 stp->st_dp->d_namep,
00166                 rt_functab[stp->st_id].ft_name+3,
00167                 stp->st_bit );
00168 
00169         stp = pp->pt_outseg->seg_stp;
00170         bu_vls_printf(v, "%s (%s#%ld) ",
00171                 stp->st_dp->d_namep,
00172                 rt_functab[stp->st_id].ft_name+3,
00173                 stp->st_bit );
00174 
00175         bu_vls_printf(v, "(%g,%g)",
00176                 pp->pt_inhit->hit_dist, pp->pt_outhit->hit_dist );
00177         if( pp->pt_inflip )  bu_vls_strcat( v, " Iflip" );
00178         if( pp->pt_outflip )  bu_vls_strcat( v, " Oflip" );
00179         bu_vls_strcat( v, "\n");
00180 
00181         rt_pr_hit_vls( v, "  In", pp->pt_inhit );
00182         rt_pr_hit_vls( v, " Out", pp->pt_outhit );
00183         bu_log_indent_vls( v );
00184         bu_vls_strcat( v, "  Primitives: " );
00185         for( BU_PTBL_FOR( segpp, (struct seg **), &pp->pt_seglist ) )  {
00186                 stp = (*segpp)->seg_stp;
00187                 RT_CK_SOLTAB(stp);
00188                 bu_vls_strcat( v, stp->st_dp->d_namep );
00189                 bu_vls_strcat( v, ", " );
00190         }
00191         bu_vls_strcat( v, "\n" );
00192 
00193         bu_log_indent_vls( v );
00194         bu_vls_strcat( v, "  Untrimmed Segments spanning this interval:\n" );
00195         bu_log_indent_delta( 4 );
00196         for( BU_PTBL_FOR( segpp, (struct seg **), &pp->pt_seglist ) )  {
00197                 RT_CK_SEG(*segpp)
00198                 rt_pr_seg_vls( v, *segpp );
00199         }
00200         bu_log_indent_delta( -4 );
00201 
00202         if( pp->pt_regionp )  {
00203                 RT_CK_REGION( pp->pt_regionp );
00204                 bu_log_indent_vls( v );
00205                 bu_vls_printf( v, "  Region: %s\n", pp->pt_regionp->reg_name );
00206         }
00207 }
00208 
00209 /*
00210  *                      R T _ P R _ P T
00211  */
00212 void
00213 rt_pr_pt(const struct rt_i *rtip, register const struct partition *pp)
00214 {
00215         struct bu_vls   v;
00216 
00217         RT_CHECK_RTI(rtip);
00218         RT_CHECK_PT(pp);
00219         bu_vls_init( &v );
00220         rt_pr_pt_vls( &v, rtip, pp );
00221         bu_log("%s", bu_vls_addr( &v ) );
00222         bu_vls_free( &v );
00223 }
00224 
00225 /*
00226  *                      R T _ P R _ S E G _ V L S
00227  */
00228 void
00229 rt_pr_seg_vls(struct bu_vls *v, register const struct seg *segp)
00230 {
00231         BU_CK_VLS(v);
00232         RT_CK_SEG(segp);
00233 
00234         bu_log_indent_vls( v );
00235         bu_vls_printf(v,
00236                 "%.8lx: SEG %s (%g,%g) st_bit=%ld xray#=%d\n",
00237                 (long)segp,
00238                 segp->seg_stp->st_dp->d_namep,
00239                 segp->seg_in.hit_dist,
00240                 segp->seg_out.hit_dist,
00241                 segp->seg_stp->st_bit,
00242                 segp->seg_in.hit_rayp->index );
00243 }
00244 
00245 /*
00246  *                      R T _ P R _ S E G
00247  */
00248 void
00249 rt_pr_seg(register const struct seg *segp)
00250 {
00251         struct bu_vls           v;
00252 
00253         RT_CK_SEG(segp);
00254 
00255         bu_vls_init( &v );
00256         rt_pr_seg_vls( &v, segp );
00257         bu_log("%s", bu_vls_addr( &v ) );
00258         bu_vls_free( &v );
00259 }
00260 
00261 /*
00262  *                      R T _ P R _ H I T
00263  */
00264 void
00265 rt_pr_hit(const char *str, register const struct hit *hitp)
00266 {
00267         struct bu_vls           v;
00268 
00269         RT_CK_HIT(hitp);
00270 
00271         bu_vls_init( &v );
00272         rt_pr_hit_vls( &v, str, hitp );
00273         bu_log("%s", bu_vls_addr( &v ) );
00274         bu_vls_free( &v );
00275 }
00276 
00277 /*
00278  *                      R T _ P R _ H I T _ V L S
00279  */
00280 void
00281 rt_pr_hit_vls(struct bu_vls *v, const char *str, register const struct hit *hitp)
00282 {
00283         BU_CK_VLS( v );
00284         RT_CK_HIT(hitp);
00285 
00286         bu_log_indent_vls( v );
00287         bu_vls_strcat( v, str );
00288 
00289         bu_vls_printf(v, "HIT dist=%g (surf %d)\n",
00290                 hitp->hit_dist, hitp->hit_surfno );
00291 }
00292 
00293 /*
00294  *                      R T _ P R _ H I T A R R A Y _ V L S
00295  */
00296 void
00297 rt_pr_hitarray_vls(struct bu_vls *v, const char *str, register const struct hit *hitp, int count)
00298 {
00299         int     i;
00300 
00301         BU_CK_VLS( v );
00302         RT_CK_HIT(hitp);
00303 
00304         bu_log_indent_vls( v );
00305         bu_vls_strcat( v, str );
00306 
00307         for( i=0; i<count; i++, hitp++ )  {
00308                 bu_vls_printf(v, "HIT%d dist=%g (surf %d)\n", i,
00309                         hitp->hit_dist, hitp->hit_surfno );
00310         }
00311 }
00312 
00313 /*
00314  *                      R T _ P R _ T R E E
00315  *
00316  *  Warning:  This function uses recursion rather than iteration and
00317  *  a stack, to preserve simplicity.
00318  *  On machines with limited stack space, such as the Gould,
00319  *  this subroutine may overwhelm the stack on complex expressions.
00320  */
00321 void
00322 rt_pr_tree(register const union tree *tp, int lvl)
00323 
00324                                 /* recursion level */
00325 {
00326         register int i;
00327 
00328         RT_CK_TREE(tp);
00329 
00330         bu_log("%.8x ", tp);
00331         for( i=lvl; i>0; i-- )
00332                 bu_log("  ");
00333 
00334         if( tp == TREE_NULL )  {
00335                 bu_log("Null???\n");
00336                 return;
00337         }
00338 
00339         switch( tp->tr_op )  {
00340 
00341         case OP_NOP:
00342                 bu_log("NOP\n");
00343                 return;
00344 
00345         case OP_SOLID:
00346                 bu_log("SOLID %s (bit %d)\n",
00347                         tp->tr_a.tu_stp->st_dp->d_namep,
00348                         tp->tr_a.tu_stp->st_bit );
00349                 return;
00350 
00351         case OP_REGION:
00352                 bu_log("REGION ctsp=x%x\n", tp->tr_c.tc_ctsp );
00353                 db_pr_combined_tree_state( tp->tr_c.tc_ctsp );
00354                 return;
00355 
00356         case OP_DB_LEAF:
00357                 bu_log("DB_LEAF %s%s\n",
00358                         tp->tr_l.tl_name,
00359                         tp->tr_l.tl_mat ? " (matrix)" : "" );
00360                 return;
00361 
00362         default:
00363                 bu_log("Unknown op=x%x\n", tp->tr_op );
00364                 return;
00365 
00366         case OP_UNION:
00367                 bu_log("UNION\n");
00368                 break;
00369         case OP_INTERSECT:
00370                 bu_log("INTERSECT\n");
00371                 break;
00372         case OP_SUBTRACT:
00373                 bu_log("MINUS\n");
00374                 break;
00375         case OP_XOR:
00376                 bu_log("XOR\n");
00377                 break;
00378         case OP_NOT:
00379                 bu_log("NOT\n");
00380                 break;
00381         }
00382 
00383         switch( tp->tr_op )  {
00384         case OP_UNION:
00385         case OP_INTERSECT:
00386         case OP_SUBTRACT:
00387         case OP_XOR:
00388                 /* BINARY type */
00389                 rt_pr_tree( tp->tr_b.tb_left, lvl+1 );
00390                 rt_pr_tree( tp->tr_b.tb_right, lvl+1 );
00391                 break;
00392         case OP_NOT:
00393         case OP_GUARD:
00394         case OP_XNOP:
00395                 /* UNARY tree */
00396                 rt_pr_tree( tp->tr_b.tb_left, lvl+1 );
00397                 break;
00398         }
00399 }
00400 
00401 /*
00402  *                      R T _ P R _ T R E E _ V L S
00403  *
00404  *  Produce a compact representation of this tree.
00405  *  The destination vls must be initialized by the caller.
00406  *
00407  *  Operations are responsible for generating white space.
00408  */
00409 void
00410 rt_pr_tree_vls(struct bu_vls *vls, register const union tree *tp)
00411 {
00412         char            *str;
00413 
00414         if( tp == TREE_NULL )  {
00415                 bu_vls_strcat( vls, "??NULL_tree??" );
00416                 return;
00417         }
00418 
00419         switch( tp->tr_op )  {
00420 
00421         case OP_NOP:
00422                 bu_vls_strcat( vls, "NOP");
00423                 return;
00424 
00425         case OP_SOLID:
00426                 bu_vls_strcat( vls, tp->tr_a.tu_stp->st_dp->d_namep );
00427                 return;
00428 
00429         case OP_REGION:
00430                 str = db_path_to_string( &(tp->tr_c.tc_ctsp->cts_p) );
00431                 bu_vls_strcat( vls, str );
00432                 bu_free( str, "path string" );
00433                 return;
00434 
00435         case OP_DB_LEAF:
00436                 bu_vls_strcat( vls, tp->tr_l.tl_name );
00437                 return;
00438 
00439         default:
00440                 bu_log("rt_pr_tree_vls() Unknown op=x%x\n", tp->tr_op );
00441                 return;
00442 
00443         case OP_UNION:
00444                 /* BINARY type */
00445                 bu_vls_strcat( vls, " (" );
00446                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00447                 bu_vls_strcat( vls, ") u (" );
00448                 rt_pr_tree_vls( vls, tp->tr_b.tb_right );
00449                 bu_vls_strcat( vls, ") " );
00450                 break;
00451         case OP_INTERSECT:
00452                 /* BINARY type */
00453                 bu_vls_strcat( vls, " (" );
00454                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00455                 bu_vls_strcat( vls, ") + (" );
00456                 rt_pr_tree_vls( vls, tp->tr_b.tb_right );
00457                 bu_vls_strcat( vls, ") " );
00458                 break;
00459         case OP_SUBTRACT:
00460                 /* BINARY type */
00461                 bu_vls_strcat( vls, " (" );
00462                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00463                 bu_vls_strcat( vls, ") - (" );
00464                 rt_pr_tree_vls( vls, tp->tr_b.tb_right );
00465                 bu_vls_strcat( vls, ") " );
00466                 break;
00467         case OP_XOR:
00468                 /* BINARY type */
00469                 bu_vls_strcat( vls, " (" );
00470                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00471                 bu_vls_strcat( vls, ") ^ (" );
00472                 rt_pr_tree_vls( vls, tp->tr_b.tb_right );
00473                 bu_vls_strcat( vls, ") " );
00474                 break;
00475         case OP_NOT:
00476                 /* UNARY tree */
00477                 bu_vls_strcat( vls, " !(" );
00478                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00479                 bu_vls_strcat( vls, ") " );
00480                 break;
00481         case OP_GUARD:
00482                 /* UNARY tree */
00483                 bu_vls_strcat( vls, " guard(" );
00484                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00485                 bu_vls_strcat( vls, ") " );
00486                 break;
00487         case OP_XNOP:
00488                 /* UNARY tree */
00489                 bu_vls_strcat( vls, " xnop(" );
00490                 rt_pr_tree_vls( vls, tp->tr_b.tb_left );
00491                 bu_vls_strcat( vls, ") " );
00492                 break;
00493         }
00494 }
00495 
00496 /*
00497  *                      R T _ P R _ T R E E _ S T R
00498  *
00499  *  JRA's tree pretty-printer.
00500  *  Formats the tree compactly into a dynamically allocated string.
00501  *  Uses recursion and lots of malloc/free activity.
00502  */
00503 char *
00504 rt_pr_tree_str(const union tree *tree)
00505 {
00506         char *left,*right;
00507         char *return_str;
00508         char op = OP_GUARD;
00509         int return_length;
00510 
00511         if( tree == NULL )
00512                 return bu_strdup("NULL_ptr");
00513         RT_CK_TREE(tree);
00514         if( tree->tr_op == OP_UNION || tree->tr_op == OP_SUBTRACT || tree->tr_op == OP_INTERSECT )
00515         {
00516                 char *blankl,*blankr;
00517 
00518                 left = rt_pr_tree_str( tree->tr_b.tb_left );
00519                 right = rt_pr_tree_str( tree->tr_b.tb_right );
00520                 switch( tree->tr_op )
00521                 {
00522                         case OP_UNION:
00523                                 op = 'u';
00524                                 break;
00525                         case OP_SUBTRACT:
00526                                 op = '-';
00527                                 break;
00528                         case OP_INTERSECT:
00529                                 op = '+';
00530                                 break;
00531                 }
00532                 return_length = strlen( left ) + strlen( right ) + 8;
00533                 return_str = (char *)bu_malloc( return_length , "rt_pr_tree_str: return string" );
00534 
00535                 blankl = strchr( left , ' ' );
00536                 blankr = strchr( right , ' ' );
00537                 if( blankl && blankr )
00538                         sprintf( return_str , "(%s) %c (%s)" , left , op , right );
00539                 else if( blankl && !blankr )
00540                         sprintf( return_str , "(%s) %c %s" , left , op , right );
00541                 else if( !blankl && blankr )
00542                         sprintf( return_str , "%s %c (%s)" , left , op , right );
00543                 else
00544                         sprintf( return_str , "%s %c %s" , left , op , right );
00545 
00546                 if( tree->tr_b.tb_left->tr_op != OP_DB_LEAF )
00547                         bu_free( (genptr_t)left , "rt_pr_tree_str: left string" );
00548                 if( tree->tr_b.tb_right->tr_op != OP_DB_LEAF )
00549                         bu_free( (genptr_t)right , "rt_pr_tree_str: right string" );
00550                 return  return_str;
00551         }
00552         else if( tree->tr_op == OP_DB_LEAF )
00553                 return bu_strdup(tree->tr_l.tl_name) ;
00554         else if( tree->tr_op == OP_REGION )
00555                 return( db_path_to_string( &tree->tr_c.tc_ctsp->cts_p ) );
00556         else if( tree->tr_op == OP_SOLID )  {
00557                 RT_CK_SOLTAB(tree->tr_a.tu_stp);
00558                 return bu_strdup(tree->tr_a.tu_stp->st_dp->d_namep);
00559         }
00560 
00561 
00562         return bu_strdup("Unknown:tr_op");
00563 }
00564 
00565 /*
00566  *                      R T _ P R _ T R E E _ V A L
00567  *
00568  *  Print the actual values of the terms in a boolean expression.
00569  *
00570  *  The values for pr_name determine the printing action:
00571  *      0       bit value
00572  *      1       name
00573  *      2       bit number
00574  */
00575 void
00576 rt_pr_tree_val(register const union tree *tp, const struct partition *partp, int pr_name, int lvl)
00577                                         /* Tree to print */
00578                                         /* Partition to evaluate */
00579                                         /* 1=print name, 0=print value */
00580                                         /* Recursion level */
00581 {
00582 
00583         if( lvl == 0 )  {
00584                 switch( pr_name )  {
00585                 default:
00586                         bu_log("tree val: ");
00587                         break;
00588                 case 1:
00589                         bu_log("tree primitives: ");
00590                         break;
00591                 case 2:
00592                         bu_log("tree primitive bits: ");
00593                         break;
00594                 }
00595         }
00596 
00597         if( tp == TREE_NULL )  {
00598                 bu_log("Null???\n");
00599                 return;
00600         }
00601 
00602         switch( tp->tr_op )  {
00603         default:
00604                 bu_log("Unknown_op=x%x", tp->tr_op );
00605                 break;
00606 
00607         case OP_SOLID:
00608                 switch( pr_name )  {
00609                 case 0:
00610                         {
00611                                 register struct soltab *seek_stp = tp->tr_a.tu_stp;
00612                                 register struct seg **segpp;
00613                                 for( BU_PTBL_FOR( segpp, (struct seg **), &partp->pt_seglist ) )  {
00614                                         if( (*segpp)->seg_stp == seek_stp )  {
00615                                                 bu_log("1");
00616                                                 goto out;
00617                                         }
00618                                 }
00619                                 bu_log("0");
00620                         }
00621                         break;
00622                 case 1:
00623                         bu_log("%s", tp->tr_a.tu_stp->st_dp->d_namep );
00624                         break;
00625                 case 2:
00626                         bu_log("%d", tp->tr_a.tu_stp->st_bit );
00627                         break;
00628                 }
00629                 break;
00630 
00631 
00632         case OP_UNION:
00633                 bu_log("(");
00634                 rt_pr_tree_val( tp->tr_b.tb_left,  partp, pr_name, lvl+1 );
00635                 bu_log(" u ");
00636                 rt_pr_tree_val( tp->tr_b.tb_right, partp, pr_name, lvl+1 );
00637                 bu_log(")");
00638                 break;
00639         case OP_INTERSECT:
00640                 bu_log("(");
00641                 rt_pr_tree_val( tp->tr_b.tb_left,  partp, pr_name, lvl+1 );
00642                 bu_log(" + ");
00643                 rt_pr_tree_val( tp->tr_b.tb_right, partp, pr_name, lvl+1 );
00644                 bu_log(")");
00645                 break;
00646         case OP_SUBTRACT:
00647                 bu_log("(");
00648                 rt_pr_tree_val( tp->tr_b.tb_left,  partp, pr_name, lvl+1 );
00649                 bu_log(" - ");
00650                 rt_pr_tree_val( tp->tr_b.tb_right, partp, pr_name, lvl+1 );
00651                 bu_log(")");
00652                 break;
00653         case OP_XOR:
00654                 bu_log("(");
00655                 rt_pr_tree_val( tp->tr_b.tb_left,  partp, pr_name, lvl+1 );
00656                 bu_log(" XOR ");
00657                 rt_pr_tree_val( tp->tr_b.tb_right, partp, pr_name, lvl+1 );
00658                 bu_log(")");
00659                 break;
00660 
00661         case OP_NOT:
00662                 bu_log(" !");
00663                 rt_pr_tree_val( tp->tr_b.tb_left, partp, pr_name, lvl+1 );
00664                 break;
00665         case OP_GUARD:
00666                 bu_log(" GUARD ");
00667                 rt_pr_tree_val( tp->tr_b.tb_left, partp, pr_name, lvl+1 );
00668                 break;
00669         }
00670 
00671 out:
00672         if( lvl == 0 )  bu_log("\n");
00673 }
00674 
00675 /*
00676  *                      R T _ P R _ F A L L B A C K _ A N G L E
00677  */
00678 void
00679 rt_pr_fallback_angle(struct bu_vls *str, const char *prefix, const double *angles)
00680 {
00681         BU_CK_VLS(str);
00682 
00683         bu_vls_printf(str, "%s direction cosines=(%1.f, %1.f, %1.f)\n",
00684                 prefix, INTCLAMP(angles[0]), INTCLAMP(angles[1]), INTCLAMP(angles[2]) );
00685 
00686         bu_vls_printf(str, "%s rotation angle=%1.f, fallback angle=%1.f\n",
00687                 prefix, INTCLAMP(angles[3]), INTCLAMP(angles[4]) );
00688 }
00689 
00690 /*
00691  *                      R T _ F I N D _ F A L L B A C K _ A N G L E
00692  *
00693  *  In degrees.
00694  */
00695 void
00696 rt_find_fallback_angle(double *angles, const fastf_t *vec)
00697 {
00698         register double f;
00699         double          asinZ;
00700 
00701         /* convert direction cosines into axis angles */
00702         if( vec[X] <= -1.0 )  {
00703                 angles[X] = 180.0;
00704         } else if( vec[X] >= 1.0 )  {
00705                 angles[X] = 0.0;
00706         } else {
00707                 angles[X] = acos( vec[X] ) * bn_radtodeg;
00708         }
00709 
00710         if( vec[Y] <= -1.0 )  {
00711                 angles[Y] = 180.0;
00712         } else if( vec[Y] >= 1.0 )  {
00713                 angles[Y] = 0.0;
00714         } else {
00715                 angles[Y] = acos( vec[Y] ) * bn_radtodeg;
00716         }
00717 
00718         if( vec[Z] <= -1.0 )  {
00719                 angles[Z] = 180.0;
00720         } else if( vec[Z] >= 1.0 )  {
00721                 angles[Z] = 0.0;
00722         } else {
00723                 angles[Z] = acos( vec[Z] ) * bn_radtodeg;
00724         }
00725 
00726         /* fallback angle */
00727         if( vec[Z] <= -1.0 )  {
00728                 /* 270 degrees:  3/2 pi */
00729                 asinZ = bn_halfpi * 3;
00730         } else if( vec[Z] >= 1.0 )  {
00731                 /* +90 degrees: 1/2 pi */
00732                 asinZ = bn_halfpi;
00733         } else {
00734                 asinZ = asin(vec[Z]);
00735         }
00736         angles[4] = asinZ * bn_radtodeg;
00737 
00738         /* rotation angle */
00739         /* For the tolerance below, on an SGI 4D/70, cos(asin(1.0)) != 0.0
00740          * with an epsilon of +/- 1.0e-17, so the tolerance below was
00741          * substituted for the original +/- 1.0e-20.
00742          */
00743         if((f = cos(asinZ)) > 1.0e-16 || f < -1.0e-16 )  {
00744                 f = vec[X]/f;
00745                 if( f <= -1.0 )  {
00746                         angles[3] = 180;
00747                 } else if( f >= 1.0 ) {
00748                         angles[3] = 0;
00749                 } else {
00750                         angles[3] = bn_radtodeg * acos( f );
00751                 }
00752         }  else  {
00753                 angles[3] = 0.0;
00754         }
00755         if( vec[Y] < 0 ) {
00756                 angles[3] = 360.0 - angles[3];
00757         }
00758 }
00759 
00760 /*
00761  *                      R T _ P R _ T O L
00762  *
00763  *  Print a tolerance structure.
00764  */
00765 void
00766 rt_pr_tol(const struct bn_tol *tol)
00767 {
00768         BN_CK_TOL(tol);
00769 
00770         bu_log("%8.8x TOL %e (sq=%e) perp=%e, para=%e\n",
00771                 tol, tol->dist, tol->dist_sq,
00772                 tol->perp, tol->para );
00773 }
00774 
00775 /*
00776  *                      R T _ P R _ U V C O O R D
00777  */
00778 void
00779 rt_pr_uvcoord(const struct uvcoord *uvp)
00780 {
00781         bu_log("%8.8x u,v=(%g, %g), du,dv=(%g, %g)\n",
00782                 INTCLAMP(uvp->uv_u), INTCLAMP(uvp->uv_v),
00783                 INTCLAMP(uvp->uv_du), INTCLAMP(uvp->uv_dv) );
00784 }
00785 
00786 /*
00787  * Local Variables:
00788  * mode: C
00789  * tab-width: 8
00790  * c-basic-offset: 4
00791  * indent-tabs-mode: t
00792  * End:
00793  * ex: shiftwidth=4 tabstop=8
00794  */

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