Esempio n. 1
0
int
mk_ring(struct rt_wdb *fp, double orbit, double width, double thick, double wallthick, double wallheight)
{
    point_t base = {0, 0, 0}, height = {0, 0, 0};
    struct wmember c;
    /* make 3 rcc's and glue them together */

    /* this additive component */
    base[Z] = -1000*width/2.0;
    height[Z] = 1000*width;
    mk_rcc(fp, "ringadd.s", base, height, 1000*orbit);

    /* the small cut to make the walls 'n stuff */
    base[Z] += 1000*wallthick;
    height[Z] -= 1000*2.0*wallthick;
    mk_rcc(fp, "ringsub1.s", base, height, 1000*(orbit-thick));

    /* the big cut out of the middle */
    base[Z] = -1000*width;
    height[Z] = 1000*2*width;
    mk_rcc(fp, "ringsub2.s", base, height, 1000*(orbit - wallheight));

    /* and do the CSG */
    BU_LIST_INIT(&c.l);
    mk_addmember("ringadd.s", &c.l, NULL, WMOP_UNION);
    mk_addmember("ringsub1.s", &c.l, NULL, WMOP_SUBTRACT);
    mk_addmember("ringsub2.s", &c.l, NULL, WMOP_SUBTRACT);
    mk_lcomb(fp, "ring.r", &c, 1, "plastic", "", NULL, 0);

    return 0;
}
Esempio n. 2
0
void
make_room(char *rname, fastf_t *imin, fastf_t *imax, fastf_t *thickness, struct wmember *headp)

    /* Interior RPP min point */


{
    struct wmember head;
    char	name[32];
    vect_t	omin;
    vect_t	omax;

    BU_LIST_INIT( &head.l );

    VSUB2( omin, imin, thickness );
    VADD2( omax, imax, thickness );

    snprintf( name, 32, "o%s", rname );
    mk_rpp( outfp, name, omin, omax );
    (void)mk_addmember( name, &head.l, NULL, WMOP_UNION );

    snprintf( name, 32, "i%s", rname );
    mk_rpp( outfp, name, imin, imax );
    mk_addmember( name, &head.l, NULL, WMOP_SUBTRACT );

    mk_lfcomb( outfp, rname, &head, 1 );
    (void)mk_addmember( rname, &(headp->l), NULL, WMOP_UNION );
}
Esempio n. 3
0
void RegionList::create(rt_wdb* wdbp)
{
    wmember allRegions;
    BU_LIST_INIT(&allRegions.l);

    for (std::map<std::string, Bot>::iterator it = m_list.begin();
	 it != m_list.end();
	 ++it) {
	it->second.write(wdbp);

	wmember regionContent;
	BU_LIST_INIT(&regionContent.l);
	mk_addmember(it->second.name().c_str(), &regionContent.l, 0, WMOP_UNION);

	int id = (int)toValue(it->first.c_str());

	mk_lrcomb(wdbp,
		  it->first.c_str(),
		  &regionContent,
		  1,
		  "plastic",
		  "sh=4 sp=0.5 di=0.5 re=0.1",
		  0,
		  id,
		  0,
		  0,
		  100,
		  0);
	mk_addmember(it->first.c_str(), &allRegions.l, 0, WMOP_UNION);
	mk_freemembers(&regionContent.l);
    }

    mk_lfcomb(wdbp, "all.g", &allRegions, 0);
    mk_freemembers(&allRegions.l);
}
Esempio n. 4
0
int
main(int argc, char *argv[])
{
    static const char usage[] = "Usage:\n%s [-o outfile] \n\n  -o file \tFile to write out (default: ringworld.g)\n\n";

    char outfile[MAXPATHLEN] = "ringworld.g";
    int optc;
    struct rt_wdb *fp;

    while ((optc = bu_getopt(argc, argv, "o:h?")) != -1) {
    	if (bu_optopt == '?') optc='h';
	switch (optc) {
	    case 'o':
		snprintf(outfile, MAXPATHLEN, "%s", bu_optarg);
		break;
	    default:
		fprintf(stderr,usage, *argv);
		return optc == '?' ? EXIT_FAILURE : EXIT_SUCCESS;
	}
    }

    if (argc == 1) {
	fprintf(stderr,usage, *argv);
    	fprintf(stderr,"       Program continues running:\n");
    }

    if (bu_file_exists(outfile, NULL))
	bu_exit(EXIT_FAILURE, "ERROR: %s already exists.  Remove file and try again.", outfile);

    bu_log("Writing ringworld out to [%s]\n", outfile);

    fp = wdb_fopen(outfile);

    mk_sol(fp, SUN_DIAMETER);
    mk_ring(fp, RING_ORBIT, RING_WIDTH, RING_FLOOR_THICKNESS, RING_WALL_THICKNESS, RING_WALL_HEIGHT);
    mk_shadowring(fp, SHADOWRING_ORBIT, SHADOWRING_NUM, SHADOWRING_WIDTH, SHADOWRING_LENGTH, SHADOWRING_THICKNESS);

    /* generate a comb all.g */
    {
	struct wmember c;
	BU_LIST_INIT(&c.l);
	mk_addmember("ring.r", &c.l, NULL, WMOP_UNION);
	mk_addmember("sun.r", &c.l, NULL, WMOP_UNION);
	/* mk_addmember("shadowring.r", &c.l, NULL, WMOP_UNION); */
	mk_lcomb(fp, "all.g", &c, 0, NULL, NULL, NULL, 0);
    }


    wdb_close(fp);
    bu_log("BRL-CAD geometry database file [%s] created.\nDone.\n", outfile);

    return EXIT_SUCCESS;
}
Esempio n. 5
0
int
make_bond(int sp1, int sp2)
{
    struct sphere * s1, *s2, *s_ptr;
    point_t base;
    vect_t height;
    char nm[128], nm1[128];
    unsigned char rgb[3];
    struct wmember reg_head;

    s1 = s2 = (struct sphere *) 0;

    for (s_ptr = s_head; s_ptr != (struct sphere *)0; s_ptr = s_ptr->next) {
	if (s_ptr->s_id == sp1)
	    s1 = s_ptr;

	if (s_ptr->s_id == sp2)
	    s2 = s_ptr;
    }

    if (s1 == (struct sphere *) 0 || s2 == (struct sphere *)0)
	return -1;		/* error */

    VMOVE(base, s1->s_center);
    VSUB2(height, s2->s_center, s1->s_center);

    sprintf(nm, "bond.%d.%d", sp1, sp2);

    rgb[0] = 191;
    rgb[1] = 142;
    rgb[2] = 57;

#if 1
    /* Use this for mol-cube.dat */
    mk_rcc(outfp, nm, base, height, s1->s_rad * 0.15);
#else
    /* Use this for chemical molecules */
    mk_rcc(outfp, nm, base, height, s1->s_rad * 0.5);
#endif

    BU_LIST_INIT(&reg_head.l);
    (void)mk_addmember(nm, &reg_head.l, NULL, WMOP_UNION);
    (void)mk_addmember(s1->s_name, &reg_head.l, NULL, WMOP_SUBTRACT);
    (void)mk_addmember(s2->s_name, &reg_head.l, NULL, WMOP_SUBTRACT);
    sprintf(nm1, "BOND.%d.%d", sp1, sp2);
    mk_lcomb(outfp, nm1, &reg_head, 1, matname, matparm, rgb, 0);
    (void)mk_addmember(nm1, &head.l, NULL, WMOP_UNION);

    return 0;		/* OK */
}
Esempio n. 6
0
void
do_tree(char *name, char *lname, int level)
{
    int i;
    char nm[64];
    char *leafp;
    int scale;
    struct wmember head;
    struct wmember *wp;

    BU_LIST_INIT(&head.l);

    if (level <= 1)
	leafp = lname;
    else
	leafp = nm;

    scale = 100;
    for (i=1; i<level; i++)
	scale *= 2;

    snprintf(nm, 64, "%sL", name);
    wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION);
    MAT_IDN(wp->wm_mat);

    snprintf(nm, 64, "%sR", name);
    wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION);
    MAT_DELTAS(wp->wm_mat, 1*scale, 0, 0);

    snprintf(nm, 64, "%sB", name);
    wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION);
    MAT_DELTAS(wp->wm_mat, 0.5*scale, sin60*scale, 0);

    snprintf(nm, 64, "%sT", name);
    wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION);
    MAT_DELTAS(wp->wm_mat, 0.5*scale, sin60/3*scale, sin60*scale);

    /* Set region flag on lowest level */
    mk_lcomb(outfp, name, &head, level<=1, NULL, NULL, NULL, 0);

    /* Loop for children if level > 1 */
    if (level <= 1)
	return;
    for (i=0; i<4; i++) {
	snprintf(nm, 64, "%s%c", name, "LRBTx"[i]);
	do_tree(nm, lname, level-1);
    }
}
Esempio n. 7
0
void
crregion(char *region, char *op, int *members, int number, char *solidname, int maxlen)
{
    int i;
    struct bu_list head;

    if (dbip == DBI_NULL)
	return;

    BU_LIST_INIT(&head);

    for (i=0; i<number; i++) {
	solidname[8] = '\0';
	crname(solidname, members[i], maxlen);
	if ( db_lookup( dbip, solidname, LOOKUP_QUIET) == DIR_NULL ) {
	    Tcl_AppendResult(interp, "region: ", region, " will skip member: ",
			     solidname, "\n", (char *)NULL);
	    continue;
	}
	mk_addmember( solidname, &head, NULL, op[i] );
    }
    (void)mk_comb( wdbp, region, &head,
		   1, NULL, NULL, NULL,
		   500+Trackpos+i, 0, mat_default, los_default,
		   0, 1, 1 );
}
Esempio n. 8
0
HIDDEN void
get_cbar(void)
{
    int eid, pid;
    int g1, g2;
    point_t pt1, pt2;
    fastf_t radius;
    vect_t height;
    struct pbar *pb;
    char cbar_name[NAMESIZE+1];

    eid = atoi( curr_rec[1] );

    pid = atoi( curr_rec[2] );
    if ( !pid )
    {
	if ( bar_def_pid )
	    pid = bar_def_pid;
	else
	    pid = eid;
    }

    g1 = atoi( curr_rec[3] );

    g2 = atoi( curr_rec[4] );

    get_grid( g1, pt1 );
    get_grid( g2, pt2 );

    for ( BU_LIST_FOR( pb, pbar, &pbar_head.l ) )
    {
	if ( pb->pid == pid )
	    break;
    }

    if ( BU_LIST_IS_HEAD( &pb->l, &pbar_head.l ) )
    {
	log_line( "Non-existent PID referenced in CBAR" );
	return;
    }

    VSCALE( pt1, pt1, conv[units] );
    VSCALE( pt2, pt2, conv[units] );

    radius = sqrt( pb->area/bn_pi );
    radius = radius * conv[units];

    VSUB2( height, pt2, pt1 );

    sprintf( cbar_name, "cbar.%d", eid );
    mk_rcc( fpout, cbar_name, pt1, height, radius );

    mk_addmember( cbar_name, &pb->head.l, NULL, WMOP_UNION );
}
Esempio n. 9
0
void
make_pillar(char *prefix, int ix, int iy, fastf_t *center, fastf_t *lwh, struct wmember *headp)


    /* center of base */


