bool BRLCADWrapper::WriteSphere(double *center, double radius) { point_t pnt; center[X] = 0.0; center[Y] = 0.0; center[Z] = 0.0; VMOVE(pnt, center); mk_sph(outfp, "s1", pnt, radius); return true; }
int mk_sol(struct rt_wdb *fp, double radius) { struct wmember c; point_t p = { 0, 0, 0}; /* make a sphere! tada! */ mk_sph(fp, "sun.s", p, radius * 1000.0); BU_LIST_INIT(&c.l); mk_addmember("sun.s", &c.l, NULL, WMOP_UNION); mk_lcomb(fp, "sun.r", &c, 1, NULL, NULL, NULL, 0); return 0; }
int sphere(int entityno) { fastf_t radius = 0.0; point_t center; fastf_t x; fastf_t y; fastf_t z; int sol_num; /* IGES solid type number */ /* Set Defaults */ x = 0.0; y = 0.0; z = 0.0; /* Acquiring Data */ if (dir[entityno]->param <= pstart) { bu_log("Illegal parameter pointer for entity D%07d (%s)\n" , dir[entityno]->direct, dir[entityno]->name); return 0; } Readrec(dir[entityno]->param); Readint(&sol_num, ""); Readcnv(&radius, ""); Readcnv(&x, ""); Readcnv(&y, ""); Readcnv(&z, ""); if (radius <= 0.0) { bu_log("Illegal parameters for entity D%07d (%s)\n" , dir[entityno]->direct, dir[entityno]->name); return 0; } /* * Making the necessaries. First an id is made for the new entity, then * the x, y, z coordinates for its vertices are converted to vectors with * VSET(), and finally the libwdb routine that makes an analogous BRL-CAD * solid is called. */ VSET(center, x, y, z); mk_sph(fdout, dir[entityno]->name, center, radius); return 1; }
void do_light(char *name, fastf_t *pos, fastf_t *dir_at, int da_flag, double r, unsigned char *rgb, struct wmember *headp) /* direction or aim point */ /* 0 = direction, !0 = aim point */ /* radius of light */ { char nbuf[64]; vect_t center; mat_t rot; mat_t xlate; mat_t both; vect_t from; vect_t dir; if ( da_flag ) { VSUB2( dir, dir_at, pos ); VUNITIZE( dir ); } else { VMOVE( dir, dir_at ); } snprintf( nbuf, 64, "%s.s", name ); VSETALL( center, 0 ); mk_sph( outfp, nbuf, center, r ); /* * Need to rotate from 0, 0, -1 to vect "dir", * then xlate to final position. */ VSET( from, 0, 0, -1 ); bn_mat_fromto( rot, from, dir ); MAT_IDN( xlate ); MAT_DELTAS_VEC( xlate, pos); bn_mat_mul( both, xlate, rot ); mk_region1( outfp, name, nbuf, "light", "shadows=1", rgb ); (void)mk_addmember( name, &(headp->l), NULL, WMOP_UNION ); }
void process_sphere(int id, fastf_t *center, double rad, int sph_type) { struct sphere *newsph; char nm[128], nm1[128]; unsigned char rgb[3]; struct wmember reg_head; BU_ALLOC(newsph, struct sphere); rgb[0] = atom_list[sph_type].red; rgb[1] = atom_list[sph_type].green; rgb[2] = atom_list[sph_type].blue; sprintf(nm1, "sph.%d", id); mk_sph(outfp, nm1, center, rad); /* Create a region nm to contain the solid nm1 */ BU_LIST_INIT(®_head.l); (void)mk_addmember(nm1, ®_head.l, NULL, WMOP_UNION); sprintf(nm, "SPH.%d", id); mk_lcomb(outfp, nm, ®_head, 1, matname, matparm, rgb, 0); /* Include this region in the larger group */ (void)mk_addmember(nm, &head.l, NULL, WMOP_UNION); newsph->next = (struct sphere *)0; newsph->s_id = id; bu_strlcpy(newsph->s_name, nm1, sizeof(newsph->s_name)); newsph->s_name[14] = '\0'; VMOVE(newsph->s_center, center); newsph->s_rad = rad; newsph->s_atom_type = sph_type; if (s_head == (struct sphere *) 0) { s_head = s_list = newsph; } else { s_list->next = newsph; s_list = newsph; } }
int main(int argc, char **argv) { /* START # 1 */ struct rt_wdb *fpw; /* File to be written to. */ char filemged[26] = {0}; /* Mged file create. */ double hgt=0; /* Height, width, & depth of gas tank. */ double wid=0; double dpt=0; double rds=0; /* Radius of the corner of gas tank. */ point_t pts[8]; /* Points for arb8. */ point_t bs; /* Base of cylinder. */ vect_t ht; /* Height of cylinder. */ fastf_t rad; /* Radius of cylinder & sphere. */ point_t cent; /* Center of sphere. */ /* point_t and vect_t are set using typedef of type fastf_t. */ /* fastf_t is a type that is machine dependent. */ char *temp; /* Temporary character string. */ char temp1[16]; /* Temporary character string. */ char solnam[9]; /* Solid name. */ char regnam[9]; /* Region name. */ char grpnam[5]; /* Group name. */ int numtnk=0; /* Number of gas tanks to be created */ /* (<=26). */ struct wmember comb; /* Used to make regions. */ struct wmember comb1; /* Used to make groups. */ int i, j, k; /* Loop counters. */ int ret; /* Set up solid, region, and group names. */ solnam[0] = 's'; solnam[1] = '.'; solnam[2] = 't'; solnam[3] = 'n'; solnam[4] = 'k'; solnam[5] = ' '; solnam[6] = '#'; solnam[7] = '#'; solnam[8] = '\0'; regnam[0] = 'r'; regnam[1] = '.'; regnam[2] = 't'; regnam[3] = 'n'; regnam[4] = 'k'; regnam[5] = ' '; regnam[6] = '#'; regnam[7] = '#'; regnam[8] = '\0'; grpnam[0] = 't'; grpnam[1] = 'n'; grpnam[2] = 'k'; grpnam[3] = ' '; grpnam[4] = '\0'; /* If there are no arguments ask questions. */ if (argc == 1) { /* START # 3 */ /* Print info about the window. */ printf("\nThis program constructs a solid gas tank with all\n"); printf("edges and corners rounded.\n\n"); /* Find name of mged file to be created. */ printf("Enter the mged file to be created (25 char max).\n\t"); (void)fflush(stdout); ret = scanf("%26s", filemged); if (ret == 0) { perror("scanf"); } if (BU_STR_EQUAL(filemged, "")) bu_strlcpy(filemged, "gastank.g", sizeof(filemged)); /* Find the number of gas tanks to create. */ printf("Enter the number of gas tanks to create (26 max).\n\t"); (void)fflush(stdout); ret = scanf("%d", &numtnk); if (ret == 0) { perror("scanf"); numtnk = 1; } if (numtnk < 1) numtnk = 1; if (numtnk > 26) numtnk = 26; /* Find the dimensions of the gas tanks. */ printf("Enter the height, width, and depth of the gas tank.\n\t"); (void)fflush(stdout); ret = scanf("%lf %lf %lf", &hgt, &wid, &dpt); if (ret == 0) { perror("scanf"); hgt = 1000.0; wid = 1000.0; dpt = 1000.0; } if (hgt < SMALL_FASTF) hgt = SMALL_FASTF; if (wid < SMALL_FASTF) wid = SMALL_FASTF; if (dpt < SMALL_FASTF) dpt = SMALL_FASTF; printf("Enter the radius of the corners.\n\t"); (void)fflush(stdout); ret = scanf("%lf", &rds); if (ret == 0) { perror("scanf"); rds = 10.0; } if (rds < SMALL_FASTF) rds = SMALL_FASTF; } /* END # 3 */ /* If there are arguments get answers from arguments. */ else { /* START # 4 */ /* List options. */ /* -fname - name = mged file name. */ /* -n# - # = number of gas tanks. */ /* -h# - # = height of gas tank in mm. */ /* -w# - # = width of gas tank in mm. */ /* -d# - # = depth of gas tank in mm. */ /* -r# - # = radius of corners in mm. */ for (i=1; i<argc; i++) { /* START # 5 */ /* Put argument in temporary character string. */ temp = argv[i]; /* -f - mged file. */ if (temp[1] == 'f') { /* START # 6 */ j = 2; k = 0; while ((temp[j] != '\0') && (k < 25)) { /* START # 7 */ filemged[k] = temp[j]; j++; k++; } /* END # 7 */ filemged[k] = '\0'; } /* END # 6 */ /* All other options. */ else { /* START # 8 */ /* Set up temporary character string. */ j = 2; k = 0; while ((temp[j] != '\0') && (k < 15)) { /* START # 9 */ temp1[k] = temp[j]; j++; k++; } /* END # 9 */ temp1[k] = '\0'; if (temp[1] == 'n') { sscanf(temp1, "%d", &numtnk); if (numtnk > 26) numtnk = 26; } else if (temp[1] == 'h') { sscanf(temp1, "%lf", &hgt); } else if (temp[1] == 'w') { sscanf(temp1, "%lf", &wid); } else if (temp[1] == 'd') { sscanf(temp1, "%lf", &dpt); } else if (temp[1] == 'r') { sscanf(temp1, "%lf", &rds); } } /* END # 8 */ } /* END # 5 */ } /* END # 4 */ /* Print out all info. */ printf("\nmged file: %s\n", filemged); printf("height of gas tank: %f mm\n", hgt); printf("width of gas tank: %f mm\n", wid); printf("depth of gas tank: %f mm\n", dpt); printf("radius of corner: %f mm\n", rds); printf("number of gas tanks: %d\n\n", numtnk); (void)fflush(stdout); /* Open mged file. */ fpw = wdb_fopen(filemged); /* Write ident record. */ mk_id(fpw, "windows"); for (i=0; i<numtnk; i++) { /* START # 2 */ /* Create all solids. */ /* Create the 3 arb8s. */ pts[0][0] = (fastf_t)(dpt / 2.0); pts[0][1] = (fastf_t)(wid / 2.0 - rds); pts[0][2] = (fastf_t)(hgt / 2.0 - rds); pts[1][0] = pts[0][0]; pts[1][1] = pts[0][1]; pts[1][2] = (-pts[0][2]); pts[2][0] = pts[0][0]; pts[2][1] = (-pts[0][1]); pts[2][2] = pts[1][2]; pts[3][0] = pts[0][0]; pts[3][1] = pts[2][1]; pts[3][2] = pts[0][2]; pts[4][0] = (-pts[0][0]); pts[4][1] = pts[0][1]; pts[4][2] = pts[0][2]; pts[5][0] = pts[4][0]; pts[5][1] = pts[0][1]; pts[5][2] = (-pts[0][2]); pts[6][0] = pts[4][0]; pts[6][1] = (-pts[0][1]); pts[6][2] = pts[1][2]; pts[7][0] = pts[4][0]; pts[7][1] = pts[2][1]; pts[7][2] = pts[0][2]; solnam[5] = 97 + i; solnam[6] = '0'; solnam[7] = '1'; mk_arb8(fpw, solnam, &pts[0][X]); pts[0][0] = (fastf_t)(dpt / 2.0 - rds); pts[0][1] = (fastf_t)(wid / 2.0); pts[1][0] = pts[0][0]; pts[1][1] = pts[0][1]; pts[2][0] = pts[0][0]; pts[2][1] = (-pts[0][1]); pts[3][0] = pts[0][0]; pts[3][1] = pts[2][1]; pts[4][0] = (-pts[0][0]); pts[4][1] = pts[0][1]; pts[5][0] = pts[4][0]; pts[5][1] = pts[0][1]; pts[6][0] = pts[4][0]; pts[6][1] = pts[2][1]; pts[7][0] = pts[4][0]; pts[7][1] = pts[2][1]; solnam[7] = '2'; mk_arb8(fpw, solnam, &pts[0][X]); pts[0][1] = (fastf_t)(wid / 2.0 - rds); pts[0][2] = (fastf_t)(hgt / 2.0); pts[1][1] = pts[0][1]; pts[1][2] = (-pts[0][2]); pts[2][1] = (-pts[0][1]); pts[2][2] = pts[1][2]; pts[3][1] = pts[2][1]; pts[3][2] = pts[0][2]; pts[4][1] = pts[0][1]; pts[4][2] = pts[0][2]; pts[5][1] = pts[0][1]; pts[5][2] = (-pts[0][2]); pts[6][1] = (-pts[0][1]); pts[6][2] = pts[1][2]; pts[7][1] = pts[2][1]; pts[7][2] = pts[0][2]; solnam[7] = '3'; mk_arb8(fpw, solnam, &pts[0][X]); /* Make 8 spheres. */ cent[0] = (fastf_t)(dpt / 2.0 - rds); cent[1] = (fastf_t)(wid / 2.0 - rds); cent[2] = (fastf_t)(hgt / 2.0 - rds); rad = (fastf_t)(rds); solnam[7] = '4'; mk_sph(fpw, solnam, cent, rad); cent[2] = (-cent[2]); solnam[7] = '5'; mk_sph(fpw, solnam, cent, rad); cent[1] = (-cent[1]); solnam[7] = '6'; mk_sph(fpw, solnam, cent, rad); cent[2] = (-cent[2]); solnam[7] = '7'; mk_sph(fpw, solnam, cent, rad); cent[0] = (-cent[0]); cent[1] = (-cent[1]); solnam[7] = '8'; mk_sph(fpw, solnam, cent, rad); cent[2] = (-cent[2]); solnam[7] = '9'; mk_sph(fpw, solnam, cent, rad); cent[1] = (-cent[1]); solnam[6] = '1'; solnam[7] = '0'; mk_sph(fpw, solnam, cent, rad); cent[2] = (-cent[2]); solnam[7] = '1'; mk_sph(fpw, solnam, cent, rad); /* Make 12 cylinders. */ bs[0] = (fastf_t)(dpt / 2.0 - rds); bs[1] = (fastf_t)(wid / 2.0 - rds); bs[2] = (fastf_t)(hgt / 2.0 - rds); ht[0] = (fastf_t)(0.0); ht[1] = (fastf_t)(-wid + 2 * rds); ht[2] = (fastf_t)(0.0); solnam[7] = '2'; mk_rcc(fpw, solnam, bs, ht, rad); bs[2] = (-bs[2]); solnam[7] = '3'; mk_rcc(fpw, solnam, bs, ht, rad); bs[0] = (-bs[0]); solnam[7] = '4'; mk_rcc(fpw, solnam, bs, ht, rad); bs[2] = (-bs[2]); solnam[7] = '5'; mk_rcc(fpw, solnam, bs, ht, rad); bs[0] = (fastf_t)(dpt / 2.0 - rds); bs[1] = (fastf_t)(wid / 2.0 - rds); bs[2] = (fastf_t)(hgt / 2.0 - rds); ht[0] = (fastf_t)(0.0); ht[1] = (fastf_t)(0.0); ht[2] = (fastf_t)(-hgt + 2 * rds); solnam[7] = '6'; mk_rcc(fpw, solnam, bs, ht, rad); bs[1] = (-bs[1]); solnam[7] = '7'; mk_rcc(fpw, solnam, bs, ht, rad); bs[0] = (-bs[0]); solnam[7] = '8'; mk_rcc(fpw, solnam, bs, ht, rad); bs[1] = (-bs[1]); solnam[7] = '9'; mk_rcc(fpw, solnam, bs, ht, rad); bs[0] = (fastf_t)(dpt / 2.0 - rds); bs[1] = (fastf_t)(wid / 2.0 - rds); bs[2] = (fastf_t)(hgt / 2.0 - rds); ht[0] = (fastf_t)(-dpt + 2 * rds); ht[1] = (fastf_t)(0.0); ht[2] = (fastf_t)(0.0); solnam[6] = '2'; solnam[7] = '0'; mk_rcc(fpw, solnam, bs, ht, rad); bs[2] = (-bs[2]); solnam[7] = '1'; mk_rcc(fpw, solnam, bs, ht, rad); bs[1] = (-bs[1]); solnam[7] = '2'; mk_rcc(fpw, solnam, bs, ht, rad); bs[2] = (-bs[2]); solnam[7] = '3'; mk_rcc(fpw, solnam, bs, ht, rad); /* Make all regions. */ /* Initialize list. */ BU_LIST_INIT(&comb.l); /* Region 1. */ solnam[5] = 97 + i; solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[5] = 97 + i; regnam[6] = '0'; regnam[7] = '1'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 2. */ solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '2'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 3. */ solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); regnam[7] = '3'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 4. */ solnam[7] = '4'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '6'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '0'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '4'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 5. */ solnam[6] = '0'; solnam[7] = '5'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '6'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '5'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 6. */ solnam[6] = '0'; solnam[7] = '6'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '7'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '6'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 7. */ solnam[6] = '0'; solnam[7] = '7'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '7'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '7'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 8. */ solnam[6] = '0'; solnam[7] = '8'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '5'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '9'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '0'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '8'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 9. */ solnam[6] = '0'; solnam[7] = '9'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '1'; solnam[7] = '4'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '9'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[7] = '9'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 10. */ solnam[6] = '1'; solnam[7] = '0'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[7] = '4'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '8'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '0'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 11. */ solnam[6] = '1'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[7] = '5'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '8'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[6] = '2'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '1'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 12. */ solnam[6] = '1'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '2'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 13. */ solnam[6] = '1'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '3'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 14. */ solnam[6] = '1'; solnam[7] = '4'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '4'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 15. */ solnam[6] = '1'; solnam[7] = '5'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '5'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 16. */ solnam[6] = '1'; solnam[7] = '6'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '6'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 17. */ solnam[6] = '1'; solnam[7] = '7'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '7'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 18. */ solnam[6] = '1'; solnam[7] = '8'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '8'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 19. */ solnam[6] = '1'; solnam[7] = '9'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '1'; regnam[7] = '9'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 20. */ solnam[6] = '2'; solnam[7] = '0'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '2'; regnam[7] = '0'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 21. */ solnam[6] = '2'; solnam[7] = '1'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '2'; regnam[7] = '1'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 22. */ solnam[6] = '2'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '2'; regnam[7] = '2'; mk_lfcomb(fpw, regnam, &comb, 1); /* Region 23. */ solnam[6] = '2'; solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_INTERSECT); solnam[6] = '0'; solnam[7] = '2'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); solnam[7] = '3'; (void)mk_addmember(solnam, &comb.l, NULL, WMOP_SUBTRACT); regnam[6] = '2'; regnam[7] = '3'; mk_lfcomb(fpw, regnam, &comb, 1); /* Create group. */ /* Initialize list. */ BU_LIST_INIT(&comb1.l); regnam[6] = '0'; regnam[7] = '1'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '2'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '3'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '4'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '5'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '6'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '7'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '8'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '9'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[6] = '1'; regnam[7] = '0'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '1'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '2'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '3'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '4'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '5'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '6'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '7'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '8'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '9'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[6] = '2'; regnam[7] = '0'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '1'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '2'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); regnam[7] = '3'; (void)mk_addmember(regnam, &comb1.l, NULL, WMOP_UNION); grpnam[3] = 97 + i; mk_lfcomb(fpw, grpnam, &comb1, 0); } /* START # 2 */ /* Close file. */ wdb_close(fpw); return 0; } /* END # 1 */
void Elbows(void) /* make a tubing elbow and fluid elbow */ { vect_t RN1, RN2; point_t pts[8]; fastf_t len; struct points *ptr; struct wmember head; if ( nothing || mitre ) return; if ( root == NULL ) return; BU_LIST_INIT(&head.l); ptr = root->next; while ( ptr->next != NULL ) { /* Make outside elbow solid */ if ( torus ) mk_tor( fdout, ptr->elbow, ptr->center, ptr->norm, ( MINR+1 )*radius, radius ); else if ( sphere ) mk_sph( fdout, ptr->elbow, ptr->p, radius ); if ( !cable ) /* Make inside elbow solid */ { if ( torus ) mk_tor( fdout, ptr->elbflu, ptr->center, ptr->norm, ( MINR+1 )*radius, radius-wall ); else if ( sphere ) mk_sph( fdout, ptr->elbflu, ptr->p, radius-wall ); } if ( torus ) /* Make ARB8 solid */ { len = ((MINR+2)*radius + delta) / cos( (pi-ptr->alpha)/4.0 ); /* vector from center of torus to rcc end */ VSUB2( RN1, ptr->p1, ptr->center ); VUNITIZE( RN1 ); /* unit vector */ /* beginning of next rcc */ VSUB2( RN2, ptr->p2, ptr->center ); VUNITIZE( RN2 ); /* and unitize again */ /* build the eight points for the ARB8 */ VJOIN1( pts[0], ptr->center, radius+delta, ptr->norm ); VJOIN1( pts[1], pts[0], len, RN1 ); VJOIN1( pts[2], pts[0], -len, ptr->nmitre ); VJOIN1( pts[3], pts[0], len, RN2 ); VJOIN1( pts[4], ptr->center, -radius-delta, ptr->norm ); VJOIN1( pts[5], pts[4], len, RN1 ); VJOIN1( pts[6], pts[4], -len, ptr->nmitre ); VJOIN1( pts[7], pts[4], len, RN2 ); mk_arb8( fdout, ptr->cut, &pts[0][X] ); } if ( torus ) { mk_addmember( ptr->elbow, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ if ( !cable ) mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_SUBTRACT ); /* make '-' member record */ mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT ); mk_lfcomb( fdout, ptr->elbow_r, &head, REGION ); /* make REGION comb record */ if ( !cable ) { mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ mk_addmember( ptr->cut, &head.l, NULL, WMOP_INTERSECT ); mk_lfcomb( fdout, ptr->elbflu_r, &head, REGION ); /* make REGION comb record */ } } else if ( sphere ) { mk_addmember( ptr->elbow, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ if ( !cable ) mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_SUBTRACT ); /* make '-' member record */ mk_addmember( ptr->tube, &head.l, NULL, WMOP_SUBTRACT ); mk_addmember( ptr->prev->tube, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->elbow_r, &head, REGION ); /* make REGION comb record */ if ( !cable ) { mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_UNION ); /* make 'u' member record */ mk_addmember( ptr->tube, &head.l, NULL, WMOP_SUBTRACT ); mk_addmember( ptr->prev->tube, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( fdout, ptr->elbflu_r, &head, REGION ); /* make REGION comb record */ } } ptr = ptr->next; } }
/* * G E T S O L I D * * Returns - * -1 error * 0 conversion OK * 1 EOF */ int getsolid(void) { char given_solid_num[16]; char solid_type[16]; int i; double r1, r2; vect_t work; double m1, m2; /* Magnitude temporaries */ char *name=NULL; double dd[4*6]; /* 4 cards of 6 nums each */ point_t tmp[8]; /* 8 vectors of 3 nums each */ int ret; #define D(_i) (&(dd[_i*3])) #define T(_i) (&(tmp[_i][0])) if ( (i = get_line( scard, sizeof(scard), "solid card" )) == EOF ) { printf("getsolid: unexpected EOF\n"); return( 1 ); } switch ( version ) { case 5: bu_strlcpy( given_solid_num, scard+0, sizeof(given_solid_num) ); given_solid_num[5] = '\0'; bu_strlcpy( solid_type, scard+5, sizeof(solid_type) ); solid_type[5] = '\0'; break; case 4: bu_strlcpy( given_solid_num, scard+0, sizeof(given_solid_num) ); given_solid_num[3] = '\0'; bu_strlcpy( solid_type, scard+3, sizeof(solid_type) ); solid_type[7] = '\0'; break; case 1: /* DoE/MORSE version, believed to be original MAGIC format */ bu_strlcpy( given_solid_num, scard+5, sizeof(given_solid_num) ); given_solid_num[4] = '\0'; bu_strlcpy( solid_type, scard+2, sizeof(solid_type) ); break; default: fprintf(stderr, "getsolid() version %d unimplemented\n", version); bu_exit(1, NULL); break; } /* Trim trailing spaces */ trim_trail_spaces( given_solid_num ); trim_trail_spaces( solid_type ); /* another solid - increment solid counter * rather than using number from the card, which may go into * pseudo-hex format in version 4 models (due to 3 column limit). */ sol_work++; if ( version == 5 ) { if ( (i = getint( scard, 0, 5 )) != sol_work ) { printf("expected solid card %d, got %d, abort\n", sol_work, i ); return(1); } } /* Reduce solid type to lower case */ { register char *cp; register char c; cp = solid_type; while ( (c = *cp) != '\0' ) { if ( !isascii(c) ) { *cp++ = '?'; } else if ( isupper(c) ) { *cp++ = tolower(c); } else { cp++; } } } namecvt( sol_work, &name, 's' ); if (verbose) col_pr( name ); if ( strcmp( solid_type, "end" ) == 0 ) { /* DoE/MORSE version 1 format */ bu_free( name, "name" ); return(1); /* END */ } if ( strcmp( solid_type, "ars" ) == 0 ) { int ncurves; int pts_per_curve; double **curve; ncurves = getint( scard, 10, 10 ); pts_per_curve = getint( scard, 20, 10 ); /* Allocate curves pointer array */ curve = (double **)bu_malloc((ncurves+1)*sizeof(double *), "curve"); /* Allocate space for a curve, and read it in */ for ( i=0; i<ncurves; i++ ) { curve[i] = (double *)bu_malloc((pts_per_curve+1)*3*sizeof(double), "curve[i]" ); /* Get data for this curve */ if ( getxsoldata( curve[i], pts_per_curve*3, sol_work ) < 0 ) { printf("ARS %d: getxsoldata failed, curve %d\n", sol_work, i); return(-1); } } if ( (ret = mk_ars( outfp, name, ncurves, pts_per_curve, curve )) < 0 ) { printf("mk_ars(%s) failed\n", name ); /* Need to free memory; 'ret' is returned below */ } for ( i=0; i<ncurves; i++ ) { bu_free( (char *)curve[i], "curve[i]" ); } bu_free( (char *)curve, "curve" ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "rpp" ) == 0 ) { double min[3], max[3]; if ( getsoldata( dd, 2*3, sol_work ) < 0 ) return(-1); VSET( min, dd[0], dd[2], dd[4] ); VSET( max, dd[1], dd[3], dd[5] ); ret = mk_rpp( outfp, name, min, max ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "box" ) == 0 ) { if ( getsoldata( dd, 4*3, sol_work ) < 0 ) return(-1); VMOVE( T(0), D(0) ); VADD2( T(1), D(0), D(2) ); VADD3( T(2), D(0), D(2), D(1) ); VADD2( T(3), D(0), D(1) ); VADD2( T(4), D(0), D(3) ); VADD3( T(5), D(0), D(3), D(2) ); VADD4( T(6), D(0), D(3), D(2), D(1) ); VADD3( T(7), D(0), D(3), D(1) ); ret = mk_arb8( outfp, name, &tmp[0][X] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "raw" ) == 0 || strcmp( solid_type, "wed" ) == 0 /* DoE name */ ) { if ( getsoldata( dd, 4*3, sol_work ) < 0 ) return(-1); VMOVE( T(0), D(0) ); VADD2( T(1), D(0), D(2) ); VMOVE( T(2), T(1) ); VADD2( T(3), D(0), D(1) ); VADD2( T(4), D(0), D(3) ); VADD3( T(5), D(0), D(3), D(2) ); VMOVE( T(6), T(5) ); VADD3( T(7), D(0), D(3), D(1) ); ret = mk_arb8( outfp, name, &tmp[0][X] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "rvw" ) == 0 ) { /* Right Vertical Wedge (Origin: DoE/MORSE) */ double a2, theta, phi, h2; double a2theta; double angle1, angle2; vect_t a, b, c; if ( getsoldata( dd, 1*3+4, sol_work ) < 0 ) return(-1); a2 = dd[3]; /* XY side length */ theta = dd[4]; phi = dd[5]; h2 = dd[6]; /* height in +Z */ angle1 = (phi+theta-90) * bn_degtorad; angle2 = (phi+theta) * bn_degtorad; a2theta = a2 * tan(theta * bn_degtorad); VSET( a, a2theta*cos(angle1), a2theta*sin(angle1), 0 ); VSET( b, -a2*cos(angle2), -a2*sin(angle2), 0 ); VSET( c, 0, 0, h2 ); VSUB2( T(0), D(0), b ); VMOVE( T(1), D(0) ); VMOVE( T(2), D(0) ); VADD2( T(3), T(0), a ); VADD2( T(4), T(0), c ); VADD2( T(5), T(1), c ); VMOVE( T(6), T(5) ); VADD2( T(7), T(3), c ); ret = mk_arb8( outfp, name, &tmp[0][X] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arw" ) == 0) { /* ARbitrary Wedge --- ERIM */ if ( getsoldata( dd, 4*3, sol_work ) < 0) return(-1); VMOVE( T(0), D(0) ); VADD2( T(1), D(0), D(2) ); VADD3( T(2), D(0), D(2), D(3) ); VADD2( T(3), D(0), D(3) ); VADD2( T(4), D(0), D(1) ); VMOVE( T(5), T(4) ); VADD3( T(6), D(0), D(1), D(3) ); VMOVE( T(7), T(6) ); ret = mk_arb8( outfp, name, &tmp[0][X]); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arb8" ) == 0 ) { if ( getsoldata( dd, 8*3, sol_work ) < 0 ) return(-1); ret = mk_arb8( outfp, name, dd ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arb7" ) == 0 ) { if ( getsoldata( dd, 7*3, sol_work ) < 0 ) return(-1); VMOVE( D(7), D(4) ); ret = mk_arb8( outfp, name, dd ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arb6" ) == 0 ) { if ( getsoldata( dd, 6*3, sol_work ) < 0 ) return(-1); /* Note that the ordering is important, as data is in D(4), D(5) */ VMOVE( D(7), D(5) ); VMOVE( D(6), D(5) ); VMOVE( D(5), D(4) ); ret = mk_arb8( outfp, name, dd ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arb5" ) == 0 ) { if ( getsoldata( dd, 5*3, sol_work ) < 0 ) return(-1); VMOVE( D(5), D(4) ); VMOVE( D(6), D(4) ); VMOVE( D(7), D(4) ); ret = mk_arb8( outfp, name, dd ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arb4" ) == 0 ) { if ( getsoldata( dd, 4*3, sol_work ) < 0 ) return(-1); ret = mk_arb4( outfp, name, dd ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "rcc" ) == 0 ) { /* V, H, r */ if ( getsoldata( dd, 2*3+1, sol_work ) < 0 ) return(-1); ret = mk_rcc( outfp, name, D(0), D(1), dd[6] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "rec" ) == 0 ) { /* V, H, A, B */ if ( getsoldata( dd, 4*3, sol_work ) < 0 ) return(-1); ret = mk_tgc( outfp, name, D(0), D(1), D(2), D(3), D(2), D(3) ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "trc" ) == 0 ) { /* V, H, r1, r2 */ if ( getsoldata( dd, 2*3+2, sol_work ) < 0 ) return(-1); ret = mk_trc_h( outfp, name, D(0), D(1), dd[6], dd[7] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "tec" ) == 0 ) { /* V, H, A, B, p */ if ( getsoldata( dd, 4*3+1, sol_work ) < 0 ) return(-1); r1 = 1.0/dd[12]; /* P */ VSCALE( D(4), D(2), r1 ); VSCALE( D(5), D(3), r1 ); ret = mk_tgc( outfp, name, D(0), D(1), D(2), D(3), D(4), D(5) ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "tgc" ) == 0 ) { /* V, H, A, B, r1, r2 */ if ( getsoldata( dd, 4*3+2, sol_work ) < 0 ) return(-1); r1 = dd[12] / MAGNITUDE( D(2) ); /* A/|A| * C */ r2 = dd[13] / MAGNITUDE( D(3) ); /* B/|B| * D */ VSCALE( D(4), D(2), r1 ); VSCALE( D(5), D(3), r2 ); ret = mk_tgc( outfp, name, D(0), D(1), D(2), D(3), D(4), D(5) ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "sph" ) == 0 ) { /* V, radius */ if ( getsoldata( dd, 1*3+1, sol_work ) < 0 ) return(-1); ret = mk_sph( outfp, name, D(0), dd[3] ); bu_free( name, "name" ); return(ret); } if ( strncmp( solid_type, "wir", 3 ) == 0 ) { int numpts; /* points per wire */ int num; int i; double dia; double *pts; /* 3 entries per pt */ struct wdb_pipept *ps; struct bu_list head; /* allow a whole struct for head */ /* This might be getint( solid_type, 3, 2 ); for non-V5 */ numpts = getint( scard, 8, 2 ); num = numpts * 3 + 1; /* 3 entries per pt */ /* allocate space for the points array */ pts = ( double *)bu_malloc(num * sizeof( double), "pts" ); if ( getsoldata( pts, num, sol_work ) < 0 ) { return(-1); } dia = pts[num-1] * 2.0; /* radius X 2.0 == diameter */ /* allocate nodes on a list and store all information in * the appropriate location. */ BU_LIST_INIT( &head ); for ( i = 0; i < numpts; i++ ) { /* malloc a new structure */ ps = (struct wdb_pipept *)bu_malloc(sizeof( struct wdb_pipept), "ps"); ps->l.magic = WDB_PIPESEG_MAGIC; VMOVE( ps->pp_coord, &pts[i*3]); /* 3 pts at a time */ ps->pp_id = 0; /* solid */ ps->pp_od = dia; ps->pp_bendradius = dia; BU_LIST_INSERT( &head, &ps->l ); } if ( mk_pipe( outfp, name, &head ) < 0 ) return(-1); mk_pipe_free( &head ); bu_free( name, "name" ); return(0); /* OK */ } if ( strcmp( solid_type, "rpc" ) == 0 ) { /* V, H, B, r */ if ( getsoldata( dd, 3*3+1, sol_work ) < 0 ) return(-1); ret = mk_rpc( outfp, name, D(0), D(1), D(2), dd[9] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "rhc" ) == 0 ) { /* V, H, B, r, c */ if ( getsoldata( dd, 3*3+2, sol_work ) < 0 ) return(-1); ret = mk_rhc( outfp, name, D(0), D(1), D(2), dd[9], dd[10] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "epa" ) == 0 ) { /* V, H, Au, r1, r2 */ if ( getsoldata( dd, 3*3+2, sol_work ) < 0 ) return(-1); ret = mk_epa( outfp, name, D(0), D(1), D(2), dd[9], dd[10] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "ehy" ) == 0 ) { /* V, H, Au, r1, r2, c */ if ( getsoldata( dd, 3*3+3, sol_work ) < 0 ) return(-1); ret = mk_ehy( outfp, name, D(0), D(1), D(2), dd[9], dd[10], dd[11] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "eto" ) == 0 ) { /* V, N, C, r, rd */ if ( getsoldata( dd, 3*3+2, sol_work ) < 0 ) return(-1); ret = mk_eto( outfp, name, D(0), D(1), D(2), dd[9], dd[10] ); bu_free( name, "name" ); return(ret); } if ( version <= 4 && strcmp( solid_type, "ell" ) == 0 ) { /* Foci F1, F2, major axis length L */ vect_t v; /* * For simplicity, we convert ELL to ELL1, then * fall through to ELL1 code. * Format of ELL is F1, F2, len * ELL1 format is V, A, r */ if ( getsoldata( dd, 2*3+1, sol_work ) < 0 ) return(-1); VADD2SCALE( v, D(0), D(1), 0.5 ); /* V is midpoint */ VSUB2( work, D(1), D(0) ); /* work holds F2 - F1 */ m1 = MAGNITUDE( work ); r2 = 0.5 * dd[6] / m1; VSCALE( D(1), work, r2 ); /* A */ dd[6] = sqrt( MAGSQ( D(1) ) - (m1 * 0.5)*(m1 * 0.5) ); /* r */ VMOVE( D(0), v ); goto ell1; } if ( (version == 5 && strcmp( solid_type, "ell" ) == 0) || strcmp( solid_type, "ell1" ) == 0 ) { /* V, A, r */ /* GIFT4 name is "ell1", GIFT5 name is "ell" */ if ( getsoldata( dd, 2*3+1, sol_work ) < 0 ) return(-1); ell1: r1 = dd[6]; /* R */ VMOVE( work, D(0) ); work[0] += bn_pi; work[1] += bn_pi; work[2] += bn_pi; VCROSS( D(2), work, D(1) ); m1 = r1/MAGNITUDE( D(2) ); VSCALE( D(2), D(2), m1 ); VCROSS( D(3), D(1), D(2) ); m2 = r1/MAGNITUDE( D(3) ); VSCALE( D(3), D(3), m2 ); /* Now we have V, A, B, C */ ret = mk_ell( outfp, name, D(0), D(1), D(2), D(3) ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "ellg" ) == 0 ) { /* V, A, B, C */ if ( getsoldata( dd, 4*3, sol_work ) < 0 ) return(-1); ret = mk_ell( outfp, name, D(0), D(1), D(2), D(3) ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "tor" ) == 0 ) { /* V, N, r1, r2 */ if ( getsoldata( dd, 2*3+2, sol_work ) < 0 ) return(-1); ret = mk_tor( outfp, name, D(0), D(1), dd[6], dd[7] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "haf" ) == 0 ) { /* N, d */ if ( getsoldata( dd, 1*3+1, sol_work ) < 0 ) return(-1); ret = mk_half( outfp, name, D(0), -dd[3] ); bu_free( name, "name" ); return(ret); } if ( strcmp( solid_type, "arbn" ) == 0 ) { ret = read_arbn( name ); bu_free( name, "name" ); } /* * The solid type string is defective, * or that solid is not currently supported. */ printf("getsolid: no support for solid type '%s'\n", solid_type ); return(-1); }
int 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; }
/** * 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"); }