Esempio n. 1
0
 def plot(self):
     from compas.plotters import MeshPlotter
     plotter = MeshPlotter(self)
     plotter.draw_vertices()
     plotter.draw_edges()
     plotter.draw_faces()
     plotter.show()
Esempio n. 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()
Esempio n. 3
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()
Esempio n. 4
0
# ==============================================================================
# Main
# ==============================================================================

if __name__ == '__main__':

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

    points = [[2.994817685045075, 10.855606612493078, 0.0],
              [4.185204599300653, 9.527867361977242, 0.0],
              [4.414125159734419, 10.718254276232818, 0.0],
              [5.925000858597267, 9.344730913630228, 0.0],
              [8.900968144236211, 10.809822500406325, 0.0],
              [9.496161601363999, 8.566401008155429, 0.0],
              [7.710581229980631, 7.9254234389408875, 0.0],
              [7.847933566240888, 6.414547740078039, 0.0],
              [3.9104999267801377, 4.9036720412151915, 0.0],
              [5.2909301507195865, 6.342692886748852, 0.0]]
    segments = list(pairwise(list(range(len(points))) + [0]))

    vertices, faces = conforming_delaunay_triangle(points, segments)

    mesh = Mesh.from_vertices_and_faces(vertices, faces)

    plotter = MeshPlotter(mesh)
    plotter.draw_faces()
    plotter.draw_vertices(text='key')
    plotter.show()
Esempio n. 5
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()
Esempio n. 6
0
    from compas.datastructures import Mesh
    from compas.plotters import MeshPlotter
    from compas.geometry import subtract_vectors

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

    vertices = set(mesh.vertices())

    fkey = 12
    where = mesh.face_vertices(fkey)[0:2]
    centroid = mesh.face_centroid(fkey)

    face = mesh.unweld_vertices(fkey, where)

    for key in face:
        if key in vertices:
            continue
        xyz = mesh.vertex_coordinates(key)
        v = subtract_vectors(centroid, xyz)
        mesh.vertex[key]['x'] += 0.3 * v[0]
        mesh.vertex[key]['y'] += 0.3 * v[1]
        mesh.vertex[key]['z'] += 0.3 * v[2]

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

    plotter.draw_vertices()
    plotter.draw_faces(text={fkey: fkey for fkey in mesh.faces()})

    plotter.show()
Esempio n. 7
0
mesh = Mesh.from_obj(compas.get('faces.obj'))

# extract numerical data from the datastructure

vertices = mesh.get_vertices_attributes(('x', 'y', 'z'))
adjacency = [mesh.vertex_neighbors(key) for key in mesh.vertices()]
fixed = [int(mesh.vertex_degree(key) == 2) for key in mesh.vertices()]

slider = list(mesh.vertices_where({'x': (-0.1, 0.1), 'y': (9.9, 10.1)}))[0]

# make a plotter for (dynamic) visualization
# and define a callback function
# for plotting the intermediate configurations

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


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

    if k < kmax - 1:
        xyz[slider][0] = 0.1 * (k + 1)

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

    for key, attr in mesh.vertices(True):
        attr['x'] = xyz[key][0]
        attr['y'] = xyz[key][1]
Esempio n. 8
0
# Main
# ==============================================================================

if __name__ == "__main__":

    import compas

    from compas.plotters import Plotter
    from compas.utilities import pairwise
    from compas.plotters import MeshPlotter

    from compas.datastructures import Mesh

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

    fkey = mesh.get_any_face()

    polyline = mesh.face_coordinates(fkey)
    polyline.append(polyline[0])

    o = offset_polyline(polyline, 0.1)

    lines = []
    for a, b in pairwise(o):
        lines.append({'start': a, 'end': b, 'color': '#00ff00', 'width': 0.5})

    plotter = MeshPlotter(mesh)
    plotter.draw_lines(lines)
    plotter.draw_faces()
    plotter.show()
Esempio n. 9
0
    vertices = mesh.get_vertices_attributes('xyz')
    faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
    adjacency = [
        mesh.vertex_faces(key, ordered=True) for key in mesh.vertices()
    ]
    fixed = [key for key in mesh.vertices() if mesh.vertex_degree(key) == 2]

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

    smooth_area(vertices, faces, adjacency, fixed=fixed, kmax=100)

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

    plotter = MeshPlotter(mesh)

    plotter.draw_lines(lines)
    plotter.draw_vertices(facecolor={key: '#ff0000' for key in fixed})
    plotter.draw_edges()

    plotter.show()
Esempio n. 10
0
# update the mesh

for key, attr in mesh.vertices(True):
    index = key_index[key]
    attr['x'] = xy[index, 0]
    attr['y'] = xy[index, 1]

# lines for visualisation
# omit the diagonal of the *hole*

lines = []

for u, v in mesh.wireframe():
    if u == v1 and v == v2:
        continue
    if u == v2 and v == v1:
        continue
    lines.append({
        'start': mesh.vertex_coordinates(u, 'xy'),
        'end'  : mesh.vertex_coordinates(v, 'xy'),
        'color': '#000000',
        'width': 0.5
    })

