Skip to content

Commit d795a8b

Browse files
authored
Merge pull request #914 from compas-dev/ghpython_moar_artists
Ghpython moar artists
2 parents 8ea7ec3 + ebf2071 commit d795a8b

File tree

12 files changed

+494
-14
lines changed

12 files changed

+494
-14
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,8 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
2424
* Added `compas_blender.artists.RobotModelArtist.clear`.
2525
* Added `compas_blender.geometry.booleans` as plugin for boolean pluggables.
2626
* Added version-based installation for Blender.
27+
* Added several shape artists to `compas_ghpython`: `BoxArtist`, `CapsuleArtist`, `ConeArtist`, `CylinderArtist`, `PolygonArtist`, `PolyhedronArtist`, `SphereArtist`, `TorusArtist` and `VectorArtist`.
28+
2729

2830
### Changed
2931

@@ -36,6 +38,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
3638
* Generalized the parameter `color` of `compas_blender.draw_texts` and various label drawing methods.
3739
* Changed `compas.IPY` to `compas.RHINO` in `orientation_rhino`.
3840
* Changed `planarity` to `requires_extra` for pip installations.
41+
* Fixed bug in handling of ngonal meshes in `compas_ghpython` artists / drawing functions.
3942

4043
### Removed
4144

src/compas_ghpython/artists/__init__.py

Lines changed: 54 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,20 @@
1313
:toctree: generated/
1414
:nosignatures:
1515
16+
BoxArtist
17+
CapsuleArtist
1618
CircleArtist
19+
ConeArtist
20+
CylinderArtist
1721
FrameArtist
1822
LineArtist
1923
PointArtist
24+
PolygonArtist
25+
PolyhedronArtist
2026
PolylineArtist
27+
SphereArtist
28+
TorusArtist
29+
VectorArtist
2130
2231
2332
Datastructure Artists
@@ -61,11 +70,20 @@
6170
from compas.artists import ShapeArtist
6271
from compas.artists import DataArtistNotRegistered
6372

73+
from compas.geometry import Box
74+
from compas.geometry import Capsule
6475
from compas.geometry import Circle
76+
from compas.geometry import Cone
77+
from compas.geometry import Cylinder
6578
from compas.geometry import Frame
6679
from compas.geometry import Line
6780
from compas.geometry import Point
81+
from compas.geometry import Polygon
82+
from compas.geometry import Polyhedron
6883
from compas.geometry import Polyline
84+
from compas.geometry import Sphere
85+
from compas.geometry import Torus
86+
from compas.geometry import Vector
6987

7088
from compas.datastructures import Mesh
7189
from compas.datastructures import Network
@@ -74,15 +92,24 @@
7492
from compas.robots import RobotModel
7593

7694
from .artist import GHArtist
95+
from .boxartist import BoxArtist
96+
from .capsuleartist import CapsuleArtist
7797
from .circleartist import CircleArtist
98+
from .coneartist import ConeArtist
99+
from .cylinderartist import CylinderArtist
78100
from .frameartist import FrameArtist
79101
from .lineartist import LineArtist
80-
from .pointartist import PointArtist
81-
from .polylineartist import PolylineArtist
82102
from .meshartist import MeshArtist
83103
from .networkartist import NetworkArtist
84-
from .volmeshartist import VolMeshArtist
104+
from .pointartist import PointArtist
105+
from .polygonartist import PolygonArtist
106+
from .polyhedronartist import PolyhedronArtist
107+
from .polylineartist import PolylineArtist
85108
from .robotmodelartist import RobotModelArtist
109+
from .sphereartist import SphereArtist
110+
from .torusartist import TorusArtist
111+
from .vectorartist import VectorArtist
112+
from .volmeshartist import VolMeshArtist
86113

87114
ShapeArtist.default_color = (255, 255, 255)
88115

@@ -120,15 +147,24 @@ def new_artist_gh(cls, *args, **kwargs):
120147
global artists_registered
121148

