Exemplo n.º 1
0
int main(int argc, char **argv)
{
    FILE *fpin;
    struct rt_wdb *fpout;

    bu_setprogname(argv[0]);

    tol.magic = BN_TOL_MAGIC;	/* Copied from proc-db/nmgmodel.c */
    tol.dist = 0.01;
    tol.dist_sq = 0.01 * 0.01;
    tol.perp = 0.001;
    tol.para = 0.999;

    /* Get filenames and open the files. */
    if (argc != 3)  {
	bu_exit(2, "Usage: off-g file.off file.g\n");
    }
    if ((fpin = fopen(argv[1], "r")) == NULL) {
	bu_exit(1, "%s: cannot open %s for reading\n",
		argv[0], argv[1]);
    }
    if ((fpout = wdb_fopen(argv[2])) == NULL) {
	bu_exit(1, "%s: cannot create %s\n",
		argv[0], argv[2]);
    }


    off2nmg(fpin, fpout);

    fclose(fpin);
    wdb_close(fpout);

    return 0;
}
Exemplo n.º 2
0
/*
 * Call parse_args to handle command line arguments first, then
 * process input.
 */
int
main(int ac, char *av[])
{
    struct bn_tol tol;
    FILE *fdplot;
    struct rt_wdb *fdmodel;

    parse_args(ac, av);
    if (ac==1) usage((char *)NULL,0);
    if (!manifold[0] && !manifold[1] && !manifold[2] && !manifold[3])
	usage("No manifolds selected\n",1);


    m = nmg_mm();
    r = nmg_mrsv(m);
    s = BU_LIST_FIRST(shell, &r->s_hd);

    tol.magic = BN_TOL_MAGIC;
    tol.dist = 0.01;
    tol.dist_sq = tol.dist * tol.dist;
    tol.perp = 0.001;
    tol.para = 0.999;

    if (manifold[3]) make_3manifold_bits(&tol);
    if (manifold[2]) make_2manifold_bits(&tol);
    if (manifold[1]) make_1manifold_bits();
    if (manifold[0]) make_0manifold_bits();

    NMG_CK_MODEL(m);

    /* write a plot file */
    if ((fdplot = fopen(plotfilename, "w")) == (FILE *)NULL)
	perror(plotfilename);
    else {
	nmg_pl_m(fdplot, m);
	fclose(fdplot);
    }

    /* write the database */
    if ((fdmodel = wdb_fopen(mfilename)) == NULL)
	perror(mfilename);
    else {
	mk_id(fdmodel, "hairy NMG");
	mk_nmg(fdmodel, "s.NMG",  m); /* releases m, boo */

	/* build a database region mentioning the solid */
	mk_comb1(fdmodel, "r.NMG", "s.NMG", 1);

	wdb_close(fdmodel);
    }


    return 0;
}
Exemplo n.º 3
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;
}
/*
 *	Get ascii input file and output file names.
 */
int
main(int argc, char **argv)
{
    char		*afile = "-", *bfile = "nmg.g";
    FILE		*fpin;
    struct rt_wdb	*fpout;

    if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) {
	usage();
	bu_exit(1, NULL);
    }

    if (isatty(fileno(stdin)) && isatty(fileno(stdout)) && argc == 1) {
	usage();
	bu_log("       Program continues running:\n");
    }

    bu_setprogname(argv[0]);

    /* Get ascii NMG input file name. */
    if (bu_optind >= argc || (int)(*argv[1]) == '-') {
	fpin = stdin;
	setmode(fileno(fpin), O_BINARY);
	bu_log("%s: will be reading from stdin\n",argv[0]);
    } else {
	afile = argv[bu_optind];
	if ((fpin = fopen(afile, "rb")) == NULL) {
	    fprintf(stderr,
		    "%s: cannot open %s for reading\n",
		    argv[0], afile);
	    bu_exit(1, NULL);
	}
    bu_log("%s: will be reading from file %s\n",argv[0],afile);
    }

    /* Get BRL-CAD output data base name. */
    bu_optind++;
    if (bu_optind < argc)
	bfile = argv[bu_optind];
    if ((fpout = wdb_fopen(bfile)) == NULL) {
	fprintf(stderr, "%s: cannot open %s for writing\n",
		argv[0], bfile);
	bu_exit(1, NULL);
    }
    bu_log("%s: will be creating file %s\n",argv[0],bfile);

    ascii_to_brlcad(fpin, fpout, "nmg", NULL);
    fclose(fpin);
    wdb_close(fpout);
    return 0;
}
Exemplo n.º 5
0
/**
 * main driver logic that creates the various random metaballs and
 * then creates another that combines them all into one.
 */
