Exemple #1
0
 def plot(self):
     from compas.plotters import MeshPlotter
     plotter = MeshPlotter(self)
     plotter.draw_vertices()
     plotter.draw_edges()
     plotter.draw_faces()
     plotter.show()
Exemple #2
0
 def plot(self):
     from compas.plotters import MeshPlotter
     plotter = MeshPlotter(self, figsize=(12, 8), tight=True)
     vertexcolor = {}
     vertexcolor.update({
         key: '#00ff00'
         for key in self.vertices_where({'is_fixed': True})
     })
     vertexcolor.update({
         key: '#0000ff'
         for key in self.vertices_where({'is_external': True})
     })
     vertexcolor.update({
         key: '#ff0000'
         for key in self.vertices_where({'is_anchor': True})
     })
     plotter.draw_vertices(facecolor=vertexcolor)
     plotter.draw_edges(keys=list(self.edges_where({'is_edge': True})))
     plotter.draw_faces(keys=list(self.faces_where({'is_loaded': True})))
     plotter.show()
vertexcolor = {}
vertexcolor.update(
    {key: '#00ff00'
     for key in form.vertices_where({'is_fixed': True})})
vertexcolor.update(
    {key: '#0000ff'
     for key in form.vertices_where({'is_external': True})})
vertexcolor.update(
    {key: '#ff0000'
     for key in form.vertices_where({'is_anchor': True})})

radius = {key: 0.05 for key in form.vertices()}
radius.update({key: 0.1 for key in form.vertices_where({'is_anchor': True})})

plotter.draw_vertices(facecolor=vertexcolor, radius=radius)

plotter.draw_edges(
    keys=list(form.edges_where({'is_edge': True})),
    color={key: '#00ff00'
           for key in form.edges_where({'is_external': True})},
    width={key: 2.0
           for key in form.edges_where({'is_external': True})})

plotter.draw_faces(facecolor={
    key: (1.0, 0.9, 0.9)
    for key in form.faces_where({'is_loaded': False})
}, )

plotter.show()
Exemple #4
0

# ==============================================================================
# Main
# ==============================================================================

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.plotters import MeshPlotter

    vertices = [(0.0, 0.0, 0.0), (10.0, 0.0, 0.0), (10.0, 10.0, 0.0),
                (0.0, 10.0, 0.0), (5.0, 5.0, 0.0), (5.0, 5.0, 0.0)]
    faces = [[0, 1, 4], [1, 2, 4], [2, 3, 4], [3, 0, 5]]

    mesh = Mesh.from_vertices_and_faces(vertices, faces)

    plotter = MeshPlotter(mesh, figsize=(10, 7))

    plotter.draw_edges(width=0.5)

    print("Original mesh:")
    print(mesh)

    mesh_cull_duplicate_vertices(mesh)

    print("Mesh with duplicate vertices deleted:")
    print(mesh)

    plotter.show()
Exemple #5
0
trimesh_remesh(delaunay, 1.0, allow_boundary_split=True)

points = [delaunay.vertex_coordinates(key) for key in delaunay.vertices()]
faces = delaunay_from_points(points)
delaunay = Mesh.from_vertices_and_faces(points, faces)

voronoi = voronoi_from_delaunay(delaunay)

lines = []
for u, v in voronoi.edges():
    lines.append({
        'start': voronoi.vertex_coordinates(u, 'xy'),
        'end': voronoi.vertex_coordinates(v, 'xy'),
        'width': 1.0
    })

plotter = MeshPlotter(delaunay, figsize=(10, 6))

plotter.draw_lines(lines)

plotter.draw_vertices(radius=0.075,
                      facecolor={
                          key: '#0092d2'
                          for key in delaunay.vertices()
                          if key not in delaunay.vertices_on_boundary()
                      })

plotter.draw_edges(color='#cccccc')

plotter.show()
Exemple #6
0
import compas
from compas.datastructures import Mesh
from compas.plotters import MeshPlotter

mesh = Mesh.from_obj(compas.get('faces.obj'))

plotter = MeshPlotter(mesh)

plotter.draw_vertices()
plotter.draw_faces(
    text={fkey: '%.1f' % mesh.face_area(fkey)
          for fkey in mesh.faces()})
plotter.draw_edges()

plotter.show()
Exemple #7
0
 def plot(self):
     from compas.plotters import MeshPlotter
     plotter = MeshPlotter(self, figsize=(12, 8), tight=True)
     plotter.draw_vertices(radius=0.05)
     plotter.draw_edges()
     plotter.show()
