def main(manikin_name, vehicle_obj, settings):
    """
    Perform all tasks related to intersection check between the specified vehicle and manikin
    """
    for ang in settings["manikin_orientations"]:
        ang %= 360.
        manikin_folder = r"voxelated_models\manikins\{}\{}".format(
            manikin_name, settings["voxel_size"])
        manikin_filename = "voxels_{}_vox{}_ang{}".format(manikin_name, settings["voxel_size"],
                                                          ang)
        logging.debug("Processing intersection between {} and {}".format(settings["run_id"],
                                                                        manikin_name))

        mani_data = data_io.load_array(manikin_folder, manikin_filename, multi_array=True)
        manikin = Component(mani_data,
                            voxel_size=settings["voxel_size"])

        ################################################
        # Process manikin
        collisions = intersection_check(vehicle_obj, manikin, settings)

        basename = "{}_{}".format(settings["run_id"], manikin_name)

        result_folder = "results/{}/{}".format(basename, settings["voxel_size"])
        file_name = "{}_vox{}_ang{}".format(basename, settings["voxel_size"], ang)

        save_results(result_folder, file_name, collisions, save_plots=settings["show_2d"])
Exemple #2
0
def main(manikin_name, vehicle_obj, settings):
    """
    Perform all tasks related to intersection check between the specified vehicle and manikin
    """
    for ang in settings["manikin_orientations"]:
        ang %= 360.
        manikin_folder = r"voxelated_models\manikins\{}\{}".format(
            manikin_name, settings["voxel_size"])
        manikin_filename = "voxels_{}_vox{}_ang{}".format(
            manikin_name, settings["voxel_size"], ang)
        logging.debug("Processing intersection between {} and {}".format(
            settings["run_id"], manikin_name))

        mani_data = data_io.load_array(manikin_folder,
                                       manikin_filename,
                                       multi_array=True)
        manikin = Component(mani_data, voxel_size=settings["voxel_size"])

        ################################################
        # Process manikin
        collisions = intersection_check(vehicle_obj, manikin, settings)

        basename = "{}_{}".format(settings["run_id"], manikin_name)

        result_folder = "results/{}/{}".format(basename,
                                               settings["voxel_size"])
        file_name = "{}_vox{}_ang{}".format(basename, settings["voxel_size"],
                                            ang)

        save_results(result_folder,
                     file_name,
                     collisions,
                     save_plots=settings["show_2d"])
Exemple #3
0
def load_create_graph(settings):
    """
    Load previously calculated arrays of walkability scores and create graph structure based on
    node connectivity
    """
    result_folder = os.path.join("results", settings["run_id"], str(settings["voxel_size"]))
    file_name = "{}_vox{}_best_scores".format(settings["run_id"], settings["voxel_size"])
                                              
    overall_walkability_scores = data_io.load_array(result_folder, file_name)

    file_name = "{}_vox{}_best_scores_by_orientation".format(settings["run_id"],
                                                             settings["voxel_size"])
    scores_by_orie = data_io.load_array(result_folder,
                                        file_name,
                                        multi_array=True)

    logging.debug("# nodes in unfiltered list: {}".format(overall_walkability_scores.size))

    connected_points_graph = grid_to_graph_new(scores_by_orie, settings)

    return connected_points_graph, overall_walkability_scores
Exemple #4
0
def load_create_graph(settings):
    """
    Load previously calculated arrays of walkability scores and create graph structure based on
    node connectivity
    """
    result_folder = os.path.join("results", settings["run_id"],
                                 str(settings["voxel_size"]))
    file_name = "{}_vox{}_best_scores".format(settings["run_id"],
                                              settings["voxel_size"])

    overall_walkability_scores = data_io.load_array(result_folder, file_name)

    file_name = "{}_vox{}_best_scores_by_orientation".format(
        settings["run_id"], settings["voxel_size"])
    scores_by_orie = data_io.load_array(result_folder,
                                        file_name,
                                        multi_array=True)

    logging.debug("# nodes in unfiltered list: {}".format(
        overall_walkability_scores.size))

    connected_points_graph = grid_to_graph_new(scores_by_orie, settings)

    return connected_points_graph, overall_walkability_scores
