Esempio n. 1
0
void
do_quad(char *line)
{
    int element_id;
    int pt1, pt2, pt3, pt4;
    fastf_t thick = 0.0;
    int pos = 0;

    bu_strlcpy(field,  &line[8], sizeof(field));
    element_id = atoi( field );

    if ( debug )
	bu_log( "do_quad: %s\n", line );

    if ( !bot )
	bot = element_id;

    if ( faces == NULL )
    {
	faces = (int *)bu_malloc( GRID_BLOCK*3*sizeof( int ), "faces" );
	thickness = (fastf_t *)bu_malloc( GRID_BLOCK*sizeof( fastf_t ), "thickness" );
	facemode = (char *)bu_malloc( GRID_BLOCK*sizeof( char ), "facemode" );
	face_size = GRID_BLOCK;
	face_count = 0;
    }

    bu_strlcpy(field,  &line[24], sizeof(field));
    pt1 = atoi( field );

    bu_strlcpy(field,  &line[32], sizeof(field));
    pt2 = atoi( field );

    bu_strlcpy(field,  &line[40], sizeof(field));
    pt3 = atoi( field );

    bu_strlcpy(field,  &line[48], sizeof(field));
    pt4 = atoi( field );

    if ( mode == PLATE_MODE )
    {
	bu_strlcpy(field,  &line[56], sizeof(field));
	thick = atof( field ) * 25.4;

	bu_strlcpy(field,  &line[64], sizeof(field));
	pos = atoi( field );

	if ( pos == 0 )	/* use default */
	    pos = POS_FRONT;

	if ( pos != POS_CENTER && pos != POS_FRONT )
	{
	    bu_log( "do_quad: illegal postion parameter (%d), must be one or two\n", pos );
	    bu_log( "\telement %d, component %d, group %d\n", element_id, comp_id, group_id );
	    return;
	}
    }

    Add_bot_face( pt1, pt2, pt3, thick, pos );
    Add_bot_face( pt1, pt3, pt4, thick, pos );
}
Esempio n. 2
0
icv_image_t *
icv_create(int width, int height, ICV_COLOR_SPACE color_space)
{
    icv_image_t *bif;
    BU_ALLOC(bif, struct icv_image);
    bif->width = width;
    bif->height = height;
    bif->color_space = color_space;
    bif->alpha_channel = 0;
    bif->magic = ICV_IMAGE_MAGIC;
    switch (color_space) {
	case ICV_COLOR_SPACE_RGB :
	    /* Add all the other three channel images here (eg. HSV, YCbCr etc.) */
	    bif->data = (double *) bu_malloc(bif->height*bif->width*3*sizeof(double), "Image Data");
	    bif->channels = 3;
	    break;
	case ICV_COLOR_SPACE_GRAY :
	    bif->data = (double *) bu_malloc(bif->height*bif->width*1*sizeof(double), "Image Data");
	    bif->channels = 1;
	    break;
	default :
	    bu_exit(1, "icv_create_image : Color Space Not Defined");
	    break;
    }
    return icv_zero(bif);
}
Esempio n. 3
0
void
Readpoints(void)
{
    struct points *ptr, *prev;
    fastf_t x, y, z;

    ptr = root;
    prev = NULL;


    printf( "X Y Z (^D for end): ");
    while (scanf("%lf%lf%lf", &x, &y, &z) ==  3 )
    {
	if ( ptr == NULL )
	{
	    ptr = (struct points *)bu_malloc( sizeof( struct points ), "ptr" );
	    root = ptr;
	}
	else
	{
	    ptr->next = (struct points *)bu_malloc( sizeof( struct points ), "ptr->next" );
	    ptr = ptr->next;
	}
	ptr->next = NULL;
	ptr->prev = prev;
	prev = ptr;
	VSET(ptr->p, k*x, k*y, k*z);
	ptr->tube[0] = '\0';
	ptr->tubflu[0] = '\0';
	ptr->elbow[0] = '\0';
	ptr->elbflu[0] = '\0';
	ptr->cut[0] = '\0';
	printf( "X Y Z (^D for end): ");
    }
}
void
texture_perlin_init(struct texture_perlin_s *P)
{
    int i, j, k;

    P->PV = (int *)bu_malloc(sizeof(int)*(2*B+2), "PV");
    P->RV = (vect_t *)bu_malloc(sizeof(vect_t)*(2*B+2), "RV");

    /* Generate Random Vectors */
    for (i = 0; i < B; i++) {
	P->RV[i][0] = (fastf_t)((PRAND % (2*B)) - B) / B;
	P->RV[i][1] = (fastf_t)((PRAND % (2*B)) - B) / B;
	P->RV[i][2] = (fastf_t)((PRAND % (2*B)) - B) / B;
	VUNITIZE(P->RV[i]);
	P->PV[i] = i;
    }

    /* Permute Indices into Vector List G */
    for (i = 0; i < B; i++) {
	k = P->PV[i];
	P->PV[i] = P->PV[j = PRAND % B];
	P->PV[j] = k;
    }

    for (i = 0; i < B + 2; i++) {
	P->PV[B+i] = P->PV[i];
	VMOVE(P->RV[B+i], P->RV[i]);
    }
}
Esempio n. 5
0
void
db_dup_full_path(struct db_full_path *newp, const struct db_full_path *oldp)
{
    unsigned int i = 0;
    RT_CK_FULL_PATH(newp);
    RT_CK_FULL_PATH(oldp);

    newp->fp_maxlen = oldp->fp_maxlen;
    newp->fp_len = oldp->fp_len;
    if (oldp->fp_len <= 0) {
	newp->fp_names = (struct directory **)0;
	newp->fp_bool = (int *)0;
	return;
    }
    newp->fp_names = (struct directory **)bu_malloc(newp->fp_maxlen * sizeof(struct directory *),
	    "db_full_path array (duplicate)");
    memcpy((char *)newp->fp_names, (char *)oldp->fp_names, newp->fp_len * sizeof(struct directory *));

    newp->fp_bool = (int *)bu_malloc(newp->fp_maxlen * sizeof(int),
	    "db_full_path bool array (duplicate)");
    memcpy((char *)newp->fp_bool, (char *)oldp->fp_bool, newp->fp_len * sizeof(int));

    newp->fp_mat = (matp_t *)bu_calloc(newp->fp_maxlen, sizeof(matp_t),
	    "db_full_path mat array (duplicate)");
    for (i = 0; i < newp->fp_len; i++) {
	if (oldp->fp_mat[i]) {
	    newp->fp_mat[i] = (matp_t)bu_calloc(1, sizeof(mat_t), "transformation matrix");
	    MAT_COPY(newp->fp_mat[i], oldp->fp_mat[i]);
	}
    }
}
Esempio n. 6
0
static struct edge_g_cnurb *
nmg_construct_edge_g_cnurb(const struct edge_g_cnurb *original, void **structArray)
{
    struct edge_g_cnurb *ret;

    NMG_GETSTRUCT(ret, edge_g_cnurb);

    ret->l.magic = NMG_EDGE_G_CNURB_MAGIC;

    BU_LIST_INIT(&ret->eu_hd2);

    ret->order = original->order;

    ret->k.magic  = NMG_KNOT_VECTOR_MAGIC;
    ret->k.k_size = original->k.k_size;
    ret->k.knots = (fastf_t *)bu_malloc(ret->k.k_size * sizeof(fastf_t), "nmg_construct_edge_g_cnurb(): k.knots");
    memcpy(ret->k.knots, original->k.knots, ret->k.k_size * sizeof(fastf_t));

    ret->c_size     = original->c_size;
    ret->pt_type    = original->pt_type;
    ret->ctl_points = (fastf_t *)bu_malloc(ret->c_size * RT_NURB_EXTRACT_COORDS(ret->pt_type) * sizeof(fastf_t),
					   "nmg_construct_edge_g_cnurb(): ctl_points");
    memcpy(ret->ctl_points, original->ctl_points, ret->c_size * RT_NURB_EXTRACT_COORDS(ret->pt_type) * sizeof(fastf_t));

    ret->index              = original->index;
    structArray[ret->index] = ret;

    return ret;
}
/*
 *	Write the nmg to a BRL-CAD style data base.
 */
