int main(int argc, char **argv) { point_t a, b, c, d; struct rt_wdb *fp; si.magic = RT_NURB_INTERNAL_MAGIC; si.nsrf = 0; si.srfs = (struct face_g_snurb **)bu_malloc( sizeof(struct face_g_snurb *)*100, "snurb ptrs"); if ((fp = wdb_fopen(argv[1])) == NULL) { bu_log("unable to open new database [%s]\n", argv[1]); perror("unable to open database file"); return 1; } mk_id( fp, "Mike's Spline Test" ); VSET( a, 0, 0, 0 ); VSET( b, 10, 0, 0 ); VSET( c, 10, 10, 0 ); VSET( d, 0, 10, 0 ); make_face( a, b, c, d, 2 ); mk_export_fwrite( fp, "spl", (genptr_t)&si, ID_BSPLINE ); return 0; }
void writeTitle ( rt_wdb* wdbp, char* string ) { mk_id(wdbp, string); }
/* * 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; }
int off2nmg(FILE *fpin, struct rt_wdb *fpout) { char title[64], geom_fname[64]; char rname[67], sname[67]; char buf[200], buf2[200]; FILE *fgeom; struct model *m; title[0] = geom_fname[0] = '\0'; bu_fgets(buf, sizeof(buf), fpin); while (!feof(fpin)) { /* Retrieve the important data */ if (sscanf(buf, "name %[^\n]s", buf2) > 0) bu_strlcpy(title, buf2, sizeof(title)); if (sscanf(buf, "geometry %200[^\n]s", buf2) > 0) { char dtype[40], format[40]; if (sscanf(buf2, "%40s %40s %64s", dtype, format, geom_fname) != 3) bu_exit(1, "Incomplete geometry field in input file."); if (!BU_STR_EQUAL(dtype, "indexed_poly")) bu_exit(1, "Unknown geometry data type. Must be \"indexed_poly\"."); } bu_fgets(buf, sizeof(buf), fpin); } if (strlen(title) < (unsigned)1) fprintf(stderr, "Warning: no title\n"); if (strlen(geom_fname) < (unsigned)1) bu_exit(1, "ERROR: no geometry filename given"); if ((fgeom = fopen(geom_fname, "rb")) == NULL) { bu_exit(1, "off2nmg: cannot open %s (geometry description) for reading\n", geom_fname); } m = nmg_mm(); read_faces(m, fgeom); fclose(fgeom); snprintf(sname, 67, "s.%s", title); snprintf(rname, 67, "r.%s", title); mk_id(fpout, title); mk_nmg(fpout, sname, m); mk_comb1(fpout, rname, sname, 1); nmg_km(m); return 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); }
int main(int argc, char *argv[]) { point_t a, b, c, d; struct rt_wdb *fp; struct rt_nurb_internal *si; char *filename = "spltest.g"; int helpflag; if (argc < 1 || argc > 2) { printusage(argv); bu_exit(1,NULL); } helpflag = (argc == 2 && ( BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?"))); if (argc == 1 || helpflag) { printusage(argv); if (helpflag) bu_exit(1,NULL); bu_log(" Program continues running:\n"); } if (argc == 2) filename = argv[1]; if ((fp = wdb_fopen(filename)) == NULL) { perror("unable to open geometry database for writing"); bu_exit(1, "unable to open new database [%s]\n", filename); } mk_id(fp, "Mike's Spline Test"); VSET(a, 0, 0, 0); VSET(b, 10, 0, -5); VSET(c, 10, 10, 10); VSET(d, 0, 10, 0); BU_ALLOC(si, struct rt_nurb_internal); si->magic = RT_NURB_INTERNAL_MAGIC; si->nsrf = 0; si->srfs = (struct face_g_snurb **)bu_malloc(sizeof(struct face_g_snurb *)*100, "allocate snurb ptrs"); make_face(si, a, b, c, d, 2); /* wdb_export */ mk_export_fwrite(fp, "spltest", (void *)si, ID_BSPLINE); bu_log("Saving file %s\n",filename); return 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; }
bool BRLCADWrapper::OpenFile(std::string &flnm) { //TODO: need to check to make sure we aren't overwriting /* open brlcad instance */ if ((outfp = wdb_fopen(flnm.c_str())) == NULL) { bu_log("Cannot open output file (%s)\n", flnm.c_str()); return false; } // hold on to output filename filename = flnm.c_str(); mk_id(outfp, "Output from STEP converter step-g."); return true; }
/* * Write the nmg to a BRL-CAD style data base. */ void create_brlcad_db(struct rt_wdb *fpout, struct model *m, char *reg_name, char *grp_name) { char *rname, *sname; int size = sizeof(reg_name) + 3; mk_id(fpout, "Ascii NMG"); rname = (char *)bu_malloc(size, "rname"); /* Region name. */ sname = (char *)bu_malloc(size, "sname"); /* Solid name. */ snprintf(sname, size, "s.%s", reg_name); mk_nmg(fpout, sname, m); /* Make nmg object. */ snprintf(rname, size, "r.%s", reg_name); mk_comb1(fpout, rname, sname, 1); /* Put object in a region. */ if (grp_name) { mk_comb1(fpout, grp_name, rname, 1); /* Region in group. */ } }
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; }
int main(int argc, char **argv) { int depth; if (argc != 2) { fprintf(stderr, "Usage: pyramid recursion\n"); return 1; } depth = atoi(argv[1]); sin60 = sin(60.0 * DEG2RAD); outfp = wdb_fopen("pyramid.g"); mk_id(outfp, "3-D Pyramids"); do_leaf("leaf"); do_tree("tree", "leaf", depth); return 0; }
func_decl * fpa_decl_plugin::mk_numeral_decl(mpf const & v) { sort * s = mk_float_sort(v.get_ebits(), v.get_sbits()); func_decl * r = nullptr; if (m_fm.is_nan(v)) r = m_manager->mk_const_decl(symbol("NaN"), s, func_decl_info(m_family_id, OP_FPA_NAN)); else if (m_fm.is_pinf(v)) r = m_manager->mk_const_decl(symbol("+oo"), s, func_decl_info(m_family_id, OP_FPA_PLUS_INF)); else if (m_fm.is_ninf(v)) r = m_manager->mk_const_decl(symbol("-oo"), s, func_decl_info(m_family_id, OP_FPA_MINUS_INF)); else if (m_fm.is_pzero(v)) r = m_manager->mk_const_decl(symbol("+zero"), s, func_decl_info(m_family_id, OP_FPA_PLUS_ZERO)); else if (m_fm.is_nzero(v)) r = m_manager->mk_const_decl(symbol("-zero"), s, func_decl_info(m_family_id, OP_FPA_MINUS_ZERO)); else { SASSERT(m_fm.is_regular(v)); parameter p(mk_id(v), true); SASSERT(p.is_external()); sort * s = mk_float_sort(v.get_ebits(), v.get_sbits()); r = m_manager->mk_const_decl(symbol("fp.numeral"), s, func_decl_info(m_family_id, OP_FPA_NUM, 1, &p)); } return r; }
int main(int argc, char **argv) { int depth; if (argc != 2 || BU_STR_EQUAL(argv[1],"-h") || BU_STR_EQUAL(argv[1],"-?")) { fprintf(stderr, "Usage: pyramid recursion\n (the argument is of type integer)\n"); return 1; } depth = atoi(argv[1]); sin60 = sin(60.0 * DEG2RAD); outfp = wdb_fopen("pyramid.g"); printf("Creating file pyramid.g\n"); mk_id(outfp, "3-D Pyramids"); do_leaf("leaf"); do_tree("tree", "leaf", depth); return 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; }
func_decl * float_decl_plugin::mk_value_decl(mpf const & v) { parameter p(mk_id(v), true); SASSERT(p.is_external()); sort * s = mk_float_sort(v.get_ebits(), v.get_sbits()); return m_manager->mk_const_decl(symbol("float"), s, func_decl_info(m_family_id, OP_FLOAT_VALUE, 1, &p)); }
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; }
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; }
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; }
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 */
discr_tree::node_cell::node_cell(node_cell const & s): m_rc(0), m_id(mk_id()), m_children(s.m_children), m_star_child(s.m_star_child), m_values(s.m_values) { }
int main(int argc, char **argv) { struct rt_sketch_internal *skt; struct bezier_seg *bsg; struct line_seg *lsg; struct carc_seg *csg; point_t V; vect_t u_vec, v_vec; point2d_t verts[] = { { 250, 0 }, /* 0 */ { 500, 0 }, /* 1 */ { 500, 500 }, /* 2 */ { 0, 500 }, /* 3 */ { 0, 250 }, /* 4 */ { 250, 250 }, /* 5 */ { 125, 125 }, /* 6 */ { 0, 125 }, /* 7 */ { 125, 0 }, /* 8 */ { 200, 200 } /* 9 */ }; int i; VSET( V, 10, 20, 30 ); VSET( u_vec, 1, 0, 0 ); VSET( v_vec, 0, 1, 0 ); skt = (struct rt_sketch_internal *)bu_calloc( 1, sizeof( struct rt_sketch_internal ), "sketch" ); skt->magic = RT_SKETCH_INTERNAL_MAGIC; VMOVE( skt->V, V ); VMOVE( skt->u_vec, u_vec ); VMOVE( skt->v_vec, v_vec ); skt->vert_count = 10; skt->verts = (point2d_t *)bu_calloc( skt->vert_count, sizeof( point2d_t ), "verts" ); for ( i=0; i<skt->vert_count; i++ ) { V2MOVE( skt->verts[i], verts[i] ); } skt->skt_curve.seg_count = 6; skt->skt_curve.reverse = (int *)bu_calloc( skt->skt_curve.seg_count, sizeof( int ), "sketch: reverse" ); skt->skt_curve.segments = (genptr_t *)bu_calloc( skt->skt_curve.seg_count, sizeof( genptr_t ), "segs" ); bsg = (struct bezier_seg *)bu_malloc( sizeof( struct bezier_seg ), "sketch: bsg" ); bsg->magic = CURVE_BEZIER_MAGIC; bsg->degree = 4; bsg->ctl_points = (int *)bu_calloc( bsg->degree+1, sizeof( int ), "sketch: bsg->ctl_points" ); bsg->ctl_points[0] = 4; bsg->ctl_points[1] = 7; bsg->ctl_points[2] = 9; bsg->ctl_points[3] = 8; bsg->ctl_points[4] = 0; skt->skt_curve.segments[0] = (genptr_t)bsg; lsg = (struct line_seg *)bu_malloc( sizeof( struct line_seg ), "sketch: lsg" ); lsg->magic = CURVE_LSEG_MAGIC; lsg->start = 0; lsg->end = 1; skt->skt_curve.segments[1] = (genptr_t)lsg; lsg = (struct line_seg *)bu_malloc( sizeof( struct line_seg ), "sketch: lsg" ); lsg->magic = CURVE_LSEG_MAGIC; lsg->start = 1; lsg->end = 2; skt->skt_curve.segments[2] = (genptr_t)lsg; lsg = (struct line_seg *)bu_malloc( sizeof( struct line_seg ), "sketch: lsg" ); lsg->magic = CURVE_LSEG_MAGIC; lsg->start = 2; lsg->end = 3; skt->skt_curve.segments[3] = (genptr_t)lsg; lsg = (struct line_seg *)bu_malloc( sizeof( struct line_seg ), "sketch: lsg" ); lsg->magic = CURVE_LSEG_MAGIC; lsg->start = 3; lsg->end = 4; skt->skt_curve.segments[4] = (genptr_t)lsg; csg = (struct carc_seg *)bu_malloc( sizeof( struct carc_seg ), "sketch: csg" ); csg->magic = CURVE_CARC_MAGIC; csg->radius = -1.0; csg->start = 6; csg->end = 5; skt->skt_curve.segments[5] = (genptr_t)csg; outfp = wdb_fopen( "sketch.g" ); mk_id( outfp, "sketch test" ); mk_sketch( outfp, "test_sketch", skt ); return 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; }
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; }
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; }
discr_tree::node_cell::node_cell():m_rc(0), m_id(mk_id()) { }
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); }
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; }
int main(int argc, char **argv) { int done; char units[16], fname[80]; int optc; while ( (optc = bu_getopt( argc, argv, "tsmnc" )) != -1) { switch ( optc ) /* Set joint type and cable option */ { case 't': torus = 1; break; case 's': sphere = 1; break; case 'm': mitre = 1; break; case 'n': nothing = 1; break; case 'c': cable = 1; break; case '?': fprintf( stderr, "Illegal option %c\n", optc ); Usage(); return 1; break; } } if ( (torus + sphere + mitre + nothing) > 1 ) /* Too many joint options */ { Usage(); fprintf( stderr, "Options t, s, m, n are mutually exclusive\n" ); return 1; } else if ( (torus + sphere + mitre + nothing) == 0 ) { torus = 1; /* default */ } if ( (argc - bu_optind) != 2 ) { Usage(); return 1; } bu_strlcpy( name, argv[bu_optind++], sizeof(name) ); /* Base name for objects */ fdout = wdb_fopen( argv[bu_optind] ); if ( fdout == NULL ) { fprintf( stderr, "Cannot open %s\n", argv[bu_optind] ); perror( "Pipe" ); Usage(); return 1; } MAT_IDN(identity); /* Identity matrix for all objects */ pi = atan2( 0.0, -1.0 ); /* PI */ printf( "FLUID & PIPING V%d.%d 10 Mar 89\n\n", VERSION, RELEASE ); printf( "append %s to your target description using 'concat' in mged\n", argv[bu_optind] ); k = 0.0; while ( k == 0.0 ) { printf( "UNITS? (ft, in, m, cm, default is millimeters) "); bu_fgets(units, sizeof(units), stdin); switch (units[0]) { case '\0': k = 1.0; break; case 'f': k = 12*25.4; break; case 'i': k=25.4; break; case 'm': if ( units[1] == '\0') k=1000.0; else k=1.0; break; case 'c': k=10.0; break; default: k=0.0; printf( "\n\t%s is not a legal choice for units\n", units ); printf( "\tTry again\n" ); break; } } done = 0; while ( !done ) { if ( !cable ) { printf( "radius and wall thickness: "); if (scanf("%lf %lf", &radius, &wall) == EOF ) return 1; if (radius > wall) done = 1; else { printf( " *** bad input!\n\n"); printf( "\tradius must be larger than wall thickness\n" ); printf( "\tTry again\n" ); } } else { printf( "radius: "); if ( scanf("%lf", &radius ) == EOF ) return 1; done=1; } } radius=k*radius; wall=k*wall; Readpoints(); /* Read data points */ Names(); /* Construct names for all solids */ Normals(); /* Calculate normals and other vectors */ Adjust(); /* Adjust points to allow for elbows */ /* Generate Title */ bu_strlcpy(fname, name, sizeof(fname)); if ( !cable ) bu_strlcat(fname, " pipe and fluid", sizeof(fname)); else bu_strlcat(fname, " cable", sizeof(fname)); /* Create ident record */ mk_id(fdout, fname); Pipes(); /* Construct the piping */ Elbows(); /* Construct the elbow sections */ Groups(); /* Make some groups */ return 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; }
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; }