def load_fit_of_pose_in_vehicle(basename, settings):
    """
    Load in intersection check results for a given pose in the vehicle
    :param basename: The manikin + vehicle name pair
    :param settings:
    :return: Dict of {angle: collision array} pairs for every orientation of mani in vehicle
    """
    result_folder = "results/{}/{}".format(basename, settings["voxel_size"])

    collision_arrays_dict = {}
    for ang in settings["manikin_orientations"]:
        data_file_name = "{}_vox{}_ang{}".format(basename, settings["voxel_size"], ang)
        collision_arrays_dict[ang] = data_io.load_array(result_folder, data_file_name)

    # Also combine results and store overall best fit (aka "does pose ever fit in this point?")
    collision_arrays_dict["overall"] = find_best_scored_pose(
        [collision_arrays_dict[k] for k in collision_arrays_dict])

    return collision_arrays_dict
                        filemode="w",
                        format="%(levelname)s %(asctime)s %(message)s",
                        level=logging.DEBUG)

    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    console.setFormatter(logging.Formatter("%(asctime)s %(message)s"))
    logging.getLogger("").addHandler(console)

    ##########
    # Load the pre-voxelated vehicle model for testing
    b_fldr = r"voxelated_models/vehicles"
    vox_size_str = str(SETTINGS["voxel_size"])
    vox_folder = os.path.join(b_fldr, SETTINGS["run_id"], vox_size_str)
    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"], vox_size_str)
    voxel_dat = data_io.load_array(vox_folder, vox_veh_file, True)
    vehicle = Vehicle(voxel_dat)

    ### Hardcoded dummy troop positions that may be meaningless. Uses 3D voxel indices. These
    # values are for testing only, based on the Ricardo master assembly 11/11/2013.
    crew_points = np.array([[40, 40, 25], [40, 80, 25], [20, 145, 40]])

    # Perform exit checks and return combined results
    can_exit, exit_grid, air_inside = main(vehicle, crew_points, debug=True)

    # Print exit status: do all points pass exit check?
    exit_ok = all(v.values() for v in can_exit.values())

    if SETTINGS["debug"]:
        ## Render a 3D image, for debugging purposes only
        from mayavi import mlab
Exemple #7
0
if __name__ == "__main__":
    # User specified settings from separate file
    from rpl.tools.api import test_bench_api as tba
    SETTINGS = tba.load_settings("settings.js")

    ## Set up logging
    logging.info("\n"+50*"_"+'\ntest bench started\n'+50*"_")

    # Value references numpy; can't be read from json
    SETTINGS["unwalkable_value"] = np.inf

    # Load in vehicle occupied voxels file in order to locate the door points
    vox_veh_folder = r"voxelated_models/vehicles/{}/{}".format(SETTINGS["run_id"],
                                                               SETTINGS["voxel_size"])
    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"], SETTINGS["voxel_size"])
    veh_vox = data_io.load_array(vox_veh_folder, vox_veh_file, multi_array=True)

    #### Standalone egress testing mode requires a few dummy points that will depend on the
    # assembly chosen. These apply to the Ricardo master assembly as of Nov 11, 2013.
    vox_veh_cabin = (29, 63, 20)  # Dummy position; must label floor regions to find door-adj

    ## Point chosen for the EFV tester model
    #vox_veh_cabin = (140,30,10)

    #### Some sample output.
    # Gridpoints for 5cm voxel spacings. One point from cabin (exit exists), and one point for
    # driver ( can not reach door)
    start_points = [(29, 63, 4), (46, 45, 4), (29, 30, 4), (46, 67, 4), (29, 74, 4), (46, 34, 4),
                    (29, 52, 4), (46, 78, 4), (46, 23, 4), (29, 96, 4), (29, 85, 4), (46, 56, 4),
                    (46, 12, 4), (29, 19, 4), (29, 41, 4), (46, 89, 4)]
Exemple #8
0
    #######
    #  Voxelize the vehicle and return all information
    # Save the voxelated model of the vehicle (sans door and other excluded parts)

    vox_veh_folder = r"voxelated_models/vehicles/{}/{}".format(
        SETTINGS["run_id"], SETTINGS["voxel_size"])

    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"],
                                            SETTINGS["voxel_size"])

    if SETTINGS["debug"] and os.path.exists(
            os.path.join(vox_veh_folder, vox_veh_file + '.npz')):
        # Load from pre-existing file if possible (if debugging option is on)
        assembly.voxel_data = data_io.load_array(vox_veh_folder,
                                                 vox_veh_file,
                                                 multi_array=True)
        logging.info(
            "Vehicle voxel data loaded from preexisting file {}".format(
                vox_veh_file))

        valid_litter_found = "litter" in assembly.voxel_data  # Does cached geom incl litter?
    else:
        logging.info('Commencing voxelization of vehicle model')
        assembly.voxelate_geometry()

        # Voxelate Litter_Open model on a grid of same size
        x_pts, y_pts, z_pts = [
            assembly.voxel_data[k] for k in ("x_grid", "y_grid", "z_grid")
        ]
        valid_litter_found = assembly.voxelate_litter(x_pts, y_pts, z_pts)
