def from_json(cls, filepath): """Construct an assembly from the data contained in a JSON file. Parameters ---------- filepath : str Path to the file containing the data. Returns ------- Assembly An assembly data structure. Examples -------- .. code-block:: python assembly = Assembly.from_json('assembly.json') """ from compas_assembly.datastructures import Block with open(filepath, 'r') as fo: data = json.load(fo) # vertex keys in an assembly can be of any hashable type # keys in the blocks dict should be treated the same way! assembly = cls.from_data(data['assembly']) assembly.blocks = { int(key): Block.from_data(data['blocks'][key]) for key in data['blocks'] } return assembly
def assembly_interfaces_xfunc(data, **kwargs): """Convenience wrapper for ``assembly_interfaces_numpy`` that can be used with ``XFunc`` or ``RPC``. Parameters ---------- data : dict The data dictionary representing an assembly data structure. The dict has the following items: * assembly: the assembly data * blocks: the data per block Returns ------- dict A data dict with the same structure as the input dict. Notes ----- For additional named parameters that can be passed to this function, see ``assembly_interfaces_numpy``. Examples -------- .. code-block:: python assembly_interfaces_xfunc = XFunc('compas_assembly.datastructures.assembly_interfaces_xfunc') data = {'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.vertices()}} result = assembly_interfaces_xfunc(data) assembly.data = result['assembly'] assembly.blocks = {int(key): Block.from_data(data) for key, data in result['blocks']} """ from compas_assembly.datastructures import Assembly from compas_assembly.datastructures import Block assembly = Assembly.from_data(data['assembly']) assembly.blocks = { int(key): Block.from_data(data['blocks'][key]) for key in data['blocks'] } assembly_interfaces_numpy(assembly, **kwargs) return { 'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.blocks} }
def compute_interface_forces_xfunc(data, backend='cvx', **kwargs): from compas_assembly.datastructures import Assembly from compas_assembly.datastructures import Block assembly = Assembly.from_data(data['assembly']) assembly.blocks = { int(key): Block.from_data(data['blocks'][key]) for key in data['blocks'] } if backend == 'cvx': compute_interface_forces_cvx(assembly, **kwargs) if backend == 'cvxopt': compute_interface_forces_cvxopt(assembly, **kwargs) return { 'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.blocks} }
def from_json(cls, filepath): """Construct an assembly from the data contained in a JSON file. Parameters ---------- filepath : str Path to the file containing the data. Returns ------- Assembly An assembly data structure. Examples -------- >>> """ from compas_assembly.datastructures import Block with open(filepath, 'r') as fo: data = json.load(fo) assembly = cls.from_data(data['assembly']) assembly.blocks = {int(key): Block.from_data(data['blocks'][key]) for key in data['blocks']} return assembly
assembly.node_attribute(0, 'is_support', True) # ============================================================================== # Identify the interfaces # ============================================================================== proxy.package = 'compas_assembly.datastructures' data = { 'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.blocks}} data = proxy.assembly_interfaces_xfunc(data, tmax=0.02) assembly.data = data['assembly'] assembly.blocks = {int(key): Block.from_data(data['blocks'][key]) for key in data['blocks']} # ============================================================================== # Compute interface forces # ============================================================================== proxy.package = 'compas_rbe.equilibrium' data = { 'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.blocks}} data = proxy.compute_interface_forces_xfunc(data, backend='CVX', solver='CPLEX') assembly.data = data['assembly'] assembly.blocks = {int(key): Block.from_data(data['blocks'][key]) for key in data['blocks']}
proxy.package = 'compas_rbe.equilibrium' data = { 'assembly': assembly.to_data(), 'blocks': {str(key): assembly.blocks[key].to_data() for key in assembly.blocks} } data = proxy.compute_interface_forces_xfunc(data, backend='CVX', solver='CPLEX') assembly.data = data['assembly'] assembly.blocks = { int(key): Block.from_data(data['blocks'][key]) for key in data['blocks'] } # ============================================================================== # Visualize # ============================================================================== artist = AssemblyArtist(assembly, layer="Arch") artist.clear_layer() artist.draw_blocks() # artist.draw_edges() artist.draw_nodes(color={ key: (255, 0, 0) for key in assembly.nodes_where({'is_support': True}) })