def calculate(FILE_IN, plot_flag): for file in FILE_IN: #print("Calculating",file) assembly = Assembly.from_json(file) # ============================================================================== # Identify interfaces # ============================================================================== assembly_interfaces_numpy(assembly, tmax=0.02) # ============================================================================== # Equilibrium # ============================================================================== compute_interface_forces_cvx(assembly, solver='CPLEX', verbose=False) #compute_interface_forces_cvx(assembly, solver='ECOS', verbose=True) # ============================================================================== # Export # ============================================================================== assembly.to_json(output_path(file)) if plot_flag: R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2) assembly.transform(R) plotter = AssemblyPlotter(assembly, figsize=(16, 10), tight=True) plotter.draw_nodes(radius=0.05) plotter.draw_edges() plotter.draw_blocks( facecolor={ key: '#ff0000' for key in assembly.nodes_where({'is_support': True}) }) plotter.show()
# ============================================================================== # Load assembly from file # ============================================================================== assembly = Assembly.from_json(FILE_I) # ============================================================================== # Identify interfaces # ============================================================================== assembly_interfaces_numpy(assembly, tmax=0.05) # ============================================================================== # Export # ============================================================================== assembly.to_json(FILE_O) # ============================================================================== # Visualize # ============================================================================== R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2, [0, 0, 0]) assembly.transform(R) plotter = AssemblyPlotter(assembly, figsize=(16, 10), tight=True) plotter.draw_nodes(radius=0.05) plotter.draw_edges() plotter.draw_blocks(facecolor={key: '#ff0000' for key in assembly.nodes_where({'is_support': True})}) plotter.show()
PATH = os.path.join(DATA, 'stack.json') # load assembly assembly = Assembly.from_json(PATH) # compute interface forces compute_interface_forces_cvx(assembly, solver='CPLEX', verbose=True) # serialise assembly.to_json(PATH) # visualise R = Rotation.from_axis_and_angle([1.0, 0.0, 0.0], -pi / 2) assembly_transform(assembly, R) plotter = AssemblyPlotter(assembly, figsize=(10, 7)) plotter.draw_vertices(text={key: str(key) for key in assembly.vertices()}) plotter.draw_edges() plotter.draw_blocks(facecolor={ key: (255, 0, 0) for key in assembly.vertices_where({'is_support': True}) }) plotter.show()
assembly = Assembly.from_json(PATH) # visualise R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2) assembly_transform(assembly, R) plotter = AssemblyPlotter(assembly, figsize=(16, 6)) courses = assembly.get_vertices_attribute('course') c_min = min(courses) c_max = max(courses) c_spn = c_max - c_min facecolor = { key: i_to_black((attr['course'] - c_min) / c_spn) for key, attr in assembly.vertices(True) } edgecolor = { key: '#000000' for key in assembly.vertices_where({'is_support': True}) } edgewidth = {key: 3 for key in assembly.vertices_where({'is_support': True})} plotter.draw_blocks(facecolor=facecolor, edgecolor=edgecolor, edgewidth=edgewidth) plotter.show()
from math import pi import compas_assembly from compas.geometry import Rotation from compas_assembly.datastructures import Assembly from compas_assembly.datastructures import assembly_transform from compas_assembly.datastructures import assembly_construct_wall from compas_assembly.plotter import AssemblyPlotter assembly = Assembly.from_json(compas_assembly.get('wall.json')) R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2) assembly_transform(assembly, R) plotter = AssemblyPlotter(assembly, figsize=(16, 6), tight=True) plotter.assembly_plotter.defaults['vertex.fontsize'] = 10 plotter.draw_blocks( edgecolor='#444444', edgewidth=0.5 ) plotter.show()
facecolor.update({ key: i_to_red((index - i_min) / i_spn) for index, key in enumerate(sequence) }) facecolor[key] = '#ff0000' plotter.clear_blocks() plotter.draw_blocks(facecolor=facecolor) def on_pick(e): index = e.ind[0] key = index_key[index] if key in top: compute_sequence(key) plotter.update() # interactive visualisation R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2) assembly_transform(assembly, R) plotter = AssemblyPlotter(assembly, figsize=(16, 6), tight=True) plotter.draw_blocks(facecolor={k: '#eeeeee' for k in assembly.vertices()}) plotter.draw_vertices(keys=top, radius=0.01, picker=10) plotter.register_listener(on_pick) plotter.show()
print(sequence) # rotate the assembly for visualisation R = Rotation.from_axis_and_angle([1.0, 0, 0], -pi / 2) assembly_transform(assembly, R) # make a plotter plotter = AssemblyPlotter(assembly, figsize=(16, 6), tight=True) plotter.assembly_plotter.defaults['vertex.fontsize'] = 10 # color vertices according to their building order i_min = 0 i_max = len(sequence) i_spn = i_max - i_min facecolor = {k: '#cccccc' for k in assembly.vertices()} facecolor.update( {k: i_to_red((index - i_min) / i_spn) for index, k in enumerate(sequence)}) facecolor[key] = '#ff0000' # plot the assembly vertices # plot the block bounding boxes plotter.draw_blocks(facecolor=facecolor) plotter.show()