def draw_stress(self, scale=None): self.clear_stress() scale = scale or self.settings['scale.stress'] stress = [ self.mesh.stress(key) for key in self.mesh.edges_where({'is_edge': True}) ] cmap = Colormap(stress, 'rgb') lines = [] for index, (u, v) in enumerate(self.mesh.edges_where({'is_edge': True})): sp, ep = self.mesh.edge_coordinates(u, v) lines.append({ 'start': sp, 'end': ep, 'radius': scale, 'color': cmap(stress[index]), 'name': "{}.stress.{}-{}".format(self.mesh.name, u, v) }) self._draw_cylinders(lines)
isolines = igl.groupsort_isolines(vertices, edges) # ============================================================================== # Visualisation # ============================================================================== viewer = ObjectViewer() viewer.add(mesh, settings={ 'color': '#ffffff', 'vertices.on': False, 'edges.on': False }) cmap = Colormap(scalars, 'rgb') for value, paths in isolines: for path in paths: points = [vertices[path[0][0]]] for i, j in path: points.append(vertices[j]) viewer.add(Polyline(points), settings={ 'edges.color': rgb_to_hex(cmap(value)), 'edges.width': 5, 'vertices.on': False }) viewer.update() viewer.show()
cablenet = Cablenet.from_json(FILE_I) # ============================================================================== # Materialize # ============================================================================== mesh_materialize_cables(cablenet) # ============================================================================== # Visualize # ============================================================================== edges = list(cablenet.edges_where({'is_edge': True})) stress = [cablenet.stress(key) for key in edges] cmap = Colormap(stress, 'rgb') edgecolor = {key: cmap(s) for key, s in zip(edges, stress)} utilization = [cablenet.stress(key) / cablenet.edge_attribute(key, 'yield') for key in edges] cmap = Colormap(utilization, 'red') edgecolor = {key: cmap(u) for key, u in zip(edges, utilization)} print(min(utilization)) print(max(utilization)) plotter = MeshPlotter(cablenet, figsize=(16, 9)) plotter.draw_vertices(radius=0.05, facecolor={key: (0.0, 0.0, 0.0) for key in cablenet.vertices_where({'is_anchor': True})}) plotter.draw_edges(width=2.0, color=edgecolor, keys=edges) plotter.save(FILE_P, dpi=150) # plotter.show()
# ============================================================================== cablenet.vertices_attribute('is_anchor', True, keys=list(cablenet.vertices_on_boundary())) # ============================================================================== # Compute equilibrium # ============================================================================== update_xyz_numpy(cablenet) # ============================================================================== # Visualize # ============================================================================== heights = cablenet.vertices_attribute('z') cmap = Colormap(heights, 'black') vertexcolor = {key: cmap(z) for key, z in zip(cablenet.vertices(), heights)} forces = cablenet.edges_attribute('f') cmap = Colormap(forces, 'rgb') edgecolor = {key: cmap(f) for key, f in zip(cablenet.edges(), forces)} plotter = MeshPlotter(cablenet, figsize=(16, 9)) plotter.draw_vertices(facecolor=vertexcolor, radius=0.05) plotter.draw_edges(width=2.0, color=edgecolor) plotter.save(FILE_P, dpi=150) # plotter.show() # ============================================================================== # Export
import compas_libigl as igl HERE = os.path.dirname(__file__) FILE = os.path.join(HERE, '..', 'data', 'tubemesh.json') mesh = Mesh.from_json(FILE) mesh_quads_to_triangles(mesh) key_index = mesh.key_index() index_key = mesh.index_key() V = mesh.vertices_attributes('xyz') F = [[key_index[key] for key in mesh.face_vertices(fkey)] for fkey in mesh.faces()] root = mesh.get_any_vertex() # D = igl.trimesh_geodistance_exact(V, F, 0) D = igl.trimesh_geodistance_heat(V, F, key_index[root]) cmap = Colormap(D, 'red') plotter = MeshPlotter(mesh, figsize=(8, 5)) plotter.draw_faces() plotter.draw_vertices( text={root: 'root'}, radius=0.2, facecolor={key: cmap(d) for key, d in zip(mesh.vertices(), D)}) plotter.show()
# and its dual mesh = Mesh.from_polyhedron(20) dual = mesh.dual() # mesh transformation for drawing various representations # of the mesh in non-overlapping way # the mesh will be transformed in-place # therefore the same transformation can be applied consecutively bbox = mesh.bounding_box_xy() dx = bbox[1][0] - bbox[0][0] X = Translation([1.5 * dx, 0, 0]) # vertex coloring key_color = vertex_coloring(mesh.adjacency) c = len(set(key_color.values())) colors = Colormap(list(range(c)), 'rgb') vertexcolor = {key: colors(key_color[key]) for key in mesh.vertices()} # face coloring # which is the same as a vertex coloring of the dual key_color = vertex_coloring(dual.adjacency) c = len(set(key_color.values())) colors = Colormap(list(range(c)), 'rgb') facecolor = {key: colors(key_color[key]) for key in dual.vertices()} # the artist for drawing various versions of the mesh artist = MeshArtist(mesh) # mesh mesh.name = "Mesh" artist.clear()
cablenet.vertices_attribute('t', 0.05) # ============================================================================== # Unload the cablenet # ============================================================================== apply_loads_numpy(cablenet) # ============================================================================== # Visualize # ============================================================================== edges = list(cablenet.edges_where({'is_edge': True})) stress = [cablenet.stress(key) for key in edges] cmap = Colormap(stress, 'rgb') edgecolor = {key: cmap(s) for key, s in zip(edges, stress)} print(stress) utilization = [ cablenet.stress(key) / cablenet.edge_attribute(key, 'yield') for key in edges ] # cmap = Colormap(utilization, 'red') # edgecolor = {key: cmap(u) for key, u in zip(edges, utilization)} print(min(utilization)) print(max(utilization)) plotter = MeshPlotter(cablenet, figsize=(16, 9))
from compas.utilities import Colormap from compas_plotters import MeshPlotter # ============================================================================== # Input geometry # ============================================================================== mesh = Mesh.from_off(igl.get('tubemesh.off')) mesh.quads_to_triangles() # ============================================================================== # Mass matrix # ============================================================================== mass = igl.trimesh_massmatrix(mesh) # ============================================================================== # Visualisation # ============================================================================== cmap = Colormap(mass, 'red') plotter = MeshPlotter(mesh, figsize=(8, 5)) plotter.draw_vertices(radius=0.2, facecolor={ key: cmap(mass[index]) for index, key in enumerate(mesh.vertices()) }) plotter.draw_faces() plotter.show()
# ============================================================================== # Input # ============================================================================== mesh = Mesh.from_off(igl.get('tubemesh.off')) mesh.quads_to_triangles() # ============================================================================== # Geodesic distance # ============================================================================== source = mesh.get_any_vertex() distance = igl.trimesh_geodistance(mesh.to_vertices_and_faces(), source, method='heat') # ============================================================================== # Visualize # ============================================================================== cmap = Colormap(distance, 'red') plotter = MeshPlotter(mesh, figsize=(16, 9), tight=True) plotter.draw_vertices(radius=0.2, facecolor={ key: cmap(distance[index]) for index, key in enumerate(mesh.vertices()) }) plotter.draw_faces() plotter.save('examples/geodistance.png')