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;
    }
}
Ejemplo n.º 2
0
int
main(int argc, char **argv)
{
    int	i;
    int	c;
    struct plate_mode pm;

    bu_setprogname(argv[0]);
    bu_setlinebuf( stderr );

    the_model = nmg_mm();
    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;

    /* NOTE: 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 */

    BARRIER_CHECK;
    /* Get command line arguments. */
    while ((c = bu_getopt(argc, argv, "d:a:n:o:r:vx:P:X:u:h?")) != -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 );
		tol.dist_sq = tol.dist * tol.dist;
		break;
	    case 'n':		/* Surface normal tolerance. */
		ttol.norm = atof(bu_optarg)*DEG2RAD;
		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;
	    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 );
		scale_factor = 1.0 / scale_factor;
		break;
	    default:
		print_usage(argv[0]);
	}
    }

    if (bu_optind+1 >= argc)
	print_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) {
	outfp = stdout;
	setmode(fileno(outfp), O_BINARY);
    } else {
	if ((outfp = fopen( out_file, "wb")) == NULL)
	{
	    perror( argv[0] );
	    bu_exit(2, "Cannot open %s\n", out_file );
	}
    }

    writeX3dHeader(outfp, out_file);
    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++ )
    {
	struct directory *dp;

	dp = db_lookup( dbip, argv[i], LOOKUP_QUIET );
	if ( dp == RT_DIR_NULL )
	{
	    bu_log( "Cannot find %s\n", argv[i] );
	    continue;
	}

	/* light source must be a combination */
	if ( !(dp->d_flags & RT_DIR_COMB) )
	    continue;

	/* walk trees selecting only light source regions */
	(void)db_walk_tree(dbip, 1, (const char **)(&argv[i]),
			   ncpu,
			   &tree_state,
			   select_lights,
			   do_region_end,
			   leaf_tess,
			   (void *)&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]),
		       ncpu,
		       &tree_state,
		       select_non_lights,
		       do_region_end,
		       leaf_tess,
		       (void *)&pm);	/* in librt/nmg_bool.c */

    BARRIER_CHECK;
    /* Release dynamic storage */
    nmg_km(the_model);

    db_close(dbip);

    /* Now we need to close each group set */
    writeX3dEnd(outfp);

    if ( verbose )
	bu_log( "Total of %d regions converted of %d regions attempted\n",
		regions_converted, regions_tried );

    return 0;
}
Ejemplo n.º 3
0
Archivo: id.c Proyecto: kanzure/brlcad
int
mk_id_units(struct rt_wdb *fp, const char *title, const char *units)
{
    return mk_id_editunits(fp, title, bu_units_conversion(units));
}
Ejemplo n.º 4
0
/*
 *			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 */
}