int main(int argc, char **argv) { int c; double percent; bu_setprogname(argv[0]); bu_setlinebuf(stderr); tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; /* Set up tessellation tolerance defaults */ ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* Set up calculation tolerance defaults */ /* FIXME: These need to be improved */ tol.magic = BN_TOL_MAGIC; tol.dist = 0.0005; tol.dist_sq = tol.dist * tol.dist; tol.perp = 1e-6; tol.para = 1 - tol.perp; /* init resources we might need */ rt_init_resource(&rt_uniresource, 0, NULL); /* make empty NMG model */ the_model = nmg_mm(); /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "r:a:n:o:vx:D:X:h?")) != -1) { switch (c) { case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name. */ /* grab output file name */ break; case 'v': verbose++; break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'D': tol.dist = atof(bu_optarg); tol.dist_sq = tol.dist * tol.dist; rt_pr_tol(&tol); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug); NMG_debug = RTG.NMG_debug; break; default: bu_exit(1, usage, argv[0]); } } if (bu_optind+1 >= argc) bu_exit(1, usage, argv[0]); /* Open output file */ /* Open BRL-CAD database */ argc -= bu_optind; argv += bu_optind; if ((dbip = db_open(argv[0], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "ERROR: Unable to open geometry database file (%s)\n", argv[0]); } if (db_dirbuild(dbip)) bu_exit(1, "db_dirbuild failed\n"); BN_CK_TOL(tree_state.ts_tol); RT_CK_TESS_TOL(tree_state.ts_ttol); if (verbose) { int i; bu_log("Model: %s\n", argv[0]); bu_log("Objects:"); for (i = 1; i < argc; i++) bu_log(" %s", argv[i]); bu_log("\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm = %g\n", tree_state.ts_ttol->abs, tree_state.ts_ttol->rel, tree_state.ts_ttol->norm); bu_log("Calculational tolerances:\n\tdist = %g mm perp = %g\n", tree_state.ts_tol->dist, tree_state.ts_tol->perp); } /* Walk indicated tree(s). Each region will be output separately */ (void) db_walk_tree(dbip, argc-1, (const char **)(argv+1), 1, /* ncpu */ &tree_state, 0, /* take all regions */ do_region_end, nmg_booltree_leaf_tess, (void *)NULL); /* in librt/nmg_bool.c */ percent = 0; if (regions_tried>0) { percent = ((double)regions_converted * 100) / regions_tried; bu_log("Tried %d regions, %d converted to NMG's successfully. %g%%\n", regions_tried, regions_converted, percent); } percent = 0; if (regions_tried > 0) { percent = ((double)regions_written * 100) / regions_tried; bu_log(" %d triangulated successfully. %g%%\n", regions_written, percent); } bu_log("%zd triangles written\n", tot_polygons); bu_log("Tessellation parameters used:\n"); bu_log(" abs [-a] %g\n", ttol.abs); bu_log(" rel [-r] %g\n", ttol.rel); bu_log(" norm [-n] %g\n", ttol.norm); bu_log(" dist [-D] %g\n", tol.dist); /* Release dynamic storage */ nmg_km(the_model); rt_vlist_cleanup(); db_close(dbip); return 0; }
/* * M A I N */ int main(int argc, char **argv) { register int c; double percent; bu_setlinebuf( stderr ); #if MEMORY_LEAK_CHECKING rt_g.debug |= DEBUG_MEM_FULL; #endif tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* XXX These need to be improved */ tol.magic = BN_TOL_MAGIC; tol.dist = 0.005; tol.dist_sq = tol.dist * tol.dist; tol.perp = 1e-5; tol.para = 1 - tol.perp; rt_init_resource( &rt_uniresource, 0, NULL ); the_model = nmg_mm(); BU_LIST_INIT( &rt_g.rtg_vlfree ); /* for vlist macros */ /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "mua:n:o:r:vx:D:P:X:e:i")) != EOF) { switch (c) { case 'm': /* include 'usemtl' statements */ usemtl = 1; break; case 'u': /* Include vertexuse normals */ do_normals = 1; break; case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name. */ output_file = bu_optarg; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi( bu_optarg ); rt_g.debug = 1; /* XXX DEBUG_ALLRAYS -- to get core dumps */ break; case 'x': sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.debug ); break; case 'D': tol.dist = atof(bu_optarg); tol.dist_sq = tol.dist * tol.dist; rt_pr_tol( &tol ); break; case 'X': sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug ); NMG_debug = rt_g.NMG_debug; break; case 'e': /* Error file name. */ error_file = bu_optarg; break; case 'i': inches = 1; break; default: bu_exit(1, usage, argv[0]); break; } } if (bu_optind+1 >= argc) { bu_exit(1, usage, argv[0]); } if ( !output_file ) fp = stdout; else { /* Open output file */ if ( (fp=fopen( output_file, "wb+" )) == NULL ) { perror( argv[0] ); bu_exit(1, "Cannot open output file (%s) for writing\n", output_file ); } } /* Open g-obj error log file */ if (!error_file) { fpe = stderr; #if defined(_WIN32) && !defined(__CYGWIN__) setmode(fileno(fpe), O_BINARY); #endif } else if ((fpe=fopen(error_file, "wb")) == NULL) { perror( argv[0] ); bu_exit(1, "Cannot open output file (%s) for writing\n", error_file ); } /* Open BRL-CAD database */ argc -= bu_optind; argv += bu_optind; if ((dbip = db_open(argv[0], "r")) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Unable to open geometry file (%s) for reading\n", argv[0]); } if ( db_dirbuild( dbip ) ) { bu_exit(1, "db_dirbuild failed\n"); } BN_CK_TOL(tree_state.ts_tol); RT_CK_TESS_TOL(tree_state.ts_ttol); /* Write out header */ if (inches) fprintf(fp, "# BRL-CAD generated Wavefront OBJ file (Units in)\n"); else fprintf(fp, "# BRL-CAD generated Wavefront OBJ file (Units mm)\n"); fprintf( fp, "# BRL-CAD model: %s\n# BRL_CAD objects:", argv[0] ); for ( c=1; c<argc; c++ ) fprintf( fp, " %s", argv[c] ); fprintf( fp, "\n" ); /* Walk indicated tree(s). Each region will be output separately */ (void) db_walk_tree(dbip, argc-1, (const char **)(argv+1), 1, /* ncpu */ &tree_state, 0, /* take all regions */ do_region_end, nmg_booltree_leaf_tess, (genptr_t)NULL); /* in librt/nmg_bool.c */ percent = 0; if (regions_tried>0) { percent = ((double)regions_converted * 100) / regions_tried; printf("Tried %d regions, %d converted to NMG's successfully. %g%%\n", regions_tried, regions_converted, percent); } percent = 0; if ( regions_tried > 0 ) { percent = ((double)regions_written * 100) / regions_tried; printf( " %d triangulated successfully. %g%%\n", regions_written, percent ); } fclose(fp); /* Release dynamic storage */ nmg_km(the_model); rt_vlist_cleanup(); db_close(dbip); #if MEMORY_LEAK_CHECKING bu_prmem("After complete G-ACAD conversion"); #endif return 0; }
int main(int argc, char **argv) { int i, j; int c; double percent; bu_setprogname(argv[0]); bu_setlinebuf(stderr); RTG.debug = 0; ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; 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_sq = tol.dist * tol.dist; tol.perp = 1e-6; tol.para = 1 - tol.perp; the_model = (struct model *)NULL; tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_m = &the_model; tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; rt_init_resource(&rt_uniresource, 0, NULL); /* For visualization purposes, in the debug plot files */ { /* WTF: This value is specific to the Bradley */ nmg_eue_dist = 2.0; } BU_LIST_INIT(&RTG.rtg_vlfree); /* for vlist macros */ /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "a:n:o:r:vx:P:X:h?")) != -1) { switch (c) { case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name */ out_file = bu_optarg; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi(bu_optarg); break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug); NMG_debug = RTG.NMG_debug; break; default: usage(argv[0]); } } if (bu_optind+1 >= argc) usage(argv[0]); /* Open BRL-CAD database */ if ((dbip = db_open(argv[bu_optind], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Cannot open geometry database file %s\n", argv[bu_optind]); } if (db_dirbuild(dbip)) { bu_exit(1, "db_dirbuild failed\n"); } if (out_file == NULL) { fp_out = stdout; setmode(fileno(fp_out), O_BINARY); } else { if ((fp_out = fopen(out_file, "wb")) == NULL) { bu_log("Cannot open %s\n", out_file); perror(argv[0]); return 2; } } bu_optind++; fprintf(fp_out, "$03"); /* First produce an unordered list of region ident codes */ (void)db_walk_tree(dbip, argc-bu_optind, (const char **)(&argv[bu_optind]), 1, /* ncpu */ &tree_state, get_reg_id, /* put id in table */ region_stub, leaf_stub, (void *)NULL); /* Process regions in ident order */ curr_id = 0; for (i = 0; i < ident_length; i++) { int next_id = 99999999; for (j = 0; j < ident_length; j++) { int test_id; test_id = idents[j]; if (test_id > curr_id && test_id < next_id) next_id = test_id; } curr_id = next_id; face_count = 0; bu_log("Processing id %d\n", curr_id); /* Walk indicated tree(s). Each region will be output separately */ tree_state = rt_initial_tree_state; /* struct copy */ the_model = nmg_mm(); tree_state.ts_m = &the_model; tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; (void)db_walk_tree(dbip, argc-bu_optind, (const char **)(&argv[bu_optind]), ncpu, &tree_state, select_region, do_region_end, nmg_booltree_leaf_tess, (void *)NULL); /* in librt/nmg_bool.c */ nmg_km(the_model); } percent = 0; if (regions_tried > 0) percent = ((double)regions_converted * 100) / regions_tried; printf("Tried %d regions, %d converted successfully. %g%%\n", regions_tried, regions_converted, percent); percent = 0; if (regions_tried > 0) percent = ((double)regions_written * 100) / regions_tried; printf(" %d written successfully. %g%%\n", regions_written, percent); /* Release dynamic storage */ rt_vlist_cleanup(); db_close(dbip); return 0; }
int main(int argc, char *argv[]) { int verbose = 0; int ncpu = 1; /* Number of processors */ char *output_file = NULL; /* output filename */ struct db_i *dbip; struct model *the_model; struct rt_tess_tol ttol; /* tessellation tolerance in mm */ struct db_tree_state tree_state; /* includes tol & model */ int i, use_mc = 0, use_bottess = 0; struct egg_conv_data conv_data; struct gcv_region_end_data gcvwriter = {nmg_to_egg, NULL}; gcvwriter.client_data = (void *)&conv_data; bu_setprogname(argv[0]); bu_setlinebuf(stderr); tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &conv_data.tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; /* Set up tessellation tolerance defaults */ ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* Set up calculation tolerance defaults */ /* FIXME: These need to be improved */ conv_data.tol.magic = BN_TOL_MAGIC; conv_data.tol.dist = BN_TOL_DIST; conv_data.tol.dist_sq = conv_data.tol.dist * conv_data.tol.dist; conv_data.tol.perp = 1e-6; conv_data.tol.para = 1 - conv_data.tol.perp; conv_data.tot_polygons = 0; /* make empty NMG model */ the_model = nmg_mm(); BU_LIST_INIT(&RTG.rtg_vlfree); /* for vlist macros */ /* Get command line arguments. */ while ((i = bu_getopt(argc, argv, "a:89n:o:r:vx:D:P:X:h?")) != -1) { switch (i) { case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name. */ output_file = bu_optarg; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi(bu_optarg); break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'D': conv_data.tol.dist = atof(bu_optarg); conv_data.tol.dist_sq = conv_data.tol.dist * conv_data.tol.dist; rt_pr_tol(&conv_data.tol); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug); break; case '8': use_mc = 1; break; case '9': use_bottess = 1; break; default: usage(argv[0]); } } if (bu_optind+1 >= argc) usage(argv[0]); conv_data.fp = stdout; if (output_file) { if ((conv_data.fp=fopen(output_file, "wb+")) == NULL) { perror(argv[0]); bu_exit(1, "Cannot open ASCII output file (%s) for writing\n", output_file); } } /* Open brl-cad database */ argc -= bu_optind; argv += bu_optind; if (argc < 2 || argv[0] == NULL || argv[1] == NULL) usage(argv[0]); gcvwriter.write_region = nmg_to_egg; if ((dbip = db_open(argv[0], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Unable to open geometry database file (%s)\n", argv[0]); } if (db_dirbuild(dbip)) { bu_exit(1, "ERROR: db_dirbuild failed\n"); } BN_CK_TOL(tree_state.ts_tol); RT_CK_TESS_TOL(tree_state.ts_ttol); if (verbose) { bu_log("Model: %s\n", argv[0]); bu_log("Objects:"); for (i=1; i<argc; i++) bu_log(" %s", argv[i]); bu_log("\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm = %g\n", tree_state.ts_ttol->abs, tree_state.ts_ttol->rel, tree_state.ts_ttol->norm); bu_log("Calculational tolerances:\n\tdist = %g mm perp = %g\n", tree_state.ts_tol->dist, tree_state.ts_tol->perp); } /* print the egg header stuff, including the command line to execute it */ fprintf(conv_data.fp, "<CoordinateSystem> { Z-Up }\n\n"); fprintf(conv_data.fp, "<Comment> {\n \"%s", *argv); for (i=1; i<argc; i++) fprintf(conv_data.fp, " %s", argv[i]); fprintf(conv_data.fp, "\"\n}\n"); /* Walk indicated tree(s). Each region will be output separately */ while (--argc) { fprintf(conv_data.fp, "<Group> %s {\n", *(argv+1)); (void) db_walk_tree(dbip, /* db_i */ 1, /* argc */ (const char **)(++argv), /* argv */ ncpu, /* ncpu */ &tree_state, /* state */ NULL, /* start func */ use_mc?gcv_region_end_mc:use_bottess?gcv_bottess_region_end:gcv_region_end, /* end func */ use_mc?NULL:nmg_booltree_leaf_tess, /* leaf func */ (void *)&gcvwriter); /* client_data */ fprintf(conv_data.fp, "}\n"); } bu_log("%ld triangles written\n", conv_data.tot_polygons); if (output_file) fclose(conv_data.fp); /* Release dynamic storage */ nmg_km(the_model); rt_vlist_cleanup(); db_close(dbip); return 0; }
int main(int argc, char **argv) { int c; double percent; int i; bu_setprogname(argv[0]); bu_setlinebuf(stderr); RTG.debug = 0; tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* FIXME: These need to be improved */ tol.magic = BN_TOL_MAGIC; tol.dist = BN_TOL_DIST; tol.dist_sq = tol.dist * tol.dist; tol.perp = 1e-6; tol.para = 1 - tol.perp; the_model = nmg_mm(); BU_LIST_INIT(&RTG.rtg_vlfree); /* for vlist macros */ /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "a:n:o:r:vx:D:P:X:e:ih?")) != -1) { switch (c) { case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name. */ output_file = bu_optarg; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi(bu_optarg); break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'D': tol.dist = atof(bu_optarg); tol.dist_sq = tol.dist * tol.dist; rt_pr_tol(&tol); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug); NMG_debug = RTG.NMG_debug; break; case 'e': /* Error file name. */ error_file = bu_optarg; break; case 'i': inches = 1; break; default: usage(argv[0]); } } if (bu_optind+1 >= argc) usage(argv[0]); if (!output_file) { fp = stdout; setmode(fileno(fp), O_BINARY); } else { /* Open output file */ if ((fp=fopen(output_file, "wb+")) == NULL) { perror(argv[0]); bu_exit(1, "Cannot open output file (%s) for writing\n", output_file); } } /* Open g-acad error log file */ if (!error_file) { fpe = stderr; setmode(fileno(fpe), O_BINARY); } else if ((fpe=fopen(error_file, "wb")) == NULL) { perror(argv[0]); bu_exit(1, "Cannot open output file (%s) for writing\n", error_file); } /* Open BRL-CAD database */ argc -= bu_optind; argv += bu_optind; if ((dbip = db_open(argv[0], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Cannot open geometry database file (%s)\n", argv[0]); } if (db_dirbuild(dbip)) { bu_exit(1, "db_dirbuild failed\n"); } BN_CK_TOL(tree_state.ts_tol); RT_CK_TESS_TOL(tree_state.ts_ttol); fprintf(fpe, "Model: %s\n", argv[0]); fprintf(fpe, "Objects:"); for (i=1; i<argc; i++) fprintf(fpe, " %s", argv[i]); fprintf(fpe, "\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm = %g\n", tree_state.ts_ttol->abs, tree_state.ts_ttol->rel, tree_state.ts_ttol->norm); fprintf(fpe, "Calculational tolerances:\n\tdist = %g mm perp = %g\n", tree_state.ts_tol->dist, tree_state.ts_tol->perp); bu_log("Model: %s\n", argv[0]); bu_log("Objects:"); for (i=1; i<argc; i++) bu_log(" %s", argv[i]); bu_log("\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm = %g\n", tree_state.ts_ttol->abs, tree_state.ts_ttol->rel, tree_state.ts_ttol->norm); bu_log("Calculational tolerances:\n\tdist = %g mm perp = %g\n", tree_state.ts_tol->dist, tree_state.ts_tol->perp); /* Write out ACAD facet header */ if (inches) fprintf(fp, "BRL-CAD generated ACAD FACET FILE (Units in)\n"); else fprintf(fp, "BRL-CAD generated ACAD FACET FILE (Units mm)\n"); /* Generate space for number of facet entities, will write over later */ fprintf(fp, " "); /* Walk indicated tree(s). Each region will be output separately */ (void) db_walk_tree(dbip, argc-1, (const char **)(argv+1), 1, /* ncpu */ &tree_state, 0, /* take all regions */ do_region_end, nmg_booltree_leaf_tess, (void *)NULL); /* in librt/nmg_bool.c */ percent = 0; if (regions_tried>0) { percent = ((double)regions_converted * 100) / regions_tried; printf("Tried %d regions, %d converted to NMG's successfully. %g%%\n", regions_tried, regions_converted, percent); } percent = 0; if (regions_tried > 0) { percent = ((double)regions_written * 100) / regions_tried; printf(" %d triangulated successfully. %g%%\n", regions_written, percent); } bu_log("%ld triangles written\n", tot_polygons); fprintf(fpe, "%ld triangles written\n", tot_polygons); /* Write out number of facet entities to .facet file */ rewind(fp); bu_fseek(fp, 46, 0); /* Re-position pointer to 2nd line */ fprintf(fp, "%d\n", regions_written); /* Write out number of regions */ fclose(fp); /* Release dynamic storage */ nmg_km(the_model); rt_vlist_cleanup(); db_close(dbip); return 0; }
/** * This is the gist for what is going on (not verified): * * 1. initialize tree_state (db_tree_state) * 2. Deal with command line arguments. Strip off everything but regions for processing. * 3. Open geometry (.g) file and build directory db_dirbuild * 4. db_walk_tree (get_layer) for layer names only * 5. Initialize tree_state * 6. Initialize model (nmg)\ * 7. db_walk_tree (gcv_region_end) * 8. Cleanup */ int main(int argc, char *argv[]) { int c; double percent; bu_setlinebuf(stderr); tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; tree_state.ts_m = &the_model; /* Set up tessellation tolerance defaults */ ttol.magic = RT_TESS_TOL_MAGIC; /* Defaults, updated by command line options. */ ttol.abs = 0.0; ttol.rel = 0.01; ttol.norm = 0.0; /* Set up calculation tolerance defaults */ /* FIXME: These need to be improved */ tol.magic = BN_TOL_MAGIC; tol.dist = 0.0005; tol.dist_sq = tol.dist * tol.dist; tol.perp = 1e-6; tol.para = 1 - tol.perp; /* init resources we might need */ rt_init_resource(&rt_uniresource, 0, NULL); BU_LIST_INIT(&RTG.rtg_vlfree); /* for vlist macros */ /* Get command line arguments. */ while ((c = bu_getopt(argc, argv, "a:n:o:pr:vx:D:P:X:ih?")) != -1) { switch (c) { case 'a': /* Absolute tolerance. */ ttol.abs = atof(bu_optarg); ttol.rel = 0.0; break; case 'n': /* Surface normal tolerance. */ ttol.norm = atof(bu_optarg); ttol.rel = 0.0; break; case 'o': /* Output file name. */ output_file = bu_optarg; break; case 'p': polyface_mesh = 1; break; case 'r': /* Relative tolerance. */ ttol.rel = atof(bu_optarg); break; case 'v': verbose++; break; case 'P': ncpu = atoi(bu_optarg); break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'D': tol.dist = atof(bu_optarg); tol.dist_sq = tol.dist * tol.dist; rt_pr_tol(&tol); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug); NMG_debug = RTG.NMG_debug; break; case 'i': inches = 1; break; default: usage(argv[0]); bu_exit(1, "%s\n", brlcad_ident("BRL-CAD to DXF Exporter")); break; } } if (bu_optind+1 >= argc) { usage(argv[0]); bu_exit(1, "%s\n", brlcad_ident("BRL-CAD to DXF Exporter")); } if (!output_file) { fp = stdout; setmode(fileno(fp), O_BINARY); } else { /* Open output file */ if ((fp=fopen(output_file, "w+b")) == NULL) { perror(argv[0]); bu_exit(1, " Cannot open output file (%s) for writing\n", output_file); } } /* Open BRL-CAD database */ argc -= bu_optind; argv += bu_optind; if ((dbip = db_open(argv[0], DB_OPEN_READONLY)) == DBI_NULL) { perror(argv[0]); bu_exit(1, "Unable to open geometry database file (%s)\n", argv[0]); } if (db_dirbuild(dbip)) { bu_exit(1, "db_dirbuild failed\n"); } BN_CK_TOL(tree_state.ts_tol); RT_CK_TESS_TOL(tree_state.ts_ttol); if (verbose) { int i; bu_log("Model: %s\n", argv[0]); bu_log("Objects:"); for (i = 1; i < argc; i++) bu_log(" %s", argv[i]); bu_log("\nTessellation tolerances:\n\tabs = %g mm\n\trel = %g\n\tnorm = %g\n", tree_state.ts_ttol->abs, tree_state.ts_ttol->rel, tree_state.ts_ttol->norm); bu_log("Calculational tolerances:\n\tdist = %g mm perp = %g\n", tree_state.ts_tol->dist, tree_state.ts_tol->perp); } /* output DXF header and start of TABLES section */ fprintf(fp, "0\nSECTION\n2\nHEADER\n999\n%s\n0\nENDSEC\n0\nSECTION\n2\nTABLES\n0\nTABLE\n2\nLAYER\n", argv[argc-1]); /* Walk indicated tree(s) just for layer names to put in TABLES section */ (void)db_walk_tree(dbip, argc-1, (const char **)(argv+1), 1, /* ncpu */ &tree_state, 0, /* take all regions */ get_layer, NULL, (void *)NULL); /* in librt/nmg_bool.c */ /* end of layers section, start of ENTITIES SECTION */ fprintf(fp, "0\nENDTAB\n0\nENDSEC\n0\nSECTION\n2\nENTITIES\n"); /* Walk indicated tree(s). Each region will be output separately */ tree_state = rt_initial_tree_state; /* struct copy */ tree_state.ts_tol = &tol; tree_state.ts_ttol = &ttol; /* make empty NMG model */ the_model = nmg_mm(); tree_state.ts_m = &the_model; (void) db_walk_tree(dbip, argc-1, (const char **)(argv+1), 1, /* ncpu */ &tree_state, 0, /* take all regions */ gcv_region_end, nmg_booltree_leaf_tess, (void *)&gcvwriter); /* callback for gcv_region_end */ percent = 0; if (regions_tried>0) { percent = ((double)regions_converted * 100) / regions_tried; if (verbose) bu_log("Tried %d regions, %d converted to NMG's successfully. %g%%\n", regions_tried, regions_converted, percent); } percent = 0; if (regions_tried > 0) { percent = ((double)regions_written * 100) / regions_tried; if (verbose) bu_log(" %d triangulated successfully. %g%%\n", regions_written, percent); } bu_log("%ld triangles written\n", (long int)tot_polygons); fprintf(fp, "0\nENDSEC\n0\nEOF\n"); if (output_file) { fclose(fp); } /* Release dynamic storage */ nmg_km(the_model); rt_vlist_cleanup(); db_close(dbip); return 0; }