Exemplo n.º 1
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()
Exemplo n.º 2
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
Exemplo n.º 3
0
X = mesh.vertices_attributes('xyz')
P = mesh.vertices_attributes(['px', 'py', 'pz'])
Q = mesh.edges_attribute('q')

fixed = [
    vertex_index[vertex] for vertex in mesh.vertices_where({'is_anchor': True})
]
edges = [(vertex_index[u], vertex_index[v]) for u, v in mesh.edges()]

# compute equilibrium

X, Q, F, L, R = fd(X, edges, fixed, Q, P)

# update network

for vertex in mesh.vertices():
    index = vertex_index[vertex]
    mesh.vertex_attributes(vertex, 'xyz', X[index])

# visualize result

artist = MeshArtist(mesh, layer="ITA20::L5::FormFinding")
artist.clear_layer()

artist.draw_vertices(color={
    vertex: (255, 0, 0)
    for vertex in mesh.vertices_where({'is_anchor': True})
})
artist.draw_edges()
artist.draw_faces()
Exemplo n.º 4
0
from compas_rhino.selectors import VertexSelector
from compas_rhino.selectors import EdgeSelector

mesh = Mesh.from_json('../cablenet.json')

vertexcolor = {
    key: (255, 0, 0)
    for key in mesh.vertices_where({'is_anchor': True})
}
edgecolor = {key: (255, 0, 0) for key in mesh.edges_where({'is_joint': True})}

artist = MeshArtist(mesh, layer="Cablenet")

artist.clear_layer()
artist.draw_vertices(color=vertexcolor)
artist.draw_edges(color=edgecolor)
artist.redraw()

# select mesh vertices
# update the attributes
# redraw mesh if successful
while True:
    selected = VertexSelector.select_vertices(mesh)
    if not selected:
        break

    if VertexModifier.update_vertex_attributes(mesh, selected):
        artist.clear_layer()
        artist.draw_vertices(color=vertexcolor)
        artist.draw_edges(color=edgecolor)
c = len(set(key_color.values()))
colors = Colormap(list(range(c)), 'rgb')
facecolor = {key: colors(key_color[key]) for key in dual.vertices()}

# the artist for drawing various versions of the mesh
artist = MeshArtist(mesh)

# mesh
mesh.name = "Mesh"
artist.clear()
artist.draw_mesh()

# edges
mesh.name = "Edges"
mesh.transform(X)
artist.clear()
artist.draw_edges()

# vertices
mesh.name = "Vertices"
mesh.transform(X)
artist.clear()
artist.draw_vertices(color=vertexcolor)
artist.draw_edges(color=(255, 255, 255))

# faces
mesh.name = "Faces"
mesh.transform(X)
artist.clear()
artist.draw_faces(color=facecolor)
Exemplo n.º 6
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()
holes = []
holes += [
    centroid_points_xy(
        [xyz[gkey_index[geometric_key(point)]] for point in hole[:-1]])
]

# ==============================================================================
# Triangulate
# ==============================================================================

vertices, faces = igl.conforming_delaunay_triangulation(xyz,
                                                        edges,
                                                        holes,
                                                        area=0.5)

mesh = Mesh.from_vertices_and_faces(vertices, faces)

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

lines = []
for u, v in edges:
    lines.append({'start': xyz[u], 'end': xyz[v], 'color': '#ff0000'})

artist = MeshArtist(mesh, layer="IGL::Triangulation")
artist.clear_layer()
artist.draw_mesh()
artist.draw_edges(keys=edges, color=(255, 0, 0))
Exemplo n.º 8
0
from compas_rhino.artists import MeshArtist
from compas.datastructures import Mesh

# Define a Frame, which is not in the origin and a bit tilted to the world frame
frame = Frame([4, 4, 4], [.5, 1, 2], [0, 1, 2])

# Create a Box with that frame
width, length, height = 1, 1, 1
box = Box(frame, width, length, height)

# Create a Projection (can be orthogonal, parallel or perspective)
point = [0, 0, 0]
normal = [0, 0, 1]
plane = Plane(point, normal)
direction = [1, 1, 1]
P = Projection.from_plane_and_direction(plane, direction)

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected = mesh.transformed(P)

