コード例 #1
0
ファイル: viewrange.c プロジェクト: cogitokat/brlcad
void
view_2init(struct application *ap, char *UNUSED(framename))
{
    if ( outfp == NULL )
	bu_exit(EXIT_FAILURE, "outfp is NULL\n");

    /*
     *  For now, RTRANGE does not operate in parallel, while ray-tracing.
     *  However, not dropping out of parallel mode until here permits
     *  tree walking and database prepping to still be done in parallel.
     */
    if ( npsw >= 1 )  {
	bu_log("Note: changing from %d cpus to 1 cpu\n", npsw );
	npsw = 1;		/* Disable parallel processing */
    }


    /* allocate a buffer that has room with as many struct cell as the
     * incoming file is wide (width).
     */

    cellp = (struct cell *)bu_malloc(sizeof(struct cell) * width,
				     "cell buffer" );

    /* Obtain the maximum distance within the model to use as the
     * background distance.  Also get the coordinates of the model's
     * bounding box and feed them to
     * pdv_3space.  This will allow the image to appear in the plot
     * starting with the same size as the model.
     */

    pdv_3space(outfp, ap->a_rt_i->rti_pmin, ap->a_rt_i->rti_pmax);

    /* Find the max dist fron emanation plane to end of model
     * space.  This can be twice the radius of the bounding
     * sphere.
     */

    max_dist = 2 * (ap->a_rt_i->rti_radius);
}
コード例 #2
0
/*
 *			M A I N
 */
