Skip to content

Commit f89a603

Browse files
committed
docs: small example and docstring updates
1 parent 40181a6 commit f89a603

File tree

5 files changed

+89
-37
lines changed

5 files changed

+89
-37
lines changed

src/compas/geometry/algorithms/hull_numpy.py

Lines changed: 64 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,15 +37,56 @@ def convex_hull_numpy(points):
3737
Indices of the points on the hull.
3838
Faces of the hull.
3939
40-
Warning
41-
-------
42-
This function requires Numpy ands Scipy.
40+
Notes
41+
-----
42+
The faces of the hull returned by this function do not necessarily have consistent
43+
cycle directions. To obtain a mesh with consistent cycle directions, construct
44+
a mesh from the returned vertices, this function should be used in combination
45+
with :func:`compas.topology.unify_cycles`.
4346
4447
Examples
4548
--------
4649
.. code-block:: python
4750
48-
#
51+
import random
52+
53+
from compas.datastructures import Mesh
54+
55+
from compas.geometry import distance_point_point
56+
from compas.geometry import convex_hull_numpy
57+
from compas.topology import unify_cycles
58+
59+
from compas.viewers import MeshViewer
60+
61+
radius = 5
62+
origin = (0., 0., 0.)
63+
count = 0
64+
points = []
65+
66+
while count < 10:
67+
x = (random.random() - 0.5) * radius * 2
68+
y = (random.random() - 0.5) * radius * 2
69+
z = (random.random() - 0.5) * radius * 2
70+
pt = x, y, z
71+
72+
if distance_point_point(origin, pt) <= radius:
73+
points.append(pt)
74+
count += 1
75+
76+
vertices, faces = convex_hull_numpy(points)
77+
78+
i_index = {i: index for index, i in enumerate(vertices)}
79+
80+
vertices = [points[index] for index in vertices]
81+
faces = [[i_index[i] for i in face] for face in faces]
82+
faces = unify_cycles(vertices, faces)
83+
84+
mesh = Mesh.from_vertices_and_faces(vertices, faces)
85+
86+
viewer = MeshViewer(mesh)
87+
88+
viewer.setup()
89+
viewer.show()
4990
5091
"""
5192
points = asarray(points)
@@ -73,10 +114,18 @@ def convex_hull_xy_numpy(points):
73114
74115
Returns
75116
-------
76-
tuple
117+
list
77118
Indices of the points on the hull.
119+
list
78120
Faces of the hull.
79121
122+
Notes
123+
-----
124+
The faces of the hull returned by this function do not necessarily have consistent
125+
cycle directions. To obtain a mesh with consistent cycle directions, construct
126+
a mesh from the returned vertices, this function should be used in combination
127+
with :func:`compas.topology.unify_cycles`.
128+
80129
Examples
81130
--------
82131
.. code-block:: python
@@ -91,9 +140,6 @@ def convex_hull_xy_numpy(points):
91140

92141
points = points[:, :2]
93142
hull = ConvexHull(points)
94-
# temp = zeros((hull.vertices.shape[0], 1))
95-
# temp[:, :-1] = points[hull.vertices]
96-
# return temp
97143
return hull.vertices, hull.simplices
98144

99145

@@ -108,19 +154,19 @@ def convex_hull_xy_numpy(points):
108154

109155
import random
110156

111-
from compas.geometry.distance import distance_point_point
157+
from compas.geometry import distance_point_point
112158

113159
from compas.datastructures import Mesh
114160
from compas.viewers import MeshViewer
115161

116-
from compas.topology import mesh_unify_cycles
162+
from compas.topology import unify_cycles
117163

118164
radius = 5
119165
origin = (0., 0., 0.)
120166
count = 0
121167
points = []
122168

123-
while count < 10:
169+
while count < 1000:
124170
x = (random.random() - 0.5) * radius * 2
125171
y = (random.random() - 0.5) * radius * 2
126172
z = (random.random() - 0.5) * radius * 2
@@ -134,14 +180,16 @@ def convex_hull_xy_numpy(points):
134180

135181
i_index = {i: index for index, i in enumerate(vertices)}
136182

137-
mesh = Mesh.from_vertices_and_faces(
138-
[points[index] for index in vertices],
139-
[[i_index[i] for i in face] for face in faces[1:]]
140-
)
183+
vertices = [points[index] for index in vertices]
184+
faces = [[i_index[i] for i in face] for face in faces]
185+
faces = unify_cycles(vertices, faces)
141186

142-
mesh_unify_cycles(mesh)
187+
mesh = Mesh.from_vertices_and_faces(vertices, faces)
143188

144189
viewer = MeshViewer(mesh)
145190

191+
viewer.axes_on = False
192+
viewer.grid_on = False
193+
146194
viewer.setup()
147195
viewer.show()

src/compas/plotters/plotter.py

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -31,13 +31,6 @@
3131
__all__ = ['Plotter', ]
3232

3333

34-
# https://matplotlib.org/faq/usage_faq.html#what-is-interactive-mode
35-
# https://matplotlib.org/api/pyplot_summary.html
36-
# https://matplotlib.org/api/figure_api.html#matplotlib.figure.Figure
37-
# https://matplotlib.org/api/axes_api.html
38-
# https://matplotlib.org/api/index.html
39-
40-
4134
class Plotter(object):
4235
"""Definition of a plotter object based on matplotlib.
4336
@@ -76,7 +69,6 @@ class Plotter(object):
7669
Computing In Science & Engineering (9) 3, p.90-95.
7770
Available at: http://ieeexplore.ieee.org/document/4160265/citations.
7871
79-
8072
"""
8173
def __init__(self, figsize=(16.0, 12.0), dpi=100.0, interactive=False, tight=False, **kwargs):
8274
"""Initialises a plotter object"""

src/compas/topology/traversal.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,7 @@ def breadth_first_ordering(adjacency, root):
256256

257257

258258
def breadth_first_traverse(adjacency, root, callback=None):
259+
""""""
259260
tovisit = deque([root])
260261
visited = set([root])
261262

src/compas/viewers/meshviewer.py

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -71,22 +71,22 @@ def display(self):
7171
'color' : (0.4, 0.4, 0.4),
7272
'size' : 5.0})
7373

74-
normals = []
75-
for fkey in self.mesh.faces():
76-
n = self.mesh.face_normal(fkey, unitized=True)
77-
sp = self.mesh.face_centroid(fkey)
78-
ep = [sp[axis] + n[axis] for axis in (0, 1, 2)]
79-
normals.append({
80-
'start' : sp,
81-
'end' : ep,
82-
'color' : (0.0, 1.0, 0.0),
83-
'width' : 2.0
84-
})
74+
# normals = []
75+
# for fkey in self.mesh.faces():
76+
# n = self.mesh.face_normal(fkey, unitized=True)
77+
# sp = self.mesh.face_centroid(fkey)
78+
# ep = [sp[axis] + n[axis] for axis in (0, 1, 2)]
79+
# normals.append({
80+
# 'start' : sp,
81+
# 'end' : ep,
82+
# 'color' : (0.0, 1.0, 0.0),
83+
# 'width' : 2.0
84+
# })
8585

8686
xdraw_polygons(polygons)
8787
xdraw_lines(lines)
8888
xdraw_points(points)
89-
xdraw_lines(normals)
89+
# xdraw_lines(normals)
9090

9191
def keypress(self, key, x, y):
9292
"""

src/compas/viewers/viewer.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,16 +48,27 @@ class Viewer(object):
4848
The width of the viewer window.
4949
height : int
5050
The height of the viewer window.
51-
clear_color : sequence(4)
51+
near : float
52+
Distance of the near clipping plane. Default is `0.1`.
53+
far : float
54+
Distance of the far clipping plane. Default is `1000.0`.
55+
fov : float
56+
Field of view. Default is `50.0`.
57+
clear_color : 4-tuple of float
5258
A sequence of 4 floats defining the background color of the scene.
59+
Default is `(0.9, 0.9, 0.9, 1.0)`.
5360
grid_on : bool
5461
Grid on or off.
62+
axes_on : bool
63+
Grid on or off.
5564
mouse : Mouse
5665
A ``Mouse`` object.
5766
camera : Camera
5867
A ``Camera`` object.
5968
grid : Grid
6069
A ``Grid`` object.
70+
displayfuncs : list of callable
71+
A list of functions called by the display callback to render the scene.
6172
6273
Notes
6374
-----

0 commit comments

Comments
 (0)