def RunCommand(is_interactive):

    #load Derivation and delete last step
    derivation = Derivation.from_json(rhino_UI_utilities.get_json_file_location())

    continue_playback = True
    step_id = 0 
    while(continue_playback):
        #ask user for which step they would like to see
        derivation_last_step_index = derivation.count - 1
        
        step_id = rs.GetInteger("Enter which step to visualize (0 - "+ str(derivation_last_step_index) + " step) (Enter -1 for last step)", step_id, -1, derivation_last_step_index)
        if (step_id == -1): step_id = derivation_last_step_index
        if (step_id == None): break # Allow user to quite the command

        #load the selected model
        model = derivation.get_step(step_id)
        step_id = step_id + 1

        #Visualization 
        artist = MeshArtist(None, layer ='BEAM::Beams_out')
        artist.clear_layer()
        for beam in model.beams:
            artist = MeshArtist(beam.mesh, layer ='BEAM::Beams_out')
            artist.draw_faces(join_faces=True)
        artist.redraw()           
예제 #2
0
파일: mesh.py 프로젝트: yijiangh/compas
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()
예제 #3
0
 def draw_subd(self):
     artist = MeshArtist(self.subd)
     layer = self.settings['layer.subd']
     color = self.settings['color.subd.edges']
     artist.layer = layer
     edges = [edge for edge in self.subd.edges() if not self.subd.is_edge_on_boundary(edge[0], edge[1])]
     guids = artist.draw_edges(edges, color=color)
     self.guid_subd_edge = zip(guids, edges)
     artist.redraw()
예제 #4
0
def mesh_draw_vertices(mesh,
                       keys=None,
                       color=None,
                       layer=None,
                       clear_layer=False,
                       clear_vertices=False,
                       redraw=True):
    """Draw a selection of vertices of the mesh.

    Parameters
    ----------
    mesh : compas.datastructures.Mesh
        A mesh object.
    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['vertex.color']``).
        Default is use the color of the parent 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.mesh.attributes['name'], key)``.
    This name is used afterwards to identify vertices of the meshin the Rhino model.

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

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

    if clear_layer:
        artist.clear_layer()

    if clear_vertices:
        artist.clear_vertices()

    guids = artist.draw_vertices(color=color)

    if redraw:
        artist.redraw()

    return guids
예제 #5
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
예제 #6
0
def subdivide(mesh, guid):
    compas_rhino.delete_object(guid)
    mesh = mesh_subdivide_catmullclark(mesh, k=1)

    artist = MeshArtist(mesh)
    artist.layer = '3GS::Skeleton'
    guid = artist.draw_faces(join_faces=True)
    artist.redraw()

    return mesh, guid[0]
예제 #7
0
def create_sk3_exo(lines, branch_radius=1, node_radius_fac=1, segments=4):
    sk3 = Skeleton3D.from_skeleton_lines(lines)
    sk3.section_seg = segments
    sk3.branch_radius = branch_radius
    sk3.node_radius_fac = node_radius_fac
    sk3.generate_mesh()
    sk3.merge_triangles()

    artist = MeshArtist(sk3)
    artist.layer = '3GS::Skeleton'
    guid = artist.draw_faces(join_faces=True)
    artist.redraw()

    return sk3, guid[0]
예제 #8
0
def main():
    #####################################
    ### NOTE: Run this file in Rhino. ###
    #####################################

    ### --- Load stl
    mesh = Mesh.from_stl(FILE)

    ### --- Get color list
    color_list = get_mesh_face_color_overhang(mesh,
                                              max_angle=85,
                                              mode="adaptive",
                                              infill=False)

    ### --- Create Rhino artist
    artist = MeshArtist(mesh, layer='COMPAS::MeshArtist')
    artist.clear_layer()
    artist.draw_faces(
        color={key: color_list[i]
               for i, key in enumerate(mesh.faces())})
    artist.redraw()
예제 #9
0
    vertices[key][2] -= dz
    fixed.append(key)

# make a conduit for visualisation

edges = list(mesh.edges())
lines = [[vertices[u], vertices[v]] for u, v in edges]

conduit = LinesConduit(lines, refreshrate=5)

# run the smoothing algorithm
# update the mesh
# and display the results

with conduit.enabled():
    smooth_area(vertices,
                faces,
                adjacency,
                fixed=fixed,
                kmax=100,
                callback=callback)

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

artist = MeshArtist(mesh)
artist.draw_faces(join_faces=True)
artist.redraw()
예제 #10
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()
예제 #11
0
    from compas.datastructures import Mesh
    from compas.geometry import Polyhedron

    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)
예제 #12
0
# ==============================================================================
# Process output
# ==============================================================================

polylines = []
for points in pointsets:
    points = [Point(*point)
              for point in points]  # otherwise Polygon throws an error
    polyline = Polyline(points)
    polylines.append(polyline)

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

meshartist = MeshArtist(bunny, layer="CGAL::Slicer::Bunny")
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=(255, 200, 200))
meshartist.redraw()

# this is very slow

polylineartist = PolylineArtist(None, layer="CGAL::Slicer::Slices")
polylineartist.clear_layer()
for polyline in polylines:
    polylineartist.primitive = polyline
    polylineartist.color = (255, 0, 0)
    polylineartist.draw()
polylineartist.redraw()