Exemplo n.º 1
0
int
parse_args(int ac, char **av)
{
    int c;

    if (! (progname=strrchr(*av, '/')))
	progname = *av;
    else
	++progname;

    bu_strlcpy(plotfilename, progname, sizeof(plotfilename));
    bu_strlcat(plotfilename, ".plot3", sizeof(plotfilename));

    bu_strlcpy(mfilename, progname, sizeof(mfilename));
    bu_strlcat(mfilename, ".g", sizeof(mfilename));

    /* get all the option flags from the command line */
    while ((c=bu_getopt(ac, av, options)) != -1)
	switch (c) {
	    case '3'	: manifold[3] = 0; break;
	    case '2'	: manifold[2] = 0; break;
	    case '1'	: manifold[1] = 0; break;
	    case '0'	: manifold[0] = 0; break;
	    default		: usage((char *)NULL,1); break;
	}

    return bu_optind;
}
Exemplo n.º 2
0
void
bn_mat_print_guts(
    const char *title,
    const mat_t m,
    char *obuf,
    int len)
{
    register int i;
    register char *cp;

    snprintf(obuf, len, "MATRIX %s:\n  ", title);
    cp = obuf + strlen(obuf);
    if (!m) {
	bu_strlcat(obuf, "(Identity)", len);
    } else {
	for (i = 0; i < 16; i++) {
	    snprintf(cp, len - (cp - obuf), " %8.3f", m[i]);
	    cp += strlen(cp);
	    if (i == 15) {
		break;
	    } else if ((i & 3) == 3) {
		*cp++ = '\n';
		*cp++ = ' ';
		*cp++ = ' ';
	    }
	}
	*cp++ = '\0';
    }
}
Exemplo n.º 3
0
int output_torii(const char *fileName, int levels, const torusLevels_t torii, const char *name) {
    char scratch[256];

    bu_strlcpy(scratch, name, sizeof(scratch));
    bu_strlcat(scratch, "_0", sizeof(scratch));

    bu_log("output_torii to file \"%s\" for %d levels using \"%s.c\" as the combination name", fileName, levels, name);

    return 0;
}
Exemplo n.º 4
0
void addtext(struct frame *fp, char *tp)
{
    char *p;
    int length;

#ifdef DEBUG
    fprintf(stderr, "addtext: %s\n", tp);
#endif

    BU_CKMAG(&(fp->l.magic), MAGIC, "frame magic");

    length = strlen(tp) + 1;	/* length of text string and NULL */
    length += 1;			/* For the Space or newline */
    if (fp->text) {
	length += fp->tp;
    }
    if (length > fp->tl || !fp->text) {
	fp->tl = (length/1024)*1024 + 1024;
	p = (char *) bu_malloc(fp->tl, "text area");
	*p = '\0';

	if (fp->text) {
	    bu_strlcpy(p, fp->text, fp->tl);
	    bu_free(fp->text, "text area");
	}
	fp->text = p;
    }
    bu_strlcat(&fp->text[fp->tp], tp, fp->tl);

    if (*tp == ';') {
	bu_strlcat(&fp->text[fp->tp], "\n", fp->tl);
    } else {
	bu_strlcat(&fp->text[fp->tp], " ", fp->tl);
    }

    fp->tp += strlen(tp)+1;
}
Exemplo n.º 5
0
void
crname(char *name, int pos, int maxlen)
{
    int i, j;
    char temp[4];

    j=1;
    if ( (i = Trackpos + pos) > 9 )
	j = 2;
    if ( i > 99 )
	j = 3;
    itoa(i, temp, j);
    bu_strlcat(name, temp, maxlen);
    return;
}
Exemplo n.º 6
0
void
Make_name(char *ptr, const char *form, const char *base, int number)
{

    char scrat[NAMESIZE];
    int len;

    bu_strlcpy( ptr, base, NAMESIZE );
    snprintf( scrat, NAMESIZE, form, number );

    len = strlen( ptr ) + strlen( scrat );
    if ( len > (NAMESIZE-1) )
	ptr[ (NAMESIZE-1) - strlen( scrat ) ] = '\0';

    bu_strlcat( ptr, scrat, NAMESIZE );
}
static long
read_Cell_Data(void)
{
    static char linebuf[MAX_LINE];
    static char *lbp = NULL;
    static char format[MAX_LINE];
    int state = STATE_VIEW_TOP;
    int i;
    Cell *gp = grid;
    int view_ct = 1;

    /*
     * First time through...
     * 1) initialize line-buffer pointer and try to fill the line buffer
     * 2) build the format for sscanf()
     */
    if (lbp == NULL) {
	lbp = linebuf;
	bu_fgets(lbp, MAX_LINE, filep);
	bu_strlcpy(format, "%lf %lf", sizeof(format));
	if (color_flag)
	    bu_strlcat(format, " %d %d %d", sizeof(format));
	else {
	    /* Skip to field of interest */
	    for (i = 1; i < field; i++)
		bu_strlcat(format, " %*lf", sizeof(format));
	    bu_strlcat(format, " %lf", sizeof(format));
	}
    }
    /* EOF encountered before we found the desired view? */
    if (feof(filep))
	return 0;

    /* Read the data */
    do {
	double x, y;
	int r, g, b;
	cell_val value;

	if (lbp[strlen(lbp) - 1] != '\n')
	    bu_exit (1, "Overlong line\n");

	/* Have we run out of room for the cells?  If so reallocate memory */
	if (gp - grid >= maxcells) {
	    long ncells = gp - grid;

	    maxcells *= 2;
	    grid = (Cell *) bu_realloc((char *) grid,
				       sizeof(Cell) * maxcells, "grid");
	    if (debug_flag & CFB_DBG_MEM)
		bu_log("cell-fb: maxcells increased to %ld\n", maxcells);
	    gp = grid + ncells;
	}
	/* Process any non-data (i.e. view-header) lines */
	while ((state != STATE_BEYOND_DATA) &&
	       ((color_flag &&
		 (sscanf(lbp, format, &x, &y, &r, &g, &b) != 5))
		|| (! color_flag &&
		    (sscanf(lbp, format, &x, &y, &value.v_scalar) != 3))))
	{
	    if (state == STATE_VIEW_TOP)
		state = STATE_IN_HEADER;
	    else if (state == STATE_IN_DATA)
		state = STATE_BEYOND_DATA;
	    if (feof(filep) || bu_fgets(lbp, MAX_LINE, filep) == NULL)
		return gp - grid;
	}
	/*
	 * At this point we know we have a line of cell data,
	 * though it might be the first line of the next view.
	 */
	if (state == STATE_BEYOND_DATA) {
	    state = STATE_VIEW_TOP;
	    if ((view_flag == 0) || (view_flag == view_ct++))
		return gp - grid;
	    else	/* Not the selected view, read the next one. */
		continue;
	} else
	    state = STATE_IN_DATA;

	/* If user has selected a view, only store values for that view. */
	if ((view_flag == 0) || (view_flag == view_ct)) {
	    MinMax(xmin, xmax, x);
	    MinMax(ymin, ymax, y);
	    if (debug_flag & CFB_DBG_MINMAX)
		bu_log("x=%g, y=%g, xmin=%g, xmax=%g, ymin=%g, ymax=%g\n",
		       x, y, xmin, xmax, ymin, ymax);
	    gp->c_x = x;
	    gp->c_y = y;
	    if (color_flag) {
		gp->c_val.v_color[RED] = r;
		gp->c_val.v_color[GRN] = g;
		gp->c_val.v_color[BLU] = b;
	    } else
		gp->c_val.v_scalar = value.v_scalar;
	    gp++;
	}
    } while (bu_fgets(lbp, MAX_LINE, filep) != NULL);
    return gp - grid;
}
void
Showtree(struct node *root)
{
    struct node *ptr;
    char *opa, *opb, *tmp, oper[4];

    bu_strlcpy(oper, "   ", sizeof(oper));

    /* initialize both stacks */
    Initastack();
    Initsstack();

    ptr = root;
    while (1) {
	while (ptr != NULL) {
	    Spush(ptr);
	    ptr = ptr->left;
	}
	ptr = Spop();

	if (ptr == NULL) {
	    bu_log("Error in Showtree: Popped a null pointer\n");
	    Afreestack();
	    Sfreestack();
	    return;
	}

	if (ptr->op < 0) /* this is an operand, push its name */
	    Apush(dir[-(1+ptr->op)/2]->name);
	else {
	    /* this is an operator */
	    size_t size;
	    /* Pop the names of the operands */
	    opb = Apop();
	    opa = Apop();

	    size = strlen(opa) + strlen(opb) + 6;

	    /* construct the character string (opa ptr->op opb) */
	    tmp = (char *)bu_malloc(size, "Showtree: tmp");
	    if (ptr->parent)
		bu_strlcpy(tmp, "(", size);
	    else
		*tmp = '\0';
	    bu_strlcat(tmp, opa, size);
	    oper[1] = operators[ptr->op];

	    bu_strlcat(tmp, oper, size);
	    bu_strlcat(tmp, opb, size);
	    if (ptr->parent)
		bu_strlcat(tmp, ")", size);

	    /* push the character string representing the result */
	    Apush(tmp);
	}

	if (ptr == root) {
	    /* done! */
	    bu_log("%s\n", Apop()); /* print the result */

	    /* free some memory */
	    Afreestack();
	    Sfreestack();
	    return;
	}

	if (ptr->parent) {
	  if (ptr != ptr->parent->right)
	    ptr = ptr->parent->right;
	  else
	    ptr = NULL;
	} else {
	  ptr = NULL;
	}
    }
}
Exemplo n.º 9
0
/*
 *			M A I N
 */
