示例#1
0
def volmesh_draw_faces(volmesh,
                       keys=None,
                       color=None,
                       layer=None,
                       clear_layer=False,
                       redraw=True):
    """Draw the faces of a volmesh.

    Parameters
    ----------
    volmesh : compas.datastructures.VolMesh
        A volmesh object.
    keys : list (None)
        A list of edge keys identifying which faces to draw.
        Default is to draw all faces.
    color : str, tuple, dict (None)
        The color specififcation for the faces.
        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 vertex color (``self.defaults['vertex.color']``).
        Default is use the color of the parent layer.
    layer : str (None)
        The layer in which the faces 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 faces.

    Examples
    --------
    >>> volmesh_draw_faces(volmesh)
    >>> volmesh_draw_faces(volmesh, keys=volmesh.faces_on_boundary())
    >>> volmesh_draw_faces(volmesh, color='#00ff00')
    >>> color = {key: (('#ff0000') if volmesh.vertex_is_on_boundary(key) else ('#00ff00')) for key in volmesh.faces()}
    >>> volmesh_draw_faces(volmesh, color=color)

    See Also
    --------
    * compas_rhino.VolMeshArtist

    """
    artist = VolMeshArtist(volmesh)
    artist.layer = layer
    if clear_layer:
        artist.clear_layer()
    artist.clear_faces()
    artist.draw_faces(color=color)
    if redraw:
        artist.redraw()
示例#2
0
def volmesh_draw(volmesh,
                 layer=None,
                 clear_layer=False,
                 vertexcolor=None,
                 edgecolor=None,
                 facecolor=None):
    """Draw a volmesh.

    Parameters
    ----------
    volmesh : compas.datastructures.VolMesh
        A volmesh object.
    layer : str (None)
        The layer to draw in.
        Default is to draw in the current layer.
    clear_layer : bool (False)
        Clear the current layer.
    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.

    Examples
    --------
    >>> volmesh_draw(volmesh)
    >>> volmesh_draw(volmesh, layer='SomeLayer')
    >>> volmesh_draw(volmesh, clear_layer=True)
    >>> volmesh_draw(volmesh, vertexcolor='#ff0000')
    >>> volmesh_draw(volmesh, edgecolor=(0, 255, 0))
    >>> volmesh_draw(volmesh, facecolor={key: (0.0, 0.0, 0.5) for key in volmesh.faces()})

    See Also
    --------
    * compas_rhino.VolMeshArtist

    """
    artist = VolMeshArtist(volmesh)
    artist.layer = layer
    if clear_layer:
        artist.clear_layer()
    artist.clear()
    artist.draw_vertices(color=vertexcolor)
    artist.draw_edges(color=edgecolor)
    artist.draw_faces(color=facecolor)
    artist.redraw()
示例#3
0

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

if __name__ == "__main__":

    import compas

    from compas.datastructures import VolMesh
    from compas_rhino.artists import VolMeshArtist

    volmesh = VolMesh.from_obj(compas.get('boxes.obj'))

    artist = VolMeshArtist(volmesh, layer='VolMeshArtist')

    artist.clear_layer()

    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)
for vkey in formdiagram.nodes():
    x = formdiagram.node_attribute(vkey, 'x')
    formdiagram.node_attribute(vkey, 'x', x + width * offset)

# ------------------------------------------------------------------------------
# 3. reciprocate
# ------------------------------------------------------------------------------
volmesh_reciprocate(forcediagram,
                    formdiagram,
                    kmax=500,
                    weight=1,
                    edge_min=0.5,
                    edge_max=20,
                    tolerance=0.01)

force_artist = VolMeshArtist(forcediagram, layer=force_layer)
form_artist = NetworkArtist(formdiagram, layer=form_layer)

scaled_cell_artist = MeshArtist(None, layer=force_layer)
prism_artist = MeshArtist(None, layer=force_layer)

force_artist.draw_faces()
form_artist.draw_edges()

# ------------------------------------------------------------------------------
# 4. draw unified diagram
# ------------------------------------------------------------------------------

while True:

    rs.EnableRedraw(True)
示例#5
0
from compas_rhino.utilities import volmesh_from_polysurfaces

