示例#1
0
 def get_geometry(self):
     """
     Get relevant geometry for vehicle
     """
     if self._vehicle_stl is None:
         all_geom = tba.get_all_geom_set()
         desired_parts = (all_geom - get_parts_excluded() -
                          tba.geom_sets["never_in_cabin"] - self.LITTERS
                          | self.DOORS)
         self._vehicle_stl = tba.load_geometry(desired_parts,
                                               single_file=False)
     return self._vehicle_stl
示例#2
0
 def get_geometry(self):
     """
     Get relevant geometry for vehicle
     """
     if self._vehicle_stl is None:
         all_geom = tba.get_all_geom_set()
         desired_parts = (all_geom - get_parts_excluded()
                          - tba.geom_sets["never_in_cabin"]
                          - self.LITTERS
                          | self.DOORS)
         self._vehicle_stl = tba.load_geometry(desired_parts,
                                               single_file=False)
     return self._vehicle_stl
示例#3
0
    def __init__(self, settings_f):
        """
        Setup field of fire metrics based on settings read in from file.
        """
        ##pass setting to the test bench api
        settings_dict = tba.load_settings(settings_f)

        ## Optional test bench settings
        self.show_3d = settings_dict.get("show_3d", False)
        horizontal_divs = settings_dict.get("horizontal_divs", 720)
        self.up_direction = settings_dict.get("up_direction",
                                              np.array([0, 1.0, 0]))
        self.ground = settings_dict.get("ground", np.array([0, 1.0, 0]))

        ## Set up some constant parameters
        self.hor_sweep = np.linspace(0, 2 * pi, horizontal_divs)

        ## How many rays are considered contiguous - 3degrees of arc
        self.contiguous = int(ceil(3 * horizontal_divs / 360.0))
        self.incr_elev = 2 * pi / 720.0

        ## Get the data for the weapon.
        fof_data = tba.get_data(parts_of_interest)["Weapon_Station_Remote"]

        ## Get a weapon object.  API will enforce there is only one.
        wep_name = fof_data.keys()[0]
        self.weapon = Weapon_Station(wep_name, fof_data)

        ## Specify the classes of objects we want geometry for and load them in.
        class_set = tba.get_all_geom_set(
        ) - tba.geom_sets["never_exterior_classes"]
        surface = tba.load_geometry(class_set, single_file=True)

        ## Make a binary space partition to speed up intersection calculations
        self.nodes = np.vstack((surface['x'], surface['y'], surface['z'])).T
        self.tris = surface['tris']
        self.b_tree = BSP_Tree(self.nodes, self.tris)
        self.b_tree.generate_tree()

        ## Set up result storage.
        self.traverse_results = []
示例#4
0
    def __init__(self, settings_f):
        """
        Setup field of fire metrics based on settings read in from file.
        """
        ##pass setting to the test bench api
        settings_dict = tba.load_settings(settings_f)

        ## Optional test bench settings
        self.show_3d = settings_dict.get("show_3d", False)
        horizontal_divs = settings_dict.get("horizontal_divs", 720)
        self.up_direction = settings_dict.get("up_direction", np.array([0, 1.0, 0]))
        self.ground = settings_dict.get("ground", np.array([0, 1.0, 0]))

        ## Set up some constant parameters
        self.hor_sweep = np.linspace(0, 2 * pi, horizontal_divs)

        ## How many rays are considered contiguous - 3degrees of arc
        self.contiguous = int(ceil(3 * horizontal_divs / 360.0))
        self.incr_elev = 2 * pi / 720.0

        ## Get the data for the weapon.
        fof_data = tba.get_data(parts_of_interest)["Weapon_Station_Remote"]

        ## Get a weapon object.  API will enforce there is only one.
        wep_name = fof_data.keys()[0]
        self.weapon = Weapon_Station(wep_name, fof_data)

        ## Specify the classes of objects we want geometry for and load them in.
        class_set = tba.get_all_geom_set() - tba.geom_sets["never_exterior_classes"]
        surface = tba.load_geometry(class_set, single_file=True)

        ## Make a binary space partition to speed up intersection calculations
        self.nodes = np.vstack((surface['x'], surface['y'], surface['z'])).T
        self.tris = surface['tris']
        self.b_tree = BSP_Tree(self.nodes, self.tris)
        self.b_tree.generate_tree()

        ## Set up result storage.
        self.traverse_results = []