int
create_brlcad_db(struct rt_wdb *fpout, struct model *m, char *reg_name, char *grp_name)
{
    char *rname, *sname;
    int empty_model;
    struct shell *s;
    struct nmgregion *r;

    rname = (char *)bu_malloc(sizeof(reg_name) + 3, "rname");	/* Region name. */
    sname = (char *)bu_malloc(sizeof(reg_name) + 3, "sname");	/* Solid name. */

    snprintf(sname, sizeof(reg_name) + 2, "s.%s", reg_name);
    empty_model = nmg_kill_zero_length_edgeuses(m);
    if (empty_model) {
	bu_log("Warning: skipping empty model.");
	return 0;
    }
    nmg_rebound(m, &tol);
    r = BU_LIST_FIRST(nmgregion, &m->r_hd);
    s = BU_LIST_FIRST(shell, &r->s_hd);
    mk_bot_from_nmg(fpout, sname,  s);		/* Make BOT object. */
    snprintf(rname, sizeof(reg_name) + 2, "r.%s", reg_name);
    mk_comb1(fpout, rname, sname, 1);	/* Put object in a region. */
    if (grp_name) {
	mk_comb1(fpout, grp_name, rname, 1);	/* Region in group. */
    }
    return 0;
}
/**
 * Create a place holder for a nurb surface.
 */
