Skip to content

Commit b649f45

Browse files
committed
docstring updates
1 parent 00a6a54 commit b649f45

File tree

8 files changed

+285
-337
lines changed

8 files changed

+285
-337
lines changed

src/compas/geometry/__init__.py

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -51,15 +51,13 @@
5151
mesh_smooth_centroid
5252
network_parallelise_edges
5353
network_smooth_centroid
54-
network_smooth_resultant
5554
oriented_bounding_box_numpy
5655
oriented_bounding_box_xy_numpy
5756
planarize_faces
5857
scalarfield_contours_numpy
5958
smooth_area
6059
smooth_centroid
6160
smooth_centerofmass
62-
smooth_resultant
6361
6462
6563
Classes

src/compas/geometry/algorithms/hull.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,10 +37,6 @@ def convex_hull(points):
3737
The triangular faces of the convex hull as lists of vertex indices
3838
referring to the original point coordinates.
3939
40-
References
41-
----------
42-
* https://gist.github.com/anonymous/5184ba0bcab21d3dd19781efd3aae543
43-
4440
Note
4541
----
4642
The algorithm is not optimized and relatively slow on large sets of points.
@@ -80,6 +76,10 @@ def convex_hull(points):
8076
show_vertices = False,
8177
show_edges = False)
8278
79+
References
80+
----------
81+
* https://gist.github.com/anonymous/5184ba0bcab21d3dd19781efd3aae543
82+
8383
"""
8484
def _normal_face(face):
8585
u = subtract_vectors(points[face[1]], points[face[0]])

src/compas/geometry/algorithms/interpolation.py

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -49,15 +49,22 @@ def discrete_coons_patch(ab, bc, dc, ad):
4949
faces : list of lists
5050
List of faces (face = list of vertex indices as integers)
5151
52-
References
53-
----------
54-
* https://en.wikipedia.org/wiki/Coons_patch
55-
* https://www.mathcurve.com/surfaces/patchcoons/patchcoons.shtml
52+
Examples
53+
--------
54+
.. code-block:: python
55+
56+
#
57+
5658
5759
See Also
5860
--------
5961
* :func:`compas.datastructures.mesh_cull_duplicate_vertices`
6062
63+
References
64+
----------
65+
* https://en.wikipedia.org/wiki/Coons_patch
66+
* https://www.mathcurve.com/surfaces/patchcoons/patchcoons.shtml
67+
6168
"""
6269
if not ab:
6370
ab = [ad[0]] * len(dc)

src/compas/geometry/algorithms/isolines.py

Lines changed: 31 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,11 +35,6 @@
3535
def scalarfield_contours_numpy(xy, s, N=50):
3636
r"""Compute the contour lines of a scalarfield.
3737
38-
Note
39-
----
40-
The computation of the contour lines is based on the `contours function`_
41-
available through matplotlib.
42-
4338
Parameters
4439
----------
4540
xy : array-like
@@ -59,6 +54,11 @@ def scalarfield_contours_numpy(xy, s, N=50):
5954
the contours. The second item in the tuple is a list of contour lines.
6055
Each contour line is a list of paths, and each path is a list polygons.
6156
57+
Note
58+
----
59+
The computation of the contour lines is based on the `contours function`_
60+
available through matplotlib.
61+
6262
Examples
6363
--------
6464
.. code-block:: python
@@ -117,7 +117,7 @@ def scalarfield_contours_numpy(xy, s, N=50):
117117
polygons = path.to_polygons()
118118
contours[i][j] = [0] * len(polygons)
119119
for k, polygon in enumerate(iter(polygons)):
120-
contours[i][j][k] = polygon.tolist()
120+
contours[i][j][k] = polygon
121121
return levels, contours
122122

123123

@@ -159,7 +159,7 @@ def mesh_contours_numpy(mesh, N=50):
159159
"""
160160
xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
161161
z = [mesh.vertex_coordinates(key, 'z') for key in mesh.vertices()]
162-
return scalarfield_contours(xy, z, N)
162+
return scalarfield_contours_numpy(xy, z, N)
163163

164164

