Esempio n. 1
0
    faces = [(0, 1, 4), (1, 2, 4), (2, 3, 4), (3, 0, 4)]

    mesh = Mesh.from_vertices_and_faces(vertices, faces)

    t0 = time.time()

    optimise_trimesh_topology(mesh,
                              0.5,
                              tol=0.05,
                              kmax=300,
                              allow_boundary_split=True,
                              allow_boundary_swap=True,
                              fixed=mesh.vertices_on_boundary())

    t1 = time.time()

    print(t1 - t0)

    plotter = MeshPlotter(mesh)

    plotter.defaults['vertex.edgewidth'] = 0.1

    plotter.defaults['face.facecolor'] = '#eeeeee'
    plotter.defaults['face.edgecolor'] = '#222222'
    plotter.defaults['face.edgewidth'] = 0.1

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

    plotter.show()
Esempio n. 2
0
# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == '__main__':

    import compas

    from compas.datastructures.mesh import Mesh
    from compas.visualization.plotters.meshplotter import MeshPlotter

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

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

    plotter = MeshPlotter(mesh)

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

    def callback(mesh, k, args):
        plotter, = args

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

    smooth_mesh_centroid(mesh,
                         fixed=fixed,
                         kmax=100,
                         callback=callback,
Esempio n. 3
0
    dual = construct_dual_mesh(mesh)

    lines = []
    for u, v in dual.wireframe():
        lines.append({
            'start': dual.vertex_coordinates(u, 'xy'),
            'end'  : dual.vertex_coordinates(v, 'xy'),
            'color': '#000000',
            'width': 2.0
        })

    points = []
    for key in dual.vertices():
        points.append({
            'pos'      : dual.vertex_coordinates(key, 'xy'),
            'text'     : str(key),
            'textcolor': '#000000',
            'facecolor': '#eeeeee',
            'edgecolor': '#000000',
            'radius'   : 0.2
        })

    plotter = MeshPlotter(mesh)

    plotter.draw_edges(color={(u, v): '#cccccc' for u, v in mesh.edges()})
    plotter.draw_xlines(lines)
    plotter.draw_xpoints(points)

    plotter.show()
Esempio n. 4
0
# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == "__main__":

    import compas
    from compas.datastructures.mesh.mesh import Mesh
    from compas.visualization.plotters.meshplotter import MeshPlotter

    data = compas.get_data('faces.obj')
    mesh = Mesh.from_obj(data)

    mesh_split_edge(mesh, 17, 32)

    print(mesh.face_vertices(11, ordered=True))
    print(mesh.face_vertices(16, ordered=True))

    print(mesh.halfedge[32][36])
    print(mesh.halfedge[36][32])

    print(mesh.halfedge[36][17])
    print(mesh.halfedge[17][36])

    plotter = MeshPlotter(mesh)

    plotter.draw_vertices()
    plotter.draw_faces()

    plotter.show()
Esempio n. 5
0
    optimise_trimesh_topology(mesh, 1.0, allow_boundary_split=True)

    points = [mesh.vertex_coordinates(key) for key in mesh]

    voronoi, delaunay = voronoi_from_points(points, return_delaunay=True)

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

    boundary = set(delaunay.vertices_on_boundary())

    plotter = MeshPlotter(delaunay)

    plotter.draw_vertices(
        radius=0.075,
        facecolor={key: '#0092d2'
                   for key in delaunay if key not in boundary})
    plotter.draw_edges(color='#cccccc')
    plotter.draw_xlines(lines)

    plotter.show()

    # delaunay.plot(
    #     vertexsize=0.075,
    #     faces_on=False,
    #     edgecolor='#cccccc',
    #     vertexcolor={key: '#0092d2' for key in delaunay if key not in boundary},
Esempio n. 6
0
if __name__ == "__main__":

    import compas
    from compas.datastructures.mesh.mesh import Mesh
    from compas.visualization.plotters.meshplotter import MeshPlotter

    data = compas.get_data('faces.obj')
    mesh = Mesh.from_obj(data)

    fkey = 12
    where = mesh.face_vertices(fkey)[0:1]
    xyz = mesh.face_centroid(fkey)

    unweld_vertices_mesh(mesh, fkey, where)

    # move the unwelded vertex to the original centroid of the face it (partially)
    # disconnects
    mesh.vertex[36]['x'] = xyz[0]
    mesh.vertex[36]['y'] = xyz[1]
    mesh.vertex[36]['z'] = xyz[2]

    print(mesh)

    plotter = MeshPlotter(mesh)

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

    plotter.show()
Esempio n. 7
0
# ==============================================================================
# Debugging
# ==============================================================================

if __name__ == '__main__':

    import compas

    from compas.visualization.plotters.meshplotter import MeshPlotter

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

    mesh.update_default_vertex_attributes({'px': 0.0, 'py': 0.0, 'pz': 0.0})
    mesh.update_default_vertex_attributes({'is_fixed': False})

    plotter = MeshPlotter(mesh)

    print(mesh.number_of_vertices())
    print(mesh.number_of_edges())
    print(mesh.number_of_faces())

    plotter.defaults['face.facecolor'] = '#eeeeee'
    plotter.defaults['face.edgewidth'] = 0.0

    plotter.draw_vertices(
        facecolor={key: '#ff0000' for key in mesh.vertices() if mesh.vertex_degree(key) == 2}
    )

    plotter.draw_faces(text={key: key for key in mesh.faces()})
    plotter.draw_edges()
from compas.datastructures.mesh import Mesh
from compas.datastructures.mesh.operations import split_face_mesh
from compas.datastructures.mesh.operations import collapse_edge_trimesh
from compas.visualization.plotters.meshplotter import MeshPlotter


__author__    = ['Tom Van Mele', ]
__copyright__ = 'Copyright 2016 - Block Research Group, ETH Zurich'
__license__   = 'MIT License'
__email__     = '*****@*****.**'


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

plotter = MeshPlotter(mesh)

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

plotter.draw_vertices()
plotter.draw_faces()

for fkey in list(mesh.faces()):
    vertices = mesh.face_vertices(fkey, ordered=True)
    split_face_mesh(mesh, fkey, vertices[0], vertices[2])

u = 18
vertices = [3, 29, 24, 1, 21, 23, 2, 12, 28, 34, 0, 20, 4, 26, 7, 32, 5, 15, 25, 17, 22, 11, 8, 31, 19, 9, 30, 16, 13, 14, 6, 33, 27, 35]

for v in vertices:
Esempio n. 9
0
    from compas.geometry import centroid_points

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

    for fkey in list(mesh.faces()):
        vertices = mesh.face_vertices(fkey, ordered=True)
        split_face_mesh(mesh, fkey, vertices[0], vertices[2])

    swap_edge_trimesh(mesh, 14, 16)
    swap_edge_trimesh(mesh, 31, 22)

    collapse_edge_trimesh(mesh, 30, 17)
    collapse_edge_trimesh(mesh, 30, 31)
    collapse_edge_trimesh(mesh, 30, 22)

    points = mesh.get_vertices_attributes('xyz',
                                          keys=mesh.vertex_neighbours(30))
    x, y, z = centroid_points(points)
    attr = {'x': x, 'y': y, 'z': z}

    mesh.set_vertex_attributes(30, attr)

    plotter = MeshPlotter(mesh)

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

    plotter.show()
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)

plotter.draw_xlines(lines)

plotter.show()