# Create artists
artist1 = BoxArtist(box)
artist2 = MeshArtist(mesh_projected)

# Draw
artist1.draw()
artist2.draw_edges(color="#00ff00")
Exemplo n.º 9
0
 def draw_edges(self, **kwattr):
     artist = MeshArtist(self)
     artist.draw_edges(**kwattr)
Exemplo n.º 10
0
P5 = Projection.from_plane_and_point(planexy,
                                     Point(3, -3,
                                           -1))  # perspective Projection

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)

# Apply the Projection onto the mesh
mesh_projected3 = mesh.transformed(P3)
mesh_projected4 = mesh.transformed(P4)
mesh_projected5 = mesh.transformed(P5)

# Create artists
artist1 = BoxArtist(box)
artist2 = FrameArtist(frame)
artist3 = MeshArtist(mesh_projected3, layer="P3")
artist4 = MeshArtist(mesh_projected4, layer="P4")
artist5 = MeshArtist(mesh_projected5, layer="P5")

#clear layers
artistl = [artist1, artist2, artist3, artist4, artist5]
for arty in artistl:
    arty.clear_layer()

# Draw
artist1.draw()
artist2.draw()
artist3.draw_edges(color="#00ffa0")
artist4.draw_edges(color=(200, 0, 0))
artist5.draw_edges(color=(200, 100, 0))
Exemplo n.º 11
0
import os
import compas
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist

HERE = os.path.dirname(__file__)
DATA = os.path.join(HERE, 'data')
FILE = os.path.join(DATA, 'faces.obj')

mesh = Mesh.from_obj(FILE)

artist = MeshArtist(mesh, layer="Mesh")

artist.draw_vertices(
    color={key: (255, 0, 0)
           for key in mesh.vertices_on_boundary()})
artist.draw_vertexlabels(
    text={key: str(mesh.vertex_degree(key))
          for key in mesh.vertices()})
artist.draw_edges(keys=list(mesh.edges_on_boundary()), color=(255, 0, 0))
artist.draw_faces(
    color={
        key: (150, 255, 150)
        for key in mesh.faces() if not mesh.is_face_on_boundary(key)
    })
Exemplo n.º 12
0
# 2D Subdivision

vertices = [[0.5, 0.0, 0.0], [0.0, 1.0, 0.0], [-0.5, 0.0, 0.0],
            [1.0, 1.0, 0.0]]

faces = [[0, 1, 2], [1, 0, 3]]

my_mesh = Mesh.from_vertices_and_faces(vertices, faces)

artist = MeshArtist(my_mesh, layer="00_my_first mesh")

artist.clear_layer()
artist.draw_vertices()
artist.draw_faces()
artist.draw_edges()
artist.draw_vertexlabels()
artist.draw_facelabels()
artist.draw_edgelabels()

# iterate through the mesh
# for key,attr in my_mesh.vertices(True):
#     print (key, attr['x'], attr['y'], attr['z'])

# for key in my_mesh.faces():
#     print(key)

# for key in my_mesh.edges():
#     print(key)

# get topology information
point = [0, 0, 0]
normal = [0, 0, -1]
plane = Plane(point, normal)
direction = [2, -2, 1]
P = Projection.from_plane_and_direction(plane, direction)

# Create a Mesh from the Box
mesh = Mesh.from_shape(box)
tmesh = Mesh.from_shape(box_transformed)

# Apply the Projection onto the mesh
mesh_projected = tmesh.transformed(P)

# clear layer
artist = BoxArtist(box, layer="Default")
artist.clear_layer()

# defining Artists
artist1 = BoxArtist(box)
artist2 = BoxArtist(box_transformed)
artist3 = MeshArtist(mesh_projected)
artist4 = FrameArtist(frame, scale=1.0)
artist5 = FrameArtist(frame1, scale=1.0)

# Draw
artist1.draw()
artist2.draw()
artist3.draw_edges(color="#00ffff")
artist4.draw()
artist5.draw()