int
main(int argc, char **argv)
{
    struct application	ap;

    static struct rt_i *rtip;
    char *title_file;
    char idbuf[RT_BUFSIZE] = {0};		/* First ID record info */
    char *ptr;
    int attr_count=0, i;
    char **attrs = (char **)NULL;

    if ( argc < 3 )  {
	bu_exit(1, usage);
    }

    RT_APPLICATION_INIT(&ap);

    argc--;
    argv++;
    while ( argv[0][0] == '-' ) switch ( argv[0][1] )  {
	case 'R':
	    bundle_radius = atof( argv[1] );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'n':
	    num_rings = atoi( argv[1] );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'c':
	    rays_per_ring = atoi( argv[1] );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'v':
	    /* count the number of attribute names provided */
	    ptr = argv[1];
	    while ( *ptr ) {
		while ( *ptr && isspace( *ptr ) )
		    ptr++;
		if ( *ptr )
		    attr_count++;
		while ( *ptr && !isspace( *ptr ) )
		    ptr++;
	    }

	    if ( attr_count == 0 ) {
		bu_log( "missing list of attribute names!\n" );
		bu_exit( 1, usage );
	    }

	    /* allocate enough for a null terminated list */
	    attrs = (char **)bu_calloc( attr_count + 1, sizeof( char *), "attrs" );

	    /* use strtok to actually grab the names */
	    i = 0;
	    ptr = strtok( argv[1], "\t " );
	    while ( ptr && i < attr_count ) {
		attrs[i] = bu_strdup( ptr );
		ptr = strtok( (char *)NULL, "\t " );
		i++;
	    }
	    argc -= 2;
	    argv += 2;
	    break;
	case 't':
	    rt_bot_tri_per_piece = atoi( argv[1] );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'b':
	    rt_bot_minpieces = atoi( argv[1] );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'o':
	    sscanf( argv[1], "%d", &set_onehit );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'r':
	{
	    float ray_len;

	    sscanf( argv[1], "%f", &ray_len );
	    set_ray_length = ray_len;
	}
	argc -= 2;
	argv += 2;
	break;
	case 'U':
	    sscanf( argv[1], "%d", &use_air );
	    argc -= 2;
	    argv += 2;
	    break;
	case 'u':
	    sscanf( argv[1], "%x", (unsigned int *)&bu_debug );
	    fprintf(stderr, "librt bu_debug=x%x\n", bu_debug);
	    argc -= 2;
	    argv += 2;
	    break;
	case 'x':
	    sscanf( argv[1], "%x", (unsigned int *)&rt_g.debug );
	    fprintf(stderr, "librt rt_g.debug=x%x\n", rt_g.debug);
	    argc -= 2;
	    argv += 2;
	    break;
	case 'X':
	    sscanf( argv[1], "%x", (unsigned int *)&rdebug );
	    fprintf(stderr, "rdebug=x%x\n", rdebug);
	    argc -= 2;
	    argv += 2;
	    break;
	case 'N':
	    sscanf( argv[1], "%x", (unsigned int *)&rt_g.NMG_debug);
	    fprintf(stderr, "librt rt_g.NMG_debug=x%x\n", rt_g.NMG_debug);
	    argc -= 2;
	    argv += 2;
	    break;
	case 'd':
	    if ( argc < 4 )  goto err;
	    ap.a_ray.r_dir[X] = atof( argv[1] );
	    ap.a_ray.r_dir[Y] = atof( argv[2] );
	    ap.a_ray.r_dir[Z] = atof( argv[3] );
	    set_dir = 1;
	    argc -= 4;
	    argv += 4;
	    continue;

	case 'p':
	    if ( argc < 4 )  goto err;
	    ap.a_ray.r_pt[X] = atof( argv[1] );
	    ap.a_ray.r_pt[Y] = atof( argv[2] );
	    ap.a_ray.r_pt[Z] = atof( argv[3] );
	    set_pt = 1;
	    argc -= 4;
	    argv += 4;
	    continue;

	case 'a':
	    if ( argc < 4 )  goto err;
	    at_vect[X] = atof( argv[1] );
	    at_vect[Y] = atof( argv[2] );
	    at_vect[Z] = atof( argv[3] );
	    set_at = 1;
	    argc -= 4;
	    argv += 4;
	    continue;

	case 'O':
	{
	    if ( !strcmp( argv[1], "resolve" ) || !strcmp( argv[1], "0") )
		overlap_claimant_handling = 0;
	    else if ( !strcmp( argv[1], "rebuild_fastgen" ) || !strcmp( argv[1], "1") )
		overlap_claimant_handling = 1;
	    else if ( !strcmp( argv[1], "rebuild_all" ) || !strcmp( argv[1], "2") )
		overlap_claimant_handling = 2;
	    else if ( !strcmp( argv[1], "retain" ) || !strcmp( argv[1], "3") )
		overlap_claimant_handling = 3;
	    else
	    {
		bu_log( "Illegal argument (%s) to '-O' option.  Must be:\n", argv[1] );
		bu_log( "\t'resolve' or '0'\n");
		bu_log( "\t'rebuild_fastgen' or '1'\n");
		bu_log( "\t'rebuild_all' or '2'\n");
		bu_log( "\t'retain' or '3'\n");
		bu_exit(1, NULL);
	    }
	    argc -= 2;
	    argv += 2;
	}
	continue;

	default:
    err:
	    bu_exit(1, usage);
    }
    if ( argc < 2 )  {
	(void)fputs(usage, stderr);
	bu_exit(1, "rtshot: MGED database not specified\n");
    }

    if ( set_dir + set_pt + set_at != 2 )  goto err;

    if ( num_rings != 0 || rays_per_ring != 0 || bundle_radius != 0.0 ) {
	if ( num_rings <= 0 || rays_per_ring <= 0 || bundle_radius <= 0.0 ) {
	    fprintf( stderr, "Must have all of \"-R\", \"-n\", and \"-c\" set\n" );
	    goto err;
	}
    }

    /* Load database */
    title_file = argv[0];
    argv++;
    argc--;
    if ( (rtip=rt_dirbuild(title_file, idbuf, sizeof(idbuf))) == RTI_NULL ) {
	bu_exit(2, "rtshot:  rt_dirbuild failure\n");
    }

    if ( overlap_claimant_handling )
	rtip->rti_save_overlaps = 1;

    ap.a_rt_i = rtip;
    fprintf(stderr, "db title:  %s\n", idbuf);
    rtip->useair = use_air;

    /* Walk trees */
    if ( rt_gettrees_and_attrs( rtip, (const char **)attrs, argc, (const char **)argv, 1 ) ) {
	bu_exit(1, "rt_gettrees FAILED\n");
    }
    ap.attrs = attrs;

    rt_prep(rtip);

    if ( R_DEBUG&RDEBUG_RAYPLOT )  {
	if ( (plotfp = fopen("rtshot.plot", "w")) == NULL )  {
	    perror("rtshot.plot");
	    bu_exit(1, NULL);
	}
	pdv_3space( plotfp, rtip->rti_pmin, rtip->rti_pmax );
    }

    /* Compute r_dir and r_pt from the inputs */
    if ( set_at )  {
	if ( set_dir ) {
	    vect_t	diag;
	    fastf_t	viewsize;
	    VSUB2( diag, rtip->mdl_max, rtip->mdl_min );
	    viewsize = MAGNITUDE( diag );
	    VJOIN1( ap.a_ray.r_pt, at_vect,
		    -viewsize/2.0, ap.a_ray.r_dir );
	} else {
	    /* set_pt */
	    VSUB2( ap.a_ray.r_dir, at_vect, ap.a_ray.r_pt );
	}
    }
    VUNITIZE( ap.a_ray.r_dir );

    if ( rays_per_ring ) {
	bu_log( "Central Ray:\n" );
    }
    VPRINT( "Pnt", ap.a_ray.r_pt );
    VPRINT( "Dir", ap.a_ray.r_dir );

    if ( set_onehit )
	ap.a_onehit = set_onehit;
    else
	ap.a_onehit = 0;

    if ( set_ray_length > 0.0 )
	ap.a_ray_length = set_ray_length;
    else
	ap.a_ray_length = 0.0;

    /* Shoot Ray */
    ap.a_purpose = "main ray";
    ap.a_hit = hit;
    ap.a_miss = miss;

    if ( rays_per_ring ) {
	vect_t avec, bvec;
	struct xray *rp;

	/* create orthogonal rays for basis of bundle */
	bn_vec_ortho( avec, ap.a_ray.r_dir );
	VCROSS( bvec, ap.a_ray.r_dir, avec );
	VUNITIZE( bvec );

	rp = (struct xray *)bu_calloc( sizeof( struct xray ),
				       (rays_per_ring * num_rings) + 1,
				       "ray bundle" );
	rp[0] = ap.a_ray;	/* struct copy */
	rp[0].magic = RT_RAY_MAGIC;
	rt_raybundle_maker( rp, bundle_radius, avec, bvec, rays_per_ring, num_rings );
	(void)rt_shootray_bundle( &ap, rp, (rays_per_ring * num_rings) + 1 );
    } else {
	(void)rt_shootray( &ap );
    }

    return(0);
}
コード例 #3
0
/*
 *			D O F I L E
 */
