def load_geometry(class_set, single_file=False): """ Given a set of classes return a dictionary with instance_id keys each containing a surface dictionary with "x", "y", "z", and "tris" keys. If ``single_file == True`` all the surfaces are merged together and a dictionary containing the "x", "y", "z", and "tris" keys is returned (i.e. no instance_id keys used). The returned surface(s) are **always** transformed to be in their correct vehicle position. """ surf = {} if not single_file else { "x": np.empty((0, ), dtype=np.float32), "y": np.empty((0, ), dtype=np.float32), "z": np.empty((0, ), dtype=np.float32), "tris": np.empty((0, 3), dtype=np.int32) } ## Loop through each class of component asked for for part_class in class_set: if part_class not in instances_by_class: logging.warn( "No parts of class '{}' to load in.".format(part_class)) continue ## Loop over each component instance of the class for inst_id, model_path in instances_by_class[part_class].items(): try: instance_data = _get_part(inst_id, model_path) except ValueError: ## For now we will carry on. ACM file is unloadable (probably not present) ## Already logged error in _get_part() continue try: g_path = join(stl_loc, instance_data["stl_name"]) geom = open_geom(g_path) transform_geometry(geom, instance_data["trans"], 0.001) logging.debug("Loaded instance {} stl_file {}".format( inst_id, g_path)) except (KeyError, IOError) as e: ## For now we will log and carry on but this may mean results are wrong. msg = "Cannot load instance '{}' stl_file '{}'. Got: {}".format( inst_id, g_path, e) logging.error(msg) continue if single_file: ## Increment the node refs in the new tris to point to appended position geom["tris"] += len(surf["x"]) surf = { k: np.concatenate((surf[k], geom[k])) for k in ["x", "y", "z", "tris"] } else: ## Store the new surface under the instance_id key surf[inst_id] = geom # Add in the part class explicitly; don't make TBs guess based on instance name. surf[inst_id]['part_class'] = part_class return surf
def load_geometry(class_set, single_file=False): """ Given a set of classes return a dictionary with instance_id keys each containing a surface dictionary with "x", "y", "z", and "tris" keys. If ``single_file == True`` all the surfaces are merged together and a dictionary containing the "x", "y", "z", and "tris" keys is returned (i.e. no instance_id keys used). The returned surface(s) are **always** transformed to be in their correct vehicle position. """ surf = {} if not single_file else {"x": np.empty((0,), dtype=np.float32), "y": np.empty((0,), dtype=np.float32), "z": np.empty((0,), dtype=np.float32), "tris": np.empty((0, 3), dtype=np.int32)} ## Loop through each class of component asked for for part_class in class_set: if part_class not in instances_by_class: logging.warn("No parts of class '{}' to load in.".format(part_class)) continue ## Loop over each component instance of the class for inst_id, model_path in instances_by_class[part_class].items(): try: instance_data = _get_part(inst_id, model_path) except ValueError: ## For now we will carry on. ACM file is unloadable (probably not present) ## Already logged error in _get_part() continue try: g_path = join(stl_loc, instance_data["stl_name"]) geom = open_geom(g_path) transform_geometry(geom, instance_data["trans"], 0.001) logging.debug("Loaded instance {} stl_file {}".format(inst_id, g_path)) except (KeyError, IOError) as e: ## For now we will log and carry on but this may mean results are wrong. msg = "Cannot load instance '{}' stl_file '{}'. Got: {}".format(inst_id, g_path, e) logging.error(msg) continue if single_file: ## Increment the node refs in the new tris to point to appended position geom["tris"] += len(surf["x"]) surf = {k: np.concatenate((surf[k], geom[k])) for k in ["x", "y", "z", "tris"]} else: ## Store the new surface under the instance_id key surf[inst_id] = geom # Add in the part class explicitly; don't make TBs guess based on instance name. surf[inst_id]['part_class'] = part_class return surf
logging.getLogger().handlers = [] ## Main logging goes to a file logging.basicConfig(filename="test_bench.log", filemode="w", format="%(levelname)s %(asctime)s %(message)s", level=logging.DEBUG) ## Also log INFO and above to the console console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logging.Formatter("%(asctime)s %(message)s")) logging.getLogger("").addHandler(console) start_load = time.time() surf = open_geom("h170_engine_comp_ign_diesel_prt.stl") x = surf["x"] / 1000.0 y = surf["y"] / 1000.0 z = surf["z"] / 1000.0 print "X", np.min(x), np.max(x) print "Y", np.min(y), np.max(y) print "Z", np.min(z), np.max(z) nodes = np.vstack((x, y, z)).T b_tree = BSP_Tree(nodes, surf["tris"], min_tris=200, min_dim=0.5) b_tree.generate_tree() start_pt = np.array([-0.25, 0.5, -1.5])
logging.getLogger().handlers = [] ## Main logging goes to a file logging.basicConfig(filename="test_bench.log", filemode="w", format="%(levelname)s %(asctime)s %(message)s", level=logging.DEBUG) ## Also log INFO and above to the console console = logging.StreamHandler() console.setLevel(logging.INFO) console.setFormatter(logging.Formatter("%(asctime)s %(message)s")) logging.getLogger("").addHandler(console) start_load = time.time() surf = open_geom("h170_engine_comp_ign_diesel_prt.stl") x = surf["x"] / 1000.0 y = surf["y"] / 1000.0 z = surf["z"] / 1000.0 print "X", np.min(x), np.max(x) print "Y", np.min(y), np.max(y) print "Z", np.min(z), np.max(z) nodes = np.vstack((x, y, z)).T b_tree = BSP_Tree(nodes, surf["tris"], min_tris=200, min_dim=0.5) b_tree.generate_tree() start_pt = np.array([-0.25, 0.5, -1.5]) end_pt = np.array([-0.05, 0.5, 0.5]) vector = (end_pt - start_pt)