示例#5
0
    def __init__(self, settings_f):
        """
        Setup vision metrics based on settings read in from file.
        """
        ##pass setting to the test bench api
        settings_dict = tba.load_settings(settings_f)

        ## Optional test bench settings
        self.show_3d = settings_dict.get("show_3d", False)
        horizontal_divs = settings_dict.get("horizontal_divs", 720)
        self.focal_length_multiplier = settings_dict.get(
            "focal_length_multiplier", 1.5)
        self.far_dist = settings_dict.get("far_dist", 20.0)
        self.up_direction = settings_dict.get("up_direction",
                                              np.array([0, 1.0, 0]))
        self.fore_direction = settings_dict.get("fore_direction",
                                                np.array([0, 0, -1.0]))
        self.ground = settings_dict.get("ground", np.array([0, 1.0, 0]))

        ## Set up some constant parameters
        self.hor_sweep = np.linspace(0, 2 * pi, horizontal_divs)
        self.target_points_horizon = np.zeros(horizontal_divs, np.uint32)

        ## Get a dictionary of parts and properties form the api (periscopes, manikins, screens)
        fov_data = tba.get_data(parts_of_interest)

        ## Get Periscope objects for any that are found
        self.periscopes = [
            Vision_Device(p, fov_data["Periscope"])
            for p in fov_data["Periscope"]
        ]

        ## Get Manikin objects for the vehicle occupants that have vision requirements
        m_data = fov_data["Manikin"]

        req_roles = ["driver", "vehicle_commander", "troop_commander"]

        vis_roles = lambda m: m_data[m]["properties"]["vehicle_role"
                                                      ] in req_roles
        self.manikins = [
            Manikin(m, fov_data["Manikin"]) for m in m_data if vis_roles(m)
        ]

        ## Need exactly one of each
        roles = [m.vehicle_role for m in self.manikins]
        if len(set(roles)) != len(req_roles):
            msg = "Didn't get 1 of each vehicle_role={} instead got={}".format(
                req_roles, roles)
            raise ValueError(msg)

        ## Specify the classes of objects we want geometry for.
        class_set = tba.get_all_geom_set(
        ) - tba.geom_sets["never_exterior_classes"]

        ## And load them all as an effective single file
        surface = tba.load_geometry(class_set, single_file=True)

        ## Make a binary space partition to speed up intersection calculations
        self.nodes = np.vstack((surface['x'], surface['y'], surface['z'])).T
        self.tris = surface['tris']
        self.b_tree = BSP_Tree(self.nodes, self.tris)
        self.b_tree.generate_tree()

        ## TODO this won't cope with unusual orientations
        ## determine orientation of the vehicle given the direction up and forward
        fore = np.dot(self.nodes, self.fore_direction).min()
        fore = np.min(surface["z"])
        self.side_direction = np.cross(self.up_direction, self.fore_direction)
        side_array = np.dot(self.nodes, self.side_direction)

        self.z_ground = np.dot(self.ground, self.up_direction)

        center = (side_array.min() + side_array.max()) / 2.0
        center = (np.min(surface["x"]) + np.max(surface["x"])) * 0.5
        ## Find the vehicle origin (point on ground at front on centerline)
        self.veh_origin = np.array([center, self.z_ground, fore])
        logging.info("Vehicle origin is at {}".format(self.veh_origin))
        self.tran_veh = translate(self.veh_origin)

        self.fore_aft = [None] * len(self.periscopes)
        self.uplook = np.array([-1000.0] * len(self.periscopes))

        self.hit = []

        self.hor_fans = []
