Beispiel #1
0
int
make_hole_in_prepped_regions(struct rt_wdb *wdbp,	/* database to be modified */
			     struct rt_i *rtip,		/* rt_i pointer for the same database */
			     point_t hole_start,	/* center of start of hole */
			     vect_t hole_depth,		/* depth and direction of hole */
			     fastf_t radius,		/* radius of hole */
			     struct bu_ptbl *regions)	/* list of region structures to which this hole
							 * is to be applied
							 */
{
    struct bu_vls tmp_name = BU_VLS_INIT_ZERO;
    size_t i, base_len, count=0;
    struct directory *dp;
    struct rt_db_internal intern;
    struct soltab *stp;

    RT_CHECK_WDB(wdbp);

    /* make a unique name for the RCC we will use (of the form "make_hole_%d") */
    bu_vls_strcat(&tmp_name, "make_hole_");
    base_len = bu_vls_strlen(&tmp_name);
    bu_vls_strcat(&tmp_name, "0");
    while ((db_lookup(wdbp->dbip, bu_vls_addr(&tmp_name), LOOKUP_QUIET)) != RT_DIR_NULL) {
	count++;
	bu_vls_trunc(&tmp_name, base_len);
	bu_vls_printf(&tmp_name, "%zu", count);
    }

    /* build the RCC based on parameters passed in */
    if (mk_rcc(wdbp, bu_vls_addr(&tmp_name), hole_start, hole_depth, radius)) {
	bu_log("Failed to create hole cylinder!!!\n");
	bu_vls_free(&tmp_name);
	return 2;
    }

    /* lookup the newly created RCC */
    dp=db_lookup(wdbp->dbip, bu_vls_addr(&tmp_name), LOOKUP_QUIET);
    if (dp == RT_DIR_NULL) {
      bu_log("Failed to lookup RCC (%s) just made by make_hole_in_prepped_regions()!!!\n",
	       bu_vls_addr(&tmp_name));
	bu_bomb("Failed to lookup RCC just made by make_hole_in_prepped_regions()!!!\n");
    }

    /* get the internal form of the new RCC */
    if (rt_db_get_internal(&intern, dp, wdbp->dbip, NULL, wdbp->wdb_resp) < 0) {
	bu_log("Failed to get internal form of RCC (%s) just made by make_hole_in_prepped_regions()!!!\n",
	       bu_vls_addr(&tmp_name));
	bu_bomb("Failed to get internal form of RCC just made by make_hole_in_prepped_regions()!!!\n");
    }

    /* Build a soltab structure for the new RCC */
    BU_ALLOC(stp, struct soltab);
    stp->l.magic = RT_SOLTAB_MAGIC;
    stp->l2.magic = RT_SOLTAB2_MAGIC;
    stp->st_uses = 1;
    stp->st_dp = dp;
    stp->st_bit = rtip->nsolids++;

    /* Add the new soltab structure to the rt_i structure */
    rtip->rti_Solids = (struct soltab **)bu_realloc(rtip->rti_Solids,
						    rtip->nsolids * sizeof(struct soltab *),
						    "new rti_Solids");
    rtip->rti_Solids[stp->st_bit] = stp;

    /* actually prep the new RCC */
    if (intern.idb_meth->ft_prep(stp, &intern, rtip)) {
	bu_log("Failed to prep RCC (%s) just made by make_hole_in_prepped_regions()!!!\n",
	       bu_vls_addr(&tmp_name));
	bu_bomb("Failed to prep RCC just made by make_hole_in_prepped_regions()!!!\n");
    }

    /* initialize the soltabs list of containing regions */
    bu_ptbl_init(&stp->st_regions, BU_PTBL_LEN(regions), "stp->st_regions");

    /* Subtract the new RCC from each region structure in the list provided */
    for (i=0; i<BU_PTBL_LEN(regions); i++) {
	struct region *rp;
	union tree *treep;

	/* get the next region structure */
	rp = (struct region *)BU_PTBL_GET(regions, i);

	RT_CK_REGION(rp);

	/* create a tree node for the subtraction operation, this will be the new tree root */
	BU_ALLOC(treep, union tree);
	RT_TREE_INIT(treep);
	treep->tr_b.tb_op = OP_SUBTRACT;
	treep->tr_b.tb_left = rp->reg_treetop;	/* subtract from the old treetop */
	treep->tr_b.tb_regionp = rp;

	/* make the new node the new treetop */
	rp->reg_treetop = treep;

	/* create a tree node for the new RCC */
	BU_ALLOC(treep, union tree);
	RT_TREE_INIT(treep);
	treep->tr_a.tu_op = OP_SOLID;
	treep->tr_a.tu_stp = stp;
	treep->tr_a.tu_regionp = rp;

	/* the new RCC gets hung on the right of the subtract node */
	rp->reg_treetop->tr_b.tb_right = treep;

	/* make sure the "all unions" flag is not set on this region */
	rp->reg_all_unions = 0;

	/* Add this region to the list of containing regions for the new RCC */
	bu_ptbl_ins(&stp->st_regions, (long *)rp);
    }

    /* insert the new RCC soltab structure into the already existing space partitioning tree */
    insert_in_bsp(stp, &rtip->rti_CutHead);

    return 0;
}
Beispiel #2
0
void MakeP(struct rt_wdb (*file), char *prefix, fastf_t diameter, fastf_t focal_length, fastf_t ref_ind, fastf_t thickness)
{
    struct wmember lensglass, lens;
    struct bu_vls str = BU_VLS_INIT_ZERO;
    fastf_t sph_R, epa_H, epa_R, rcc_h;
    int lens_type;
    point_t origin;
    vect_t height;
    vect_t breadth;

    if (focal_length > 0) {
	lens_type = 1;
    } else {
	lens_type = -1;
    }

    sph_R = lens_type*focal_length*(ref_ind - 1);
    bu_log("sph_R = %f\n", sph_R);
    epa_R = diameter / 2;
    bu_log("epa_R = %f\n", epa_R);
    epa_H = sph_R - sqrt(sph_R*sph_R-epa_R*epa_R);
    bu_log("epa_H = %f\n", epa_H);
    rcc_h = thickness - lens_type * epa_H;
    bu_log("rcc_h = %f\n", rcc_h);

    BU_LIST_INIT(&lensglass.l);
    BU_LIST_INIT(&lens.l);

    if (epa_R > 0 && epa_H > 0) {
	if (rcc_h < 0) bu_log("Warning - specified thickness too thin for lens\n");

	if (rcc_h >= 0) {
	    VSET(origin, 0, 0, 0);
	    VSET(height, 0, -rcc_h, 0);
	    bu_vls_trunc(&str, 0);
	    bu_vls_printf(&str, "%s-cyl.s", prefix);
	    mk_rcc(file, bu_vls_addr(&str), origin, height, diameter/2);
	    (void)mk_addmember(bu_vls_addr(&str), &lensglass.l, NULL, WMOP_UNION);
	}

	VSET(origin, 0, -rcc_h, 0);
	VSET(height, 0, -1*lens_type*epa_H, 0);
	VSET(breadth, 0, 0, 1);
	bu_vls_trunc(&str, 0);
	bu_vls_printf(&str, "%s-epa.s", prefix);
	mk_epa(file, bu_vls_addr(&str), origin, height, breadth, epa_R, epa_R);
	if (lens_type == 1) {
	    (void)mk_addmember(bu_vls_addr(&str), &lensglass.l, NULL, WMOP_UNION);
	} else {
	    (void)mk_addmember(bu_vls_addr(&str), &lensglass.l, NULL, WMOP_SUBTRACT);
	}

	bu_vls_trunc(&str, 0);
	bu_vls_printf(&str, "%s.c", prefix);
	mk_lcomb(file, bu_vls_addr(&str), &lensglass, 0,  NULL, NULL, NULL, 0);

	(void)mk_addmember(bu_vls_addr(&str), &lens.l, NULL, WMOP_UNION);
	bu_vls_trunc(&str, 0);
	bu_vls_printf(&str, "%s.r", prefix);
	mk_lcomb(file, bu_vls_addr(&str), &lens, 1, "glass", "ri=1.5", NULL, 0);
    } else {
	bu_log("Error - specified parameters result in non-physical geometry");
    }
}
Beispiel #3
0
/*
 *			G E T S O L I D
 *
 *  Returns -
 *	-1	error
 *	 0	conversion OK
 *	 1	EOF
 */