from compas_3gs.diagrams import ForceVolMesh

from compas_rhino.artists import VolMeshArtist

try:
    import rhinoscriptsyntax as rs
except ImportError:
    compas.raise_if_ironpython()

# ------------------------------------------------------------------------------
# 1. make vomesh from rhino polysurfaces
# ------------------------------------------------------------------------------
layer = 'force_volmesh'

guids = rs.GetObjects("select polysurfaces", filter=rs.filter.polysurface)
rs.HideObjects(guids)

forcediagram = ForceVolMesh()
forcediagram = volmesh_from_polysurfaces(forcediagram, guids)
forcediagram.layer = layer
forcediagram.attributes['name'] = layer

artist = VolMeshArtist(forcediagram)

artist.draw_vertices()
artist.draw_faces()
artist.draw_vertexlabels()
示例#6
0
 def draw_vertex_labels(self, **kwattr):
     artist = VolMeshArtist(self)
     artist.draw_vertexlabels(**kwattr)
示例#7
0
 def draw_edge_labels(self, **kwattr):
     artist = VolMeshArtist(self)
     artist.draw_edgelabels(**kwattr)
示例#8
0
 def clear_faces(self, **kwattr):
     artist = VolMeshArtist(self)
     artist.clear_faces(**kwattr)
示例#9
0
 def draw_vertices(self, **kwattr):
     artist = VolMeshArtist(self)
     artist.draw_vertices(**kwattr)
示例#10
0
 def clear_edges(self, **kwattr):
     artist = VolMeshArtist(self, **kwattr)
     artist.clear_edges(**kwattr)
示例#11
0
 def draw_edges(self, **kwattr):
     artist = VolMeshArtist(self, **kwattr)
     artist.draw_edges(**kwattr)
示例#12
0
 def clear(self):
     artist = VolMeshArtist(self)
     # self.clear_cell_labels()
     artist.clear()
dual_volmesh = volmesh_dual_volmesh(volmesh, cls=FormVolMesh)
dual_volmesh.layer = dual_layer
dual_volmesh.attributes['name'] = dual_layer

# move dual_network
offset = 3
width = dual_volmesh.bounding_box()[1][0] - dual_volmesh.bounding_box()[0][0]
for vkey in dual_volmesh.vertices():
    x = dual_volmesh.vertex_attribute(vkey, 'x')
    dual_volmesh.vertex_attribute(vkey, 'x', x + width * offset)

# ------------------------------------------------------------------------------
# 3. visualise diagrams
# ------------------------------------------------------------------------------
force_artist = VolMeshArtist(volmesh)
form_artist = VolMeshArtist(dual_volmesh)

# draw volmesh cell labels and dual_volmesh vertex labels
cell_c_dict = get_index_colordict(list(volmesh.cells()))

# draw volmesh
force_artist.draw_edges()
force_artist.draw_celllabels(color=cell_c_dict)

# draw dual volmesh
form_artist.draw_faces()
form_artist.draw_vertexlabels(color=cell_c_dict)

# draw directed volmesh halffaces and directed dual_volmesh edges
uv_c_dict = get_index_colordict(list(dual_volmesh.edges()))
    compas.raise_if_ironpython()

# ------------------------------------------------------------------------------
# 1. make vomesh from rhino polysurfaces
# ------------------------------------------------------------------------------
layer_force = 'force_volmesh'

guids = rs.GetObjects("select polysurfaces", filter=rs.filter.polysurface)
rs.HideObjects(guids)

forcediagram = ForceVolMesh()
forcediagram = volmesh_from_polysurfaces(forcediagram, guids)
forcediagram.layer = layer_force
forcediagram.attributes['name'] = layer_force

force_artist = VolMeshArtist(forcediagram, layer=layer_force)

force_artist.draw_faces()

# ------------------------------------------------------------------------------
# 2. make dual network (form diagram)
# ------------------------------------------------------------------------------
layer_form = 'form_network'

formdiagram = volmesh_dual_network(forcediagram, cls=FormNetwork)
formdiagram.layer = layer_form
formdiagram.attributes['name'] = layer_form

# move dual_network
offset = 2
width = formdiagram.bounding_box()[1][0] - formdiagram.bounding_box()[0][0]