conduits
Display conduits can be used to visualize iterative processes with less of a performance penalty than with regular geometry objects.
import compas
from compas.datastructures import Mesh
from compas_rhino.artists import MeshArtist
from compas_rhino.conduits import LinesConduit
mesh = Mesh.from_obj(compas.get('faces.obj'))
fixed = list(mesh.vertices_where({'vertex_degree': 2})
artist = MeshArtist(mesh, layer="COMPAS::faces.obj")
artist.clear_layer()
artist.draw_mesh()
artist.redraw()
conduit = LinesConduit()
def redraw(k, args):
conduit.lines = [mesh.edge_coordinates(*edges) for edge in mesh.edges()]
conduit.redraw()
with conduit.enabled():
mesh.smooth_centroid(
fixed=fixed),
kmax=100,
callback=redraw)
BaseConduit
- class compas_rhino.conduits.BaseConduit(*args: Any, **kwargs: Any)[source]
Bases:
Rhino.Display.
Base class for conduits.
- Parameters
refreshrate (int, optional) – The number of iterations after which the conduit should be redrawn. Default is
1
.
- disable()[source]
Disable the conduit.
- enable()[source]
Enable the conduit.
- enabled()[source]
- redraw(k=0, pause=None)[source]
Redraw the conduit.
- Parameters
k (int, optional) – The current iteration. If the current iteration is a multiple of
refreshrate
, the conduit will be redrawn. Default is0
.pause (float, optional) – Include a pause after redrawing. The pause value should be provided in seconds. Default is no pause.
Faces Conduit
- class compas_rhino.conduits.FacesConduit(*args: Any, **kwargs: Any)[source]
A Rhino display conduit for faces.
- Parameters
vertices (list of list of float) – The coordinates of the vertices of the faces.
faces (list of list of int) – The faces defined as lists of indices in
vertices
.color (list of str or 3-tuple, optional) – The colors of the faces. Default is
None
, in which case the default color is used for all faces.
- Attributes
color (list of RGB colors) – The color specification per face.
vertices (list of list of float) – The coordinates of the vertices of the faces.
faces (list of list of int) – The faces defined as lists of indices in
vertices
.
Examples
from compas.geometry import Polyhedron from compas_rhino.conduits import FacesConduit polyhedron = Polyhedron.generate(6) faces = polyhedron.faces vertices = polyhedron.vertices polygons = [[vertices[index] for index in face] for face in faces] conduit = FacesConduit(polygons) with conduit.enabled(): conduit.redraw(pause=5.0)
Lines Conduit
- class compas_rhino.conduits.LinesConduit(*args: Any, **kwargs: Any)[source]
A Rhino display conduit for lines.
- Parameters
lines (list of 2-tuple) – A list of start-end point pairs that define the lines.
thickness (list of int, optional) – The thickness of the individual lines. Default is
1.0
for all lines.color (list of str or 3-tuple, optional) – The colors of the faces. Default is
(255, 255, 255)
for all lines.
- Attributes
color (list of RGB colors) – A color specification per line.
thickness (list of float) – A thickness value per line.
lines (list) – A list of start-end point pairs that define the lines.
Examples
from random import randint points = [(1.0 * randint(0, 30), 1.0 * randint(0, 30), 0.0) for _ in range(100)] lines = [(points[i], points[i + 1]) for i in range(99)] conduit = LinesConduit(lines) with conduit.enabled(): for i in range(100): points = [(1.0 * randint(0, 30), 1.0 * randint(0, 30), 0.0) for _ in range(100)] conduit.lines = [(points[i], points[i + 1]) for i in range(99)] conduit.redraw(pause=0.1)
Points Conduit
- class compas_rhino.conduits.PointsConduit(*args: Any, **kwargs: Any)[source]
A Rhino display conduit for points.
- Parameters
points (list of list of float) – The coordinates of the points.
size (list of int, optional) – The size of the points. Default is
3
for all points.color (list of str or 3-tuple) – The individual colors of the points. Default is
(255, 0, 0)
for all points.
- Attributes
size (list of float) – The size specification per point.
color (list of RGB colors) – The color specification per point.
points (list of point) – The location of every point.
Examples
from random import randint from compas_rhino.conduits import PointsConduit points = [(1.0 * randint(0, 30), 1.0 * randint(0, 30), 0.0) for _ in range(100)] conduit = PointsConduit(points) with conduit.enabled(): for i in range(100): conduit.points = [(1.0 * randint(0, 30), 1.0 * randint(0, 30), 0.0) for _ in range(100)] conduit.redraw(pause=0.1)
Labels Conduit
- class compas_rhino.conduits.LabelsConduit(*args: Any, **kwargs: Any)[source]
A Rhino display conduit for labels.
- Parameters
labels (list of 2-tuple) – A list of label tuples. Each tuple contains a position and text for the label.
color (list of 2-tuple, optional) – The colors of the labels. Each color is a tuple with a background color and a text color. Default is
((0, 0, 0), (255, 255, 255))
for all labels.
- Attributes
color (list of RGB colors) – A color specification per label.
labels (list) – A list of label tuples. Each tuple contains a position and text for the label.
Examples
from random import randint from compas_rhino.conduits import LabelsConduit labels = [([1.0 * randint(0, 100), 1.0 * randint(0, 100), 0.0], str(i)) for i in range(100)] conduit = LabelsConduit(labels) with conduit.enabled(): for i in range(100): conduit.labels = [([1.0 * randint(0, 100), 1.0 * randint(0, 100), 0.0], str(i)) for i in range(100)] conduit.redraw(pause=0.1)