int
main(int argc, char **argv)
{
    char		*dot, *fig_file;
    register int	c;
    double		percent;
    int size;

    bu_setlinebuf( stderr );

    jack_tree_state = rt_initial_tree_state;	/* struct copy */
    jack_tree_state.ts_tol = &tol;
    jack_tree_state.ts_ttol = &ttol;
    jack_tree_state.ts_m = &the_model;

    ttol.magic = RT_TESS_TOL_MAGIC;
    /* Defaults, updated by command line options. */
    ttol.abs = 0.0;
    ttol.rel = 0.01;
    ttol.norm = 0.0;

    /* XXX These need to be improved */
    tol.magic = BN_TOL_MAGIC;
    tol.dist = 0.005;
    tol.dist_sq = tol.dist * tol.dist;
    tol.perp = 1e-6;
    tol.para = 1 - tol.perp;

    rt_init_resource( &rt_uniresource, 0, NULL );

    the_model = nmg_mm();
    BU_LIST_INIT( &rt_g.rtg_vlfree );	/* for vlist macros */

    /* Get command line arguments. */
    while ((c = bu_getopt(argc, argv, "a:dn:p:r:vx:P:X:")) != EOF) {
	switch (c) {
	    case 'a':		/* Absolute tolerance. */
		ttol.abs = atof(bu_optarg);
		break;
	    case 'd':
		debug_plots = 1;
		break;
	    case 'n':		/* Surface normal tolerance. */
		ttol.norm = atof(bu_optarg);
		break;
	    case 'p':		/* Prefix for Jack file names. */
		prefix = bu_optarg;
		break;
	    case 'r':		/* Relative tolerance. */
		ttol.rel = atof(bu_optarg);
		break;
	    case 'v':
		verbose++;
		break;
	    case 'P':
		ncpu = atoi( bu_optarg );
		rt_g.debug = 1;	/* XXX DEBUG_ALLRAYS -- to get core dumps */
		break;
	    case 'x':
		sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.debug );
		break;
	    case 'X':
		sscanf( bu_optarg, "%x", (unsigned int *)&rt_g.NMG_debug );
		NMG_debug = rt_g.NMG_debug;
		break;
	    default:
		bu_exit(1, usage, argv[0]);
		break;
	}
    }

    if (bu_optind+1 >= argc) {
	bu_exit(1, usage, argv[0]);
    }

    /* Open BRL-CAD database */
    argc -= bu_optind;
    argv += bu_optind;
    if ((dbip = db_open(argv[0], "r")) == DBI_NULL) {
	perror(argv[0]);
	bu_exit(1, "ERROR: Unable to open geometry database (%s)\n", argv[0]);
    }
    if ( db_dirbuild( dbip ) ) {
	bu_exit(1, "db_dirbuild failed\n" );
    }

    /* Create .fig file name and open it. */
    size = sizeof(prefix) + sizeof(argv[0] + 4);
    fig_file = bu_malloc(size, "st");
    /* Ignore leading path name. */
    if ((dot = strrchr(argv[0], '/')) != (char *)NULL) {
	if (prefix) {
	    snprintf(fig_file, size, "%s%s", prefix, 1+dot);
	} else {
	    snprintf(fig_file, size, "%s", 1+dot);
	}
    } else {
	if (prefix)
	    snprintf(fig_file, size, "%s%s", prefix, argv[0]);
	else
	    snprintf(fig_file, size, "%s", argv[0]);
    }

    /* Get rid of any file name extension (probably .g). */
    if ((dot = strrchr(fig_file, '.')) != (char *)NULL)
	*dot = '\0';
    bu_strlcat(fig_file, ".fig", size);	/* Add required Jack suffix. */

    if ((fp_fig = fopen(fig_file, "wb")) == NULL)
	perror(fig_file);
    fprintf(fp_fig, "figure {\n");
    bu_vls_init(&base_seg);		/* .fig figure file's main segment. */

    /* Walk indicated tree(s).  Each region will be output separately */
    (void)db_walk_tree(dbip, argc-1, (const char **)(argv+1),
		       1,			/* ncpu */
		       &jack_tree_state,
		       0,			/* take all regions */
		       do_region_end,
		       nmg_booltree_leaf_tess,
		       (genptr_t)NULL);	/* in librt/nmg_bool.c */

    fprintf(fp_fig, "\troot=%s_seg.base;\n", bu_vls_addr(&base_seg));
    fprintf(fp_fig, "}\n");
    fclose(fp_fig);
    bu_free(fig_file, "st");
    bu_vls_free(&base_seg);

    percent = 0;
    if (regions_tried>0)  percent = ((double)regions_done * 100) / regions_tried;
    printf("Tried %d regions, %d converted successfully.  %g%%\n",
	   regions_tried, regions_done, percent);

    return 0;
}
Exemplo n.º 10
0
/*
 *
 *	F _ A M T R A C K ( ) :	adds track given "wheel" info
 *
 */