示例#6
0
文件: fov.py 项目: hitej/meta-core
    def __init__(self, settings_f):
        """
        Setup vision metrics based on settings read in from file.
        """
        ##pass setting to the test bench api
        settings_dict = tba.load_settings(settings_f)

        ## Optional test bench settings
        self.show_3d = settings_dict.get("show_3d", False)
        horizontal_divs = settings_dict.get("horizontal_divs", 720)
        self.focal_length_multiplier = settings_dict.get("focal_length_multiplier", 1.5)
        self.far_dist = settings_dict.get("far_dist", 20.0)
        self.up_direction = settings_dict.get("up_direction", np.array([0, 1.0, 0]))
        self.fore_direction = settings_dict.get("fore_direction", np.array([0, 0, -1.0]))
        self.ground = settings_dict.get("ground", np.array([0, 1.0, 0]))

        ## Set up some constant parameters
        self.hor_sweep = np.linspace(0, 2 * pi, horizontal_divs)
        self.target_points_horizon = np.zeros(horizontal_divs, np.uint32)

        ## Get a dictionary of parts and properties form the api (periscopes, manikins, screens)
        fov_data = tba.get_data(parts_of_interest)

        ## Get Periscope objects for any that are found
        self.periscopes = [Vision_Device(p, fov_data["Periscope"]) for p in fov_data["Periscope"]]

        ## Get Manikin objects for the vehicle occupants that have vision requirements
        m_data = fov_data["Manikin"]

        req_roles = ["driver", "vehicle_commander", "troop_commander"]

        vis_roles = lambda m: m_data[m]["properties"]["vehicle_role"] in req_roles
        self.manikins = [Manikin(m, fov_data["Manikin"]) for m in m_data if vis_roles(m)]

        ## Need exactly one of each
        roles = [m.vehicle_role for m in self.manikins]
        if len(set(roles)) != len(req_roles):
            msg = "Didn't get 1 of each vehicle_role={} instead got={}".format(req_roles, roles)
            raise ValueError(msg)

        ## Specify the classes of objects we want geometry for.
        class_set = tba.get_all_geom_set() - tba.geom_sets["never_exterior_classes"]

        ## And load them all as an effective single file
        surface = tba.load_geometry(class_set, single_file=True)

        ## Make a binary space partition to speed up intersection calculations
        self.nodes = np.vstack((surface["x"], surface["y"], surface["z"])).T
        self.tris = surface["tris"]
        self.b_tree = BSP_Tree(self.nodes, self.tris)
        self.b_tree.generate_tree()

        ## TODO this won't cope with unusual orientations
        ## determine orientation of the vehicle given the direction up and forward
        fore = np.dot(self.nodes, self.fore_direction).min()
        fore = np.min(surface["z"])
        self.side_direction = np.cross(self.up_direction, self.fore_direction)
        side_array = np.dot(self.nodes, self.side_direction)

        self.z_ground = np.dot(self.ground, self.up_direction)

        center = (side_array.min() + side_array.max()) / 2.0
        center = (np.min(surface["x"]) + np.max(surface["x"])) * 0.5
        ## Find the vehicle origin (point on ground at front on centerline)
        self.veh_origin = np.array([center, self.z_ground, fore])
        logging.info("Vehicle origin is at {}".format(self.veh_origin))
        self.tran_veh = translate(self.veh_origin)

        self.fore_aft = [None] * len(self.periscopes)
        self.uplook = np.array([-1000.0] * len(self.periscopes))

        self.hit = []

        self.hor_fans = []
示例#7
0