struct face_g_snurb *
rt_nurb_new_snurb(int u_order, int v_order, int n_u, int n_v, int n_rows, int n_cols, int pt_type, struct resource *res)
{
    register struct face_g_snurb * srf;
    int pnum;

    if (res) RT_CK_RESOURCE(res);

    GET_SNURB(srf);
    srf->order[0] = u_order;
    srf->order[1] = v_order;
    srf->dir = RT_NURB_SPLIT_ROW;

    srf->u.k_size = n_u;
    srf->v.k_size = n_v;
    srf->s_size[0] = n_rows;
    srf->s_size[1] = n_cols;
    srf->pt_type = pt_type;

    pnum = sizeof (fastf_t) * n_rows * n_cols * RT_NURB_EXTRACT_COORDS(pt_type);

    srf->u.knots = (fastf_t *) bu_malloc (
	n_u * sizeof (fastf_t), "rt_nurb_new_snurb: u kv knot values");
    srf->v.knots = (fastf_t *) bu_malloc (
	n_v * sizeof (fastf_t), "rt_nurb_new_snurb: v kv knot values");
    srf->ctl_points = (fastf_t *) bu_malloc(
	pnum, "rt_nurb_new_snurb: control mesh points");

    return srf;
}
Esempio n. 9
0
/* This attempts to find the surface area by subdividing the uv plane
 * into squares, and finding the approximate surface area of each
 * square.
 */
static fastf_t
superell_surf_area_general(const struct rt_superell_internal *sip, vect_t mags, fastf_t side_length)
{
    fastf_t area = 0;
    fastf_t u, v;

    /* There are M_PI / side_length + 1 values because both ends have
       to be stored */
    int row_length = sizeof(point_t) * (M_PI / side_length + 1);

    point_t *row1 = (point_t *)bu_malloc(row_length, "superell_surf_area_general");
    point_t *row2 = (point_t *)bu_malloc(row_length, "superell_surf_area_general");

    int idx = 0;


    /* This function keeps a moving window of two rows at any time,
     * and calculates the area of space between those two rows. It
     * calculates the first row outside of the loop so that at each
     * iteration it only has to calculate the second. Following
     * standard definitions of u and v, u ranges from -pi to pi, and v
     * ranges from -pi/2 to pi/2. Using an extra index variable allows
     * the code to compute the index into the array very efficiently.
     */
    for (v = -M_PI_2; v < M_PI_2; v += side_length, idx++) {
        superell_xyz_from_uv(row1[idx], -M_PI, v, mags, sip);
    }


    /* This starts at -M_PI + side_length because the first row is
     * computed outside the loop, which allows the loop to always
     * calculate the second row of the pair.
     */
    for (u = -M_PI + side_length; u < M_PI; u += side_length) {
        idx = 0;
        for (v = -M_PI_2; v < M_PI_2; v += side_length, idx++) {
            superell_xyz_from_uv(row2[idx], u + side_length, v, mags, sip);
        }

        idx = 0;

        /* This ends at -M_PI / 2 - side_length because if it kept
         * going it would overflow the array, since it always looks at
         * the square to the right of its current index.
         */
        for (v = - M_PI_2; v < M_PI_2 - side_length; v += side_length, idx++) {
            area +=
                bn_dist_pt3_pt3(row1[idx], row1[idx + 1]) *
                bn_dist_pt3_pt3(row1[idx], row2[idx]);
        }

        memcpy(row1, row2, row_length);
    }

    bu_free(row1, "superell_surf_area_general");
    bu_free(row2, "superell_surf_area_general");

    return area;
}
Esempio n. 10
0
HIDDEN int
wdb_add_operand(Tcl_Interp *interp, struct bu_list *hp, char *name)
{
    char *ptr_lparen;
    char *ptr_rparen;
    int name_len;
    union tree *node;
    struct tokens *tok;

    BU_CK_LIST_HEAD(hp);

    ptr_lparen = strchr(name, '(');
    ptr_rparen = strchr(name, ')');

    RT_GET_TREE( node, &rt_uniresource );
    node->magic = RT_TREE_MAGIC;
    node->tr_op = OP_DB_LEAF;
    node->tr_l.tl_mat = (matp_t)NULL;
    if (ptr_lparen || ptr_rparen) {
	int tmp1, tmp2;

	if (ptr_rparen)
	    tmp1 = ptr_rparen - name;
	else
	    tmp1 = (-1);
	if (ptr_lparen)
	    tmp2 = ptr_lparen - name;
	else
	    tmp2 = (-1);

	if (tmp2 == (-1) && tmp1 > 0)
	    name_len = tmp1;
	else if (tmp1 == (-1) && tmp2 > 0)
	    name_len = tmp2;
	else if (tmp1 > 0 && tmp2 > 0) {
	    if (tmp1 < tmp2)
		name_len = tmp1;
	    else
		name_len = tmp2;
	}
	else {
	    Tcl_AppendResult(interp, "Cannot determine length of operand name: ",
			     name, ", aborting\n", (char *)NULL);
	    return (0);
	}
    } else
	name_len = strlen( name );

    node->tr_l.tl_name = (char *)bu_malloc(name_len+1, "node name");
    bu_strlcpy(node->tr_l.tl_name, name, name_len+1);

    tok = (struct tokens *)bu_malloc(sizeof(struct tokens), "tok");
    tok->type = WDB_TOK_TREE;
    tok->tp = node;
    BU_LIST_INSERT(hp, &tok->l);
    return (name_len);
}
Esempio n. 11
0
void render_surfel_init(render_t *render, uint32_t num, render_surfel_pt_t *list) {
    render_surfel_t *d;

    render->work = render_surfel_work;
    render->free = render_surfel_free;
    render->data = (render_surfel_t *)bu_malloc(sizeof(render_surfel_t), "render data");
    d = (render_surfel_t *)render->data;
    d->list = (render_surfel_pt_t *)bu_malloc(num * sizeof(render_surfel_pt_t), "data list");
    d->num = num;
    d->list = list;
}
Esempio n. 12
0
/**
 * rt_nurb_c_xsplit()
 *
 * Split a NURB curve by inserting a multiple knot and return the
 * result of the two curves.
 *
 * Algorithm:
 *
 * Insert a multiple knot of the curve order. A parameter is give for
 * the knot value for which the curve will be split.
 */
