static void make_bot_object(const char *name, struct rt_wdb *wdbp) { int i; int max_pt=0, min_pt=999999; int num_vertices; struct bu_bitv *bv=NULL; int bot_mode; int count; struct rt_bot_internal bot_ip; bot_ip.magic = RT_BOT_INTERNAL_MAGIC; for (i = 0; i < face_count; i++) { V_MIN(min_pt, faces[i*3]); V_MAX(max_pt, faces[i*3]); V_MIN(min_pt, faces[i*3+1]); V_MAX(max_pt, faces[i*3+1]); V_MIN(min_pt, faces[i*3+2]); V_MAX(max_pt, faces[i*3+2]); } num_vertices = max_pt - min_pt + 1; bot_ip.num_vertices = num_vertices; bot_ip.vertices = (fastf_t *)bu_calloc(num_vertices*3, sizeof(fastf_t), "BOT vertices"); for (i = 0; i < num_vertices; i++) VMOVE(&bot_ip.vertices[i*3], grid_pts[min_pt+i]); for (i = 0; i < face_count * 3; i++) faces[i] -= min_pt; bot_ip.num_faces = face_count; bot_ip.faces = bu_calloc(face_count*3, sizeof(int), "BOT faces"); for (i = 0; i < face_count*3; i++) bot_ip.faces[i] = faces[i]; bot_ip.face_mode = (struct bu_bitv *)NULL; bot_ip.thickness = (fastf_t *)NULL; if (mode == PLATE_MODE) { bot_mode = RT_BOT_PLATE; bv = bu_bitv_new(face_count); for (i = 0; i < face_count; i++) { if (facemode[i] == POS_FRONT) BU_BITSET(bv, i); } bot_ip.face_mode = bv; bot_ip.thickness = (fastf_t *)bu_calloc(face_count, sizeof(fastf_t), "BOT thickness"); for (i = 0; i < face_count; i++) bot_ip.thickness[i] = thickness[i]; } else bot_mode = RT_BOT_SOLID; bot_ip.mode = bot_mode; bot_ip.orientation = RT_BOT_UNORIENTED; bot_ip.bot_flags = 0; count = rt_bot_vertex_fuse(&bot_ip, &wdbp->wdb_tol); count = rt_bot_face_fuse(&bot_ip); if (count) bu_log("WARNING: %d duplicate faces eliminated from group %d component %d\n", count, group_id, comp_id); rt_mk_bot(wdbp, name, bot_mode, RT_BOT_UNORIENTED, 0, bot_ip.num_vertices, bot_ip.num_faces, bot_ip.vertices, bot_ip.faces, bot_ip.thickness, bot_ip.face_mode); if (mode == PLATE_MODE) { bu_free((char *)bot_ip.thickness, "BOT thickness"); bu_free((char *)bot_ip.face_mode, "BOT face_mode"); } bu_free((char *)bot_ip.vertices, "BOT vertices"); bu_free((char *)bot_ip.faces, "BOT faces"); }
int main(int argc, char **argv) { int faces[15]; fastf_t vertices[36]; fastf_t thickness[4]; struct rt_wdb *outfp = NULL; struct bu_bitv *face_mode = NULL; static const char *filename = "bot-test.g"; if (BU_STR_EQUAL(argv[1], "-h") || BU_STR_EQUAL(argv[1], "-?")) { printusage(); return 0; } if (argc == 1) { printusage(); fprintf(stderr," Program continues running (will create file bot-test.g because 'filename' was blank):\n"); } else if (argc > 1) filename = argv[1]; outfp = wdb_fopen(filename); mk_id(outfp, "BOT test"); VSET(vertices, 0.0, 0.0, 0.0); VSET(&vertices[3], 0.0, 100.0, 0.0); VSET(&vertices[6], 0.0, 100.0, 50.0); VSET(&vertices[9], 200.0, 0.0, 0.0); /* face #1 */ faces[0] = 0; faces[1] = 1; faces[2] = 2; /* face #2 */ faces[3] = 0; faces[4] = 2; faces[5] = 3; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_u_surf", RT_BOT_SURFACE, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); /* face #1 */ faces[0] = 0; faces[1] = 2; faces[2] = 1; /* face #2 */ faces[3] = 0; faces[4] = 3; faces[5] = 2; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_ccw_surf", RT_BOT_SURFACE, RT_BOT_CCW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); /* face #1 */ faces[0] = 1; faces[1] = 2; faces[2] = 0; /* face #2 */ faces[3] = 2; faces[4] = 3; faces[5] = 0; /* face #3 */ faces[6] = 3; faces[7] = 1; faces[8] = 0; /* face #4 */ faces[9] = 3; faces[10] = 2; faces[11] = 1; mk_bot(outfp, "bot_cw_surf", RT_BOT_SURFACE, RT_BOT_CW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); /* face #1 */ faces[0] = 0; faces[1] = 1; faces[2] = 2; /* face #2 */ faces[3] = 0; faces[4] = 2; faces[5] = 3; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_u_solid", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); /* face #1 */ faces[0] = 0; faces[1] = 2; faces[2] = 1; /* face #2 */ faces[3] = 0; faces[4] = 3; faces[5] = 2; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_ccw_solid", RT_BOT_SOLID, RT_BOT_CCW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); /* face #1 */ faces[0] = 1; faces[1] = 2; faces[2] = 0; /* face #2 */ faces[3] = 2; faces[4] = 3; faces[5] = 0; /* face #3 */ faces[6] = 3; faces[7] = 1; faces[8] = 0; /* face #4 */ faces[9] = 3; faces[10] = 2; faces[11] = 1; mk_bot(outfp, "bot_cw_solid", RT_BOT_SOLID, RT_BOT_CW, 0, 4, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); face_mode = bu_bitv_new(4); BU_BITSET(face_mode, 1); thickness[0] = 2.1; thickness[1] = 2.2; thickness[2] = 2.3; thickness[3] = 2.4; /* face #1 */ faces[0] = 0; faces[1] = 1; faces[2] = 2; /* face #2 */ faces[3] = 0; faces[4] = 2; faces[5] = 3; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_u_plate", RT_BOT_PLATE, RT_BOT_UNORIENTED, 0, 4, 4, vertices, faces, thickness, face_mode); /* face #1 */ faces[0] = 0; faces[1] = 2; faces[2] = 1; /* face #2 */ faces[3] = 0; faces[4] = 3; faces[5] = 2; /* face #3 */ faces[6] = 0; faces[7] = 1; faces[8] = 3; /* face #4 */ faces[9] = 1; faces[10] = 2; faces[11] = 3; mk_bot(outfp, "bot_ccw_plate", RT_BOT_PLATE, RT_BOT_CCW, 0, 4, 4, vertices, faces, thickness, face_mode); /* face #1 */ faces[0] = 1; faces[1] = 2; faces[2] = 0; /* face #2 */ faces[3] = 2; faces[4] = 3; faces[5] = 0; /* face #3 */ faces[6] = 3; faces[7] = 1; faces[8] = 0; /* face #4 */ faces[9] = 3; faces[10] = 2; faces[11] = 1; mk_bot(outfp, "bot_cw_plate", RT_BOT_PLATE, RT_BOT_CW, 0, 4, 4, vertices, faces, thickness, face_mode); /* Make a bot with duplicate vertices to test the "fuse" and "condense" code */ VSET(vertices, 0.0, 0.0, 0.0); VSET(&vertices[3], 0.0, 100.0, 0.0); VSET(&vertices[6], 0.0, 100.0, 50.0); VMOVE(&vertices[9], &vertices[0]); VMOVE(&vertices[12], &vertices[6]); VSET(&vertices[15], 200.0, 0.0, 0.0); VMOVE(&vertices[18], &vertices[0]); VMOVE(&vertices[21], &vertices[3]); VMOVE(&vertices[24], &vertices[15]); VMOVE(&vertices[27], &vertices[3]); VMOVE(&vertices[30], &vertices[6]); VMOVE(&vertices[33], &vertices[15]); /* face #1 */ faces[0] = 0; faces[1] = 1; faces[2] = 2; /* face #2 */ faces[3] = 3; faces[4] = 4; faces[5] = 5; /* face #3 */ faces[6] = 6; faces[7] = 7; faces[8] = 8; /* face #4 */ faces[9] = 9; faces[10] = 10; faces[11] = 11; mk_bot(outfp, "bot_solid_dup_vs", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 12, 4, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); faces[12] = 9; faces[13] = 10; faces[14] = 11; mk_bot(outfp, "bot_solid_dup_fs", RT_BOT_SOLID, RT_BOT_UNORIENTED, 0, 12, 5, vertices, faces, (fastf_t *)NULL, (struct bu_bitv *)NULL); bu_free((char *)face_mode, "bottest: face_mode"); wdb_close(outfp); return 0; }