22from __future__ import absolute_import
33from __future__ import division
44
5+ from compas .utilities import pairwise
56import compas_rhino
67from ._shapeartist import ShapeArtist
78
@@ -18,9 +19,32 @@ class CapsuleArtist(ShapeArtist):
1819 -----
1920 See :class:`compas_rhino.artists.ShapeArtist` for all other parameters.
2021
22+ Examples
23+ --------
24+ .. code-block:: python
25+
26+ import random
27+ from compas.geometry import Pointcloud
28+ from compas.geometry import Capsule
29+ from compas.geometry import Translation
30+ from compas.utilities import i_to_rgb
31+
32+ import compas_rhino
33+ from compas_rhino.artists import CapsuleArtist
34+
35+ pcl = Pointcloud.from_bounds(10, 10, 10, 100)
36+ tpl = Capsule([[0, 0, 0], [0.8, 0, 0]], 0.15)
37+
38+ compas_rhino.clear_layer("Test::CapsuleArtist")
39+
40+ for point in pcl.points:
41+ capsule = tpl.transformed(Translation.from_vector(point))
42+ artist = CapsuleArtist(capsule, color=i_to_rgb(random.random()), layer="Test::CapsuleArtist")
43+ artist.draw()
44+
2145 """
2246
23- def draw (self , u = 10 , v = 10 ):
47+ def draw (self , u = 10 , v = 10 , show_vertices = False , show_edges = False , show_faces = True , join_faces = True ):
2448 """Draw the capsule associated with the artist.
2549
2650 Parameters
@@ -31,6 +55,14 @@ def draw(self, u=10, v=10):
3155 v : int, optional
3256 Number of faces in the "v" direction.
3357 Default is ``10``.
58+ show_vertices : bool, optional
59+ Default is ``False``.
60+ show_edges : bool, optional
61+ Default is ``False``.
62+ show_faces : bool, optional
63+ Default is ``True``.
64+ join_faces : bool, optional
65+ Default is ``True``.
3466
3567 Returns
3668 -------
@@ -39,10 +71,27 @@ def draw(self, u=10, v=10):
3971 """
4072 vertices , faces = self .shape .to_vertices_and_faces (u = u , v = v )
4173 vertices = [list (vertex ) for vertex in vertices ]
42- points = [{'pos' : point , 'color' : self .color } for point in vertices ]
43- polygons = [{'points' : [vertices [index ] for index in face ], 'color' : self .color } for face in faces ]
44- guids = compas_rhino .draw_points (points , layer = self .layer , clear = False , redraw = False )
45- guids += compas_rhino .draw_faces (polygons , layer = self .layer , clear = False , redraw = False )
74+ guids = []
75+ if show_vertices :
76+ points = [{'pos' : point , 'color' : self .color } for point in vertices ]
77+ guids += compas_rhino .draw_points (points , layer = self .layer , clear = False , redraw = False )
78+ if show_edges :
79+ lines = []
80+ seen = set ()
81+ for face in faces :
82+ for u , v in pairwise (face + face [:1 ]):
83+ if (u , v ) not in seen :
84+ seen .add ((u , v ))
85+ seen .add ((v , u ))
86+ lines .append ({'start' : vertices [u ], 'end' : vertices [v ], 'color' : self .color })
87+ guids += compas_rhino .draw_lines (lines , layer = self .layer , clear = False , redraw = False )
88+ if show_faces :
89+ if join_faces :
90+ guid = compas_rhino .draw_mesh (vertices , faces , layer = self .layer , name = self .name , color = self .color , disjoint = True )
91+ guids .append (guid )
92+ else :
93+ polygons = [{'points' : [vertices [index ] for index in face ], 'color' : self .color } for face in faces ]
94+ guids += compas_rhino .draw_faces (polygons , layer = self .layer , clear = False , redraw = False )
4695 self ._guids = guids
4796 return guids
4897
0 commit comments