/* * Write the nmg to a BRL-CAD style data base. */ int create_brlcad_db(struct rt_wdb *fpout, struct model *m, char *reg_name, char *grp_name) { char *rname, *sname; int empty_model; struct shell *s; struct nmgregion *r; rname = (char *)bu_malloc(sizeof(reg_name) + 3, "rname"); /* Region name. */ sname = (char *)bu_malloc(sizeof(reg_name) + 3, "sname"); /* Solid name. */ snprintf(sname, sizeof(reg_name) + 2, "s.%s", reg_name); empty_model = nmg_kill_zero_length_edgeuses(m); if (empty_model) { bu_log("Warning: skipping empty model."); return 0; } nmg_rebound(m, &tol); r = BU_LIST_FIRST(nmgregion, &m->r_hd); s = BU_LIST_FIRST(shell, &r->s_hd); mk_bot_from_nmg(fpout, sname, s); /* Make BOT object. */ snprintf(rname, sizeof(reg_name) + 2, "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. */ } 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); }
/* * 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. */ } }
/* * 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; }
void Pipes(void) { vect_t ht; struct points *ptr; fastf_t len; int comblen; struct wmember head; BU_LIST_INIT(&head.l); ptr = root; if ( ptr == NULL ) return; while ( ptr->next != NULL ) { /* Make the basic pipe solids */ VSUB2( ht, ptr->next->p1, ptr->p2); mk_rcc( fdout, ptr->tube, ptr->p2, ht, radius ); /* make a solid record */ if ( !cable ) /* make inside solid */ mk_rcc( fdout, ptr->tubflu, ptr->p2, ht, radius-wall ); if ( torus ) { /* Make tubing region */ mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ if ( !cable ) { /* Subtract inside solid */ mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT ); /* make '-' member record */ /* Make fluid region */ mk_comb1( fdout, ptr->tubflu_r, ptr->tubflu, 1 ); } mk_lfcomb( fdout, ptr->tube_r, &head, 1 ); } else if ( mitre ) { if ( ptr->prev != NULL ) { len = VDOT( ptr->p, ptr->mnorm ); mk_half( fdout, ptr->cut, ptr->mnorm, len ); } comblen = 4 - cable; if ( ptr->next->next == NULL ) comblen--; if ( ptr->prev == NULL ) comblen--; mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ if ( !cable ) mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT ); /* make '-' member record */ if ( ptr->next->next != NULL ) mk_addmember( ptr->next->cut, &head.l, NULL, WMOP_SUBTRACT ); /* make '+' member record */ if ( ptr->prev != NULL ) mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT ); /* subtract HAF */ mk_lfcomb( fdout, ptr->tube_r, &head, 1 ); if ( !cable ) { /* Make fluid region */ comblen = 3; if ( ptr->next->next == NULL ) comblen--; if ( ptr->prev == NULL ) comblen--; mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ if ( ptr->next->next != NULL ) mk_addmember( ptr->next->cut, &head.l, NULL, WMOP_SUBTRACT ); /* make '+' member record */ if ( ptr->prev != NULL ) mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT ); /* subtract */ mk_lfcomb( fdout, ptr->tubflu_r, &head, 1 ); /* make REGION comb record */ } } else if ( sphere ) { /* make REGION comb record for tube */ comblen = 2; if ( cable ) comblen--; if ( ptr->next->tube[0] != '\0' ) comblen++; if ( !cable && ptr->prev != NULL ) comblen++; /* make 'u' member record */ mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION ); /* make '-' member record */ if ( !cable ) mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT ); if ( ptr->next->tube[0] != '\0' ) /* subtract outside of next tube */ mk_addmember( ptr->next->tube, &head.l, NULL, WMOP_SUBTRACT ); if ( !cable && ptr->prev != NULL ) /* subtract inside of previous tube */ mk_addmember( ptr->prev->tubflu, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->tube_r, &head, REGION ); if ( !cable ) { /* make REGION for fluid */ /* make 'u' member record */ mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION ); if ( ptr->next->tubflu[0] != '\0' ) /* subtract inside of next tube */ mk_addmember( ptr->next->tubflu, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->tubflu_r, &head, REGION ); } } else if ( nothing ) { /* make REGION comb record for tube */ comblen = 2; if ( cable ) comblen--; if ( ptr->next->tube[0] != '\0' ) comblen++; if ( !cable && ptr->prev != NULL ) comblen++; /* make 'u' member record */ mk_addmember( ptr->tube, &head.l, NULL, WMOP_UNION ); /* make '-' member record */ if ( !cable ) mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_SUBTRACT ); if ( ptr->next->tube[0] != '\0' ) /* subtract outside of next tube */ mk_addmember( ptr->next->tube, &head.l, NULL, WMOP_SUBTRACT ); if ( !cable && ptr->prev != NULL ) /* subtract inside of previous tube */ mk_addmember( ptr->prev->tubflu, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->tube_r, &head, REGION ); if ( !cable ) { /* make REGION for fluid */ /* make 'u' member record */ mk_addmember( ptr->tubflu, &head.l, NULL, WMOP_UNION ); if ( ptr->next->tubflu[0] != '\0' ) /* subtract inside of next tube */ mk_addmember( ptr->next->tubflu, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->tubflu_r, &head, REGION ); } } ptr = ptr->next; } }