Skip to content

Commit 0feb74b

Browse files
committed
Merge remote-tracking branch 'origin/main' into main
2 parents 6f4d84d + 57a48c8 commit 0feb74b

File tree

9 files changed

+95
-50
lines changed

9 files changed

+95
-50
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99

1010
### Added
1111

12+
* Added `draw_mesh` method to `compas_ghpython.artists.MeshArtist` to match all other mesh artists.
13+
1214
### Changed
1315

1416
* Changed new artist registration to check if subclass.

src/compas/artists/meshartist.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -326,6 +326,10 @@ def draw_faces(self, faces=None, color=None, text=None):
326326
"""
327327
raise NotImplementedError
328328

329+
@abstractmethod
330+
def draw_mesh(self):
331+
raise NotImplementedError
332+
329333
@abstractmethod
330334
def clear_vertices(self):
331335
raise NotImplementedError

src/compas_ghpython/artists/meshartist.py

Lines changed: 64 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -5,9 +5,7 @@
55
import Rhino
66
from functools import partial
77

8-
from compas.geometry import centroid_polygon
98
from compas.utilities import color_to_colordict
10-
from compas.utilities import pairwise
119

1210
import compas_ghpython
1311
from compas.artists import MeshArtist
@@ -25,12 +23,69 @@ class MeshArtist(GHArtist, MeshArtist):
2523
A COMPAS mesh.
2624
"""
2725

28-
def __init__(self, mesh, **kwargs):
26+
def __init__(self,
27+
mesh,
28+
show_mesh=False,
29+
show_vertices=True,
30+
show_edges=True,
31+
show_faces=True,
32+
**kwargs):
2933
super(MeshArtist, self).__init__(mesh=mesh, **kwargs)
34+
self.show_mesh = show_mesh
35+
self.show_vertices = show_vertices
36+
self.show_edges = show_edges
37+
self.show_faces = show_faces
3038

31-
def draw(self, color=None):
39+
def draw(self, vertices=None, edges=None, faces=None, vertexcolor=None, edgecolor=None, facecolor=None, color=None, join_faces=False):
40+
"""Draw the mesh using the chosen visualization settings.
41+
42+
Parameters
43+
----------
44+
vertices : list, optional
45+
A list of vertices to draw.
46+
Default is ``None``, in which case all vertices are drawn.
47+
edges : list, optional
48+
A list of edges to draw.
49+
The default is ``None``, in which case all edges are drawn.
50+
faces : list, optional
51+
A selection of faces to draw.
52+
The default is ``None``, in which case all faces are drawn.
53+
vertexcolor : tuple or dict of tuple, optional
54+
The color specification for the vertices.
55+
The default color is the value of ``~MeshArtist.default_vertexcolor``.
56+
edgecolor : tuple or dict of tuple, optional
57+
The color specification for the edges.
58+
The default color is the value of ``~MeshArtist.default_edgecolor``.
59+
facecolor : tuple or dict of tuple, optional
60+
The color specification for the faces.
61+
The default color is the value of ``~MeshArtist.default_facecolor``.
62+
color : tuple, optional
63+
The color of the mesh.
64+
Default is the value of ``~MeshArtist.default_color``.
65+
join_faces : bool, optional
66+
Join the faces into 1 mesh.
67+
Default is ``False``, in which case the faces are drawn as individual meshes.
68+
69+
Returns
70+
-------
71+
list of :class:`Rhino.Geometry.Mesh`, :class:`Rhino.Geometry.Point3d` and :class:`Rhino.Geometry.Line` depending on the selection.
72+
"""
73+
geometry = []
74+
if self.show_mesh:
75+
geometry.append(self.draw_mesh(color=color))
76+
if self.show_vertices:
77+
geometry.extend(self.draw_vertices(vertices=vertices, color=vertexcolor))
78+
if self.show_edges:
79+
geometry.extend(self.draw_edges(edges=edges, color=edgecolor))
80+
if self.show_faces:
81+
geometry.extend(self.draw_faces(faces=faces, color=facecolor, join_faces=join_faces))
82+
return geometry
83+
84+
def draw_mesh(self, color=None):
3285
"""Draw the mesh as a RhinoMesh.
3386
87+
This method is an alias for ``~MeshArtist.draw``.
88+
3489
Parameters
3590
----------
3691
color : tuple, optional
@@ -47,24 +102,8 @@ def draw(self, color=None):
47102
Faces with more than 4 vertices will be triangulated on-the-fly.
48103
"""
49104
color = color or self.default_color
50-
vertex_index = self.mesh.vertex_index()
51-
vertex_xyz = self.vertex_xyz
52-
vertices = [vertex_xyz[vertex] for vertex in self.mesh.vertices()]
53-
faces = [[vertex_index[vertex] for vertex in self.mesh.face_vertices(face)] for face in self.mesh.faces()]
54-
new_faces = []
55-
for face in faces:
56-
f = len(face)
57-
if f == 3:
58-
new_faces.append(face + [face[-1]])
59-
elif f == 4:
60-
new_faces.append(face)
61-
elif f > 4:
62-
centroid = len(vertices)
63-
vertices.append(centroid_polygon(
64-
[vertices[index] for index in face]))
65-
for a, b in pairwise(face + face[0:1]):
66-
new_faces.append([centroid, a, b, b])
67-
return compas_ghpython.draw_mesh(vertices, new_faces, color)
105+
vertices, faces = self.mesh.to_vertices_and_faces()
106+
return compas_ghpython.draw_mesh(vertices, faces, color)
68107

