コード例 #1
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()
コード例 #2
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()
コード例 #3
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
コード例 #4
0
    def draw_mesh_faces(mesh):
        fkeys_nodraw = [
            fkey for fkey in mesh.faces() if mesh.face_area(fkey) <= 0
        ]
        fkeys = list(set(list(mesh.faces())) - set(fkeys_nodraw))

        artist = MeshArtist(mesh)
        artist.layer = '3GS::Skeleton'
        artist.draw_faces(faces=fkeys, join_faces=True)
コード例 #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
# ==============================================================================

polylines = []
for points in pointsets:
    points = [Point(*point) for point in points]
    polyline = Polyline(points)
    polylines.append(polyline)

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

meshartist = MeshArtist(None)

meshartist.mesh = Mesh.from_vertices_and_faces(*A)
meshartist.layer = "CGAL::Intersections::A"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#222222'))

meshartist.mesh = Mesh.from_vertices_and_faces(*B)
meshartist.layer = "CGAL::Intersections::B"
meshartist.clear_layer()
meshartist.draw_faces(join_faces=True, color=hex_to_rgb('#888888'))

polylineartist = PolylineArtist(None, layer="CGAL::Intersections::Polylines")
polylineartist.clear_layer()
pointartist = PointArtist(None, layer='CGAL::Intersections::Points')
pointartist.clear_layer()

for polyline in polylines:
    polylineartist.primitive = polyline
コード例 #9
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()
コード例 #10
0
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for visualisation
artist = MeshArtist(mesh, layer='SubdModeling::Control')

# draw the control mesh
draw_mesh()

# allow the user to change the attributes of the vertices
while True:
    keys = VertexSelector.select_vertices(mesh)
    if not keys:
        break
    VertexModifier.update_vertex_attributes(mesh, keys)
    draw_mesh()

# make a subd mesh (using catmullclark)
subd = mesh_subdivide(mesh,
                      scheme='catmullclark',
                      k=4,
                      fixed=mesh.vertices_where({'is_fixed': True}))

# give the subdivision mesh a different name
subd.attributes['name'] = 'Mesh'

# draw the result
artist.mesh = subd
artist.layer = 'SubdModeling::Mesh'
artist.clear_layer()
artist.draw_mesh()
コード例 #11
0
]

STRIPS = SOUTH + SW + WEST + NW + NORTH + RING

# ==============================================================================
# Visualise
# ==============================================================================

ARTIST = MeshArtist(FABRIC, layer="Fabric")
ARTIST.clear_layer()

# INTRADOS

ARTIST.mesh = IDOS

ARTIST.layer = "Fabric::Intrados"

for i, strip in enumerate(STRIPS):
    guid = ARTIST.draw_faces(keys=strip, join_faces=True)
    color = (255, 128, 128) if i % 2 else (255, 0, 0)
    rs.ObjectColor(guid, color)

ARTIST.layer = "Fabric::Normals"
ARTIST.draw_facenormals(color=(255, 0, 0), scale=0.05)

# EXTRADOS

ARTIST.mesh = EDOS

ARTIST.layer = "Fabric::Extrados"
コード例 #12
0
mesh = Mesh.from_json(FILE_I)

idos = mesh.copy()
edos = mesh.copy()

for vertex in mesh.vertices():
    point = mesh.vertex_coordinates(vertex)
    normal = mesh.vertex_normal(vertex)
    thickness = 0.10
    idos.vertex_attributes(
        vertex, 'xyz',
        add_vectors(point, scale_vector(normal, +0.5 * thickness)))
    edos.vertex_attributes(
        vertex, 'xyz',
        add_vectors(point, scale_vector(normal, -0.5 * thickness)))

idos.to_json(FILE_O1)
edos.to_json(FILE_O2)

artist = MeshArtist(None)

artist.mesh = idos
artist.layer = "RV2::Idos"
artist.clear_layer()
artist.draw_faces(color=(255, 0, 0))

artist.mesh = edos
artist.layer = "RV2::Edos"
artist.clear_layer()
artist.draw_faces(color=(0, 0, 255))
コード例 #13
0
]

STRIPS = SOUTH + SW + WEST + NW + NORTH + RING

# ==============================================================================
# Visualise
# ==============================================================================

ARTIST = MeshArtist(FABRIC, layer="Fabric")
ARTIST.clear_layer()

# INTRADOS

ARTIST.mesh = IDOS

ARTIST.layer = "Fabric::Intrados"

for name, panel in [('SOUTH', SOUTH), ('WEST', WEST), ('NORTH', NORTH),
                    ('RING', RING)]:
    for strip, faces in enumerate(panel):
        ARTIST.layer = "Fabric::Intrados::{}-{}".format(
            name,
            str(strip).zfill(2))
        color = (255, 0, 0)
        points = []
        fkeys = []
        for fkey in faces:
            origin = IDOS.face_centroid(fkey)
            normal = IDOS.face_normal(fkey, unitized=True)
            plane = origin, normal
            if SHELL.has_vertex(fkey):
コード例 #14
0
mesh.update_default_vertex_attributes({'is_fixed': False})

# make an artist for visualisation
artist = MeshArtist(mesh, layer='InteractiveSubdivision::Cage')

# draw the control mesh
draw()

# allow the user to change the attributes of the vertices
while True:
    keys = VertexSelector.select_vertices(mesh)
    if not keys:
        break
    VertexModifier.update_vertex_attributes(mesh, keys)
    draw()

# make a subd mesh (using catmullclark)
subd = mesh_subdivide(mesh,
                      scheme='catmullclark',
                      k=4,
                      fixed=mesh.vertices_where({'is_fixed': True}))

# give the subdivision mesh a different name
subd.attributes['name'] = 'Mesh'

# draw the result
artist.mesh = subd
artist.layer = 'InteractiveSubdivision::Mesh'
artist.clear_layer()
artist.draw_mesh()