a = split_edge_network(network, 0, 22) b = split_edge_network(network, 2, 30) c = split_edge_network(network, 17, 21) d = split_edge_network(network, 28, 16) lines = [] for u, v in network.edges(): lines.append({ 'start': network.vertex_coordinates(u, 'xy'), 'end' : network.vertex_coordinates(v, 'xy'), 'arrow': 'end', 'width': 4.0, 'color': '#00ff00' }) plotter = NetworkPlotter(network) plotter.draw_vertices(radius=0.2, facecolor={key: '#ff0000' for key in (a, b, c, d)}, text={key: key for key in network.vertices()}) plotter.draw_edges(color={(u, v): '#cccccc' for u, v in network.edges()}) plotter.draw_faces(facecolor={fkey: '#eeeeee' for fkey in network.faces()}, text={fkey: fkey for fkey in network.faces()}) plotter.draw_xlines(lines) plotter.show()
# -------------------------------------------------------------------------- # selections # -------------------------------------------------------------------------- # ============================================================================== # Debugging # ============================================================================== if __name__ == '__main__': from compas.visualization.plotters.networkplotter import NetworkPlotter network = Network.from_obj(compas.get_data('open_edges.obj')) print(network) plotter = NetworkPlotter(network) plotter.defaults['vertex.fontsize'] = 10.0 plotter.draw_vertices( facecolor={key: '#ff0000' for key in network.leaves()}, radius=0.2, text={key: key for key in network.vertices()} ) plotter.draw_edges() plotter.show()
if not any([b in network.halfedge[key] for key in colored_with_current]): key_to_color[b] = current_color colored_with_current.append(b) for key in colored_with_current[1:]: uncolored.remove(key) current_color += 1 return key_to_color # ============================================================================== # Debugging # ============================================================================== if __name__ == "__main__": import compas from compas.datastructures.network import Network from compas.visualization.plotters.networkplotter import NetworkPlotter network = Network.from_obj(compas.get_data('grid_irregular.obj')) key_color = network_vertex_coloring(network) colors = ['#ff0000', '#00ff00', '#0000ff'] plotter = NetworkPlotter(network) plotter.draw_vertices(facecolor={key: colors[key_color[key]] for key in network}) plotter.draw_edges() plotter.show()
if __name__ == '__main__': import compas from compas.datastructures.network import Network from compas.visualization.plotters.networkplotter import NetworkPlotter network = Network.from_obj(compas.get_data('fink.obj')) embedding = network.copy() fix = (1, 12) if embed_network_in_plane(embedding, fix=fix): plotter = NetworkPlotter(embedding) plotter.draw_xlines([{ 'start': network.vertex_coordinates(u, 'xy'), 'end': network.vertex_coordinates(v, 'xy'), 'color': '#cccccc' } for u, v in network.edges()]) plotter.draw_vertices(radius=0.3, text={key: key for key in embedding.vertices()}, facecolor={key: '#ff0000' for key in fix}) plotter.draw_edges()
path = path1 + path2[1:] edges = [] for i in range(len(path) - 1): u = path[i] v = path[i + 1] if v not in network.edge[u]: u, v = v, u edges.append([u, v]) vertexcolor = {key: '#ff0000' for key in path} vertexcolor[21] = '#00ff00' vertexcolor[22] = '#00ff00' plotter = NetworkPlotter(network) plotter.draw_vertices(text={key: key for key in network.vertices()}, textcolor={key: '#ffffff' for key in path[1:-1]}, facecolor=vertexcolor, radius=0.15) plotter.draw_edges(color={(u, v): '#ff0000' for u, v in edges}, width={(u, v): 2.0 for u, v in edges}, text={(u, v): '{:.1f}'.format(weight[(u, v)]) for u, v in network.edges()})
for vertices in faces: network.add_face(vertices) # ============================================================================== # Debugging # ============================================================================== if __name__ == '__main__': import compas from compas.datastructures.network import Network from compas.visualization.plotters.networkplotter import NetworkPlotter network = Network.from_obj(compas.get_data('grid_irregular.obj')) network_find_faces(network, breakpoints=network.leaves()) plotter = NetworkPlotter(network) plotter.draw_vertices( radius=0.075, facecolor={key: '#cccccc' for key in network.leaves()}) plotter.draw_edges(color={(u, v): '#cccccc' for u, v in network.edges()}) plotter.draw_faces(facecolor={fkey: '#eeeeee' for fkey in network.faces()}, text={fkey: fkey for fkey in network.faces()}) plotter.show()
edges = [(key_index[u], key_index[v]) for u, v in network.edges()] C = connectivity_matrix(edges, rtype='list') C = matlab.double(C) # compute coordinate differences in Matlab # # using an engine function # uv = matlab.engine.mtimes(C, xyz) # using workspace data matlab.engine.workspace['C'] = C matlab.engine.workspace['xyz'] = xyz uv = matlab.engine.eval('C * xyz') # compute edge lengths in Python l = normrow(uv) l = l.flatten().tolist() # plot results as edge labels plotter = NetworkPlotter(network) plotter.draw_vertices() plotter.draw_edges(text={(u, v): '%.1f' % l[index] for index, (u, v) in enumerate(network.edges())}) plotter.show()
import compas from compas.datastructures.network import Network from compas.datastructures.network.algorithms import network_find_faces from compas.visualization.plotters.networkplotter import NetworkPlotter network = Network.from_obj(compas.get_data('grid_irregular.obj')) smooth = network.copy() fixed = smooth.leaves() # find_network_faces(smooth, breakpoints=fixed) plotter = NetworkPlotter(smooth) # draw the orginal network plotter.draw_xlines([{ 'start': network.vertex_coordinates(u, 'xy'), 'end': network.vertex_coordinates(v, 'xy'), 'color': '#cccccc' } for u, v in network.edges()]) # draw the smooth network # and visualise the smoothing process plotter.draw_vertices(facecolor={key: '#ff0000' for key in fixed}, edgecolor='#000000', radius=0.15)
line2.set_ydata(ydata2) plt.draw() plt.pause(1e-17) xyz, q, f, l, r = dr(vertices, edges, fixed, loads, qpre, fpre, lpre, linit, E, radius, callback=plot_iterations) plt.show() for key, attr in network.vertices(True): index = k2i[key] attr['x'] = xyz[index][0] attr['y'] = xyz[index][1] attr['z'] = xyz[index][2] plotter = NetworkPlotter(network) plotter.draw_vertices() plotter.draw_edges() plotter.show()
# compute the shortest path path = network_dijkstra_path(network.adjacency, weight, start, end) # plot! edges = [] for i in range(len(path) - 1): u = path[i] v = path[i + 1] if v not in network.edge[u]: u, v = v, u edges.append([u, v]) plotter = NetworkPlotter(network) plotter.draw_vertices( text={key: key for key in (start, end)}, facecolor={key: '#ff0000' for key in (path[0], path[-1])}, radius=0.15) plotter.draw_edges(color={(u, v): '#ff0000' for u, v in edges}, width={(u, v): 2.0 for u, v in edges}, text={(u, v): '{:.1f}'.format(weight[(u, v)]) for u, v in network.edges()})