struct bn_vlblock * bn_vlblock_init(struct bu_list *free_vlist_hd, /**< where to get/put free vlists */ int max_ent /**< maximum number of entities to get/put */) { struct bn_vlblock *vbp; size_t i; if (!BU_LIST_IS_INITIALIZED(free_vlist_hd)) BU_LIST_INIT(free_vlist_hd); BU_ALLOC(vbp, struct bn_vlblock); vbp->magic = BN_VLBLOCK_MAGIC; vbp->free_vlist_hd = free_vlist_hd; vbp->max = max_ent; vbp->head = (struct bu_list *)bu_calloc(vbp->max, sizeof(struct bu_list), "head[]"); vbp->rgb = (long *)bu_calloc(vbp->max, sizeof(long), "rgb[]"); for (i=0; i < vbp->max; i++) { vbp->rgb[i] = 0; BU_LIST_INIT(&(vbp->head[i])); } vbp->rgb[0] = 0xFFFF00L; /* Yellow, default */ vbp->rgb[1] = 0xFFFFFFL; /* White */ vbp->nused = 2; return vbp; }
void RegionList::create(rt_wdb* wdbp) { wmember allRegions; BU_LIST_INIT(&allRegions.l); for (std::map<std::string, Bot>::iterator it = m_list.begin(); it != m_list.end(); ++it) { it->second.write(wdbp); wmember regionContent; BU_LIST_INIT(®ionContent.l); mk_addmember(it->second.name().c_str(), ®ionContent.l, 0, WMOP_UNION); int id = (int)toValue(it->first.c_str()); mk_lrcomb(wdbp, it->first.c_str(), ®ionContent, 1, "plastic", "sh=4 sp=0.5 di=0.5 re=0.1", 0, id, 0, 0, 100, 0); mk_addmember(it->first.c_str(), &allRegions.l, 0, WMOP_UNION); mk_freemembers(®ionContent.l); } mk_lfcomb(wdbp, "all.g", &allRegions, 0); mk_freemembers(&allRegions.l); }
static union tree * facetize_region_end(struct db_tree_state *tsp, const struct db_full_path *pathp, union tree *curtree, void *client_data) { struct bu_list vhead; union tree **facetize_tree; if (tsp) RT_CK_DBTS(tsp); if (pathp) RT_CK_FULL_PATH(pathp); facetize_tree = (union tree **)client_data; BU_LIST_INIT(&vhead); if (curtree->tr_op == OP_NOP) return curtree; if (*facetize_tree) { union tree *tr; BU_ALLOC(tr, union tree); RT_TREE_INIT(tr); tr->tr_op = OP_UNION; tr->tr_b.tb_regionp = REGION_NULL; tr->tr_b.tb_left = *facetize_tree; tr->tr_b.tb_right = curtree; *facetize_tree = tr; } else { *facetize_tree = curtree; } /* Tree has been saved, and will be freed later */ return TREE_NULL; }
/* * R T _ N U R B _ B E Z I E R * * Given a single snurb, if it is in Bezier form, * duplicate the snurb, and enqueue it on the bezier_hd list. * If the original snurb is NOT in Bezier form, * subdivide it a set of snurbs which are, * each of which are enqueued on the bezier_hd list. * * In either case, the original surface remains untouched. * * Returns - * 0 Surface splitting was done. * 1 Original surface was Bezier, only a copy was done. */ int rt_nurb_bezier(struct bu_list *bezier_hd, const struct face_g_snurb *orig_surf, struct resource *res) { struct face_g_snurb *s; int dir; struct bu_list todo; NMG_CK_SNURB(orig_surf); if ( (dir = rt_bez_check( orig_surf )) == -1) { s = rt_nurb_scopy( orig_surf, res ); BU_LIST_APPEND( bezier_hd, &s->l ); return 1; /* Was already Bezier, nothing done */ } BU_LIST_INIT( &todo ); rt_nurb_s_split( &todo, orig_surf, dir, res ); while ( BU_LIST_WHILE( s, face_g_snurb, &todo ) ) { if ( (dir = rt_bez_check(s)) == -1) { /* This snurb is now a Bezier */ BU_LIST_DEQUEUE( &s->l ); BU_LIST_APPEND( bezier_hd, &s->l ); } else { /* Split, and keep going */ BU_LIST_DEQUEUE( &s->l ); rt_nurb_s_split( &todo, s, dir, res ); rt_nurb_free_snurb(s, res); } } return 0; /* Bezier snurbs on bezier_hd list */ }
void make_room(char *rname, fastf_t *imin, fastf_t *imax, fastf_t *thickness, struct wmember *headp) /* Interior RPP min point */ { struct wmember head; char name[32]; vect_t omin; vect_t omax; BU_LIST_INIT( &head.l ); VSUB2( omin, imin, thickness ); VADD2( omax, imax, thickness ); snprintf( name, 32, "o%s", rname ); mk_rpp( outfp, name, omin, omax ); (void)mk_addmember( name, &head.l, NULL, WMOP_UNION ); snprintf( name, 32, "i%s", rname ); mk_rpp( outfp, name, imin, imax ); mk_addmember( name, &head.l, NULL, WMOP_SUBTRACT ); mk_lfcomb( outfp, rname, &head, 1 ); (void)mk_addmember( rname, &(headp->l), NULL, WMOP_UNION ); }
HIDDEN struct bu_cmdhist_obj * cho_open(ClientData UNUSED(clientData), Tcl_Interp *interp, const char *name) { struct bu_cmdhist_obj *chop; /* check to see if command history object exists */ for (BU_LIST_FOR(chop, bu_cmdhist_obj, &HeadCmdHistObj.l)) { if (BU_STR_EQUAL(name, bu_vls_addr(&chop->cho_name))) { Tcl_AppendResult(interp, "ch_open: ", name, " exists.\n", (char *)NULL); return BU_CMDHIST_OBJ_NULL; } } BU_GET(chop, struct bu_cmdhist_obj); bu_vls_init(&chop->cho_name); bu_vls_strcpy(&chop->cho_name, name); BU_LIST_INIT(&chop->cho_head.l); bu_vls_init(&chop->cho_head.h_command); chop->cho_head.h_start.tv_sec = chop->cho_head.h_start.tv_usec = chop->cho_head.h_finish.tv_sec = chop->cho_head.h_finish.tv_usec = 0L; chop->cho_head.h_status = TCL_OK; chop->cho_curr = &chop->cho_head; BU_LIST_APPEND(&HeadCmdHistObj.l, &chop->l); return chop; }
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; }
int mk_ring(struct rt_wdb *fp, double orbit, double width, double thick, double wallthick, double wallheight) { point_t base = {0, 0, 0}, height = {0, 0, 0}; struct wmember c; /* make 3 rcc's and glue them together */ /* this additive component */ base[Z] = -1000*width/2.0; height[Z] = 1000*width; mk_rcc(fp, "ringadd.s", base, height, 1000*orbit); /* the small cut to make the walls 'n stuff */ base[Z] += 1000*wallthick; height[Z] -= 1000*2.0*wallthick; mk_rcc(fp, "ringsub1.s", base, height, 1000*(orbit-thick)); /* the big cut out of the middle */ base[Z] = -1000*width; height[Z] = 1000*2*width; mk_rcc(fp, "ringsub2.s", base, height, 1000*(orbit - wallheight)); /* and do the CSG */ BU_LIST_INIT(&c.l); mk_addmember("ringadd.s", &c.l, NULL, WMOP_UNION); mk_addmember("ringsub1.s", &c.l, NULL, WMOP_SUBTRACT); mk_addmember("ringsub2.s", &c.l, NULL, WMOP_SUBTRACT); mk_lcomb(fp, "ring.r", &c, 1, "plastic", "", NULL, 0); return 0; }
static struct nmgregion * nmg_construct_region(struct model *parent, const struct nmgregion *original, void **structArray) { struct nmgregion *ret; NMG_GETSTRUCT(ret, nmgregion); ret->l.magic = NMG_REGION_MAGIC; ret->m_p = parent; ret->ra_p = (struct nmgregion_a *)NULL; BU_LIST_INIT(&ret->s_hd); ret->index = original->index; structArray[ret->index] = ret; if (original->ra_p != NULL) { const struct nmgregion_a *originalAttributes = original->ra_p; struct nmgregion_a *newAttributes = (struct nmgregion_a *)structArray[originalAttributes->index]; if (newAttributes == NULL) newAttributes = nmg_construct_region_a(originalAttributes, structArray); ret->ra_p = newAttributes; } return ret; }
void crregion(char *region, char *op, int *members, int number, char *solidname, int maxlen) { int i; struct bu_list head; if (dbip == DBI_NULL) return; BU_LIST_INIT(&head); for (i=0; i<number; i++) { solidname[8] = '\0'; crname(solidname, members[i], maxlen); if ( db_lookup( dbip, solidname, LOOKUP_QUIET) == DIR_NULL ) { Tcl_AppendResult(interp, "region: ", region, " will skip member: ", solidname, "\n", (char *)NULL); continue; } mk_addmember( solidname, &head, NULL, op[i] ); } (void)mk_comb( wdbp, region, &head, 1, NULL, NULL, NULL, 500+Trackpos+i, 0, mat_default, los_default, 0, 1, 1 ); }
static union tree * bev_facetize_region_end(struct db_tree_state *UNUSED(tsp), const struct db_full_path *pathp, union tree *curtree, genptr_t client_data) { struct bu_list vhead; struct ged *gedp = (struct ged *)client_data; BU_LIST_INIT(&vhead); if (RT_G_DEBUG&DEBUG_TREEWALK) { char *sofar = db_path_to_string(pathp); bu_vls_printf(gedp->ged_result_str, "bev_facetize_region_end() path='%s'\n", sofar); bu_free((genptr_t)sofar, "path string"); } if (curtree->tr_op == OP_NOP) return curtree; bu_semaphore_acquire(RT_SEM_MODEL); if (bev_facetize_tree) { union tree *tr; BU_ALLOC(tr, union tree); RT_TREE_INIT(tr); tr->tr_op = OP_UNION; tr->tr_b.tb_regionp = REGION_NULL; tr->tr_b.tb_left = bev_facetize_tree; tr->tr_b.tb_right = curtree; bev_facetize_tree = tr; } else { bev_facetize_tree = curtree; } bu_semaphore_release(RT_SEM_MODEL); /* Tree has been saved, and will be freed later */ return TREE_NULL; }
void bu_hook_list_init(struct bu_hook_list *hlp) { BU_LIST_INIT(&hlp->l); hlp->hookfunc = BU_HOOK_NULL; hlp->clientdata = GENPTR_NULL; }
static void _bu_add_to_list(const char *fn, int fd) { struct _bu_tf_list *newtf; _bu_temp_files++; if (_bu_temp_files == 1) { /* schedule files for closure on exit */ atexit(_bu_close_files); BU_GETSTRUCT(_bu_tf, _bu_tf_list); BU_LIST_INIT(&(_bu_tf->l)); bu_vls_init(&_bu_tf->fn); bu_vls_strcpy(&_bu_tf->fn, fn); _bu_tf->fd = fd; return; } BU_GETSTRUCT(newtf, _bu_tf_list); bu_vls_init(&_bu_tf->fn); bu_vls_strcpy(&_bu_tf->fn, fn); newtf->fd = fd; BU_LIST_PUSH(&(_bu_tf->l), &(newtf->l)); return; }
/** * Stub function which will "simulate" a call to a vector shot routine */ HIDDEN void vshot_stub(struct soltab **stp, struct xray **rp, struct seg *segp, int n, struct application *ap) /* An array of solid pointers */ /* An array of ray pointers */ /* array of segs (results returned) */ /* Number of ray/object pairs */ /* pointer to an application */ { register int i; register struct seg *tmp_seg; struct seg seghead; int ret; BU_LIST_INIT(&(seghead.l)); /* go through each ray/solid pair and call a scalar function */ for (i = 0; i < n; i++) { if (stp[i] != 0) { /* skip call if solid table pointer is NULL */ /* do scalar call, place results in segp array */ ret = -1; if (OBJ[stp[i]->st_id].ft_shot) { ret = OBJ[stp[i]->st_id].ft_shot(stp[i], rp[i], ap, &seghead); } if (ret <= 0) { segp[i].seg_stp=(struct soltab *) 0; } else { tmp_seg = BU_LIST_FIRST(seg, &(seghead.l)); BU_LIST_DEQUEUE(&(tmp_seg->l)); segp[i] = *tmp_seg; /* structure copy */ RT_FREE_SEG(tmp_seg, ap->a_resource); } } } }
/** * Creates one metaball object that includes all points from an * existing list (in 'av') of named metaballs. This routine creates * an rt_metaball_internal object directly via LIBRT given it requires * reading existing metaballs from the database. */ static void mix_balls(struct db_i *dbip, const char *name, int ac, const char *av[]) { int i; struct directory *dp; struct rt_metaball_internal *newmp; RT_CK_DBI(dbip); /* allocate a struct rt_metaball_internal object that we'll * manually fill in with points from the other metaballs being * joined together. */ BU_ALLOC(newmp, struct rt_metaball_internal); newmp->magic = RT_METABALL_INTERNAL_MAGIC; newmp->threshold = 1.0; newmp->method = 1; BU_LIST_INIT(&newmp->metaball_ctrl_head); bu_log("Combining together the following metaballs:\n"); for (i = 0; i < ac; i++) { struct rt_db_internal dir; struct rt_metaball_internal *mp; struct wdb_metaballpt *mpt; /* get a handle on the existing database object */ bu_log("\t%s\n", av[i]); dp = db_lookup(dbip, av[i], 1); if (!dp) { bu_log("Unable to find %s\n", av[i]); continue; } /* load the existing database object */ if (rt_db_get_internal(&dir, dp, dbip, NULL, &rt_uniresource) < 0) { bu_log("Unable to load %s\n", av[i]); continue; } /* access the metaball-specific internal structure */ mp = (struct rt_metaball_internal *)dir.idb_ptr; RT_METABALL_CK_MAGIC(mp); /* iterate over each point in that database object and add it * to our new metaball. */ for (BU_LIST_FOR(mpt, wdb_metaballpt, &mp->metaball_ctrl_head)) { bu_log("Adding point (%lf %lf %lf)\n", V3ARGS(mpt->coord)); rt_metaball_add_point(newmp, (const point_t *)&mpt->coord, mpt->fldstr, mpt->sweat); } } bu_log("Joining balls together and creating [%s] object\n", name); /* write out new "mega metaball" out to disk */ dbip->dbi_wdbp = wdb_dbopen(dbip, RT_WDB_TYPE_DB_DISK); wdb_export(dbip->dbi_wdbp, name, newmp, ID_METABALL, 1.0); }
int Fbo_Init(Tcl_Interp *interp) { BU_LIST_INIT(&HeadFBObj.l); (void)Tcl_CreateCommand(interp, "fb_open", (Tcl_CmdProc *)fbo_open_tcl, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); return TCL_OK; }
int rt_process_casec(struct edge_g_cnurb *trim, fastf_t u, fastf_t v) { struct edge_g_cnurb * clip; int jordan_hit; struct bu_list plist; int trim_flag = 0; int caset; /* determine if the the u, v values are on the curve */ if ( rt_nurb_uv_dist(trim, u, v) == TRIM_ON) return TRIM_IN; jordan_hit = 0; BU_LIST_INIT(&plist); if ( nurb_crv_is_bezier( trim ) ) rt_clip_cnurb(&plist, trim, u, v); else nurb_c_to_bezier( &plist, trim ); while ( BU_LIST_WHILE( clip, edge_g_cnurb, &plist ) ) { BU_LIST_DEQUEUE( &clip->l ); caset = rt_trim_case(clip, u, v); trim_flag = 0; if ( caset == CASE_B) trim_flag = rt_process_caseb(clip, u, v); if ( caset == CASE_C) trim_flag = rt_process_casec(clip, u, v); rt_nurb_free_cnurb( clip ); if ( trim_flag == TRIM_IN) jordan_hit++; if ( trim_flag == TRIM_ON) break; } while ( BU_LIST_WHILE( clip, edge_g_cnurb, &plist) ) { BU_LIST_DEQUEUE( &clip->l ); rt_nurb_free_cnurb( clip ); } if ( trim_flag == TRIM_ON) return TRIM_ON; else if ( jordan_hit & 01 ) return TRIM_IN; else return TRIM_OUT; }
/** * used for db put/asc2g */ int rt_metaball_adjust(struct bu_vls *logstr, struct rt_db_internal *intern, int argc, const char **argv) { struct rt_metaball_internal *mb; const char *pts; const char *pend; double thresh; if (argc != 3) { bu_vls_printf(logstr, "Invalid number of arguments: %d\n", argc); return BRLCAD_ERROR; } RT_CK_DB_INTERNAL(intern); mb = (struct rt_metaball_internal *)intern->idb_ptr; RT_METABALL_CK_MAGIC(mb); if ( strlen(*argv) != 1 || (**argv < '0' || **argv > '2') ) { bu_vls_printf(logstr, "Invalid method type, must be one of 0, 1, or 2."); return BRLCAD_ERROR; } mb->method = *argv[0] - '0'; sscanf(argv[1], "%lG", &thresh); mb->threshold = thresh; BU_LIST_INIT(&mb->metaball_ctrl_head); pts = argv[2]; pend = pts + strlen(pts); while (1) { int len; double xyz[3]; double fldstr, goo; point_t loc; const point_t *locp = (const point_t *)&loc; while ( pts < pend && *pts != '{' ) ++pts; if (pts >= pend) break; len = sscanf(pts, "{%lG %lG %lG %lG %lG}", &xyz[0], &xyz[1], &xyz[2], &fldstr, &goo); VMOVE(loc, xyz); if (len == EOF) break; if (len != 5) { bu_vls_printf(logstr, "Failed to parse point information: \"%s\"", pts); return BRLCAD_ERROR; } pts++; if (rt_metaball_add_point (mb, locp, fldstr, goo)) { bu_vls_printf(logstr, "Failure adding point: {%f %f %f %f %f}", V3ARGS(loc), fldstr, goo); return BRLCAD_ERROR; } } return BRLCAD_OK; }
/** * B U _ P T B L _ I N I T * * Initialize struct & get storage for table. * Recommend 8 or 64 for initial len. */ void bu_ptbl_init(struct bu_ptbl *b, int len, const char *str) { if (bu_debug & BU_DEBUG_PTBL) bu_log("bu_ptbl_init(%8x, len=%d, %s)\n", b, len, str); BU_LIST_INIT(&b->l); b->l.magic = BU_PTBL_MAGIC; if ( len <= 0 ) len = 64; b->blen = len; b->buffer = (long **)bu_calloc(b->blen, sizeof(long *), str); b->end = 0; }
int main(int argc, char *argv[]) { static const char usage[] = "Usage:\n%s [-o outfile] \n\n -o file \tFile to write out (default: ringworld.g)\n\n"; char outfile[MAXPATHLEN] = "ringworld.g"; int optc; struct rt_wdb *fp; while ((optc = bu_getopt(argc, argv, "o:h?")) != -1) { if (bu_optopt == '?') optc='h'; switch (optc) { case 'o': snprintf(outfile, MAXPATHLEN, "%s", bu_optarg); break; default: fprintf(stderr,usage, *argv); return optc == '?' ? EXIT_FAILURE : EXIT_SUCCESS; } } if (argc == 1) { fprintf(stderr,usage, *argv); fprintf(stderr," Program continues running:\n"); } if (bu_file_exists(outfile, NULL)) bu_exit(EXIT_FAILURE, "ERROR: %s already exists. Remove file and try again.", outfile); bu_log("Writing ringworld out to [%s]\n", outfile); fp = wdb_fopen(outfile); mk_sol(fp, SUN_DIAMETER); mk_ring(fp, RING_ORBIT, RING_WIDTH, RING_FLOOR_THICKNESS, RING_WALL_THICKNESS, RING_WALL_HEIGHT); mk_shadowring(fp, SHADOWRING_ORBIT, SHADOWRING_NUM, SHADOWRING_WIDTH, SHADOWRING_LENGTH, SHADOWRING_THICKNESS); /* generate a comb all.g */ { struct wmember c; BU_LIST_INIT(&c.l); mk_addmember("ring.r", &c.l, NULL, WMOP_UNION); mk_addmember("sun.r", &c.l, NULL, WMOP_UNION); /* mk_addmember("shadowring.r", &c.l, NULL, WMOP_UNION); */ mk_lcomb(fp, "all.g", &c, 0, NULL, NULL, NULL, 0); } wdb_close(fp); bu_log("BRL-CAD geometry database file [%s] created.\nDone.\n", outfile); return EXIT_SUCCESS; }
int mk_sol(struct rt_wdb *fp, double radius) { struct wmember c; point_t p = { 0, 0, 0}; /* make a sphere! tada! */ mk_sph(fp, "sun.s", p, radius * 1000.0); BU_LIST_INIT(&c.l); mk_addmember("sun.s", &c.l, NULL, WMOP_UNION); mk_lcomb(fp, "sun.r", &c, 1, NULL, NULL, NULL, 0); return 0; }
int make_bond(int sp1, int sp2) { struct sphere * s1, *s2, *s_ptr; point_t base; vect_t height; char nm[128], nm1[128]; unsigned char rgb[3]; struct wmember reg_head; s1 = s2 = (struct sphere *) 0; for (s_ptr = s_head; s_ptr != (struct sphere *)0; s_ptr = s_ptr->next) { if (s_ptr->s_id == sp1) s1 = s_ptr; if (s_ptr->s_id == sp2) s2 = s_ptr; } if (s1 == (struct sphere *) 0 || s2 == (struct sphere *)0) return -1; /* error */ VMOVE(base, s1->s_center); VSUB2(height, s2->s_center, s1->s_center); sprintf(nm, "bond.%d.%d", sp1, sp2); rgb[0] = 191; rgb[1] = 142; rgb[2] = 57; #if 1 /* Use this for mol-cube.dat */ mk_rcc(outfp, nm, base, height, s1->s_rad * 0.15); #else /* Use this for chemical molecules */ mk_rcc(outfp, nm, base, height, s1->s_rad * 0.5); #endif BU_LIST_INIT(®_head.l); (void)mk_addmember(nm, ®_head.l, NULL, WMOP_UNION); (void)mk_addmember(s1->s_name, ®_head.l, NULL, WMOP_SUBTRACT); (void)mk_addmember(s2->s_name, ®_head.l, NULL, WMOP_SUBTRACT); sprintf(nm1, "BOND.%d.%d", sp1, sp2); mk_lcomb(outfp, nm1, ®_head, 1, matname, matparm, rgb, 0); (void)mk_addmember(nm1, &head.l, NULL, WMOP_UNION); return 0; /* OK */ }
int Cho_Init(Tcl_Interp *interp) { memset(&HeadCmdHistObj, 0, sizeof(struct bu_cmdhist_obj)); BU_LIST_INIT(&HeadCmdHistObj.l); BU_VLS_INIT(&HeadCmdHistObj.cho_name); /* cho_head already zero'd */ HeadCmdHistObj.cho_curr = NULL; (void)Tcl_CreateCommand(interp, "ch_open", (Tcl_CmdProc *)cho_open_tcl, (ClientData)NULL, (Tcl_CmdDeleteProc *)NULL); return TCL_OK; }
HIDDEN void historyInit(void) { BU_LIST_INIT(&(histHead.l)); bu_vls_init(&(histHead.h_command)); histHead.h_start.tv_sec = histHead.h_start.tv_usec = histHead.h_finish.tv_sec = histHead.h_finish.tv_usec = 0L; histHead.h_status = TCL_OK; currHist = &histHead; #if 0 journalfp = NULL; #endif historyInitialized=1; }
/* * R T _ H T B L _ I N I T */ void rt_htbl_init(struct rt_htbl *b, int len, const char *str) /* initial len. */ { if (bu_debug & BU_DEBUG_PTBL) bu_log("rt_htbl_init(%8x, len=%d, %s)\n", b, len, str); BU_LIST_INIT(&b->l); b->l.magic = RT_HTBL_MAGIC; if ( len <= 0 ) len = 64; b->blen = len; b->hits = (struct hit *)bu_calloc(b->blen, sizeof(struct hit), str); b->end = 0; }
/* * M K _ V E R T E X ( ) * */ struct vertex *mk_vertex (long int index, char *label) { struct vertex *vp; vp = (struct vertex *) bu_malloc(sizeof(struct vertex), "vertex"); vp -> v_magic = VERTEX_MAGIC; vp -> v_index = index; vp -> v_label = label; vp -> v_civilized = 0; BU_LIST_INIT(&(vp -> v_neighbors)); vp -> v_bridge = mk_init_bridge(vp); return (vp); }
/** * prep and build bounding volumes... unfortunately, generating the * bounding sphere is too 'loose' (I think) and O(n^2). */ int rt_metaball_prep(struct soltab *stp, struct rt_db_internal *ip, struct rt_i *rtip) { struct rt_metaball_internal *mb, *nmb; struct wdb_metaballpt *mbpt, *nmbpt; fastf_t minfstr = +INFINITY; if (rtip) RT_CK_RTI(rtip); mb = (struct rt_metaball_internal *)ip->idb_ptr; RT_METABALL_CK_MAGIC(mb); /* generate a copy of the metaball */ BU_ALLOC(nmb, struct rt_metaball_internal); nmb->magic = RT_METABALL_INTERNAL_MAGIC; BU_LIST_INIT(&nmb->metaball_ctrl_head); nmb->threshold = mb->threshold; nmb->method = mb->method; /* and copy the list of control points */ for (BU_LIST_FOR(mbpt, wdb_metaballpt, &mb->metaball_ctrl_head)) { BU_ALLOC(nmbpt, struct wdb_metaballpt); nmbpt->fldstr = mbpt->fldstr; if (mbpt->fldstr < minfstr) minfstr = mbpt->fldstr; nmbpt->sweat = mbpt->sweat; VMOVE(nmbpt->coord, mbpt->coord); BU_LIST_INSERT(&nmb->metaball_ctrl_head, &nmbpt->l); } /* find the bounding sphere */ stp->st_aradius = rt_metaball_get_bounding_sphere(&stp->st_center, mb->threshold, mb); stp->st_bradius = stp->st_aradius * 1.01; /* XXX magic numbers, increase if scalloping is observed. :(*/ nmb->initstep = minfstr / 2.0; if (nmb->initstep < (stp->st_aradius / 200.0)) nmb->initstep = (stp->st_aradius / 200.0); else if (nmb->initstep > (stp->st_aradius / 10.0)) nmb->initstep = (stp->st_aradius / 10.0); nmb->finalstep = /*stp->st_aradius * */minfstr / 1e5; /* generate a bounding box around the sphere... * XXX this can be optimized greatly to reduce the BSP presence... */ if (rt_metaball_bbox(ip, &(stp->st_min), &(stp->st_max), &rtip->rti_tol)) return 1; stp->st_specific = (void *)nmb; return 0; }
void do_tree(char *name, char *lname, int level) { int i; char nm[64]; char *leafp; int scale; struct wmember head; struct wmember *wp; BU_LIST_INIT(&head.l); if (level <= 1) leafp = lname; else leafp = nm; scale = 100; for (i=1; i<level; i++) scale *= 2; snprintf(nm, 64, "%sL", name); wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION); MAT_IDN(wp->wm_mat); snprintf(nm, 64, "%sR", name); wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION); MAT_DELTAS(wp->wm_mat, 1*scale, 0, 0); snprintf(nm, 64, "%sB", name); wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION); MAT_DELTAS(wp->wm_mat, 0.5*scale, sin60*scale, 0); snprintf(nm, 64, "%sT", name); wp = mk_addmember(leafp, &head.l, NULL, WMOP_UNION); MAT_DELTAS(wp->wm_mat, 0.5*scale, sin60/3*scale, sin60*scale); /* Set region flag on lowest level */ mk_lcomb(outfp, name, &head, level<=1, NULL, NULL, NULL, 0); /* Loop for children if level > 1 */ if (level <= 1) return; for (i=0; i<4; i++) { snprintf(nm, 64, "%s%c", name, "LRBTx"[i]); do_tree(nm, lname, level-1); } }
void bn_vlist_cleanup(struct bu_list *hd) { register struct bn_vlist *vp; if (!BU_LIST_IS_INITIALIZED(hd)) { BU_LIST_INIT(hd); return; } while (BU_LIST_WHILE(vp, bn_vlist, hd)) { BN_CK_VLIST(vp); BU_LIST_DEQUEUE(&(vp->l)); bu_free((char *)vp, "bn_vlist"); } }
static struct face_g_plane * nmg_construct_face_g_plane(const struct face_g_plane *original, void **structArray) { struct face_g_plane *ret; NMG_GETSTRUCT(ret, face_g_plane); ret->magic = NMG_FACE_G_PLANE_MAGIC; BU_LIST_INIT(&ret->f_hd); HMOVE(ret->N, original->N); ret->index = original->index; structArray[ret->index] = ret; return ret; }