示例#1
0
def visualize_mesh_traversal() -> None:
    ''' Datastructures task
    '''

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

    x_values = {}
    for vkey in mesh.vertices_on_boundary():
        x_values[vkey] = mesh.vertex_coordinates(vkey)[0]

    max_x = max(x_values.values())

    print("Vertices on the right edge of the mesh:")
    print([key for key in x_values if x_values[key] == max_x])

    start_key = int(input("\nSelect start vertex: "))

    path_verts = traverse_mesh(mesh, start_key)

    print('\nPath calculated, starting MeshPlotter.')

    plotter = MeshPlotter(mesh, figsize=(16, 10))
    plotter.draw_vertices(text={key: key
                                for key in path_verts},
                          radius=0.2,
                          facecolor={key: '#ff0000'
                                     for key in path_verts})

    plotter.draw_edges()
    plotter.draw_faces()

    plotter.show()
示例#2
0
 def plot(self):
     """Plot a form diagram with a plotter with all the default settings."""
     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: '#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()
示例#3
0
 def plot(self):
     """Plot a force diagram with a plotter with all the default settings."""
     from compas_plotters import MeshPlotter
     plotter = MeshPlotter(self, figsize=(12, 8), tight=True)
     plotter.draw_vertices(radius=0.05)
     plotter.draw_edges()
     plotter.show()
示例#4
0
def plot_mesh(mesh_info_dict,
              current_vertex_info_dict,
              edges_flag=1,
              faces_flag=1):
    """
    This function plot the mesh and the path dynamically. But the problem is that
    it seems that plotter.close() have not been defined in the current version
    of the COMPAS (0.10.0)
    """
    mesh = mesh_info_dict['mesh']
    # define the facecolor dictionaries for vertices
    facecolor = {}
    # facecolor for all on-baoundary vertices
    facecolor.update({
        key: (200, 200, 200)
        for key in mesh_info_dict['non_on_boundry_vertices']
    })
    # facecolor for all non-on-baoundary  vertices
    facecolor.update({
        key: (150, 150, 150)
        for key in mesh_info_dict['on_boundry_vertices']
    })
    # facecolor for all on-baoundary neighborhood vertices
    facecolor.update({
        key: (0, 255, 0)
        for key in current_vertex_info_dict['non_on_boundry_neighbs_vertices']
    })
    # facecolor for all non-on-baoundary neighborhood vertices
    facecolor.update({
        key: (0, 0, 255)
        for key in current_vertex_info_dict['on_boundry_neighbs_vertices']
    })
    # facecolor for the current vertes
    facecolor.update({current_vertex_info_dict['current_vertex']: (255, 0, 0)})
    # define important vertices
    keys = mesh_info_dict['all_vertices']

    # instantiate the MeshPlotter
    plotter = MeshPlotter(mesh=mesh, figsie=(4, 4))
    # draw vertices
    plotter.draw_vertices(radius=0.3,
                          text='key',
                          keys=keys,
                          facecolor=facecolor)
    # draw edges
    if edges_flag == 1: plotter.draw_edges()
    # draw faces
    if faces_flag == 1: plotter.draw_faces()
    # show mesh plot
    plotter.show()
示例#5
0
def plot_mesh(mesh):
    """
    Compas Mesh Plotter
    """
    all_keys=list(mesh.vertices())
    plotter=MeshPlotter(mesh)
    plotter.draw_vertices(text='key', keys=all_keys, radius=0.01)
    plotter.draw_faces()
    plotter.show()
示例#6
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()
def traverse_boundary_to_boundary(mesh):
    """
    traverse the mesh from boundary to boundary in a "straight" line and visulize the results
    mesh: mesh data structure
    return a list of ordered vertex keys for the path and the mesh plotter with highlighted path (use plotter.show() to visualize))
    """
    bound_keys=mesh.vertices_on_boundary()
    # randomly pick a boundary key
    ind=randrange(len(bound_keys))  
    key=bound_keys[ind]
    pick_keys=[key]
    prev_fkeys=set()
    
    # non-corner vertices
    if mesh.vertex_degree(key)>2: 
        f_keys=mesh.vertex_faces(key)
        adj_keys=mesh.face_adjacency_vertices(f_keys[0], f_keys[1])
        next_key=list(set(adj_keys)-set(pick_keys))[0]
        pick_keys.append(next_key) 
        prev_fkeys.update(f_keys)

        while next_key not in bound_keys:
            f_keys=mesh.vertex_faces(next_key)
            f_keys=list(set(f_keys)-prev_fkeys)
            adj_keys=mesh.face_adjacency_vertices(f_keys[0], f_keys[1])
            next_key=list(set(adj_keys)-set(pick_keys))[0]
            pick_keys.append(next_key) 
            prev_fkeys.update(f_keys)
    
    # corner vertices
    elif mesh.vertex_degree(key)==2:
        f_keys=mesh.vertex_faces(key)
        next_key=mesh.face_vertex_ancestor(f_keys[0], key)  # one way of moving on the boundary!
        pick_keys.append(next_key)
        prev_fkeys.update(f_keys)

        while mesh.vertex_degree(next_key)!=2:
            f_keys=mesh.vertex_faces(next_key)
            f_keys=list(set(f_keys)-prev_fkeys)
            next_key=mesh.face_vertex_ancestor(f_keys[0], next_key)
            pick_keys.append(next_key)
            prev_fkeys.update(f_keys)

    # mesh plotter with highlighted path
    plotter = MeshPlotter(mesh, figsize=(8, 5))
    plotter.draw_vertices(text='key', fontsize=10.0, radius=0.02)
    plotter.draw_edges()
    plotter.highlight_path(pick_keys, edgecolor=(255, 0, 0), edgewidth=2.0)

    return pick_keys, plotter
        if not mesh.is_vertex_on_boundary(n):
            previous = index
            index = n
            break

    while True:
        path.append(index)
        if mesh.is_vertex_on_boundary(index):
            break
        neighbors = mesh.vertex_neighbors(index, ordered=True)
        i = neighbors.index(previous)
        previous = index
        index = neighbors[i + 2]

    return path


# Test

start = 3
path = TraverseMesh(mesh, start)
print(path)

plotter = MeshPlotter(mesh, figsize=(4, 4))
plotter.draw_vertices(radius=0.4,
                      text='key',
                      keys=path,
                      facecolor=(100, 100, 0))
plotter.draw_edges()
plotter.draw_faces()
plotter.show()
示例#9
0
    fpre = mesh.get_edges_attribute('fpre')
    lpre = mesh.get_edges_attribute('lpre')
    linit = mesh.get_edges_attribute('linit')
    E = mesh.get_edges_attribute('E')
    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):
示例#10
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), (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)

    area = sum(mesh.face_area(fkey)
               for fkey in mesh.faces()) / mesh.number_of_faces()
    print(area)

    for fkey in mesh.faces():
        print(len(mesh.face_vertices(fkey)))

    finer = trimesh_remesh_triangle(mesh, target=area / 10.0)
    print(finer, key)

    plotter = MeshPlotter(finer, figsize=(10, 7))
    plotter.draw_edges()
    plotter.show()
示例#11
0
import compas
from compas.datastructures import Mesh
from compas_plotters import MeshPlotter

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

plotter = MeshPlotter(mesh, figsize=(12, 7.5))
plotter.draw_vertices(text={
    vertex: str(mesh.vertex_degree(vertex))
    for vertex in mesh.vertices()
},
                      radius=0.2)
plotter.draw_faces()
plotter.show()
示例#12
0
# ==============================================================================
# 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
# ==============================================================================

cablenet.to_json(FILE_O)
示例#13
0
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()
示例#14
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()})
HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, 'data')
FILE = os.path.join(DATA, 'faces.obj')
mesh = Mesh.from_obj(FILE)

# set random boundary vertex as start
deg3_vertices = []
for key in mesh.vertices():
    if mesh.vertex_degree(key) == 3:
        deg3_vertices.append(key)

start_vertex = random.choice(deg3_vertices)

# compute straight path
path = get_straight_path(mesh, start_vertex)

# visualize mesh, vertices and path
plotter = MeshPlotter(mesh, figsize=(16, 10))
plotter.draw_faces()
plotter.draw_edges()
plotter.draw_vertices(text='key', radius=0.15)
plotter.draw_vertices(facecolor=(0, 255, 255),
                      text='key',
                      keys=path[:1],
                      radius=0.2)
plotter.draw_vertices(facecolor=(255, 0, 255),
                      text='key',
                      keys=path[1:],
                      radius=0.2)
plotter.show()
示例#16
0
    polylines = []
    control_points = []
    for streamline in streamsystem.streamlines:
        polylines.append({
            'points': streamline.polyline.points,
            'color': (0, 0, 255)
        })

        for xyz in streamline.polyline.points:
            control_points.append({
                'pos': xyz,
                'facecolor': (255, 255, 255),
                'radius': 0.03
            })

    plotter = MeshPlotter(mesh, figsize=(12, 9))
    plotter.draw_faces(keys=umbilic_keys, facecolor=(255, 0, 0))
    # plotter.draw_edges(color=(10, 10, 10))
    # plotter.draw_faces(keys=not_umbilic_keys)
    plotter.draw_lines(lines)
    # plotter.draw_points([{'pos': closest_pt, 'facecolor': (0, 255, 0), 'radius': 0.02},
    # 					{'pos': test_pt, 'facecolor': (0, 0, 255), 'radius': 0.02}
    # 					]
    # 					)

    # plotter.draw_points(control_points)
    plotter.draw_polylines(polylines)

    plotter.show()
示例#17
0
文件: join.py 项目: itaycsguy/compas
    Returns
    -------
    mesh
        The joined and welded mesh.

    """
    return mesh_weld(meshes_join(meshes, cls=cls), precision=precision)


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

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.datastructures import mesh_weld
    from compas_plotters import MeshPlotter

    vertices = [[0, 0, 0], [0.04, 0, 0], [1.0, 0, 0], [1.0, 1.0, 0], [0, 1.0, 0]]
    faces = [[0, 1, 2, 3, 4]]

    mesh = Mesh.from_vertices_and_faces(vertices, faces)
    mesh = mesh_weld(mesh, precision='1f')

    plotter = MeshPlotter(mesh, figsize=(10, 7))
    plotter.draw_vertices(text={key: "{:.3f}".format(mesh.vertex[key]['x']) for key in mesh.vertices()}, radius=0.03)
    plotter.draw_edges()
    plotter.show()
示例#18
0
    attr['y'] = y
    attr['z'] = z

# 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

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 = MeshPlotter(mesh, figsize=(6, 4))
plotter.draw_vertices(facecolor=facecolor, radius=0.5)
plotter.draw_faces()
plotter.show()
示例#19
0
# ==============================================================================
# Post-process
# ==============================================================================

postprocess(unrolled_SOUTH)
postprocess(unrolled_WEST)
postprocess(unrolled_NW)
postprocess(unrolled_NE)
postprocess(unrolled_EAST)

# ==============================================================================
# Visualize
# ==============================================================================

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

mesh = unrolled_SOUTH[0]
bbox = oriented_bounding_box_xy_numpy(mesh.get_vertices_attributes('xyz'))
points = []
lines = []
for index, (x, y) in enumerate(bbox[0]):
    point = Point(x, y, 0)
    points.append({
        'pos': point,
        'radius': 0.01,
    })
for u, v in pairwise(bbox[0] + bbox[0][:1]):
    lines.append({'start': u, 'end': v, 'width': 0.1})

plotter.mesh = mesh
示例#20
0
    'color': (1.0, 0.0, 0.0)
}]
for u, v in parallel:
    if u not in start and v not in start:
        arrows.append({
            'start': cablenet.vertex_coordinates(u),
            'end': cablenet.vertex_coordinates(v),
            'color': (0.0, 0.0, 0.0)
        })

facecolor = {
    key: i_to_blue(index / len(faces))
    for index, key in enumerate(faces)
}

plotter = MeshPlotter(cablenet, figsize=(10, 7))
plotter.defaults['vertex.radius'] = 0.04
plotter.defaults['edge.width'] = 0.5
plotter.draw_edges(width={key: 3.0 for edges in cables for key in edges})
plotter.draw_vertices(radius={key: 0.06
                              for key in chain},
                      facecolor=vertexcolor)
plotter.draw_arrows2(arrows)
plotter.draw_faces(facecolor=facecolor,
                   keys=faces,
                   text={key: str(index)
                         for index, key in enumerate(faces)})
plotter.show()

# ==============================================================================
# Export
示例#21
0
    #             boundary.append(boundary_edges[boundary[-1]])
    #             boundary_edges.pop(boundary[-2])
    #         boundaries.append(boundary[: -1])
    #     return boundaries


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

if __name__ == '__main__':

    import compas
    from compas.datastructures import Network
    from compas_plotters import MeshPlotter

    network = Network.from_obj(compas.get('lines.obj'))
    lines = network.to_lines()

    mesh = BaseMesh.from_lines(lines, delete_boundary_face=False)

    mesh.summary()

    plotter = MeshPlotter(mesh, figsize=(8, 5))

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

    plotter.show()
from compas_tna.diagrams import ForceDiagram
from compas_tna.equilibrium import horizontal_nodal
from compas_plotters import MeshPlotter

FILE = compas_tna.get('tutorial/boundaryconditions.json')

form = FormDiagram.from_json(FILE)
force = ForceDiagram.from_formdiagram(form)

horizontal_nodal(form, force, kmax=100)

# ==============================================================================
# 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.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.face_attribute(key, '_is_loaded')
})

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

plotter.draw_edges()
            for fkey in cluster.faces_keys:
                facedict[fkey] = color

        facecolors = sorted(facedict.items(), key=lambda x: x[0])
        facecolors = [x[1] for x in facecolors]
        plotter.facecollection.set_facecolors(facecolors)

        if export:
            plotter.save(THERE + '{}_{}.png'.format(time(), k))
        plotter.update(pause=0.50)

    # ==========================================================================
    # Set up Plotter
    # ==========================================================================

    plotter = MeshPlotter(mesh, figsize=(12, 9))
    plotter.draw_lines(lines)
    plotter.draw_faces()

    callback = partial(callback,
                       plotter=plotter,
                       filepath=THERE,
                       export=EXPORT_PNG)

    # ==========================================================================
    # Set up K-Means algorithm
    # ==========================================================================

    faces = make_faces(str_mesh, vector_tag, weight=False)
    clusters = furthest_init(NUM, faces, callback=None)
示例#24
0
    DRAW_FACES = False
    DRAW_VF = False

    # ==========================================================================
    # Import mesh
    # ==========================================================================

    mesh = Mesh()
    mesh = Mesh.from_json(HERE)
    mesh_unify_cycles(mesh)

    # ==========================================================================
    # Visualization
    # ==========================================================================

    plotter = MeshPlotter(mesh, figsize=(12, 9))

    if DRAW_EDGES:
        plotter.draw_edges(color=(100, 100, 100), width=0.1)

    if DRAW_FACES:
        plotter.draw_faces()

    # ==========================================================================
    # Instantiate StructuralMesh()
    # ==========================================================================

    str_mesh = StructuralMesh(mesh)

    # ==========================================================================
    # Create closest-point seeds
示例#25
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()
示例#26
0
    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()
示例#27
0
# ==============================================================================
# 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()

# ==============================================================================
# Export
# ==============================================================================

cablenet.to_json(FILE_O)
示例#28
0
#     return voronoi

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

if __name__ == "__main__":

    from compas.datastructures import Mesh
    from compas.geometry import pointcloud_xy
    from compas_plotters import MeshPlotter

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

    delaunay = Mesh.from_vertices_and_faces(points, faces)

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

    facecolor = {
        fkey: (255, 0, 0) if delaunay.face_normal(fkey)[2] > 0 else (0, 0, 255)
        for fkey in delaunay.faces()
    }

    plotter.draw_vertices(keys=list(delaunay.vertices_on_boundary()),
                          radius=0.5)
    plotter.draw_faces(facecolor=facecolor)
    plotter.draw_edges(keys=list(delaunay.edges_on_boundary()))
    plotter.show()
示例#29
0
    from compas.datastructures import Mesh
    from compas.datastructures import mesh_quads_to_triangles

    from compas_plotters import MeshPlotter

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

    points = mesh.vertices_attributes('xyz')
    points[:] = [[x, y, 0] for x, y, z in points]

    mesh_quads_to_triangles(target)

    pulled = trimesh_pull_points_numpy(target, points)

    plotter = MeshPlotter(mesh, figsize=(8, 5))
    plotter.defaults['vertex.fontsize'] = 6
    plotter.draw_vertices(text={
        key: "{:.1f}".format(attr['z'])
        for key, attr in mesh.vertices(True)
    },
                          radius=0.08)
    plotter.draw_faces()
    plotter.draw_points([{
        'pos': [x, y, z],
        'text': "{:.1f}".format(z),
        'radius': 0.08,
        'facecolor': '#00ff00',
        'fontsize': 6
    } for x, y, z in pulled])
示例#30
0
from compas.datastructures import Mesh
from compas.utilities import geometric_key
from compas_plotters import MeshPlotter
from compas.geometry import delaunay_triangulation

points = [[2.994817685045075, 12.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]]

vertices, faces = delaunay_triangulation(points, 'q30a1D')

mesh = Mesh.from_vertices_and_faces(vertices, faces)

plotter = MeshPlotter(mesh, figsize=(8, 5))
plotter.defaults['vertex.fontsize'] = 6
plotter.draw_faces()
plotter.draw_vertices(text='key')
plotter.show()