void
bu_ptbl_init(struct bu_ptbl *b, size_t len, const char *str)
{
    if (UNLIKELY(bu_debug & BU_DEBUG_PTBL))
	bu_log("bu_ptbl_init(%p, len=%zu, %s)\n", (void *)b, len, str);

    BU_LIST_INIT_MAGIC(&b->l, BU_PTBL_MAGIC);

    if (UNLIKELY(len <= (size_t)0))
	len = 64;

    b->blen = len;
    b->buffer = (long **)bu_calloc(b->blen, sizeof(long *), str);
    b->end = 0;
}
Example #2
0
struct frame *getframe(FILE *in)
{
    extern FILE *yyin;
    extern char yytext[];
    struct frame *newframe;

    yyin = in;

/*
 * If we are not IN a frame, then every thing is part of the globals
 * and gets attached to the head.
 */
    if (token == SHELL) token = yylex();
    while (token != START && (token != 0)) {
	addtext(&globals, yytext);
	token = yylex();
    }
    if (!token) return NULL;
/*
 * The next token MUST be a frame number!
 */
    token = yylex();
    if (!token) return NULL;
    if (token != INT) {
	fprintf(stderr, "getframe: BAD start format. Skipping.\n");
	while ((token=yylex()) != END);
	token = yylex();	/* the semi-colon. */
	return NULL;
    }
/*
 * get a frame and set it up.
 */
    BU_ALLOC(newframe, struct frame);
    BU_LIST_INIT_MAGIC(&(newframe->l), MAGIC);
    newframe->number = atoi(yytext);
    newframe->number += frame_offset;
/*
 * The next token should be SEMI COLON;
 */
    token = yylex();
    if (!token) {
	newframe->l.magic = -1;
	bu_free(newframe, "struct frame");
	return NULL;
    }

    if (token != SEMI) {
	fprintf(stderr, "getframe: Missing semi colon after start %%d.\n");
	fprintf(stderr, "getframe: Inserting semi colon.\n");
    }
/*
 * Now comes the rest.
 */
    while ((token = yylex()) != END && (token)) {
	if (token == CLEAN) {
	    (void) yylex(); /* skip semi-colon */
	    newframe->flags |= FLAG_CLEAN;
	} else {
	    addtext(newframe, yytext);
	    /* Can't concatenate commands to comments. */
	    if (token == COMMENT) {
		addtext(newframe, "\n");
	    }
	}
    }
    token = yylex();	/* scarf the semi-colon */
    token = yylex();	/* Get the next token.  It could be shell */
    if (token == SHELL) {
	newframe->flags |= FLAG_SCRIPT;
    }
    if (verbose) {
	fprintf(stderr, "scriptsort: Frame %d(%d)\n", newframe->number, newframe->tp);
    }
    return newframe;
}
static void
tree_solids(union tree *tp, struct tree_bark *tb, int op, struct resource *resp)
{
    RT_CK_TREE(tp);

    switch (tp->tr_op) {
	case OP_NOP:
	    return;

	case OP_SOLID: {
	    struct reg_db_internals *dbint;
	    matp_t mp;
	    long sol_id = 0;
	    struct rt_ell_internal *ell_p;
	    vect_t v;
	    int ret;

	    BU_ALLOC(dbint, struct reg_db_internals);
	    BU_LIST_INIT_MAGIC(&(dbint->l), DBINT_MAGIC);

	    if (tp->tr_a.tu_stp->st_matp)
		mp = tp->tr_a.tu_stp->st_matp;
	    else
		mp = (matp_t)bn_mat_identity;

	    /* Get the internal form of this solid & add it to the list */
	    ret = rt_db_get_internal(&dbint->ip, tp->tr_a.tu_stp->st_dp, tb->dbip, mp, resp);
	    if (ret < 0) {
		bu_log("Failure reading %s object from database.\n", OBJ[sol_id].ft_name);
		return;
	    }

	    RT_CK_DB_INTERNAL(&dbint->ip);
	    dbint->st_p = tp->tr_a.tu_stp;

	    sol_id = dbint->ip.idb_type;

	    if (sol_id < 0) {
		bu_log("Primitive ID %ld out of bounds\n", sol_id);
		bu_bomb("");
	    }


	    if (sol_id != ID_ELL) {

		if (op == OP_UNION)
		    bu_log("Non-ellipse \"union\" primitive of \"%s\" being ignored\n",
			   tb->name);

		if (rdebug&RDEBUG_SHADE)
		    bu_log(" got a primitive type %ld \"%s\".  This primitive ain't no ellipse bucko!\n",
			   sol_id, OBJ[sol_id].ft_name);

		break;
	    }


	    ell_p = (struct rt_ell_internal *)dbint->ip.idb_ptr;

	    if (rdebug&RDEBUG_SHADE)
		bu_log(" got a primitive type %ld \"%s\"\n",
		       sol_id,
		       OBJ[sol_id].ft_name);

	    RT_ELL_CK_MAGIC(ell_p);

	    if (rdebug&RDEBUG_SHADE) {
		VPRINT("point", ell_p->v);
		VPRINT("a", ell_p->a);
		VPRINT("b", ell_p->b);
		VPRINT("c", ell_p->c);
	    }

	    /* create the matrix that maps the coordinate system defined
	     * by the ellipse into model space, and get inverse for use
	     * in the _render() proc
	     */
	    MAT_IDN(mp);
	    VMOVE(v, ell_p->a);	VUNITIZE(v);
	    mp[0] = v[0];	mp[4] = v[1];	mp[8] = v[2];

	    VMOVE(v, ell_p->b);	VUNITIZE(v);
	    mp[1] = v[0];	mp[5] = v[1];	mp[9] = v[2];

	    VMOVE(v, ell_p->c);	VUNITIZE(v);
	    mp[2] = v[0];	mp[6] = v[1];	mp[10] = v[2];

	    MAT_DELTAS_VEC(mp, ell_p->v);

	    MAT_COPY(dbint->ell2model, mp);
	    bn_mat_inv(dbint->model2ell, mp);


	    /* find scaling of gaussian puff in ellipsoid space */
	    VSET(dbint->one_sigma,
		 MAGNITUDE(ell_p->a) / tb->gs->gauss_sigma,
		 MAGNITUDE(ell_p->b) / tb->gs->gauss_sigma,
		 MAGNITUDE(ell_p->c) / tb->gs->gauss_sigma);


	    if (rdebug&RDEBUG_SHADE) {
		VPRINT("sigma", dbint->one_sigma);
	    }
	    BU_LIST_APPEND(tb->l, &(dbint->l));

	    break;
	}
	case OP_UNION:
	    tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp);
	    tree_solids(tp->tr_b.tb_right, tb, tp->tr_op, resp);
	    break;

	case OP_NOT: bu_log("Warning: 'Not' region operator in %s\n", tb->name);
	    tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp);
	    break;
	case OP_GUARD:bu_log("Warning: 'Guard' region operator in %s\n", tb->name);
	    tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp);
	    break;
	case OP_XNOP:bu_log("Warning: 'XNOP' region operator in %s\n", tb->name);
	    tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp);
	    break;

	case OP_INTERSECT:
	case OP_SUBTRACT:
	case OP_XOR:
	    /* XXX this can get us in trouble if 1 solid is subtracted
	     * from less than all the "union" solids of the region.
	     */
	    tree_solids(tp->tr_b.tb_left, tb, tp->tr_op, resp);
	    tree_solids(tp->tr_b.tb_right, tb, tp->tr_op, resp);
	    return;

	default:
	    bu_bomb("rt_tree_region_assign: bad op\n");
    }
}