Ejemplo n.º 1
0
def mesh_draw_edge_labels(mesh, attr_name=None, layer=None, color=None, formatter=None):
    """Display labels for the edges of a mesh.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        A mesh object.
    attr_name : str (None)
        The name of the attribute value to display in the label.
        Default is to display the edge keys.
    layer : str (None)
        The layer to draw in.
        Default is to draw in the current layer.
    color : str, tuple, list, dict (None)
        The color specififcation for the labels.
        Colors should be specified in the form of a string (hex colors) or as a tuple of RGB components.
        To apply the same color to all face labels, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default edge color (``self.defaults['edge.color']``).
        Default is to inherit color from the parent layer.
    formatter : callable (None)
        A formatting function.
        Defaults to the built-in ``str`` function.

    Notes
    -----
    The labels are named using the following template:
    ``"{}.edge.label.{}".format(self.mesh.name, key)``.
    This name is used afterwards to identify edges of the mesh in the Rhino model.

    Examples
    --------
    >>>

    """

    if not attr_name:
        attr_name = 'key'

    if formatter:
        assert callable(formatter), 'The provided formatter is not callable.'
    else:
        formatter = str

    text = {}
    for index, (u, v, attr) in enumerate(mesh.vertices(True)):
        if 'key' == attr_name:
            value = '{}-{}'.format(u, v)
        elif 'index' == attr_name:
            value = index
        else:
            value = attr[attr_name]
        text[(u, v)] = formatter(value)

    artist = MeshArtist(mesh)
    artist.layer = layer
    artist.clear_edgelabels()
    artist.draw_edgelabels(text=text, color=color)
    artist.redraw()
Ejemplo n.º 2
0
 def draw_edgelabels(self, **kwattr):
     artist = MeshArtist(self)
     artist.draw_edgelabels(**kwattr)
Ejemplo n.º 3
0
    from compas_rhino.artists import MeshArtist

    poly = Polyhedron.generate(12)

    mesh = Mesh.from_vertices_and_faces(poly.vertices, poly.faces)

    artist = MeshArtist(mesh)

    artist.clear()

    artist.draw_vertices()
    artist.redraw(0.0)

    artist.draw_vertexlabels()
    artist.redraw(1.0)

    artist.draw_faces()
    artist.redraw(1.0)

    artist.draw_facelabels()
    artist.redraw(1.0)

    artist.draw_edges()
    artist.redraw(1.0)

    artist.draw_edgelabels()
    artist.redraw(1.0)

    print(artist.save(os.path.join(compas.TEMP, 'test4.png')))
Ejemplo n.º 4
0
vertices = [[0.5, 0.0, 0.0], [0.0, 1.0, 0.0], [-0.5, 0.0, 0.0],
            [1.0, 1.0, 0.0]]

faces = [[0, 1, 2], [1, 0, 3]]

my_mesh = Mesh.from_vertices_and_faces(vertices, faces)

artist = MeshArtist(my_mesh, layer="00_my_first mesh")

artist.clear_layer()
artist.draw_vertices()
artist.draw_faces()
artist.draw_edges()
artist.draw_vertexlabels()
artist.draw_facelabels()
artist.draw_edgelabels()

# iterate through the mesh
# for key,attr in my_mesh.vertices(True):
#     print (key, attr['x'], attr['y'], attr['z'])

# for key in my_mesh.faces():
#     print(key)

# for key in my_mesh.edges():
#     print(key)

# get topology information
vertex = 0
#print (my_mesh.vertex_neighbors(vertex , ordered=False))
#print (my_mesh.vertex_degree(vertex))