Exemple #1
0
from compas.plotters import MeshPlotter

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

vertices = mesh.get_vertices_attributes('xyz')
neighbours = [mesh.vertex_neighbours(key) 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_centroid(vertices, neighbours, 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}, radius=0.05)
plotter.draw_edges()

plotter.show()
Exemple #2
0
            'width': 1.0
        })

    plotter = Plotter(figsize=(10, 6))

    pcoll = plotter.draw_points(points)
    lcoll = plotter.draw_lines(lines)

    def callback(k, args):
        plotter.update_pointcollection(pcoll, vertices, 0.1)

        segments = []
        for u, v in mesh.edges():
            a = vertices[u][0:2]
            b = vertices[v][0:2]
            segments.append([a, b])

        plotter.update_linecollection(lcoll, segments)
        plotter.update(pause=0.001)

    vertices = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
    adjacency = [mesh.vertex_neighbors(key) for key in mesh.vertices()]

    smooth_centroid(vertices,
                    adjacency,
                    fixed=fixed,
                    kmax=100,
                    callback=callback)

    plotter.show()
Exemple #3
0
# ==============================================================================
# store the original geometry

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

smooth_centroid(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]

# ==============================================================================
# visualise the result

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

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