Revision: 46845
          http://brlcad.svn.sourceforge.net/brlcad/?rev=46845&view=rev
Author:   r_weiss
Date:     2011-09-21 21:51:10 +0000 (Wed, 21 Sep 2011)
Log Message:
-----------
Significate updates to the 'g-vrml' converter. Some logic bugs were fixed. 
Triangulation was changed to use 'nmg_triangulate_model' instead of its own 
function which was very limited. Added two new options. A '-b' option to 
perform a bot dump (all csg geometry is ignored) and '-e' to perform an 
evaluation or all opjects including bots. By default bots are dumped and csg 
evaluation is perform ignoring the bots. Some code refactoring was also done. 
More testing is needed but appears to be working well.

Modified Paths:
--------------
    brlcad/trunk/src/conv/g-vrml.c

Modified: brlcad/trunk/src/conv/g-vrml.c
===================================================================
--- brlcad/trunk/src/conv/g-vrml.c      2011-09-21 21:27:04 UTC (rev 46844)
+++ brlcad/trunk/src/conv/g-vrml.c      2011-09-21 21:51:10 UTC (rev 46845)
@@ -44,20 +44,6 @@
 #include "raytrace.h"
 #include "wdb.h"
 
-
-/* #define MEMORY_LEAK_CHECKING 1 */
-
-#ifdef MEMORY_LEAK_CHECKING
-#define BARRIER_CHECK { \
-       if ( bu_mem_barriercheck() ) { \
-           bu_log( "memory is corrupted at line %d in file %d\n", __LINE__, 
__FILE__ ); \
-       } \
-    }
-#else
-#define BARRIER_CHECK /* */
-#endif
-
-
 #define TXT_BUF_LEN    512
 #define TXT_NAME_SIZE  128
 
@@ -80,13 +66,13 @@
     fastf_t lt_angle;
 
     /* texture parameters */
-    char       tx_file[TXT_NAME_SIZE];
+    char tx_file[TXT_NAME_SIZE];
     int        tx_w;
     int        tx_n;
 };
 
-#define PL_O(_m)       bu_offsetof(struct vrml_mat, _m)
-#define PL_OA(_m)      bu_offsetofarray(struct vrml_mat, _m)
+#define PL_O(_m) bu_offsetof(struct vrml_mat, _m)
+#define PL_OA(_m) bu_offsetofarray(struct vrml_mat, _m)
 
 const struct bu_structparse vrml_mat_parse[]={
     {"%s", TXT_NAME_SIZE, "ma_shader", PL_OA(shader), 
BU_STRUCTPARSE_FUNC_NULL, NULL, NULL },
@@ -103,88 +89,119 @@
     {"",0, (char *)0,0,BU_STRUCTPARSE_FUNC_NULL, NULL, NULL }
 };
 
-extern union tree *do_region_end(struct db_tree_state *tsp, const struct 
db_full_path *pathp, union tree *curtree, genptr_t client_data);
+extern union tree *do_region_end1(struct db_tree_state *tsp, const struct 
db_full_path *pathp, union tree *curtree, genptr_t client_data);
+extern union tree *do_region_end2(struct db_tree_state *tsp, const struct 
db_full_path *pathp, union tree *curtree, genptr_t client_data);
 extern union tree *nmg_region_end(struct db_tree_state *tsp, const struct 
db_full_path *pathp, union tree *curtree, genptr_t client_data);
 
-static const char usage[] = "Usage: %s [-v] [-xX lvl] [-d tolerance_distance 
(mm) ] [-a abs_tol (mm)] [-r rel_tol] [-n norm_tol] [-o out_file] [-u units] 
brlcad_db.g object(s)\n";
+static const char usage[] = "Usage: %s [-b] [-e] [-v] [-xX lvl] [-d 
tolerance_distance (mm) ] [-a abs_tol (mm)] [-r rel_tol] [-n norm_tol] [-o 
out_file] [-u units] brlcad_db.g object(s)\n";
 
-static char    *tok_sep = " \t";
-static int     NMG_debug;              /* saved arg of -X, for longjmp 
handling */
-static int     verbose=0;
-/* static int  ncpu = 1; */            /* Number of processors */
-static char    *out_file = NULL;       /* Output filename */
-static FILE    *fp_out;                /* Output file pointer */
-static struct db_i             *dbip;
-static struct rt_tess_tol      ttol;
-static struct bn_tol           tol;
-static struct model            *the_model;
+static char *tok_sep = " \t";
+static int NMG_debug; /* saved arg of -X, for longjmp handling */
+static int verbose = 0;
+static char *out_file = (char *)NULL; /* Output filename */
+static FILE *fp_out; /* Output file pointer */
+static struct db_i *dbip;
+static struct rt_tess_tol ttol;
+static struct bn_tol tol;
+static struct model *the_model;
 
-static char*   units=NULL;
-static fastf_t scale_factor=1.0;
+static char *units = (char *)NULL;
+static fastf_t scale_factor = 1.0;
 
-static struct db_tree_state    tree_state;     /* includes tol & model */
+static struct db_tree_state tree_state;        /* includes tol & model */
 
-static int     regions_tried = 0;
-static int     regions_converted = 0;
+static int regions_tried = 0;
+static int regions_converted = 0;
 
+static int bot_dump = 0;
+static int eval_all = 0;
+
 static void
-clean_pmp( struct plate_mode *pmp )
+clean_pmp(struct plate_mode *pmp)
 {
     int i;
 
-    BARRIER_CHECK;
+    for (i = 0; i < pmp->num_bots; i++) {
+       bu_free(pmp->bots[i]->faces, "pmp->bots[i]->faces");
+       bu_free(pmp->bots[i]->vertices, "pmp->bots[i]->vertices");
+       if ((pmp->bots[i]->bot_flags & RT_BOT_PLATE) || 
+           (pmp->bots[i]->bot_flags & RT_BOT_PLATE_NOCOS)) {
+           bu_free(pmp->bots[i]->thickness, "pmp->bots[i]->thickness");
+       }
+       if (pmp->bots[i]->bot_flags & RT_BOT_HAS_SURFACE_NORMALS) {
+           bu_free(pmp->bots[i]->normals, "pmp->bots[i]->normals");
+       }
+       if ((pmp->bots[i]->bot_flags & RT_BOT_PLATE) || 
+           (pmp->bots[i]->bot_flags & RT_BOT_PLATE_NOCOS)) {
+           bu_bomb("about to free pmp->bots[i]->face_mode\n");
+           bu_bitv_free(pmp->bots[i]->face_mode);
+       }
+       bu_free(pmp->bots[i], "bots");
+       pmp->bots[i] = (struct rt_bot_internal *)NULL;
+    }
 
     pmp->num_bots = 0;
     pmp->num_nonbots = 0;
-    for ( i=0; i<pmp->array_size; i++ ) {
-       if ( pmp->bots[i] ) {
-           struct rt_db_internal intern;
-
-           intern.idb_ptr = (genptr_t) pmp->bots[i];
-           intern.idb_major_type = DB5_MAJORTYPE_BRLCAD;
-           intern.idb_type = ID_BOT;
-           intern.idb_meth = &rt_functab[ID_BOT];
-           intern.idb_magic = RT_DB_INTERNAL_MAGIC;
-           intern.idb_meth->ft_ifree( &intern );
-           pmp->bots[i] = NULL;
-       }
-    }
-    BARRIER_CHECK;
 }
 
+/* duplicate bot */
 struct rt_bot_internal *