Exemple #8
0
                'end': voronoi.vertex_coordinates(v, 'xy'),
                'width': 1.0
            })

        plotter = MeshPlotter(mesh, figsize=(10, 7))

        plotter.draw_lines(lines)

        plotter.draw_vertices(radius=0.075,
                              facecolor={
                                  key: '#0092d2'
                                  for key in mesh.vertices()
                                  if key not in mesh.vertices_on_boundary()
                              })

        plotter.draw_edges(color='#cccccc')

        plotter.show()

    if testrun == 2:
        from compas.datastructures import Mesh
        from compas.plotters import MeshPlotter
        from compas.geometry import mesh_smooth_area

        vertices = [(0.0, 0.0, 0.0), (10.0, 0.0, 0.0), (10.0, 10.0, 0.0),
                    (0.0, 10.0, 0.0)]
        faces = [[0, 1, 2, 3]]

        mesh = Mesh.from_vertices_and_faces(vertices, faces)

        key = mesh.insert_vertex(0)
Exemple #9
0
    fixed = mesh.vertices_where({'is_anchor': True})
    fixed = [k_i[k] for k in fixed]
    edges = [(k_i[u], k_i[v]) for u, v in mesh.edges()]

    xyz, q, f, l, r = fd_numpy(xyz, edges, fixed, q, loads)

    for key, attr in mesh.vertices(True):
        index = k_i[key]
        attr['x'] = xyz[index, 0]
        attr['y'] = xyz[index, 1]
        attr['z'] = xyz[index, 2]

    for index, (u, v, attr) in enumerate(mesh.edges(True)):
        attr['f'] = f[index, 0]

    plotter = MeshPlotter(mesh, figsize=(10, 7))

    zmax = max(mesh.get_vertices_attribute('z'))
    fmax = max(mesh.get_edges_attribute('f'))

    plotter.draw_lines(lines)

    plotter.draw_vertices()
    plotter.draw_faces()
    plotter.draw_edges(
        width={(u, v): 10 * attr['f'] / fmax for u, v, attr in mesh.edges(True)},
        color={(u, v): i_to_rgb(attr['f'] / fmax) for u, v, attr in mesh.edges(True)},
    )

    plotter.show()
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()
mesh = Mesh.from_obj(compas.get('faces.obj'))

edges = list(mesh.edges())

root = mesh.get_any_vertex()

ordering, predecessors, paths = depth_first_tree(mesh.adjacency, root)

edgecolor = {}
edgewidth = {}

for u, v in pairwise(paths[0]):
    if not mesh.has_edge(u, v):
        u, v = v, u
    edgecolor[(u, v)] = '#ff0000'
    edgewidth[(u, v)] = 3.0

for path in paths[1:]:
    parent = predecessors[path[0]]
    for u, v in pairwise([parent] + path):
        if not mesh.has_edge(u, v):
            u, v = v, u
        edgecolor[(u, v)] = '#00ff00'
        edgewidth[(u, v)] = 3.0

plotter = MeshPlotter(mesh, figsize=(10, 7))

plotter.draw_vertices(text='key', facecolor={root: '#ff0000'}, radius=0.2)
plotter.draw_edges(color=edgecolor, width=edgewidth)

plotter.show()
Exemple #12
0
        for path in paths[1:]:
            parent = predecessors[path[0]]
            for u, v in pairwise([parent] + path):
                if not mesh.has_edge(u, v):
                    u, v = v, u
                edgecolor[(u, v)] = '#00ff00'
                edgewidth[(u, v)] = 5.0

        plotter = MeshPlotter(mesh, figsize=(10, 7))

        plotter.draw_vertices(text='key',
                              facecolor={key: '#ff0000'
                                         for key in (root, )},
                              radius=0.2)
        plotter.draw_edges(color=edgecolor, width=edgewidth)

        plotter.show()

    # dynamic traversal to visualize the difference
    # between DFS and BFS

    # ==========================================================================
    # testrun 2
    # ==========================================================================

    if testrun == 2:
        import compas

        from compas.datastructures import Network
        from compas.topology import shortest_path
Exemple #13
0
    radius   = mesh.get_edges_attribute('radius')

    lines = []
    for u, v in mesh.edges():
        lines.append({
            'start': mesh.vertex_coordinates(u, 'xy'),
            'end'  : mesh.vertex_coordinates(v, 'xy'),
            'color': '#cccccc',
            'width': 0.5
        })

    plotter = MeshPlotter(mesh, figsize=(10, 7), fontsize=6)

    plotter.draw_lines(lines)
    plotter.draw_vertices(facecolor={key: '#000000' for key in mesh.vertices_where({'is_fixed': True})})
    plotter.draw_edges()

    plotter.update(pause=1.0)

    def callback(k, xyz, crits, args):
        print(k)

        plotter.update_vertices()
        plotter.update_edges()
        plotter.update(pause=0.001)

        for key, attr in mesh.vertices(True):
            index = k_i[key]
            attr['x'] = xyz[index, 0]
            attr['y'] = xyz[index, 1]
            attr['z'] = xyz[index, 2]