if __name__ == "__main__":
    from rpl.tools.api import test_bench_api as tb_api
    SETTINGS = tb_api.load_settings("settings.js")

    DOORS = {'Hatch_Assembly_Rear_Ramp', 'Hatch_Assembly_Personnel_Door'}
    HATCHES = {'Hatch_Assembly_Driver_Commander', 'Hatch_Assembly_Cargo'}
    HULLS = {
        "Hull_Assembly_Parametric", 'Hull_Assembly_Example_With_Connector'
    }
    MANIKINS = {"Manikin"}
    # Special labels applied to specific types of voxels
    VOXEL_LABELS = {2: HULLS, 4: DOORS, 8: HATCHES, 16: MANIKINS}

    vehicle_surfs = tb_api.load_geometry(tb_api.get_all_geom_set() - MANIKINS,
                                         single_file=False)

    # Modify node coords so object aligns with cartesian axes of occ voxel grid, +z=up
    # Vector to rotate around is cross product of current z axis and sfc normal
    veh_up = np.array([0., 1., 0.])
    rot_around = np.cross(veh_up, np.array([0, 0, 1]))
    rot_ang = -np.arccos(veh_up[2])
    tr_mat = geom_utils.rotation_about_vector(rot_around, rot_ang)

    #    voxel_data = main(vehicle_surfs, tr_mat, VOXEL_LABELS, SETTINGS)
    vox_veh_folder = r"voxelated_models/vehicles/{}/{}".format(
        SETTINGS["run_id"], SETTINGS["voxel_size"])

    vox_veh_file = "voxels_{}_vox{}_hacked".format(SETTINGS["run_id"],
                                                   SETTINGS["voxel_size"])
    def __init__(self, settings):
        """
        Setup vehicle metrics based on settings read in from file.
        """
        ## Essential test bench settings
        self.output_json_file = settings["output_json_file"]

        ##testbench specific settings
        transport_dimensions = settings["transport_dimensions"]
        self.up_direction = settings.get("up_direction", np.array([0, 1.0, 0]))
        self.fore_direction = settings.get("fore_direction",
                                           np.array([0, 0, 1.0]))
        self.ground = settings.get("ground", np.array([0, 1.0, 0]))
        self.curb_mass = tba.get_veh_mass()
        self.cent_grav = tba.get_veh_cg()

        try:
            self.up_direction, self.ground_plane, _ = tba.get_up_vector()
        except:
            self.up_direction = settings.get("up_direction",
                                             np.array([0, 1.0, 0]))

        trans_data = tba.get_data(parts_of_interest)

        ## Define dictionaries for each lifting and tie down class
        self.eye_weld = {}
        self.eye_bolt = {}
        self.ring_hoist = {}
        self.d_ring = {}
        self.dbar_weld = {}
        self.dbar_bolt = {}
        self.dbar_eye = {}
        self.pintle = {}
        self.cleat = {}

        self.eye_weld = trans_data[
            "Eye_Welded"]  # TODO: does this crash on empty list?
        self.eye_bolt = trans_data["Eye_Bolted"]
        self.ring_hoist = trans_data["Ring_Hoist"]
        self.d_ring = trans_data["D_Ring_Lashing"]
        self.pintle = trans_data["Pintle_Tow"]
        self.cleat = trans_data["Cleat_Mooring"]
        self.dbar_weld = trans_data["Drawbar_Welded"]
        self.dbar_bolt = trans_data["Drawbar_Bolted"]
        self.dbar_eye = trans_data["Drawbar_Eyebolt"]

        ## Define set of classes to get geometry for
        all_class_set = tba.get_all_geom_set()
        ## Class sets and geometry for approach angles
        class_set = all_class_set - tba.geom_sets["never_exterior_classes"] - \
                    {"Roadwheel",
                     "Trailing_Arm_Hydropneumatic_Rh",
                     "Trailing_Arm_Hydropneumatic_Lh",
                     "Track",
                     "Sprocket_And_Carrier_Drive",
                     "Wheel_Idler"}
        surface = tba.load_geometry(class_set, single_file=True)

        self.surface_coords = np.vstack(
            [surface["x"], surface["y"], surface["z"]]).T

        wheel_set = {"Roadwheel", "Sprocket_And_Carrier_Drive", "Wheel_Idler"}
        wheels = tba.load_geometry(wheel_set, single_file=True)

        track_set = {"Track"}
        track = tba.load_geometry(track_set, single_file=True)

        ## Class set and geometry for container fitting
        trans_class_set = all_class_set
        trans_geom = tba.load_geometry(trans_class_set, single_file=True)

        ## Class sets and geometry for lift eyes and tie_downs
        lift_set = {"Eye_Welded"}
        tie_down_set = {"Ring_Hoist"}

        lift_geom = tba.load_geometry(lift_set, single_file=True)
        tie_down_geom = tba.load_geometry(tie_down_set, single_file=True)

        self.trans_dict = vehicle_fit(surface, self.up_direction,
                                      self.fore_direction,
                                      transport_dimensions)

        self.trans_dict["Lifting_Metrics"] = self.lifting_metrics()
        self.trans_dict["Tie_Down_Metrics"] = self.tie_down_metrics()

        self.trans_dict["Approach_Angles"] = approach_angles(
            surface, wheels, track)

        pintle_count = len(self.pintle)

        cleat_count = len(self.cleat)

        tow_count = len(self.eye_bolt) + len(self.eye_weld) + len(self.dbar_bolt) + \
                    len(self.dbar_eye) + len(self.dbar_weld) + len(self.pintle)
        lift_count = len(self.eye_bolt) + len(self.eye_weld)

        self.trans_dict["Count_for_components_in_towing_class"] = tow_count
        self.trans_dict["Count_for_components_in_lifting_class"] = lift_count
        self.trans_dict["Count_for_components_in_pintle_class"] = pintle_count
        self.trans_dict["Count_for_components_in_mooring_class"] = cleat_count

        plot_vehicle(trans_geom, transport_dimensions)

        plot_lift_tie_down(trans_geom, lift_geom, tie_down_geom)

        tba.write_results(self.trans_dict)