void
dofile(FILE *fp)
{
    register int	c;

    while ( (c = getc(fp)) != EOF ) {
	switch ( c ) {
	    /* One of a kind functions */
	    case 'e':
	    case 'F':
		putchar( c );
		break;
	    case 'f':
	    case 't':
		putchar( c );
		copy_string( fp );
		break;
	    case 'C':
		putchar( c );
		COPY(3);
		break;
	    case 'c':	/* map x, y? */
		putchar( c );
		COPY(6);
		break;
	    case 'a':	/* map points? */
		putchar( c );
		COPY(12);
		break;
	    case 'p':
	    case 'm':
	    case 'n':
		/* Two coordinates in, three out. Change command. */
		putchar( UPPER_CASE(c) );
		two_coord_out( fp, rmat );
		break;
	    case 'l':
		putchar( 'L' );
		two_coord_out( fp, rmat );
		two_coord_out( fp, rmat );
		break;
	    case 'P':
	    case 'M':
	    case 'N':
		putchar( c );
		three_coord_out( fp, rmat );
		break;
	    case 'L':
		putchar( c );
		three_coord_out( fp, rmat );
		three_coord_out( fp, rmat );
		break;
	    case 's':
	    {
		/*  2-D integer SPACE command.
		 *  This is the only AT&T compatible space
		 *  command;  be certain to only output
		 *  with pl_space(), to ensure that output
		 *  file is AT&T style if input was.
		 */
		long	minx, miny, maxx, maxy;
		point_t	min, max;

		minx = getshort(fp);
		miny = getshort(fp);
		maxx = getshort(fp);
		maxy = getshort(fp);

		VSET( min, minx, miny, -1 );
		VSET( max, maxx, maxy, -1 );
		model_rpp( min, max );

		minx = (long)floor( space_min[X] );
		miny = (long)floor( space_min[Y] );
		maxx = (long)ceil( space_max[X] );
		maxy = (long)ceil( space_max[Y] );
		if ( minx < -32768 )  minx = -32768;
		if ( miny < -32768 )  miny = -32768;
		if ( maxx > 32767 )  maxx = 32767;
		if ( maxy > 32767 )  maxy = 32767;

		pl_space( stdout, minx, miny, maxx, maxy );
	    }
	    break;
	    case 'S':
	    {
		/* BRL-extended 3-D integer SPACE command */
		point_t	min, max;

		min[X] = getshort(fp);
		min[Y] = getshort(fp);
		min[Z] = getshort(fp);
		max[X] = getshort(fp);
		max[Y] = getshort(fp);
		max[Z] = getshort(fp);

		model_rpp( min, max );

		pdv_3space( stdout, space_min, space_max );
	    }
	    break;
	    /* 2D and 3D IEEE */
	    case 'w':
	    {
		/* BRL 2-D floating point SPACE command */
		point_t	min, max;

		min[X] = getdouble(fp);
		min[Y] = getdouble(fp);
		min[Z] = -1.0;
		max[X] = getdouble(fp);
		max[Y] = getdouble(fp);
		max[Z] = 1.0;

		model_rpp( min, max );

		pdv_3space( stdout, space_min, space_max );
	    }
	    break;
	    case 'W':
	    {
		/* BRL 3-D floating point SPACE command */
		point_t	min, max;

		min[X] = getdouble(fp);
		min[Y] = getdouble(fp);
		min[Z] = getdouble(fp);
		max[X] = getdouble(fp);
		max[Y] = getdouble(fp);
		max[Z] = getdouble(fp);

		model_rpp( min, max );

		pdv_3space( stdout, space_min, space_max );
	    }
	    break;
	    case 'i':
		putchar(c);
		COPY(3*8);
		break;
	    case 'r':
		putchar(c);
		COPY(6*8);
		break;
	    case 'x':
	    case 'o':
	    case 'q':
		/* Two coordinates in, three out.  Change command. */
		putchar( UPPER_CASE(c) );
		two_dcoord_out( fp, rmat );
		break;
	    case 'v':
		/* Two coordinates in, three out.  Change command. */
		putchar( 'V' );
		two_dcoord_out( fp, rmat );
		two_dcoord_out( fp, rmat );
		break;
	    case 'X':
	    case 'O':
	    case 'Q':
		putchar( c );
		three_dcoord_out( fp, rmat );
		break;
	    case 'V':
		putchar( c );
		three_dcoord_out( fp, rmat );
		three_dcoord_out( fp, rmat );
		break;
	    default:
		fprintf( stderr, "plrot: unrecognized command '%c' (0x%x)\n",
			 (isascii(c) && isprint(c)) ? c : '?',
			 c );
		fprintf( stderr, "plrot: ftell = %ld\n", ftell(fp) );
		putchar( c );
		break;
	}
    }
}
コード例 #4
0
int
get_args(int argc, register char **argv)
{
    register int c;
    mat_t	tmp, m;
    int	i, num;
    double	mtmp[16];

    MAT_IDN( rmat );
    scale = 1.0;

    while ( (c = bu_getopt( argc, argv, "S:m:vMga:e:x:y:z:X:Y:Z:s:" )) != EOF )  {
	switch ( c )  {
	    case 'M':
		/* take model RPP from space() command */
		rpp++;
		Mflag = 1;		/* don't rebound */
		break;
	    case 'g':
		bn_mat_angles( tmp, -90.0, 0.0, -90.0 );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'a':
		bn_mat_angles( tmp, 0.0, 0.0, -atof(bu_optarg) );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		rpp++;
		break;
	    case 'e':
		bn_mat_angles( tmp, 0.0, -atof(bu_optarg), 0.0 );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		rpp++;
		break;
	    case 'x':
		bn_mat_angles( tmp, atof(bu_optarg), 0.0, 0.0 );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'y':
		bn_mat_angles( tmp, 0.0, atof(bu_optarg), 0.0 );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'z':
		bn_mat_angles( tmp, 0.0, 0.0, atof(bu_optarg) );
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'm':
		num = sscanf(&bu_optarg[0], "%lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf %lf",
			     &mtmp[0], &mtmp[1], &mtmp[2], &mtmp[3],
			     &mtmp[4], &mtmp[5], &mtmp[6], &mtmp[7],
			     &mtmp[8], &mtmp[9], &mtmp[10], &mtmp[11],
			     &mtmp[12], &mtmp[13], &mtmp[14], &mtmp[15]);

		if ( num != 16)  {
		    fprintf(stderr, "Num of arguments to -m only %d, should be 16\n", num);
		    bu_exit (1, NULL);
		}

		/* Now copy the array of doubles into mat. */
		for (i=0; i < 16; i++ )  {
		    rmat[i] = mtmp[i];
		}
		break;
	    case 'X':
		MAT_IDN( tmp );
		tmp[MDX] = atof(bu_optarg);
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'Y':
		MAT_IDN( tmp );
		tmp[MDY] = atof(bu_optarg);
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 'Z':
		MAT_IDN( tmp );
		tmp[MDZ] = atof(bu_optarg);
		MAT_COPY( m, rmat );
		bn_mat_mul( rmat, tmp, m );
		break;
	    case 's':
		scale *= atof(bu_optarg);
		/*
		 *  If rpp flag has already been set, defer
		 *  application of scale until after the
		 *  xlate to space-center, in model_rpp().
		 *  Otherwise, do it here, in the sequence
		 *  seen in the arg list.
		 */
		if ( !rpp )  {
		    MAT_IDN( tmp );
		    tmp[15] = 1/scale;
		    MAT_COPY( m, rmat );
		    bn_mat_mul( rmat, tmp, m );
		    scale = 1.0;
		}
		break;
	    case 'v':
		verbose++;
		break;
	    case 'S':
		num = sscanf(bu_optarg, "%lf %lf %lf %lf %lf %lf",
			     &mtmp[0], &mtmp[1], &mtmp[2],
			     &mtmp[3], &mtmp[4], &mtmp[5]);
		VSET(forced_space_min, mtmp[0], mtmp[1], mtmp[2]);
		VSET(forced_space_max, mtmp[3], mtmp[4], mtmp[5]);

		/* Write it now, in case input does not have one */
		pdv_3space( stdout, forced_space_min, forced_space_max );
		forced_space = 1;
		break;
	    default:		/* '?' */
		return(0);	/* Bad */
	}
    }


    if ( isatty(fileno(stdout))
	 || (isatty(fileno(stdin)) && (bu_optind >= argc)) )  {
	return(0);	/* Bad */
    }

    return(1);		/* OK */
}