# visualise the result

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

plotter.draw_lines(lines)
plotter.show()
Esempio n. 11
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.geometry import pointcloud_xy
from compas.datastructures import Mesh
from compas.topology import delaunay_from_points
from compas.plotters import MeshPlotter

points = pointcloud_xy(10, (0, 10))
faces = delaunay_from_points(points)

delaunay = Mesh.from_vertices_and_faces(points, faces)

plotter = MeshPlotter(delaunay)

plotter.draw_vertices(radius=0.1)
plotter.draw_faces()

plotter.show()
Esempio n. 13
0
        [2, 3, 4],
        [3, 0, 4],
    ]

    lines = [
        ([0., 0., 0.], [1., 0., -1.]),
        ([0., 0., 0.], [-1., 0., -1.]),
        ([0., 0., 0.], [0., 1., -1.]),
        ([0., 0., 0.], [0., -1., -1.]),
        ([0., 0., 0.], [0., 0., 1.]),
    ]

    #kagome = Kagome.from_skeleton(lines)
    kagome = Kagome.from_vertices_and_faces(vertices, faces)
    kagome.densification(3)
    kagome.patterning()
    kagome.store_kagome_polyedge_data()

    plotter = MeshPlotter(kagome.kagome)
    plotter.draw_vertices(radius=.005)
    plotter.draw_edges()
    plotter.draw_faces()
    plotter.show()

    #print kagome.kagome_negative_singularities()
    #print kagome.kagome_singularities()
    #print kagome.kagome_polyline_frames()
    #kagome.kagome_polyedges()
    #kagome.kagome_polyline_colouring()
    kagome.kagome_polyedge_weaving()
Esempio n. 14
0
#         a, b, c = delaunay.face_coordinates(key)
#         center, radius, normal = circle_from_points_xy(a, b, c)
#         voronoi.vertex[key]['x'] = center[0]
#         voronoi.vertex[key]['y'] = center[1]
#         voronoi.vertex[key]['z'] = center[2]

#     return voronoi

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

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.geometry import pointcloud_xy
    from compas.geometry import delaunay_from_points
    from compas.plotters import MeshPlotter

    points = pointcloud_xy(20, (0, 50))
    faces = delaunay_from_points(points)

    delaunay = Mesh.from_vertices_and_faces(points, faces)

    plotter = MeshPlotter(delaunay, figsize=(12, 8))

    plotter.draw_vertices(radius=0.1)
    plotter.draw_faces()

    plotter.show()
Esempio n. 15
0
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()
Esempio n. 16
0
    # mesh = Mesh.from_obj(compas.get('faces.obj'))
    # mesh_quads_to_triangles(mesh)

    # mesh = Mesh.from_polyhedron(12)
    # mesh_quads_to_triangles(mesh)

    index_key = mesh.index_key()

    sources = [0]

    d = mesh_geodesic_distances(mesh, sources, m=1.0).tolist()

    dmin = min(d)
    dmax = max(d)
    drange = dmax - dmin

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

    facecolor = {key: i_to_blue(1 - (d[i] - dmin) / drange) for i, key in enumerate(mesh.vertices())}
    for i in sources:
        facecolor[index_key[i]] = '#ff0000'

    plotter.draw_vertices(
        facecolor=facecolor,
        radius=0.05
    )
    # plotter.draw_edges()
    plotter.draw_faces()

    plotter.show()
Esempio n. 17
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(text='key', radius=0.15)
plotter.draw_edges()
plotter.draw_faces()

plotter.show()
Esempio n. 18
0
        points = [mesh.vertex_coordinates(key) for key in mesh.vertices()]

        faces = delaunay_from_points(points)
        mesh = Mesh.from_vertices_and_faces(points, faces)

        voronoi = voronoi_from_delaunay(mesh)

        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(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:
def update_plot(k, args):
    plotter.update_vertices()
    plotter.update_edges()
    plotter.update_faces()
    plotter.update(pause=0.001)


# path to the sample file
DATA = os.path.join(os.path.dirname(__file__), '..', 'data')
FILE = os.path.join(DATA, 'faces.obj')

# make a mesh
mesh = Mesh.from_obj(FILE)

# identify fixed points
fixed = list(mesh.vertices_where({'vertex_degree': 2}))

# make a plotter
plotter = MeshPlotter(mesh, figsize=(10, 7))

# draw the original configuration
plotter.draw_vertices(facecolor={key: '#ff0000' for key in fixed})
plotter.draw_edges()
plotter.draw_faces()

# smooth with dynamic viz
mesh_smooth_centroid(mesh, fixed=fixed, kmax=100, callback=update_plot)

# keep plot alive
plotter.show()
Esempio n. 20
0
    points = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
    faces = delaunay_from_points(points)
    mesh = Mesh.from_vertices_and_faces(points, faces)

    dual = mesh_dual(mesh)

    # network = FaceNetwork.from_vertices_and_faces(points, faces)
    # network_find_faces(network)
    # dual = network_dual(network)

    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(dual, figsize=(10, 7))

    plotter.draw_lines(lines)
    plotter.draw_vertices(facecolor='#eeeeee',
                          edgecolor='#000000',
                          radius=0.05)
    plotter.draw_faces(facecolor='#eeeeee', edgecolor='#eeeeee', text='key')
    plotter.draw_edges()

    plotter.show()
Esempio n. 21
0
    loads = mesh.get_vertices_attributes(('px', 'py', 'pz'))
    q     = mesh.get_edges_attribute('q')
    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()]

    # compute equilibrium
    # update the mesh geometry

    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]

    # visualisae the result
    # color the vertices according to their elevation

    plotter = MeshPlotter(mesh)

    zmax = max(mesh.get_vertices_attribute('z'))

    plotter.draw_vertices(
        facecolor={key: i_to_black(attr['z'] / zmax) for key, attr in mesh.vertices(True)}
    )
    plotter.draw_faces()
    plotter.draw_edges()
    plotter.show()
