def from_lines(cls, lines, delete_boundary_face=False, precision=None): """Construct a mesh object from a list of lines described by start and end point coordinates. Parameters ---------- lines : list A list of pairs of point coordinates. delete_boundary_face : bool, optional The algorithm that finds the faces formed by the connected lines first finds the face *on the outside*. In most cases this face is not expected to be there. Therefore, there is the option to have it automatically deleted. precision: str, optional The precision of the geometric map that is used to connect the lines. Returns ------- Mesh A mesh object. Examples -------- >>> """ from compas.datastructures import Network from compas.datastructures import network_find_cycles network = Network.from_lines(lines, precision=precision) vertices = network.to_points() faces = network_find_cycles(network) mesh = cls.from_vertices_and_faces(vertices, faces) if delete_boundary_face: mesh.delete_face(0) mesh.cull_vertices() return mesh
def from_graph(cls, graph): """Construct a form diagram from a form graph. This constructor converts the form graph into a mesh by finding the cycles of its planar embedding. Note that tt doesn't check if the graph actually is a planar embedding. The outside face of the mesh is automatically split into smaller faces at the leaves. Parameters ---------- graph : :class:`compas_ags.diagrams.FormGraph` Returns ------- :class:`compas_ags.diagrams.FormDiagram` """ for node in list(graph.nodes()): if graph.degree(node) == 2: graph.delete_node(node) node_index = graph.node_index() cycles = network_find_cycles(graph, breakpoints=graph.leaves()) points = graph.nodes_attributes('xyz') cycles[:] = [[node_index[node] for node in cycle] for cycle in cycles] form = cls.from_vertices_and_faces(points, cycles) form.edges_attribute('_is_edge', False, keys=list(form.edges_on_boundary())) form.edges_attribute('is_external', True, keys=form.leaf_edges()) form.graph = graph return form
def from_graph(cls, graph): points = graph.to_points() cycles = network_find_cycles(graph, breakpoints=graph.leaves()) print(cycles) form = cls.from_vertices_and_faces(points, cycles) form.edges_attribute('is_edge', False, keys=list(form.edges_on_boundary())) return form
def add_vertex_edge_for_load_support(network, sup_dic, load_dic, bars_len, key_removed_dic): """ Post-Processing Function: Adds vertices and edges in accordance with supports and loads returns the cured network """ if not key_removed_dic: load_sup_dic=merge_two_dicts(sup_dic, load_dic) else: load_dic_2=load_dic.copy() for key in key_removed_dic: load_dic_2.pop(key) load_dic_2=merge_two_dicts(load_dic_2, key_removed_dic[key]) load_sup_dic=merge_two_dicts(sup_dic, load_dic_2) # define arbitrary r to be added to get leaf vertex coordinates max_len=max(bars_len) r=max_len/3.0 # make a polygon and polyline from outer vertices of network points = network.to_points() cycles = network_find_cycles(network) mesh = Mesh.from_vertices_and_faces(points, cycles) if 0 in mesh.face and len(mesh.face)>1: mesh.delete_face(0) if len(mesh.face)==1: ver_lis=[key for key in mesh.vertices()] else: ver_lis=mesh.vertices_on_boundary(ordered=True) ver_lis_plyln=ver_lis[:] ver_lis_plyln.append(ver_lis[0]) pt_lis_plygn=[mesh.vertex_coordinates(key) for key in ver_lis] pt_lis_plyln=[mesh.vertex_coordinates(key) for key in ver_lis_plyln] plygn=Polygon(pt_lis_plygn) plyln=Polyline(pt_lis_plyln) # add leaf vertices for key in load_sup_dic: if load_sup_dic[key][0]!=0.0: pt_1=add_vectors(network.node_coordinates(key), (+r, 0.0, 0.0)) plyln_bln=is_point_on_polyline(pt_1, plyln.points, tol=0.001) plygn_bln=is_point_in_polygon_xy(pt_1, plygn.points) if plyln_bln or plygn_bln: pt_1=add_vectors(network.node_coordinates(key), (-r, 0.0, 0.0)) key_2=network.add_node(x=np.asscalar(pt_1[0]), y=pt_1[1], z=0.0) network.add_edge(key, key_2) if load_sup_dic[key][1]!=0.0: pt_2=add_vectors(network.node_coordinates(key), (0.0,+r, 0.0)) plyln_bln=is_point_on_polyline(pt_2, plyln.points, tol=0.001) plygn_bln=is_point_in_polygon_xy(pt_2, plygn.points) if plyln_bln or plygn_bln: pt_2=add_vectors(network.node_coordinates(key), (0.0,-r, 0.0)) key_2=network.add_node(x=pt_2[0], y=np.asscalar(pt_2[1]), z=0.0) network.add_edge(key, key_2) return network, plygn, plyln
def gh_from_rhino_lines(mesh, max): from compas.datastructures import Network from compas.datastructures import network_find_cycles network = Network.from_lines(lines, precision=precision) vertices = network.to_points() faces = [face_vertices for face_vertices in network_find_cycles(network) if len(face_vertices) <=4] mesh = CoarsePseudoQuadMesh.from_vertices_and_faces(vertices, faces) if delete_boundary_face: mesh.delete_face(0) mesh.cull_vertices() return mesh
def get_halfedge_face(network): """ returns halfedge and face dictionary of the network """ points={key: network.node_coordinates(key) for key in network.nodes()} cycles=network_find_cycles(network, network.leaves()) mesh=Mesh.from_vertices_and_faces(points, cycles) dic_he=mesh.halfedge dic_fc=mesh.face return dic_he, dic_fc
def from_lines(cls, lines, delete_boundary_face=True, precision=None, **kwargs): """Construct a FormDiagram from a list of lines described by start and end point coordinates. Parameters ---------- lines : list A list of pairs of point coordinates. delete_boundary_face : bool, optional Set ``True`` to delete the face on the outside of the boundary, ``False`` to keep it. Default is ``True``. precision: str, optional The precision of the geometric map that is used to connect the lines. If not specified, the global precision stored in ``compas.PRECISION`` will be used. Returns ------- FormDiagram A FormDiagram object. Examples -------- >>> import compas >>> from compas.files import OBJ >>> from compas_tna.diagrams import FormDiagram >>> obj = OBJ(compas.get('lines.obj')) >>> vertices = obj.parser.vertices >>> edges = obj.parser.lines >>> lines = [(vertices[u], vertices[v]) for u, v in edges] >>> form = FormDiagram.from_lines(lines) """ network = Network.from_lines(lines, precision=precision) points = network.to_points() cycles = network_find_cycles(network, breakpoints=network.leaves()) form = cls.from_vertices_and_faces(points, cycles) if delete_boundary_face: form.delete_face(0) if 'name' in kwargs: form.name = kwargs['name'] return form
edges = [(0, 8), (0, 1), (1, 2), (10, 2), (0, 6), (6, 4), (4, 11), (4, 7), (7, 2)] # edges = [(key_index[u], key_index[v]) for u, v in edges] # net = Network.from_nodes_and_edges(nodes, edges) # network = net.copy() network = Network() for key, xyz in data.items(): network.add_node(key, x=xyz[0], y=xyz[1], z=xyz[2]) for u, v in edges: network.add_edge(u, v) points = {key: network.node_coordinates(key) for key in network.nodes()} cycles = network_find_cycles(network, breakpoints=network.leaves()) mesh = Mesh.from_vertices_and_faces(points, cycles) # e1 = network.edge_coordinates(0, 4) # e2 = network.edge_coordinates(1, 3) # xyz = intersection_line_line_xy(e1, e2) # network.delete_edge(0, 4) # network.delete_edge(1, 3) # x = network.add_node(x=xyz[0], y=xyz[1], z=xyz[2]) # network.add_edge(x, 0) # network.add_edge(x, 1)