int
getsolid(void)
{
    char	given_solid_num[16];
    char	solid_type[16];
    int	i;
    double	r1, r2;
    vect_t	work;
    double	m1, m2;		/* Magnitude temporaries */
    char	*name=NULL;
    double	dd[4*6];	/* 4 cards of 6 nums each */
    point_t	tmp[8];		/* 8 vectors of 3 nums each */
    int	ret;
#define D(_i)	(&(dd[_i*3]))
#define T(_i)	(&(tmp[_i][0]))

    if ( (i = get_line( scard, sizeof(scard), "solid card" )) == EOF )  {
        printf("getsolid: unexpected EOF\n");
        return( 1 );
    }

    switch ( version )  {
    case 5:
        bu_strlcpy( given_solid_num, scard+0, sizeof(given_solid_num) );
        given_solid_num[5] = '\0';
        bu_strlcpy( solid_type, scard+5, sizeof(solid_type) );
        solid_type[5] = '\0';
        break;
    case 4:
        bu_strlcpy( given_solid_num, scard+0, sizeof(given_solid_num) );
        given_solid_num[3] = '\0';
        bu_strlcpy( solid_type, scard+3, sizeof(solid_type) );
        solid_type[7] = '\0';
        break;
    case 1:
        /* DoE/MORSE version, believed to be original MAGIC format */
        bu_strlcpy( given_solid_num, scard+5, sizeof(given_solid_num) );
        given_solid_num[4] = '\0';
        bu_strlcpy( solid_type, scard+2, sizeof(solid_type) );
        break;
    default:
        fprintf(stderr, "getsolid() version %d unimplemented\n", version);
        bu_exit(1, NULL);
        break;
    }
    /* Trim trailing spaces */
    trim_trail_spaces( given_solid_num );
    trim_trail_spaces( solid_type );

    /* another solid - increment solid counter
     * rather than using number from the card, which may go into
     * pseudo-hex format in version 4 models (due to 3 column limit).
     */
    sol_work++;
    if ( version == 5 )  {
        if ( (i = getint( scard, 0, 5 )) != sol_work )  {
            printf("expected solid card %d, got %d, abort\n",
                   sol_work, i );
            return(1);
        }
    }

    /* Reduce solid type to lower case */
    {
        register char	*cp;
        register char	c;

        cp = solid_type;
        while ( (c = *cp) != '\0' )  {
            if ( !isascii(c) )  {
                *cp++ = '?';
            } else if ( isupper(c) )  {
                *cp++ = tolower(c);
            } else {
                cp++;
            }
        }
    }

    namecvt( sol_work, &name, 's' );
    if (verbose) col_pr( name );

    if ( strcmp( solid_type, "end" ) == 0 )  {
        /* DoE/MORSE version 1 format */
        bu_free( name, "name" );
        return(1);		/* END */
    }

    if ( strcmp( solid_type, "ars" ) == 0 )  {
        int		ncurves;
        int		pts_per_curve;
        double		**curve;

        ncurves = getint( scard, 10, 10 );
        pts_per_curve = getint( scard, 20, 10 );

        /* Allocate curves pointer array */
        curve = (double **)bu_malloc((ncurves+1)*sizeof(double *), "curve");

        /* Allocate space for a curve, and read it in */
        for ( i=0; i<ncurves; i++ )  {
            curve[i] = (double *)bu_malloc((pts_per_curve+1)*3*sizeof(double), "curve[i]" );

            /* Get data for this curve */
            if ( getxsoldata( curve[i], pts_per_curve*3, sol_work ) < 0 )  {
                printf("ARS %d: getxsoldata failed, curve %d\n",
                       sol_work, i);
                return(-1);
            }
        }
        if ( (ret = mk_ars( outfp, name, ncurves, pts_per_curve, curve )) < 0 )  {
            printf("mk_ars(%s) failed\n", name );
            /* Need to free memory; 'ret' is returned below */
        }

        for ( i=0; i<ncurves; i++ )  {
            bu_free( (char *)curve[i], "curve[i]" );
        }
        bu_free( (char *)curve, "curve" );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "rpp" ) == 0 )  {
        double	min[3], max[3];

        if ( getsoldata( dd, 2*3, sol_work ) < 0 )
            return(-1);
        VSET( min, dd[0], dd[2], dd[4] );
        VSET( max, dd[1], dd[3], dd[5] );
        ret = mk_rpp( outfp, name, min, max );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "box" ) == 0 )  {
        if ( getsoldata( dd, 4*3, sol_work ) < 0 )
            return(-1);
        VMOVE( T(0), D(0) );
        VADD2( T(1), D(0), D(2) );
        VADD3( T(2), D(0), D(2), D(1) );
        VADD2( T(3), D(0), D(1) );

        VADD2( T(4), D(0), D(3) );
        VADD3( T(5), D(0), D(3), D(2) );
        VADD4( T(6), D(0), D(3), D(2), D(1) );
        VADD3( T(7), D(0), D(3), D(1) );
        ret = mk_arb8( outfp, name, &tmp[0][X] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "raw" ) == 0 ||
            strcmp( solid_type, "wed" ) == 0		/* DoE name */
       )  {
        if ( getsoldata( dd, 4*3, sol_work ) < 0 )
            return(-1);
        VMOVE( T(0), D(0) );
        VADD2( T(1), D(0), D(2) );
        VMOVE( T(2), T(1) );
        VADD2( T(3), D(0), D(1) );

        VADD2( T(4), D(0), D(3) );
        VADD3( T(5), D(0), D(3), D(2) );
        VMOVE( T(6), T(5) );
        VADD3( T(7), D(0), D(3), D(1) );
        ret = mk_arb8( outfp, name, &tmp[0][X] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "rvw" ) == 0 )  {
        /* Right Vertical Wedge (Origin: DoE/MORSE) */
        double	a2, theta, phi, h2;
        double	a2theta;
        double	angle1, angle2;
        vect_t	a, b, c;

        if ( getsoldata( dd, 1*3+4, sol_work ) < 0 )
            return(-1);
        a2 = dd[3];		/* XY side length */
        theta = dd[4];
        phi = dd[5];
        h2 = dd[6];		/* height in +Z */

        angle1 = (phi+theta-90) * bn_degtorad;
        angle2 = (phi+theta) * bn_degtorad;
        a2theta = a2 * tan(theta * bn_degtorad);

        VSET( a, a2theta*cos(angle1), a2theta*sin(angle1), 0 );
        VSET( b, -a2*cos(angle2), -a2*sin(angle2), 0 );
        VSET( c, 0, 0, h2 );

        VSUB2( T(0), D(0), b );
        VMOVE( T(1), D(0) );
        VMOVE( T(2), D(0) );
        VADD2( T(3), T(0), a );

        VADD2( T(4), T(0), c );
        VADD2( T(5), T(1), c );
        VMOVE( T(6), T(5) );
        VADD2( T(7), T(3), c );
        ret = mk_arb8( outfp, name, &tmp[0][X] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arw" ) == 0) {
        /* ARbitrary Wedge --- ERIM */
        if ( getsoldata( dd, 4*3, sol_work ) < 0)
            return(-1);
        VMOVE( T(0), D(0) );
        VADD2( T(1), D(0), D(2) );
        VADD3( T(2), D(0), D(2), D(3) );
        VADD2( T(3), D(0), D(3) );

        VADD2( T(4), D(0), D(1) );
        VMOVE( T(5), T(4) );

        VADD3( T(6), D(0), D(1), D(3) );
        VMOVE( T(7), T(6) );
        ret = mk_arb8( outfp, name, &tmp[0][X]);
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arb8" ) == 0 )  {
        if ( getsoldata( dd, 8*3, sol_work ) < 0 )
            return(-1);
        ret = mk_arb8( outfp, name, dd );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arb7" ) == 0 )  {
        if ( getsoldata( dd, 7*3, sol_work ) < 0 )
            return(-1);
        VMOVE( D(7), D(4) );
        ret = mk_arb8( outfp, name, dd );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arb6" ) == 0 )  {
        if ( getsoldata( dd, 6*3, sol_work ) < 0 )
            return(-1);
        /* Note that the ordering is important, as data is in D(4), D(5) */
        VMOVE( D(7), D(5) );
        VMOVE( D(6), D(5) );
        VMOVE( D(5), D(4) );
        ret = mk_arb8( outfp, name, dd );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arb5" ) == 0 )  {
        if ( getsoldata( dd, 5*3, sol_work ) < 0 )
            return(-1);
        VMOVE( D(5), D(4) );
        VMOVE( D(6), D(4) );
        VMOVE( D(7), D(4) );
        ret = mk_arb8( outfp, name, dd );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arb4" ) == 0 )  {
        if ( getsoldata( dd, 4*3, sol_work ) < 0 )
            return(-1);
        ret = mk_arb4( outfp, name, dd );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "rcc" ) == 0 )  {
        /* V, H, r */
        if ( getsoldata( dd, 2*3+1, sol_work ) < 0 )
            return(-1);
        ret = mk_rcc( outfp, name, D(0), D(1), dd[6] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "rec" ) == 0 )  {
        /* V, H, A, B */
        if ( getsoldata( dd, 4*3, sol_work ) < 0 )
            return(-1);
        ret = mk_tgc( outfp, name, D(0), D(1),
                      D(2), D(3), D(2), D(3) );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "trc" ) == 0 )  {
        /* V, H, r1, r2 */
        if ( getsoldata( dd, 2*3+2, sol_work ) < 0 )
            return(-1);
        ret = mk_trc_h( outfp, name, D(0), D(1), dd[6], dd[7] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "tec" ) == 0 )  {
        /* V, H, A, B, p */
        if ( getsoldata( dd, 4*3+1, sol_work ) < 0 )
            return(-1);
        r1 = 1.0/dd[12];	/* P */
        VSCALE( D(4), D(2), r1 );
        VSCALE( D(5), D(3), r1 );
        ret = mk_tgc( outfp, name, D(0), D(1),
                      D(2), D(3), D(4), D(5) );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "tgc" ) == 0 )  {
        /* V, H, A, B, r1, r2 */
        if ( getsoldata( dd, 4*3+2, sol_work ) < 0 )
            return(-1);
        r1 = dd[12] / MAGNITUDE( D(2) );	/* A/|A| * C */
        r2 = dd[13] / MAGNITUDE( D(3) );	/* B/|B| * D */
        VSCALE( D(4), D(2), r1 );
        VSCALE( D(5), D(3), r2 );
        ret = mk_tgc( outfp, name, D(0), D(1),
                      D(2), D(3), D(4), D(5) );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "sph" ) == 0 )  {
        /* V, radius */
        if ( getsoldata( dd, 1*3+1, sol_work ) < 0 )
            return(-1);
        ret = mk_sph( outfp, name, D(0), dd[3] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strncmp( solid_type, "wir", 3 ) == 0 )  {
        int			numpts;		/* points per wire */
        int			num;
        int			i;
        double			dia;
        double			*pts;		/* 3 entries per pt */
        struct	wdb_pipept	*ps;
        struct	bu_list		head;		/* allow a whole struct for head */

        /* This might be getint( solid_type, 3, 2 ); for non-V5 */
        numpts = getint( scard, 8, 2 );
        num = numpts * 3 + 1;			/* 3 entries per pt */

        /* allocate space for the points array */
        pts = ( double *)bu_malloc(num * sizeof( double), "pts" );

        if ( getsoldata( pts, num, sol_work ) < 0 )  {
            return(-1);
        }
        dia = pts[num-1] * 2.0;	/* radius X 2.0 == diameter */

        /* allocate nodes on a list and store all information in
         * the appropriate location.
         */
        BU_LIST_INIT( &head );
        for ( i = 0; i < numpts; i++ )  {
            /* malloc a new structure */
            ps = (struct wdb_pipept *)bu_malloc(sizeof( struct wdb_pipept), "ps");

            ps->l.magic = WDB_PIPESEG_MAGIC;
            VMOVE( ps->pp_coord, &pts[i*3]);	/* 3 pts at a time */
            ps->pp_id = 0;				/* solid */
            ps->pp_od = dia;
            ps->pp_bendradius = dia;
            BU_LIST_INSERT( &head, &ps->l );
        }

        if ( mk_pipe( outfp, name, &head ) < 0 )
            return(-1);
        mk_pipe_free( &head );
        bu_free( name, "name" );
        return(0);		/* OK */
    }

    if ( strcmp( solid_type, "rpc" ) == 0 )  {
        /* V, H, B, r */
        if ( getsoldata( dd, 3*3+1, sol_work ) < 0 )
            return(-1);
        ret = mk_rpc( outfp, name, D(0), D(1),
                      D(2), dd[9] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "rhc" ) == 0 )  {
        /* V, H, B, r, c */
        if ( getsoldata( dd, 3*3+2, sol_work ) < 0 )
            return(-1);
        ret = mk_rhc( outfp, name, D(0), D(1),
                      D(2), dd[9], dd[10] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "epa" ) == 0 )  {
        /* V, H, Au, r1, r2 */
        if ( getsoldata( dd, 3*3+2, sol_work ) < 0 )
            return(-1);
        ret = mk_epa( outfp, name, D(0), D(1),
                      D(2), dd[9], dd[10] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "ehy" ) == 0 )  {
        /* V, H, Au, r1, r2, c */
        if ( getsoldata( dd, 3*3+3, sol_work ) < 0 )
            return(-1);
        ret = mk_ehy( outfp, name, D(0), D(1),
                      D(2), dd[9], dd[10], dd[11] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "eto" ) == 0 )  {
        /* V, N, C, r, rd */
        if ( getsoldata( dd, 3*3+2, sol_work ) < 0 )
            return(-1);
        ret = mk_eto( outfp, name, D(0), D(1),
                      D(2), dd[9], dd[10] );
        bu_free( name, "name" );
        return(ret);
    }


    if ( version <= 4 && strcmp( solid_type, "ell" ) == 0 )  {
        /* Foci F1, F2, major axis length L */
        vect_t	v;

        /*
         * For simplicity, we convert ELL to ELL1, then
         * fall through to ELL1 code.
         * Format of ELL is F1, F2, len
         * ELL1 format is V, A, r
         */
        if ( getsoldata( dd, 2*3+1, sol_work ) < 0 )
            return(-1);
        VADD2SCALE( v, D(0), D(1), 0.5 ); /* V is midpoint */

        VSUB2( work, D(1), D(0) );	/* work holds F2 -  F1 */
        m1 = MAGNITUDE( work );
        r2 = 0.5 * dd[6] / m1;
        VSCALE( D(1), work, r2 );	/* A */

        dd[6] = sqrt( MAGSQ( D(1) ) -
                      (m1 * 0.5)*(m1 * 0.5) );	/* r */
        VMOVE( D(0), v );
        goto ell1;
    }

    if ( (version == 5 && strcmp( solid_type, "ell" ) == 0)  ||
            strcmp( solid_type, "ell1" ) == 0 )  {
        /* V, A, r */
        /* GIFT4 name is "ell1", GIFT5 name is "ell" */
        if ( getsoldata( dd, 2*3+1, sol_work ) < 0 )
            return(-1);

ell1:
        r1 = dd[6];		/* R */
        VMOVE( work, D(0) );
        work[0] += bn_pi;
        work[1] += bn_pi;
        work[2] += bn_pi;
        VCROSS( D(2), work, D(1) );
        m1 = r1/MAGNITUDE( D(2) );
        VSCALE( D(2), D(2), m1 );

        VCROSS( D(3), D(1), D(2) );
        m2 = r1/MAGNITUDE( D(3) );
        VSCALE( D(3), D(3), m2 );

        /* Now we have V, A, B, C */
        ret = mk_ell( outfp, name, D(0), D(1), D(2), D(3) );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "ellg" ) == 0 )  {
        /* V, A, B, C */
        if ( getsoldata( dd, 4*3, sol_work ) < 0 )
            return(-1);
        ret = mk_ell( outfp, name, D(0), D(1), D(2), D(3) );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "tor" ) == 0 )  {
        /* V, N, r1, r2 */
        if ( getsoldata( dd, 2*3+2, sol_work ) < 0 )
            return(-1);
        ret = mk_tor( outfp, name, D(0), D(1), dd[6], dd[7] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "haf" ) == 0 )  {
        /* N, d */
        if ( getsoldata( dd, 1*3+1, sol_work ) < 0 )
            return(-1);
        ret = mk_half( outfp, name, D(0), -dd[3] );
        bu_free( name, "name" );
        return(ret);
    }

    if ( strcmp( solid_type, "arbn" ) == 0 )  {
        ret = read_arbn( name );
        bu_free( name, "name" );
    }

    /*
     *  The solid type string is defective,
     *  or that solid is not currently supported.
     */
    printf("getsolid:  no support for solid type '%s'\n", solid_type );
    return(-1);
}
int
cyl(int entityno)
{
    fastf_t radius = 0.0;
    point_t base;		/* center point of base */
    vect_t height;
    vect_t hdir;		/* direction in which to grow height */
    fastf_t scale_height = 0.0;
    fastf_t x_1;
    fastf_t y_1;
    fastf_t z_1;
    fastf_t x_2;
    fastf_t y_2;
    fastf_t z_2;
    int sol_num;		/* IGES solid type number */

    /* Default values */
    x_1 = 0.0;
    y_1 = 0.0;
    z_1 = 0.0;
    x_2 = 0.0;
    y_2 = 0.0;
    z_2 = 1.0;

    /* Acquiring Data */
    if (dir[entityno]->param <= pstart) {
	bu_log("Illegal parameter pointer for entity D%07d (%s)\n" ,
	       dir[entityno]->direct, dir[entityno]->name);
	return 0;
    }
    Readrec(dir[entityno]->param);
    Readint(&sol_num, "");
    Readcnv(&scale_height, "");
    Readcnv(&radius, "");
    Readcnv(&x_1, "");
    Readcnv(&y_1, "");
    Readcnv(&z_1, "");
    Readcnv(&x_2, "");
    Readcnv(&y_2, "");
    Readcnv(&z_2, "");

    if (radius < SMALL_FASTF || scale_height < SMALL_FASTF) {
	bu_log("Illegal parameters for entity D%07d (%s)\n" ,
	       dir[entityno]->direct, dir[entityno]->name);
	if (ZERO(radius)) {
	    bu_log("\tradius of cylinder is zero!!!\n");
	    return 0;
	}
	if (ZERO(scale_height)) {
	    bu_log("\theight of cylinder is zero!!!\n");
	    return 0;
	}

	if (radius < 0.0) {
	    bu_log("\tUsing the absolute value of a negative radius\n");
	    radius = (-radius);
	}

	if (scale_height < 0.0) {
	    bu_log("\tUsing absolute value of a negative height and reversing axis direction\n");
	    scale_height = (-scale_height);
	    x_2 = (-x_2);
	    y_2 = (-y_2);
	    z_2 = (-z_2);
	}

    }


    /*
     * Making the necessaries. First an id is made for the new entity, then
     * the x, y, z coordinates for its vertices are converted to vectors with
     * VSET(), and finally the libwdb routine that makes an analogous BRL-CAD
     * solid is called.
     */

    VSET(base, x_1, y_1, z_1);
    VSET(hdir, x_2, y_2, z_2);
    VUNITIZE(hdir);

    /* Multiply the hdir * scale_height to obtain height. */

    VSCALE(height, hdir, scale_height);

    if (mk_rcc(fdout, dir[entityno]->name, base, height, radius) < 0) {
	bu_log("Unable to write entity D%07d (%s)\n" ,
	       dir[entityno]->direct, dir[entityno]->name);
	return 0;
    }
    return 1;

}