Esempio n. 22
0
    for u, v in mesh.edges():
        lines.append({
            'start': mesh.vertex_coordinates(u, 'xy'),
            'end': mesh.vertex_coordinates(v, 'xy'),
            'color': '#cccccc',
            'width': 1.0,
        })

    smooth_centerofmass(vertices, adjacency, fixed=fixed, kmax=100)

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

    plotter = MeshPlotter(mesh)

    plotter.draw_lines(lines)
    plotter.draw_vertices(
        text={key: mesh.vertex_degree(key)
              for key in mesh.vertices()},
        facecolor={key: '#ff0000'
                   for key in fixed})
    plotter.draw_edges()
    plotter.draw_faces(text={
        key: "{:.1f}".format(mesh.face_area(key))
        for key in mesh.faces()
    })

    plotter.show()
Esempio n. 23
0
    import compas

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

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

    for key, attr in mesh.vertices(True):
        attr['is_fixed'] = mesh.vertex_degree(key) == 2

    fixed = [key for key in mesh.vertices_where({'is_fixed': True})]
    radius = {key: (0.05 if key in fixed else 0.01) for key in mesh.vertices()}

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

    plotter.draw_vertices(radius=radius)
    plotter.draw_faces()
    plotter.draw_edges()

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

        if k % 100 == 0:
            dev = mesh_flatness(mesh, maxdev=0.02)

            plotter.update_vertices(radius=radius)
            plotter.update_faces(
                facecolor={fkey: i_to_rgb(dev[fkey])
                           for fkey in mesh.faces()})
import compas
from compas.datastructures import Mesh
from compas.plotters import MeshPlotter

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

key = 12
nbrs = mesh.face_neighbours(key)

text = {nbr: str(nbr) for nbr in nbrs}
text[key] = str(key)

color = {nbr: '#cccccc' for nbr in nbrs}
color[key] = '#ff0000'

plotter = MeshPlotter(mesh)
plotter.draw_vertices()
plotter.draw_faces(text=text, facecolor=color)
plotter.draw_edges()
plotter.show()
Esempio n. 25
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()
Esempio n. 26
0
    from compas.datastructures import Mesh
    from compas.datastructures import mesh_smooth_area

    from compas.plotters import MeshPlotter


    vertices = [(0.0, 0.0, 0.0), (10.0, 0.0, 0.0), (6.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)
    fixed = [key]

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

    plotter.draw_edges(width=0.5)

    def callback(mesh, k, args):
        print(k)
        plotter.update_edges()
        plotter.update()

    trimesh_remesh(
        mesh,
        0.5,
        kmax=200,
        allow_boundary_split=True,
        allow_boundary_swap=True,
        allow_boundary_collapse=True,
Esempio n. 27
0
# Main
# ==============================================================================

if __name__ == "__main__":

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

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

    mesh_quads_to_triangles(mesh)

    split = mesh.split_edge_tri(15, 20)

    facecolor = {
        key: '#cccccc' if key != split else '#ff0000'
        for key in mesh.vertices()
    }

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

    plotter.draw_vertices(text={key: key
                                for key in mesh.vertices()},
                          radius=0.2,
                          facecolor=facecolor)
    plotter.draw_faces(text={fkey: fkey for fkey in mesh.faces()})

    plotter.show()
Esempio n. 28
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()
Esempio n. 29
0
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'
     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})})
Esempio n. 30
0
"""

from __future__ import print_function

import compas

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

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

u = [key for key in mesh.vertices() if mesh.vertex_degree(key) == 2][0]

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

plotter.defaults['face.facecolor'] = '#eeeeee'
plotter.defaults['face.edgecolor'] = '#cccccc'

plotter.draw_vertices()
plotter.draw_faces()
plotter.draw_edges()

mesh_quads_to_triangles(mesh)

while True:
    nbrs = mesh.vertex_neighbors(u, ordered=True)

    if not nbrs:
        break