static void
make_spaghetti(const char *filename, const char *name, long count)
{
    const char *balls[4] = {"someballs.s", "moreballs.s", "manyballs.s", NULL};
    const char title[BUFSIZ] = "metaball";
    struct rt_wdb *fp;
    struct db_i *dbip;

    long some, more, many;

    /* get a write-only handle */
    fp = wdb_fopen(filename);
    if (fp == RT_WDB_NULL)
	bu_exit(EXIT_FAILURE, "ERROR: unable to open file for writing.\n");

    mk_id(fp, title);

    /* just to make things interesting, make varying sized sets */
    some = lrint(ceil((double)count * (1.0 / 111.0)));
    more = lrint(ceil((double)count * (10.0 / 111.0)));
    many = lrint(ceil((double)count * (100.0 / 111.0)));

    /* create individual metaballs with random points using LIBWDB */
    make_meatballs(fp, balls[0], some);
    make_meatballs(fp, balls[1], more);
    make_meatballs(fp, balls[2], many);

    mk_comb1(fp, "someballs.r", balls[0], 1);
    mk_comb1(fp, "moreballs.r", balls[1], 1);
    mk_comb1(fp, "manyballs.r", balls[2], 1);
    mk_comb1(fp, "meatballs.r", "meatballs.s", 1);

    wdb_close(fp);

    /* done with the write-only, now begins read/write */
    dbip = db_open(filename, DB_OPEN_READWRITE);
    if (dbip == DBI_NULL) {
	perror("ERROR");
	bu_exit(EXIT_FAILURE, "Failed to open geometry file [%s].  Aborting.\n", filename);
    }

    /* load a database directory */
    db_dirbuild(dbip);

    /* combine all metaballs into one "mega metaball" */
    mix_balls(dbip, name, 3, balls);

    /* and clean up */
    db_close(dbip);
}
Exemplo n.º 6
0
bool
BRLCADWrapper::Close()
{

    if (outfp) {
	wdb_close(outfp);
	outfp = NULL;
    }
    if (dbip) {
	db_close(dbip);
	dbip = NULL;
    }

    return true;
}
Exemplo n.º 7
0
int
main(int argc, char** argv)
{
    struct rt_wdb* outfp;
    ON_Brep* brep;
    ON_TextLog error_log;
    const char* id_name = "B-Rep Example";
    const char* geom_name = "cube.s";

    ON::Begin();

    if (argc > 1) {
	printf("Writing a twisted cube b-rep...\n");
	outfp = wdb_fopen("brep_cube1.g");
	mk_id(outfp, id_name);
	brep = MakeTwistedCube(error_log);
	mk_brep(outfp, geom_name, brep);

	//mk_comb1(outfp, "cube.r", geom_name, 1);
	unsigned char rgb[] = {255,255,255};
	mk_region1(outfp, "cube.r", geom_name, "plastic", "", rgb);

	wdb_close(outfp);
	delete brep;
    }

    printf("Reading a twisted cube b-rep...\n");
    struct db_i* dbip = db_open("brep_cube1.g", "r");
    db_dirbuild(dbip);
    struct directory* dirp;
    if ((dirp = db_lookup(dbip, "cube.s", 0)) != DIR_NULL) {
	printf("\tfound cube.s\n");
	struct rt_db_internal ip;
	mat_t mat;
	MAT_IDN(mat);
	if (rt_db_get_internal(&ip, dirp, dbip, mat, &rt_uniresource) >= 0) {
	    printPoints((struct rt_brep_internal*)ip.idb_ptr);
	} else {
	    fprintf(stderr, "problem getting internal object rep\n");
	}
    }
    db_close(dbip);

    ON::End();

    return 0;
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{

    if (argc != 2) {
	fputs(usage, stderr);
	return 1;
    }

    BU_LIST_INIT(&head.l);
    outfp = wdb_fopen("molecule.g");
    mk_id(outfp, argv[1]);
    read_data();

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

    wdb_close(outfp);
    return 0;
}
Exemplo n.º 9
0
int
ged_dump(struct ged *gedp, int argc, const char *argv[])
{
    struct rt_wdb *op;
    int ret;
    static const char *usage = "file.g";

    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);

    /* initialize result */
    bu_vls_trunc(gedp->ged_result_str, 0);

    /* must be wanting help */
    if (argc == 1) {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
	return GED_HELP;
    }

    if (argc != 2) {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage);
	return GED_ERROR;
    }

    if ((op = wdb_fopen(argv[1])) == RT_WDB_NULL) {
	bu_vls_printf(gedp->ged_result_str, "dump: %s: cannot create", argv[1]);
	return GED_ERROR;
    }

    ret = db_dump(op, gedp->ged_wdbp->dbip);
    wdb_close(op);

    if (ret < 0) {
	bu_vls_printf(gedp->ged_result_str, "dump: %s: db_dump() error", argv[1]);
	return GED_ERROR;
    }

    return GED_OK;
}
Exemplo n.º 10
0
int
main(int argc, char** argv)
{
    struct rt_wdb* outfp;
    ON_Brep* brep;
    ON_TextLog error_log;
    ON_3dPoint origin(0.0,0.0,0.0);
    const char* id_name = "B-Rep Cobb Sphere";
    const char* geom_name = "cobb.s";

    if (argc > 1 || BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) {
	return 0;
    }

    ON::Begin();

    /* export brep to file */
    bu_log("Writing a Cobb unit sphere b-rep...\n");
    outfp = wdb_fopen("brep_cobb.g");
    mk_id(outfp, id_name);


    brep = Cobb_Sphere(1, &origin);
    mk_brep(outfp, geom_name, brep);

    //mk_comb1(outfp, "cube.r", geom_name, 1);
    unsigned char rgb[] = {50, 255, 50};
    mk_region1(outfp, "cobb.r", geom_name, "plastic", "", rgb);

    wdb_close(outfp);
    delete brep;

    ON::End();

    return 0;
}
Exemplo n.º 11
0
int
main(int argc, char **argv)
{
    struct rt_wdb	*fp;
    struct db_i	*dbip;
    struct directory	*dp;
    long	errors = 0;
    struct bn_tol tol;
    char name[17];

    bu_setprogname(argv[0]);

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

    bu_debug = BU_DEBUG_COREDUMP;

    rt_init_resource( &rt_uniresource, 0, NULL );

    if ( argc != 3 )  {
	fprintf(stderr, "Usage: %s v4.g v5.g\n", argv[0]);
	return 1;
    }

    if ( (dbip = db_open(argv[1], DB_OPEN_READONLY)) == DBI_NULL )  {
	perror( argv[1] );
	return 2;
    }

    if ( (fp = wdb_fopen( argv[2] )) == NULL )  {
	perror( argv[2] );
	return 3;
    }

    if ( db_version(dbip) != 4 ) {
	bu_log( "Input database must be a version 4 database!!!!\n" );
	return 4;
    }

    RT_CK_DBI(dbip);
    if ( db_dirbuild( dbip ) )
	bu_exit(1, "db_dirbuild failed\n" );

    db_update_ident( fp->dbip, dbip->dbi_title, dbip->dbi_local2base );

    /* Retrieve every item in the input database */
    FOR_ALL_DIRECTORY_START(dp, dbip)  {
	struct rt_db_internal	intern;
	int id;
	int ret;

	fprintf(stderr, "%.16s\n", dp->d_namep );

	id = rt_db_get_internal( &intern, dp, dbip, NULL, &rt_uniresource );
	if ( id < 0 )  {
	    fprintf(stderr,
		    "%s: rt_db_get_internal(%s) failure, skipping\n",
		    argv[0], dp->d_namep);
	    errors++;
	    continue;
	}
	if ( id == ID_COMBINATION ) {
	    struct rt_comb_internal *comb;
	    char *ptr;

	    comb = (struct rt_comb_internal *)intern.idb_ptr;
	    RT_CK_COMB( comb );

	    /* Convert "plastic" to "phong" in the shader string */
	    while ( (ptr=strstr( bu_vls_addr( &comb->shader), "plastic" )) != NULL ) {
		ptr[0] = 'p'; /* p */
		ptr[1] = 'h'; /* l */
		ptr[2] = 'o'; /* a */
		ptr[3] = 'n'; /* s */
		ptr[4] = 'g'; /* t */
		ptr[5] = ' '; /* i */
		ptr[6] = ' '; /* c */
	    }
	}
	if ( id == ID_HF ) {
	    if (rt_hf_to_dsp( &intern )) {
		fprintf(stderr,
			"%s: Conversion from HF to DSP failed for solid %s\n",
			argv[0], dp->d_namep );
		errors++;
		continue;
	    }
	}
	if ( id == ID_POLY)
	{
	    if ( rt_pg_to_bot( &intern, &tol, &rt_uniresource ) )
	    {
		fprintf( stderr, "%s: Conversion from polysolid to BOT failed for solid %s\n",
			 argv[0], dp->d_namep );
		errors++;
		continue;
	    }
	}

	/* to insure null termination */
	bu_strlcpy( name, dp->d_namep, sizeof(name) );
	ret = wdb_put_internal( fp, name, &intern, 1.0 );
	if ( ret < 0 )  {
	    fprintf(stderr,
		    "%s: wdb_put_internal(%s) failure, skipping\n",
		    argv[0], dp->d_namep);
	    rt_db_free_internal(&intern);
	    errors++;
	    continue;
	}
	rt_db_free_internal(&intern);
    } FOR_ALL_DIRECTORY_END

	  wdb_close( fp );
    db_close( dbip );

    fprintf(stderr, "%ld objects failed to convert\n", errors);
    return 0;
}
Exemplo n.º 12
0
int
main(int argc, char *argv[])
{
    struct rt_wdb *wdbp = NULL;
    const char *name = "brep";
    ON_Brep *brep = NULL;
    int ret;

    if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) {
    	printusage();
    	return 0;
    }
    if (argc >= 1) {
    	printusage();
    	fprintf(stderr,"       Program continues running (will create file breplicator.g):\n");
    }

    bu_log("Breplicating...please wait...\n");

    ON_3dPoint points[8] = {
	/* left */
	ON_3dPoint(0.0, 0.0, 0.0), // 0
	ON_3dPoint(1.0, 0.0, 0.0), // 1
	ON_3dPoint(1.0, 0.0, 2.5), // 2
	ON_3dPoint(0.0, 0.0, 2.5), // 3
	/* right */
	ON_3dPoint(0.0, 1.0, 0.0), // 4
	ON_3dPoint(1.0, 1.0, 0.0), // 5
	ON_3dPoint(1.0, 1.0, 2.5), // 6
	ON_3dPoint(0.0, 1.0, 2.5), // 7
    };

    brep = generate_brep(8, points);
    if (!brep)
	bu_exit(1, "ERROR: We don't have a BREP\n");

    ON_TextLog log(stdout);

    brep->Dump(log);

    if (!brep->IsValid(&log)) {
	delete brep;
	bu_exit(1, "ERROR: We don't have a valid BREP\n");
    }

    brep->Dump(log);

    wdbp = wdb_fopen("breplicator.g");
    if (!wdbp) {
	delete brep;
	bu_exit(2, "ERROR: Unable to open breplicator.g\n");
    }
    mk_id(wdbp, "Breplicator test geometry");

    bu_log("Creating the BREP as BRL-CAD geometry\n");
    ret = mk_brep(wdbp, name, brep);
    if (ret) {
	delete brep;
	wdb_close(wdbp);
	bu_exit(3, "ERROR: Unable to export %s\n", name);
    }

    bu_log("Done.\n");

    delete brep;
    wdb_close(wdbp);

    return 0;
}
Exemplo n.º 13
0
int
main(int argc, char **argv) 			/* really has no arguments */

