void nirt_units(char *buffer, com_table *ctp, struct rt_i *rtip) { double tmp_dbl; int i = 0; /* current position on the *buffer */ double mk_cvt_factor(); while (isspace((int)*(buffer+i))) ++i; if (*(buffer+i) == '\0') { /* display current destination */ fprintf(stdout, "units = '%s'\n", local_u_name); return; } if (BU_STR_EQUAL(buffer + i, "?")) { com_usage(ctp); return; } else if (BU_STR_EQUAL(buffer + i, "default")) { base2local = rtip->rti_dbip->dbi_base2local; local2base = rtip->rti_dbip->dbi_local2base; bu_strlcpy(local_u_name, bu_units_string(base2local), sizeof(local_u_name)); } else { tmp_dbl = bu_units_conversion(buffer + i); if (tmp_dbl <= 0.0) { bu_log("Invalid unit specification: '%s'\n", buffer + i); return; } bu_strlcpy(local_u_name, buffer + i, sizeof(local_u_name)); local2base = tmp_dbl; base2local = 1.0 / tmp_dbl; } }
/* * G E T _ A R G S */ int get_args( int argc, register char **argv ) { register int c; register int i; bu_optind = 1; /* restart */ #define GETOPT_STR \ ".:,:@:a:b:c:d:e:f:g:h:ij:k:l:n:o:p:q:rs:tu:v:w:x:A:BC:D:E:F:G:H:IJ:K:MN:O:P:Q:RST:U:V:WX:!:+:" while ( (c=bu_getopt( argc, argv, GETOPT_STR )) != EOF ) { switch ( c ) { case 'q': i = atoi(bu_optarg); if (i <= 0) { bu_exit(EXIT_FAILURE, "-q %d is < 0\n", i); } if ( i > BN_RANDHALFTABSIZE) { bu_exit(EXIT_FAILURE, "-q %d is > maximum (%d)\n", i, BN_RANDHALFTABSIZE); } bn_randhalftabsize = i; break; case 'h': i = sscanf(bu_optarg, "%lg,%lg,%lg,%lg", &airdensity, &haze[X], &haze[Y], &haze[Z]); break; case 't': transpose_grid = 1; break; case 'j': { register char *cp = bu_optarg; sub_xmin = atoi(cp); while ( (*cp >= '0' && *cp <= '9') ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; sub_ymin = atoi(cp); while ( (*cp >= '0' && *cp <= '9') ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; sub_xmax = atoi(cp); while ( (*cp >= '0' && *cp <= '9') ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; sub_ymax = atoi(cp); bu_log("Sub-rectangle: (%d,%d) (%d,%d)\n", sub_xmin, sub_ymin, sub_xmax, sub_ymax ); if ( sub_xmin >= 0 && sub_xmin < sub_xmax && sub_ymin >= 0 && sub_ymin < sub_ymax ) { sub_grid_mode = 1; } else { sub_grid_mode = 0; bu_log("WARNING: bad sub-rectangle, ignored\n"); } } break; case 'k': /* define cutting plane */ { fastf_t f; do_kut_plane = 1; i = sscanf(bu_optarg, "%lg,%lg,%lg,%lg", &kut_plane[X], &kut_plane[Y], &kut_plane[Z], &kut_plane[H]); if( i != 4 ) { bu_exit( EXIT_FAILURE, "ERROR: bad cutting plane\n" ); } /* verify that normal has unit length */ f = MAGNITUDE( kut_plane ); if( f <= SMALL ) { bu_exit( EXIT_FAILURE, "Bad normal for cutting plane, length=%g\n", f ); } f = 1.0 /f; VSCALE( kut_plane, kut_plane, f ); kut_plane[3] *= f; break; } case '.': nu_gfactor = (double)atof( bu_optarg ); break; case ',': space_partition = atoi(bu_optarg); break; case '@': nugrid_dimlimit = atoi(bu_optarg); break; case 'c': (void)rt_do_cmd( (struct rt_i *)0, bu_optarg, rt_cmdtab ); break; case 'C': { char buf[128] = {0}; int r, g, b; register char *cp = bu_optarg; r = atoi(cp); while ( (*cp >= '0' && *cp <= '9') ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; g = atoi(cp); while ( (*cp >= '0' && *cp <= '9') ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; b = atoi(cp); if ( r < 0 || r > 255 ) r = 255; if ( g < 0 || g > 255 ) g = 255; if ( b < 0 || b > 255 ) b = 255; #if defined(_WIN32) if (r == 0) background[0] = 0.0; else background[0] = r / 255.0; if (g == 0) background[1] = 0.0; else background[1] = g / 255.0; if (b == 0) background[2] = 0.0; else background[2] = b / 255.0; #else sprintf(buf, "set background=%f/%f/%f", r/255., g/255., b/255. ); (void)rt_do_cmd( (struct rt_i *)0, buf, rt_cmdtab ); #endif } break; case 'T': { double f; char *cp; f = 0; if ( sscanf( bu_optarg, "%lf", &f ) == 1 ) { if ( f > 0 ) rt_dist_tol = f; } f = 0; if ( (cp = strchr(bu_optarg, '/')) || (cp = strchr(bu_optarg, ',')) ) { if ( sscanf( cp+1, "%lf", &f ) == 1 ) { if ( f > 0 && f < 1 ) rt_perp_tol = f; } } bu_log("Using tolerance %lg", f); break; } case 'U': use_air = atoi( bu_optarg ); break; case 'I': interactive = 1; break; case 'i': incr_mode = 1; break; case 'S': stereo = 1; break; case 'J': sscanf( bu_optarg, "%x", &jitter ); break; case 'H': hypersample = atoi( bu_optarg ); if ( hypersample > 0 ) jitter = 1; break; case 'F': framebuffer = bu_optarg; break; case 'D': desiredframe = atoi( bu_optarg ); break; case 'K': finalframe = atoi( bu_optarg ); break; case 'N': sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug); bu_log("NMG_debug=0x%x\n", rt_g.NMG_debug); break; case 'M': matflag = 1; break; case 'A': AmbientIntensity = atof( bu_optarg ); break; case 'x': sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.debug ); break; case 'X': sscanf( bu_optarg, "%x", (unsigned int *)&rdebug ); break; case '!': sscanf( bu_optarg, "%x", (unsigned int *)&bu_debug ); break; case 's': /* Square size */ i = atoi( bu_optarg ); if ( i < 2 || i > MAX_WIDTH ) fprintf(stderr, "squaresize=%d out of range\n", i); else width = height = i; break; case 'n': i = atoi( bu_optarg ); if ( i < 2 || i > MAX_WIDTH ) fprintf(stderr, "height=%d out of range\n", i); else height = i; break; case 'W': (void)rt_do_cmd( (struct rt_i *)0, "set background=1.0/1.0/1.0", rt_cmdtab ); default_background = 0; break; case 'w': i = atoi( bu_optarg ); if ( i < 2 || i > MAX_WIDTH ) fprintf(stderr, "width=%d out of range\n", i); else width = i; break; case 'g': cell_width = atof( bu_optarg ); cell_newsize = 1; break; case 'G': cell_height = atof( bu_optarg ); cell_newsize = 1; break; case 'a': /* Set azimuth */ azimuth = atof( bu_optarg ); matflag = 0; break; case 'e': /* Set elevation */ elevation = atof( bu_optarg ); matflag = 0; break; case 'l': { char *item; /* Select lighting model # */ lightmodel= 1; /* Initialize with Full Lighting Model */ item= strtok(bu_optarg, ","); lightmodel= atoi(item); if (lightmodel == 7) { /* Process the photon mapping arguments */ item= strtok(NULL, ","); pmargs[0]= item ? atoi(item) : 16384; /* Number of Global Photons */ item= strtok(NULL, ","); pmargs[1]= item ? atof(item) : 50; /* Percent of Global Photons that should be used for Caustic Photons */ item= strtok(NULL, ","); pmargs[2]= item ? atoi(item) : 10; /* Number of Irradiance Sample Rays, Total Rays is this number squared */ item= strtok(NULL, ","); pmargs[3]= item ? atof(item) : 60.0; /* Angular Tolerance */ item= strtok(NULL, ","); pmargs[4]= item ? atoi(item) : 0; /* Random Seed */ item= strtok(NULL, ","); pmargs[5]= item ? atoi(item) : 0; /* Importance Mapping */ item= strtok(NULL, ","); pmargs[6]= item ? atoi(item) : 0; /* Irradiance Hypersampling */ item= strtok(NULL, ","); pmargs[7]= item ? atoi(item) : 0; /* Visualize Irradiance */ item= strtok(NULL, ","); pmargs[8]= item ? atof(item) : 1.0; /* Scale Lumens */ item= strtok(NULL,","); if (item) { bu_strlcpy(pmfile, item, sizeof(pmfile)); } else { pmfile[0]= 0; } } } break; case 'O': /* Output pixel file name, double precision format */ outputfile = bu_optarg; doubles_out = 1; break; case 'o': /* Output pixel file name, unsigned char format */ outputfile = bu_optarg; doubles_out = 0; break; case 'p': rt_perspective = atof( bu_optarg ); if ( rt_perspective < 0 || rt_perspective > 179 ) { fprintf(stderr, "persp=%g out of range\n", rt_perspective); rt_perspective = 0; } break; case 'u': units = bu_units_conversion(bu_optarg); if (units <= 0.0) { units = 1.0; bu_log("WARNING: bad units, using default (%s)\n", bu_units_string(units)); } break; case 'v': /* Set level of "non-debug" debugging output */ sscanf( bu_optarg, "%x", (unsigned int *)&rt_verbosity ); bu_printb( "Verbosity:", rt_verbosity, VERBOSE_FORMAT); bu_log("\n"); break; case 'E': eye_backoff = atof( bu_optarg ); break; case 'P': { /* Number of parallel workers */ int avail_cpus; avail_cpus = bu_avail_cpus(); npsw = atoi( bu_optarg ); if (npsw > avail_cpus ) { fprintf( stderr, "Requesting %d cpus, only %d available.", npsw, avail_cpus ); if ((bu_debug & BU_DEBUG_PARALLEL) || (RT_G_DEBUG & DEBUG_PARALLEL)) { fprintf(stderr, "\nAllowing surplus cpus due to debug flag.\n"); } else { fprintf( stderr, " Will use %d.\n", avail_cpus ); npsw = avail_cpus; } } if ( npsw == 0 || npsw < -MAX_PSW || npsw > MAX_PSW ) { fprintf(stderr, "Numer of requested cpus (%d) is out of range 1..%d", npsw, MAX_PSW); if ((bu_debug & BU_DEBUG_PARALLEL) || (RT_G_DEBUG & DEBUG_PARALLEL)) { fprintf(stderr, ", but allowing due to debug flag\n"); } else { fprintf(stderr, ", using -P1\n"); npsw = 1; } } } break; case 'Q': Query_one_pixel = ! Query_one_pixel; sscanf(bu_optarg, "%d,%d\n", &query_x, &query_y); break; case 'B': /* Remove all intentional random effects * (dither, etc) for benchmarking purposes. */ benchmark = 1; bn_mathtab_constant(); break; case 'b': /* Specify a single pixel to be done */ /* Actually processed in do_frame() */ string_pix_start = bu_optarg; npsw = 1; /* Cancel running in parallel */ break; case 'f': /* set expected playback rate in frames-per-second. * This actually gets stored as the delta-t per frame. */ if ( (frame_delta_t=atof( bu_optarg )) == 0.0) { fprintf(stderr, "Invalid frames/sec (%s) == 0.0\n", bu_optarg); frame_delta_t = 30.0; } frame_delta_t = 1.0 / frame_delta_t; break; case 'V': { /* View aspect */ fastf_t xx, yy; register char *cp = bu_optarg; xx = atof(cp); while ( (*cp >= '0' && *cp <= '9') || *cp == '.' ) cp++; while ( *cp && (*cp < '0' || *cp > '9') ) cp++; yy = atof(cp); if ( yy == 0 ) aspect = xx; else aspect = xx/yy; if ( aspect <= 0.0 ) { fprintf(stderr, "Bogus aspect %g, using 1.0\n", aspect); aspect = 1.0; } } break; case 'r': /* report overlapping region names */ rpt_overlap = 1; break; case 'R': /* DON'T report overlapping region names */ rpt_overlap = 0; break; case 'd': rpt_dist = atoi( bu_optarg ); break; case '+': { register char *cp = bu_optarg; switch (*cp) { case 't': output_is_binary = 0; break; default: fprintf(stderr, "ERROR: unknown option %c\n", *cp); return(0); /* BAD */ } } break; case EOF: fprintf(stderr, "ERROR: unknown option %c\n", c); return(0); /* BAD */ default: /* '?' */ fprintf(stderr, "ERROR: bad option specified\n"); return(0); /* BAD */ } } /* sanity checks for sane values */ if ( aspect <= 0.0 ) { aspect = 1.0; } /* Compat */ if (RT_G_DEBUG || R_DEBUG || rt_g.NMG_debug ) bu_debug |= BU_DEBUG_COREDUMP; if (RT_G_DEBUG & DEBUG_MEM_FULL) bu_debug |= BU_DEBUG_MEM_CHECK; if (RT_G_DEBUG & DEBUG_MEM) bu_debug |= BU_DEBUG_MEM_LOG; if (RT_G_DEBUG & DEBUG_PARALLEL) bu_debug |= BU_DEBUG_PARALLEL; if (RT_G_DEBUG & DEBUG_MATH) bu_debug |= BU_DEBUG_MATH; if (R_DEBUG & RDEBUG_RTMEM_END) bu_debug |= BU_DEBUG_MEM_CHECK; return(1); /* OK */ }
int ged_units(struct ged *gedp, int argc, const char *argv[]) { double loc2mm; const char *str; int sflag = 0; static const char *usage = "[-s] [mm|cm|m|in|ft|...]"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); if (argc > 2) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } if (argc == 2) { if (BU_STR_EQUAL(argv[1], "-s")) { --argc; ++argv; sflag = 1; } else if (BU_STR_EQUAL(argv[1], "-t")) { struct bu_vls *vlsp = bu_units_strings_vls(); bu_vls_printf(gedp->ged_result_str, "%V", vlsp); bu_vls_free(vlsp); bu_free(vlsp, "ged_units: vlsp"); return GED_OK; } } /* Get units */ if (argc == 1) { str = bu_units_string(gedp->ged_wdbp->dbip->dbi_local2base); if (!str) str = "Unknown_unit"; if (sflag) bu_vls_printf(gedp->ged_result_str, "%s", str); else bu_vls_printf(gedp->ged_result_str, "You are editing in '%s'. 1 %s = %g mm \n", str, str, gedp->ged_wdbp->dbip->dbi_local2base); return GED_OK; } /* Set units */ /* Allow inputs of the form "25cm" or "3ft" */ if ((loc2mm = bu_mm_value(argv[1])) <= 0) { bu_vls_printf(gedp->ged_result_str, "%s: unrecognized unit\nvalid units: <um|mm|cm|m|km|in|ft|yd|mi>\n", argv[1]); return GED_ERROR; } if (db_update_ident(gedp->ged_wdbp->dbip, gedp->ged_wdbp->dbip->dbi_title, loc2mm) < 0) { bu_vls_printf(gedp->ged_result_str, "Warning: unable to stash working units into database\n"); } gedp->ged_wdbp->dbip->dbi_local2base = loc2mm; gedp->ged_wdbp->dbip->dbi_base2local = 1.0 / loc2mm; str = bu_units_string(gedp->ged_wdbp->dbip->dbi_local2base); if (!str) str = "Unknown_unit"; bu_vls_printf(gedp->ged_result_str, "You are now editing in '%s'. 1 %s = %g mm \n", str, str, gedp->ged_wdbp->dbip->dbi_local2base); return GED_OK; }
int main(int argc, char *argv[]) { struct rt_i *rtip = NULL; char db_title[TITLE_LEN+1];/* title from MGED file */ const char *tmp_str; extern char local_u_name[65]; extern double base2local; extern double local2base; FILE *fPtr; int Ch; /* Option name */ int mat_flag = 0; /* Read matrix from stdin? */ int use_of_air = 0; int print_ident_flag = 1; char ocastring[1024] = {0}; struct bu_list script_list; /* For -e and -f options */ struct script_rec *srp; extern outval ValTab[]; /* from if.c, callback functions for overlap, hit, and miss shots */ int if_overlap(struct application *, struct partition *, struct region *, struct region *, struct partition *); int if_hit(struct application *, struct partition *, struct seg *); int if_miss(struct application *); BU_LIST_INIT(&script_list); bu_setprogname(argv[0]); ocname[OVLP_RESOLVE] = "resolve"; ocname[OVLP_REBUILD_FASTGEN] = "rebuild_fastgen"; ocname[OVLP_REBUILD_ALL] = "rebuild_all"; ocname[OVLP_RETAIN] = "retain"; *ocastring = '\0'; bu_optind = 1; /* restart */ /* Handle command-line options */ while ((Ch = bu_getopt(argc, argv, OPT_STRING)) != -1) { if (bu_optopt == '?') Ch='h'; switch (Ch) { case 'A': attrib_add(bu_optarg, &need_prep); break; case 'B': rt_bot_minpieces = atoi(bu_optarg); break; case 'T': setenv("LIBRT_BOT_MINTIE", bu_optarg, 1); break; case 'b': do_backout = 1; break; case 'E': if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "before erasure"); while (BU_LIST_WHILE(srp, script_rec, &script_list)) { BU_LIST_DEQUEUE(&(srp->l)); free_script(srp); } if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after erasure"); break; case 'e': enqueue_script(&script_list, READING_STRING, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a literal"); break; case 'f': enqueue_script(&script_list, READING_FILE, bu_optarg); if (nirt_debug & DEBUG_SCRIPTS) show_scripts(&script_list, "after enqueueing a file name"); break; case 'L': listformats(); bu_exit(EXIT_SUCCESS, NULL); case 'M': mat_flag = 1; break; case 'O': sscanf(bu_optarg, "%1024s", ocastring); break; case 's': silent_flag = SILENT_YES; /* Positively yes */ break; case 'v': silent_flag = SILENT_NO; /* Positively no */ break; case 'x': sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug); break; case 'X': sscanf(bu_optarg, "%x", (unsigned int *)&nirt_debug); break; case 'u': if (sscanf(bu_optarg, "%d", &use_of_air) != 1) { (void) fprintf(stderr, "Illegal use-air specification: '%s'\n", bu_optarg); return 1; } break; case 'H': if (sscanf(bu_optarg, "%d", &print_ident_flag) != 1) { (void) fprintf(stderr, "Illegal header output option specified: '%s'\n", bu_optarg); return 1; } break; default: printusage(); bu_exit (Ch != 'h', NULL); } } /* end while getopt */ if (argc - bu_optind < 2) { printusage(); return 1; } if (isatty(0)) { if (silent_flag != SILENT_YES) silent_flag = SILENT_NO; } else { /* stdin is not a TTY */ if (silent_flag != SILENT_NO) silent_flag = SILENT_YES; } if (silent_flag != SILENT_YES && print_ident_flag) (void) fputs(brlcad_ident("Natalie's Interactive Ray Tracer"), stdout); if (use_of_air && (use_of_air != 1)) { fprintf(stderr, "Warning: useair=%d specified, will set to 1\n", use_of_air); use_of_air = 1; } switch (*ocastring) { case '\0': overlap_claims = OVLP_RESOLVE; break; case '0': case '1': case '2': case '3': if (ocastring[1] == '\0') { sscanf(ocastring, "%d", &overlap_claims); } else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; case 'r': if (BU_STR_EQUAL(ocastring, "resolve")) overlap_claims = OVLP_RESOLVE; else if (BU_STR_EQUAL(ocastring, "rebuild_fastgen")) overlap_claims = OVLP_REBUILD_FASTGEN; else if (BU_STR_EQUAL(ocastring, "rebuild_all")) overlap_claims = OVLP_REBUILD_ALL; else if (BU_STR_EQUAL(ocastring, "retain")) overlap_claims = OVLP_RETAIN; else { fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } break; default: fprintf(stderr, "Illegal overlap_claims specification: '%s'\n", ocastring); return 1; } db_name = argv[bu_optind]; /* build directory for target object */ if (silent_flag != SILENT_YES) { printf("Database file: '%s'\n", db_name); printf("Building the directory..."); } if ((rtip = rt_dirbuild(db_name, db_title, TITLE_LEN)) == RTI_NULL) { fflush(stdout); fprintf(stderr, "Could not load file %s\n", db_name); return 1; } rti_tab[use_of_air] = rtip; rti_tab[1 - use_of_air] = RTI_NULL; rtip->useair = use_of_air; rtip->rti_save_overlaps = (overlap_claims > 0); ++bu_optind; do_rt_gettrees(rtip, argv + bu_optind, argc - bu_optind, &need_prep); /* Initialize the table of resource structures */ rt_init_resource(&res_tab, 0, rtip); /* initialization of the application structure */ RT_APPLICATION_INIT(&ap); ap.a_hit = if_hit; /* branch to if_hit routine */ ap.a_miss = if_miss; /* branch to if_miss routine */ ap.a_overlap = if_overlap;/* branch to if_overlap routine */ ap.a_logoverlap = rt_silent_logoverlap; ap.a_onehit = 0; /* continue through shotline after hit */ ap.a_resource = &res_tab; ap.a_purpose = "NIRT ray"; ap.a_rt_i = rtip; /* rt_i pointer */ ap.a_zero1 = 0; /* sanity check, sayth raytrace.h */ ap.a_zero2 = 0; /* sanity check, sayth raytrace.h */ ap.a_uptr = (void *)a_tab.attrib; /* initialize variables */ azimuth() = 0.0; elevation() = 0.0; direct(X) = -1.0; direct(Y) = 0.0; direct(Z) = 0.0; grid(HORZ) = 0.0; grid(VERT) = 0.0; grid(DIST) = 0.0; grid2targ(); set_diameter(rtip); /* initialize the output specification */ default_ospec(); /* initialize NIRT's local units */ base2local = rtip->rti_dbip->dbi_base2local; local2base = rtip->rti_dbip->dbi_local2base; tmp_str = bu_units_string(local2base); if (tmp_str) { bu_strlcpy(local_u_name, tmp_str, sizeof(local_u_name)); } else { bu_strlcpy(local_u_name, "Unknown units", sizeof(local_u_name)); } if (silent_flag != SILENT_YES) { printf("Database title: '%s'\n", db_title); printf("Database units: '%s'\n", local_u_name); printf("model_min = (%g, %g, %g) model_max = (%g, %g, %g)\n", rtip->mdl_min[X] * base2local, rtip->mdl_min[Y] * base2local, rtip->mdl_min[Z] * base2local, rtip->mdl_max[X] * base2local, rtip->mdl_max[Y] * base2local, rtip->mdl_max[Z] * base2local); } /* Run the run-time configuration file, if it exists */ if ((fPtr = fopenrc()) != NULL) { interact(READING_FILE, fPtr, rtip); fclose(fPtr); } /* Run all scripts specified on the command line */ run_scripts(&script_list, rtip); /* Perform the user interface */ if (mat_flag) { read_mat(rtip); return 0; } else { interact(READING_FILE, stdin, rtip); } return 0; }
/* d e c k ( ) make a COMGEOM deck for current list of objects */ void deck(register char *prefix) { register int i; nns = nnr = 0; /* Create file for solid table. */ if ( prefix != 0 ) { /* !!! this seems wrong. st_file is a pointer into a bu_vls */ bu_strlcpy(st_file, prefix, 80); bu_strlcat(st_file, ".st", 80); } else bu_strlcpy( st_file, "solids", 80 ); if ( (solfd = creat( st_file, 0644 )) < 0 ) { perror( st_file ); bu_exit( 10, NULL ); } /* Target units (a2, 3x) */ ewrite( solfd, bu_units_string(dbip->dbi_local2base), 2 ); blank_fill( solfd, 3 ); /* Title */ if ( dbip->dbi_title == NULL ) ewrite( solfd, objfile, (unsigned) strlen( objfile ) ); else ewrite( solfd, dbip->dbi_title, (unsigned) strlen( dbip->dbi_title ) ); ewrite( solfd, LF, 1 ); /* Save space for number of solids and regions. */ savsol = lseek( solfd, 0L, 1 ); blank_fill( solfd, 10 ); ewrite( solfd, LF, 1 ); /* Create file for region table. */ if ( prefix != 0 ) { bu_strlcpy(rt_file, prefix, 80); bu_strlcat(rt_file, ".rt", 80); } else bu_strlcpy(rt_file, "regions", 80); if ( (regfd = creat( rt_file, 0644 )) < 0 ) { perror( rt_file ); bu_exit( 10, NULL ); } /* create file for region ident table */ if ( prefix != 0 ) { bu_strlcpy(id_file, prefix, 80); bu_strlcat(id_file, ".id", 80); } else bu_strLcpy(id_file, "region_ids", 80); if ( (ridfd = creat( id_file, 0644 )) < 0 ) { perror( id_file ); bu_exit( 10, NULL ); } itoa( -1, buff, 5 ); ewrite( ridfd, buff, 5 ); ewrite( ridfd, LF, 1 ); /* Initialize matrices. */ MAT_IDN( identity ); /* Check integrity of list against directory and build card deck. */ for ( i = 0; i < curr_ct; i++ ) { struct directory *dirp; if ( (dirp = db_lookup( dbip, curr_list[i], LOOKUP_NOISY )) != DIR_NULL ) { #if 1 treewalk( curr_list[i] ); #else cgobj( dirp, 0, identity ); #endif } } /* Add number of solids and regions on second card. */ (void) lseek( solfd, savsol, 0 ); itoa( nns, buff, 5 ); ewrite( solfd, buff, 5 ); itoa( nnr, buff, 5 ); ewrite( solfd, buff, 5 ); /* Finish region id table. */ ewrite( ridfd, LF, 1 ); (void) printf( "====================================================\n" ); (void) printf( "O U T P U T F I L E S :\n\n" ); (void) printf( "solid table = \"%s\"\n", st_file ); (void) printf( "region table = \"%s\"\n", rt_file ); (void) printf( "region identification table = \"%s\"\n", id_file ); (void) close( solfd ); (void) close( regfd ); (void) close( ridfd ); /* reset starting numbers for solids and regions */ delsol = delreg = 0; /* XXX should free soltab list */ }