def align_bricks(bricks_): list_bricks = bricks_.get_bricks() list_positions = [] for brick_ in list_bricks: list_positions.append(brick_.get_position()) positions = np.array(list_positions) trans = np.array([ np.min(positions[:, 0]), np.min(positions[:, 1]), np.min(positions[:, 2]), ]) list_bricks_new = [] for brick_ in list_bricks: position_new = copy.deepcopy(brick_.get_position()) direction_new = copy.deepcopy(brick_.get_direction()) position_new -= trans brick_new = brick.Brick() brick_new.set_position(position_new) brick_new.set_direction(direction_new) list_bricks_new.append(brick_new) bricks_aligned = bricks.Bricks(bricks_.get_length()) bricks_aligned.bricks = list_bricks_new bricks_aligned.validate_all() return bricks_aligned
def assemble(list_conns): bricks_ = bricks.Bricks(10000, '0') z = 0 dir_cur = 0 brick_ = brick.Brick() brick_.set_position([0, 0, z]) brick_.set_direction(dir_cur) bricks_.add(brick_) for conn in list_conns: z += 1 print(list_rules[conn]) dir_cur = (dir_cur + list_rules[conn][1][0]) % 2 brick_ = brick.Brick() brick_.set_position(list_rules[conn][1][1] + [z]) brick_.set_direction(dir_cur) bricks_.add(brick_) return bricks_
def align_bricks_to_origin(bricks_): list_bricks = bricks_.get_bricks() list_positions = [] for brick_ in list_bricks: list_positions.append(brick_.get_position()) positions = np.array(list_positions) bottoms = np.where(positions[:, 2] == np.min(positions[:, 2]))[0] ind_origin = np.random.choice(bottoms, 1) ind_origin = ind_origin[0] brick_origin = copy.deepcopy(list_bricks[ind_origin]) list_bricks_new = [] for brick_ in list_bricks: position_new = copy.deepcopy(brick_.get_position()) direction_new = copy.deepcopy(brick_.get_direction()) position_new -= brick_origin.get_position() if brick_origin.get_direction() == 1: angle_rotated = np.pi * 1.0 / 2.0 position_new_ = copy.deepcopy(position_new) position_new_.astype(np.float) position_new.astype(np.float) position_new[0] = np.round(np.cos(angle_rotated) * position_new_[0]) - np.round(np.sin(angle_rotated) * position_new_[1]) position_new[1] = np.round(np.sin(angle_rotated) * position_new_[0]) + np.round(np.cos(angle_rotated) * position_new_[1]) position_new = np.round(position_new) direction_new = (direction_new + brick_origin.get_direction()) % 2 brick_new = brick.Brick() brick_new.set_position(position_new) brick_new.set_direction(direction_new) list_bricks_new.append(brick_new) bricks_aligned = bricks.Bricks(bricks_.get_length()) bricks_aligned.bricks = list_bricks_new bricks_aligned.validate_all() return bricks_aligned
import time import copy from geometric_primitives import brick from geometric_primitives import bricks from geometric_primitives import rules from geometric_primitives import utils_io from geometric_primitives import utils_meshes size_brick = [2, 4] brick_ = brick.Brick(size_upper=size_brick, size_lower=size_brick) brick_.set_position([0, 0, 0]) brick_.set_direction(0) bricks_ = bricks.Bricks(100, 'mixed') bricks_.add(brick_) list_bricks = bricks_.get_possible_contacts(str_type='2') for elem in list_bricks: bricks_copied = copy.deepcopy(bricks_) bricks_copied.add(elem) mesh_bricks, mesh_cubes = utils_meshes.get_mesh_bricks(bricks_copied) utils_io.visualize(mesh_bricks)
import time import copy from geometric_primitives import brick from geometric_primitives import bricks from geometric_primitives import rules from geometric_primitives import utils_io from geometric_primitives import utils_meshes brick_ = brick.Brick(size_upper=[2, 2], size_lower=[2, 2]) brick_.set_position([0, 0, 0]) brick_.set_direction(0) bricks_ = bricks.Bricks(100, '1') bricks_.add(brick_) for ind in range(0, 10): brick_ = bricks_.sample()[0] bricks_.add(brick_) print(brick_.get_position(), brick_.get_direction()) mesh_bricks, mesh_cubes = utils_meshes.get_mesh_bricks(bricks_) utils_io.visualize(mesh_bricks)
import time import copy from geometric_primitives import brick from geometric_primitives import bricks from geometric_primitives import rules from geometric_primitives import utils_io from geometric_primitives import utils_meshes brick_ = brick.Brick(size_upper=[1, 2], size_lower=[1, 2]) brick_.set_position([0, 0, 0]) brick_.set_direction(0) bricks_ = bricks.Bricks(100, '2') bricks_.add(brick_) for ind in range(0, 10): brick_ = bricks_.sample()[0] bricks_.add(brick_) print(brick_.get_position(), brick_.get_direction()) mesh_bricks, mesh_cubes = utils_meshes.get_mesh_bricks(bricks_) utils_io.visualize(mesh_bricks)