{
    vect_t	min, max;
    unsigned char	rgb[4];		/* needs all 4 */
    char	pilname[32], rname[32], sname[32], oname[32];
    int	i;
    struct wmember head;
    struct wmember *wp;

    BU_LIST_INIT( &head.l );

    snprintf( pilname, 32, "%s%d,%d", prefix, ix, iy );
    snprintf( rname, 32, "%s.r", pilname );
    snprintf( sname, 32, "%s.s", pilname );
    snprintf( oname, 32, "Obj%d,%d", ix, iy );

    VMOVE( min, center );
    min[X] -= lwh[X];
    min[Y] -= lwh[Y];
    VADD2( max, center, lwh );
    mk_rpp( outfp, sname, min, max );

    /* Needs to be in a region, with color!  */
    get_rgb(rgb);
    i = PICK_MAT;
    mk_region1( outfp, rname, sname,
		mtab[i].mt_name, mtab[i].mt_param, rgb );

    (void)mk_addmember( rname, &head.l, NULL, WMOP_UNION );
    wp = mk_addmember( oname, &head.l, NULL, WMOP_UNION );
    MAT_DELTAS( wp->wm_mat, center[X], center[Y], center[Z]+lwh[Z] );
    mk_lfcomb( outfp, pilname, &head, 0 );

    (void)mk_addmember( pilname, &(headp->l), NULL, WMOP_UNION );
}
Esempio n. 10
0
void
process_sphere(int id, fastf_t *center, double rad, int sph_type)
{
    struct sphere *newsph;
    char nm[128], nm1[128];
    unsigned char rgb[3];
    struct wmember reg_head;

    BU_ALLOC(newsph, struct sphere);

    rgb[0] = atom_list[sph_type].red;
    rgb[1] = atom_list[sph_type].green;
    rgb[2] = atom_list[sph_type].blue;

    sprintf(nm1, "sph.%d", id);
    mk_sph(outfp, nm1, center, rad);

    /* Create a region nm to contain the solid nm1 */
    BU_LIST_INIT(&reg_head.l);
    (void)mk_addmember(nm1, &reg_head.l, NULL, WMOP_UNION);
    sprintf(nm, "SPH.%d", id);
    mk_lcomb(outfp, nm, &reg_head, 1, matname, matparm, rgb, 0);

    /* Include this region in the larger group */
    (void)mk_addmember(nm, &head.l, NULL, WMOP_UNION);

    newsph->next = (struct sphere *)0;
    newsph->s_id = id;
    bu_strlcpy(newsph->s_name, nm1, sizeof(newsph->s_name));
    newsph->s_name[14] = '\0';
    VMOVE(newsph->s_center, center);
    newsph->s_rad = rad;
    newsph->s_atom_type = sph_type;

    if (s_head == (struct sphere *) 0) {
	s_head = s_list = newsph;
    } else {
	s_list->next = newsph;
	s_list = newsph;
    }
}
Esempio n. 11
0
bool
BRLCADWrapper::AddMember(const std::string &combname,const std::string &member,mat_t mat)
{
    MAP_OF_BU_LIST_HEADS::iterator i = heads.find(combname);
    if (i != heads.end()) {
	struct bu_list *head = (*i).second;
	if (mk_addmember(member.c_str(), head, mat, WMOP_UNION) == WMEMBER_NULL)
	    return false;
    } else {
	struct bu_list *head = NULL;

	BU_ALLOC(head, struct bu_list);

	BU_LIST_INIT(head);
	if (mk_addmember(member.c_str(), head, mat, WMOP_UNION) == WMEMBER_NULL)
	    return false;
	heads[combname] = head;
    }

    return true;
}
Esempio n. 12
0
int
mk_sol(struct rt_wdb *fp, double radius)
{
    struct wmember c;
    point_t p = { 0, 0, 0};
    /* make a sphere! tada! */
    mk_sph(fp, "sun.s", p, radius * 1000.0);

    BU_LIST_INIT(&c.l);
    mk_addmember("sun.s", &c.l, NULL, WMOP_UNION);
    mk_lcomb(fp, "sun.r", &c, 1, NULL, NULL, NULL, 0);
    return 0;
}
Esempio n. 13
0
void
do_light(char *name, fastf_t *pos, fastf_t *dir_at, int da_flag, double r, unsigned char *rgb, struct wmember *headp)


    /* direction or aim point */
    /* 0 = direction, !0 = aim point */
    /* radius of light */


{
    char	nbuf[64];
    vect_t	center;
    mat_t	rot;
    mat_t	xlate;
    mat_t	both;
    vect_t	from;
    vect_t	dir;

    if ( da_flag )  {
	VSUB2( dir, dir_at, pos );
	VUNITIZE( dir );
    } else {
	VMOVE( dir, dir_at );
    }

    snprintf( nbuf, 64, "%s.s", name );
    VSETALL( center, 0 );
    mk_sph( outfp, nbuf, center, r );

    /*
     * Need to rotate from 0, 0, -1 to vect "dir",
     * then xlate to final position.
     */
    VSET( from, 0, 0, -1 );
    bn_mat_fromto( rot, from, dir );
    MAT_IDN( xlate );
    MAT_DELTAS_VEC( xlate, pos);
    bn_mat_mul( both, xlate, rot );

    mk_region1( outfp, name, nbuf, "light", "shadows=1", rgb );
    (void)mk_addmember( name, &(headp->l), NULL, WMOP_UNION );
}
Esempio n. 14
0
void
make_carpet(char *rname, fastf_t *min, fastf_t *max, char *file, struct wmember *headp)
{
    char	sname[32];
    char	args[128];
    vect_t	cmin, cmax;

    VMOVE( cmin, min );
    VMOVE( cmax, max );
    cmax[Z] = cmin[Z] + 10;		/* not very plush carpet */
    min[Z] = cmax[Z];		/* raise the caller's floor */

    snprintf( sname, 32, "%s.s", rname );
    snprintf( args, 128, "texture file=%s;plastic", file );
    mk_rpp( outfp, sname, cmin, cmax );
    mk_region1( outfp, rname, sname,
		"stack", args,
		(unsigned char *)0 );

    (void)mk_addmember( rname, &(headp->l), NULL, WMOP_UNION );
}
Esempio n. 15
0
void
build_cyl(char *cname, int npts, double radius)
{
    int i;
    vect_t v, h, a, b;
    char name[32];
    struct wmember head;

    BU_LIST_INIT(&head.l);

    for (i=0; i<npts-1; i++) {
	VMOVE(v, sample[i]);
	VSUB2(h, sample[i+1], v);
	VSET(a, 0, radius, 0);
	VSET(b, 0, 0, radius);

	snprintf(name, 32, "%s%d", cname, i);
	mk_tgc(outfp, name, v, h, a, b, a, b);
	(void)mk_addmember(name, &head.l, NULL, WMOP_UNION);
    }
    mk_lfcomb(outfp, cname, &head, 0);
}
Esempio n. 16
0
bool
BRLCADWrapper::WriteBrep(std::string name, ON_Brep *brep, mat_t &mat)
{
    std::ostringstream str;
    std::string strcnt;
    std::string sol = name + ".s";
    std::string reg = name;

    mk_brep(outfp, sol.c_str(), brep);
    unsigned char rgb[] = {200, 180, 180};

    BRLCADWrapper::getRandomColor(rgb);

    struct bu_list head;
    BU_LIST_INIT(&head);
    if (mk_addmember(sol.c_str(), &head, mat, WMOP_UNION) == WMEMBER_NULL)
	return false;

    if (mk_comb(outfp, reg.c_str(), &head, 1, "plastic", "", rgb, 0, 0, 0, 0, 0, 0, 0) > 0)
	return true;

    return false;
}
Esempio n. 17
0
HIDDEN void
create_boxes(genptr_t callBackData, int x, int y, int z, const char *UNUSED(a), fastf_t fill)
{
    fastf_t min[3], max[3];

    struct bu_vls *vp;
    char bufx[50], bufy[50], bufz[50];
    char *nameDestination;

    struct voxelizeData *dataValues = (struct voxelizeData *)callBackData;

    sprintf(bufx, "%d", x);
    sprintf(bufy, "%d", y);
    sprintf(bufz, "%d", z);
    if(dataValues->threshold <= fill) {
	vp = bu_vls_vlsinit();
	bu_vls_strcat(vp, dataValues->newname);
	bu_vls_strcat(vp, ".x");
	bu_vls_strcat(vp, bufx);
	bu_vls_strcat(vp, "y");
	bu_vls_strcat(vp, bufy);
	bu_vls_strcat(vp, "z");
	bu_vls_strcat(vp, bufz);
	bu_vls_strcat(vp, ".s");

	min[0] = (dataValues->bbMin)[0] + (x * (dataValues->sizeVoxel)[0]);
	min[1] = (dataValues->bbMin)[1] + (y * (dataValues->sizeVoxel)[1]);
	min[2] = (dataValues->bbMin)[2] + (z * (dataValues->sizeVoxel)[2]);
	max[0] = (dataValues->bbMin)[0] + ( (x + 1.0) * (dataValues->sizeVoxel)[0]);
	max[1] = (dataValues->bbMin)[1] + ( (y + 1.0) * (dataValues->sizeVoxel)[1]);
	max[2] = (dataValues->bbMin)[2] + ( (z + 1.0) * (dataValues->sizeVoxel)[2]);

	nameDestination = bu_vls_strgrab(vp);
	mk_rpp(dataValues->wdbp,nameDestination, min, max);
	mk_addmember(nameDestination, &dataValues->content.l, 0, WMOP_UNION);
    }
}
Esempio n. 18
0
void
make_walls(char *rname, fastf_t *imin, fastf_t *imax, fastf_t *thickness, int bits, struct wmember *headp)

    /* Interior RPP min point */