165165
def mesh_isolines_numpy(mesh, attr_name, N=50):
@@ -186,7 +186,7 @@ def mesh_isolines_numpy(mesh, attr_name, N=50):
186186
"""
187187
xy = [mesh.vertex_coordinates(key, 'xy') for key in mesh.vertices()]
188188
s = [mesh.vertex[key][attr_name] for key in mesh.vertices()]
189-
return scalarfield_contours(xy, s, N)
189+
return scalarfield_contours_numpy(xy, s, N)
190190

191191

192192
# ==============================================================================
@@ -195,4 +195,26 @@ def mesh_isolines_numpy(mesh, attr_name, N=50):
195195

196196
if __name__ == "__main__":
197197

198-
pass
198+
import compas
199+
from compas.datastructures import Mesh
200+
from compas.geometry import centroid_points
201+
from compas.geometry import distance_point_point
202+
from compas.geometry import scalarfield_contours_numpy
203+
204+
mesh = Mesh.from_obj(compas.get('faces.obj'))
205+
206+
points = [mesh.vertex_coordinates(key) for key in mesh.vertices()]
207+
centroid = centroid_points(points)
208+
distances = [distance_point_point(point, centroid) for point in points]
209+
210+
xy = [point[0:2] for point in points]
211+
212+
levels, contours = scalarfield_contours_numpy(xy, distances)
213+
214+
for i in range(len(contours)):
215+
level = levels[i]
216+
contour = contours[i]
217+
print(level)
218+
for path in contour:
219+
for polygon in path:
220+
print([point.tolist() for point in polygon])

src/compas/geometry/algorithms/planarisation.py

Lines changed: 46 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
]
3131

3232

33-
def flatness(vertices, faces, maxdev=1.0):
33+
def flatness(vertices, faces, maxdev=0.02):
3434
"""Compute mesh flatness per face.
3535
3636
Parameters
@@ -41,7 +41,7 @@ def flatness(vertices, faces, maxdev=1.0):
4141
The face vertices.
4242
maxdev : float, optional
4343
A maximum value for the allowed deviation from flatness.
44-
Default is ``1.0``.
44+
Default is ``0.02``.
4545
4646
Returns
4747
-------
@@ -166,9 +166,14 @@ def mesh_flatness(mesh, maxdev=1.0):
166166
This function only works as expected for quadrilateral faces.
167167
168168
"""
169-
vertices = {key: mesh.vertex_coordinates(key) for key in mesh.vertices()}
170-
faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
171-
return flatness(vertices, faces, maxdev=maxdev)
169+
dev = []
170+
for fkey in mesh.faces():
171+
points = mesh.face_coordinates(fkey)
172+
lengths = [distance_point_point(a, b) for a, b in window(points + points[0:1], 2)]
173+
l = sum(lengths) / len(lengths)
174+
d = distance_line_line((points[0], points[2]), (points[1], points[3]))
175+
dev.append((d / l) / maxdev)
176+
return dev
172177

173178

174179
def mesh_planarize_faces(mesh, fixed=None, kmax=100, callback=None, callback_args=None):
@@ -194,6 +199,16 @@ def mesh_planarize_faces(mesh, fixed=None, kmax=100, callback=None, callback_arg
194199
callback_args : list, optional [None]
195200
A list of arguments to be passed to the callback function.
196201
202+
Returns
203+
-------
204+
None
205+
206+
Examples
207+
--------
208+
.. code-block:: python
209+
210+
#
211+
197212
"""
198213
if callback:
199214
if not callable(callback):
@@ -202,21 +217,36 @@ def mesh_planarize_faces(mesh, fixed=None, kmax=100, callback=None, callback_arg
202217
fixed = fixed or []
203218
fixed = set(fixed)
204219

205-
vertices = {key: mesh.vertex_coordinates(key) for key in mesh.vertices()}
206-
faces = [mesh.face_vertices(fkey) for fkey in mesh.faces()]
207-
208220
for k in range(kmax):
209-
planarize_faces(vertices, faces, fixed=fixed, kmax=1)
221+
222+
positions = {key: [] for key in mesh.vertices()}
223+
224+
for fkey in mesh.faces():
225+
vertices = mesh.face_vertices(fkey)
226+
points = [mesh.vertex_coordinates(key) for key in vertices]
227+
plane = bestfit_plane(points)
228+
projections = project_points_plane(points, plane)
229+
230+
for index, key in enumerate(vertices):
231+
positions[key].append(projections[index])
210232

211233
for key, attr in mesh.vertices(True):
212-
attr['x'] = vertices[key][0]
213-
attr['y'] = vertices[key][1]
214-
attr['z'] = vertices[key][2]
234+
if key in fixed:
235+
continue
236+
237+
x, y, z = centroid_points(positions[key])
238+
attr['x'] = x
239+
attr['y'] = y
240+
attr['z'] = z
215241

216242
if callback:
217243
callback(k, callback_args)
218244

219245

246+
def mesh_planarize_faces_numpy(mesh, fixed=None, kmax=100, callback=None, callback_args=None):
247+
pass
248+
249+
220250
def mesh_planarize_faces_shapeop(mesh,
221251
fixed=None,
222252
kmax=100,
@@ -409,20 +439,17 @@ def mesh_circularize_faces_shapeop(mesh,
409439
plotter.draw_faces()
410440
plotter.draw_edges()
411441

412-
key_index = mesh.key_index()
413-
# vertices = mesh.get_vertices_attributes('xyz')
414-
# faces = [[key_index[key] for key in mesh.face_vertices(fkey)] for fkey in mesh.faces()]
415-
# fixed = [key_index[key] for key in fixed]
416-
417442
def callback(k, args):
418-
if k % 10 == 0:
443+
print(k)
444+
445+
if k % 100 == 0:
419446
dev = mesh_flatness(mesh, maxdev=0.02)
420447

421448
plotter.update_vertices(radius=radius)
422449
plotter.update_faces(facecolor={fkey: i_to_rgb(dev[fkey]) for fkey in mesh.faces()})
423450
plotter.update_edges()
424451
plotter.update()
425452

426-
mesh_planarize_faces_shapeop(mesh, fixed=fixed, kmax=1000, callback=callback)
453+
mesh_planarize_faces_shapeop(mesh, fixed=fixed, kmax=2000, callback=callback)
427454

428455
plotter.show()

0 commit comments

Comments
 (0)