void writeArb8
(
    rt_wdb* wdbp,
    Form&   form,
    bool    translate
) {
    char    name[NAMELEN + 1];
    point_t shuffle[8];

    if (translate) {
      VADD2(shuffle[0], form.data.pt[0], form.tr_vec);
      VADD2(shuffle[1], form.data.pt[7], form.tr_vec);
      VADD2(shuffle[2], form.data.pt[3], form.tr_vec);
      VADD2(shuffle[3], form.data.pt[1], form.tr_vec);
      VADD2(shuffle[4], form.data.pt[6], form.tr_vec);
      VADD2(shuffle[5], form.data.pt[5], form.tr_vec);
      VADD2(shuffle[6], form.data.pt[4], form.tr_vec);
      VADD2(shuffle[7], form.data.pt[2], form.tr_vec);
    } else {
      VMOVE(shuffle[0], form.data.pt[0]);
      VMOVE(shuffle[1], form.data.pt[7]);
      VMOVE(shuffle[2], form.data.pt[3]);
      VMOVE(shuffle[3], form.data.pt[1]);
      VMOVE(shuffle[4], form.data.pt[6]);
      VMOVE(shuffle[5], form.data.pt[5]);
      VMOVE(shuffle[6], form.data.pt[4]);
      VMOVE(shuffle[7], form.data.pt[2]);
    }

    for (size_t i = 0; i < 8; ++i) {
      VSCALE(shuffle[i], shuffle[i], IntavalUnitInMm);
    }

    sprintf(name, "s%lu.arb8", (long unsigned)++arb8_counter);
    mk_arb8(wdbp, name, reinterpret_cast<fastf_t*>(shuffle));
    addToRegion(form.compnr, name);

    if (form.s_compnr >= 1000)
	excludeFromRegion(form.s_compnr, name);
}
Ejemplo n.º 2
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 */
Ejemplo n.º 3
0
void
Elbows(void)	/* make a tubing elbow and fluid elbow */
{
    vect_t RN1, RN2;
    point_t pts[8];
    fastf_t len;
    struct points *ptr;
    struct wmember head;

    if ( nothing || mitre )
	return;

    if ( root == NULL )
	return;

    BU_LIST_INIT(&head.l);

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

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

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

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

	    /* build the eight points for the ARB8 */

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

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

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

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

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

	    if ( !cable )
	    {
		mk_addmember( ptr->elbflu, &head.l, NULL, WMOP_UNION );	/* make 'u' member record	*/
		mk_addmember( ptr->tube, &head.l, NULL, WMOP_SUBTRACT );
		mk_addmember( ptr->prev->tube, &head.l, NULL, WMOP_SUBTRACT );
		mk_lfcomb( fdout, ptr->elbflu_r, &head, REGION );		/* make REGION comb record	*/
	    }
	}
	ptr = ptr->next;
    }
}
Ejemplo n.º 4
0
/*
 *			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);
}
Ejemplo n.º 5
0
int
block(int entityno)
{

    fastf_t xscale = 0.0;
    fastf_t yscale = 0.0;
    fastf_t zscale = 0.0;
    fastf_t x_1, y_1, z_1;		/* First vertex components */
    fastf_t x_2, y_2, z_2;		/* xdir vector components */
    fastf_t x_3, y_3, z_3;		/* zdir vector components */
    point_t v;			/* the first vertex */
    vect_t xdir;			/* a unit vector */
    vect_t xvec;			/* vector along x-axis */
    vect_t ydir;			/* a unit vector */
    vect_t yvec;			/* vector along y-axis */
    vect_t zdir;			/* a unit vector */
    vect_t zvec;			/* vector along z-axis */
    point_t pts[9];			/* array of points */
    int sol_num;		/* IGES solid type number */

    /* Default values */
    x_1 = 0.0;
    y_1 = 0.0;
    z_1 = 0.0;
    x_2 = 1.0;
    y_2 = 0.0;
    z_2 = 0.0;
    x_3 = 0.0;
    y_3 = 0.0;
    z_3 = 1.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(&xscale, "");
    Readcnv(&yscale, "");
    Readcnv(&zscale, "");
    Readcnv(&x_1, "");
    Readcnv(&y_1, "");
    Readcnv(&z_1, "");
    Readflt(&x_2, "");
    Readflt(&y_2, "");
    Readflt(&z_2, "");
    Readflt(&x_3, "");
    Readflt(&y_3, "");
    Readflt(&z_3, "");

    if (xscale <= 0.0 || yscale <= 0.0 || zscale <= 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 vertices for the bottom and top faces are found.  Point
     * is located in the lower left corner of the solid, and the vertices are
     * counted in the counter-clockwise direction, around the bottom face.
     * Next these vertices are extruded to form the top face.  The points
     * thus made are loaded into an array of points and handed off to mk_arb8().
     * Make and unitize necessary vectors.
     */

    VSET(xdir, x_2, y_2, z_2);			/* Makes x-dir vector */
    VUNITIZE(xdir);
    VSET(zdir, x_3, y_3, z_3);			/* Make z-dir vector */
    VUNITIZE(zdir);
    VCROSS(ydir, zdir, xdir);		/* Make y-dir vector */

    /* Scale all vectors */

    VSCALE(xvec, xdir, xscale);
    VSCALE(zvec, zdir, zscale);
    VSCALE(yvec, ydir, yscale);

    /* Make the bottom face. */

    VSET(v, x_1, y_1, z_1);			/* Yields first vertex */
    VMOVE(pts[0], v);			/* put first vertex into array */
    VADD2(pts[1], v, xvec);			/* Finds second vertex */
    VADD3(pts[2], v, xvec, yvec);		/* Finds third vertex */
    VADD2(pts[3], v, yvec);			/* Finds fourth vertex */

    /* Now extrude the bottom face to make the top.
     */

    VADD2(pts[4], v, zvec);			/* Finds fifth vertex */
    VADD2(pts[5], pts[1], zvec);		/* Finds sixth vertex */
    VADD2(pts[6], pts[2], zvec);		/* Finds seventh vertex */
    VADD2(pts[7], pts[3], zvec);		/* Find eighth vertex */


    /* Now the information is handed off to mk_arb8(). */

    mk_arb8(fdout, dir[entityno]->name, &pts[0][X]);

    return 1;


}