struct edge_g_cnurb *
rt_nurb_c_xsplit(struct edge_g_cnurb *crv, fastf_t param)
{
    struct knot_vector new_kv;
    struct oslo_mat * oslo;
    int k_index;
    struct edge_g_cnurb * crv1, * crv2;
    int coords;

    NMG_CK_CNURB(crv);

    coords = RT_NURB_EXTRACT_COORDS(crv->pt_type),

	k_index = crv->order;
    rt_nurb_kvmult(&new_kv, &crv->k, crv->order, param, (struct resource *)NULL);

    oslo = (struct oslo_mat *)
	rt_nurb_calc_oslo(crv->order, &crv->k, &new_kv, (struct resource *)NULL);

    GET_CNURB(crv1);
    crv1->order  = crv->order;
    rt_nurb_kvextract(&crv1->k, &new_kv, 0, k_index + crv->order, (struct resource *)NULL);
    crv1->pt_type = crv->pt_type;
    crv1->c_size = crv1->k.k_size - crv1->order;
    crv1->ctl_points = (fastf_t *)
	bu_malloc(sizeof(fastf_t) * crv1->c_size *
		  RT_NURB_EXTRACT_COORDS(crv1->pt_type),
		  "rt_nurb_c_xsplit: crv1 control points");

    GET_CNURB(crv2);
    crv2->order  = crv->order;
    rt_nurb_kvextract(&crv2->k, &new_kv, k_index, new_kv.k_size, (struct resource *)NULL);
    crv2->pt_type = crv->pt_type;
    crv2->c_size = crv2->k.k_size - crv2->order;
    crv2->ctl_points = (fastf_t *)
	bu_malloc(sizeof(fastf_t) * crv2->c_size *
		  RT_NURB_EXTRACT_COORDS(crv2->pt_type),
		  "rt_nurb_c_xsplit: crv2 row mesh control points");

    rt_nurb_map_oslo(oslo, crv->ctl_points, crv1->ctl_points,
		     coords, coords, 0, k_index, crv->pt_type);

    rt_nurb_map_oslo(oslo, crv->ctl_points, crv2->ctl_points,
		     coords, coords, k_index, new_kv.k_size - crv2->order,
		     crv2->pt_type);

    rt_nurb_free_oslo(oslo, (struct resource *)NULL);

    bu_free((char *) new_kv.knots, "rt_nurb_c_xsplit: new_kv.knots");

    BU_LIST_APPEND(&crv1->l, &crv2->l);
    return crv1;
}
Esempio n. 13
0
/**
 * Solve must be passed two matrices that are of the form of pointer
 * to double arrays. mat_1 is the n by n matrix that is to be
 * decomposed and mat_2 is the matrix that contains the left side of
 * the equation.  The variable solution which is double is also to be
 * created by the user and consisting of n elements of which the
 * solution set is passed back.
 *
 * Arguments mat_1 and mat_2 are modified by this call.
 * The solution is written into the solution[] array.
 */
void
rt_nurb_solve(fastf_t *mat_1, fastf_t *mat_2, fastf_t *solution, int dim, int coords)
    /* A and b array of the system Ax= b*/


    /* dimension of the matrix */
    /* Number of coordinates for mat_2 and solution */
{
    register int i, k;
    fastf_t *y;
    fastf_t * b;
    fastf_t * s;

    y = (fastf_t *) bu_malloc(sizeof (fastf_t) * dim,
			      "rt_nurb_solve: y");/* Create temp array */

    b = (fastf_t *) bu_malloc(sizeof (fastf_t) * dim,
			      "rt_nurb_solve: b");/* Create temp array */

    s = (fastf_t *) bu_malloc(sizeof (fastf_t) * dim,
			      "rt_nurb_solve: s");/* Create temp array */

    rt_nurb_doolittle (mat_1, mat_2, dim, coords);/* Create LU decomposition */

    for (k =0; k < coords; k++) {
	fastf_t * ptr;

	ptr = mat_2 + k;

	for (i = 0; i < dim; i++) {
	    b[i] = *ptr;
	    ptr += coords;
	}

	/* Solve the system Ly =b */
	rt_nurb_forw_solve (mat_1, b, y, dim);

	/* Solve the system Ux = y */
	rt_nurb_back_solve (mat_1, y, s, dim);


	ptr = solution + k;
	for (i=0; i < dim; i++) {
	    *ptr = s[i];
	    ptr += coords;
	}
    }

    bu_free ((char *)y, "rt_nurb_solve: y");			/* Free up storage */
    bu_free ((char *)b, "rt_nurb_solve: b");			/* Free up storage */
    bu_free ((char *)s, "rt_nurb_solve: s");			/* Free up storage */
}
Esempio n. 14
0
void texture_image_init(texture_t *texture, short w, short h, unsigned char *image) {
    texture_image_t *td;

    texture->data = bu_malloc(sizeof(texture_image_t), "texture data");
    texture->free = texture_image_free;
    texture->work = (texture_work_t *)texture_image_work;

    td = (texture_image_t *)texture->data;
    td->w = w;
    td->h = h;
    td->image = (unsigned char *)bu_malloc(3*w*h, "texture image");
    memcpy(td->image, image, 3*w*h);
}
Esempio n. 15
0
/**
 *	P O P _ I N I T --- initialize a population of a given size
 */