122149
if not artists_registered:
150+
GHArtist.register(Box, BoxArtist)
151+
GHArtist.register(Capsule, CapsuleArtist)
123152
GHArtist.register(Circle, CircleArtist)
153+
GHArtist.register(Cone, ConeArtist)
154+
GHArtist.register(Cylinder, CylinderArtist)
124155
GHArtist.register(Frame, FrameArtist)
125156
GHArtist.register(Line, LineArtist)
126-
GHArtist.register(Point, PointArtist)
127-
GHArtist.register(Polyline, PolylineArtist)
128157
GHArtist.register(Mesh, MeshArtist)
129158
GHArtist.register(Network, NetworkArtist)
130-
GHArtist.register(VolMesh, VolMeshArtist)
159+
GHArtist.register(Point, PointArtist)
160+
GHArtist.register(Polygon, PolygonArtist)
161+
GHArtist.register(Polyhedron, PolyhedronArtist)
162+
GHArtist.register(Polyline, PolylineArtist)
131163
GHArtist.register(RobotModel, RobotModelArtist)
164+
GHArtist.register(Sphere, SphereArtist)
165+
GHArtist.register(Torus, TorusArtist)
166+
GHArtist.register(Vector, VectorArtist)
167+
GHArtist.register(VolMesh, VolMeshArtist)
132168
artists_registered = True
133169

134170
data = args[0]
@@ -153,15 +189,23 @@ def new_artist_gh(cls, *args, **kwargs):
153189

