Beispiel #1
0
def network_draw_vertices(network,
                          keys=None,
                          color=None,
                          layer=None,
                          clear_layer=False,
                          redraw=True):
    """Draw a selection of vertices of a network.

    Parameters
    ----------
    keys : list (None)
        A list of vertex keys identifying which vertices to draw.
        Default is to draw all vertices.
    color : str, tuple, dict (None)
        The color specififcation for the vertices.
        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 vertices, provide a single color specification.
        Individual colors can be assigned using a dictionary of key-color pairs.
        Missing keys will be assigned the default vertex color (``self.defaults['color.vertex']``).
        Default is to inherit the color from the layer.
    layer : str (None)
        The layer in which the vertices 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 vertices.

    Notes
    -----
    The vertices are named using the following template:
    ``"{}.vertex.{}".format(self.network.name, key)``.
    This name is used afterwards to identify vertices of the networkin the Rhino model.

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

    """
    artist = NetworkArtist(network)
    artist.layer = layer
    if clear_layer:
        artist.clear_layer()
    artist.clear_vertices()
    artist.draw_vertices(keys=keys, color=color)
    if redraw:
        artist.redraw()
Beispiel #2
0
from itertools import combinations

from compas.datastructures import Network
from compas.utilities import linspace, meshgrid
from compas_rhino.artists import NetworkArtist

X, Y = meshgrid(linspace(0, 10, 10), linspace(0, 5, 5))

points = []
for z in linspace(0, 3, 3):
    for xs, ys in zip(X, Y):
        for x, y in zip(xs, ys):
            points.append([x, y, z])

network = Network()

for point in points:
    network.add_node(x=point[0], y=point[1], z=point[2])

for a, b in combinations(network.nodes(), 2):
    if network.node_attribute(a, 'z') != network.node_attribute(b, 'z'):
        network.add_edge(a, b)

artist = NetworkArtist(network, layer="ITA20::Network")
artist.clear_layer()
artist.draw_nodes()
artist.draw_edges()
Beispiel #3
0
def network_draw(network,
                 layer=None,
                 clear_layer=False,
                 clear_vertices=True,
                 clear_edges=True,
                 vertexcolor=None,
                 edgecolor=None):
    """Draw a network data structure in Rhino.

    Parameters
    ----------
    network : compas.datastructures.Network
        A network object.
    layer : str (None)
        The layer to draw in.
        Default is the current layer.
    clear_layer : bool (False)
        Clear the layer.
    vertexcolor : list, tuple, str, dict (None)
        The color specification for the vertices.
        * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``).
        * str: hex color (e.g. ``'#ff0000'``).
        * dict: dictionary of hex or rgb colors.
    edgecolor : list, tuple, str, dict (None)
        The color specification for the edges.
        * list, tuple: rgb color, with color specs between 0 and 255 (e.g. ``(255, 0, 0)``).
        * str: hex color (e.g. ``'#ff0000'``).
        * dict: dictionary of hex or rgb color.

    Notes
    -----
    * Any network objects with the same name that are already present in the
      model will be deleted by this function.
    * To also clear the entire layer the network will be drawn on, for
      example, if you have a dedicated network layer, use the ``clear_layer`` flag as well.

    See Also
    --------
    * :func:`network_draw_vertices`
    * :func:`network_draw_edges`

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

    """
    artist = NetworkArtist(network)
    artist.layer = layer

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()

    if clear_edges:
        artist.clear_edges()

    artist.draw_vertices(color=vertexcolor)
    artist.draw_edges(color=edgecolor)
    artist.redraw()
# ------------------------------------------------------------------------------

while True:

    rs.EnableRedraw(True)

    alpha = rs.GetReal('unified diagram scale', minimum=0.01, maximum=1.0)

    if alpha is None:
        break

    if not alpha:
        break

    force_artist.clear_layer()
    form_artist.clear_layer()

    # 1. get colors ------------------------------------------------------------
    hf_color = (0, 0, 0)

    uv_c_dict = get_force_colors_uv(forcediagram, formdiagram, gradient=True)
    hf_c_dict = get_force_colors_hf(forcediagram,
                                    formdiagram,
                                    uv_c_dict=uv_c_dict)

    # 2. compute unified diagram geometries ------------------------------------
    # halffaces, prism_faces = volmesh_ud(forcediagram, formdiagram, scale=alpha)
    cells, prisms = volmesh_ud(forcediagram, formdiagram, scale=alpha)

    # 3. draw ------------------------------------------------------------------
    for cell in cells: