int ged_bot_condense(struct ged *gedp, int argc, const char *argv[]) { struct directory *old_dp, *new_dp; struct rt_db_internal intern; struct rt_bot_internal *bot; int count2=0; static const char *usage = "new_bot old_bot"; GED_CHECK_DATABASE_OPEN(gedp, GED_ERROR); GED_CHECK_READ_ONLY(gedp, GED_ERROR); GED_CHECK_ARGC_GT_0(gedp, argc, GED_ERROR); /* initialize result */ bu_vls_trunc(gedp->ged_result_str, 0); /* must be wanting help */ if (argc == 1) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_HELP; } if (argc != 3) { bu_vls_printf(gedp->ged_result_str, "Usage: %s %s", argv[0], usage); return GED_ERROR; } GED_DB_LOOKUP(gedp, old_dp, argv[2], LOOKUP_NOISY, GED_ERROR & GED_QUIET); GED_DB_GET_INTERNAL(gedp, &intern, old_dp, bn_mat_identity, &rt_uniresource, GED_ERROR); if (intern.idb_major_type != DB5_MAJORTYPE_BRLCAD || intern.idb_minor_type != DB5_MINORTYPE_BRLCAD_BOT) { bu_vls_printf(gedp->ged_result_str, "%s: %s is not a BOT solid!\n", argv[0], argv[2]); return GED_ERROR; } bot = (struct rt_bot_internal *)intern.idb_ptr; RT_BOT_CK_MAGIC(bot); count2 = rt_bot_condense(bot); bu_vls_printf(gedp->ged_result_str, "%s: %d dead vertices eliminated\n", argv[0], count2); GED_DB_DIRADD(gedp, new_dp, argv[1], RT_DIR_PHONY_ADDR, 0, RT_DIR_SOLID, (void *)&intern.idb_type, GED_ERROR); GED_DB_PUT_INTERNAL(gedp, new_dp, &intern, &rt_uniresource, GED_ERROR); return GED_OK; }
void make_bot_object(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 element_id=bot; 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 ); bu_bitv_clear( bv ); 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 ); if ( count ) (void)rt_bot_condense( &bot_ip ); 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" ); }