void
pop_init (struct population *p, int size)
{
    p->parent = bu_malloc(sizeof(struct individual) * size, "parent");
    p->child  = bu_malloc(sizeof(struct individual) * size, "child");
    p->size = size;
    p->db_c = p->db_p = DBI_NULL;
    p->name = bu_malloc(sizeof(char *) * size, "names");

#define SEED 33
    /* init in main() bn_rand_init(randomer, SEED);*/
    bn_rand_init(randomer, SEED);
}
Esempio n. 16
0
/*	bn_gauss_init	Initialize a random number struct for gaussian
 *	numbers.
 *
 * @par Entry
 *	setseed		Seed to use.
 *	method		method to use to generate numbers (not used)
 *
 * @par Exit
 *	Returns a pointer toa bn_msr_guass structure.
 *	returns 0 on error.
 *
 * @par Calls
 *	bu_malloc
 *
 * @par Uses
 *	None.
 *
 * @par Method @code
 *	malloc up a structure
 *	get table space
 *	set seed and pointer.
 *	if setseed != 0 then seed = setseed
 @endcode
*/
struct bn_gauss *
bn_gauss_init(long int setseed, int method)
{
    struct bn_gauss *p;
    p = (struct bn_gauss *) bu_malloc(sizeof(struct bn_gauss), "bn_msr_guass");
    p->msr_gausses=(double *) bu_malloc(BN_MSR_MAXTBL*sizeof(double), "msr guass table");
    p->msr_gauss_doubles=(double *) bu_malloc(BN_MSR_MAXTBL*sizeof(double), "msr guass doubles");
    p->msr_gauss_seed = 1;
    p->msr_gauss_ptr = 0;
    p->msr_gauss_dbl_ptr = 0;

    if (setseed&0x7fffffff) p->msr_gauss_seed=setseed&0x7fffffff;
    p->magic = BN_GAUSS_MAGIC;
    return(p);
}
Esempio n. 17
0
/**
 * b u _ v l s _ e x t e n d
 *
 * Ensure that the provided VLS has at least 'extra' characters of
 * space available.
 */
void
bu_vls_extend(register struct bu_vls *vp, unsigned int extra)
{
    BU_CK_VLS(vp);

    /* increment by at least 40 bytes */
    if ( extra < _VLS_ALLOC_MIN )
	extra = _VLS_ALLOC_MIN;

    /* first time allocation */
    if ( vp->vls_max <= 0 || vp->vls_str == (char *)0 ) {
	vp->vls_max = extra;
	vp->vls_str = (char *)bu_malloc( (size_t)vp->vls_max, bu_vls_message );
	vp->vls_len = 0;
	vp->vls_offset = 0;
	*vp->vls_str = '\0';
	return;
    }

    /* need more space? */
    if ( vp->vls_offset + vp->vls_len + extra >= (size_t)vp->vls_max )  {
	vp->vls_max += extra;
	if ( vp->vls_max < _VLS_ALLOC_STEP ) {
	    /* extend to at least this much */
	    vp->vls_max = _VLS_ALLOC_STEP;
	}
	vp->vls_str = (char *)bu_realloc( vp->vls_str, (size_t)vp->vls_max, bu_vls_message );
    }
}
Esempio n. 18
0
File: ls.c Progetto: kanzure/brlcad
int
db_ls(const struct db_i *dbip, int flags, struct directory ***dpv)
{
    int i;
    int objcount = 0;
    struct directory *dp;

    RT_CK_DBI(dbip);

    for (i = 0; i < RT_DBNHASH; i++) {
	for (dp = dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) {
	    objcount += dp_eval_flags(dp, flags);
	}
    }
    if (objcount > 0) {
	(*dpv) = (struct directory **)bu_malloc(sizeof(struct directory *) * (objcount + 1), "directory pointer array");
	objcount = 0;
	for (i = 0; i < RT_DBNHASH; i++) {
	    for (dp = dbip->dbi_Head[i]; dp != RT_DIR_NULL; dp = dp->d_forw) {
		if (dp_eval_flags(dp,flags)) {
		    (*dpv)[objcount] = dp;
		    objcount++;
		}
	    }
	}
	(*dpv)[objcount] = NULL;
    }
    return objcount;
}
Esempio n. 19
0
int
main(int argc, char **argv)
{
    point_t	a, b, c, d;
    struct rt_wdb *fp;

    si.magic = RT_NURB_INTERNAL_MAGIC;
    si.nsrf = 0;
    si.srfs = (struct face_g_snurb **)bu_malloc( sizeof(struct face_g_snurb *)*100, "snurb ptrs");

    if ((fp = wdb_fopen(argv[1])) == NULL) {
        bu_log("unable to open new database [%s]\n", argv[1]);
        perror("unable to open database file");
        return 1;
    }

    mk_id( fp, "Mike's Spline Test" );

    VSET( a,  0,  0,  0 );
    VSET( b, 10,  0,  0 );
    VSET( c, 10, 10,  0 );
    VSET( d,  0, 10,  0 );

    make_face( a, b, c, d, 2 );

    mk_export_fwrite( fp, "spl", (genptr_t)&si, ID_BSPLINE );

    return 0;
}
Esempio n. 20
0
/**
 * rt_nurb_kvmerge()
 *
 * Merge two knot vectors together and return the new resulting knot
 * vector.
 */
