Example #1
0
def mesh_draw_edges(mesh,
                    keys=None,
                    color=None,
                    layer=None,
                    clear_layer=False,
                    redraw=True):
    """Draw a selection of edges of the mesh.

    Parameters
    ----------
    keys : list
        A list of edge keys (as uv pairs) identifying which edges to draw.
        Default is to draw all edges.
    color : str, tuple, dict
        The color specififcation for the edges.
        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 faces, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default face color (``self.defaults['face.color']``).
        Default is use the color of the parent layer.
    layer : str (None)
        The layer in which the edges are drawn.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    redraw : bool (True)
        Redraw the view after adding the edges.

    Notes
    -----
    All edges are named using the following template:
    ``"{}.edge.{}-{}".fromat(self.mesh.attributes['name'], u, v)``.
    This name is used afterwards to identify edges of the mesh in the Rhino model.

    Examples
    --------
    >>> mesh_draw_edges(mesh)
    >>> mesh_draw_edges(mesh, color='#ff0000')
    >>> mesh_draw_edges(mesh, color=(255, 0, 0))
    >>> mesh_draw_edges(mesh, keys=mesh.edges_on_boundary())
    >>> mesh_draw_edges(mesh, color={(u, v): '#00ff00' for u, v in mesh.edges_on_boundary()})

    """
    artist = MeshArtist(mesh)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    artist.clear_edges()
    guids = artist.draw_edges(color=color)

    if redraw:
        artist.redraw()

    return guids
Example #2
0
def mesh_draw(mesh,
              layer=None,
              clear_layer=False,
              clear_vertices=False,
              clear_faces=False,
              clear_edges=False,
              show_faces=True,
              show_vertices=False,
              show_edges=False,
              vertexcolor=None,
              edgecolor=None,
              facecolor=None):
    """
    Draw a mesh object in Rhino.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        The mesh object.
    layer : str (None)
        The layer to draw in.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the drawing layer.
    show_faces : bool (True)
        Draw the faces.
    show_vertices : bool (False)
        Draw the vertices.
    show_edges : bool (False)
        Draw the edges.
    vertexcolor : str, tuple, list, dict (None)
        The vertex color specification.
        Default is to use the color of the parent layer.
    edgecolor : str, tuple, list, dict (None)
        The edge color specification.
        Default is to use the color of the parent layer.
    facecolor : str, tuple, list, dict (None)
        The face color specification.
        Default is to use the color of the parent layer.

    Notes
    -----
    Colors can be specifiedin different ways:

    * str: A hexadecimal color that will be applied to all elements subject to the specification.
    * tuple, list: RGB color that will be applied to all elements subject to the specification.
    * dict: RGB or hex color dict with a specification for some or all of the related elements.

    Notes
    -----
    RGB colors specified as values between 0 and 255, should be integers.
    RGB colors specified as values between 0.0 and 1.0, should be floats.

    """
    artist = MeshArtist(mesh)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()
    if clear_edges:
        artist.clear_edges()
    if clear_faces:
        artist.clear_faces()

    if show_faces:
        artist.draw_faces(color=facecolor)
    if show_edges:
        artist.draw_edges(color=edgecolor)
    if show_vertices:
        artist.draw_vertices(color=vertexcolor)

    artist.redraw()
Example #3
0
    pointsconduit.redraw(k)
    linesconduit.redraw(k)

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


pointsconduit = PointsConduit(radius=10, refreshrate=5)
linesconduit = LinesConduit(refreshrate=5)

with pointsconduit.enabled():
    with linesconduit.enabled():
        xyz = smooth_centroid_cpp(vertices,
                                  adjacency,
                                  fixed,
                                  kmax=kmax,
                                  callback=callback)

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

artist.clear_edges()
artist.draw_vertices()
artist.draw_edges()
artist.redraw()