def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] settings = TNA['settings'] options = ['obj', 'json', 'lines', 'mesh'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'obj': filepath = compas_rhino.select_file(folder=compas_tna.DATA, filter='OBJ files (*.obj)|*.obj||') if not filepath: return form = FormDiagram.from_obj(filepath) elif option == 'json': filepath = compas_rhino.select_file( folder=compas_tna.DATA, filter='JSON files (*.json)|*.json||') if not filepath: return form = FormDiagram.from_json(filepath) elif option == 'lines': guids = compas_rhino.select_lines() if not guids: return lines = compas_rhino.get_line_coordinates(guids) form = FormDiagram.from_lines(lines) elif option == 'mesh': guid = compas_rhino.select_mesh() if not guid: return form = FormDiagram.from_rhinomesh(guid) else: raise NotImplementedError del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = None compas_rhino.clear_layer(settings['layer.force']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings)
def horizontal_nodal_xfunc(formdata, forcedata, *args, **kwargs): from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
def force_update_from_form_xfunc(force, form, *args, **kwargs): from compas_ags.diagrams import FormDiagram from compas_ags.diagrams import ForceDiagram form = FormDiagram.from_data(form) force = ForceDiagram.from_data(force) force_update_from_form(force, form, *args, **kwargs) return force.to_data()
def from_vertices_and_faces(vs, fs): mesh = Mesh.from_vertices_and_faces(vs, fs) form = FormDiagram.from_mesh(mesh) corners = list(form.vertices_where({'vertex_degree': 2})) form.vertices_attribute('is_anchor', True, keys=corners) form.edges_attribute('q', 10.0, keys=form.edges_on_boundary()) relax_boundary_openings(form, corners) form.update_boundaries() force = ForceDiagram.from_formdiagram(form) horizontal_nodal(form, force, alpha=95) scale = vertical_from_zmax(form, 450.0) return form
def randomise_form(form): """ Randomises the FormDiagram by shuffling the edges. Parameters ---------- form : obj Original FormDiagram. Returns ------- obj Shuffled FormDiagram. """ # Edges edges = [form.edge_coordinates(u, v) for u, v in form.edges()] edges = [[sp[:2] + [0], ep[:2] + [0]] for sp, ep in edges] shuffle(edges) form_ = FormDiagram.from_lines(edges, delete_boundary_face=False) form_.update_default_edge_attributes({'is_symmetry': False}) sym = [ geometric_key(form.edge_midpoint(u, v)[:2] + [0]) for u, v in form.edges_where({'is_symmetry': True}) ] for u, v in form_.edges(): if geometric_key(form_.edge_midpoint(u, v)) in sym: form_.set_edge_attribute((u, v), 'is_symmetry', True) # Vertices gkey_key = form_.gkey_key() for key, vertex in form.vertex.items(): gkey = geometric_key(form.vertex_coordinates(key)[:2] + [0]) form_.vertex[gkey_key[gkey]] = vertex form_.attributes['indset'] = [] return form_
from __future__ import print_function import compas import compas_rhino import compas_tna from compas_tna.diagrams import FormDiagram from compas_tna.rhino import DiagramHelper # create a form diagram from a set of lines guids = compas_rhino.select_lines() lines = compas_rhino.get_line_coordinates(guids) form = FormDiagram.from_lines(lines) # identify the supports # as the vertices that lie on the support curves guids = compas_rhino.select_curves() keys = DiagramHelper.identify_vertices_on_curves(form, guids) form.set_vertices_attribute('is_anchor', True, keys) # update the boundaries to include the horizontal reaction forces form.update_boundaries() # serialise the result form.to_json('aag_00_formdiagram_from_lines.json')
from __future__ import print_function import compas import compas_rhino import compas_tna from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import DiagramHelper # create a form diagram from a serialised file form = FormDiagram.from_json('aag_02_formdiagram.json') # create a force diagram from the form diagram force = ForceDiagram.from_formdiagram(form) # visualise the result force.draw(layer='AAG::ForceDiagram') # move the force diagram to a different location DiagramHelper.move(force)
__copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' __all__ = [] f = XFunc('compas_ags.ags.graphstatics.identify_dof_xfunc') def identify_dof(form): return f(form.to_data()) form = FormDiagram.from_obj(compas.get('lines.obj')) form.set_vertices_attributes(('is_fixed', 'is_anchor'), (True, True), keys=form.vertices_on_boundary()) form.set_edges_attribute('is_edge', False, keys=form.edges_on_boundary()) k, m, ind = identify_dof(form) for u, v in ind: form.set_edge_attributes((u, v), ('is_ind', 'q'), (True, random.choice(range(1, 5)))) vertical_from_qind(form) artist = FormArtist(form, layer='FormDiagram')
import compas_rhino import compas_tna from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files form = FormDiagram.from_json('aag_04_horizontal_formdiagram.json') force = ForceDiagram.from_json('aag_04_horizontal_forcediagram.json') # compute the scale of the force diagram # such that the highest vertex of the form diagram is at a prescribed value zmax = 3 scale = vertical(form, zmax, kmax=100) force.attributes['scale'] = scale print(scale) # draw the result
from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical_from_zmax from compas_tna.equilibrium import vertical_from_formforce_rhino as vertical_from_formforce from compas_tna.rhino import FormArtist __author__ = ['Tom Van Mele', ] __copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' # make a form diagram from an obj file file = compas.get('faces.obj') form = FormDiagram.from_obj(file) # update the boundary conditions boundaries = form.vertices_on_boundaries() exterior = boundaries[0] interior = boundaries[1:] form.set_vertices_attribute('is_anchor', True, keys=exterior) form.update_exterior(exterior, feet=1) form.update_interior(interior) # create the force diagram
def relax_boundary_openings_proxy(formdata): from compas_tna.diagrams import FormDiagram form = FormDiagram.from_data(formdata) relax_boundary_openings(form) return form.to_data()
viewer = VtkViewer(datastructure=form) viewer.setup() viewer.start() # ============================================================================== # Main # ============================================================================== if __name__ == "__main__": # Load FormDiagram file = '/home/al/compas_loadpath/data/gridshell.json' form = FormDiagram.from_json(file) # Single run # form = randomise_form(form) # fopt, qopt = optimise_single(form, qmax=5, population=200, generations=200, printout=10, tol=0.01) # Multiple runs fopts, forms, best = optimise_multi(form, trials=50, save_figs='/home/al/temp/lp/', qmin=-5, qmax=5, population=200, generations=200,
def vertical_from_bbox_proxy(formdata, *args, **kwargs): from compas_tna.diagrams import FormDiagram form = FormDiagram.from_data(formdata) scale = vertical_from_bbox(form, *args, **kwargs) return form.to_data(), scale
def vertical_from_zmax_proxy(formdata, *args, **kwargs): form = FormDiagram.from_data(formdata) scale = vertical_from_zmax(form, *args, **kwargs) return form.to_data(), scale
def vertical_from_q_proxy(formdata, *args, **kwargs): form = FormDiagram.from_data(formdata) vertical_from_q(form, *args, **kwargs) return form.to_data()
from __future__ import print_function import compas import compas_rhino import compas_tna from compas.geometry import mesh_smooth_area from compas_tna.diagrams import FormDiagram # create a form diagram from a serialised file form = FormDiagram.from_json('aag_01_formdiagram_from_mesh.json') # smooth the diagram keeping some of the vertices fixed fixed = list(form.vertices_where({'is_anchor': True})) fixed += list(form.vertices_where({'is_fixed': True})) fixed += [ key for fkey in form.faces_where({'is_loaded': False}) for key in form.face_vertices(fkey) ] fixed[:] = list(set(fixed)) mesh_smooth_area(form, fixed=fixed, kmax=50) # serialise the result form.to_json('aag_02_formdiagram.json')
from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files <<<<<<< HEAD form = FormDiagram.from_json('aag_07_formdiagram_tweaked.json') force = ForceDiagram.from_json('aag_07_forcediagram_tweaked.json') ======= form = FormDiagram.from_json('aag_06_distribution_formdiagram.json') force = ForceDiagram.from_json('aag_06_distribution_forcediagram.json') >>>>>>> eedc4909fa94efc94d3da187e62f355a854c5508 # visualise the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') ## update the force bounds on the edges of the form diagram #
from compas.utilities import geometric_key import rhinoscriptsyntax as rs __author__ = ['Andrew Liew <*****@*****.**>'] __copyright__ = 'Copyright 2018, BLOCK Research Group - ETH Zurich' __license__ = 'MIT License' __email__ = '*****@*****.**' # Form guids = rs.ObjectsByLayer('Lines') + rs.ObjectsByLayer('Symmetry') lines = [[rs.CurveStartPoint(i), rs.CurveEndPoint(i)] for i in guids if rs.IsCurve(i)] form = FormDiagram.from_lines(lines, delete_boundary_face=False) form.update_default_vertex_attributes({'is_roller': False}) form.update_default_edge_attributes({'q': 1, 'is_symmetry': False}) form.attributes['loadpath'] = 0 form.attributes['indset'] = [] gkey_key = form.gkey_key() # Pins for i in rs.ObjectsByLayer('Pins'): gkey = geometric_key(rs.PointCoordinates(i)) form.set_vertex_attribute(gkey_key[gkey], 'is_fixed', True) # Loads
def __init__(self): FormDiagram.__init__(self) self.vec_GblArLd = [0, 0, 0]
import compas import compas_rhino import compas_tna compas_tna.TEMP = os.path.join(os.path.dirname(__file__), 'tmp') from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist # create diagrams from serialised files form = FormDiagram.from_json('aag_08_final_formdiagram.json') force = ForceDiagram.from_json('aag_08_final_forcediagram.json') # draw the result form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') artist = FormArtist(form, layer='AAG::FormDiagram') artist.clear_reactions() artist.draw_reactions(scale=0.25) artist.draw_forces(scale=0.01) artist.redraw()
from __future__ import print_function import compas import compas_rhino import compas_tna from compas_tna.diagrams import FormDiagram from compas_tna.rhino import DiagramHelper # create a form diagram from a set of lines guid = compas_rhino.select_mesh() form = FormDiagram.from_rhinomesh(guid) # identify the supports # as the vertices that lie on the support curves guids = compas_rhino.select_curves() keys = DiagramHelper.identify_vertices_on_curves(form, guids) form.set_vertices_attribute('is_anchor', True, keys) # update the boundaries to include the horizontal reaction forces form.update_boundaries() # serialise the result form.to_json('aag_01_formdiagram_from_mesh.json') # draw the result in the layer AAG > FormDiagram
The form diagram. zmax : float The maximum z-coordinate of all vertices of the equilibrium network. """ formdata, scale = tna.vertical_from_zmax_proxy(form.to_data(), zmax) form.data = formdata return scale # 1. make the form diagram from selected line elements guids = compas_rhino.select_lines() rs.HideObjects(guids) form = FormDiagram.from_rhinolines(guids) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 2. identify the supports keys = DiagramHelper.select_vertices(form) if keys: form.set_vertices_attributes(['is_anchor', 'is_fixed'], [True, True], keys=keys) form.draw(layer='TNA::FormDiagram', clear_layer=True) # 3. update the boundaries # Note: add only one foot per support to control the direction of the horizontal component # of the reaction force
import compas_tna from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.equilibrium import horizontal_nodal from compas_plotters import MeshPlotter FILE = compas_tna.get('tutorial/boundaryconditions.json') form = FormDiagram.from_json(FILE) force = ForceDiagram.from_formdiagram(form) horizontal_nodal(form, force, kmax=100) # ============================================================================== # Visualise # ============================================================================== plotter = MeshPlotter(force, figsize=(12, 8), tight=True) vertexcolor = { key: (1.0, 0.9, 0.9) for key in force.vertices() if not form.face_attribute(key, '_is_loaded') } radius = {key: 0.05 for key in force.vertices()} radius.update({ key: 0.1 for key in force.vertices() if not form.face_attribute(key, '_is_loaded') })
def RunCommand(is_interactive): if 'TNA' not in sc.sticky: raise Exception("Initialise the plugin first!") TNA = sc.sticky['TNA'] form = TNA['form'] force = TNA['force'] settings = TNA['settings'] options = ['save', 'save_as', 'open'] option = rs.GetString("Initialise FormDiagram from", options[0], options) if not option: return if option == 'save': # save the current file in the current directory # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return settings['file.dir'] = file_dir if not settings['file.name']: file_name = compas_rhino.select_file(folder=settings['file.dir']) if not file_name: print('The filename is invalid: {}'.format(file_name)) return settings['file.name'] = file_name file_name = settings['file.name'] if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) # compile the data dict data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() # write the data dict to the specified file with open(filepath, 'w') as f: json.dump(data, f) elif option == 'save_as': # save the current file using a different name and location # get the components of the current filepath if not settings['file.dir']: file_dir = compas_rhino.select_folder(default=HERE) else: file_dir = compas_rhino.select_folder(default=settings['file.dir']) settings['file.dir'] = file_dir if not os.path.isdir(file_dir): print('The selected directory is invalid: {}'.format(file_dir)) return file_name = rs.GetString('File name') if not file_name: print('The filename is invalid: {}'.format(file_name)) return if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return settings['file.dir'] = file_dir settings['file.name'] = file_name if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) data = {'settings': settings} if form: data['form'] = form.to_data() if force: data['force'] = force.to_data() with open(filepath, 'w') as f: json.dump(data, f) elif option == 'open': # open a specified file # and update the current file properties in the settings # get the dirname of the current filepath if not settings['file.dir']: filepath = compas_rhino.select_file( folder=HERE, filter='JSON files (*.json)|*.json||') else: filepath = compas_rhino.select_file( folder=settings['file.dir'], filter='JSON files (*.json)|*.json||') if not filepath: return file_dir = os.path.dirname(filepath) file_name = os.path.basename(filepath) settings['file.dir'] = file_dir settings['file.name'] = file_name if not file_name.endswith('.json'): print('The filename is invalid: {}'.format(file_name)) return # compile the filepath filepath = os.path.join(file_dir, file_name) compas_rhino.clear_layer(settings['layer.form']) compas_rhino.clear_layer(settings['layer.force']) with open(filepath, 'r') as f: data = json.load(f) settings.update(data['settings']) if 'form' in data and data['form']: form = FormDiagram.from_data(data['form']) form.draw(layer=settings['layer.form'], clear_layer=True, settings=settings) else: form = None if form and 'force' in data and data['force']: force = ForceDiagram.from_data(data['force']) force.draw(layer=settings['layer.force'], clear_layer=True) else: force = None del TNA['form'] del TNA['force'] TNA['form'] = form TNA['force'] = force TNA['settings'] = settings else: # any other options are invalid raise NotImplementedError
def horizontal_nodal_proxy(formdata, forcedata, *args, **kwargs): form = FormDiagram.from_data(formdata) force = ForceDiagram.from_data(forcedata) horizontal_nodal(form, force, *args, **kwargs) return form.to_data(), force.to_data()
"""""" from __future__ import absolute_import from __future__ import division from __future__ import print_function import os import compas_tna from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.equilibrium import horizontal from compas.plotters import MeshPlotter form = FormDiagram.from_json(compas_tna.get('form_boundaryconditions.json')) force = ForceDiagram.from_formdiagram(form) horizontal(form, force) # force.plot() plotter = MeshPlotter(force, figsize=(12, 8), tight=True) vertexcolor = {key: (1.0, 0.9, 0.9) for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')} radius = {key: 0.05 for key in force.vertices()} radius.update({key: 0.1 for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')}) plotter.draw_vertices( facecolor=vertexcolor, radius=radius
def vertical_from_q_xfunc(formdata, *args, **kwargs): from compas_tna.diagrams import FormDiagram form = FormDiagram.from_data(formdata) vertical_from_q(form, *args, **kwargs) return form.to_data()
from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas.plotters import MeshPlotter form = FormDiagram.from_json('data/boundaryconditions.json') force = ForceDiagram.from_formdiagram(form) # ============================================================================== # Visualise # ============================================================================== plotter = MeshPlotter(force, figsize=(12, 8), tight=True) vertexcolor = {key: (1.0, 0.9, 0.9) for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')} radius = {key: 0.05 for key in force.vertices()} radius.update({key: 0.1 for key in force.vertices() if not form.get_face_attribute(key, 'is_loaded')}) plotter.draw_vertices(facecolor=vertexcolor, radius=radius) color = {key: '#00ff00' for key in force.edges() if force.get_form_edge_attribute(form, key, 'is_external')} width = {key: 2.0 for key in force.edges() if force.get_form_edge_attribute(form, key, 'is_external')} plotter.draw_edges(color=color, width=width) plotter.show()
from compas.plotters import MeshPlotter from compas_tna.diagrams import FormDiagram from compas_tna.utilities import relax_boundary_openings form = FormDiagram.from_obj('data/rhinomesh.obj') corners = list(form.vertices_where({'vertex_degree': 2})) form.set_vertices_attributes(('is_anchor', 'is_fixed'), (True, True), keys=corners) form.set_edges_attribute('q', 10.0, keys=form.edges_on_boundary()) relax_boundary_openings(form) form.update_boundaries(feet=2) form.to_json('data/boundaryconditions.json') # ============================================================================== # Visualisation # ============================================================================== plotter = MeshPlotter(form, figsize=(12, 8), tight=True) vertexcolor = {} vertexcolor.update( {key: '#00ff00' for key in form.vertices_where({'is_fixed': True})}) vertexcolor.update( {key: '#0000ff'
compas_tna.TEMP = os.path.join(os.path.dirname(__file__), 'tmp') from compas.utilities import i_to_green from compas_tna.diagrams import FormDiagram from compas_tna.diagrams import ForceDiagram from compas_tna.rhino import FormArtist from compas_tna.rhino import DiagramHelper from compas_tna.equilibrium import horizontal_nodal_rhino as horizontal from compas_tna.equilibrium import vertical_from_zmax_rhino as vertical # create diagrams from serialised files form = FormDiagram.from_json('aag_06_distribution_formdiagram.json') force = ForceDiagram.from_json('aag_06_distribution_forcediagram.json') # visualise the diagrams form.draw(layer='AAG::FormDiagram') force.draw(layer='AAG::ForceDiagram') # update the force bounds on the edges of the form diagram while True: keys = DiagramHelper.select_continuous_edges(form) if not keys: break DiagramHelper.update_edge_attributes(form, keys)