void
rt_nurb_kvmerge(struct knot_vector *new_knots, const struct knot_vector *kv1, const struct knot_vector *kv2, struct resource *res)
{
    int kv1_ptr = 0;
    int kv2_ptr = 0;
    int new_ptr;

    if (res) RT_CK_RESOURCE(res);

    new_knots->k_size = kv1->k_size + kv2->k_size;

    new_knots->knots = (fastf_t *) bu_malloc(
	sizeof (fastf_t) * new_knots->k_size,
	"rt_nurb_kvmerge: new knot values");

    for (new_ptr = 0; new_ptr < new_knots->k_size; new_ptr++) {
	if (kv1_ptr >= kv1->k_size)
	    new_knots->knots[new_ptr] = kv2->knots[kv2_ptr++];
	else if (kv2_ptr >= kv2->k_size)
	    new_knots->knots[new_ptr] = kv1->knots[kv1_ptr++];
	else if (kv1->knots[kv1_ptr] < kv2->knots[kv2_ptr])
	    new_knots->knots[new_ptr] = kv1->knots[kv1_ptr++];
	else
	    new_knots->knots[new_ptr] = kv2->knots[kv2_ptr++];
    }
}
Esempio n. 21
0
void
db_add_node_to_full_path(struct db_full_path *pp, struct directory *dp)
{
    RT_CK_FULL_PATH(pp);

    if (pp->fp_maxlen <= 0) {
	pp->fp_maxlen = 32;
	pp->fp_names = (struct directory **)bu_malloc(
	    pp->fp_maxlen * sizeof(struct directory *),
	    "db_full_path array");
	pp->fp_bool = (int *)bu_calloc(pp->fp_maxlen, sizeof(int),
	    "db_full_path bool array");
	pp->fp_mat = (matp_t *)bu_calloc(pp->fp_maxlen, sizeof(matp_t),
	    "db_full_path matrices array");
    } else if (pp->fp_len >= pp->fp_maxlen) {
	pp->fp_maxlen *= 4;
	pp->fp_names = (struct directory **)bu_realloc(
	    (char *)pp->fp_names,
	    pp->fp_maxlen * sizeof(struct directory *),
	    "enlarged db_full_path array");
	pp->fp_bool = (int *)bu_realloc(
	    (char *)pp->fp_bool,
	    pp->fp_maxlen * sizeof(int),
	    "enlarged db_full_path bool array");
	pp->fp_mat = (matp_t *)bu_realloc(
	    (char *)pp->fp_mat,
	    pp->fp_maxlen * sizeof(matp_t),
	    "enlarged db_full_path matrices array");
    }
    pp->fp_names[pp->fp_len++] = dp;
}
Esempio n. 22
0
int
db_argv_to_path(struct db_full_path *pp, struct db_i *dbip, int argc, const char *const *argv)
{
    struct directory *dp;
    int ret = 0;
    int i;

    RT_CK_DBI(dbip);

    /* Make a path structure just big enough */
    pp->magic = DB_FULL_PATH_MAGIC;
    pp->fp_maxlen = pp->fp_len = argc;
    pp->fp_names = (struct directory **)bu_malloc(
	pp->fp_maxlen * sizeof(struct directory *),
	"db_argv_to_path path array");
    pp->fp_bool = (int *)bu_calloc(pp->fp_maxlen, sizeof(int),
	"db_argv_to_path bool array");
    pp->fp_mat = (matp_t *)bu_calloc(pp->fp_maxlen, sizeof(matp_t),
	"db_string_to_path mat array");

    for (i = 0; i<argc; i++) {
	if ((dp = db_lookup(dbip, argv[i], LOOKUP_NOISY)) == RT_DIR_NULL) {
	    bu_log("db_argv_to_path() failed on element %d='%s'\n",
		   i, argv[i]);
	    ret = -1; /* FAILED */
	    /* Fall through, storing null dp in this location */
	}
	pp->fp_names[i] = dp;
    }
    return ret;
}
Esempio n. 23
0
File: str.c Progetto: kanzure/brlcad
char *
bu_strdupm(register const char *cp, const char *label)
{
    char *base;
    size_t len;

    if (UNLIKELY(!cp && label)) {
	bu_semaphore_acquire(BU_SEM_SYSCALL);
	fprintf(stderr, "WARNING: [%s] NULL copy buffer\n", label);
	bu_semaphore_release(BU_SEM_SYSCALL);
    }
    if (!label) {
	label = "bu_strdup";
    }

    len = strlen(cp)+1;
    base = (char *)bu_malloc(len, label);

    if (UNLIKELY(bu_debug&BU_DEBUG_MEM_LOG)) {
	bu_semaphore_acquire(BU_SEM_SYSCALL);
	fprintf(stderr, "%p strdup%llu \"%s\"\n", (void *)base, (unsigned long long)len, cp);
	bu_semaphore_release(BU_SEM_SYSCALL);
    }

    memcpy(base, cp, len);
    return base;
}
Esempio n. 24
0
void
render_camera_init(render_camera_t *camera, int threads)
{
    camera->type = RENDER_CAMERA_PERSPECTIVE;

    camera->view_num = 1;
    camera->view_list = (render_camera_view_t *) bu_malloc (sizeof(render_camera_view_t), "render_camera_init");
    camera->dof = 0;
    camera->tilt = 0;

    /* The camera will use a thread for every cpu the machine has. */
    camera->thread_num = threads ? threads : (uint8_t)bu_avail_cpus();

    bu_semaphore_init(TIE_SEM_LAST);

    /* Initialize camera to rendering surface normals */
    render_normal_init(&camera->render, NULL);
    camera->rm = RENDER_METHOD_PHONG;

    if (shaders == NULL) {
#define REGISTER(x) render_shader_register((const char *)#x, render_##x##_init);
	REGISTER(component);
	REGISTER(cut);
	REGISTER(depth);
	REGISTER(flat);
	REGISTER(flos);
	REGISTER(grid);
	REGISTER(normal);
	REGISTER(path);
	REGISTER(phong);
	REGISTER(spall);
	REGISTER(surfel);
#undef REGISTER
    }
}
Esempio n. 25
0
void
Wgl_fb_open()
{
    char *wgl_name = "/dev/wgl";

    if ((fbp = (FBIO *)calloc(sizeof(FBIO), 1)) == FBIO_NULL) {
	Tcl_AppendResult(interp, "Wgl_fb_open: failed to allocate framebuffer memory\n",
			 (char *)NULL);
	return;
    }

    *fbp = wgl_interface; /* struct copy */

    fbp->if_name = bu_malloc((unsigned)strlen(wgl_name)+1, "if_name");
    bu_strlcpy(fbp->if_name, wgl_name, strlen(wgl_name)+1);

    /* Mark OK by filling in magic number */
    fbp->if_magic = FB_MAGIC;
    _wgl_open_existing(fbp,
		       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->dpy,
		       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->win,
		       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->cmap,
		       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->vip,
		       ((struct dm_xvars *)dmp->dm_vars.pub_vars)->hdc,
		       dmp->dm_width, dmp->dm_height,
		       ((struct wgl_vars *)dmp->dm_vars.priv_vars)->glxc,
		       ((struct wgl_vars *)dmp->dm_vars.priv_vars)->mvars.doublebuffer, 0);
}
Esempio n. 26
0
int
main(int argc, char **argv)
{
    int i;

    if (!get_args(argc, argv) || isatty(fileno(stdout))) {
	(void)fputs(usage, stderr);
	bu_exit (1, NULL);
    }

    if (inx <= 0 || iny <= 0 || outx <= 0 || outy <= 0) {
	fprintf(stderr, "bwscale: bad size\n");
	bu_exit (2, NULL);
    }

    /* See how many lines we can buffer */
    scanlen = inx;
    init_buffer(scanlen);

    i = (inx < outx) ? outx : inx;
    outbuf = (unsigned char *)bu_malloc(i, "outbuf");

    /* Here we go */
    scale(stdout, inx, iny, outx, outy);

    bu_free(outbuf, (const char *)buffer);
    bu_free(buffer, (const char *)buffer);
    return 0;
}
Esempio n. 27
0
/**
 * Using a single call to db_put(), write multiple zeroed records out,
 * all with u_id field set to ID_FREE.
 * This will zap all records from "start" to the end of this entry.
 *
 * Returns:
 * 0 on success (from db_put())
 * non-zero on failure
 */