{
    struct nmgregion *r;
    char * id_name = "BRL-CAD t-NURBS NMG Example";
    char * tea_name = "UtahTeapot";
    char * uplot_name = "teapot.pl";
    struct bu_list vhead;
    FILE *fp;
    int i;

    tol.magic = BN_TOL_MAGIC;
    tol.dist = 0.005;
    tol.dist_sq = tol.dist * tol.dist;
    tol.perp = 1e-6;
    tol.para = 1 - tol.perp;

    BU_LIST_INIT( &rt_g.rtg_vlfree );

    outfp = wdb_fopen( "tea_nmg.g" );

    rt_g.debug |= DEBUG_ALLRAYS;	/* Cause core dumps on bu_bomb(), but no extra messages */

    while ((i=bu_getopt(argc, argv, "d")) != EOF) {
        switch (i) {
        case 'd' :
            rt_g.debug |= DEBUG_MEM | DEBUG_MEM_FULL;
            break;
        default	:
            (void)fprintf(stderr,
                          "Usage: %s [-d] > database.g\n", *argv);
            return(-1);
        }
    }

    mk_id( outfp, id_name);

    m = nmg_mm();
    NMG_CK_MODEL( m );
    r = nmg_mrsv( m );
    NMG_CK_REGION( r );
    s = BU_LIST_FIRST( shell, &r->s_hd );
    NMG_CK_SHELL( s );

    /* Step through each patch and create a NMG TNURB face
     * representing the patch then dump them out.
     */

    for ( i = 0; i < PATCH_COUNT; i++)
    {
        dump_patch( patches[i] );
    }

    /* Connect up the coincident vertexuses and edges */
    (void)nmg_model_fuse( m, &tol );

    /* write NMG to output file */
    (void)mk_nmg( outfp, tea_name, m );
    wdb_close(outfp);

    /* Make a vlist drawing of the model */
    BU_LIST_INIT( &vhead );
    nmg_m_to_vlist( &vhead, m, 0 );

    /* Make a UNIX plot file from this vlist */
    if ( (fp=fopen( uplot_name, "w" )) == NULL )
    {
        bu_log( "Cannot open plot file: %s\n", uplot_name );
        perror( "teapot_nmg" );
    }
    else
        rt_vlist_to_uplot( fp, &vhead );

    return(0);
}
Exemplo n.º 14
0
/**
 *	P O P _ S P A W N --- spawn a new population
 *	TODO: generalize/modularize somehow to allow adding more shapes and primitives
 *	also use variable/defined rates, intersection with bounding box, etc...
 */