int
f_amtrack(ClientData clientData, Tcl_Interp *interp, int argc, char **argv)
{

    fastf_t fw[3], lw[3], iw[3], dw[3], tr[3];
    char solname[12], regname[12], grpname[9], oper[3];
    int i, j, memb[4];
    char temp[4];
    vect_t	temp1, temp2;
    int item, mat, los;
    int arg;
    int edit_result;
    struct bu_list head;

    CHECK_DBI_NULL;
    CHECK_READ_ONLY;

    BU_LIST_INIT(&head);

    if (argc < 1 || 27 < argc) {
	struct bu_vls vls;

	bu_vls_init(&vls);
	bu_vls_printf(&vls, "help track");
	Tcl_Eval(interp, bu_vls_addr(&vls));
	bu_vls_free(&vls);
	return TCL_ERROR;
    }

    /* interupts */
    if ( setjmp( jmp_env ) == 0 )
	(void)signal( SIGINT, sig3);  /* allow interupts */
    else
	return TCL_OK;

    oper[0] = oper[2] = WMOP_INTERSECT;
    oper[1] = WMOP_SUBTRACT;

    arg = 1;

    /* get the roadwheel info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the FIRST roadwheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the LAST roadwheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    lw[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( fw[0] <= lw[0] ) {
	Tcl_AppendResult(interp, "First wheel after last wheel - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the roadwheels: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[1] = lw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the roadwheels: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    fw[2] = lw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( fw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	/* get the drive wheel info */
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[0] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( dw[0] >= lw[0] ) {
	Tcl_AppendResult(interp, "DRIVE wheel not in the rear - STOP \n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the drive (REAR) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    dw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( dw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    /* get the idler wheel info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter X of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[0] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( iw[0] <= fw[0] ) {
	Tcl_AppendResult(interp, "IDLER wheel not in the front - STOP \n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Z of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[1] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter radius of the idler (FRONT) wheel: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    iw[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( iw[2] <= 0 ) {
	Tcl_AppendResult(interp, "Radius <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    /* get track info */
    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Y-MIN of the track: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[2] = tr[0] = atof( argv[arg] ) * local2base;
    ++arg;

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter Y-MAX of the track: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[1] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( tr[0] == tr[1] ) {
	Tcl_AppendResult(interp, "MIN == MAX ... STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    if ( tr[0] > tr[1] ) {
	Tcl_AppendResult(interp, "MIN > MAX .... will switch\n", (char *)NULL);
	tr[1] = tr[0];
	tr[0] = tr[2];
    }

    if ( argc < arg+1 ) {
	Tcl_AppendResult(interp, MORE_ARGS_STR, "Enter track thickness: ",
			 (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }
    tr[2] = atof( argv[arg] ) * local2base;
    ++arg;
    if ( tr[2] <= 0 ) {
	Tcl_AppendResult(interp, "Track thickness <= 0 - STOP\n", (char *)NULL);
	edit_result = TCL_ERROR;
	goto end;
    }

    solname[0] = regname[0] = grpname[0] = 't';
    solname[1] = regname[1] = grpname[1] = 'r';
    solname[2] = regname[2] = grpname[2] = 'a';
    solname[3] = regname[3] = grpname[3] = 'c';
    solname[4] = regname[4] = grpname[4] = 'k';
    solname[5] = regname[5] = '.';
    solname[6] = 's';
    regname[6] = 'r';
    solname[7] = regname[7] = '.';
    grpname[5] = solname[8] = regname[8] = '\0';
    grpname[8] = solname[11] = regname[11] = '\0';
/*
  bu_log("\nX of first road wheel  %10.4f\n", fw[0]);
  bu_log("X of last road wheel   %10.4f\n", lw[0]);
  bu_log("Z of road wheels       %10.4f\n", fw[1]);
  bu_log("radius of road wheels  %10.4f\n", fw[2]);
  bu_log("\nX of drive wheel       %10.4f\n", dw[0]);
  bu_log("Z of drive wheel       %10.4f\n", dw[1]);
  bu_log("radius of drive wheel  %10.4f\n", dw[2]);
  bu_log("\nX of idler wheel       %10.4f\n", iw[0]);
  bu_log("Z of idler wheel       %10.4f\n", iw[1]);
  bu_log("radius of idler wheel  %10.4f\n", iw[2]);
  bu_log("\nY MIN of track         %10.4f\n", tr[0]);
  bu_log("Y MAX of track         %10.4f\n", tr[1]);
  bu_log("thickness of track     %10.4f\n", tr[2]);
*/

/* Check for names to use:
 *	1.  start with track.s.1->10 and track.r.1->10
 *	2.  if bad, increment count by 10 and try again
 */

 tryagain:	/* sent here to try next set of names */

    for (i=0; i<11; i++) {
	crname(solname, i, sizeof(solname));
	crname(regname, i, sizeof(regname));
	if (	(db_lookup( dbip, solname, LOOKUP_QUIET) != DIR_NULL)	||
		(db_lookup( dbip, regname, LOOKUP_QUIET) != DIR_NULL)	) {
	    /* name already exists */
	    solname[8] = regname[8] = '\0';
	    if ( (Trackpos += 10) > 500 ) {
		Tcl_AppendResult(interp, "Track: naming error -- STOP\n",
				 (char *)NULL);
		edit_result = TCL_ERROR;
		goto end;
	    }
	    goto tryagain;
	}
	solname[8] = regname[8] = '\0';
    }

    /* no interupts */
    (void)signal( SIGINT, SIG_IGN );

    /* find the front track slope to the idler */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;

    slope(fw, iw, tr);
    VMOVE(temp2, &sol.s_values[0]);
    crname(solname, 1, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;

    solname[8] = '\0';

    /* find track around idler */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    sol.s_type = ID_TGC;
    trcurve(iw, tr);
    crname(solname, 2, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj( solname, DIR_SOLID ) )
	return TCL_ERROR;
    solname[8] = '\0';
    /* idler dummy rcc */
    sol.s_values[6] = iw[2];
    sol.s_values[11] = iw[2];
    VMOVE(&sol.s_values[12], &sol.s_values[6]);
    VMOVE(&sol.s_values[15], &sol.s_values[9]);
    crname(solname, 3, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj( solname, DIR_SOLID ) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* find idler track dummy arb8 */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    crname(solname, 4, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    crdummy(iw, tr, 1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track slope to drive */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    slope(lw, dw, tr);
    VMOVE(temp1, &sol.s_values[0]);
    crname(solname, 5, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if (wrobj(solname, DIR_SOLID))
	return TCL_ERROR;
    solname[8] = '\0';

    /* track around drive */
    for (i=0; i<24; i++)
	sol.s_values[i] = 0.0;
    sol.s_type = ID_TGC;
    trcurve(dw, tr);
    crname(solname, 6, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* drive dummy rcc */
    sol.s_values[6] = dw[2];
    sol.s_values[11] = dw[2];
    VMOVE(&sol.s_values[12], &sol.s_values[6]);
    VMOVE(&sol.s_values[15], &sol.s_values[9]);
    crname(solname, 7, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* drive dummy arb8 */
    for (i=0; i<24; i++)
	sol.s_name[i] = 0.0;
    crname(solname, 8, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    sol.s_type = ID_ARB8;
    crdummy(dw, tr, 2);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track bottom */
    temp1[1] = temp2[1] = tr[0];
    bottom(temp1, temp2, tr);
    crname(solname, 9, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* track top */
    temp1[0] = dw[0];
    temp1[1] = temp2[1] = tr[0];
    temp1[2] = dw[1] + dw[2];
    temp2[0] = iw[0];
    temp2[2] = iw[1] + iw[2];
    top(temp1, temp2, tr);
    crname(solname, 10, sizeof(solname));
    bu_strlcpy(sol.s_name, solname, NAMESIZE+1);
    if ( wrobj(solname, DIR_SOLID) )
	return TCL_ERROR;
    solname[8] = '\0';

    /* add the regions */
    item = item_default;
    mat = mat_default;
    los = los_default;
    item_default = 500;
    mat_default = 1;
    los_default = 50;
    /* region 1 */
    memb[0] = 1;
    memb[1] = 4;
    crname(regname, 1, sizeof(regname));
    crregion(regname, oper, memb, 2, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 2 */
    crname(regname, 2, sizeof(regname));
    memb[0] = 2;
    memb[1] = 3;
    memb[2] = 4;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 5 */
    crname(regname, 5, sizeof(regname));
    memb[0] = 5;
    memb[1] = 8;
    crregion(regname, oper, memb, 2, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 6 */
    crname(regname, 6, sizeof(regname));
    memb[0] = 6;
    memb[1] = 7;
    memb[2] = 8;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 9 */
    crname(regname, 9, sizeof(regname));
    memb[0] = 9;
    memb[1] = 1;
    memb[2] = 5;
    oper[2] = WMOP_SUBTRACT;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* region 10 */
    crname(regname, 10, sizeof(regname));
    memb[0] = 10;
    memb[1] = 4;
    memb[2] = 8;
    crregion(regname, oper, memb, 3, solname, sizeof(regname));
    solname[8] = regname[8] = '\0';

    /* group all the track regions */
    j = 1;
    if ( (i = Trackpos / 10 + 1) > 9 )
	j = 2;
    itoa(i, temp, j);
    bu_strlcat(grpname, temp, sizeof(grpname));
    for (i=1; i<11; i++) {
	if ( i == 3 || i ==4 || i == 7 || i == 8 )
	    continue;
	regname[8] = '\0';
	crname(regname, i, sizeof(regname));
	if ( db_lookup( dbip, regname, LOOKUP_QUIET) == DIR_NULL ) {
	    Tcl_AppendResult(interp, "group: ", grpname, " will skip member: ",
			     regname, "\n", (char *)NULL);
	    continue;
	}
	mk_addmember( regname, &head, NULL, WMOP_UNION );
    }

    /* Add them all at once */
    if ( mk_comb( wdbp, grpname, &head,
		  0, NULL, NULL, NULL,
		  0, 0, 0, 0,
		  0, 1, 1 ) < 0 )
    {
	Tcl_AppendResult(interp,
			 "An error has occured while adding '",
			 grpname, "' to the database.\n", (char *)NULL);
    }

    /* draw this track */
    Tcl_AppendResult(interp, "The track regions are in group ", grpname,
		     "\n", (char *)NULL);
    {
	const char *arglist[3];
	arglist[0] = "e";
	arglist[1] = grpname;
	arglist[2] = NULL;
	edit_result = cmd_draw( clientData, interp, 2, arglist );
    }

    Trackpos += 10;
    item_default = item;
    mat_default = mat;
    los_default = los;
    grpname[5] = solname[8] = regname[8] = '\0';

    return edit_result;
 end:
    (void)signal( SIGINT, SIG_IGN );
    return edit_result;
}
Exemplo n.º 11
0
int
main(int argc, char **argv)
{
    int done;
    char units[16], fname[80];
    int optc;

    while ( (optc = bu_getopt( argc, argv, "tsmnc" )) != -1)
    {
	switch ( optc )	/* Set joint type and cable option */
	{
	    case 't':
		torus = 1;
		break;
	    case 's':
		sphere = 1;
		break;
	    case 'm':
		mitre = 1;
		break;
	    case 'n':
		nothing = 1;
		break;
	    case 'c':
		cable = 1;
		break;
	    case '?':
		fprintf( stderr, "Illegal option %c\n", optc );
		Usage();
		return 1;
		break;

	}
    }

    if ( (torus + sphere + mitre + nothing) > 1 ) /* Too many joint options */
    {
	Usage();
	fprintf( stderr, "Options t, s, m, n are mutually exclusive\n" );
	return 1;
    }
    else if ( (torus + sphere + mitre + nothing) == 0 ) {
	torus = 1;		/* default */
    }

    if ( (argc - bu_optind) != 2 ) {
	Usage();
	return 1;
    }

    bu_strlcpy( name, argv[bu_optind++], sizeof(name) ); /* Base name for objects */

    fdout = wdb_fopen( argv[bu_optind] );
    if ( fdout == NULL )
    {
	fprintf( stderr, "Cannot open %s\n", argv[bu_optind] );
	perror( "Pipe" );
	Usage();
	return 1;
    }

    MAT_IDN(identity);	/* Identity matrix for all objects */
    pi = atan2( 0.0, -1.0 );	/* PI */

    printf( "FLUID & PIPING V%d.%d 10 Mar 89\n\n", VERSION, RELEASE );
    printf( "append %s to your target description using 'concat' in mged\n", argv[bu_optind] );

    k = 0.0;
    while ( k == 0.0 )
    {
	printf( "UNITS? (ft, in, m, cm, default is millimeters) ");
	bu_fgets(units, sizeof(units), stdin);
	switch (units[0])
	{

	    case '\0':
		k = 1.0;
		break;

	    case 'f':
		k = 12*25.4;
		break;

	    case 'i':
		k=25.4;
		break;

	    case 'm':
		if ( units[1] == '\0') k=1000.0;
		else k=1.0;
		break;

	    case 'c':
		k=10.0;
		break;

	    default:
		k=0.0;
		printf( "\n\t%s is not a legal choice for units\n", units );
		printf( "\tTry again\n" );
		break;
	}
    }

    done = 0;
    while ( !done )
    {
	if ( !cable ) {
	    printf( "radius and wall thickness: ");
	    if (scanf("%lf %lf", &radius, &wall) == EOF )
		return 1;
	    if (radius > wall)
		done = 1;
	    else
	    {
		printf( " *** bad input!\n\n");
		printf( "\tradius must be larger than wall thickness\n" );
		printf( "\tTry again\n" );
	    }
	}
	else {
	    printf( "radius: ");
	    if ( scanf("%lf", &radius ) == EOF )
		return 1;
	    done=1;
	}
    }
    radius=k*radius;
    wall=k*wall;

    Readpoints();	/* Read data points */

    Names();	/* Construct names for all solids */

    Normals();	/* Calculate normals and other vectors */

    Adjust();       /* Adjust points to allow for elbows */

/*	Generate Title */

    bu_strlcpy(fname, name, sizeof(fname));

    if ( !cable )
	bu_strlcat(fname, " pipe and fluid", sizeof(fname));
    else
	bu_strlcat(fname, " cable", sizeof(fname));

/*	Create ident record	*/

    mk_id(fdout, fname);

    Pipes();	/* Construct the piping */

    Elbows();	/* Construct the elbow sections */

    Groups();	/* Make some groups */

    return 0;
}
Exemplo n.º 12
0
/*
 * F _ N I R T
 *
 * Invoke nirt with the current view & stuff
 */
int
dgo_nirt_cmd(struct dg_obj *dgop,
	     struct view_obj *vop,
	     int argc,
	     const char **argv)
{
    const char **vp;
    FILE *fp_in;
    FILE *fp_out, *fp_err;
#ifndef _WIN32
    int ret;
    size_t sret;
    int pid, rpid;
    int retcode;
    int pipe_in[2];
    int pipe_out[2];
    int pipe_err[2];
#else
    HANDLE pipe_in[2], pipe_inDup;
    HANDLE pipe_out[2], pipe_outDup;
    HANDLE pipe_err[2], pipe_errDup;
    STARTUPINFO si;
    PROCESS_INFORMATION pi;
    SECURITY_ATTRIBUTES sa;
    char name[1024];
    char line1[2048];
    int rem = 2048;
#endif
    int use_input_orig = 0;
    vect_t center_model;
    vect_t dir;
    vect_t cml;
    int i;
    struct solid *sp;
    char line[RT_MAXLINE];
    char *val;
    struct bu_vls vls = BU_VLS_INIT_ZERO;
    struct bu_vls o_vls = BU_VLS_INIT_ZERO;
    struct bu_vls p_vls = BU_VLS_INIT_ZERO;
    struct bu_vls t_vls = BU_VLS_INIT_ZERO;
    struct bn_vlblock *vbp;
    struct dg_qray_dataList *ndlp;
    struct dg_qray_dataList HeadQRayData;
    int args;

    args = argc + 20 + 2 + dgo_count_tops((struct solid *)&dgop->dgo_headSolid);
    dgop->dgo_rt_cmd = (char **)bu_calloc(args, sizeof(char *), "alloc dgo_rt_cmd");

    vp = (const char **)&dgop->dgo_rt_cmd[0];
    *vp++ = "nirt";

    /* swipe x, y, z off the end if present */
    if (argc > 3) {
	double scan[3];

	if (sscanf(argv[argc-3], "%lf", &scan[X]) == 1 &&
	    sscanf(argv[argc-2], "%lf", &scan[Y]) == 1 &&
	    sscanf(argv[argc-1], "%lf", &scan[Z]) == 1)
	{

	    VMOVE(center_model, scan);
	    use_input_orig = 1;
	    argc -= 3;
	    VSCALE(center_model, center_model, dgop->dgo_wdbp->dbip->dbi_local2base);
	}
    }

    /* Calculate point from which to fire ray */
    if (!use_input_orig) {
	VSET(center_model, -vop->vo_center[MDX],
	     -vop->vo_center[MDY], -vop->vo_center[MDZ]);
    }

    VSCALE(cml, center_model, dgop->dgo_wdbp->dbip->dbi_base2local);
    VMOVEN(dir, vop->vo_rotation + 8, 3);
    VSCALE(dir, dir, -1.0);

    bu_vls_printf(&p_vls, "xyz %lf %lf %lf;",
		  cml[X], cml[Y], cml[Z]);
    bu_vls_printf(&p_vls, "dir %lf %lf %lf; s",
		  dir[X], dir[Y], dir[Z]);

    i = 0;
    if (DG_QRAY_GRAPHICS(dgop)) {

	*vp++ = "-e";
	*vp++ = DG_QRAY_FORMAT_NULL;

	/* first ray ---- returns partitions */
	*vp++ = "-e";
	*vp++ = DG_QRAY_FORMAT_P;

	/* ray start, direction, and 's' command */
	*vp++ = "-e";
	*vp++ = bu_vls_addr(&p_vls);

	/* second ray ---- returns overlaps */
	*vp++ = "-e";
	*vp++ = DG_QRAY_FORMAT_O;

	/* ray start, direction, and 's' command */
	*vp++ = "-e";
	*vp++ = bu_vls_addr(&p_vls);

	if (DG_QRAY_TEXT(dgop)) {
	    char *cp;
	    int count = 0;

	    /* get 'r' format now; prepend its' format string with a newline */
	    val = bu_vls_addr(&dgop->dgo_qray_fmts[0].fmt);

	    /* find first '"' */
	    while (*val != '"' && *val != '\0')
		++val;

	    if (*val == '\0')
		goto done;
	    else
		++val;	    /* skip first '"' */

	    /* find last '"' */
	    cp = (char *)strrchr(val, '"');

	    if (cp != (char *)NULL) /* found it */
		count = cp - val;

	done:
	    if (*val == '\0')
		bu_vls_printf(&o_vls, " fmt r \"\\n\" ");
	    else {
		struct bu_vls tmp = BU_VLS_INIT_ZERO;
		bu_vls_strncpy(&tmp, val, count);
		bu_vls_printf(&o_vls, " fmt r \"\\n%V\" ", &tmp);
		bu_vls_free(&tmp);

		if (count)
		    val += count + 1;
		bu_vls_printf(&o_vls, "%s", val);
	    }

	    i = 1;

	    *vp++ = "-e";
	    *vp++ = bu_vls_addr(&o_vls);
	}
    }

    if (DG_QRAY_TEXT(dgop)) {

	/* load vp with formats for printing */
	for (; dgop->dgo_qray_fmts[i].type != (char)0; ++i)
	    bu_vls_printf(&t_vls, "fmt %c %s; ",
			  dgop->dgo_qray_fmts[i].type,
			  bu_vls_addr(&dgop->dgo_qray_fmts[i].fmt));

	*vp++ = "-e";
	*vp++ = bu_vls_addr(&t_vls);

	/* nirt does not like the trailing ';' */
	bu_vls_trunc(&t_vls, -2);
    }

    /* include nirt script string */
    if (bu_vls_strlen(&dgop->dgo_qray_script)) {
	*vp++ = "-e";
	*vp++ = bu_vls_addr(&dgop->dgo_qray_script);
    }

    *vp++ = "-e";
    *vp++ = bu_vls_addr(&p_vls);

    for (i = 1; i < argc; i++)
	*vp++ = argv[i];
    *vp++ = dgop->dgo_wdbp->dbip->dbi_filename;

    dgop->dgo_rt_cmd_len = (char **)vp - (char **)dgop->dgo_rt_cmd;

    /* Note - dgo_build_tops sets the last vp to (char *)0 */
    dgop->dgo_rt_cmd_len += dgo_build_tops((struct solid *)&dgop->dgo_headSolid,
					   vp,
					   (const char **)&dgop->dgo_rt_cmd[args]);

    if (dgop->dgo_qray_cmd_echo) {
	/* Print out the command we are about to run */
	vp = (const char **)&dgop->dgo_rt_cmd[0];
	while (*vp)
	    Tcl_AppendResult(dgop->interp, *vp++, " ", (char *)NULL);

	Tcl_AppendResult(dgop->interp, "\n", (char *)NULL);
    }

    if (use_input_orig) {
	bu_vls_printf(&vls, "\nFiring from (%lf, %lf, %lf)...\n",
		      center_model[X], center_model[Y], center_model[Z]);
	Tcl_AppendResult(dgop->interp, bu_vls_addr(&vls), (char *)NULL);
	bu_vls_free(&vls);
    } else
	Tcl_AppendResult(dgop->interp, "\nFiring from view center...\n", (char *)NULL);

#ifndef _WIN32
    ret = pipe(pipe_in);
    if (ret < 0)
	perror("pipe");
    ret = pipe(pipe_out);
    if (ret < 0)
	perror("pipe");
    ret = pipe(pipe_err);
    if (ret < 0)
	perror("pipe");
    (void)signal(SIGINT, SIG_IGN);
    if ((pid = fork()) == 0) {
	/* Redirect stdin, stdout, stderr */
	(void)close(0);
	ret = dup(pipe_in[0]);
	if (ret < 0)
	    perror("dup");
	(void)close(1);
	ret = dup(pipe_out[1]);
	if (ret < 0)
	    perror("dup");
	(void)close(2);
	ret = dup(pipe_err[1]);
	if (ret < 0)
	    perror("dup");

	/* close pipes */
	(void)close(pipe_in[0]);
	(void)close(pipe_in[1]);
	(void)close(pipe_out[0]);
	(void)close(pipe_out[1]);
	(void)close(pipe_err[0]);
	(void)close(pipe_err[1]);
	for (i = 3; i < 20; i++)
	    (void)close(i);
	(void)signal(SIGINT, SIG_DFL);
	(void)execvp(dgop->dgo_rt_cmd[0], dgop->dgo_rt_cmd);
	perror (dgop->dgo_rt_cmd[0]);
	exit(16);
    }

    /* use fp_in to feed view info to nirt */
    (void)close(pipe_in[0]);
    fp_in = fdopen(pipe_in[1], "w");

    /* use fp_out to read back the result */
    (void)close(pipe_out[1]);
    fp_out = fdopen(pipe_out[0], "r");

    /* use fp_err to read any error messages */
    (void)close(pipe_err[1]);
    fp_err = fdopen(pipe_err[0], "r");

    /* send quit command to nirt */
    sret = fwrite("q\n", 1, 2, fp_in);
    if (sret != 2)
	bu_log("fwrite failure\n");

    (void)fclose(fp_in);

#else
    memset((void *)&si, 0, sizeof(STARTUPINFO));
    memset((void *)&pi, 0, sizeof(PROCESS_INFORMATION));
    memset((void *)&sa, 0, sizeof(SECURITY_ATTRIBUTES));

    sa.nLength = sizeof(sa);
    sa.bInheritHandle = TRUE;
    sa.lpSecurityDescriptor = NULL;

    /* Create a pipe for the child process's STDOUT. */
    CreatePipe(&pipe_out[0], &pipe_out[1], &sa, 0);

    /* Create noninheritable read handle and close the inheritable read handle. */
    DuplicateHandle(GetCurrentProcess(), pipe_out[0],
		    GetCurrentProcess(),  &pipe_outDup ,
		    0,  FALSE,
		    DUPLICATE_SAME_ACCESS);
    CloseHandle(pipe_out[0]);

    /* Create a pipe for the child process's STDERR. */
    CreatePipe(&pipe_err[0], &pipe_err[1], &sa, 0);

    /* Create noninheritable read handle and close the inheritable read handle. */
    DuplicateHandle(GetCurrentProcess(), pipe_err[0],
		    GetCurrentProcess(),  &pipe_errDup ,
		    0,  FALSE,
		    DUPLICATE_SAME_ACCESS);
    CloseHandle(pipe_err[0]);

    /* The steps for redirecting child process's STDIN:
     *     1.  Save current STDIN, to be restored later.
     *     2.  Create anonymous pipe to be STDIN for child process.
     *     3.  Set STDIN of the parent to be the read handle to the
     *         pipe, so it is inherited by the child process.
     *     4.  Create a noninheritable duplicate of the write handle,
     *         and close the inheritable write handle.
     */

    /* Create a pipe for the child process's STDIN. */
    CreatePipe(&pipe_in[0], &pipe_in[1], &sa, 0);

    /* Duplicate the write handle to the pipe so it is not inherited. */
    DuplicateHandle(GetCurrentProcess(), pipe_in[1],
		    GetCurrentProcess(), &pipe_inDup,
		    0, FALSE,                  /* not inherited */
		    DUPLICATE_SAME_ACCESS);
    CloseHandle(pipe_in[1]);

    si.cb = sizeof(STARTUPINFO);
    si.lpReserved = NULL;
    si.lpReserved2 = NULL;
    si.cbReserved2 = 0;
    si.lpDesktop = NULL;
    si.dwFlags = STARTF_USESTDHANDLES | STARTF_USESHOWWINDOW;
    si.hStdInput   = pipe_in[0];
    si.hStdOutput  = pipe_out[1];
    si.hStdError   = pipe_err[1];
    si.wShowWindow = SW_HIDE;

    snprintf(line1, rem, "%s ", dgop->dgo_rt_cmd[0]);
    rem -= (int)strlen(line1) - 1;

    for (i = 1; i < dgop->dgo_rt_cmd_len; i++) {
	/* skip commands */
	if (strstr(dgop->dgo_rt_cmd[i], "-e") != NULL)
	    ++i;
	else {
	    /* append other arguments (i.e. options, file and obj(s)) */
	    snprintf(name, 1024, "\"%s\" ", dgop->dgo_rt_cmd[i]);
	    if (rem - strlen(name) < 1) {
		bu_log("Ran out of buffer space!");
		bu_free(dgop->dgo_rt_cmd, "free dgo_rt_cmd");
		dgop->dgo_rt_cmd = NULL;
		return TCL_ERROR;
	    }
	    bu_strlcat(line1, name, sizeof(line1));
	    rem -= (int)strlen(name);
	}
    }

    CreateProcess(NULL, line1, NULL, NULL, TRUE,
		  DETACHED_PROCESS, NULL, NULL,
		  &si, &pi);

    /* use fp_in to feed view info to nirt */
    CloseHandle(pipe_in[0]);
    fp_in = _fdopen(_open_osfhandle((intptr_t)pipe_inDup, _O_TEXT), "wb");
    setmode(fileno(fp_in), O_BINARY);

    /* send commands down the pipe */
    for (i = 1; i < dgop->dgo_rt_cmd_len-2; i++)
	if (strstr(dgop->dgo_rt_cmd[i], "-e") != NULL)
	    fprintf(fp_in, "%s\n", dgop->dgo_rt_cmd[++i]);

    /* use fp_out to read back the result */
    CloseHandle(pipe_out[1]);
    fp_out = _fdopen(_open_osfhandle((intptr_t)pipe_outDup, _O_TEXT), "rb");
    setmode(fileno(fp_out), O_BINARY);

    /* use fp_err to read any error messages */
    CloseHandle(pipe_err[1]);
    fp_err = _fdopen(_open_osfhandle((intptr_t)pipe_errDup, _O_TEXT), "rb");
    setmode(fileno(fp_err), O_BINARY);

    /* send quit command to nirt */
    fwrite("q\n", 1, 2, fp_in);
    (void)fclose(fp_in);

#endif

    bu_vls_free(&p_vls);   /* use to form "partition" part of nirt command above */
    if (DG_QRAY_GRAPHICS(dgop)) {
	double scan[4];

	if (DG_QRAY_TEXT(dgop))
	    bu_vls_free(&o_vls); /* used to form "overlap" part of nirt command above */

	BU_LIST_INIT(&HeadQRayData.l);

	/* handle partitions */
	while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL) {
	    if (line[0] == '\n') {
		Tcl_AppendResult(dgop->interp, line+1, (char *)NULL);
		break;
	    }

	    BU_ALLOC(ndlp, struct dg_qray_dataList);
	    BU_LIST_APPEND(HeadQRayData.l.back, &ndlp->l);

	    if (sscanf(line, "%le %le %le %le",
		       &scan[0], &scan[1], &scan[2], &scan[3]) != 4)
		break;
	    ndlp->x_in = scan[0];
	    ndlp->y_in = scan[1];
	    ndlp->z_in = scan[2];
	    ndlp->los = scan[3];
	}

	vbp = rt_vlblock_init();
	dgo_qray_data_to_vlist(dgop, vbp, &HeadQRayData, dir, 0);
	bu_list_free(&HeadQRayData.l);
	dgo_cvt_vlblock_to_solids(dgop, vbp, bu_vls_addr(&dgop->dgo_qray_basename), 0);
	rt_vlblock_free(vbp);

	/* handle overlaps */
	while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL) {
	    if (line[0] == '\n') {
		Tcl_AppendResult(dgop->interp, line+1, (char *)NULL);
		break;
	    }

	    BU_ALLOC(ndlp, struct dg_qray_dataList);
	    BU_LIST_APPEND(HeadQRayData.l.back, &ndlp->l);

	    if (sscanf(line, "%le %le %le %le",
		       &scan[0], &scan[1], &scan[2], &scan[3]) != 4)
		break;
	    ndlp->x_in = scan[0];
	    ndlp->y_in = scan[1];
	    ndlp->z_in = scan[2];
	    ndlp->los = scan[3];
	}
	vbp = rt_vlblock_init();
	dgo_qray_data_to_vlist(dgop, vbp, &HeadQRayData, dir, 1);
	bu_list_free(&HeadQRayData.l);
	dgo_cvt_vlblock_to_solids(dgop, vbp, bu_vls_addr(&dgop->dgo_qray_basename), 0);
	rt_vlblock_free(vbp);
    }

    /*
     * Notify observers, if any, before generating textual output since
     * such an act (observer notification) wipes out whatever gets stuffed
     * into the result.
     */
    dgo_notify(dgop);

    if (DG_QRAY_TEXT(dgop)) {
	bu_vls_free(&t_vls);

	while (bu_fgets(line, RT_MAXLINE, fp_out) != (char *)NULL)
	    Tcl_AppendResult(dgop->interp, line, (char *)NULL);
    }

    (void)fclose(fp_out);

    while (bu_fgets(line, RT_MAXLINE, fp_err) != (char *)NULL)
	Tcl_AppendResult(dgop->interp, line, (char *)NULL);
    (void)fclose(fp_err);


#ifndef _WIN32

    /* Wait for program to finish */
    while ((rpid = wait(&retcode)) != pid && rpid != -1)
	;	/* NULL */

    if (retcode != 0)
	pr_wait_status(dgop->interp, retcode);
#else
    /* Wait for program to finish */
    WaitForSingleObject(pi.hProcess, INFINITE);

#endif

    FOR_ALL_SOLIDS(sp, &dgop->dgo_headSolid)
	sp->s_wflag = DOWN;

    bu_free(dgop->dgo_rt_cmd, "free dgo_rt_cmd");
    dgop->dgo_rt_cmd = NULL;

    return TCL_OK;
}
Exemplo n.º 13
0
int
main(int argc, char *argv[])
{
    int length, frame_number, number, success, maxnum;
    int first_frame, spread, reserve;
    off_t last_pos;
    char line[MAXLEN];
    char pbuffer[MAXLEN*MAXLINES];


    if (!get_args(argc, argv))
	fprintf(stderr, "Get_args error\n");

    /* copy any lines preceding the first "start" command */
    last_pos = bu_ftell(stdin);
    while (bu_fgets(line, MAXLEN, stdin)!=NULL) {
	if (bu_strncmp(line, "start", 5)) {
	    printf("%s", line);
	    last_pos = bu_ftell(stdin);
	} else
	    break;
    }

    /* read the frame number of the first "start" command */
    sscanf(strpbrk(line, "0123456789"), "%d", &frame_number);

    /* find the highest frame number in the file */
    maxnum = 0;
    while (bu_fgets(line, MAXLEN, stdin)!=NULL) {
	if (!bu_strncmp(line, "start", 5)) {
	    sscanf(strpbrk(line, "0123456789"), "%d", &number);
	    maxnum = (maxnum>number)?maxnum:number;
	}
    }

    length = maxnum - frame_number + 1;
    /* spread should initially be the smallest power of two larger than
     * or equal to length */
    spread = 2;
    while (spread < length)
	spread = spread<<1;

    first_frame = frame_number;
    success = 1;
    while (length--) {
	number = -1;
	success = 0; /* tells whether or not any frames have been found which have the current frame number*/
	if (incremental) {
	    bu_fseek(stdin, 0, 0);
	} else {
	    bu_fseek(stdin, last_pos, 0);
	}

	reserve = MAXLEN*MAXLINES;
	pbuffer[0] = '\0'; /* delete old pbuffer */

	/* inner loop: search through the entire file for frames */
	/* which have the current frame number */
	while (!feof(stdin)) {

	    /*read to next "start" command*/
	    while (bu_fgets(line, MAXLEN, stdin)!=NULL) {
		if (!bu_strncmp(line, "start", 5)) {
		    sscanf(strpbrk(line, "0123456789"), "%d", &number);
		    break;
		}
	    }
	    if (number==frame_number) {
		if (!success) {
		    /*first successful match*/
		    printf("%s", line);
		    if (!suppressed) printf("clean;\n");
		    success = 1;
		    last_pos = bu_ftell(stdin);
		}
		/* print contents until next "end" */
		while (bu_fgets(line, MAXLEN, stdin)!=NULL) {
		    if (!bu_strncmp(line, "end;", 4))
			break;
		    else if (bu_strncmp(line, "clean", 5))
			printf("%s", line);
		}
		/* save contents until next "start" */
		while (bu_fgets(line, MAXLEN, stdin)!=NULL) {
		    if (!bu_strncmp(line, "start", 5))
			break;
		    else {
			reserve -= strlen(line);
			reserve -= 1;
			if (reserve > 0) {
			    bu_strlcat(pbuffer, line, reserve + strlen(line) + 1);
			} else {
			    printf("ERROR: ran out of buffer space (%d characters)\n", MAXLEN*MAXLINES);
			}
		    }
		}
	    }
	}
	if (success)
	    printf("end;\n");
	/* print saved-up post-raytracing commands, if any */
	printf("%s", pbuffer);

	/* get next frame number */
	if (incremental) {
	    frame_number = frame_number + 2*spread;
	    while (frame_number > maxnum) {
		spread = spread>>1;
		frame_number = first_frame + spread;
	    }
	} else {
	    frame_number += 1;
	}
    }
Exemplo n.º 14
0
int
rt_comb_import4(
    struct rt_db_internal *ip,
    const struct bu_external *ep,
    const mat_t matrix,		/* NULL if identity */
    const struct db_i *dbip,
    struct resource *resp)
{
    union record *rp;
    struct rt_tree_array *rt_tree_array;
    union tree *tree;
    struct rt_comb_internal *comb;
    size_t j;
    size_t node_count;

    BU_CK_EXTERNAL(ep);
    rp = (union record *)ep->ext_buf;
    if (dbip) RT_CK_DBI(dbip);

    if (rp[0].u_id != ID_COMB) {
	bu_log("rt_comb_import4: Attempt to import a non-combination\n");
	return -1;
    }

    /* Compute how many granules of MEMBER records follow */
    node_count = ep->ext_nbytes/sizeof(union record) - 1;

    if (node_count)
	rt_tree_array = (struct rt_tree_array *)bu_calloc(node_count, sizeof(struct rt_tree_array), "rt_tree_array");
    else
	rt_tree_array = (struct rt_tree_array *)NULL;

    for (j = 0; j < node_count; j++) {
	if (rp[j+1].u_id != ID_MEMB) {
	    bu_free((void *)rt_tree_array, "rt_comb_import4: rt_tree_array");
	    bu_log("rt_comb_import4(): granule in external buffer is not ID_MEMB, id=%d\n", rp[j+1].u_id);
	    return -1;
	}

	switch (rp[j+1].M.m_relation) {
	    case '+':
		rt_tree_array[j].tl_op = OP_INTERSECT;
		break;
	    case '-':
		rt_tree_array[j].tl_op = OP_SUBTRACT;
		break;
	    default:
		bu_log("rt_comb_import4() unknown op=x%x, assuming UNION\n", rp[j+1].M.m_relation);
		/* Fall through */
	    case 'u':
		rt_tree_array[j].tl_op = OP_UNION;
		break;
	}

	/* Build leaf node for in-memory tree */
	{
	    union tree *tp;
	    mat_t diskmat;
	    char namebuf[NAMESIZE+1];

	    RT_GET_TREE(tp, resp);
	    rt_tree_array[j].tl_tree = tp;
	    tp->tr_l.tl_op = OP_DB_LEAF;

	    /* bu_strlcpy not safe here, buffer size mismatch */
	    memset(namebuf, 0, NAMESIZE+1);
	    memcpy(namebuf, rp[j+1].M.m_instname, sizeof(rp[j+1].M.m_instname));

	    tp->tr_l.tl_name = bu_strdup(namebuf);

	    flip_mat_dbmat(diskmat, rp[j+1].M.m_mat, dbip->dbi_version < 0 ? 1 : 0);

	    /* Verify that rotation part is pure rotation */
	    if (fabs(diskmat[0]) > 1 || fabs(diskmat[1]) > 1 ||
		fabs(diskmat[2]) > 1 ||
		fabs(diskmat[4]) > 1 || fabs(diskmat[5]) > 1 ||
		fabs(diskmat[6]) > 1 ||
		fabs(diskmat[8]) > 1 || fabs(diskmat[9]) > 1 ||
		fabs(diskmat[10]) > 1)
	    {
		bu_log("ERROR: %s/%s improper scaling, rotation matrix elements > 1\n",
		       rp[0].c.c_name, namebuf);
	    }

	    /* Verify that perspective isn't used as a modeling transform */
	    if (!ZERO(diskmat[12])
		|| !ZERO(diskmat[13])
		|| !ZERO(diskmat[14]))
	    {
		bu_log("ERROR: %s/%s has perspective transform\n", rp[0].c.c_name, namebuf);
	    }

	    /* See if disk record is identity matrix */
	    if (bn_mat_is_identity(diskmat)) {
		if (matrix == NULL) {
		    tp->tr_l.tl_mat = NULL;	/* identity */
		} else {
		    tp->tr_l.tl_mat = bn_mat_dup(matrix);
		}
	    } else {
		if (matrix == NULL) {
		    tp->tr_l.tl_mat = bn_mat_dup(diskmat);
		} else {
		    mat_t prod;
		    bn_mat_mul(prod, matrix, diskmat);
		    tp->tr_l.tl_mat = bn_mat_dup(prod);
		}
	    }
/* bu_log("M_name=%s, matp=x%x\n", tp->tr_l.tl_name, tp->tr_l.tl_mat); */
	}
    }
    if (node_count)
	tree = db_mkgift_tree(rt_tree_array, node_count, &rt_uniresource);
    else
	tree = (union tree *)NULL;

    RT_DB_INTERNAL_INIT(ip);
    ip->idb_major_type = DB5_MAJORTYPE_BRLCAD;
    ip->idb_type = ID_COMBINATION;
    ip->idb_meth = &OBJ[ID_COMBINATION];

    BU_ALLOC(comb, struct rt_comb_internal);
    RT_COMB_INTERNAL_INIT(comb);

    comb->tree = tree;

    ip->idb_ptr = (void *)comb;

    switch (rp[0].c.c_flags) {
	case DBV4_NON_REGION_NULL:
	case DBV4_NON_REGION:
	    comb->region_flag = 0;
	    break;
	case DBV4_REGION:
	    comb->region_flag = 1;
	    comb->is_fastgen = REGION_NON_FASTGEN;
	    break;
	case DBV4_REGION_FASTGEN_PLATE:
	    comb->region_flag = 1;
	    comb->is_fastgen = REGION_FASTGEN_PLATE;
	    break;
	case DBV4_REGION_FASTGEN_VOLUME:
	    comb->region_flag = 1;
	    comb->is_fastgen = REGION_FASTGEN_VOLUME;
	    break;
	default:
	    bu_log("WARNING: combination %s has illegal c_flag=x%x\n",
		   rp[0].c.c_name, rp[0].c.c_flags);
	    break;
    }

    if (comb->region_flag) {
	if (dbip->dbi_version < 0) {
	    comb->region_id = flip_short(rp[0].c.c_regionid);
	    comb->aircode = flip_short(rp[0].c.c_aircode);
	    comb->GIFTmater = flip_short(rp[0].c.c_material);
	    comb->los = flip_short(rp[0].c.c_los);
	} else {
	    comb->region_id = rp[0].c.c_regionid;
	    comb->aircode = rp[0].c.c_aircode;
	    comb->GIFTmater = rp[0].c.c_material;
	    comb->los = rp[0].c.c_los;
	}
    } else {
	/* set some reasonable defaults */
	comb->region_id = 0;
	comb->aircode = 0;
	comb->GIFTmater = 0;
	comb->los = 0;
    }

    comb->rgb_valid = rp[0].c.c_override;
    if (comb->rgb_valid) {
	comb->rgb[0] = rp[0].c.c_rgb[0];
	comb->rgb[1] = rp[0].c.c_rgb[1];
	comb->rgb[2] = rp[0].c.c_rgb[2];
    }
    if (rp[0].c.c_matname[0] != '\0') {
#define MAX_SS 128
	char shader_str[MAX_SS];

	memset(shader_str, 0, MAX_SS);

	/* copy shader info to a static string */

	/* write shader name.  c_matname is a buffer, bu_strlcpy not
	 * safe here.
	 */
	memcpy(shader_str, rp[0].c.c_matname, sizeof(rp[0].c.c_matname));

	bu_strlcat(shader_str, " ", MAX_SS);

	/* write shader parameters.  c_matparm is a buffer, bu_strlcpy
	 * not safe here.
	 */
	memcpy(shader_str+strlen(shader_str), rp[0].c.c_matparm, sizeof(rp[0].c.c_matparm));

	/* convert to TCL format and place into comb->shader */
	if (bu_shader_to_list(shader_str, &comb->shader)) {
	    bu_log("rt_comb_import4: Error: Cannot convert following shader to TCL format:\n");
	    bu_log("\t%s\n", shader_str);
	    bu_vls_free(&comb->shader);
	    return -1;
	}
    }
    /* XXX Separate flags for color inherit, shader inherit, (new) material inherit? */
    /* XXX cf: ma_cinherit, ma_minherit */
    /* This ? is necessary to clean up old databases with grunge here */
    comb->inherit = (rp[0].c.c_inherit == DB_INH_HIGHER) ? 1 : 0;
    /* Automatic material table lookup here? */
    if (comb->region_flag)
	bu_vls_printf(&comb->material, "gift%ld", comb->GIFTmater);

    if (rt_tree_array) bu_free((void *)rt_tree_array, "rt_tree_array");

    return 0;
}
Exemplo n.º 15
0
/*	d e c k ( )
	make a COMGEOM deck for current list of objects

*/
void
deck(register char *prefix)
{
    register int	i;

    nns = nnr = 0;

    /* Create file for solid table.					*/
    if ( prefix != 0 ) {
	/* !!! this seems wrong. st_file is a pointer into a bu_vls */
	bu_strlcpy(st_file, prefix, 80);
	bu_strlcat(st_file, ".st", 80);
    } else
	bu_strlcpy( st_file, "solids", 80 );

    if ( (solfd = creat( st_file, 0644 )) < 0 ) {
	perror( st_file );
	bu_exit( 10, NULL );
    }

    /* Target units (a2, 3x)						*/
    ewrite( solfd, bu_units_string(dbip->dbi_local2base), 2 );
    blank_fill( solfd, 3 );

    /* Title							*/
    if ( dbip->dbi_title == NULL )
	ewrite( solfd, objfile, (unsigned) strlen( objfile ) );
    else
	ewrite( solfd, dbip->dbi_title, (unsigned) strlen( dbip->dbi_title ) );
    ewrite( solfd, LF, 1 );

    /* Save space for number of solids and regions.			*/
    savsol = lseek( solfd, 0L, 1 );
    blank_fill( solfd, 10 );
    ewrite( solfd, LF, 1 );

    /* Create file for region table.				*/
    if ( prefix != 0 ) {
	bu_strlcpy(rt_file, prefix, 80);
	bu_strlcat(rt_file, ".rt", 80);
    } else
	bu_strlcpy(rt_file, "regions", 80);

    if ( (regfd = creat( rt_file, 0644 )) < 0 ) {
	perror( rt_file );
	bu_exit( 10, NULL );
    }

    /* create file for region ident table
     */
    if ( prefix != 0 ) {
	bu_strlcpy(id_file, prefix, 80);
	bu_strlcat(id_file, ".id", 80);
    }
    else
	bu_strLcpy(id_file, "region_ids", 80);

    if ( (ridfd = creat( id_file, 0644 )) < 0 ) {
	perror( id_file );
	bu_exit( 10, NULL );
    }
    itoa( -1, buff, 5 );
    ewrite( ridfd, buff, 5 );
    ewrite( ridfd, LF, 1 );

    /* Initialize matrices.						*/
    MAT_IDN( identity );

    /* Check integrity of list against directory and build card deck.	*/
    for ( i = 0; i < curr_ct; i++ )
    {
	struct directory	*dirp;
	if ( (dirp = db_lookup( dbip, curr_list[i], LOOKUP_NOISY )) != DIR_NULL )  {
#if 1
	    treewalk( curr_list[i] );
#else
	    cgobj( dirp, 0, identity );
#endif
	}
    }
    /* Add number of solids and regions on second card.		*/
    (void) lseek( solfd, savsol, 0 );
    itoa( nns, buff, 5 );
    ewrite( solfd, buff, 5 );
    itoa( nnr, buff, 5 );
    ewrite( solfd, buff, 5 );

    /* Finish region id table.					*/
    ewrite( ridfd, LF, 1 );

    (void) printf( "====================================================\n" );
    (void) printf( "O U T P U T    F I L E S :\n\n" );
    (void) printf( "solid table = \"%s\"\n", st_file );
    (void) printf( "region table = \"%s\"\n", rt_file );
    (void) printf( "region identification table = \"%s\"\n", id_file );
    (void) close( solfd );
    (void) close( regfd );
    (void) close( ridfd );

    /* reset starting numbers for solids and regions
     */
    delsol = delreg = 0;
    /* XXX should free soltab list */
}