int
db_zapper(struct db_i *dbip, struct directory *dp, size_t start)
{
    union record *rp;
    size_t i;
    size_t todo;
    int ret;

    RT_CK_DBI(dbip);
    RT_CK_DIR(dp);
    if (RT_G_DEBUG&DEBUG_DB) bu_log("db_zapper(%s) %p, %p, start=%zu\n",
				    dp->d_namep, (void *)dbip, (void *)dp, start);

    if (dp->d_flags & RT_DIR_INMEM) bu_bomb("db_zapper() called on RT_DIR_INMEM object\n");

    if (dbip->dbi_read_only)
	return -1;

    BU_ASSERT_LONG(dbip->dbi_version, ==, 4);

    if (dp->d_len < start)
	return -1;

    if ((todo = dp->d_len - start) == 0)
	return 0;		/* OK -- trivial */

    rp = (union record *)bu_malloc(todo * sizeof(union record), "db_zapper buf");
    memset((char *)rp, 0, todo * sizeof(union record));

    for (i=0; i < todo; i++)
	rp[i].u_id = ID_FREE;
    ret = db_put(dbip, dp, rp, (off_t)start, todo);
    bu_free((char *)rp, "db_zapper buf");
    return ret;
}
Esempio n. 28
0
/**
 * rt_nurb_kvknot()
 *
 * Generate a open knot vector with n=order knots at the beginning of
 * the sequence and n knots at the end of the sequence with a lower,
 * and an upper value and num knots in between
 */