{
    struct wmember head;
    char	name[32];
    vect_t	omin, omax;	/* outer dimensions */
    vect_t	wmin, wmax;
    int	mask;

    BU_LIST_INIT( &head.l );

    /* thickness[Z] = 0; */

    /*
     *  Set exterior dimensions to interior dimensions.
     *  Then, thicken them as necessary due to presence of
     *  exterior walls.
     *  It may be useful to return the exterior min, max.
     */
    VMOVE( omin, imin );
    VMOVE( omax, imax );
    if ( bits & EAST )
	omax[X] += thickness[X];
    if ( bits & WEST )
	omin[X] -= thickness[X];
    if ( bits & NORTH )
	omax[Y] += thickness[Y];
    if ( bits & SOUTH )
	omin[Y] -= thickness[Y];

    for ( mask=8; mask > 0; mask >>= 1 )  {
	if ( (bits & mask) == 0 )  continue;

	VMOVE( wmin, omin );
	VMOVE( wmax, omax );

	switch ( mask )  {
	    case SOUTH:
		/* South (-Y) wall */
		snprintf( name, 32, "S%s", rname );
		wmax[Y] = imin[Y];
		break;
	    case WEST:
		/* West (-X) wall */
		snprintf( name, 32, "W%s", rname );
		wmax[X] = imin[X];
		break;
	    case NORTH:
		/* North (+Y) wall */
		snprintf( name, 32, "N%s", rname );
		wmin[Y] = imax[Y];
		break;
	    case EAST:
		/* East (+X) wall */
		snprintf( name, 32, "E%s", rname );
		wmin[X] = imax[X];
		break;
	}
	mk_rpp( outfp, name, wmin, wmax );
	(void)mk_addmember( name, &head.l, NULL, WMOP_UNION );
    }

    mk_lfcomb( outfp, rname, &head, 1 );
    (void)mk_addmember( rname, &(headp->l), NULL, WMOP_UNION );
}
Esempio n. 19
0
int
main(int argc, char **argv)
{
    int c;
    int i;
    struct pshell *psh;
    struct pbar *pbp;
    struct wmember head;
    struct wmember all_head;
    char *nastran_file = "Converted from NASTRAN file (stdin)";

    bu_setprogname(argv[0]);

    fpin = stdin;

    units = INCHES;

    /* 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;

    while ((c=bu_getopt(argc, argv, "x:X:t:ni:o:mh?")) != -1) {
	switch (c) {
	    case 'x':
		sscanf(bu_optarg, "%x", (unsigned int *)&RTG.debug);
		bu_printb("librt RT_G_DEBUG", RT_G_DEBUG, DEBUG_FORMAT);
		bu_log("\n");
		break;
	    case 'X':
		sscanf(bu_optarg, "%x", (unsigned int *)&RTG.NMG_debug);
		bu_printb("librt RTG.NMG_debug", RTG.NMG_debug, NMG_DEBUG_FORMAT);
		bu_log("\n");
		break;
	    case 't':		/* calculational tolerance */
		tol.dist = atof(bu_optarg);
		tol.dist_sq = tol.dist * tol.dist;
		break;
	    case 'n':
		polysolids = 0;
		break;
	    case 'm':
		units = MM;
		break;
	    case 'i':
		fpin = fopen(bu_optarg, "rb");
		if (fpin == (FILE *)NULL) {
		    bu_log("Cannot open NASTRAN file (%s) for reading!\n", bu_optarg);
		    bu_exit(1, Usage, argv[0]);
		}
		nastran_file = bu_optarg;
		break;
	    case 'o':
		output_file = bu_optarg;
		break;
	    default:
		bu_exit(1, Usage, argv[0]);
	}
    }

    fpout = wdb_fopen(output_file);
    if (fpout == NULL) {
	bu_log("Cannot open BRL-CAD file (%s) for writing!\n", output_file);
	bu_exit(1, Usage, argv[0]);
    }

    if (!fpin || !fpout) {
	bu_exit(1, Usage, argv[0]);
    }

    line = (char *)bu_malloc(MAX_LINE_SIZE, "line");
    next_line = (char *)bu_malloc(MAX_LINE_SIZE, "next_line");
    prev_line = (char *)bu_malloc(MAX_LINE_SIZE, "prev_line");
    curr_rec = (char **)bu_calloc(NO_OF_FIELDS, sizeof(char *), "curr_rec");
    for (i=0; i<NO_OF_FIELDS; i++)
	curr_rec[i] = (char *)bu_malloc(sizeof(char)*FIELD_LENGTH, "curr_rec[i]");
    prev_rec = (char **)bu_calloc(NO_OF_FIELDS, sizeof(char *), "prev_rec");
    for (i=0; i<NO_OF_FIELDS; i++)
	prev_rec[i] = (char *)bu_malloc(sizeof(char)*FIELD_LENGTH, "prev_rec[i]");

    /* first pass, find start of NASTRAN "bulk data" */
    start_off = (-1);
    bulk_data_start_line = 0;
    while (bu_fgets(line, MAX_LINE_SIZE, fpin)) {
	bulk_data_start_line++;
	if (bu_strncmp(line, "BEGIN BULK", 10))
	    continue;

	start_off = bu_ftell(fpin);
	break;
    }

    if (start_off < 0) {
	bu_log("Cannot find start of bulk data in NASTRAN file!\n");
	bu_exit(1, Usage, argv[0]);
    }

    /* convert BULK data deck into something reasonable */
    fptmp = bu_temp_file(NULL, 0);
    if (fptmp == NULL) {
	perror(argv[0]);
	bu_exit(1, "Cannot open temporary file\n");
    }
    convert_input();

    /* initialize some lists */
    BU_LIST_INIT(&coord_head.l);
    BU_LIST_INIT(&pbar_head.l);
    BU_LIST_INIT(&pshell_head.l);
    BU_LIST_INIT(&all_head.l);

    nmg_model = (struct model *)NULL;

    /* count grid points */
    bu_fseek(fptmp, 0, SEEK_SET);
    while (bu_fgets(line, MAX_LINE_SIZE, fptmp)) {
	if (!bu_strncmp(line, "GRID", 4))
	    grid_count++;
    }
    if (!grid_count) {
	bu_exit(1, "No geometry in this NASTRAN file!\n");
    }

    /* get default values and properties */
    bu_fseek(fptmp, 0, SEEK_SET);
    while (get_next_record(fptmp, 1, 0)) {
	if (!bu_strncmp(curr_rec[0], "BAROR", 5)) {
	    /* get BAR defaults */
	    bar_def_pid = atoi(curr_rec[2]);
	} else if (!bu_strncmp(curr_rec[0], "PBAR", 4)) {
	    struct pbar *pb;

	    BU_ALLOC(pb, struct pbar);

	    pb->pid = atoi(curr_rec[1]);
	    pb->mid = atoi(curr_rec[2]);
	    pb->area = atof(curr_rec[3]);

	    BU_LIST_INIT(&pb->head.l);

	    BU_LIST_INSERT(&pbar_head.l, &pb->l);
	} else if (!bu_strncmp(curr_rec[0], "PSHELL", 6)) {
	    BU_ALLOC(psh, struct pshell);

	    psh->s = (struct shell *)NULL;
	    psh->pid = atoi(curr_rec[1]);
	    psh->mid = atoi(curr_rec[2]);
	    psh->thick = atof(curr_rec[3]);
	    BU_LIST_INSERT(&pshell_head.l, &psh->l);
	    pshell_count++;
	}
    }

    /* allocate storage for grid points */
    g_pts = (struct grid_point *)bu_calloc(grid_count, sizeof(struct grid_point), "grid points");

    /* get all grid points */
    bu_fseek(fptmp, 0, SEEK_SET);
    while (get_next_record(fptmp, 1, 0)) {
	int gid;
	int cid;
	double tmp[3];

	if (bu_strncmp(curr_rec[0], "GRID", 4))
	    continue;

	gid = atoi(curr_rec[1]);
	cid = atoi(curr_rec[2]);

	for (i=0; i<3; i++) {
	    tmp[i] = atof(curr_rec[i+3]);
	}

	g_pts[grid_used].gid = gid;
	g_pts[grid_used].cid = cid;
	g_pts[grid_used].v = (struct vertex **)bu_calloc(pshell_count + 1, sizeof(struct vertex *), "g_pts vertex array");
	VMOVE(g_pts[grid_used].pt, tmp);
	grid_used++;
    }


    /* find coordinate systems */
    bu_fseek(fptmp, 0, SEEK_SET);
    while (get_next_record(fptmp, 1, 0)) {
	if (bu_strncmp(curr_rec[0], "CORD", 4))
	    continue;

	get_coord_sys();
    }
    /* convert everything to BRL-CAD coordinate system */
    i = 0;
    while (convert_all_cs() || convert_all_pts()) {
	i++;
	if (i > 10) {
	    bu_exit(1, "Cannot convert to default coordinate system, check for circular definition\n");
	}
    }

    mk_id(fpout, nastran_file);

    /* get elements */
    bu_fseek(fptmp, 0, SEEK_SET);
    while (get_next_record(fptmp, 1, 0)) {
	if (!bu_strncmp(curr_rec[0], "CBAR", 4))
	    get_cbar();
	else if (!bu_strncmp(curr_rec[0], "CROD", 4))
	    get_cbar();
	else if (!bu_strncmp(curr_rec[0], "CTRIA3", 6))
	    get_ctria3();
	else if (!bu_strncmp(curr_rec[0], "CQUAD4", 6))
	    get_cquad4();
    }

    if (nmg_model) {
	nmg_rebound(nmg_model, &tol);
	if (polysolids)
	    mk_bot_from_nmg(fpout, "pshell.0", nmg_shell);
	else
	    mk_nmg(fpout, "pshell.0", nmg_model);
    }

    BU_LIST_INIT(&head.l);
    for (BU_LIST_FOR(psh, pshell, &pshell_head.l)) {
	struct model *m;
	char name[NAMESIZE+1];

	if (!psh->s)
	    continue;

	m = nmg_find_model(&psh->s->l.magic);
	nmg_rebound(m, &tol);
	nmg_fix_normals(psh->s, &tol);
	if (psh->thick > tol.dist) {
	    nmg_model_face_fuse(m, &tol);
	    nmg_hollow_shell(psh->s, psh->thick*conv[units], 1, &tol);
	}
	sprintf(name, "pshell.%d", psh->pid);
	if (polysolids)
	    mk_bot_from_nmg(fpout, name, psh->s);
	else
	    mk_nmg(fpout, name, m);

	mk_addmember(name, &head.l, NULL, WMOP_UNION);
    }
    if (BU_LIST_NON_EMPTY(&head.l)) {
	mk_lfcomb(fpout, "shells", &head, 0);
	mk_addmember("shells", &all_head.l, NULL, WMOP_UNION);
    }

    BU_LIST_INIT(&head.l);
    for (BU_LIST_FOR(pbp, pbar, &pbar_head.l)) {
	char name[NAMESIZE+1];

	if (BU_LIST_IS_EMPTY(&pbp->head.l))
	    continue;

	sprintf(name, "pbar_group.%d", pbp->pid);
	mk_lfcomb(fpout, name, &pbp->head, 0);

	mk_addmember(name, &head.l, NULL, WMOP_UNION);
    }
    if (BU_LIST_NON_EMPTY(&head.l)) {
	mk_lfcomb(fpout, "pbars", &head, 0);
	mk_addmember("pbars", &all_head.l, NULL, WMOP_UNION);
    }

    if (BU_LIST_NON_EMPTY(&all_head.l)) {
	mk_lfcomb(fpout, "all", &all_head, 0);
    }
    wdb_close(fpout);
    return 0;
}
Esempio n. 20
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");
    }
}
Esempio n. 21
0
int
main(int argc, char **argv)
{
    /* START # 1 */
    struct rt_wdb *fpw;		/* File to be written to. */
    char filemged[26] = {0};	/* Mged file create. */
    double hgt=0;       	/* Height, width, & depth of gas tank. */
    double wid=0;
    double dpt=0;
    double rds=0;		/* Radius of the corner of gas tank. */
    point_t pts[8];		/* Points for arb8. */
    point_t bs;			/* Base of cylinder. */
    vect_t ht;			/* Height of cylinder. */
    fastf_t rad;		/* Radius of cylinder & sphere. */
    point_t cent;		/* Center of sphere. */

    /* point_t and vect_t are set using typedef of type fastf_t. */
    /* fastf_t is a type that is machine dependent. */

    char *temp;			/* Temporary character string. */
    char temp1[16];		/* Temporary character string. */

    char solnam[9];		/* Solid name. */
    char regnam[9];		/* Region name. */
    char grpnam[5];		/* Group name. */
    int numtnk=0;		/* Number of gas tanks to be created */
				/* (<=26). */

    struct wmember comb;	/* Used to make regions. */
    struct wmember comb1;	/* Used to make groups. */

    int i, j, k;		/* Loop counters. */
    int ret;

    /* Set up solid, region, and group names. */
    solnam[0] = 's';
    solnam[1] = '.';
    solnam[2] = 't';
    solnam[3] = 'n';
    solnam[4] = 'k';
    solnam[5] = ' ';
    solnam[6] = '#';
    solnam[7] = '#';
    solnam[8] = '\0';
    regnam[0] = 'r';
    regnam[1] = '.';
    regnam[2] = 't';
    regnam[3] = 'n';
    regnam[4] = 'k';
    regnam[5] = ' ';
    regnam[6] = '#';
    regnam[7] = '#';
    regnam[8] = '\0';
    grpnam[0] = 't';
    grpnam[1] = 'n';
    grpnam[2] = 'k';
    grpnam[3] = ' ';
    grpnam[4] = '\0';

    /* If there are no arguments ask questions. */
    if (argc == 1) {
	/* START # 3 */

	/* Print info about the window. */
	printf("\nThis program constructs a solid gas tank with all\n");
	printf("edges and corners rounded.\n\n");

	/* Find name of mged file to be created. */
	printf("Enter the mged file to be created (25 char max).\n\t");
	(void)fflush(stdout);
	ret = scanf("%26s", filemged);
	if (ret == 0) {
	    perror("scanf");
	}
	if (BU_STR_EQUAL(filemged, ""))
	    bu_strlcpy(filemged, "gastank.g", sizeof(filemged));

	/* Find the number of gas tanks to create. */
	printf("Enter the number of gas tanks to create (26 max).\n\t");
	(void)fflush(stdout);
	ret = scanf("%d", &numtnk);
	if (ret == 0) {
	    perror("scanf");
	    numtnk = 1;
	}
	if (numtnk < 1)
	    numtnk = 1;
	if (numtnk > 26)
	    numtnk = 26;

	/* Find the dimensions of the gas tanks. */
	printf("Enter the height, width, and depth of the gas tank.\n\t");
	(void)fflush(stdout);
	ret = scanf("%lf %lf %lf", &hgt, &wid, &dpt);
	if (ret == 0) {
	    perror("scanf");
	    hgt = 1000.0;
	    wid = 1000.0;
	    dpt = 1000.0;
	}
	if (hgt < SMALL_FASTF)
	    hgt = SMALL_FASTF;
	if (wid < SMALL_FASTF)
	    wid = SMALL_FASTF;
	if (dpt < SMALL_FASTF)
	    dpt = SMALL_FASTF;

	printf("Enter the radius of the corners.\n\t");
	(void)fflush(stdout);
	ret = scanf("%lf", &rds);
	if (ret == 0) {
	    perror("scanf");
	    rds = 10.0;
	}
	if (rds < SMALL_FASTF)
	    rds = SMALL_FASTF;
    }							/* END # 3 */

    /* If there are arguments get answers from arguments. */
    else {
	/* START # 4 */
	/* List options. */
	/* -fname - name = mged file name. */
	/* -n# - # = number of gas tanks. */
	/* -h# - # = height of gas tank in mm. */
	/* -w# - # = width of gas tank in mm. */
	/* -d# - # = depth of gas tank in mm. */
	/* -r# - # = radius of corners in mm. */

	for (i=1; i<argc; i++) {
	    /* START # 5 */
	    /* Put argument in temporary character string. */
	    temp = argv[i];

	    /* -f - mged file. */
	    if (temp[1] == 'f') {
		/* START # 6 */
		j = 2;
		k = 0;
		while ((temp[j] != '\0') && (k < 25)) {
		    /* START # 7 */
		    filemged[k] = temp[j];
		    j++;
		    k++;
		}					/* END # 7 */
		filemged[k] = '\0';
	    }						/* END # 6 */

	    /* All other options. */
	    else {
		/* START # 8 */
		/* Set up temporary character string. */
		j = 2;
		k = 0;
		while ((temp[j] != '\0') && (k < 15)) {
		    /* START # 9 */
		    temp1[k] = temp[j];
		    j++;
		    k++;
		}					/* END # 9 */
		temp1[k] = '\0';
		if (temp[1] == 'n') {
		    sscanf(temp1, "%d", &numtnk);
		    if (numtnk > 26) numtnk = 26;
		} else if (temp[1] == 'h') {
		    sscanf(temp1, "%lf", &hgt);
		} else if (temp[1] == 'w') {
		    sscanf(temp1, "%lf", &wid);
		} else if (temp[1] == 'd') {
		    sscanf(temp1, "%lf", &dpt);
		} else if (temp[1] == 'r') {
		    sscanf(temp1, "%lf", &rds);
		}
	    }						/* END # 8 */
	}						/* END # 5 */
    }							/* END # 4 */

    /* Print out all info. */
    printf("\nmged file:  %s\n", filemged);
    printf("height of gas tank:  %f mm\n", hgt);
    printf("width of gas tank:  %f mm\n", wid);
    printf("depth of gas tank:  %f mm\n", dpt);
    printf("radius of corner:  %f mm\n", rds);
    printf("number of gas tanks:  %d\n\n", numtnk);
    (void)fflush(stdout);

    /* Open mged file. */
    fpw = wdb_fopen(filemged);

    /* Write ident record. */
    mk_id(fpw, "windows");

    for (i=0; i<numtnk; i++) {
	/* START # 2 */

	/* Create all solids. */

	/* Create the 3 arb8s. */

	pts[0][0] = (fastf_t)(dpt / 2.0);
	pts[0][1] = (fastf_t)(wid / 2.0 - rds);
	pts[0][2] = (fastf_t)(hgt / 2.0 - rds);
	pts[1][0] = pts[0][0];
	pts[1][1] = pts[0][1];
	pts[1][2] = (-pts[0][2]);
	pts[2][0] = pts[0][0];
	pts[2][1] = (-pts[0][1]);
	pts[2][2] = pts[1][2];
	pts[3][0] = pts[0][0];
	pts[3][1] = pts[2][1];
	pts[3][2] = pts[0][2];
	pts[4][0] = (-pts[0][0]);
	pts[4][1] = pts[0][1];
	pts[4][2] = pts[0][2];
	pts[5][0] = pts[4][0];
	pts[5][1] = pts[0][1];
	pts[5][2] = (-pts[0][2]);
	pts[6][0] = pts[4][0];
	pts[6][1] = (-pts[0][1]);
	pts[6][2] = pts[1][2];
	pts[7][0] = pts[4][0];
	pts[7][1] = pts[2][1];
	pts[7][2] = pts[0][2];
	solnam[5] = 97 + i;
	solnam[6] = '0';
	solnam[7] = '1';
	mk_arb8(fpw, solnam, &pts[0][X]);

	pts[0][0] = (fastf_t)(dpt / 2.0 - rds);
	pts[0][1] = (fastf_t)(wid / 2.0);
	pts[1][0] = pts[0][0];
	pts[1][1] = pts[0][1];
	pts[2][0] = pts[0][0];
	pts[2][1] = (-pts[0][1]);
	pts[3][0] = pts[0][0];
	pts[3][1] = pts[2][1];
	pts[4][0] = (-pts[0][0]);
	pts[4][1] = pts[0][1];
	pts[5][0] = pts[4][0];
	pts[5][1] = pts[0][1];
	pts[6][0] = pts[4][0];
	pts[6][1] = pts[2][1];
	pts[7][0] = pts[4][0];
	pts[7][1] = pts[2][1];
	solnam[7] = '2';
	mk_arb8(fpw, solnam, &pts[0][X]);

	pts[0][1] = (fastf_t)(wid / 2.0 - rds);
	pts[0][2] = (fastf_t)(hgt / 2.0);
	pts[1][1] = pts[0][1];
	pts[1][2] = (-pts[0][2]);
	pts[2][1] = (-pts[0][1]);
	pts[2][2] = pts[1][2];
	pts[3][1] = pts[2][1];
	pts[3][2] = pts[0][2];
	pts[4][1] = pts[0][1];
	pts[4][2] = pts[0][2];
	pts[5][1] = pts[0][1];
	pts[5][2] = (-pts[0][2]);
	pts[6][1] = (-pts[0][1]);
	pts[6][2] = pts[1][2];
	pts[7][1] = pts[2][1];
	pts[7][2] = pts[0][2];
	solnam[7] = '3';
	mk_arb8(fpw, solnam, &pts[0][X]);

	/* Make 8 spheres. */

	cent[0] = (fastf_t)(dpt / 2.0 - rds);
	cent[1] = (fastf_t)(wid / 2.0 - rds);
	cent[2] = (fastf_t)(hgt / 2.0 - rds);
	rad = (fastf_t)(rds);
	solnam[7] = '4';
	mk_sph(fpw, solnam, cent, rad);

	cent[2] = (-cent[2]);
	solnam[7] = '5';
	mk_sph(fpw, solnam, cent, rad);

	cent[1] = (-cent[1]);
	solnam[7] = '6';
	mk_sph(fpw, solnam, cent, rad);

	cent[2] = (-cent[2]);
	solnam[7] = '7';
	mk_sph(fpw, solnam, cent, rad);

	cent[0] = (-cent[0]);
	cent[1] = (-cent[1]);
	solnam[7] = '8';
	mk_sph(fpw, solnam, cent, rad);

	cent[2] = (-cent[2]);
	solnam[7] = '9';
	mk_sph(fpw, solnam, cent, rad);

	cent[1] = (-cent[1]);
	solnam[6] = '1';
	solnam[7] = '0';
	mk_sph(fpw, solnam, cent, rad);

	cent[2] = (-cent[2]);
	solnam[7] = '1';
	mk_sph(fpw, solnam, cent, rad);

	/* Make 12 cylinders. */

	bs[0] = (fastf_t)(dpt / 2.0 - rds);
	bs[1] = (fastf_t)(wid / 2.0 - rds);
	bs[2] = (fastf_t)(hgt / 2.0 - rds);
	ht[0] = (fastf_t)(0.0);
	ht[1] = (fastf_t)(-wid + 2 * rds);
	ht[2] = (fastf_t)(0.0);
	solnam[7] = '2';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[2] = (-bs[2]);
	solnam[7] = '3';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[0] = (-bs[0]);
	solnam[7] = '4';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[2] = (-bs[2]);
	solnam[7] = '5';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[0] = (fastf_t)(dpt / 2.0 - rds);
	bs[1] = (fastf_t)(wid / 2.0 - rds);
	bs[2] = (fastf_t)(hgt / 2.0 - rds);
	ht[0] = (fastf_t)(0.0);
	ht[1] = (fastf_t)(0.0);
	ht[2] = (fastf_t)(-hgt + 2 * rds);
	solnam[7] = '6';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[1] = (-bs[1]);
	solnam[7] = '7';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[0] = (-bs[0]);
	solnam[7] = '8';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[1] = (-bs[1]);
	solnam[7] = '9';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[0] = (fastf_t)(dpt / 2.0 - rds);
	bs[1] = (fastf_t)(wid / 2.0 - rds);
	bs[2] = (fastf_t)(hgt / 2.0 - rds);
	ht[0] = (fastf_t)(-dpt + 2 * rds);
	ht[1] = (fastf_t)(0.0);
	ht[2] = (fastf_t)(0.0);
	solnam[6] = '2';
	solnam[7] = '0';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[2] = (-bs[2]);
	solnam[7] = '1';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[1] = (-bs[1]);
	solnam[7] = '2';
	mk_rcc(fpw, solnam, bs, ht, rad);

	bs[2] = (-bs[2]);
	solnam[7] = '3';
	mk_rcc(fpw, solnam, bs, ht, rad);

	/* Make all regions. */

	/* Initialize list. */
	BU_LIST_INIT(&comb.l);

	/* Region 1. */
	solnam[5] = 97 + i;
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[5] = 97 + i;
	regnam[6] = '0';
	regnam[7] = '1';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 2. */
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '2';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 3. */
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	regnam[7] = '3';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 4. */
	solnam[7] = '4';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '6';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '0';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '4';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 5. */
	solnam[6] = '0';
	solnam[7] = '5';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '6';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '5';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 6. */
	solnam[6] = '0';
	solnam[7] = '6';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '7';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '6';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 7. */
	solnam[6] = '0';
	solnam[7] = '7';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '7';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '7';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 8. */
	solnam[6] = '0';
	solnam[7] = '8';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '5';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '9';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '0';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '8';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 9. */
	solnam[6] = '0';
	solnam[7] = '9';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '1';
	solnam[7] = '4';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '9';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[7] = '9';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 10. */
	solnam[6] = '1';
	solnam[7] = '0';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[7] = '4';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '8';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '0';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 11. */
	solnam[6] = '1';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[7] = '5';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '8';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[6] = '2';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '1';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 12. */
	solnam[6] = '1';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '2';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 13. */
	solnam[6] = '1';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '3';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 14. */
	solnam[6] = '1';
	solnam[7] = '4';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '4';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 15. */
	solnam[6] = '1';
	solnam[7] = '5';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '5';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 16. */
	solnam[6] = '1';
	solnam[7] = '6';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '6';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 17. */
	solnam[6] = '1';
	solnam[7] = '7';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '7';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 18. */
	solnam[6] = '1';
	solnam[7] = '8';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '8';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 19. */
	solnam[6] = '1';
	solnam[7] = '9';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '1';
	regnam[7] = '9';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 20. */
	solnam[6] = '2';
	solnam[7] = '0';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '2';
	regnam[7] = '0';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 21. */
	solnam[6] = '2';
	solnam[7] = '1';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '2';
	regnam[7] = '1';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 22. */
	solnam[6] = '2';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '2';
	regnam[7] = '2';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Region 23. */
	solnam[6] = '2';
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT);
	solnam[6] = '0';
	solnam[7] = '2';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	solnam[7] = '3';
	(void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT);
	regnam[6] = '2';
	regnam[7] = '3';
	mk_lfcomb(fpw, regnam, &comb, 1);

	/* Create group. */

	/* Initialize list. */
	BU_LIST_INIT(&comb1.l);

	regnam[6] = '0';
	regnam[7] = '1';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '2';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '3';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '4';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '5';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '6';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '7';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '8';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '9';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[6] = '1';
	regnam[7] = '0';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '1';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '2';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '3';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '4';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '5';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '6';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '7';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '8';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '9';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[6] = '2';
	regnam[7] = '0';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '1';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '2';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	regnam[7] = '3';
	(void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION);
	grpnam[3] = 97 + i;
	mk_lfcomb(fpw, grpnam, &comb1, 0);

    }							/* START # 2 */

    /* Close file. */
    wdb_close(fpw);
    return 0;
}							/* END # 1 */
void
Convassem()
{
    int i, j, k, comblen, conv = 0, totass = 0;
    struct solid_list *root, *ptr, *ptr_tmp;
    struct wmember head, *wmem;
    int no_of_assoc = 0;
    int no_of_props = 0;
    int att_de = 0;
    unsigned char *rgb;
    struct brlcad_att brl_att;
    fastf_t *flt;

    bu_log("\nConverting solid assembly entities:\n");

    ptr = NULL;
    root = NULL;
    BU_LIST_INIT(&head.l);

    for (i = 0; i < totentities; i++) {
	/* loop through all entities */
	if (dir[i]->type != 184)	/* This is not a solid assembly */
	    continue;

	/* Increment count of solid assemblies */
	totass++;

	if (dir[i]->param <= pstart) {
	    bu_log("Illegal parameter pointer for entity D%07d (%s)\n" ,
		   dir[i]->direct, dir[i]->name);
	    continue;
	}
	Readrec(dir[i]->param); /* read first record into buffer */

	Readint(&j, "");	/* read entity type */
	if (j != 184) {
	    bu_log("Incorrect entity type in Parameter section for entity %d\n", i);
	    return;
	}

	Readint(&comblen, "");	/* read number of members in group */

	/* Read pointers to group members */
	for (j = 0; j < comblen; j++) {
	    if (ptr == NULL) {
		root = (struct solid_list *)bu_malloc(sizeof(struct solid_list),
						      "Convassem: root");
		ptr = root;
	    } else {
		ptr->next = (struct solid_list *)bu_malloc(sizeof(struct solid_list),
							   "Convassem: ptr->next");
		ptr = ptr->next;
	    }
	    ptr->next = NULL;

	    /* Read pointer to an object */
	    Readint(&ptr->item, "");
	    if (ptr->item < 0)
		ptr->item = (-ptr->item);

	    /* Convert pointer to a "dir" index */
	    ptr->item = (ptr->item-1)/2;

	    /* Save name of object */
	    ptr->name = dir[ptr->item]->name;

	    /* increment reference count */
	    dir[ptr->item]->referenced++;
	}

	/* Read pointer to transformation matrix for each member */
	ptr = root;
	for (j = 0; j < comblen; j++) {
	    ptr->matrix = 0;

	    /* Read pointer to a transformation */
	    Readint(&ptr->matrix, "");

	    if (ptr->matrix < 0)
		ptr->matrix = (-ptr->matrix);

	    /* Convert to a "dir" index */
	    if (ptr->matrix)
		ptr->matrix = (ptr->matrix-1)/2;
	    else
		ptr->matrix = (-1); /* flag to indicate "none" */

	    ptr = ptr->next;
	}

	/* skip over the associativities */
	Readint(&no_of_assoc, "");
	for (k = 0; k < no_of_assoc; k++)
	    Readint(&j, "");

	/* get property entity DE's */
	Readint(&no_of_props, "");
	for (k = 0; k < no_of_props; k++) {
	    Readint(&j, "");
	    if (dir[(j-1)/2]->type == 422 &&
		dir[(j-1)/2]->referenced == brlcad_att_de) {
		/* this is one of our attribute instances */
		att_de = j;
	    }
	}

	Read_att(att_de, &brl_att);

	/* Make the members */
	ptr = root;
	while (ptr != NULL) {
	    /* copy the members original transformation matrix */
	    for (j = 0; j < 16; j++)
		ptr->rot[j] = (*dir[ptr->item]->rot)[j];

	    /* Apply any matrix indicated for this group member */
	    if (ptr->matrix > (-1)) {
#if defined(USE_BN_MULT_)
		/* a <= a X b */
		bn_mat_mul2(ptr->rot, *(dir[ptr->matrix]->rot));
#else
		/* a X b => o */
		Matmult(ptr->rot, *(dir[ptr->matrix]->rot), ptr->rot);
#endif
	    }

	    wmem = mk_addmember(ptr->name, &head.l, NULL, operators[Union]);
	    flt = (fastf_t *)ptr->rot;
	    for (j = 0; j < 16; j++) {
		wmem->wm_mat[j] = (*flt);
		flt++;
	    }
	    ptr = ptr->next;
	}

	/* Make the object */
	if (dir[i]->colorp != 0)
	    rgb = (unsigned char*)dir[i]->rgb;
	else
	    rgb = (unsigned char *)0;

	mk_lrcomb(fdout ,
		  dir[i]->name,		/* name */
		  &head,			/* members */
		  brl_att.region_flag,	/* region flag */
		  brl_att.material_name,	/* material name */
		  brl_att.material_params, /* material parameters */
		  rgb,			/* color */
		  brl_att.ident,		/* ident */
		  brl_att.air_code,	/* air code */
		  brl_att.material_code,	/* GIFT material */
		  brl_att.los_density,	/* los density */
		  brl_att.inherit);	/* inherit */


	/* Increment the count of successful conversions */
	conv++;

	/* Free some memory */
	ptr = root;
	while (ptr != NULL) {
	    ptr_tmp = ptr->next;
	    bu_free((char *)ptr, "convassem: ptr");
	    ptr = ptr_tmp;
	}
    }
    bu_log("Converted %d solid assemblies successfully out of %d total assemblies\n", conv, totass);
}
Esempio n. 23
0
struct obj_info *
Assembly_import( int id_start )
{
    char line[MAX_LINE_SIZE];
    struct obj_info *this_assem, *member;
    struct wmember assem_head;
    int id_end, member_id;
    size_t i;

    BU_ALLOC(this_assem, struct obj_info);

    this_assem->obj_type = ASSEMBLY_TYPE;
    this_assem->obj_id = id_start;
    this_assem->part_count = 0;
    this_assem->members = NULL;
    while ( bu_fgets( line, MAX_LINE_SIZE, fd_in ) ) {
	if ( !bu_strncmp( line, "AssemblyName", 12 ) ) {
	    line[strlen( line ) - 1] = '\0';
	    this_assem->obj_name = bu_strdup( &line[13] );
	    lower_case( this_assem->obj_name );
	    DO_INDENT;
	    bu_log( "Start of assembly %s (id = %d)\n", this_assem->obj_name, id_start );
	    indent_level += indent_delta;
	} else if ( !bu_strncmp( line, "PartId", 6 ) ) {
	    /* found a member part */
	    member_id = atoi( &line[7] );
	    member = Part_import( member_id );
	    if ( !member )
		continue;
	    this_assem->part_count++;
	    this_assem->members = (struct obj_info **)bu_realloc(
		this_assem->members,
		this_assem->part_count * sizeof( struct obj_info *),
		"this_assem->members" );
	    this_assem->members[this_assem->part_count-1] = member;
	} else if ( !bu_strncmp( line, "AssemblyId", 10 ) ) {
	    /* found a member assembly */
	    member_id = atoi( &line[11] );
	    member = Assembly_import( member_id );
	    this_assem->part_count++;
	    this_assem->members = (struct obj_info **)bu_realloc(
		this_assem->members,
		this_assem->part_count * sizeof( struct obj_info *),
		"this_assem->members" );
	    this_assem->members[this_assem->part_count-1] = member;
	} else if ( !bu_strncmp( line, "EndAssemblyId", 13 ) ) {
	    /* found end of assembly, make sure it is this one */
	    id_end = atoi( &line[14] );
	    if ( id_end != id_start )
		bu_exit( 1, "%s: ERROR: found end of assembly id %d while processing id %d\n", progname,id_end, id_start );
	    indent_level -= indent_delta;
	    DO_INDENT;
	    bu_log( "Found end of assembly %s (id = %d)\n",  this_assem->obj_name, id_start );
	    break;
	} else {
	    bu_log( "%s: Unrecognized line encountered while processing assembly id %d:\n", progname,id_start );
	    bu_exit( 1, "%s\n", line );
	}
    }

    Make_brlcad_names( this_assem );

    /* write this assembly to the database */
    BU_LIST_INIT( &assem_head.l );

    for ( i=0; i<this_assem->part_count; i++ )
	if ( mk_addmember( this_assem->members[i]->brlcad_comb,
			   &assem_head.l, NULL, WMOP_UNION ) == WMEMBER_NULL )
	    bu_exit( 1, "%s: ERROR: Failed to add region %s to assembly %s\n",
			progname,this_assem->members[i]->brlcad_comb, this_assem->brlcad_comb );

    if ( mk_comb( fd_out, this_assem->brlcad_comb, &assem_head.l, 0, NULL, NULL, NULL,
		  0, 0, 0, 0, 0, 0, 0 ) )
	bu_exit( 1, "%s: ERROR: Failed to write combination (%s) to database\n", progname,this_assem->brlcad_comb );
    if ( use_part_name_hash ) {
	if ( db5_update_attribute( this_assem->brlcad_comb, "Part_No",
				   this_assem->obj_name, fd_out->dbip ) ) {
	    bu_log( "Failed to assign Part_no attribute to %s\n",
		    this_assem->brlcad_comb );
	}
    }

    return this_assem;
}
Esempio n. 24
0
struct obj_info *
Part_import( int id_start )
{
    char line[MAX_LINE_SIZE];
    struct obj_info *part;
    struct wmember reg_head;
    unsigned char rgb[3];
    int surf_count=0;
    int id_end;
    int last_surf=0;
    int i;
    int tri[3];
    int corner_index=-1;

    clean_vert_tree( tree_root );

    VSETALL( rgb, 128 );

    BU_ALLOC(part, struct obj_info);
    part->obj_type = PART_TYPE;
    part->obj_id = id_start;
    while ( bu_fgets( line, MAX_LINE_SIZE, fd_in ) ) {
	if ( !bu_strncmp( line, "PartName", 8 ) ) {
	    line[strlen( line ) - 1] = '\0';
	    part->obj_name = bu_strdup( &line[9] );
	    lower_case( part->obj_name );
	    Make_brlcad_names( part );
	} else if ( !bu_strncmp( line, "FaceCount", 9 ) ) {
	    surf_count = atoi( &line[10] );
	    if ( surf_count == 0 ) {
		last_surf = 1;
	    }
	} else if ( !bu_strncmp( line, "EndPartId", 9 ) ) {
	    /* found end of part, check id */
	    id_end = atoi( &line[10] );
	    if ( id_end != id_start )
		bu_exit( 1, "%s: ERROR: found end of part id %d while processing part %d\n", progname,id_end, id_start );
	    if ( last_surf ) {
		break;
	    }
	} else if ( !bu_strncmp( line, "FaceRGB", 7 ) ) {
	    /* get face color */
	    char *ptr;

	    i = 8;
	    ptr = strtok( &line[i], " \t" );
	    for ( i=0; i<3 && ptr; i++ ) {
		rgb[i] = atof( ptr );
		ptr = strtok( (char *)NULL, " \t" );
	    }
	} else if ( !bu_strncmp( line, "Facet", 5 ) ) {
	    /* read a triangle */
	    VSETALL( tri, -1 );
	    corner_index = -1;
	} else if ( !bu_strncmp( line, "Face", 4 ) ) {
	    /* start of a surface */
	    int surf_no;

	    surf_no = atoi( &line[5] );
	    if ( surf_no == surf_count ) {
		last_surf = 1;
	    }
	} else if ( !bu_strncmp( line, "TriangleCount", 13 ) ) {
	    /* get number of triangles for this surface */
	} else if ( !bu_strncmp( line, "Vertices", 9 ) ) {
	    /* get vertex list for this triangle */
	} else if ( !bu_strncmp( line, "Vertex", 6 ) ) {
	    /* get a vertex */
	    char *ptr = NULL;
	    vect_t v = VINIT_ZERO;

	    i = 7;
	    while ( !isspace( (int)line[i] ) && line[i] != '\0' )
		i++;
	    ptr = strtok( &line[i], " \t" );
	    for ( i=0; i<3 && ptr; i++ ) {
		v[i] = atof( ptr );
		ptr = strtok( (char *)NULL, " \t" );
	    }
	    tri[++corner_index] = Add_vert( V3ARGS( v ), tree_root, local_tol_sq );
	    if ( corner_index == 2 ) {
		if ( !bad_triangle( tri, tree_root->the_array ) ) {
		    add_triangle( tri );
		}
	    }
	} else if ( !bu_strncmp( line, "Normal", 6 ) ) {
	    /* get a vertex normal */
	} else if ( !bu_strncmp( line, "PointCount", 10 ) ) {
	    /* get number of vertices for this surface */
	} else
	    bu_exit( 1, "%s: ERROR: unrecognized line encountered while processing part id %d:\n%s\n", progname,id_start, line );
    }

    if ( curr_tri == 0 ) {
	/* no facets in this part, so ignore it */
	bu_free( (char *)part, "part" );
	part = (struct obj_info *)NULL;
    } else {

	/* write this part to database, first make a primitive solid */
	if ( mk_bot( fd_out, part->brlcad_solid, RT_BOT_SOLID, RT_BOT_UNORIENTED, 0,
		     tree_root->curr_vert, curr_tri, tree_root->the_array, part_tris, NULL, NULL ) )
	    bu_exit( 1, "%s: Failed to write primitive %s (%s) to database\n", progname,part->brlcad_solid, part->obj_name );
	if ( verbose ) {
	    DO_INDENT;
	    bu_log( "Wrote BOT %s\n", part->brlcad_solid );
	}

	/* then a region */
	BU_LIST_INIT( &reg_head.l );
	if ( mk_addmember( part->brlcad_solid, &reg_head.l, NULL, WMOP_UNION ) == WMEMBER_NULL )
	    bu_exit( 1, "%s: ERROR: Failed to add solid (%s), to region (%s)\n", progname,part->brlcad_solid, part->brlcad_comb );
	if ( mk_comb( fd_out, part->brlcad_comb, &reg_head.l, 1, NULL, NULL, rgb, ident++,
		      0, 1, 100, 0, 0, 0 ) )
	    bu_exit( 1, "%s: Failed to write region %s (%s) to database\n", progname,part->brlcad_comb, part->obj_name );
	if ( verbose ) {
	    DO_INDENT;
	    bu_log( "Wrote region %s\n", part->brlcad_comb );
	}

	if ( use_part_name_hash ) {
	    if ( db5_update_attribute( part->brlcad_comb, "Part_No",
				       part->obj_name, fd_out->dbip ) ) {
		bu_log( "Failed to assign Part_no attribute to %s\n",
			part->brlcad_comb );
	    }
	}
    }

    /* free some memory */
    if ( part_tris ) {
	bu_free( (char *)part_tris, "part_tris" );
    }
    max_tri = 0;
    curr_tri = 0;
    part_tris = NULL;

    return part;
}
Esempio n. 25
0
void
Pipes(void)
{
    vect_t ht;
    struct points *ptr;
    fastf_t len;
    int comblen;
    struct wmember head;

    BU_LIST_INIT(&head.l);

    ptr = root;
    if ( ptr == NULL )
	return;

    while ( ptr->next != NULL )
    {

	/* Make the basic pipe solids */

	VSUB2( ht, ptr->next->p1, ptr->p2);

	mk_rcc( fdout, ptr->tube, ptr->p2, ht, radius );	/* make a solid record	     */

	if ( !cable ) /* make inside solid */
	    mk_rcc( fdout, ptr->tubflu, ptr->p2, ht, radius-wall );

	if ( torus )
	{
	    /* Make tubing region */
	    mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	   */
	    if ( !cable )
	    {
		/* Subtract inside solid */
		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT );	/* make '-' member record	   */

		/* Make fluid region */
		mk_comb1( fdout, ptr->tubflu_r, ptr->tubflu, 1 );
	    }
	    mk_lfcomb( fdout, ptr->tube_r, &head, 1 );
	}
	else if ( mitre )
	{
	    if ( ptr->prev != NULL )
	    {
		len = VDOT( ptr->p, ptr->mnorm );
		mk_half( fdout, ptr->cut, ptr->mnorm, len );
	    }

	    comblen = 4 - cable;
	    if ( ptr->next->next == NULL )
		comblen--;
	    if ( ptr->prev == NULL )
		comblen--;

	    mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	   */

	    if ( !cable )
		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT );	/* make '-' member record	   */

	    if ( ptr->next->next != NULL )
		mk_addmember( ptr->next->cut, &head.l, NULL, WMOP_SUBTRACT );	/* make '+' member record	   */

	    if ( ptr->prev != NULL )
		mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT );	/* subtract HAF */

	    mk_lfcomb( fdout, ptr->tube_r, &head, 1 );

	    if ( !cable )
	    {
		/* Make fluid region */

		comblen = 3;
		if ( ptr->next->next == NULL )
		    comblen--;
		if ( ptr->prev == NULL )
		    comblen--;

		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	*/

		if ( ptr->next->next != NULL )
		    mk_addmember( ptr->next->cut, &head.l, NULL, WMOP_SUBTRACT );	/* make '+' member record	   */

		if ( ptr->prev != NULL )
		    mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT );	/* subtract */

		mk_lfcomb( fdout, ptr->tubflu_r, &head, 1 );	/* make REGION comb record	*/
	    }
	}
	else if ( sphere )
	{

	    /* make REGION  comb record for tube */
	    comblen = 2;
	    if ( cable )
		comblen--;
	    if ( ptr->next->tube[0] != '\0' )
		comblen++;
	    if ( !cable && ptr->prev != NULL )
		comblen++;

	    /* make 'u' member record	   */

	    mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION );

	    /* make '-' member record	   */
	    if ( !cable )
		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT );

	    if ( ptr->next->tube[0] != '\0' )	/* subtract outside of next tube */
		mk_addmember( ptr->next->tube, &head.l, NULL, WMOP_SUBTRACT );
	    if ( !cable && ptr->prev != NULL ) /* subtract inside of previous tube */
		mk_addmember( ptr->prev->tubflu, &head.l, NULL, WMOP_SUBTRACT );

	    mk_lfcomb( fdout, ptr->tube_r, &head, REGION );

	    if ( !cable )
	    {
		/* make REGION for fluid */

		/* make 'u' member record	*/

		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION );

		if ( ptr->next->tubflu[0] != '\0'  )	/* subtract inside of next tube */
		    mk_addmember( ptr->next->tubflu, &head.l, NULL, WMOP_SUBTRACT );

		mk_lfcomb( fdout, ptr->tubflu_r, &head, REGION );
	    }
	}
	else if ( nothing )
	{

	    /* make REGION  comb record for tube */
	    comblen = 2;
	    if ( cable )
		comblen--;
	    if ( ptr->next->tube[0] != '\0' )
		comblen++;
	    if ( !cable && ptr->prev != NULL )
		comblen++;

	    /* make 'u' member record	   */

	    mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION );

	    /* make '-' member record	   */
	    if ( !cable )
		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT );

	    if ( ptr->next->tube[0] != '\0' )	/* subtract outside of next tube */
		mk_addmember( ptr->next->tube, &head.l, NULL, WMOP_SUBTRACT );
	    if ( !cable && ptr->prev != NULL ) /* subtract inside of previous tube */
		mk_addmember( ptr->prev->tubflu, &head.l, NULL, WMOP_SUBTRACT );

	    mk_lfcomb( fdout, ptr->tube_r, &head, REGION );

	    if ( !cable )
	    {
		/* make REGION for fluid */

		/* make 'u' member record	*/

		mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION );

		if ( ptr->next->tubflu[0] != '\0'  )	/* subtract inside of next tube */
		    mk_addmember( ptr->next->tubflu, &head.l, NULL, WMOP_SUBTRACT );

		mk_lfcomb( fdout, ptr->tubflu_r, &head, REGION );
	    }
	}
	ptr = ptr->next;
    }
}
Esempio n. 26
0
/*
 *
 *	F _ A M T R A C K ( ) :	adds track given "wheel" info
 *
 */