154190
__all__ = [
155191
'GHArtist',
156-
'PrimitiveArtist',
157192
'ShapeArtist',
193+
'BoxArtist',
194+
'CapsuleArtist',
158195
'CircleArtist',
196+
'ConeArtist',
197+
'CylinderArtist',
159198
'FrameArtist',
160199
'LineArtist',
161-
'PointArtist',
162-
'PolylineArtist',
163200
'MeshArtist',
164201
'NetworkArtist',
165-
'VolMeshArtist',
202+
'PointArtist',
203+
'PolygonArtist',
204+
'PolyhedronArtist',
205+
'PolylineArtist',
166206
'RobotModelArtist'
207+
'SphereArtist',
208+
'TorusArtist',
209+
'VectorArtist',
210+
'VolMeshArtist',
167211
]
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
from __future__ import print_function
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
5+
import compas_ghpython
6+
from compas.artists import ShapeArtist
7+
from .artist import GHArtist
8+
9+
10+
class BoxArtist(GHArtist, ShapeArtist):
11+
"""Artist for drawing box shapes.
12+
13+
Parameters
14+
----------
15+
box : :class:`compas.geometry.Box`
16+
A COMPAS box.
17+
"""
18+
19+
def __init__(self, box, **kwargs):
20+
super(BoxArtist, self).__init__(shape=box, **kwargs)
21+
22+
def draw(self, color=None):
23+
"""Draw the box associated with the artist.
24+
25+
Parameters
26+
----------
27+
color : tuple of float, optional
28+
The RGB color of the box.
29+
30+
Returns
31+
-------
32+
:class:`Rhino.Geometry.Mesh`
33+
"""
34+
color = color or self.color
35+
vertices = [list(vertex) for vertex in self.shape.vertices]
36+
faces = self.shape.faces
37+
mesh = compas_ghpython.draw_mesh(vertices,
38+
faces,
39+
color=color)
40+
return mesh
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
from __future__ import print_function
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
5+
import compas_ghpython
6+
from compas.artists import ShapeArtist
7+
from .artist import GHArtist
8+
9+
10+
class CapsuleArtist(GHArtist, ShapeArtist):
11+
"""Artist for drawing capsule shapes.
12+
13+
Parameters
14+
----------
15+
capsule : :class:`compas.geometry.Capsule`
16+
A COMPAS capsule.
17+
"""
18+
19+
def __init__(self, capsule, **kwargs):
20+
super(CapsuleArtist, self).__init__(shape=capsule, **kwargs)
21+
22+
def draw(self, color=None, u=None, v=None):
23+
"""Draw the capsule associated with the artist.
24+
25+
Parameters
26+
----------
27+
color : tuple of float, optional
28+
The RGB color of the capsule.
29+
u : int, optional
30+
Number of faces in the "u" direction.
31+
Default is ``~CapsuleArtist.u``.
32+
v : int, optional
33+
Number of faces in the "v" direction.
34+
Default is ``~CapsuleArtist.v``.
35+
36+
Returns
37+
-------
38+
:class:`Rhino.Geometry.Mesh`
39+
"""
40+
color = color or self.color
41+
u = u or self.u
42+
v = v or self.v
43+
vertices, faces = self.shape.to_vertices_and_faces(u=u, v=v)
44+
vertices = [list(vertex) for vertex in vertices]
45+
mesh = compas_ghpython.draw_mesh(vertices,
46+
faces,
47+
color=color)
48+
return mesh
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import print_function
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
5+
import compas_ghpython
6+
from compas.artists import ShapeArtist
7+
from .artist import GHArtist
8+
9+
10+
class ConeArtist(GHArtist, ShapeArtist):
11+
"""Artist for drawing cone shapes.
12+
13+
Parameters
14+
----------
15+
shape : :class:`compas.geometry.Cone`
16+
A COMPAS cone.
17+
"""
18+
19+
def __init__(self, cone, **kwargs):
20+
super(ConeArtist, self).__init__(shape=cone, **kwargs)
21+
22+
def draw(self, color=None, u=None):
23+
"""Draw the cone associated with the artist.
24+
25+
Parameters
26+
----------
27+
color : tuple of float, optional
28+
The RGB color of the cone.
29+
u : int, optional
30+
Number of faces in the "u" direction.
31+
Default is ``~ConeArtist.u``.
32+
33+
Returns
34+
-------
35+
:class:`Rhino.Geometry.Mesh`
36+
"""
37+
color = color or self.color
38+
u = u or self.u
39+
vertices, faces = self.shape.to_vertices_and_faces(u=u)
40+
vertices = [list(vertex) for vertex in vertices]
41+
mesh = compas_ghpython.draw_mesh(vertices,
42+
faces,
43+
color=color)
44+
return mesh
Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,44 @@
1+
from __future__ import print_function
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
5+
import compas_ghpython
6+
from compas.artists import ShapeArtist
7+
from .artist import GHArtist
8+
9+
10+
class CylinderArtist(GHArtist, ShapeArtist):
11+
"""Artist for drawing cylinder shapes.
12+
13+
Parameters
14+
----------
15+
cylinder : :class:`compas.geometry.Cylinder`
16+
A COMPAS cylinder.
17+
"""
18+
19+
def __init__(self, cylinder, **kwargs):
20+
super(CylinderArtist, self).__init__(shape=cylinder, **kwargs)
21+
22+
def draw(self, color=None, u=None):
23+
"""Draw the cylinder associated with the artist.
24+
25+
Parameters
26+
----------
27+
color : tuple of float, optional
28+
The RGB color of the cylinder.
29+
u : int, optional
30+
Number of faces in the "u" direction.
31+
Default is ``~CylinderArtist.u``.
32+
33+
Returns
34+
-------
35+
:class:`Rhino.Geometry.Mesh`
36+
"""
37+
color = color or self.color
38+
u = u or self.u
39+
vertices, faces = self.shape.to_vertices_and_faces(u=u)
40+
vertices = [list(vertex) for vertex in vertices]
41+
mesh = compas_ghpython.draw_mesh(vertices,
42+
faces,
43+
color=color)
44+
return mesh
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from __future__ import print_function
2+
from __future__ import absolute_import
3+
from __future__ import division
4+
5+
import compas_ghpython
6+
from compas.artists import PrimitiveArtist
7+
from .artist import GHArtist
8+
9+
10+
class PolygonArtist(GHArtist, PrimitiveArtist):
11+
"""Artist for drawing polygons.
12+
13+
Parameters
14+
----------
15+
polygon : :class:`compas.geometry.Polygon`
16+
A COMPAS polygon.
17+
"""
18+
19+
def __init__(self, polygon, **kwargs):
20+
super(PolygonArtist, self).__init__(primitive=polygon, **kwargs)
21+
22+
def draw(self, show_points=False, show_edges=False, show_face=True):
23+
"""Draw the polygon.
24+
25+
Parameters
26+
----------
27+
show_points : bool, optional
28+
Default is ``False``.
29+
show_edges : bool, optional
30+
Default is ``False``.
31+
show_face : bool, optional
32+
Default is ``True``.
33+
34+
Returns
35+
-------
36+
list
37+
The Rhino points, lines and face.
38+
"""
39+
_points = map(list, self.primitive.points)
40+
result = []
41+
if show_points:
42+
points = [{'pos': point, 'color': self.color, 'name': self.primitive.name} for point in _points]
43+
result += compas_ghpython.draw_points(points)
44+
if show_edges:
45+
lines = [{'start': list(a), 'end': list(b), 'color': self.color, 'name': self.primitive.name} for a, b in self.primitive.lines]
46+
result += compas_ghpython.draw_lines(lines)
47+
if show_face:
48+
polygons = [{'points': _points, 'color': self.color, 'name': self.primitive.name}]
49+
result += compas_ghpython.draw_faces(polygons)
50+
return result

0 commit comments

Comments
 (0)