void
rt_nurb_kvknot(register struct knot_vector *new_knots, int order, fastf_t lower, fastf_t upper, int num, struct resource *res)
{
    register int i;
    int total;
    fastf_t knot_step;

    if (res) RT_CK_RESOURCE(res);

    total = order * 2 + num;

    knot_step = (upper - lower) / (num + 1);

    new_knots->k_size = total;

    new_knots->knots = (fastf_t *) bu_malloc (sizeof(fastf_t) * total,
					      "rt_nurb_kvknot: new knots values");

    for (i = 0; i < order; i++)
	new_knots->knots[i] = lower;

    for (i = order; i <= (num + order - 1); i++)
	new_knots->knots[i] = new_knots->knots[i-1] + knot_step;

    for (i = (num + order); i < total; i++)
	new_knots->knots[i] = upper;
}
Esempio n. 29
0
/**
 * rt_nurb_kvmult()
 *
 * Construct a new knot vector which is the same as the passed in knot
 * vector except it has multiplicity of num of val. It checks to see
 * if val already is a multiple knot.
 */
void
rt_nurb_kvmult(struct knot_vector *new_kv, const struct knot_vector *kv, int num, register fastf_t val, struct resource *res)
{
    int n;
    register int i;
    struct knot_vector check;

    if (res) RT_CK_RESOURCE(res);

    n = rt_nurb_kvcheck(val, kv);

    check.k_size = num - n;
    if (check.k_size <= 0) {
	bu_log("rt_nurb_kvmult(new_kv=%p, kv=%p, num=%d, val=%g)\n",
	       (void *)new_kv, (void *)kv, num, val);
	rt_nurb_pr_kv(kv);
	bu_bomb("rt_nurb_kvmult\n");
    }

    check.knots = (fastf_t *) bu_malloc(sizeof(fastf_t) * check.k_size,
					"rt_nurb_kvmult: check knots");

    for (i = 0; i < num - n; i++)
	check.knots[i] = val;

    rt_nurb_kvmerge(new_kv, &check, kv, res);

    /* free up old knot values */
    bu_free((char *)check.knots, "rt_nurb_kvmult:check knots");
}
Esempio n. 30
0
/**
 * The external format is:
 * V point
 * A vector
 * B vector
 * C vector
 */
int
rt_superell_export5(struct bu_external *ep, const struct rt_db_internal *ip, double local2mm, const struct db_i *dbip)
{
    struct rt_superell_internal *eip;

    /* must be double for import and export */
    double vec[ELEMENTS_PER_VECT*4 + 2];

    if (dbip) RT_CK_DBI(dbip);

    RT_CK_DB_INTERNAL(ip);
    if (ip->idb_type != ID_SUPERELL) return -1;
    eip = (struct rt_superell_internal *)ip->idb_ptr;
    RT_SUPERELL_CK_MAGIC(eip);

    BU_CK_EXTERNAL(ep);
    ep->ext_nbytes = SIZEOF_NETWORK_DOUBLE * (ELEMENTS_PER_VECT*4 + 2);
    ep->ext_buf = (uint8_t *)bu_malloc(ep->ext_nbytes, "superell external");

    /* scale 'em into local buffer */
    VSCALE(&vec[0*ELEMENTS_PER_VECT], eip->v, local2mm);
    VSCALE(&vec[1*ELEMENTS_PER_VECT], eip->a, local2mm);
    VSCALE(&vec[2*ELEMENTS_PER_VECT], eip->b, local2mm);
    VSCALE(&vec[3*ELEMENTS_PER_VECT], eip->c, local2mm);

    vec[4*ELEMENTS_PER_VECT] = eip->n;
    vec[4*ELEMENTS_PER_VECT + 1] = eip->e;

    /* Convert from internal (host) to database (network) format */
    bu_cv_htond(ep->ext_buf, (unsigned char *)vec, ELEMENTS_PER_VECT*4 + 2);

    return 0;
}