Exemple #9
0
    #######
    #  Call test bench api to obtain desired information
    assembly = Assembly_Info(SETTINGS)

    #######
    #  Voxelize the vehicle and return all information
    # Save the voxelated model of the vehicle (sans door and other excluded parts)

    vox_veh_folder = r"voxelated_models/vehicles/{}/{}".format(SETTINGS["run_id"],
                                                               SETTINGS["voxel_size"])

    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"], SETTINGS["voxel_size"])

    if SETTINGS["debug"] and os.path.exists(os.path.join(vox_veh_folder, vox_veh_file + '.npz')):
        # Load from pre-existing file if possible (if debugging option is on)
        assembly.voxel_data = data_io.load_array(vox_veh_folder, vox_veh_file, multi_array=True)
        logging.info("Vehicle voxel data loaded from preexisting file {}".format(vox_veh_file))

        valid_litter_found = "litter" in assembly.voxel_data  # Does cached geom incl litter?
    else:
        logging.info('Commencing voxelization of vehicle model')
        assembly.voxelate_geometry()

        # Voxelate Litter_Open model on a grid of same size
        x_pts, y_pts, z_pts = [assembly.voxel_data[k] for k in ("x_grid", "y_grid", "z_grid")]
        valid_litter_found = assembly.voxelate_litter(x_pts, y_pts, z_pts)

        data_io.save_multi_array(vox_veh_folder, vox_veh_file, assembly.voxel_data)
        logging.info("Vehicle successfully voxelated.")

    # All later operations act on pre-voxelated models. Create voxel objects with redundant info.
                        filemode="w",
                        format="%(levelname)s %(asctime)s %(message)s",
                        level=logging.DEBUG)

    console = logging.StreamHandler()
    console.setLevel(logging.INFO)
    console.setFormatter(logging.Formatter("%(asctime)s %(message)s"))
    logging.getLogger("").addHandler(console)

    ##########
    # Load the pre-voxelated vehicle model for testing
    b_fldr = r"voxelated_models/vehicles"
    vox_size_str = str(SETTINGS["voxel_size"])
    vox_folder = os.path.join(b_fldr, SETTINGS["run_id"], vox_size_str)
    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"], vox_size_str)
    voxel_dat = data_io.load_array(vox_folder, vox_veh_file, True)
    vehicle = Vehicle(voxel_dat)

    ### Hardcoded dummy troop positions that may be meaningless. Uses 3D voxel indices. These
    # values are for testing only, based on the Ricardo master assembly 11/11/2013.
    crew_points = np.array([[40, 40, 25], [40, 80, 25], [20, 145, 40]])

    # Perform exit checks and return combined results
    can_exit, exit_grid, air_inside = main(vehicle, crew_points, debug=True)

    # Print exit status: do all points pass exit check?
    exit_ok = all(v.values() for v in can_exit.values())

    if SETTINGS["debug"]:
        ## Render a 3D image, for debugging purposes only
        from mayavi import mlab
Exemple #11
0
    from rpl.tools.api import test_bench_api as tba
    SETTINGS = tba.load_settings("settings.js")

    ## Set up logging
    logging.info("\n" + 50 * "_" + '\ntest bench started\n' + 50 * "_")

    # Value references numpy; can't be read from json
    SETTINGS["unwalkable_value"] = np.inf

    # Load in vehicle occupied voxels file in order to locate the door points
    vox_veh_folder = r"voxelated_models/vehicles/{}/{}".format(
        SETTINGS["run_id"], SETTINGS["voxel_size"])
    vox_veh_file = "voxels_{}_vox{}".format(SETTINGS["run_id"],
                                            SETTINGS["voxel_size"])
    veh_vox = data_io.load_array(vox_veh_folder,
                                 vox_veh_file,
                                 multi_array=True)

    #### Standalone egress testing mode requires a few dummy points that will depend on the
    # assembly chosen. These apply to the Ricardo master assembly as of Nov 11, 2013.
    vox_veh_cabin = (
        29, 63, 20
    )  # Dummy position; must label floor regions to find door-adj

    ## Point chosen for the EFV tester model
    #vox_veh_cabin = (140,30,10)

    #### Some sample output.
    # Gridpoints for 5cm voxel spacings. One point from cabin (exit exists), and one point for
    # driver ( can not reach door)
    start_points = [(29, 63, 4), (46, 45, 4), (29, 30, 4), (46, 67, 4),