int
f_amtrack(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{

    fastf_t fw[3], lw[3], iw[3], dw[3], tr[3];
    char solname[12], regname[12], grpname[9], oper[3];
    int i, j, memb[4];
    char temp[4];
    vect_t	temp1, temp2;
    int item, mat, los;
    int arg;
    int edit_result;
    struct bu_list head;

    CHECK_DBI_NULL;
    CHECK_READ_ONLY;

    BU_LIST_INIT(&head);

    if (argc < 1 || 27 < argc) {
	struct bu_vls vls;

	bu_vls_init(&vls);
	bu_vls_printf(&vls, "help track");
	Tcl_Eval(interp, bu_vls_addr(&vls));
	bu_vls_free(&vls);
	return TCL_ERROR;
    }

    /* interupts */
    if ( setjmp( jmp_env ) == 0 )
	(void)signal( SIGINT, sig3);  /* allow interupts */
    else
	return TCL_OK;

    oper[0] = oper[2] = WMOP_INTERSECT;
    oper[1] = WMOP_SUBTRACT;

    arg = 1;

    /* get the roadwheel info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the FIRST roadwheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the LAST roadwheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    lw[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( fw[0] <= lw[0] ) {
	Tcl_AppendResult(interp, "First wheel after last wheel - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the roadwheels: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[1] = lw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the roadwheels: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[2] = lw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( fw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	/* get the drive wheel info */
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[0] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( dw[0] >= lw[0] ) {
	Tcl_AppendResult(interp, "DRIVE wheel not in the rear - STOP \n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( dw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    /* get the idler wheel info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[0] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( iw[0] <= fw[0] ) {
	Tcl_AppendResult(interp, "IDLER wheel not in the front - STOP \n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( iw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    /* get track info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Y-MIN of the track: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[2] = tr[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Y-MAX of the track: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[1] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( tr[0] == tr[1] ) {
	Tcl_AppendResult(interp, "MIN == MAX ... STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    if ( tr[0] > tr[1] ) {
	Tcl_AppendResult(interp, "MIN > MAX .... will switch\n", (char *)NULL);
	tr[1] = tr[0];
	tr[0] = tr[2];
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter track thickness: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( tr[2] <= 0 ) {
	Tcl_AppendResult(interp, "Track thickness <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    solname[0] = regname[0] = grpname[0] = 't';
    solname[1] = regname[1] = grpname[1] = 'r';
    solname[2] = regname[2] = grpname[2] = 'a';
    solname[3] = regname[3] = grpname[3] = 'c';
    solname[4] = regname[4] = grpname[4] = 'k';
    solname[5] = regname[5] = '.';
    solname[6] = 's';
    regname[6] = 'r';
    solname[7] = regname[7] = '.';
    grpname[5] = solname[8] = regname[8] = '\0';
    grpname[8] = solname[11] = regname[11] = '\0';
/*
  bu_log("\nX of first road wheel  %10.4f\n", fw[0]);
  bu_log("X of last road wheel   %10.4f\n", lw[0]);
  bu_log("Z of road wheels       %10.4f\n", fw[1]);
  bu_log("radius of road wheels  %10.4f\n", fw[2]);
  bu_log("\nX of drive wheel       %10.4f\n", dw[0]);
  bu_log("Z of drive wheel       %10.4f\n", dw[1]);
  bu_log("radius of drive wheel  %10.4f\n", dw[2]);
  bu_log("\nX of idler wheel       %10.4f\n", iw[0]);
  bu_log("Z of idler wheel       %10.4f\n", iw[1]);
  bu_log("radius of idler wheel  %10.4f\n", iw[2]);
  bu_log("\nY MIN of track         %10.4f\n", tr[0]);
  bu_log("Y MAX of track         %10.4f\n", tr[1]);
  bu_log("thickness of track     %10.4f\n", tr[2]);
*/

/* Check for names to use:
 *	1.  start with track.s.1->10 and track.r.1->10
 *	2.  if bad, increment count by 10 and try again
 */

 tryagain:	/* sent here to try next set of names */

    for (i=0; i<11; i++) {
	crname(solname, i, sizeof(solname));
	crname(regname, i, sizeof(regname));
	if (	(db_lookup( dbip, solname, LOOKUP_QUIET) != DIR_NULL)	||
		(db_lookup( dbip, regname, LOOKUP_QUIET) != DIR_NULL)	) {
	    /* name already exists */
	    solname[8] = regname[8] = '\0';
	    if ( (Trackpos += 10) > 500 ) {
		Tcl_AppendResult(interp, "Track: naming error -- STOP\n",
				 (char *)NULL);
		edit_result = TCL_ERROR;
		goto end;
	    }
	    goto tryagain;
	}
	solname[8] = regname[8] = '\0';
    }

    /* no interupts */
    (void)signal( SIGINT, SIG_IGN );

    /* find the front track slope to the idler */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;

    slope(fw, iw, tr);
    VMOVE(temp2, &sol.s_values[0]);
    crname(solname, 1, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;

    solname[8] = '\0';

    /* find track around idler */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    sol.s_type = ID_TGC;
    trcurve(iw, tr);
    crname(solname, 2, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj( solname, DIR_SOLID ) )
	return TCL_ERROR;
    solname[8] = '\0';
    /* idler dummy rcc */
    sol.s_values[6] = iw[2];
    sol.s_values[11] = iw[2];
    VMOVE(&sol.s_values[12], &sol.s_values[6]);
    VMOVE(&sol.s_values[15], &sol.s_values[9]);
    crname(solname, 3, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj( solname, DIR_SOLID ) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* find idler track dummy arb8 */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    crname(solname, 4, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    crdummy(iw, tr, 1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track slope to drive */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    slope(lw, dw, tr);
    VMOVE(temp1, &sol.s_values[0]);
    crname(solname, 5, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if (wrobj(solname, DIR_SOLID))
	return TCL_ERROR;
    solname[8] = '\0';

    /* track around drive */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    sol.s_type = ID_TGC;
    trcurve(dw, tr);
    crname(solname, 6, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* drive dummy rcc */
    sol.s_values[6] = dw[2];
    sol.s_values[11] = dw[2];
    VMOVE(&sol.s_values[12], &sol.s_values[6]);
    VMOVE(&sol.s_values[15], &sol.s_values[9]);
    crname(solname, 7, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* drive dummy arb8 */
    for (i=0; i<24; i++)
	sol.s_name[i] = 0.0;
    crname(solname, 8, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    crdummy(dw, tr, 2);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track bottom */
    temp1[1] = temp2[1] = tr[0];
    bottom(temp1, temp2, tr);
    crname(solname, 9, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track top */
    temp1[0] = dw[0];
    temp1[1] = temp2[1] = tr[0];
    temp1[2] = dw[1] + dw[2];
    temp2[0] = iw[0];
    temp2[2] = iw[1] + iw[2];
    top(temp1, temp2, tr);
    crname(solname, 10, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* add the regions */
    item = item_default;
    mat = mat_default;
    los = los_default;
    item_default = 500;
    mat_default = 1;
    los_default = 50;
    /* region 1 */
    memb[0] = 1;
    memb[1] = 4;
    crname(regname, 1, sizeof(regname));
    crregion(regname, oper, memb, 2, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 2 */
    crname(regname, 2, sizeof(regname));
    memb[0] = 2;
    memb[1] = 3;
    memb[2] = 4;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 5 */
    crname(regname, 5, sizeof(regname));
    memb[0] = 5;
    memb[1] = 8;
    crregion(regname, oper, memb, 2, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 6 */
    crname(regname, 6, sizeof(regname));
    memb[0] = 6;
    memb[1] = 7;
    memb[2] = 8;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 9 */
    crname(regname, 9, sizeof(regname));
    memb[0] = 9;
    memb[1] = 1;
    memb[2] = 5;
    oper[2] = WMOP_SUBTRACT;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 10 */
    crname(regname, 10, sizeof(regname));
    memb[0] = 10;
    memb[1] = 4;
    memb[2] = 8;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* group all the track regions */
    j = 1;
    if ( (i = Trackpos / 10 + 1) > 9 )
	j = 2;
    itoa(i, temp, j);
    bu_strlcat(grpname, temp, sizeof(grpname));
    for (i=1; i<11; i++) {
	if ( i == 3 || i ==4 || i == 7 || i == 8 )
	    continue;
	regname[8] = '\0';
	crname(regname, i, sizeof(regname));
	if ( db_lookup( dbip, regname, LOOKUP_QUIET) == DIR_NULL ) {
	    Tcl_AppendResult(interp, "group: ", grpname, " will skip member: ",
			     regname, "\n", (char *)NULL);
	    continue;
	}
	mk_addmember( regname, &head, NULL, WMOP_UNION );
    }

    /* Add them all at once */
    if ( mk_comb( wdbp, grpname, &head,
		  0, NULL, NULL, NULL,
		  0, 0, 0, 0,
		  0, 1, 1 ) < 0 )
    {
	Tcl_AppendResult(interp,
			 "An error has occured while adding '",
			 grpname, "' to the database.\n", (char *)NULL);
    }

    /* draw this track */
    Tcl_AppendResult(interp, "The track regions are in group ", grpname,
		     "\n", (char *)NULL);
    {
	const char *arglist[3];
	arglist[0] = "e";
	arglist[1] = grpname;
	arglist[2] = NULL;
	edit_result = cmd_draw( clientData, interp, 2, arglist );
    }

    Trackpos += 10;
    item_default = item;
    mat_default = mat;
    los_default = los;
    grpname[5] = solname[8] = regname[8] = '\0';

    return edit_result;
 end:
    (void)signal( SIGINT, SIG_IGN );
    return edit_result;
}
void
Do_subfigs()
{
    int i, j;
    int entity_type;
    struct wmember head1;
    struct wmember *wmem;

    if (RT_G_DEBUG & DEBUG_MEM_FULL)
	bu_mem_barriercheck();

    BU_LIST_INIT(&head1.l);

    for (i = 0; i < totentities; i++) {
	int subfigdef_de;
	int subfigdef_index;
	int no_of_members;
	int *members;
	char *name = NULL;
	struct wmember head2;
	double mat_scale[3];
	int non_unit;

	if (dir[i]->type != 408)
	    continue;

	if (RT_G_DEBUG & DEBUG_MEM_FULL)
	    bu_mem_barriercheck();

	if (dir[i]->param <= pstart) {
	    bu_log("Illegal parameter pointer for entity D%07d (%s)\n" ,
		   dir[i]->direct, dir[i]->name);
	    continue;
	}

	Readrec(dir[i]->param);
	Readint(&entity_type, "");
	if (entity_type != 408) {
	    bu_log("Expected Singular Subfigure Instance Entity, found %s\n",
		   iges_type(entity_type));
	    continue;
	}

	Readint(&subfigdef_de, "");
	subfigdef_index = (subfigdef_de - 1)/2;
	if (subfigdef_index >= totentities) {
	    bu_log("Singular Subfigure Instance Entity gives Subfigure Definition");
	    bu_log("\tEntity DE of %d, largest DE in file is %d\n",
		   subfigdef_de, (totentities * 2) - 1);
	    continue;
	}
	if (dir[subfigdef_index]->type != 308) {
	    bu_log("Expected Subfigure Definition Entity, found %s\n",
		   iges_type(dir[subfigdef_index]->type));
	    continue;
	}

	if (dir[subfigdef_index]->param <= pstart) {
	    bu_log("Illegal parameter pointer for entity D%07d (%s)\n" ,
		   dir[subfigdef_index]->direct, dir[subfigdef_index]->name);
	    continue;
	}
	Readrec(dir[subfigdef_index]->param);
	Readint(&entity_type, "");
	if (entity_type != 308) {
	    bu_log("Expected Subfigure Definition Entity, found %s\n",
		   iges_type(entity_type));
	    continue;
	}

	Readint(&j, "");	/* ignore depth */
	Readstrg("");		/* ignore subfigure name */

	wmem = mk_addmember(dir[subfigdef_index]->name, &head1.l, NULL, WMOP_UNION);
	non_unit = 0;
	for (j = 0; j < 3; j++) {
	    double mag_sq;

	    mat_scale[j] = 1.0;
	    mag_sq = MAGSQ(&(*dir[i]->rot)[j*4]);

	    /* FIXME: arbitrary undefined tolerance */
	    if (!NEAR_EQUAL(mag_sq, 1.0, 100.0*SQRT_SMALL_FASTF)) {
		mat_scale[j] = 1.0/sqrt(mag_sq);
		non_unit = 1;
	    }
	}

	if (non_unit) {
	    bu_log("Illegal transformation matrix in %s for member %s\n",
		   curr_file->obj_name, wmem->wm_name);
	    bu_log(" row vector magnitudes are %g, %g, and %g\n",
		   1.0/mat_scale[0], 1.0/mat_scale[1], 1.0/mat_scale[2]);
	    bn_mat_print("", *dir[i]->rot);
	    for (j = 0; j < 11; j++) {
		if ((j+1)%4 == 0)
		    continue;
		(*dir[i]->rot)[j] *= mat_scale[0];
	    }
	    bn_mat_print("After scaling:", *dir[i]->rot);

	}
	memcpy(wmem->wm_mat, *dir[i]->rot, sizeof(mat_t));

	Readint(&no_of_members, "");	/* get number of members */
	members = (int *)bu_calloc(no_of_members, sizeof(int), "Do_subfigs: members");
	for (j = 0; j < no_of_members; j++)
	    Readint(&members[j], "");

	BU_LIST_INIT(&head2.l);
	for (j = 0; j < no_of_members; j++) {
	    int idx;

	    idx = (members[j] - 1)/2;

	    if (idx >= totentities) {
		bu_log("Subfigure Definition Entity gives Member Entity");
		bu_log("\tDE of %d, largest DE in file is %d\n",
		       members[j], (totentities * 2) - 1);
		continue;
	    }
	    if (dir[idx]->param <= pstart) {
		bu_log("Illegal parameter pointer for entity D%07d (%s)\n" ,
		       dir[idx]->direct, dir[idx]->name);
		continue;
	    }

	    if (dir[idx]->type == 416) {
		struct file_list *list_ptr;
		char *file_name;
		int found = 0;

		/* external reference */

		Readrec(dir[idx]->param);
		Readint(&entity_type, "");

		if (entity_type != 416) {
		    bu_log("Expected External reference Entity, found %s\n",
			   iges_type(entity_type));
		    continue;
		}

		if (dir[idx]->form != 1) {
		    bu_log("External Reference Entity of form #%d found\n",
			   dir[idx]->form);
		    bu_log("\tOnly form #1 is currently handled\n");
		    continue;
		}

		Readname(&file_name, "");

		/* Check if this external reference is already on the list */
		for (BU_LIST_FOR(list_ptr, file_list, &iges_list.l)) {
		    if (BU_STR_EQUAL(file_name, list_ptr->file_name)) {
			found = 1;
			name = list_ptr->obj_name;
			break;
		    }
		}

		if (!found) {
		    /* Need to add this one to the list */
		    BU_ALLOC(list_ptr, struct file_list);

		    list_ptr->file_name = file_name;
		    if (no_of_members == 1)
			bu_strlcpy(list_ptr->obj_name, dir[subfigdef_index]->name, NAMESIZE+1);
		    else {
			bu_strlcpy(list_ptr->obj_name, "subfig", NAMESIZE+1);
			(void) Make_unique_brl_name(list_ptr->obj_name);
		    }


		    BU_LIST_APPEND(&curr_file->l, &list_ptr->l);

		    name = list_ptr->obj_name;
		} else
		    bu_free((char *)file_name, "Do_subfigs: file_name");

	    } else
		name = dir[idx]->name;

	    if (no_of_members > 1) {
		wmem = mk_addmember(name, &head2.l, NULL, WMOP_UNION);
		memcpy(wmem->wm_mat, dir[idx]->rot, sizeof(mat_t));
	    }
	}

	if (no_of_members > 1)
	    (void)mk_lcomb(fdout, dir[subfigdef_index]->name, &head2, 0,
			   (char *)NULL, (char *)NULL, (unsigned char *)NULL, 0);
    }
Esempio n. 28
0
int
main(int argc, char **argv)
{
    vect_t	norm;
    unsigned char	rgb[3];
    int	ix;
    double	x;
    double	size;
    int	quant;
    struct wmember head;
    vect_t	bmin, bmax, bthick;
    vect_t	r1min, r1max, r1thick;
    vect_t	lwh;		/* length, width, height */
    vect_t	pbase;

    BU_LIST_INIT( &head.l );

    MAT_IDN( identity );
    sin60 = sin(60.0 * 3.14159265358979323846264 / 180.0);

    outfp = wdb_fopen("room.g");
    mk_id( outfp, "Procedural Rooms" );

    /* Create the building */
    VSET( bmin, 0, 0, 0 );
    VSET( bmax, 80000, 60000, HEIGHT );
    VSET( bthick, 100, 100, 100 );
    make_room( "bldg", bmin, bmax, bthick, &head );

    /* Create the first room */
    VSET( r1thick, 100, 100, 0 );
    VMOVE( r1min, bmin );
    VSET( r1max, 40000, 10000, HEIGHT );
    VADD2( r1max, r1min, r1max );
    make_walls( "rm1", r1min, r1max, r1thick, NORTH|EAST, &head );
    make_carpet( "rm1carpet", r1min, r1max, "carpet.pix", &head );

    /* Create the golden earth */
    VSET( norm, 0, 0, 1 );
    mk_half( outfp, "plane", norm, -bthick[Z]-10.0 );
    rgb[0] = 240;	/* gold/brown */
    rgb[1] = 180;
    rgb[2] = 64;
    mk_region1( outfp, "plane.r", "plane", NULL, NULL, rgb );
    (void)mk_addmember( "plane.r", &head.l, NULL, WMOP_UNION );

    /* Create the display pillars */
    size = 4000;	/* separation between centers */
    quant = 5;	/* pairs */
    VSET( lwh, 400, 400, 1000 );
    for ( ix=quant-1; ix>=0; ix-- )  {
	x = 10000 + ix*size;
	VSET( pbase, x, 10000*.25, r1min[Z] );
	make_pillar( "Pil", ix, 0, pbase, lwh, &head );
	VSET( pbase, x, 10000*.75, r1min[Z] );
	make_pillar( "Pil", ix, 1, pbase, lwh, &head );
    }

#ifdef never
    /* Create some light */
    white[0] = white[1] = white[2] = 255;
    base = size*(quant/2+1);
    VSET( aim, 0, 0, 0 );
    VSET( pos, base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l1", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l2", pos, aim, 1, 100.0, white, &head );
    VSET( pos, -base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l3", pos, aim, 1, 100.0, white, &head );
    VSET( pos, base, -base, minheight+maxheight*bn_rand0to1(randp) );
    do_light( "l4", pos, aim, 1, 100.0, white, &head );
#endif

    /* Build the overall combination */
    mk_lfcomb( outfp, "room", &head, 0 );

    return 0;
}
Esempio n. 29
0
void
Elbows(void)	/* make a tubing elbow and fluid elbow */
{
    vect_t RN1, RN2;
    point_t pts[8];
    fastf_t len;
    struct points *ptr;
    struct wmember head;

    if ( nothing || mitre )
	return;

    if ( root == NULL )
	return;

    BU_LIST_INIT(&head.l);

    ptr = root->next;
    while ( ptr->next != NULL )
    {

	/* Make outside elbow solid */
	if ( torus )
	    mk_tor( fdout, ptr->elbow, ptr->center, ptr->norm, ( MINR+1 )*radius, radius );
	else if ( sphere )
	    mk_sph( fdout, ptr->elbow, ptr->p, radius );

	if ( !cable ) /* Make inside elbow solid */
	{
	    if ( torus )
		mk_tor( fdout, ptr->elbflu, ptr->center, ptr->norm, ( MINR+1 )*radius, radius-wall );
	    else if ( sphere )
		mk_sph( fdout, ptr->elbflu, ptr->p, radius-wall );
	}

	if ( torus )	/* Make ARB8 solid */
	{
	    len = ((MINR+2)*radius + delta) / cos( (pi-ptr->alpha)/4.0 );
	    /* vector from center of torus to rcc end */
	    VSUB2( RN1, ptr->p1, ptr->center );
	    VUNITIZE( RN1 );		/* unit vector */
	    /* beginning of next rcc */
	    VSUB2( RN2, ptr->p2, ptr->center );
	    VUNITIZE( RN2 );		/* and unitize again */

	    /* build the eight points for the ARB8 */

	    VJOIN1( pts[0], ptr->center, radius+delta, ptr->norm );
	    VJOIN1( pts[1], pts[0], len, RN1 );
	    VJOIN1( pts[2], pts[0], -len, ptr->nmitre );
	    VJOIN1( pts[3], pts[0], len, RN2 );
	    VJOIN1( pts[4], ptr->center, -radius-delta, ptr->norm );
	    VJOIN1( pts[5], pts[4], len, RN1 );
	    VJOIN1( pts[6], pts[4], -len, ptr->nmitre );
	    VJOIN1( pts[7], pts[4], len, RN2 );

	    mk_arb8( fdout, ptr->cut, &pts[0][X] );
	}

	if ( torus )
	{
	    mk_addmember( ptr->elbow, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	   */
	    if ( !cable )
		mk_addmember(  ptr->elbflu, &head.l, NULL, WMOP_SUBTRACT );	/* make '-' member record	   */
	    mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT );
	    mk_lfcomb( fdout, ptr->elbow_r, &head, REGION );	/* make REGION  comb record	   */

	    if ( !cable )
	    {
		mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	*/
		mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT );
		mk_lfcomb( fdout, ptr->elbflu_r, &head, REGION );		/* make REGION comb record	*/
	    }
	}
	else if ( sphere )
	{
	    mk_addmember( ptr->elbow, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	   */
	    if ( !cable )
		mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_SUBTRACT );	/* make '-' member record	   */
	    mk_addmember( ptr->tube, &head.l, NULL, WMOP_SUBTRACT );
	    mk_addmember( ptr->prev->tube, &head.l, NULL, WMOP_SUBTRACT );

	    mk_lfcomb( fdout, ptr->elbow_r, &head, REGION );	/* make REGION  comb record	   */

	    if ( !cable )
	    {
		mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	*/
		mk_addmember( ptr->tube, &head.l, NULL, WMOP_SUBTRACT );
		mk_addmember( ptr->prev->tube, &head.l, NULL, WMOP_SUBTRACT );
		mk_lfcomb( fdout, ptr->elbflu_r, &head, REGION );		/* make REGION comb record	*/
	    }
	}
	ptr = ptr->next;
    }
}
Esempio n. 30
0
void
Groups(void)
{
    struct points *ptr;
    char tag[NAMESIZE];
    char *pipe_group=".pipe";
    char *fluid_group=".fluid";
    int comblen=0;
    struct wmember	head;

    BU_LIST_INIT(&head.l);

    ptr = root;
    if ( ptr == NULL )
	return;

    while ( ptr->next != NULL )
    {
	if ( !nothing && !mitre && comblen)	/* count elbow sections (except first point) */
	    comblen++;
	comblen++;	/* count pipe sections */

	ptr = ptr->next;
    }

    if ( comblen )
    {

	/* Make name for pipe group = "name".pipe */
	Make_name( tag, pipe_group, name, 0 );

	/* Make group */
	ptr = root;
	while ( ptr->next != NULL )
	{
	    mk_addmember( ptr->tube_r, &head.l, NULL, WMOP_UNION );	/* tube regions */

	    if ( !nothing && !mitre && ptr != root )
		mk_addmember( ptr->elbow_r, &head.l, NULL, WMOP_UNION );	/* elbows */

	    ptr = ptr->next;
	}
	mk_lfcomb( fdout, tag, &head, 0 );

	if ( !cable )
	{
	    /* Make name for fluid group = "name".fluid */
	    Make_name( tag, fluid_group, name, 0 );

	    /* Make group */
	    ptr = root;
	    while ( ptr->next != NULL )
	    {
		mk_addmember( ptr->tubflu_r, &head.l, NULL, WMOP_UNION );	/* fluid in tubes */

		if ( !nothing && !mitre && ptr != root )
		    mk_addmember( ptr->elbflu_r, &head.l, NULL, WMOP_UNION ); /* fluid in elbows */

		ptr = ptr->next;
	    }
	    mk_lfcomb( fdout, tag, &head, 0 );
	}
    }
}