-dup_bot( struct rt_bot_internal *bot_in )
+dup_bot(struct rt_bot_internal *bot_in)
 {
     struct rt_bot_internal *bot;
     size_t i;
 
-    RT_BOT_CK_MAGIC( bot_in );
+    RT_BOT_CK_MAGIC(bot_in);
 
-    bot = (struct rt_bot_internal *)bu_malloc( sizeof( struct rt_bot_internal 
), "dup bot" );
+    bot = (struct rt_bot_internal *)bu_calloc(1, sizeof( struct 
rt_bot_internal ), "dup bot");
 
-    *bot = *bot_in;    /* struct copy */
+    bot->magic = bot_in->magic;
+    bot->mode = bot_in->mode;
+    bot->orientation = bot_in->orientation;
+    bot->bot_flags = bot_in->bot_flags;
+    bot->num_vertices = bot_in->num_vertices;
+    bot->num_faces = bot_in->num_faces;
+    bot->num_normals = bot_in->num_normals;
+    bot->num_face_normals = bot_in->num_face_normals;
 
-    bot->faces = (int *)bu_calloc( bot_in->num_faces*3, sizeof( int ), "bot 
faces" );
-    for ( i=0; i<bot_in->num_faces*3; i++ )
+    bot->faces = (int *)bu_calloc(bot_in->num_faces * 3, sizeof(int), "bot 
faces");
+    for (i = 0; i < bot_in->num_faces * 3; i++) {
        bot->faces[i] = bot_in->faces[i];
+    }
 
-    bot->vertices = (fastf_t *)bu_calloc( bot_in->num_vertices*3, sizeof( 
fastf_t ), "bot verts" );
-    for ( i=0; i<bot_in->num_vertices*3; i++ )
+    bot->vertices = (fastf_t *)bu_calloc(bot_in->num_vertices * 3, 
sizeof(fastf_t), "bot verts");
+    for (i = 0; i < bot_in->num_vertices * 3; i++) {
        bot->vertices[i] = bot_in->vertices[i];
+    }
 
-    if ( bot_in->thickness ) {
-       bot->thickness = (fastf_t *)bu_calloc( bot_in->num_faces, sizeof( 
fastf_t ), "bot thickness" );
-       for ( i=0; i<bot_in->num_faces; i++ )
-           bot->thickness[i] = bot_in->thickness[i];
+    if ((bot_in->bot_flags & RT_BOT_PLATE) || (bot_in->bot_flags & 
RT_BOT_PLATE_NOCOS)) {
+       if (bot_in->thickness) {
+           bot->thickness = (fastf_t *)bu_calloc(bot_in->num_faces, 
sizeof(fastf_t), "bot thickness");
+            for (i = 0; i < bot_in->num_faces; i++) {
+               bot->thickness[i] = bot_in->thickness[i];
+           }
+       } else {
+           bu_bomb("dup_bot(): flag should not say plate but thickness is 
null\n");
+       }
     }
 
-    if ( bot_in->face_mode ) {
-       bot->face_mode = bu_bitv_dup( bot_in->face_mode );
+    if (bot_in->face_mode) {
+       bot->face_mode = bu_bitv_dup(bot_in->face_mode);
     }
 
+    if (bot_in->bot_flags & RT_BOT_HAS_SURFACE_NORMALS) {
+       bot->num_normals = bot_in->num_normals;
+       bot->normals = (fastf_t *)bu_calloc(bot_in->num_normals * 3, 
sizeof(fastf_t), "BOT normals");
+       bot->face_normals = (int *)bu_calloc(bot_in->num_faces * 3, 
sizeof(int), "BOT face normals");
+       memcpy(bot->face_normals, bot_in->face_normals, bot_in->num_faces * 3 * 
sizeof(int));
+    }
+
     return bot;
 }
 
+/* return 0 when object is NOT a light or an error occured. regions
+ * are skipped when this function returns 0.
+ */
 static int
 select_lights(struct db_tree_state *UNUSED(tsp), const struct db_full_path 
*pathp, const struct rt_comb_internal *UNUSED(combp), genptr_t 
UNUSED(client_data))
 {
@@ -193,91 +210,143 @@
     struct rt_comb_internal *comb;
     int id;
 
-    RT_CK_FULL_PATH( pathp );
-    dp = DB_FULL_PATH_CUR_DIR( pathp );
+    RT_CK_FULL_PATH(pathp);
+    dp = DB_FULL_PATH_CUR_DIR(pathp);
 
-    if ( !(dp->d_flags & RT_DIR_COMB) )
-       return -1;
+    if (!(dp->d_flags & RT_DIR_COMB)) {
+       /* object is not a combination therefore can not be a light */
+       return 0;
+    }
 
-    id = rt_db_get_internal( &intern, dp, dbip, (matp_t)NULL, &rt_uniresource 
);
-    if ( id < 0 )
-    {
-       bu_log( "Cannot internal form of %s\n", dp->d_namep );
-       return -1;
+    id = rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource);
+    if (id < 0) {
+       /* error occured retrieving object */
+       bu_log("Warning: Can not load internal form of %s\n", dp->d_namep);
+       return 0;
     }
 
-    if ( id != ID_COMBINATION )
-    {
-       bu_log( "Directory/database mismatch!\n\t is '%s' a combination or 
not?\n",
-               dp->d_namep );
-       return -1;
+    if (id != ID_COMBINATION) {
+       /* object is not a combination therefore can not be a light */
+       return 0;
     }
 
     comb = (struct rt_comb_internal *)intern.idb_ptr;
-    RT_CK_COMB( comb );
+    RT_CK_COMB(comb);
 
-    if ( BU_STR_EQUAL( bu_vls_addr( &comb->shader ), "light" ) )
-    {
+    if (BU_STR_EQUAL(bu_vls_addr(&comb->shader), "light" )) {
        rt_db_free_internal(&intern);
+       return 1;
+    } else {
+       rt_db_free_internal(&intern);
        return 0;
     }
-    else
-    {
-       rt_db_free_internal(&intern);
-       return -1;
-    }
 }
 
+
+/* return 0 when IS a light or an error occured. regions are skipped
+ * when this function returns 0.
+ */
 static int
-select_non_lights(struct db_tree_state *tsp, const struct db_full_path *pathp, 
const struct rt_comb_internal *combp, genptr_t client_data)
+select_non_lights(struct db_tree_state *UNUSED(tsp), const struct db_full_path 
*pathp, const struct rt_comb_internal *UNUSED(combp), genptr_t 
UNUSED(client_data))
 {
-    int ret;
+    struct directory *dp;
+    struct rt_db_internal intern;
+    struct rt_comb_internal *comb;
+    int id;
 
-    ret =  select_lights( tsp, pathp, combp, client_data );
-    if ( ret == 0 )
-       return -1;
-    else
+    RT_CK_FULL_PATH(pathp);
+    dp = DB_FULL_PATH_CUR_DIR(pathp);
+
+    id = rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource);
+    if (id < 0) {
+       /* error occured retrieving object */
+       bu_log("Warning: Can not load internal form of %s\n", dp->d_namep);
        return 0;
+    }
+
+    if ((dp->d_flags & RT_DIR_COMB) && (id == ID_COMBINATION)) {
+       comb = (struct rt_comb_internal *)intern.idb_ptr;
+       RT_CK_COMB(comb);
+       if (BU_STR_EQUAL(bu_vls_addr(&comb->shader), "light")) {
+           rt_db_free_internal(&intern);
+           return 0;
+       }
+    }
+
+    return 1;
 }
 
+
+/* CSG objects are tesselated and stored in the tree. BOTs are
+ * processed but stored outside tree. This leaf-tess function is
+ * used when we want CSG objects tesselated and evaluated but we
+ * want to output BOTs without boolean evaluation.
+ */
 union tree *
-leaf_tess(struct db_tree_state *tsp, const struct db_full_path *pathp, struct 
rt_db_internal *ip, genptr_t client_data)
+leaf_tess1(struct db_tree_state *tsp, const struct db_full_path *pathp, struct 
rt_db_internal *ip, genptr_t client_data)
 {
     struct rt_bot_internal *bot;
     struct plate_mode *pmp = (struct plate_mode *)client_data;
 
-    BARRIER_CHECK;
-
-    if ( ip->idb_type != ID_BOT ) {
+    if (ip->idb_type != ID_BOT) {
        pmp->num_nonbots++;
        return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
     }
 
     bot = (struct rt_bot_internal *)ip->idb_ptr;
-    RT_BOT_CK_MAGIC( bot );
+    RT_BOT_CK_MAGIC(bot);
 
-    if ( bot->mode == RT_BOT_PLATE || bot->mode == RT_BOT_SURFACE )
-    {
-       if ( pmp->array_size <= pmp->num_bots ) {
-           pmp->array_size += 5;
-           pmp->bots = (struct rt_bot_internal **)bu_realloc(
-               (char *)pmp->bots,
-               pmp->array_size * sizeof( struct rt_bot_internal *),
-               "pmp->bots" );
-       }
+    if (pmp->array_size <= pmp->num_bots) {
+       struct rt_bot_internal **bots_tmp;
+       pmp->array_size += 5;
+       bots_tmp = (struct rt_bot_internal **)bu_realloc((genptr_t)pmp->bots,
+                   pmp->array_size * sizeof(struct rt_bot_internal **), 
"pmp->bots");
+       pmp->bots = bots_tmp;
+    }
 
-       /* walk tree will free the BOT, so we need a copy */
-       pmp->bots[pmp->num_bots] = dup_bot( bot );
-       BARRIER_CHECK;
-       pmp->num_bots++;
+    /* walk tree will free the bot, so we need a copy */
+    pmp->bots[pmp->num_bots] = dup_bot(bot);
+    pmp->num_bots++;
+
+    return (union tree *)NULL;
+}
+
+/* CSG objects are skipped. BOTs are processed but stored outside
+ * tree. This leaf-tess function is used when we want to output
+ * BOTs directly to the VRML file without performing a boolean 
+ * evaluation.
+ */
+union tree *
+leaf_tess2(struct db_tree_state *tsp, const struct db_full_path *pathp, struct 
rt_db_internal *ip, genptr_t client_data)
+{
+    struct rt_bot_internal *bot;
+    struct plate_mode *pmp = (struct plate_mode *)client_data;
+    struct db_tree_state *tsp_tmp;
+    const struct db_full_path *pathp_tmp;
+
+    tsp_tmp = tsp; /* to quiet compiler */
+    pathp_tmp = pathp; /* to quiet compiler */
+
+    if (ip->idb_type != ID_BOT) {
        return (union tree *)NULL;
     }
 
-    pmp->num_nonbots++;
+    bot = (struct rt_bot_internal *)ip->idb_ptr;
+    RT_BOT_CK_MAGIC(bot);
 
-    BARRIER_CHECK;
+    if (pmp->array_size <= pmp->num_bots) {
+       struct rt_bot_internal **bots_tmp;
+       pmp->array_size += 5;
+       bots_tmp = (struct rt_bot_internal **)bu_realloc((genptr_t)pmp->bots,
+                   pmp->array_size * sizeof(struct rt_bot_internal **), 
"pmp->bots");
+       pmp->bots = bots_tmp;
+    }
 
-    return nmg_booltree_leaf_tess(tsp, pathp, ip, client_data);
+    /* walk tree will free the bot, so we need a copy */
+    pmp->bots[pmp->num_bots] = dup_bot(bot);
+    pmp->num_bots++;
+
+    return (union tree *)NULL;
 }
 
 
@@ -534,9 +603,8 @@
     ttol.rel = 0.01;
     ttol.norm = 0.0;
 
-    /* FIXME: These need to be improved */
     tol.magic = BN_TOL_MAGIC;
-    tol.dist = 0.0005;
+    tol.dist = 0.005;
     tol.dist_sq = tol.dist * tol.dist;
     tol.perp = 1e-6;
     tol.para = 1 - tol.perp;
@@ -547,22 +615,27 @@
        nmg_eue_dist = 2.0;
     }
 
-    rt_init_resource( &rt_uniresource, 0, NULL );
+    rt_init_resource(&rt_uniresource, 0, NULL);
 
-    BU_LIST_INIT( &rt_g.rtg_vlfree );  /* for vlist macros */
+    BU_LIST_INIT(&rt_g.rtg_vlfree);    /* for vlist macros */
 
-    BARRIER_CHECK;
     /* Get command line arguments. */
-    while ((c = bu_getopt(argc, argv, "d:a:n:o:r:vx:P:X:u:")) != -1) {
+    while ((c = bu_getopt(argc, argv, "a:bd:en:o:r:vx:X:u:")) != -1) {
        switch (c) {
            case 'a':           /* Absolute tolerance. */
                ttol.abs = atof(bu_optarg);
                ttol.rel = 0.0;
                break;
-           case 'd':           /* calculational tolerance */
-               tol.dist = atof( bu_optarg );
+           case 'b':           /* BOT dump */
+               bot_dump = 1;
+               break;
+           case 'd':           /* Calculational tolerance */
+               tol.dist = atof(bu_optarg);
                tol.dist_sq = tol.dist * tol.dist;
                break;
+           case 'e':           /* Evaluate all, CSG and BOTs */
+               eval_all = 1;
+               break;
            case 'n':           /* Surface normal tolerance. */
                ttol.norm = atof(bu_optarg)*bn_pi/180.0;
                ttol.rel = 0.0;
@@ -576,23 +649,18 @@
            case 'v':
                verbose++;
                break;
-           case 'P':
-/*                     ncpu = atoi( bu_optarg ); */
-               rt_g.debug = 1;
-               break;
            case 'x':
-               sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.debug );
+               sscanf(bu_optarg, "%x", (unsigned int *)&rt_g.debug);
                break;
            case 'X':
-               sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug );
+               sscanf(bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug);
                NMG_debug = rt_g.NMG_debug;
                break;
            case 'u':
-               units = bu_strdup( bu_optarg );
-               scale_factor = bu_units_conversion( units );
-               if ( ZERO(scale_factor) )
-               {
-                   bu_exit(1, "Unrecognized units (%s)\n", units );
+               units = bu_strdup(bu_optarg);
+               scale_factor = bu_units_conversion(units);
+               if (ZERO(scale_factor)) {
+                   bu_exit(1, "Unrecognized units (%s)\n", units);
                }
                scale_factor = 1.0 / scale_factor;
                break;
@@ -602,21 +670,25 @@
        }
     }
 
-    if (bu_optind+1 >= argc) {
+    if (bu_optind + 1 >= argc) {
        bu_exit(1, usage, argv[0]);
     }
 
-    if ( !units )
+    if (!units) {
        units = "mm";
+    }
 
+    if ((bot_dump == 1) && (eval_all == 1)) {
+       bu_exit(1, "BOT Dump and Evaluate All are mutually exclusive\n");
+    }
+
     /* Open BRL-CAD database */
-    if ((dbip = db_open( argv[bu_optind], "r")) == DBI_NULL)
-    {
+    if ((dbip = db_open( argv[bu_optind], "r")) == DBI_NULL) {
        perror(argv[0]);
-       bu_exit(1, "Cannot open %s\n", argv[bu_optind] );
+       bu_exit(1, "Cannot open %s\n", argv[bu_optind]);
     }
-    if ( db_dirbuild( dbip ) ) {
-       bu_exit(1, "db_dirbuild() failed!\n" );
+    if (db_dirbuild(dbip)) {
+       bu_exit(1, "db_dirbuild() failed!\n");
     }
 
     if (out_file == NULL) {
@@ -625,101 +697,135 @@
        setmode(fileno(fp_out), O_BINARY);
 #endif
     } else {
-       if ((fp_out = fopen( out_file, "wb")) == NULL)
-       {
-           perror( argv[0] );
-           bu_exit(1, "Cannot open %s\n", out_file );
+       if ((fp_out = fopen( out_file, "wb")) == NULL) {
+           perror(argv[0]);
+           bu_exit(1, "Cannot open %s\n", out_file);
        }
     }
 
-    fprintf( fp_out, "#VRML V2.0 utf8\n" );
-    fprintf( fp_out, "#Units are %s\n", units);
-    /* Note we may want to inquire about bounding boxes for the various groups 
and add Viewpoints nodes that
-     * point the camera to the center and orient for Top, Side, etc Views
-     *
-     * We will add some default Material Color definitions (for thousands 
groups) before we start defining the geometry
+    fprintf(fp_out, "#VRML V2.0 utf8\n");
+    fprintf(fp_out, "#Units are %s\n", units);
+    /* NOTE: We may want to inquire about bounding boxes for the
+     * various groups and add Viewpoints nodes that point the camera
+     * to the center and orient for Top, Side, etc Views. We will add
+     * some default Material Color definitions (for thousands groups)
+     * before we start defining the geometry.
      */
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_999 Material { diffuseColor 0.78 0.78 0.78 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_1999 Material { diffuseColor 0.88 0.29 0.29 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_2999 Material { diffuseColor 0.82 0.53 0.54 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_3999 Material { diffuseColor 0.39 0.89 0.00 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_4999 Material { diffuseColor 1.00 0.00 0.00 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_5999 Material { diffuseColor 0.82 0.00 0.82 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_6999 Material { diffuseColor 0.62 0.62 0.62 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_7999 Material { diffuseColor 0.49 0.49 0.49 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_8999 Material { diffuseColor 0.18 0.31 0.31 } } }\n");
-    fprintf( fp_out, "Shape { appearance Appearance { material DEF 
Material_9999 Material { diffuseColor 0.00 0.41 0.82 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF Material_999 
Material { diffuseColor 0.78 0.78 0.78 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_1999 Material { diffuseColor 0.88 0.29 0.29 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_2999 Material { diffuseColor 0.82 0.53 0.54 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_3999 Material { diffuseColor 0.39 0.89 0.00 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_4999 Material { diffuseColor 1.00 0.00 0.00 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_5999 Material { diffuseColor 0.82 0.00 0.82 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_6999 Material { diffuseColor 0.62 0.62 0.62 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_7999 Material { diffuseColor 0.49 0.49 0.49 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_8999 Material { diffuseColor 0.18 0.31 0.31 } } }\n");
+    fprintf(fp_out, "Shape { appearance Appearance { material DEF 
Material_9999 Material { diffuseColor 0.00 0.41 0.82 } } }\n");
 
-    /* I had hoped to create a separate sub-tree (using the Transform node) 
for each group name argument
-     * however, it appears they are all handled at the same time so I will 
only have one Transform for the
-     * complete conversion
-     * Later on switch nodes may be added to turn on and off the groups (via 
ROUTE nodes) */
-    fprintf ( fp_out, "Transform {\n");
-    fprintf ( fp_out, "\tchildren [\n");
+    /* I had hoped to create a separate sub-tree (using the Transform
+     * node) for each group name argument however, it appears they are
+     * all handled at the same time so I will only have one Transform
+     * for the complete conversion. Later on switch nodes may be added
+     * to turn on and off the groups (via ROUTE nodes).
+     */
+    fprintf(fp_out, "Transform {\n");
+    fprintf(fp_out, "\tchildren [\n");
 
     bu_optind++;
 
-    BARRIER_CHECK;
-
     pm.num_bots = 0;
     pm.num_nonbots = 0;
-    pm.array_size = 5;
-    pm.bots = (struct rt_bot_internal **)bu_calloc( pm.array_size,
-                                                   sizeof( struct 
rt_bot_internal *), "pm.bots" );
-    for ( i=bu_optind; i<argc; i++ )
-    {
+
+    if (!eval_all) {
+       pm.array_size = 5;
+       pm.bots = (struct rt_bot_internal **)bu_calloc(pm.array_size,
+                  sizeof(struct rt_bot_internal **), "pm.bots");
+    }
+
+    if (eval_all) {
+       (void)db_walk_tree(dbip, argc-bu_optind, (const char 
**)(&argv[bu_optind]),
+              1,               /* ncpu */
+              &tree_state,
+              0,
+              nmg_region_end,
+              nmg_booltree_leaf_tess,
+              (genptr_t)&pm);  /* in librt/nmg_bool.c */
+       goto out;
+    }
+
+    if (bot_dump) {
+       (void)db_walk_tree(dbip, argc-bu_optind, (const char 
**)(&argv[bu_optind]),
+              1,               /* ncpu */
+              &tree_state,
+              0,
+              do_region_end2,
+              leaf_tess2,
+              (genptr_t)&pm);  /* in librt/nmg_bool.c */
+       goto out;
+    }
+
+    for (i = bu_optind; i < argc; i++) {
        struct directory *dp;
 
-       dp = db_lookup( dbip, argv[i], LOOKUP_QUIET );
-       if ( dp == RT_DIR_NULL )
-       {
-           bu_log( "Cannot find %s\n", argv[i] );
+       dp = db_lookup(dbip, argv[i], LOOKUP_QUIET);
+       if (dp == RT_DIR_NULL) {
+           bu_log("Cannot find %s\n", argv[i]);
            continue;
        }
 
-       fprintf ( fp_out, "# Includes group %s\n", argv[i]);
-
-       /* light source must be a combibation */
-       if ( !(dp->d_flags & RT_DIR_COMB) )
+       /* light source must be a combination */
+       if (!(dp->d_flags & RT_DIR_COMB)) {
            continue;
+       }
 
+       fprintf(fp_out, "# Includes group %s\n", argv[i]);
+
        /* walk trees selecting only light source regions */
        (void)db_walk_tree(dbip, 1, (const char **)(&argv[i]),
-                          1,                           /* ncpu */
+                          1,                   /* ncpu */
                           &tree_state,
                           select_lights,
-                          do_region_end,
-                          leaf_tess,
+                          do_region_end1,
+                          leaf_tess1,
                           (genptr_t)&pm);      /* in librt/nmg_bool.c */
-
-
     }
-    BARRIER_CHECK;
 
     /* Walk indicated tree(s).  Each non-light-source region will be output 
separately */
-    (void)db_walk_tree(dbip, argc-bu_optind, (const char **)(&argv[bu_optind]),
-                      1,                               /* ncpu */
+    (void)db_walk_tree(dbip, argc - bu_optind, (const char 
**)(&argv[bu_optind]),
+                      1,               /* ncpu */
                       &tree_state,
                       select_non_lights,
-                      do_region_end,
-                      leaf_tess,
+                      do_region_end1,
+                      leaf_tess1,
                       (genptr_t)&pm);  /* in librt/nmg_bool.c */
 
-    BARRIER_CHECK;
     /* Release dynamic storage */
     nmg_km(the_model);
 
+    if (!eval_all) {
+       bu_free(pm.bots, "pm.bots");
+    }
+
+out:
     db_close(dbip);
 
     /* Now we need to close each group set */
-    fprintf ( fp_out, "\t]\n}\n");
+    fprintf(fp_out, "\t]\n}\n");
 
-    if ( verbose )
-       bu_log( "Total of %d regions converted of %d regions attempted\n",
-               regions_converted, regions_tried );
+    if (verbose) {
+       bu_log("Total of %d regions converted of %d regions attempted\n",
+               regions_converted, regions_tried);
+    }
 
+    fclose(fp_out);
+    bu_log("Done.\n");
+
     return 0;
 }
+
+
+#if 0
+/* disable unused function */
 void
 process_non_light(struct model *m)
 {
@@ -793,26 +899,31 @@
        }
     }
 }
+#endif
 
 
 void
-nmg_2_vrml(FILE *fp, const struct db_full_path *pathp, struct model *m, struct 
mater_info *mater)
+nmg_2_vrml(struct db_tree_state *tsp, const struct db_full_path *pathp, struct 
model *m)
 {
+    struct mater_info *mater = &tsp->ts_mater;
+    const struct bn_tol *tol2 = tsp->ts_tol;
     struct nmgregion *reg;
     struct bu_ptbl verts;
     struct vrml_mat mat;
     struct bu_vls vls;
     char *tok;
     int i;
-    int first=1;
-    int is_light=0;
+    int first = 1;
+    int is_light = 0;
     point_t ave_pt = VINIT_ZERO;
     struct bu_vls shape_name;
     char *full_path;
-    /*There may be a better way to capture the region_id, than getting the 
rt_comb_internal structure,
-     * (and may be a better way to capture the rt_comb_internal struct), but 
for now I just copied the
-     * method used in select_lights/select_non_lights above, could have used a 
global variable but I noticed
-     * none other were used, so I didn't want to be the first
+    /* There may be a better way to capture the region_id, than
+     * getting the rt_comb_internal structure, (and may be a better
+     * way to capture the rt_comb_internal struct), but for now I just
+     * copied the method used in select_lights/select_non_lights above,
+     * could have used a global variable but I noticed none other were
+     * used, so I didn't want to be the first
      */
     struct directory *dp;
     struct rt_db_internal intern;
@@ -822,146 +933,138 @@
     /* static due to libbu exception handling */
     static float r, g, b;
 
-    NMG_CK_MODEL( m );
+    NMG_CK_MODEL(m);
 
-    BARRIER_CHECK;
+    full_path = db_path_to_string(pathp);
 
-    full_path = db_path_to_string( pathp );
+    RT_CK_FULL_PATH(pathp);
+    dp = DB_FULL_PATH_CUR_DIR(pathp);
 
-    RT_CK_FULL_PATH( pathp );
-    dp = DB_FULL_PATH_CUR_DIR( pathp );
-
-    if ( !(dp->d_flags & RT_DIR_COMB) )
+    if (!(dp->d_flags & RT_DIR_COMB)) {
        return;
+    }
 
     bu_vls_init(&shape_name);
 
-    id = rt_db_get_internal( &intern, dp, dbip, (matp_t)NULL, &rt_uniresource 
);
-    if ( id < 0 )
-    {
-       bu_log( "Cannot internal form of %s\n", dp->d_namep );
+    id = rt_db_get_internal(&intern, dp, dbip, (matp_t)NULL, &rt_uniresource);
+    if (id < 0) {
+       bu_log("Cannot internal form of %s\n", dp->d_namep);
        return;
     }
 
-    if ( id != ID_COMBINATION )
-    {
-       bu_log( "Directory/database mismatch!\n\t is '%s' a combination or 
not?\n",
-               dp->d_namep );
+    if (id != ID_COMBINATION) {
+       bu_log("Directory/database mismatch!\n\t is '%s' a combination or 
not?\n",
+               dp->d_namep);
        return;
     }
 
     comb = (struct rt_comb_internal *)intern.idb_ptr;
-    RT_CK_COMB( comb );
+    RT_CK_COMB(comb);
 
-    if ( mater->ma_color_valid )
-    {
+    if (mater->ma_color_valid) {
        r = mater->ma_color[0];
        g = mater->ma_color[1];
        b = mater->ma_color[2];
-    }
-    else
-    {
+    } else {
        r = g = b = 0.5;
     }
 
-    if ( mater->ma_shader )
-    {
-       tok = strtok( mater->ma_shader, tok_sep );
-       bu_strlcpy( mat.shader, tok, TXT_NAME_SIZE );
+    if (mater->ma_shader) {
+       tok = strtok(mater->ma_shader, tok_sep);
+       bu_strlcpy(mat.shader, tok, TXT_NAME_SIZE);
+    } else {
+       mat.shader[0] = '\0';
     }
-    else
-       mat.shader[0] = '\0';
+
     mat.shininess = -1;
     mat.transparency = -1.0;
     mat.lt_fraction = -1.0;
-    VSETALL( mat.lt_dir, 0.0 );
+    VSETALL(mat.lt_dir, 0.0);
     mat.lt_angle = -1.0;
     mat.tx_file[0] = '\0';
     mat.tx_w = -1;
     mat.tx_n = -1;
-    bu_vls_init( &vls );
-    bu_vls_strcpy( &vls, &mater->ma_shader[strlen(mat.shader)] );
-    (void)bu_struct_parse( &vls, vrml_mat_parse, (char *)&mat );
+    bu_vls_init(&vls);
+    bu_vls_strcpy(&vls, &mater->ma_shader[strlen(mat.shader)]);
+    (void)bu_struct_parse(&vls, vrml_mat_parse, (char *)&mat);
 
-    if ( strncmp( "light", mat.shader, 5 ) == 0 )
-    {
+    if (strncmp("light", mat.shader, 5) == 0) {
        /* this is a light source */
        is_light = 1;
-    }
-    else
-    {
+    } else {
        path_2_vrml_id(&shape_name, full_path);
-       fprintf( fp, "\t\tDEF %s Shape { \n", bu_vls_addr(&shape_name));
+       fprintf(fp_out, "\t\tDEF %s Shape { \n", bu_vls_addr(&shape_name));
 
-       fprintf( fp, "\t\t\t# Component_ID: %ld   %s\n", comb->region_id, 
full_path);
-       fprintf( fp, "\t\t\tappearance Appearance { \n");
+       fprintf(fp_out, "\t\t\t# Component_ID: %ld   %s\n", comb->region_id, 
full_path);
+       fprintf(fp_out, "\t\t\tappearance Appearance { \n");
 
-       if ( strncmp( "plastic", mat.shader, 7 ) == 0 )
-       {
-           if ( mat.shininess < 0 )
+       if (strncmp("plastic", mat.shader, 7) == 0) {
+           if (mat.shininess < 0) {
                mat.shininess = 10;
-           if ( mat.transparency < 0.0 )
+           }
+           if (mat.transparency < SMALL_FASTF) {
                mat.transparency = 0.0;
+           }
 
-           fprintf( fp, "\t\t\t\tmaterial Material {\n" );
-           fprintf( fp, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, g, b );
-           fprintf( fp, "\t\t\t\t\tshininess %g\n", 
1.0-exp(-(double)mat.shininess/20.0 ) );
-           if ( mat.transparency > 0.0 )
-               fprintf( fp, "\t\t\t\t\ttransparency %g\n", mat.transparency );
-           fprintf( fp, "\t\t\t\t\tspecularColor %g %g %g \n\t\t\t\t}\n", 1.0, 
1.0, 1.0 );
-       }
-       else if ( strncmp( "glass", mat.shader, 5 ) == 0 )
-       {
-           if ( mat.shininess < 0 )
+           fprintf(fp_out, "\t\t\t\tmaterial Material {\n");
+           fprintf(fp_out, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, g, b);
+           fprintf(fp_out, "\t\t\t\t\tshininess %g\n", 
1.0-exp(-(double)mat.shininess/20.0));
+           if (mat.transparency > SMALL_FASTF) {
+               fprintf(fp_out, "\t\t\t\t\ttransparency %g\n", 
mat.transparency);
+           }
+           fprintf(fp_out, "\t\t\t\t\tspecularColor %g %g %g \n\t\t\t\t}\n", 
1.0, 1.0, 1.0);
+       } else if (strncmp("glass", mat.shader, 5) == 0) {
+           if (mat.shininess < 0) {
                mat.shininess = 4;
-           if ( mat.transparency < 0.0 )
+           }
+           if (mat.transparency < SMALL_FASTF) {
                mat.transparency = 0.8;
+           }
 
-           fprintf( fp, "\t\t\t\tmaterial Material {\n" );
-           fprintf( fp, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, g, b );
-           fprintf( fp, "\t\t\t\t\tshininess %g\n", 
1.0-exp(-(double)mat.shininess/20.0 ) );
-           if ( mat.transparency > 0.0 )
-               fprintf( fp, "\t\t\t\t\ttransparency %g\n", mat.transparency );
-           fprintf( fp, "\t\t\t\t\tspecularColor %g %g %g \n\t\t\t\t}\n", 1.0, 
1.0, 1.0 );
-       }
-       else if ( strncmp( "texture", mat.shader, 7 ) == 0 )
-       {
-           if ( mat.tx_w < 0 )
+           fprintf(fp_out, "\t\t\t\tmaterial Material {\n");
+           fprintf(fp_out, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, g, b);
+           fprintf(fp_out, "\t\t\t\t\tshininess %g\n", 
1.0-exp(-(double)mat.shininess/20.0));
+           if (mat.transparency > SMALL_FASTF) {
+               fprintf(fp_out, "\t\t\t\t\ttransparency %g\n", 
mat.transparency);
+           }
+           fprintf(fp_out, "\t\t\t\t\tspecularColor %g %g %g \n\t\t\t\t}\n", 
1.0, 1.0, 1.0);
+       } else if (strncmp("texture", mat.shader, 7) == 0) {
+           if (mat.tx_w < 0) {
                mat.tx_w = 512;
-           if ( mat.tx_n < 0 )
+           }
+           if (mat.tx_n < 0) {
                mat.tx_n = 512;
-
-           if ( strlen( mat.tx_file ) )
-           {
+           }
+           if (strlen(mat.tx_file)) {
                int tex_fd;
                int nbytes;
                long tex_len;
-               long bytes_read=0;
-               unsigned char tex_buf[TXT_BUF_LEN*3];
+               long bytes_read = 0;
+               unsigned char tex_buf[TXT_BUF_LEN * 3];
 
                if ((tex_fd = open(mat.tx_file, O_RDONLY | O_BINARY)) == (-1)) {
-                   bu_log( "Cannot open texture file (%s)\n", mat.tx_file );
-                   perror( "g-vrml: " );
+                   bu_log("Cannot open texture file (%s)\n", mat.tx_file);
+                   perror("g-vrml: ");
                } else {
                    /* Johns note - need to check (test) the texture stuff */
-                   fprintf( fp, "\t\t\t\ttextureTransform TextureTransform 
{\n");
-                   fprintf( fp, "\t\t\t\t\tscale 1.33333 
1.33333\n\t\t\t\t}\n");
-                   fprintf( fp, "\t\t\t\ttexture PixelTexture {\n");
-                   fprintf( fp, "\t\t\t\t\trepeatS TRUE\n");
-                   fprintf( fp, "\t\t\t\t\trepeatT TRUE\n");
-                   fprintf( fp, "\t\t\t\t\timage %d %d %d\n", mat.tx_w, 
mat.tx_n, 3 );
-                   tex_len = mat.tx_w*mat.tx_n*3;
-                   while ( bytes_read < tex_len )
-                   {
+                   fprintf(fp_out, "\t\t\t\ttextureTransform TextureTransform 
{\n");
+                   fprintf(fp_out, "\t\t\t\t\tscale 1.33333 
1.33333\n\t\t\t\t}\n");
+                   fprintf(fp_out, "\t\t\t\ttexture PixelTexture {\n");
+                   fprintf(fp_out, "\t\t\t\t\trepeatS TRUE\n");
+                   fprintf(fp_out, "\t\t\t\t\trepeatT TRUE\n");
+                   fprintf(fp_out, "\t\t\t\t\timage %d %d %d\n", mat.tx_w, 
mat.tx_n, 3);
+                   tex_len = mat.tx_w*mat.tx_n * 3;
+                   while (bytes_read < tex_len) {
                        long bytes_to_go=tex_len;
                        long readval;
 
                        bytes_to_go = tex_len - bytes_read;
-                       if ( bytes_to_go > TXT_BUF_LEN*3 )
-                           bytes_to_go = TXT_BUF_LEN*3;
+                       if (bytes_to_go > TXT_BUF_LEN * 3) {
+                           bytes_to_go = TXT_BUF_LEN * 3;
+                       }
                        nbytes = 0;
-                       while ( nbytes < bytes_to_go ) {
-                           readval = read( tex_fd, &tex_buf[nbytes], 
bytes_to_go-nbytes );
+                       while (nbytes < bytes_to_go) {
+                           readval = read(tex_fd, &tex_buf[nbytes], 
bytes_to_go-nbytes);
                            if (readval < 0) {
                                perror("READ ERROR");
                                break;
@@ -969,184 +1072,168 @@
                                nbytes += readval;
                            }
                        }
-
                        bytes_read += nbytes;
-                       for ( i=0; i<nbytes; i += 3 )
-                           fprintf( fp, "\t\t\t0x%02x%02x%02x\n",
-                                    tex_buf[i],
-                                    tex_buf[i+1],
-                                    tex_buf[i+2] );
+                       for (i = 0; i < nbytes; i += 3) {
+                           fprintf(fp_out, "\t\t\t0x%02x%02x%02x\n", 
+                                   tex_buf[i], tex_buf[i+1], tex_buf[i+2]);
+                       }
                    }
-                   fprintf( fp, "\t\t\t\t}\n" );
+                   fprintf(fp_out, "\t\t\t\t}\n");
                }
            }
-       }
-       else if ( mater->ma_color_valid )
-       {
+       } else if (mater->ma_color_valid) {
            /* no shader specified, but a color is assigned */
-           fprintf( fp, "\t\t\t\tmaterial Material {\n" );
-           fprintf( fp, "\t\t\t\t\tdiffuseColor %g %g %g }\n", r, g, b );
-       }
-       else
-       {
+           fprintf(fp_out, "\t\t\t\tmaterial Material {\n");
+           fprintf(fp_out, "\t\t\t\t\tdiffuseColor %g %g %g }\n", r, g, b);
+       } else {
            /* If no color was defined set the colors according to the 
thousands groups */
-           int thou = comb->region_id/1000;
-           thou == 0 ? fprintf( fp, "\t\t\tmaterial USE Material_999\n")
-               : thou == 1 ? fprintf( fp, "\t\t\tmaterial USE Material_1999\n")
-               : thou == 2 ? fprintf( fp, "\t\t\tmaterial USE Material_2999\n")
-               : thou == 3 ? fprintf( fp, "\t\t\tmaterial USE Material_3999\n")
-               : thou == 4 ? fprintf( fp, "\t\t\tmaterial USE Material_4999\n")
-               : thou == 5 ? fprintf( fp, "\t\t\tmaterial USE Material_5999\n")
-               : thou == 6 ? fprintf( fp, "\t\t\tmaterial USE Material_6999\n")
-               : thou == 7 ? fprintf( fp, "\t\t\tmaterial USE Material_7999\n")
-               : thou == 8 ? fprintf( fp, "\t\t\tmaterial USE Material_8999\n")
-               : fprintf( fp, "\t\t\tmaterial USE Material_9999\n");
-
-/*                     fprintf( fp, "\t\t\t\tmaterial Material {\n" );
- *                     fprintf( fp, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, 
g, b );
- *                     fprintf( fp, "\t\t\t\t\tspecularColor %g %g %g 
\n\t\t\t\t}\n", 1.0, 1.0, 1.0 );
- */
+           int thou = comb->region_id / 1000;
+           thou == 0 ? fprintf(fp_out, "\t\t\tmaterial USE Material_999\n")
+               : thou == 1 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_1999\n")
+               : thou == 2 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_2999\n")
+               : thou == 3 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_3999\n")
+               : thou == 4 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_4999\n")
+               : thou == 5 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_5999\n")
+               : thou == 6 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_6999\n")
+               : thou == 7 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_7999\n")
+               : thou == 8 ? fprintf(fp_out, "\t\t\tmaterial USE 
Material_8999\n")
+               : fprintf(fp_out, "\t\t\tmaterial USE Material_9999\n");
+#if 0
+           fprintf( fp, "\t\t\t\tmaterial Material {\n");
+           fprintf( fp, "\t\t\t\t\tdiffuseColor %g %g %g \n", r, g, b);
+           fprintf( fp, "\t\t\t\t\tspecularColor %g %g %g \n\t\t\t\t}\n", 1.0, 
1.0, 1.0);
+#endif
        }
     }
 
-    if ( !is_light )
-    {
-       process_non_light(m);
-       fprintf( fp, "\t\t\t} \n");
-       fprintf( fp, "\t\t\tgeometry IndexedFaceSet { \n");
-       fprintf( fp, "\t\t\t\tcoord Coordinate { \n");
+    if (!is_light) {
+       nmg_triangulate_model(m, tol2);
+       fprintf(fp_out, "\t\t\t} \n");
+       fprintf(fp_out, "\t\t\tgeometry IndexedFaceSet { \n");
+       fprintf(fp_out, "\t\t\t\tcoord Coordinate { \n");
     }
 
     /* get list of vertices */
-    nmg_vertex_tabulate( &verts, &m->magic );
-    if ( !is_light )
-       fprintf( fp, "\t\t\t\t\tpoint [");
-    else
-    {
-       VSETALL( ave_pt, 0.0 );
+    nmg_vertex_tabulate(&verts, &m->magic);
+    if (!is_light) {
+       fprintf(fp_out, "\t\t\t\t\tpoint [");
+    } else {
+       VSETALL(ave_pt, 0.0);
     }
 
-    for ( i=0; i<BU_PTBL_END( &verts ); i++ )
-    {
+    for (i = 0; i < BU_PTBL_END(&verts); i++) {
        struct vertex *v;
        struct vertex_g *vg;
        point_t pt_meters;
 
-       v = (struct vertex *)BU_PTBL_GET( &verts, i );
-       NMG_CK_VERTEX( v );
+       v = (struct vertex *)BU_PTBL_GET(&verts, i);
+       NMG_CK_VERTEX(v);
        vg = v->vg_p;
-       NMG_CK_VERTEX_G( vg );
+       NMG_CK_VERTEX_G(vg);
 
        /* convert to desired units */
-       VSCALE( pt_meters, vg->coord, scale_factor );
+       VSCALE(pt_meters, vg->coord, scale_factor);
 
-       if ( is_light )
-           VADD2( ave_pt, ave_pt, pt_meters )
-               if ( first )
-               {
-                   if ( !is_light )
-                       fprintf( fp, " %10.10e %10.10e %10.10e, # point %d\n", 
V3ARGS( pt_meters ), i );
-                   first = 0;
-               }
-               else
-                   if ( !is_light )
-                       fprintf( fp, "\t\t\t\t\t%10.10e %10.10e %10.10e, # 
point %d\n", V3ARGS( pt_meters ), i );
+       if (is_light) {
+           VADD2(ave_pt, ave_pt, pt_meters);
+       }
+
+       if (first) {
+           if (!is_light) {
+               fprintf(fp_out, " %10.10e %10.10e %10.10e, # point %d\n", 
V3ARGS(pt_meters), i);
+           }   
+           first = 0;
+       } else if (!is_light) {
+           fprintf(fp_out, "\t\t\t\t\t%10.10e %10.10e %10.10e, # point %d\n", 
V3ARGS(pt_meters), i);
+       }
     }
-    if ( !is_light )
-       fprintf( fp, "\t\t\t\t\t]\n\t\t\t\t}\n" );
-    else
-    {
+
+    if (!is_light) {
+       fprintf(fp_out, "\t\t\t\t\t]\n\t\t\t\t}\n");
+    } else {
        fastf_t one_over_count;
-
-       one_over_count = 1.0/(fastf_t)BU_PTBL_END( &verts );
-       VSCALE( ave_pt, ave_pt, one_over_count );
+       one_over_count = 1.0/(fastf_t)BU_PTBL_END(&verts);
+       VSCALE(ave_pt, ave_pt, one_over_count);
     }
 
     first = 1;
-    if ( !is_light )
-    {
-       fprintf( fp, "\t\t\t\tcoordIndex [\n");
-       for ( BU_LIST_FOR( reg, nmgregion, &m->r_hd ) )
-       {
+    if (!is_light) {
+       fprintf(fp_out, "\t\t\t\tcoordIndex [\n");
+       for (BU_LIST_FOR(reg, nmgregion, &m->r_hd)) {
            struct shell *s;
 
-           NMG_CK_REGION( reg );
-           for ( BU_LIST_FOR( s, shell, &reg->s_hd ) )
-           {
+           NMG_CK_REGION(reg);
+           for (BU_LIST_FOR( s, shell, &reg->s_hd)) {
                struct faceuse *fu;
 
-               NMG_CK_SHELL( s );
-               for ( BU_LIST_FOR( fu, faceuse, &s->fu_hd ) )
-               {
+               NMG_CK_SHELL(s);
+               for (BU_LIST_FOR(fu, faceuse, &s->fu_hd)) {
                    struct loopuse *lu;
 
-                   NMG_CK_FACEUSE( fu );
+                   NMG_CK_FACEUSE(fu);
 
-                   if ( fu->orientation != OT_SAME )
+                   if (fu->orientation != OT_SAME) {
                        continue;
+                   }
 
-                   for ( BU_LIST_FOR( lu, loopuse, &fu->lu_hd ) )
-                   {
+                   for (BU_LIST_FOR(lu, loopuse, &fu->lu_hd)) {
                        struct edgeuse *eu;
 
-                       NMG_CK_LOOPUSE( lu );
-
-                       if ( BU_LIST_FIRST_MAGIC( &lu->down_hd ) != 
NMG_EDGEUSE_MAGIC )
+                       NMG_CK_LOOPUSE(lu);
+                       if (BU_LIST_FIRST_MAGIC( &lu->down_hd ) != 
NMG_EDGEUSE_MAGIC) {
                            continue;
+                       }
 
-                       if ( !first )
-                           fprintf( fp, ",\n" );
-                       else
+                       if (!first) {
+                           fprintf(fp_out, ",\n");
+                       } else {
                            first = 0;
+                       }
 
-                       fprintf( fp, "\t\t\t\t\t" );
-                       for ( BU_LIST_FOR( eu, edgeuse, &lu->down_hd ) )
-                       {
+                       fprintf(fp_out, "\t\t\t\t\t");
+                       for (BU_LIST_FOR(eu, edgeuse, &lu->down_hd)) {
                            struct vertex *v;
 
-                           NMG_CK_EDGEUSE( eu );
-
+                           NMG_CK_EDGEUSE(eu);
                            v = eu->vu_p->v_p;
-                           NMG_CK_VERTEX( v );
-                           fprintf( fp, " %d,", bu_ptbl_locate( &verts, (long 
*)v ) );
+                           NMG_CK_VERTEX(v);
+                           fprintf(fp_out, " %d,", bu_ptbl_locate( &verts, 
(long *)v ));
                        }
-                       fprintf( fp, "-1" );
+                       fprintf(fp_out, "-1");
                    }
                }
            }
        }
-       fprintf( fp, "\n\t\t\t\t]\n\t\t\t\tnormalPerVertex FALSE\n");
-       fprintf( fp, "\t\t\t\tconvex FALSE\n");
-       fprintf( fp, "\t\t\t\tcreaseAngle 0.5\n");
-       fprintf( fp, "\t\t\t}\n\t\t}\n");
-    }
-    else
-    {
+       fprintf(fp_out, "\n\t\t\t\t]\n\t\t\t\tnormalPerVertex FALSE\n");
+       fprintf(fp_out, "\t\t\t\tconvex FALSE\n");
+       fprintf(fp_out, "\t\t\t\tcreaseAngle 0.5\n");
+       fprintf(fp_out, "\t\t\t}\n\t\t}\n");
+    } else {
        mat.lt_fraction = 0.0;
        mat.lt_angle = 180.0;
-       VSETALL( mat.lt_dir, 0.0 );
+       VSETALL(mat.lt_dir, 0.0);
 
-       if ( !ZERO(mat.lt_dir[X]) || !ZERO(mat.lt_dir[Y]) || 
!ZERO(mat.lt_dir[Z]) )
-       {
-           fprintf( fp, "\t\tSpotLight {\n" );
-           fprintf( fp, "\t\t\ton \tTRUE\n" );
-           if ( mat.lt_fraction > 0.0 )
-               fprintf( fp, "\t\t\tintensity \t%g\n", mat.lt_fraction );
-           fprintf( fp, "\t\t\tcolor \t%g %g %g\n", r, g, b );
-           fprintf( fp, "\t\t\tlocation \t%g %g %g\n", V3ARGS( ave_pt ) );
-           fprintf( fp, "\t\t\tdirection \t%g %g %g\n", V3ARGS( mat.lt_dir ) );
-           fprintf( fp, "\t\t\tcutOffAngle \t%g }\n", mat.lt_angle );
+       if (!ZERO(mat.lt_dir[X]) || !ZERO(mat.lt_dir[Y]) || 
!ZERO(mat.lt_dir[Z])) {
+           fprintf(fp_out, "\t\tSpotLight {\n");
+           fprintf(fp_out, "\t\t\ton \tTRUE\n");
+           if (mat.lt_fraction > 0.0) {
+               fprintf(fp_out, "\t\t\tintensity \t%g\n", mat.lt_fraction);
+           }
+           fprintf(fp_out, "\t\t\tcolor \t%g %g %g\n", r, g, b);
+           fprintf(fp_out, "\t\t\tlocation \t%g %g %g\n", V3ARGS(ave_pt));
+           fprintf(fp_out, "\t\t\tdirection \t%g %g %g\n", V3ARGS(mat.lt_dir));
+           fprintf(fp_out, "\t\t\tcutOffAngle \t%g }\n", mat.lt_angle);
+       } else {
+           fprintf(fp_out, "\t\tPointLight {\n\t\t\ton TRUE\n\t\t\tintensity 
1\n\t\t\tcolor %g %g %g\n\t\t\tlocation %g %g %g\n\t\t}\n", 
+                   r, g, b, V3ARGS(ave_pt));
        }
-       else
-           fprintf( fp, "\t\tPointLight {\n\t\t\ton TRUE\n\t\t\tintensity 
1\n\t\t\tcolor %g %g %g\n\t\t\tlocation %g %g %g\n\t\t}\n", r, g, b, V3ARGS( 
ave_pt ) );
     }
 
     bu_vls_free(&vls);
     bu_vls_free(&shape_name);
-
-    BARRIER_CHECK;
 }
 
+
 void
 bot2vrml( struct plate_mode *pmp, const struct db_full_path *pathp, int 
region_id )
 {
@@ -1158,8 +1245,6 @@
     size_t i;
     size_t vert_count=0;
 
-    BARRIER_CHECK;
-
     path_str = db_path_to_string( pathp );
 
     bu_vls_init(&shape_name);
@@ -1205,49 +1290,77 @@
     fprintf( fp_out, "\t\t\t\tcreaseAngle 0.5\n" );
     fprintf( fp_out, "\t\t\t\tsolid FALSE\n" );
     fprintf( fp_out, "\t\t\t}\n\t\t}\n" );
-    BARRIER_CHECK;
 }
 
-/*
- *                     D O _ R E G I O N _ E N D
+
+/*     D O _ R E G I O N _ E N D 1
  *
  *  Called from db_walk_tree().
- *
  *  This routine must be prepared to run in parallel.
  */
 union tree *
-do_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, genptr_t client_data)
+do_region_end1(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, genptr_t client_data)
 {
     struct plate_mode *pmp = (struct plate_mode *)client_data;
     char *name;
 
-    BARRIER_CHECK;
-    if ( tsp->ts_is_fastgen != REGION_FASTGEN_PLATE ) {
-       clean_pmp( pmp );
-       return nmg_region_end(tsp, pathp, curtree, client_data);
+    if (pmp->num_bots > 0 && pmp->num_nonbots > 0) {
+       bu_log("pmp->num_bots = %d pmp->num_nonbots = %d\n", pmp->num_bots, 
pmp->num_nonbots);
+       bu_bomb("region was both bot and non-bot objects\n");
     }
+    if (RT_G_DEBUG&DEBUG_TREEWALK || verbose) {
+       bu_log("\nConverted %d%% so far (%d of %d)\n",
+               regions_tried > 0 ? (regions_converted * 100) / regions_tried : 
0,
+               regions_converted, regions_tried);
+    }
 
-    /* FASTGEN plate mode region, just spew the bot triangles */
-    if ( pmp->num_bots < 1 || pmp->num_nonbots > 0 ) {
-       clean_pmp( pmp );
-       BARRIER_CHECK;
+    regions_tried++;
+    if (pmp->num_bots > 0) {
+       name = db_path_to_string(pathp);
+       bu_log("Attempting %s\n", name);
+       bu_free(name, "db_path_to_string");
+       bot2vrml(pmp, pathp, tsp->ts_regionid);
+       clean_pmp(pmp);
+       regions_converted++;
+       return (union tree *)NULL;
+    } else {
+       regions_converted++;
        return nmg_region_end(tsp, pathp, curtree, client_data);
     }
+}
 
-    if (RT_G_DEBUG&DEBUG_TREEWALK || verbose) {
+/*     D O _ R E G I O N _ E N D 2
+ *
+ *  Called from db_walk_tree().
+ *  This routine must be prepared to run in parallel.
+ *
+ *  Only send bots from structure outside tree to vrml file.
+ */
+union tree *
+do_region_end2(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, genptr_t client_data)
+{
+    struct plate_mode *pmp = (struct plate_mode *)client_data;
+    char *name;
+    union tree *curtree_tmp;
+
+    curtree_tmp = curtree; /* to quiet compiler */
+
+    if ((pmp->num_bots > 0) && (RT_G_DEBUG&DEBUG_TREEWALK || verbose)) {
        bu_log("\nConverted %d%% so far (%d of %d)\n",
-              regions_tried>0 ? (regions_converted * 100) / regions_tried : 0,
-              regions_converted, regions_tried );
+               regions_tried > 0 ? (regions_converted * 100) / regions_tried : 
0,
+               regions_converted, regions_tried);
     }
 
     regions_tried++;
-    name = db_path_to_string( pathp );
-    bu_log( "Attempting %s\n", name );
-    bu_free( name, "db_path_to_string" );
-    bot2vrml( pmp, pathp, tsp->ts_regionid );
-    clean_pmp( pmp );
-    regions_converted++;
-    BARRIER_CHECK;
+    if (pmp->num_bots > 0) {
+       name = db_path_to_string(pathp);
+       bu_log("Attempting %s\n", name);
+       bu_free(name, "db_path_to_string");
+       bot2vrml(pmp, pathp, tsp->ts_regionid);
+       clean_pmp(pmp);
+       regions_converted++;
+    }
+
     return (union tree *)NULL;
 }
 
@@ -1258,100 +1371,96 @@
     union tree *ret_tree = TREE_NULL;
 
     /* Begin bomb protection */
-    if ( !BU_SETJUMP ) {
+    if (!BU_SETJUMP) {
        /* try */
-
        ret_tree = nmg_booltree_evaluate(curtree, tsp->ts_tol, &rt_uniresource);
-
     } else {
        /* catch */
-
        char *name = db_path_to_string(pathp);
 
        /* Error, bail out */
-       bu_log( "conversion of %s FAILED!\n", name );
+       bu_log("conversion of %s FAILED!\n", name);
 
        /* Sometimes the NMG library adds debugging bits when
         * it detects an internal error, before before bombing out.
         */
-       rt_g.NMG_debug = NMG_debug;     /* restore mode */
+       rt_g.NMG_debug = NMG_debug; /* restore mode */
 
        /* Release any intersector 2d tables */
        nmg_isect2d_final_cleanup();
 
        /* Release the tree memory & input regions */
-       db_free_tree(curtree, &rt_uniresource);         /* Does an nmg_kr() */
+       db_free_tree(curtree, &rt_uniresource); /* Does an nmg_kr() */
 
        /* Get rid of (m)any other intermediate structures */
-       if ( (*tsp->ts_m)->magic == NMG_MODEL_MAGIC ) {
+       if ((*tsp->ts_m)->magic == NMG_MODEL_MAGIC) {
            nmg_km(*tsp->ts_m);
        } else {
            bu_log("WARNING: tsp->ts_m pointer corrupted, ignoring it.\n");
        }
 
-       bu_free( name, "db_path_to_string" );
+       bu_free(name, "db_path_to_string");
        /* Now, make a new, clean model structure for next pass. */
        *tsp->ts_m = nmg_mm();
-    } BU_UNSETJUMP;            /* Relinquish the protection */
+    }
 
+    BU_UNSETJUMP; /* Relinquish the protection */
+
     return ret_tree;
 }
 
 union tree *
 nmg_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, 
union tree *curtree, genptr_t UNUSED(client_data))
 {
-    struct nmgregion   *r;
-    struct bu_list             vhead;
-    union tree         *ret_tree;
-    char                       *name;
+    struct nmgregion *r;
+    struct bu_list vhead;
+    union tree *ret_tree;
+    char *name;
 
     RT_CK_TESS_TOL(tsp->ts_ttol);
     BN_CK_TOL(tsp->ts_tol);
     NMG_CK_MODEL(*tsp->ts_m);
 
-    BARRIER_CHECK;
     BU_LIST_INIT(&vhead);
 
     if (RT_G_DEBUG&DEBUG_TREEWALK || verbose) {
        bu_log("\nConverted %d%% so far (%d of %d)\n",
-              regions_tried>0 ? (regions_converted * 100) / regions_tried : 0,
-              regions_converted, regions_tried );
+              regions_tried > 0 ? (regions_converted * 100) / regions_tried : 
0,
+              regions_converted, regions_tried);
     }
 
-    if (curtree->tr_op == OP_NOP)
+    if (curtree->tr_op == OP_NOP) {
        return curtree;
+    }
 
-    name = db_path_to_string( pathp );
-    bu_log( "Attempting %s\n", name );
+    name = db_path_to_string(pathp);
+    bu_log("Attempting %s\n", name);
 
     regions_tried++;
 
     ret_tree = process_boolean(curtree, tsp, pathp);
 
-    if ( ret_tree )
+    if (ret_tree) {
        r = ret_tree->tr_d.td_r;
-    else
+    } else {
        r = (struct nmgregion *)NULL;
+    }
 
-    bu_free( name, "db_path_to_string" );
+    bu_free(name, "db_path_to_string");
     regions_converted++;
-    if (r != (struct nmgregion *)NULL)
-    {
+    if (r != (struct nmgregion *)NULL) {
        struct shell *s;
-       int empty_region=0;
-       int empty_model=0;
+       int empty_region = 0;
+       int empty_model = 0;
 
        /* Kill cracks */
-       s = BU_LIST_FIRST( shell, &r->s_hd );
-       while ( BU_LIST_NOT_HEAD( &s->l, &r->s_hd ) )
-       {
+       s = BU_LIST_FIRST(shell, &r->s_hd);
+       while (BU_LIST_NOT_HEAD(&s->l, &r->s_hd)) {
            struct shell *next_s;
 
-           next_s = BU_LIST_PNEXT( shell, &s->l );
-           if ( nmg_kill_cracks( s ) )
-           {
-               if ( nmg_ks( s ) )
-               {
+           next_s = BU_LIST_PNEXT(shell, &s->l);
+           if (nmg_kill_cracks(s)) {
+               if (nmg_ks(s)) {
                    empty_region = 1;
                    break;
                }
@@ -1360,38 +1469,34 @@
        }
 
        /* kill zero length edgeuses */
-       if ( !empty_region )
-       {
-           empty_model = nmg_kill_zero_length_edgeuses( *tsp->ts_m );
+       if (!empty_region) {
+           empty_model = nmg_kill_zero_length_edgeuses(*tsp->ts_m);
        }
 
-       if ( !empty_region && !empty_model )
-       {
+       if (!empty_region && !empty_model) {
            /* Write the nmgregion to the output file */
-           nmg_2_vrml( fp_out, pathp, r->m_p, &tsp->ts_mater );
+           nmg_2_vrml(tsp, pathp, r->m_p);
        }
 
        /* NMG region is no longer necessary */
-       if ( !empty_model )
+       if (!empty_model) {
            nmg_kr(r);
-
+       }
+    } else {
+       bu_log("WARNING: Nothing left after Boolean evaluation of %s\n",
+               db_path_to_string(pathp));
     }
-    else
-       bu_log( "WARNING: Nothing left after Boolean evaluation of %s\n",
-               db_path_to_string( pathp ) );
 
-    /*
-     *  Dispose of original tree, so that all associated dynamic
+    /*  Dispose of original tree, so that all associated dynamic
      *  memory is released now, not at the end of all regions.
      *  A return of TREE_NULL from this routine signals an error,
      *  so we need to cons up an OP_NOP node to return.
      */
-    db_free_tree(curtree, &rt_uniresource);            /* Does an nmg_kr() */
+    db_free_tree(curtree, &rt_uniresource); /* Does an nmg_kr() */
 
     BU_GETUNION(curtree, tree);
     RT_TREE_INIT(curtree);
     curtree->tr_op = OP_NOP;
-    BARRIER_CHECK;
     return curtree;
 }
 
@@ -1404,3 +1509,4 @@
  * End:
  * ex: shiftwidth=4 tabstop=8
  */
+

This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.


------------------------------------------------------------------------------
All the data continuously generated in your IT infrastructure contains a
definitive record of customers, application performance, security
threats, fraudulent activity and more. Splunk takes this data and makes
sense of it. Business sense. IT sense. Common sense.
http://p.sf.net/sfu/splunk-d2dcopy1
_______________________________________________
BRL-CAD Source Commits mailing list
brlcad-commits@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to