69108
def draw_vertices(self, vertices=None, color=None):
70109
"""Draw a selection of vertices.
@@ -75,7 +114,7 @@ def draw_vertices(self, vertices=None, color=None):
75114
A selection of vertices to draw.
76115
Default is ``None``, in which case all vertices are drawn.
77116
color : tuple or dict of tuple, optional
78-
The color specififcation for the vertices.
117+
The color specification for the vertices.
79118
The default is the value of ``~MeshArtist.default_vertexcolor``.
80119
81120
Returns
@@ -104,7 +143,7 @@ def draw_faces(self, faces=None, color=None, join_faces=False):
104143
A selection of faces to draw.
105144
The default is ``None``, in which case all faces are drawn.
106145
color : tuple or dict of tuple, optional
107-
The color specififcation for the faces.
146+
The color specification for the faces.
108147
The default color is the value of ``~MeshArtist.default_facecolor``.
109148
join_faces : bool, optional
110149
Join the faces into 1 mesh.
@@ -142,7 +181,7 @@ def draw_edges(self, edges=None, color=None):
142181
A selection of edges to draw.
143182
The default is ``None``, in which case all edges are drawn.
144183
color : tuple or dict of tuple, optional
145-
The color specififcation for the edges.
184+
The color specification for the edges.
146185
The default color is the value of ``~MeshArtist.default_edgecolor``.
147186
148187
Returns

src/compas_ghpython/artists/networkartist.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,7 @@ def draw_nodes(self, nodes=None, color=None):
4444
The selection of nodes that should be drawn.
4545
Default is ``None``, in which case all nodes are drawn.
4646
color: 3-tuple or dict of 3-tuple, optional
47-
The color specififcation for the nodes.
47+
The color specification for the nodes.
4848
The default color is ``(255, 255, 255)``.
4949
5050
Returns
@@ -72,7 +72,7 @@ def draw_edges(self, edges=None, color=None):
7272
A list of edges to draw.
7373
The default is ``None``, in which case all edges are drawn.
7474
color : tuple or dict of tuple, optional
75-
The color specififcation for the edges.
75+
The color specification for the edges.
7676
The default color is the value of ``~NetworkArtist.default_edgecolor``.
7777
7878
Returns

src/compas_ghpython/artists/volmeshartist.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ def draw_vertices(self, vertices=None, color=None):
4040
A list of vertices to draw.
4141
Default is ``None``, in which case all vertices are drawn.
4242
color : str, tuple, dict
43-
The color specififcation for the vertices.
43+
The color specification for the vertices.
4444
The default color of the vertices is ``~VolMeshArtist.default_vertexcolor``.
4545
4646
Returns
@@ -68,7 +68,7 @@ def draw_edges(self, edges=None, color=None):
6868
A list of edges to draw.
6969
The default is ``None``, in which case all edges are drawn.
7070
color : str, tuple, dict
71-
The color specififcation for the edges.
71+
The color specification for the edges.
7272
The default color is ``~VolMeshArtist.default_edgecolor``.
7373
7474
Returns
@@ -97,7 +97,7 @@ def draw_faces(self, faces=None, color=None, join_faces=False):
9797
A list of faces to draw.
9898
The default is ``None``, in which case all faces are drawn.
9999
color : str, tuple, dict
100-
The color specififcation for the faces.
100+
The color specification for the faces.
101101
The default color is ``~VolMeshArtist.default_facecolor``.
102102
103103
Returns

src/compas_plotters/plotter.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -161,7 +161,7 @@ def bgcolor(self, value: Union[str, Tuple[float, float, float]]):
161161
Parameters
162162
----------
163163
value : str, tuple
164-
The color specififcation for the figure background.
164+
The color specification for the figure background.
165165
Colors should be specified in the form of a string (hex colors) or
166166
as a tuple of normalized RGB components.
167167

src/compas_rhino/artists/meshartist.py

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -106,7 +106,7 @@ def clear_facelabels(self):
106106
# ==========================================================================
107107

108108
def draw(self, vertices=None, edges=None, faces=None, vertexcolor=None, edgecolor=None, facecolor=None, join_faces=False):
109-
"""Draw the network using the chosen visualisation settings.
109+
"""Draw the mesh using the chosen visualization settings.
110110
111111
Parameters
112112
----------
@@ -120,13 +120,13 @@ def draw(self, vertices=None, edges=None, faces=None, vertexcolor=None, edgecolo
120120
A selection of faces to draw.
121121
The default is ``None``, in which case all faces are drawn.
122122
vertexcolor : tuple or dict of tuple, optional
123-
The color specififcation for the vertices.
123+
The color specification for the vertices.
124124
The default color is the value of ``~MeshArtist.default_vertexcolor``.
125125
edgecolor : tuple or dict of tuple, optional
126-
The color specififcation for the edges.
126+
The color specification for the edges.
127127
The default color is the value of ``~MeshArtist.default_edgecolor``.
128128
facecolor : tuple or dict of tuple, optional
129-
The color specififcation for the faces.
129+
The color specification for the faces.
130130
The default color is the value of ``~MeshArtist.default_facecolor``.
131131
join_faces : bool, optional
132132
Join the faces into 1 mesh.
@@ -200,7 +200,7 @@ def draw_vertices(self, vertices=None, color=None):
200200
A selection of vertices to draw.
201201
Default is ``None``, in which case all vertices are drawn.
202202
color : tuple or dict of tuple, optional
203-
The color specififcation for the vertices.
203+
The color specification for the vertices.
204204
The default is the value of ``~MeshArtist.default_vertexcolor``.
205205
206206
Returns
@@ -231,7 +231,7 @@ def draw_edges(self, edges=None, color=None):
231231
A selection of edges to draw.
232232
The default is ``None``, in which case all edges are drawn.
233233
color : tuple or dict of tuple, optional
234-
The color specififcation for the edges.
234+
The color specification for the edges.
235235
The default color is the value of ``~MeshArtist.default_edgecolor``.
236236
237237
Returns
@@ -263,7 +263,7 @@ def draw_faces(self, faces=None, color=None, join_faces=False):
263263
A selection of faces to draw.
264264
The default is ``None``, in which case all faces are drawn.
265265
color : tuple or dict of tuple, optional
266-
The color specififcation for the faces.
266+
The color specification for the faces.
267267
The default color is the value of ``~MeshArtist.default_facecolor``.
268268
join_faces : bool, optional
269269
Join the faces into 1 mesh.

src/compas_rhino/artists/networkartist.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -97,10 +97,10 @@ def draw(self, nodes=None, edges=None, nodecolor=None, edgecolor=None):
9797
A list of edges to draw.
9898
The default is ``None``, in which case all edges are drawn.
9999
nodecolor : tuple or dict of tuple, optional
100-
The color specififcation for the nodes.
100+
The color specification for the nodes.
101101
The default color is the value of ``~NetworkArtist.default_nodecolor``.
102102
edgecolor : tuple or dict of tuple, optional
103-
The color specififcation for the edges.
103+
The color specification for the edges.
104104
The default color is the value of ``~NetworkArtist.default_edgecolor``.
105105
106106
Returns
@@ -122,7 +122,7 @@ def draw_nodes(self, nodes=None, color=None):
122122
A list of nodes to draw.
123123
Default is ``None``, in which case all nodes are drawn.
124124
color : tuple or dict of tuple, optional
125-
The color specififcation for the nodes.
125+
The color specification for the nodes.
126126
The default color is the value of ``~NetworkArtist.default_nodecolor``.
127127
128128
Returns
@@ -151,7 +151,7 @@ def draw_edges(self, edges=None, color=None):
151151
A list of edges to draw.
152152
The default is ``None``, in which case all edges are drawn.
153153
color : tuple or dict of tuple, optional
154-
The color specififcation for the edges.
154+
The color specification for the edges.
155155
The default color is the value of ``~NetworkArtist.default_edgecolor``.
156156
157157
Returns

src/compas_rhino/artists/volmeshartist.py

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,16 +55,16 @@ def draw(self, vertices=None, edges=None, faces=None, cells=None, vertexcolor=No
5555
A selection of cells to draw.
5656
The default is ``None``, in which case all cells are drawn.
5757
vertexcolor : tuple or dict of tuple, optional
58-
The color specififcation for the vertices.
58+
The color specification for the vertices.
5959
The default color is the value of ``~VolMeshArtist.default_vertexcolor``.
6060
edgecolor : tuple or dict of tuple, optional
61-
The color specififcation for the edges.
61+
The color specification for the edges.
6262
The default color is the value of ``~VolMeshArtist.default_edgecolor``.
6363
facecolor : tuple or dict of tuple, optional
64-
The color specififcation for the faces.
64+
The color specification for the faces.
6565
The default color is the value of ``~VolMeshArtist.default_facecolor``.
6666
cellcolor : tuple or dict of tuple, optional
67-
The color specififcation for the cells.
67+
The color specification for the cells.
6868
The default color is the value of ``~VolMeshArtist.default_cellcolor``.
6969
7070
Returns
@@ -88,7 +88,7 @@ def draw_vertices(self, vertices=None, color=None):
8888
A list of vertices to draw.
8989
Default is ``None``, in which case all vertices are drawn.
9090
color : str, tuple, dict
91-
The color specififcation for the vertices.
91+
The color specification for the vertices.
9292
The default color of the vertices is ``~VolMeshArtist.default_vertexcolor``.
9393
9494
Returns
@@ -118,7 +118,7 @@ def draw_edges(self, edges=None, color=None):
118118
A list of edges to draw.
119119
The default is ``None``, in which case all edges are drawn.
120120
color : str, tuple, dict
121-
The color specififcation for the edges.
121+
The color specification for the edges.
122122
The default color is ``~VolMeshArtist.default_edgecolor``.
123123
124124
Returns
@@ -149,7 +149,7 @@ def draw_faces(self, faces=None, color=None):
149149
A list of faces to draw.
150150
The default is ``None``, in which case all faces are drawn.
151151
color : str, tuple, dict
152-
The color specififcation for the faces.
152+
The color specification for the faces.
153153
The default color is ``~VolMeshArtist.default_facecolor``.
154154
155155
Returns
@@ -179,7 +179,7 @@ def draw_cells(self, cells=None, color=None):
179179
A list of cells to draw.
180180
The default is ``None``, in which case all cells are drawn.
181181
color : str, tuple, dict
182-
The color specififcation for the cells.
182+
The color specification for the cells.
183183
The default color is ``~VolMeshArtist.default_cellcolor``.
184184
185185
Returns

0 commit comments

Comments
 (0)