comb.c

Go to the documentation of this file.
00001 /*                          C O M B . C
00002  * BRL-CAD
00003  *
00004  * Copyright (c) 1996-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 dbio */
00023 /*@{*/
00024 /** @file comb.c
00025  * XXX Move to db_tree.c when complete.
00026  *
00027  *  Authors -
00028  *      John R. Anderson
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/comb.c,v 14.14 2006/09/16 02:04:24 lbutler Exp $ (ARL)";
00039 #endif
00040 
00041 #include "common.h"
00042 
00043 #include <stdlib.h>
00044 #include <stdio.h>
00045 #include <math.h>
00046 #include <string.h>
00047 
00048 #include "machine.h"
00049 #include "bu.h"
00050 #include "vmath.h"
00051 #include "bn.h"
00052 #include "nmg.h"
00053 #include "rtgeom.h"
00054 #include "raytrace.h"
00055 #include "../librt/debug.h"
00056 
00057 
00058 /* --- Begin John's pretty-printer --- */
00059 
00060 void
00061 Print_tree(union tree *tree)
00062 {
00063         char *str;
00064 
00065         str = (char *)rt_pr_tree_str( tree );
00066         if( str != NULL )
00067         {
00068                 printf( "%s\n" , str );
00069                 bu_free( str , "Print_tree" );
00070         }
00071         else
00072                 printf( "NULL Tree\n" );
00073 }
00074 
00075 int
00076 main(int argc, char *argv[])
00077 {
00078         struct db_i             *dbip;
00079         struct directory        *dp;
00080         struct rt_db_internal   ip;
00081         struct rt_comb_internal *comb;
00082         mat_t                   identity_mat;
00083         int                     i;
00084         struct bu_vls           file;
00085 
00086         bu_debug = BU_DEBUG_MEM_CHECK | BU_DEBUG_COREDUMP;
00087 
00088         if( argc < 3 )
00089         {
00090                 fprintf( stderr , "Usage:\n\t%s db_file object1 object2 ...\n" , argv[0] );
00091                 return 1;
00092         }
00093 
00094         MAT_IDN( identity_mat );
00095         bu_vls_init( &file );
00096 
00097         if( (dbip = db_open( argv[1] , "r" ) ) == NULL )
00098         {
00099                 fprintf( stderr , "Cannot open %s\n" , argv[1] );
00100                 perror( "test" );
00101                 return 1;
00102         }
00103 
00104         rt_init_resource( &rt_uniresource, 0, NULL );
00105 
00106         /* Scan the database */
00107         db_dirbuild( dbip );
00108 
00109         for( i=2 ; i<argc ; i++ )
00110         {
00111                 printf( "%s\n" , argv[i] );
00112 
00113                 dp = db_lookup( dbip , argv[i] , 1 );
00114 
00115                 if( rt_db_get_internal( &ip, dp, dbip, NULL, &rt_uniresource ) < 0 )  {
00116                         bu_log("import of %s failed\n", dp->d_namep);
00117                         continue;
00118                 }
00119 
00120                 RT_CK_DB_INTERNAL( &ip );
00121                 bu_mem_barriercheck();
00122 
00123                 if( ip.idb_type != ID_COMBINATION )
00124                 {
00125                         bu_log( "idb_type = %d\n" , ip.idb_type );
00126                         rt_db_free_internal( &ip, &rt_uniresource );
00127                         continue;
00128                 }
00129 
00130                 comb = (struct rt_comb_internal *)ip.idb_ptr;
00131                 RT_CK_COMB(comb);
00132                 if( comb->region_flag )
00133                 {
00134                         bu_log( "\tRegion id = %d, aircode = %d GIFTmater = %d, los = %d\n",
00135                                 comb->region_id, comb->aircode, comb->GIFTmater, comb->los );
00136                 }
00137                 bu_log( "\trgb_valid = %d, color = %d/%d/%d\n" , comb->rgb_valid , V3ARGS( comb->rgb ) );
00138                 bu_log( "\tshader = %s (%s)\n" ,
00139                                 bu_vls_addr( &comb->shader ),
00140                                 bu_vls_addr( &comb->material )
00141                 );
00142 
00143                 /* John's way */
00144                 bu_log( "Pretty print:\n" );
00145                 Print_tree( comb->tree );
00146 
00147                 /* Standard way */
00148                 bu_log( "Standard print:\n" );
00149                 rt_pr_tree( comb->tree, 1 );
00150 
00151                 /* Compact way */
00152                 {
00153                         struct bu_vls   str;
00154                         bu_vls_init( &str );
00155                         rt_pr_tree_vls( &str, comb->tree );
00156                         bu_log("%s\n", bu_vls_addr(&str) );
00157                         bu_vls_free(&str );
00158                 }
00159 
00160                 /* Test the support routines */
00161                 if( db_ck_v4gift_tree( comb->tree ) < 0 )
00162                         bu_log("ERROR: db_ck_v4gift_tree is unhappy\n");
00163 
00164                 /* Test the lumberjacks */
00165                 rt_db_free_internal( &ip, &rt_uniresource );
00166 
00167         }
00168 
00169         return 0;
00170 }
00171 
00172 /*
00173  * Local Variables:
00174  * mode: C
00175  * tab-width: 8
00176  * c-basic-offset: 4
00177  * indent-tabs-mode: t
00178  * End:
00179  * ex: shiftwidth=4 tabstop=8
00180  */

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