void
pop_spawn (struct population *p)
{
    int i, j;
    point_t p1/*, p2, p3*/;
    struct wmember wm_hd;
    double r1/*, r2, r3*/;

    char shape[256];

    p->db_p = db_create("gen000", 5);
    p->db_p->dbi_wdbp = wdb_dbopen(p->db_p, RT_WDB_TYPE_DB_DISK);

    for (i = 0; i < p->size; i++) {
	p->name[i] = bu_malloc(sizeof(char) * 256, "name");
	snprintf(p->name[i], 256, "ind%.3d", i);

	BU_LIST_INIT(&wm_hd.l);
	/*
	  VSET(p1, -5, -5, -5);
	  VSET(p2, 5, 5, 5);
	  r1 = r2 = 2.5;
	*/
	for (j = 0; j < 6; j++) {
	    /* VSETALL(p1, -10+pop_rand()*10); */
	    p1[0] = -10*pop_rand()*10;
	    p1[1] = -10*pop_rand()*10;
	    p1[2] = -10*pop_rand()*10;
	    r1 = 1+3*pop_rand();
	    snprintf(shape, 256, "ind%.3d-%.3d", i, j);
	    mk_sph(p->db_p->dbi_wdbp, shape, p1, r1);
	    mk_addmember(shape, &wm_hd.l, NULL, WMOP_UNION);
	}


	p->parent[i].fitness = 0.0;
	p->parent[i].id = i;
	/*

	snprintf(shape, 256, "ind%.3d-%.3d", i, 0);
	mk_sph(p->db_p->dbi_wdbp, shape, p1, r1);
	mk_addmember(shape, &wm_hd.l, NULL, WMOP_UNION);


	snprintf(shape, 256, "ind%.3d-%.3d", i, 1);
	mk_sph(p->db_p->dbi_wdbp, shape, p2, r2);
	mk_addmember(shape, &wm_hd.l, NULL, WMOP_UNION);

	snprintf(shape, 256, "gen%.3dind%.3d-%.3d", 0, i, 2);
	mk_sph(p->db_p->dbi_wdbp, shape, p3, r3);
	mk_addmember(shape, &wm_hd.l, NULL, WMOP_UNION);
	*/
	mk_lcomb(p->db_p->dbi_wdbp, NL_P(p->parent[i].id), &wm_hd, 1, NULL, NULL, NULL, 0);
    }

/*
 * reload the db so we dont
 * have to do any extra checks
 * in the main loop
 */
    wdb_close(p->db_p->dbi_wdbp);
    if ((p->db_p = db_open("gen000", "r")) == DBI_NULL)
	bu_exit(EXIT_FAILURE, "Failed to re-open initial population");
    if (db_dirbuild(p->db_p) < 0)
	bu_exit(EXIT_FAILURE, "Failed to load initial database");
}
int
main(int argc, char *argv[])
{
    struct db_i *dbip;
    struct directory *dp;
    struct rt_db_internal intern;
    struct rt_bot_internal *bot_ip = NULL;
    struct rt_wdb *wdbp;
    struct bu_vls name;
    struct bu_vls bname;
    struct Mesh_Info *prev_mesh = NULL;
    struct Mesh_Info *mesh = NULL;

    bu_vls_init(&name);

    if (argc != 3) {
	bu_exit(1, "Usage: %s file.g object", argv[0]);
    }

    dbip = db_open(argv[1], DB_OPEN_READWRITE);
    if (dbip == DBI_NULL) {
	bu_exit(1, "ERROR: Unable to read from geometry database file %s\n", argv[1]);
    }

    if (db_dirbuild(dbip) < 0)
	bu_exit(1, "ERROR: Unable to read from %s\n", argv[1]);

    dp = db_lookup(dbip, argv[2], LOOKUP_QUIET);
    if (dp == RT_DIR_NULL) {
	bu_exit(1, "ERROR: Unable to look up object %s\n", argv[2]);
    }

    RT_DB_INTERNAL_INIT(&intern)
	if (rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource) < 0) {
	    bu_exit(1, "ERROR: Unable to get internal representation of %s\n", argv[2]);
	}

    if (intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) {
	bu_exit(1, "ERROR: object %s does not appear to be of type BoT\n", argv[2]);
    } else {
	bot_ip = (struct rt_bot_internal *)intern.idb_ptr;
    }
    RT_BOT_CK_MAGIC(bot_ip);

    for (size_t i_cnt = 1; i_cnt < 3; i_cnt++) {
	mesh = iterate(bot_ip, prev_mesh);
	prev_mesh = mesh;

	// Plot results
	struct bu_vls fname;
	bu_vls_init(&fname);
	bu_vls_printf(&fname, "root3_%d.pl", i_cnt);
	FILE* plot_file = fopen(bu_vls_addr(&fname), "w");
	std::map<size_t, std::vector<size_t> >::iterator f_it;
	std::vector<size_t>::iterator l_it;
	int r = int(256*drand48() + 1.0);
	int g = int(256*drand48() + 1.0);
	int b = int(256*drand48() + 1.0);
	for (f_it = mesh->face_pts.begin(); f_it != mesh->face_pts.end(); f_it++) {
	    l_it = (*f_it).second.begin();
	    plot_face(&mesh->points_p0[(int)(*l_it)], &mesh->points_p0[(int)(*(l_it+1))], &mesh->points_p0[(int)(*(l_it+2))], r, g , b, plot_file);
	}
	fclose(plot_file);
    }

    // When constructing the final BoT, use the limit points for all
    // vertices
    ON_3dPointArray points_inf;
    for (size_t v = 0; v < (size_t)mesh->points_p0.Count(); v++) {
        points_inf.Append(*mesh->points_p0.At((int)v));
	//point_inf(v, mesh, &points_inf);
    }
    // The subdivision process shrinks the bot relative to its original
    // vertex positions - to better approximate the original surface,
    // average the change in position of the original vertices to get a
    // scaling factor and apply it to all points in the final mesh.
    fastf_t scale = 0.0;
    for (size_t pcnt = 0; pcnt < bot_ip->num_vertices; pcnt++) {
	ON_3dVector v1(ON_3dPoint(&bot_ip->vertices[pcnt*3]));
	ON_3dVector v2(*points_inf.At((int)pcnt));
	scale += 1 + (v1.Length() - v2.Length())/v1.Length();
    }
    scale = scale / bot_ip->num_vertices;
    for (size_t pcnt = 0; pcnt < (size_t)points_inf.Count(); pcnt++) {
	ON_3dPoint p0(*points_inf.At((int)pcnt));
	ON_3dPoint p1 = p0 * scale;
	*points_inf.At((int)pcnt) = p1;
    }

    wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK);

    fastf_t *vertices = (fastf_t *)bu_malloc(sizeof(fastf_t) * points_inf.Count() * 3, "new verts");
    int *faces = (int *)bu_malloc(sizeof(int) * mesh->face_pts.size() * 3, "new faces");
    for (size_t v = 0; v < (size_t)points_inf.Count(); v++) {
	vertices[v*3] = points_inf[(int)v].x;
	vertices[v*3+1] = points_inf[(int)v].y;
	vertices[v*3+2] = points_inf[(int)v].z;
    }
    std::map<size_t, std::vector<size_t> >::iterator f_it;
    std::vector<size_t>::iterator l_it;
    for (f_it = mesh->face_pts.begin(); f_it != mesh->face_pts.end(); f_it++) {
	l_it = (*f_it).second.begin();
	faces[(*f_it).first*3] = (*l_it);
	faces[(*f_it).first*3+1] = (*(l_it + 1));
	faces[(*f_it).first*3+2] = (*(l_it + 2));
    }

    bu_vls_init(&bname);
    bu_vls_sprintf(&bname, "%s_subd", argv[2]);
    mk_bot(wdbp, bu_vls_addr(&bname), RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, points_inf.Count(), mesh->face_pts.size(), vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);
    wdb_close(wdbp);
    bu_vls_free(&bname);

    bu_free(vertices, "free subdivision BoT vertices");
    bu_free(faces, "free subdivision BoT faces");

    return 0;
}
Exemplo n.º 16
0
int main(int   argc,
	 char* argv[])
{
    int        ret = 0;
    RegionList regions;

    if (argc < 3) {
	std::cout << "Usage: " << argv[0] << " <RAW file> <BRL-CAD file>" << std::endl;
	ret = 1;
    }
    else {
	std::ifstream is(argv[1]);

	if (!is.is_open()) {
	    std::cout << "Error reading RAW file" << std::endl;
	    ret = 1;
	}
	else {
	    struct rt_wdb* wdbp = wdb_fopen(argv[2]);
	    std::string title = "Converted from ";
	    title += argv[1];

	    mk_id(wdbp, title.c_str());

	    std::vector<std::string> nameLine = readLine(is);

	    while (is && !is.eof()) {
		if (nameLine.size() == 0) {
		    nameLine = readLine(is);
		    continue;
		}

		std::cout << "Read: " << nameLine[0].c_str() << '\n';
		assert(nameLine[0].size() > 0);

		Bot& bot = regions.addRegion(nameLine[0]);

		if (nameLine.size() > 1) {
		    size_t thicknessIndex = nameLine[1].find("thickf=");

		    if (thicknessIndex != std::string::npos) {
			std::string thickf = nameLine[1].substr(thicknessIndex + 7);

			if (thickf.size() > 0) {
			    fastf_t val = toValue(thickf.c_str());
			    bot.setThickness(val);
			} else {
			    std::cout << "Missing thickness in " << nameLine[0].c_str() << '\n';
			}
		    }
		}

		std::vector<std::string> triangleLine = readLine(is);

		while (is && (triangleLine.size() == 9)) {
		    point_t p;

		    getPoint(triangleLine[0], triangleLine[1], triangleLine[2], p);
		    size_t a = bot.addPoint(p);

		    getPoint(triangleLine[3], triangleLine[4], triangleLine[5], p);
		    size_t b = bot.addPoint(p);

		    getPoint(triangleLine[6], triangleLine[7], triangleLine[8], p);
		    size_t c = bot.addPoint(p);

		    bot.addTriangle(a, b, c);

		    triangleLine = readLine(is);
		}

		nameLine = triangleLine;
	    }

	    regions.create(wdbp);
	    wdb_close(wdbp);
	}
    }

    regions.printStat();

    return ret;
}
Exemplo n.º 17
0
int
ged_keep(struct ged *gedp, int argc, const char *argv[])
{
    int i;
    struct keep_node_data knd;
    struct rt_wdb *keepfp;
    struct directory *dp;
    struct bu_vls title = BU_VLS_INIT_ZERO;
    struct db_i *new_dbip;
    const char *cmd = argv[0];
    static const char *usage = "[-R] file object(s)";

    int c;
    int flag_R = 0;

    GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR);
    GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR);

    /* initialize result */
    bu_vls_trunc(gedp->ged_result_str, 0);

    /* must be wanting help */
    if (argc == 1) {
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", cmd, usage);
	return GED_HELP;
    }

    /* check for options */
    bu_optind = 1;
    while ((c = bu_getopt(argc, (char * const *)argv, "R")) != -1) {
	switch (c) {
	    case 'R':
		/* not recursively */
		flag_R = 1;
		break;
	    default:
		bu_vls_printf(gedp->ged_result_str, "Unrecognized option - %c", c);
		return GED_ERROR;
	}
    }
    /* skip options processed plus command name */
    argc -= bu_optind;
    argv += bu_optind;

    if (argc < 2) {
	bu_vls_printf(gedp->ged_result_str, "ERROR: missing file or object names\n");
	bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", cmd, usage);
	return GED_ERROR;
    }

    /* First, clear any existing counts */
    for (i = 0; i < RT_DBNHASH; i++) {
	for (dp = gedp->ged_wdbp->dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw)
	    dp->d_nref = 0;
    }

    /* Alert user if named file already exists */

    new_dbip = db_open(argv[0], DB_OPEN_READWRITE);

    if (new_dbip != DBI_NULL) {
	if (db_version(new_dbip) != db_version(gedp->ged_wdbp->dbip)) {
	    bu_vls_printf(gedp->ged_result_str, "%s: File format mismatch between '%s' and '%s'\n",
			  cmd, argv[0], gedp->ged_wdbp->dbip->dbi_filename);
	    return GED_ERROR;
	}

	if ((keepfp = wdb_dbopen(new_dbip, RT_WDB_TYPE_DB_DISK)) == NULL) {
	    bu_vls_printf(gedp->ged_result_str, "%s:  Error opening '%s'\n", cmd, argv[0]);
	    return GED_ERROR;
	} else {
	    bu_vls_printf(gedp->ged_result_str, "%s:  Appending to '%s'\n", cmd, argv[0]);

	    /* --- Scan geometry database and build in-memory directory --- */
	    db_dirbuild(new_dbip);
	}
    } else {
	/* Create a new database */
	keepfp = wdb_fopen_v(argv[0], db_version(gedp->ged_wdbp->dbip));

	if (keepfp == NULL) {
	    perror(argv[0]);
	    return GED_ERROR;
	}
    }

    knd.wdbp = keepfp;
    knd.gedp = gedp;

    /* ident record */
    if (bu_strncmp(gedp->ged_wdbp->dbip->dbi_title, "Parts of: ", 10) != 0) {
	bu_vls_strcat(&title, "Parts of: ");
    }
    bu_vls_strcat(&title, gedp->ged_wdbp->dbip->dbi_title);

    if (db_update_ident(keepfp->dbip, bu_vls_addr(&title), gedp->ged_wdbp->dbip->dbi_local2base) < 0) {
	perror("fwrite");
	bu_vls_printf(gedp->ged_result_str, "db_update_ident() failed\n");
	wdb_close(keepfp);
	bu_vls_free(&title);
	return GED_ERROR;
    }
    bu_vls_free(&title);

    for (i = 1; i < argc; i++) {
	if ((dp = db_lookup(gedp->ged_wdbp->dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL)
	    continue;

	if (!flag_R) {
	    /* recursively keep objects */
	    db_functree(gedp->ged_wdbp->dbip, dp, node_write, node_write, &rt_uniresource, (void *)&knd);
	} else {
	    /* keep just this object */
	    node_write(gedp->ged_wdbp->dbip, dp, (void *)&knd);
	}
    }

    wdb_close(keepfp);
    return GED_OK;
}
Exemplo n.º 18
0
int main( int argc, char *argv[] )
{
    char inputString[512];
    float inputX, inputY, inputZ;
    fastf_t *vertices;
    int *faces;
    fastf_t *thickness;
    FILE *inputFile;
    short int triangleAvailable;
    long int triangleCount;
    long int maxTriangleCapacity;
    long int j;
    char *outputObjectName;

    if (argc != 2) {
	usage(argv[0]);
    }

    outfp = wdb_fopen( "rawbot.g" );
    if (outfp == NULL) {
	fprintf(stderr, "Unable to open the output file rawbot.g\n");
	return 1;
    }
    /* units would be nice... */
    mk_id( outfp, "RAW BOT" );

    inputFile = fopen(argv[1], "r");
    if (inputFile == NULL) {
	perror("unable to open file");
	fprintf(stderr, "The input file [%s] was not readable\n", argv[1]);
	return 1;
    }

    vertices = bu_calloc(128 * 3, sizeof(fastf_t), "vertices");
    maxTriangleCapacity = 128;

    triangleCount=0;
    triangleAvailable = 1;
    while ( triangleAvailable == 1 ) {
	/* read a set of input values -- input data should be a 3-tuple
	 * of floating points.
	 */
	if (fscanf(inputFile, "%512s", inputString) != 1) {
	    triangleAvailable = 0;
	    continue;
	}
	inputX = atof(inputString);
	if (fscanf(inputFile, "%512s", inputString) != 1) {
	    triangleAvailable = 0;
	    continue;
	}
	inputY = atof(inputString);
	if (fscanf(inputFile, "%512s", inputString) != 1) {
	    triangleAvailable = 0;
	    continue;
	}
	inputZ = atof(inputString);

	if (triangleCount >= maxTriangleCapacity) {
	    vertices = bu_realloc(vertices, ((maxTriangleCapacity + 128) * 3) * sizeof(fastf_t), "vertices");
	    maxTriangleCapacity += 128;
	}

	/*		VSET( &vertices[triangleCount*3], inputX, inputY, inputZ ); */
	vertices[(triangleCount*3)] = inputX;
	vertices[(triangleCount*3)+1] = inputY;
	vertices[(triangleCount*3)+2] = inputZ;
	/*		printf("%f %f %f\n", vertices[(triangleCount*3)], vertices[(triangleCount*3)+1], vertices[(triangleCount*3)+2]); */
	triangleCount++;
    }

    /* done with the input file */
    fclose(inputFile);

    /* make sure we found some vertices */
    if (triangleCount <= 0) {
	fprintf(stderr, "There were no triangles found in the input file\n");
	bu_free(vertices, "vertices");
	return 0;
    } else {
	printf("Found %ld triangles\n", triangleCount);
    }

    /* allocate memory for faces and thickness arrays */
    /* XXX unfortunately we are limited to sizeof(int) since mk_bot takes
     * an int array */
    faces = (int *)bu_calloc(triangleCount * 3, sizeof(int), "faces");
    thickness = (fastf_t *)bu_calloc(triangleCount * 3, sizeof(int), "thickness");
    for (j=0; j<triangleCount; j++) {
	faces[(j*3)] = (j*3);
	faces[(j*3)+1] = (j*3) + 1;
	faces[(j*3)+2] = (j*3) + 2;
	printf("%ld %ld %ld == (%f %f %f)\n", (j*3), (j*3)+1, (j*3)+2, vertices[(j*3)], vertices[(j*3)+1], vertices[(j*3)+2]);
	thickness[(j*3)] = thickness[(j*3)+1] = thickness[(j*3)+2] = 1.0;
    }

    /*
      for (j=0; j < triangleCount * 3; j++) {
      printf("%f\n", vertices[j]);
      }
    */

    outputObjectName = (char *)bu_calloc(512, sizeof(char), "outputObjectName");

    snprintf(outputObjectName, 512, "%s.surface.s", argv[1]);
    mk_bot( outfp, outputObjectName, RT_BOT_SURFACE, RT_BOT_UNORIENTED, 0, triangleCount*3, triangleCount, vertices,  faces, (fastf_t *)NULL, (struct bu_bitv *)NULL );

    snprintf(outputObjectName, 512, "%s.solid.s", argv[1]);
    mk_bot( outfp, outputObjectName, RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, triangleCount*3, triangleCount, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL );

    /*	snprintf(outputObjectName, 512, "%s.plate.s", argv[1]);*/
    /*	mk_bot( outfp, "bot_u_plate", RT_BOT_PLATE, RT_BOT_UNORIENTED, 0, triangleCount, triangleCount, vertices, faces, thickness, NULL ); */

    bu_free(vertices, "vertices");
    bu_free(faces, "faces");
    bu_free(thickness, "thickness");

    wdb_close(outfp);

    return 0;
}
Exemplo n.º 19
0
int main(int ac, char *av[])
{
    struct rt_wdb *db_fp = NULL;
    struct bu_vls lens_type = BU_VLS_INIT_ZERO;
    struct bu_vls name = BU_VLS_INIT_ZERO;
    int lens_1side_2side;
    fastf_t ref_ind, thickness, diameter, focal_length;

    bu_vls_trunc(&lens_type, 0);
    bu_vls_trunc(&name, 0);

    ref_ind = 1.5;
    diameter = 200;
    thickness = diameter/5;
    focal_length = 600;
    lens_1side_2side = 2;
    bu_vls_printf(&lens_type, "DCX");
    bu_vls_printf(&name, "lens_%s_f%.1f_d%.1f", bu_vls_addr(&lens_type), focal_length, diameter);

    /* Process arguments */
    ReadArgs(ac, av, &lens_1side_2side, &ref_ind, &diameter, &thickness, &focal_length);

    /* Create file name if supplied, else use "lens.g" */
    if (av[bu_optind]) {
	if (!bu_file_exists(av[bu_optind], NULL)) {
	    db_fp = wdb_fopen(av[bu_optind]);
	} else {
	    bu_exit(-1, "Error - refusing to overwrite pre-existing file %s", av[bu_optind]);
	}
    }
    if (!av[bu_optind]) {
	if (!bu_file_exists(DEFAULT_LENS_FILENAME, NULL)) {
	    db_fp = wdb_fopen(DEFAULT_LENS_FILENAME);
	} else {
	    bu_exit(-1, "Error - no filename supplied and lens.g exists.");
	}
    }
    /* Make the requested lens*/
    if (lens_1side_2side == 1 && focal_length > 0) {
	bu_log("Making Plano-Convex lens...\n");
	bu_vls_trunc(&lens_type, 0);
	bu_vls_trunc(&name, 0);
	bu_vls_printf(&lens_type, "PCX");
	bu_vls_printf(&name, "lens_%s_f%.1f_d%.1f", bu_vls_addr(&lens_type), focal_length, diameter);
	MakeP(db_fp, bu_vls_addr(&name), diameter, focal_length, ref_ind, thickness);
    }
    if (lens_1side_2side == 1 && focal_length < 0) {
	bu_log("Making Plano-Concave lens...\n");
	bu_vls_trunc(&lens_type, 0);
	bu_vls_trunc(&name, 0);
	bu_vls_printf(&lens_type, "PCV");
	bu_vls_printf(&name, "lens_%s_f%.1f_d%.1f", bu_vls_addr(&lens_type), focal_length, diameter);
	MakeP(db_fp, bu_vls_addr(&name), diameter, focal_length, ref_ind, thickness);
    }

    if (lens_1side_2side == 2 && focal_length > 0) {
	bu_log("Making BiConvex lens...\n");
	bu_vls_trunc(&lens_type, 0);
	bu_vls_trunc(&name, 0);
	bu_vls_printf(&lens_type, "DCX");
	bu_vls_printf(&name, "lens_%s_f%.1f_d%.1f", bu_vls_addr(&lens_type), focal_length, diameter);
	MakeD(db_fp, bu_vls_addr(&name), diameter, focal_length, ref_ind, thickness);
    }
    if (lens_1side_2side == 2 && focal_length < 0) {
	bu_log("Making BiConcave lens...\n");
	bu_vls_trunc(&lens_type, 0);
	bu_vls_trunc(&name, 0);
	bu_vls_printf(&lens_type, "DCV");
	bu_vls_printf(&name, "lens_%s_f%.1f_d%.1f", bu_vls_addr(&lens_type), focal_length, diameter);
	MakeD(db_fp, bu_vls_addr(&name), diameter, focal_length, ref_ind, thickness);
    }

    /* Close database */
    wdb_close(db_fp);

    return 0;
}
Exemplo n.º 20
0
int
main(int argc, char **argv)
{
    int faces[15];
    fastf_t vertices[36];
    fastf_t thickness[4];
    struct rt_wdb *outfp = NULL;
    struct bu_bitv *face_mode = NULL;
    static const char *filename = "bot-test.g";

    if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) {
	printusage();
	return 0;
    }
    if (argc == 1) {
	printusage();
	fprintf(stderr,"       Program continues running (will create file bot-test.g because 'filename' was blank):\n");
    }
    else if (argc > 1)
	filename = argv[1];

    outfp = wdb_fopen(filename);
    mk_id(outfp, "BOT test");

    VSET(vertices, 0.0, 0.0, 0.0);
    VSET(&vertices[3], 0.0, 100.0, 0.0);
    VSET(&vertices[6], 0.0, 100.0, 50.0);
    VSET(&vertices[9], 200.0, 0.0, 0.0);

    /* face #1 */
    faces[0] = 0;
    faces[1] = 1;
    faces[2] = 2;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 2;
    faces[5] = 3;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_u_surf", RT_BOT_SURFACE, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);

    /* face #1 */
    faces[0] = 0;
    faces[1] = 2;
    faces[2] = 1;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 3;
    faces[5] = 2;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_ccw_surf", RT_BOT_SURFACE, RT_BOT_CCW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);


    /* face #1 */
    faces[0] = 1;
    faces[1] = 2;
    faces[2] = 0;

    /* face #2 */
    faces[3] = 2;
    faces[4] = 3;
    faces[5] = 0;

    /* face #3 */
    faces[6] = 3;
    faces[7] = 1;
    faces[8] = 0;

    /* face #4 */
    faces[9] = 3;
    faces[10] = 2;
    faces[11] = 1;

    mk_bot(outfp, "bot_cw_surf", RT_BOT_SURFACE, RT_BOT_CW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);


    /* face #1 */
    faces[0] = 0;
    faces[1] = 1;
    faces[2] = 2;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 2;
    faces[5] = 3;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_u_solid", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);

    /* face #1 */
    faces[0] = 0;
    faces[1] = 2;
    faces[2] = 1;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 3;
    faces[5] = 2;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_ccw_solid", RT_BOT_SOLID, RT_BOT_CCW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);


    /* face #1 */
    faces[0] = 1;
    faces[1] = 2;
    faces[2] = 0;

    /* face #2 */
    faces[3] = 2;
    faces[4] = 3;
    faces[5] = 0;

    /* face #3 */
    faces[6] = 3;
    faces[7] = 1;
    faces[8] = 0;

    /* face #4 */
    faces[9] = 3;
    faces[10] = 2;
    faces[11] = 1;

    mk_bot(outfp, "bot_cw_solid", RT_BOT_SOLID, RT_BOT_CW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);

    face_mode = bu_bitv_new(4);
    BU_BITSET(face_mode, 1);

    thickness[0] = 2.1;
    thickness[1] = 2.2;
    thickness[2] = 2.3;
    thickness[3] = 2.4;

    /* face #1 */
    faces[0] = 0;
    faces[1] = 1;
    faces[2] = 2;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 2;
    faces[5] = 3;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_u_plate", RT_BOT_PLATE, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, thickness, face_mode);

    /* face #1 */
    faces[0] = 0;
    faces[1] = 2;
    faces[2] = 1;

    /* face #2 */
    faces[3] = 0;
    faces[4] = 3;
    faces[5] = 2;

    /* face #3 */
    faces[6] = 0;
    faces[7] = 1;
    faces[8] = 3;

    /* face #4 */
    faces[9] = 1;
    faces[10] = 2;
    faces[11] = 3;

    mk_bot(outfp, "bot_ccw_plate", RT_BOT_PLATE, RT_BOT_CCW, 0, 4, 4, vertices, faces, thickness, face_mode);


    /* face #1 */
    faces[0] = 1;
    faces[1] = 2;
    faces[2] = 0;

    /* face #2 */
    faces[3] = 2;
    faces[4] = 3;
    faces[5] = 0;

    /* face #3 */
    faces[6] = 3;
    faces[7] = 1;
    faces[8] = 0;

    /* face #4 */
    faces[9] = 3;
    faces[10] = 2;
    faces[11] = 1;

    mk_bot(outfp, "bot_cw_plate", RT_BOT_PLATE, RT_BOT_CW, 0, 4, 4, vertices, faces, thickness, face_mode);

    /* Make a bot with duplicate vertices to test the "fuse" and "condense" code */
    VSET(vertices, 0.0, 0.0, 0.0);
    VSET(&vertices[3], 0.0, 100.0, 0.0);
    VSET(&vertices[6], 0.0, 100.0, 50.0);
    VMOVE(&vertices[9], &vertices[0]);
    VMOVE(&vertices[12], &vertices[6]);
    VSET(&vertices[15], 200.0, 0.0, 0.0);
    VMOVE(&vertices[18], &vertices[0]);
    VMOVE(&vertices[21], &vertices[3]);
    VMOVE(&vertices[24], &vertices[15]);
    VMOVE(&vertices[27], &vertices[3]);
    VMOVE(&vertices[30], &vertices[6]);
    VMOVE(&vertices[33], &vertices[15]);

    /* face #1 */
    faces[0] = 0;
    faces[1] = 1;
    faces[2] = 2;

    /* face #2 */
    faces[3] = 3;
    faces[4] = 4;
    faces[5] = 5;

    /* face #3 */
    faces[6] = 6;
    faces[7] = 7;
    faces[8] = 8;

    /* face #4 */

    faces[9] = 9;
    faces[10] = 10;
    faces[11] = 11;

    mk_bot(outfp, "bot_solid_dup_vs", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 12, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);

    faces[12] = 9;
    faces[13] = 10;
    faces[14] = 11;

    mk_bot(outfp, "bot_solid_dup_fs", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 12, 5, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL);

    bu_free((char *)face_mode, "bottest: face_mode");

    wdb_close(outfp);

    return 0;
}
Exemplo n.º 21
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;
}
Exemplo n.º 22
0
int
main(int argc, char **argv)
{
    struct rt_wdb *fp;
    struct directory *dp;
    struct rt_db_internal ip;
    struct pc_pc_set pcs;

    point_t cent;
    fastf_t rad;
    char solnam[9];
    /* Set up solid name */
    solnam[0] = 's';
    solnam[1] = '.';
    solnam[2] = 's';
    solnam[3] = 'p';
    solnam[4] = 'h';
    solnam[5] = ' ';
    solnam[6] = 'P';
    solnam[7] = '1';
    solnam[8] = '\0';

    /*rt_init_resource(&rt_uniresource, 0, NULL);*/
    if (argc!=2) {
	bu_exit(1, "Too few arguments, Please provide output filename\n");
    }

    if ((fp = wdb_fopen(argv[1])) == NULL) {
	perror(argv[2]);
	return 1;
    }
    mk_id(fp, "Parametrics test");
    cent[0] = 3.4;
    cent[1] = 4.5;
    cent[2] = 5.3;
    rad = 53.2;
    mk_sph(fp, solnam, cent, rad);

    solnam[0] = 's';
    solnam[1] = '.';
    solnam[2] = 's';
    solnam[3] = 'p';
    solnam[4] = 'h';
    solnam[5] = ' ';
    solnam[6] = 'P';
    solnam[7] = '2';
    solnam[8] = '\0';

    cent[0] = 23.4;
    cent[1] = 34.5;
    cent[2] = 45.3;
    rad = 153.2;
    mk_sph(fp, solnam, cent, rad);

    dp = db_lookup(fp->dbip, solnam, LOOKUP_QUIET);
    if (dp == RT_DIR_NULL)
	return 2;
    /*rt_db_get_internal(&intern, dp, fp->dbip, NULL, &rt_uniresource);*/


    mk_constraint(fp, "Constraint", 0);
    dp = db_lookup(fp->dbip, "Constraint", LOOKUP_QUIET);
    if (dp == RT_DIR_NULL)
	return 3;
    wdb_import(fp, &ip, solnam, (matp_t)NULL);
    ip.idb_meth->ft_params(&pcs, &ip);

    /* Todo: Free pcs parametric set */

    wdb_close(fp);

    return 0;
}
Exemplo n.º 23
0
int
main(int ac, char *av[])
{
    char *progname ="torii";

    torusLevels_t torii;
    const char *prototypeName="torus";

    char fileName[512];
    struct rt_wdb *db_fp;
    char scratch[512];
    int levels=2;
    int direction=4;
    point_t initialPosition = {0.0, 0.0, 0.0};
    int i;

    /* this array is a flake pattern */
    static const int dirArray[6][6]={
	{1, 1, 0, 1, 0, 0},
	{1, 1, 1, 0, 0, 0},
	{0, 1, 1, 1, 0, 0},
	{1, 0, 1, 1, 0, 0},
	{1, 1, 1, 1, 0, 0},
	{1, 1, 1, 1, 0, 0}
    };

    progname = *av;

    if (ac < 2) usage(progname);

    if (ac > 1) snprintf(fileName, 512, "%s", av[1]);

    bu_log("Output file name is \"%s\"\n", fileName);

    if ((db_fp = wdb_fopen(fileName)) == NULL) {
	perror(fileName);
	bu_exit(-1, NULL);
    }

    /* create the database header record */
    snprintf(scratch, 512, "%s Torii", fileName);
    mk_id(db_fp, scratch);

    /* init the levels array */
    torii.levels = levels;
    torii.level = bu_calloc(levels, sizeof(torusArray_t), "torii");

    /* initialize at least a few torus to minimize allocation calls */
    for (i=0; i<levels; i++) {
	torii.level[i].torus = bu_calloc(6, sizeof(torus_t), "torii.level[i].torus");
	torii.level[i].count=0;
	torii.level[i].max=6;
    }

    /* create the mofosunavabish */
    create_torii(levels, 0, &torii, initialPosition, dirArray, direction);

    /* write out the biatch to disk */
    output_torii(fileName, levels, torii, prototypeName);

    bu_log("\n...done! (see %s)\n", av[1]);

    wdb_close(db_fp);

    return 0;
}
Exemplo n.º 24
0
int
main(int argc, char **argv)
{
    char		*base, *bfile, *grp_name, *jfile, *reg_name;
    FILE		*fpin;
    struct rt_wdb	*fpout = NULL;
    size_t doti;
    int	c;

    grp_name = reg_name = NULL;

    /* Get command line arguments. */
    while ((c = bu_getopt(argc, argv, "g:r:h?")) != -1) {
	switch (c) {
	    case 'g':
		grp_name = bu_optarg;
		/* BRL-CAD group to add psurf to. */
		break;
	    case 'r':
		/* BRL-CAD region name for psurf. */
		reg_name = bu_optarg;
		break;
	    default:
		print_usage(argv[0]);
		break;
	}
    }

    /* Get Jack psurf input file name. */
    if (bu_optind >= argc) {
	jfile = "-";
	fpin = stdin;
    } else {
	jfile = argv[bu_optind];
	if ((fpin = fopen(jfile, "rb")) == NULL) {
	    bu_exit(1, "%s: cannot open %s for reading\n",
		    argv[0], jfile);
	}
    }

    /* Get BRL-CAD output data base name. */
    bu_optind++;
    if (bu_optind >= argc) {
	print_usage(argv[0]);
    }
    bfile = argv[bu_optind];
    if ((fpout = wdb_fopen(bfile)) == NULL) {
	bu_exit(1, "%s: cannot open %s for writing\n",
		argv[0], bfile);
    }

    /* Output BRL-CAD database header.  No problem if more than one. */
    mk_id(fpout, jfile);

    /* Make default region name if none given. */
    if (!reg_name) {
	/* Ignore leading path info. */
	base = strrchr(argv[1], '/');
	if (base)
	    base++;
	else
	    base = argv[1];
	reg_name = (char *)bu_malloc(sizeof(base)+1, "reg_name");
	bu_strlcpy(reg_name, base, sizeof(base)+1);

	/* Ignore .pss extension if it's there. */
	doti = strlen(reg_name);
	if (doti > 4) {
	    doti -= 4;
	    if (BU_STR_EQUAL(".pss", reg_name+doti))
		reg_name[doti] = '\0';
	}
    }

    jack_to_brlcad(fpin, fpout, reg_name, grp_name, jfile);
    fclose(fpin);
    wdb_close(fpout);
    return 0;
}
Exemplo n.º 25
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 */
Exemplo n.º 26
0
int
main(int argc, char *argv[])
{
    int opt;
    size_t i;
    const char *argv0 = argv[0];
    struct rt_wdb *fd_out;
    struct bu_vls vls_in = BU_VLS_INIT_ZERO;
    struct bu_vls vls_out = BU_VLS_INIT_ZERO;

    int opt_debug = 0;
    int opt_verbose = 0;

    /* shapelib vars */
    SHPHandle shapefile;
    size_t shp_num_invalid = 0;
    int shp_num_entities = 0;
    int shp_type = 0;

    /* intentionally double for scan */
    double shp_min[4] = HINIT_ZERO;
    double shp_max[4] = HINIT_ZERO;

    /* geometry */
    point2d_t *verts = NULL;
    size_t num_verts = 0;

    if (argc < 2) {
	usage(argv0);
	bu_exit(1, NULL);
    }

    while ((opt = bu_getopt(argc, argv, "dxv")) != -1) {
	switch (opt) {
	    case 'd':
		opt_debug = 1;
		break;
	    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 'v':
		opt_verbose++;
		break;
	    default:
		usage(argv0);
		bu_exit(1, NULL);
		break;
	}
    }
    argv += bu_optind;
    argc -= bu_optind;

    if (opt_verbose)
	bu_log("Verbose output enabled.\n");

    if (opt_debug)
	bu_log("Debugging output enabled.\n");

    /* validate input/output file specifiers */
    if (argc < 1) {
	usage(argv0);
	bu_exit(1, "ERROR: Missing input and output file names\n");
    }

    bu_vls_strcat(&vls_in, argv[0]);

    if (argc < 2) {
	bu_vls_printf(&vls_out, "%s.g", argv[0]);
    } else {
	bu_vls_strcat(&vls_out, argv[1]);
    }

    if (opt_verbose) {
	bu_log("Reading from [%s]\n", bu_vls_addr(&vls_in));
	bu_log("Writing to [%s]\n\n", bu_vls_addr(&vls_out));
    }

    /* initialize single threaded resource */
    rt_init_resource(&rt_uniresource, 0, NULL);

    /* open the input */
    shapefile = SHPOpen(bu_vls_addr(&vls_in), "rb");
    if (!shapefile) {
	bu_log("ERROR: Unable to open shapefile [%s]\n", bu_vls_addr(&vls_in));
	bu_vls_free(&vls_in);
	bu_vls_free(&vls_out);
	bu_exit(4, NULL);    }

    /* print shapefile details */
    if (opt_verbose) {
	SHPGetInfo(shapefile, &shp_num_entities, &shp_type, shp_min, shp_max);

	bu_log("Shapefile Type: %s\n", SHPTypeName(shp_type));
	bu_log("# of Shapes: %d\n\n", shp_num_entities);
	bu_log("File Bounds: (%12.3f,%12.3f, %.3g, %.3g)\n"
	       "         to  (%12.3f,%12.3f, %.3g, %.3g)\n",
	       shp_min[0], shp_min[1], shp_min[2], shp_min[3],
	       shp_max[0], shp_max[1], shp_max[2], shp_max[3]);
    }

    /* open the .g for writing */
    if ((fd_out = wdb_fopen(bu_vls_addr(&vls_out))) == NULL) {
	bu_log("ERROR: Unable to open shapefile [%s]\n", bu_vls_addr(&vls_out));
	bu_vls_free(&vls_in);
	bu_vls_free(&vls_out);
	perror(argv0);
	bu_exit(5, NULL);
    }

    /* iterate over all entities */
    for (i=0; i < (size_t)shp_num_entities; i++) {
	SHPObject *object;
	int shp_part;
	size_t j;

	object = SHPReadObject(shapefile, i);
	if (!object) {
	    if (opt_debug)
		bu_log("Shape %zu of %zu is missing, skipping.\n", i+1, (size_t)shp_num_entities);
	    continue;
	}

	/* validate the object */
	if (opt_debug) {
	    int shp_altered = SHPRewindObject(shapefile, object);
	    if (shp_altered > 0) {
		bu_log("WARNING: Shape %zu of %zu has [%d] bad loop orientations.\n", i+1, (size_t)shp_num_entities, shp_altered);
		shp_num_invalid++;
	    }
	}

	/* print detail header */
	if (opt_verbose) {
	    if (object->bMeasureIsUsed) {
		bu_log("\nShape:%zu (%s)  nVertices=%d, nParts=%d\n"
		       "  Bounds:(%12.3f,%12.3f, %g, %g)\n"
		       "      to (%12.3f,%12.3f, %g, %g)\n",
		       i+1, SHPTypeName(object->nSHPType), object->nVertices, object->nParts,
		       object->dfXMin, object->dfYMin, object->dfZMin, object->dfMMin,
		       object->dfXMax, object->dfYMax, object->dfZMax, object->dfMMax);
	    } else {
		bu_log("\nShape:%zu (%s)  nVertices=%d, nParts=%d\n"
		       "  Bounds:(%12.3f,%12.3f, %g)\n"
		       "      to (%12.3f,%12.3f, %g)\n",
		       i+1, SHPTypeName(object->nSHPType), object->nVertices, object->nParts,
		       object->dfXMin, object->dfYMin, object->dfZMin,
		       object->dfXMax, object->dfYMax, object->dfZMax);
	    }

	    if (object->nParts > 0 && object->panPartStart[0] != 0) {
		if (opt_debug)
		    bu_log("Shape %zu of %zu: panPartStart[0] = %d, not zero as expected.\n", i+1, (size_t)shp_num_entities, object->panPartStart[0]);
		continue;
	    }
	}

	num_verts = 0;
	verts = (point2d_t *)bu_calloc((size_t)object->nVertices, sizeof(point2d_t), "alloc point array");

	for (j = 0, shp_part = 1; j < (size_t)object->nVertices; j++) {
	    if (shp_part < object->nParts
		&& j == (size_t)object->panPartStart[shp_part]) {
		shp_part++;
		bu_log("Shape %zu of %zu: End of Loop\n", i+1, (size_t)shp_num_entities);
		make_shape(fd_out, opt_verbose, opt_debug, i, num_verts, verts);

		/* reset for next loop */
		memset(verts, 0, sizeof(point2d_t) * object->nVertices);
		num_verts = 0;
	    }
	    bu_log("%zu/%zu:%zu/%zu\t\t", i+1, (size_t)shp_num_entities, j+1, (size_t)object->nVertices);
	    bu_log("(%12.4f, %12.4f, %12.4f, %g)\n", object->padfX[j], object->padfY[j], object->padfZ[j], object->padfM[j]);

	    V2SET(verts[num_verts], object->padfX[j], object->padfY[j]);
	    num_verts++;
	}
	bu_log("Shape %zu of %zu: End of Loop\n", i+1, (size_t)shp_num_entities);
	make_shape(fd_out, opt_verbose, opt_debug, i, num_verts, verts);

	bu_free(verts, "free point array");
	verts = NULL;
	num_verts = 0;

	SHPDestroyObject(object);
	object = NULL;
    }

    if (opt_verbose) {
	if (shp_num_invalid > 0) {
	    bu_log("WARNING: %zu of %zu shape(s) had bad loop orientations.\n", shp_num_invalid, (size_t)shp_num_entities);
	}
	bu_log("\nDone.\n");
    }

    /* close up our files */
    SHPClose(shapefile);
    wdb_close(fd_out);

    /* free up allocated resources */
    bu_vls_free(&vls_in);
    bu_vls_free(&vls_out);

    return 0;
}
Exemplo n.º 27
0
int
main(int argc, char **argv)
{
    struct directory *dp;

    if (argc != 3 && argc != 4) {
	bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0]);
    }

    if (argc == 4) {
	if (BU_STR_EQUAL(argv[1], "-v"))
	    verbose = 1;
	else {
	    bu_log("Illegal option: %s\n", argv[1]);
	    bu_exit(1, "Usage:\n\t%s [-v] input.g output.g\n", argv[0]);
	}
    }

    rt_init_resource(&rt_uniresource, 0, NULL);

    dbip = db_open(argv[argc-2], DB_OPEN_READONLY);
    if (dbip == DBI_NULL) {
	perror(argv[0]);
	bu_exit(1, "Cannot open geometry database file (%s)\n", argv[argc-2]);
    }

    if ((fdout=wdb_fopen(argv[argc-1])) == NULL) {
	perror(argv[0]);
	bu_exit(1, "Cannot open file (%s)\n", argv[argc-1]);
    }
    if (db_dirbuild(dbip)) {
	bu_exit(1, "db_dirbuild failed\n");
    }

    /* Visit all records in input database, and spew them out,
     * modifying NMG objects into BoTs.
     */
    FOR_ALL_DIRECTORY_START(dp, dbip) {
	struct rt_db_internal intern;
	int id;
	int ret;
	id = rt_db_get_internal(&intern, dp, dbip, NULL, &rt_uniresource);
	if (id < 0) {
	    fprintf(stderr,
		    "%s: rt_db_get_internal(%s) failure, skipping\n",
		    argv[0], dp->d_namep);
	    continue;
	}
	if (id == ID_NMG) {
	    nmg_conv(&intern, dp->d_namep);
	} else {
	    ret = wdb_put_internal(fdout, dp->d_namep, &intern, 1.0);
	    if (ret < 0) {
		fprintf(stderr,
			"%s: wdb_put_internal(%s) failure, skipping\n",
			argv[0], dp->d_namep);
		rt_db_free_internal(&intern);
		continue;
	    }
	}
	rt_db_free_internal(&intern);
    } FOR_ALL_DIRECTORY_END
	  wdb_close(fdout);
    return 0;
}
Exemplo n.º 28
0
int
main(int argc, char **argv)
{
    int frame;
    char name[128];
    char gname[128];
    vect_t normal;
    struct wmember head, ghead;
    matp_t matp;
    mat_t xlate;
    mat_t rot1, rot2, rot3;
    vect_t from, to;
    vect_t offset;

    if (argc > 0) {
	bu_log("Usage: %s\n", argv[0]);
    	bu_log("       (Program expects ./pos.dat file to be present)\n");
    	bu_log("       (Will generate file tube.g)\n");
    	if (argc == 2) {
	    if ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?"))
		bu_exit(1,NULL);
    	}
	else if (argc == 1)
	    bu_log("       Program continues running:\n");
    }

    BU_LIST_INIT(&head.l);
    BU_LIST_INIT(&ghead.l);

    outfp = wdb_fopen("tube.g");
    if ((pos_fp = fopen("pos.dat", "r")) == NULL)
	perror("pos.dat");	/* Just warn */

    mk_id(outfp, "Procedural Gun Tube with Projectile");

    VSET(normal, 0, -1, 0);
    mk_half(outfp, "cut", normal, 0.0);
    VSET(normal, 0, 1, 0);
    mk_half(outfp, "bg.s", normal, -1000.0);
    (void)mk_addmember("bg.s", &head.l, NULL, WMOP_UNION);	/* temp use of "head" */
    mk_lcomb(outfp, "bg.r", &head, 1,
	     "texture", "file=movie128bw.pix w=128",
	     (unsigned char *)0, 0);

#ifdef never
    /* Numbers for a 105-mm M68 gun */
    oradius = 5 * inches2mm / 2;		/* 5" outer diameter */
    iradius = 4.134 * inches2mm / 2;	/* 5" inner (land) diameter */
#else
    /* Numbers invented to match 125-mm KE (Erline) round */
    iradius = 125.0/2;
    oradius = iradius + (5-4.134) * inches2mm / 2;		/* 5" outer diameter */
#endif
    fprintf(stderr, "inner radius=%gmm, outer radius=%gmm\n", iradius, oradius);

    length = 187.0 * inches2mm;
#ifdef never
    spacing = 100.;			/* mm per sample */
    nsamples = ceil(length/spacing);
    fprintf(stderr, "length=%gmm, spacing=%gmm\n", length, spacing);
    fprintf(stderr, "nframes=%d\n", nframes);
#endif

    for (frame=0;; frame++) {
	cur_time = frame * delta_t;
#ifdef never
	/* Generate some dummy sample data */
	if (frame < 16) break;
	for (i=0; i<nsamples; i++) {
	    sample[i][X] = i * spacing;
	    sample[i][Y] = 0;
	    sample[i][Z] = 4 * oradius * sin(
		((double)i*i)/nsamples * M_2PI +
		frame * M_PI_4);
	}
	projectile_pos = ((double)frame)/nframes *
	    (sample[nsamples-1][X] - sample[0][X]); /* length */
#else
	if (read_frame(stdin) < 0) break;
	if (pos_fp != NULL) read_pos(pos_fp);
#endif

#define build_spline build_cyl
	sprintf(name, "tube%do", frame);
	build_spline(name, nsamples, oradius);
	(void)mk_addmember(name, &head.l, NULL, WMOP_UNION);

	sprintf(name, "tube%di", frame);
	build_spline(name, nsamples, iradius);
	mk_addmember(name, &head.l, NULL, WMOP_SUBTRACT);

	mk_addmember("cut", &head.l, NULL, WMOP_SUBTRACT);

	sprintf(name, "tube%d", frame);
	mk_lcomb(outfp, name, &head, 1,
		 "plastic", "",
		 (unsigned char *)0, 0);

	/* Place the tube region and the ammo together.
	 * The origin of the ammo is expected to be the center
	 * of the rearmost plate.
	 */
	mk_addmember(name, &ghead.l, NULL, WMOP_UNION);
	matp = mk_addmember("ke", &ghead.l, NULL, WMOP_UNION)->wm_mat;

	VSET(from, 0, -1, 0);
	VSET(to, 1, 0, 0);		/* to X axis */
	bn_mat_fromto(rot1, from, to, &outfp->wdb_tol);

	VSET(from, 1, 0, 0);
	/* Projectile is 480mm long -- use center pt, not end */
	xfinddir(to, projectile_pos + 480.0/2, offset);
	bn_mat_fromto(rot2, from, to, &outfp->wdb_tol);

	MAT_IDN(xlate);
	MAT_DELTAS_VEC(xlate, offset);
	bn_mat_mul(rot3, rot2, rot1);
	bn_mat_mul(matp, xlate, rot3);

	(void)mk_addmember("light.r", &ghead.l, NULL, WMOP_UNION);
	(void)mk_addmember("bg.r", &ghead.l, NULL, WMOP_UNION);

	sprintf(gname, "g%d", frame);
	mk_lcomb(outfp, gname, &ghead, 0,
		 (char *)0, "", (unsigned char *)0, 0);

	fprintf(stderr, "frame %d\n", frame);  fflush(stderr);
    }
    wdb_close(outfp);
    fflush(stderr);

    return 0;
}