示例#9
0
    def __init__(self, settings):
        """
        Setup vehicle metrics based on settings read in from file.
        """
        ## Essential test bench settings
        self.output_json_file = settings["output_json_file"]

        ##testbench specific settings
        transport_dimensions = settings["transport_dimensions"]
        self.up_direction = settings.get("up_direction", np.array([0, 1.0, 0]))
        self.fore_direction = settings.get("fore_direction", np.array([0, 0, 1.0]))
        self.ground = settings.get("ground", np.array([0, 1.0, 0]))
        self.curb_mass = tba.get_veh_mass()
        self.cent_grav = tba.get_veh_cg()

        try:
            self.up_direction, self.ground_plane, _ = tba.get_up_vector()
        except:
            self.up_direction = settings.get("up_direction", np.array([0, 1.0, 0]))

        trans_data = tba.get_data(parts_of_interest)

        ## Define dictionaries for each lifting and tie down class
        self.eye_weld = {}
        self.eye_bolt = {}
        self.ring_hoist = {}
        self.d_ring = {}
        self.dbar_weld = {}
        self.dbar_bolt = {}
        self.dbar_eye = {}
        self.pintle = {}
        self.cleat = {}

        self.eye_weld = trans_data["Eye_Welded"]  # TODO: does this crash on empty list?
        self.eye_bolt = trans_data["Eye_Bolted"]
        self.ring_hoist = trans_data["Ring_Hoist"]
        self.d_ring = trans_data["D_Ring_Lashing"]
        self.pintle = trans_data["Pintle_Tow"]
        self.cleat = trans_data["Cleat_Mooring"]
        self.dbar_weld = trans_data["Drawbar_Welded"]
        self.dbar_bolt = trans_data["Drawbar_Bolted"]
        self.dbar_eye = trans_data["Drawbar_Eyebolt"]

        ## Define set of classes to get geometry for
        all_class_set = tba.get_all_geom_set()
        ## Class sets and geometry for approach angles
        class_set = all_class_set - tba.geom_sets["never_exterior_classes"] - \
                    {"Roadwheel",
                     "Trailing_Arm_Hydropneumatic_Rh",
                     "Trailing_Arm_Hydropneumatic_Lh",
                     "Track",
                     "Sprocket_And_Carrier_Drive",
                     "Wheel_Idler"}
        surface = tba.load_geometry(class_set, single_file=True)

        self.surface_coords = np.vstack([surface["x"], surface["y"], surface["z"]]).T

        wheel_set = {"Roadwheel", "Sprocket_And_Carrier_Drive", "Wheel_Idler"}
        wheels = tba.load_geometry(wheel_set, single_file=True)

        track_set = {"Track"}
        track = tba.load_geometry(track_set, single_file=True)

        ## Class set and geometry for container fitting
        trans_class_set = all_class_set
        trans_geom = tba.load_geometry(trans_class_set, single_file=True)

        ## Class sets and geometry for lift eyes and tie_downs
        lift_set = {"Eye_Welded"}
        tie_down_set = {"Ring_Hoist"}

        lift_geom = tba.load_geometry(lift_set, single_file=True)
        tie_down_geom = tba.load_geometry(tie_down_set, single_file=True)

        self.trans_dict = vehicle_fit(surface,
                                      self.up_direction,
                                      self.fore_direction,
                                      transport_dimensions)

        self.trans_dict["Lifting_Metrics"] = self.lifting_metrics()
        self.trans_dict["Tie_Down_Metrics"] = self.tie_down_metrics()

        self.trans_dict["Approach_Angles"] = approach_angles(surface, wheels, track)

        pintle_count = len(self.pintle)

        cleat_count = len(self.cleat)

        tow_count = len(self.eye_bolt) + len(self.eye_weld) + len(self.dbar_bolt) + \
                    len(self.dbar_eye) + len(self.dbar_weld) + len(self.pintle)
        lift_count = len(self.eye_bolt) + len(self.eye_weld)

        self.trans_dict["Count_for_components_in_towing_class"] = tow_count
        self.trans_dict["Count_for_components_in_lifting_class"] = lift_count
        self.trans_dict["Count_for_components_in_pintle_class"] = pintle_count
        self.trans_dict["Count_for_components_in_mooring_class"] = cleat_count

        plot_vehicle(trans_geom, transport_dimensions)

        plot_lift_tie_down(trans_geom, lift_geom, tie_down_geom)

        tba.write_results(self.trans_dict)