Skip to content

Commit cfaf6c1

Browse files
committed
add examples
1 parent 932a996 commit cfaf6c1

File tree

8 files changed

+152
-44
lines changed

8 files changed

+152
-44
lines changed

src/compas_cgal/booleans.py

Lines changed: 50 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,9 @@ def _boolean(A, B, operation):
88
99
Parameters
1010
----------
11-
A : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
11+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1212
Mesh A.
13-
B : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
13+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1414
Mesh B.
1515
operation : Literal['union', 'difference', 'intersection']
1616
The type of boolean operation.
@@ -53,9 +53,9 @@ def boolean_union(A, B):
5353
5454
Parameters
5555
----------
56-
A : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
56+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
5757
Mesh A.
58-
B : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
58+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
5959
Mesh B.
6060
operation : Literal['union', 'difference', 'intersection']
6161
The type of boolean operation.
@@ -67,6 +67,20 @@ def boolean_union(A, B):
6767
NDArray[(Any, 3), np.int32]
6868
The faces of the boolean mesh.
6969
70+
Examples
71+
--------
72+
>>> from compas.geometry import Box, Sphere, Polyhedron
73+
>>> from compas_cgal.booleans import boolean_union
74+
75+
>>> box = Box.from_width_height_depth(1, 1, 1)
76+
>>> sphere = Sphere([1, 1, 1], 0.5)
77+
78+
>>> A = box.to_vertices_and_faces(triangulated=True)
79+
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
80+
81+
>>> C = boolean_union(A, B)
82+
>>> shape = Polyhedron(*C)
83+
7084
"""
7185
return _boolean(A, B, 'union')
7286

@@ -77,9 +91,9 @@ def boolean_difference(A, B):
7791
7892
Parameters
7993
----------
80-
A : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
94+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
8195
Mesh A.
82-
B : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
96+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
8397
Mesh B.
8498
operation : Literal['union', 'difference', 'intersection']
8599
The type of boolean operation.
@@ -91,6 +105,20 @@ def boolean_difference(A, B):
91105
NDArray[(Any, 3), np.int32]
92106
The faces of the boolean mesh.
93107
108+
Examples
109+
--------
110+
>>> from compas.geometry import Box, Sphere, Polyhedron
111+
>>> from compas_cgal.booleans import boolean_difference
112+
113+
>>> box = Box.from_width_height_depth(1, 1, 1)
114+
>>> sphere = Sphere([1, 1, 1], 0.5)
115+
116+
>>> A = box.to_vertices_and_faces(triangulated=True)
117+
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
118+
119+
>>> C = boolean_difference(A, B)
120+
>>> shape = Polyhedron(*C)
121+
94122
"""
95123
return _boolean(A, B, 'difference')
96124

@@ -101,9 +129,9 @@ def boolean_intersection(A, B):
101129
102130
Parameters
103131
----------
104-
A : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
132+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
105133
Mesh A.
106-
B : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
134+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
107135
Mesh B.
108136
operation : Literal['union', 'difference', 'intersection']
109137
The type of boolean operation.
@@ -115,5 +143,19 @@ def boolean_intersection(A, B):
115143
NDArray[(Any, 3), np.int32]
116144
The faces of the boolean mesh.
117145
146+
Examples
147+
--------
148+
>>> from compas.geometry import Box, Sphere, Polyhedron
149+
>>> from compas_cgal.booleans import boolean_intersection
150+
151+
>>> box = Box.from_width_height_depth(1, 1, 1)
152+
>>> sphere = Sphere([1, 1, 1], 0.5)
153+
154+
>>> A = box.to_vertices_and_faces(triangulated=True)
155+
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
156+
157+
>>> C = boolean_intersection(A, B)
158+
>>> shape = Polyhedron(*C)
159+
118160
"""
119161
return _boolean(A, B, 'intersection')

src/compas_cgal/intersections.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ def intersection_mesh_mesh(A, B):
99
1010
Parameters
1111
----------
12-
A : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
12+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1313
Mesh A.
14-
B : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
14+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1515
Mesh B.
1616
1717
Returns
1818
-------
1919
list[NDArray[(Any, 3), np.float64]]
2020
A list of intersection polylines, with each polyline an array of points.
2121
22+
Examples
23+
--------
24+
>>> from compas.geometry import Box, Sphere, Polyline
25+
>>> from compas_cgal.intersections import intersection_mesh_mesh
26+
27+
>>> box = Box.from_width_height_depth(1, 1, 1)
28+
>>> sphere = Sphere([1, 1, 1], 0.5)
29+
30+
>>> A = box.to_vertices_and_faces(triangulated=True)
31+
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
32+
33+
>>> result = intersection_mesh_mesh(A, B)
34+
>>> polylines = [Polyline(points) for points in result]
35+
2236
"""
2337
VA, FA = A
2438
VB, FB = B

src/compas_cgal/measure.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,25 @@ def volume(mesh):
99
1010
Parameters
1111
----------
12-
mesh : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
12+
mesh : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1313
The mesh.
1414
1515
Returns
1616
-------
1717
float
1818
The volume of the mesh.
1919
20+
Examples
21+
--------
22+
>>> from compas.geometry import Box
23+
>>> from compas_cgal.measure import volume
24+
25+
>>> box = Box.from_width_height_depth(1, 1, 1)
26+
>>> mesh = box.to_vertices_and_faces(triangulated=True)
27+
28+
>>> volume(mesh)
29+
1.0
30+
2031
"""
2132
V, F = mesh
2233
V = np.asarray(V, dtype=np.float64)

src/compas_cgal/meshing.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ def remesh(mesh, target_edge_length, number_of_iterations=10, do_project=True):
99
1010
Parameters
1111
----------
12-
mesh : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
12+
mesh : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1313
The mesh to remesh.
1414
target_edge_length : float
1515
The target edge length.
@@ -30,6 +30,17 @@ def remesh(mesh, target_edge_length, number_of_iterations=10, do_project=True):
3030
This remeshing function only constrains the edges on the boundary of the mesh.
3131
Protecting specific features or edges is not implemented yet.
3232
33+
Examples
34+
--------
35+
>>> from compas.geometry import Sphere, Polyhedron
36+
>>> from compas_cgal.meshing import remesh
37+
38+
>>> sphere = Sphere([1, 1, 1], 0.5)
39+
>>> mesh = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
40+
41+
>>> result = remesh(mesh)
42+
>>> shape = Polyhedron(*result)
43+
3344
"""
3445
V, F = mesh
3546
V = np.asarray(V, dtype=np.float64)

src/compas_cgal/slicer.py

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,30 @@ def slice_mesh(mesh, planes):
99
1010
Parameters
1111
----------
12-
mesh : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
12+
mesh : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1313
The mesh to slice.
14-
planes : list[[point, normal] | :class:`compas.geometry.Plane`]
14+
planes : list[[point, normal] | :class:`~compas.geometry.Plane`]
1515
The slicing planes.
1616
1717
Returns
1818
-------
1919
list[NDArray[(Any, 3), np.float64]]
2020
A list of slice polylines, with each polyline an array of points.
2121
22+
Examples
23+
--------
24+
>>> from compas.geometry import Sphere, Plane, Polylines
25+
>>> from compas.utilities import linspace
26+
>>> from compas_cgal.slicer import slice_mesh
27+
28+
>>> sphere = Sphere([0, 0, 1.0], 1.0)
29+
>>> mesh = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
30+
31+
>>> planes = [Plane([0, 0, z], [0, 0, 1.0]) for z in linspace(0.1, 1.9, 19)]
32+
33+
>>> result = slice_mesh(mesh, planes)
34+
>>> polylines = [Polyline(points) for points in result]
35+
2236
"""
2337
vertices, faces = mesh
2438
points, normals = zip(*planes)

src/compas_cgal/subdivision.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ def catmull_clark(mesh, k=1):
77
88
Parameters
99
----------
10-
mesh : tuple[Sequence[[float, float, float] | :class:`compas.geometry.Point`], Sequence[[int, int, int]]]
10+
mesh : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
1111
The mesh to remesh.
1212
k : int, optional
1313
The number of subdivision steps.
@@ -19,6 +19,17 @@ def catmull_clark(mesh, k=1):
1919
NDArray[(Any, 4), np.int32]
2020
The faces of the subdivided mesh.
2121
22+
Examples
23+
--------
24+
>>> from compas.geometry import Box, Polyhedron
25+
>>> from compas_cgal.subdivision import catmull_clark
26+
27+
>>> box = Box.from_width_height_depth(1, 1, 1)
28+
>>> mesh = box.to_vertices_and_faces()
29+
30+
>>> result = catmull_clark(mesh, k=3)
31+
>>> shape = Polyhedron(*result)
32+
2233
"""
2334
V, F = mesh
2435
V = np.asarray(V, dtype=np.float64)

src/compas_cgal/triangulation.py

Lines changed: 30 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -9,17 +9,24 @@ def delaunay_triangulation(points):
99
1010
Parameters
1111
----------
12-
points : list of :class:`compas.geometry.Point`
12+
points : list of :class:`~compas.geometry.Point`
1313
Points of the triangulation.
1414
1515
Returns
1616
-------
17-
list
17+
NDArray[(Any, 3), np.int32]
1818
The faces of the triangulation.
1919
20-
Notes
21-
-----
22-
...
20+
Examples
21+
--------
22+
>>> from compas.geometry import Pointcloud
23+
>>> from compas.datastructures import Mesh
24+
>>> from compas_cgal.triangulation import delaunay_triangulation
25+
26+
>>> points = Pointcloud.from_bounds(8, 5, 0, 17)
27+
>>> triangles = delaunay_triangulation(points)
28+
29+
>>> mesh = Mesh.from_vertices_and_faces(points, triangles)
2330
2431
"""
2532
vertices = np.asarray(points, dtype=np.float64)
@@ -32,23 +39,21 @@ def constrained_delaunay_triangulation(boundary, points=None, holes=None, curves
3239
3340
Parameters
3441
----------
35-
boundary : :class:`compas.geometry.Polygon`
42+
boundary : :class:`~compas.geometry.Polygon`
3643
The boundary of the triangulation.
37-
points : list of :class:`compas.geometry.Point`, optional
44+
points : list of :class:`~compas.geometry.Point`, optional
3845
Additional internal points.
39-
holes : list of :class:`compas.geometry.Polygon`, optional
46+
holes : list of :class:`~compas.geometry.Polygon`, optional
4047
Internal boundary polygons.
41-
curves : list of :class:`compas.geometry.Polyline`, optional
48+
curves : list of :class:`~compas.geometry.Polyline`, optional
4249
Internal constraint curves.
4350
4451
Returns
4552
-------
46-
list
47-
The vertices and faces of the triangulation.
48-
49-
Notes
50-
-----
51-
...
53+
NDArray[(Any, 3), np.float64]
54+
The vertices of the triangulation.
55+
NDArray[(Any, 3), np.int32]
56+
The faces of the triangulation.
5257
5358
"""
5459
boundary = np.asarray(boundary, dtype=np.float64)
@@ -75,20 +80,20 @@ def conforming_delaunay_triangulation(boundary, points=None, holes=None, curves=
7580
7681
Parameters
7782
----------
78-
boundary : :class:`compas.geometry.Polygon`
83+
boundary : :class:`~compas.geometry.Polygon`
7984
The boundary of the triangulation.
80-
points : list[:class:`compas.geometry.Point`], optional
85+
points : list[:class:`~compas.geometry.Point`], optional
8186
Additional internal points.
82-
holes : list[:class:`compas.geometry.Polygon`], optional
87+
holes : list[:class:`~compas.geometry.Polygon`], optional
8388
Internal boundary polygons.
84-
curves : list[:class:`compas.geometry.Polyline`], optional
89+
curves : list[:class:`~compas.geometry.Polyline`], optional
8590
Internal constraint curves.
8691
8792
Returns
8893
-------
89-
(V, 3) np.array[float]
94+
NDArray[(Any, 3), np.float64]
9095
The vertices of the triangulation.
91-
(F, 3) np.array[int]
96+
NDArray[(Any, 3), np.int32]
9297
The faces of the triangulation.
9398
9499
"""
@@ -115,13 +120,13 @@ def refined_delaunay_mesh(boundary, points=None, holes=None, curves=None, maxlen
115120
116121
Parameters
117122
----------
118-
boundary : :class:`compas.geometry.Polygon`
123+
boundary : :class:`~compas.geometry.Polygon`
119124
The boundary of the triangulation.
120-
points : list[:class:`compas.geometry.Point`], optional
125+
points : list[:class:`~compas.geometry.Point`], optional
121126
Additional internal points.
122-
holes : list[:class:`compas.geometry.Polygon`], optional
127+
holes : list[:class:`~compas.geometry.Polygon`], optional
123128
Internal boundary polygons.
124-
curves : list[:class:`compas.geometry.Polyline`], optional
129+
curves : list[:class:`~compas.geometry.Polyline`], optional
125130
Internal constraint curves.
126131
maxlength : float, optional
127132
The maximum length of the triangle edges.

src/compas_cgal/trimesh.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -221,7 +221,7 @@ def from_mesh(cls, mesh):
221221
222222
Parameters
223223
----------
224-
mesh : :class:`compas.datastructures.Mesh`
224+
mesh : :class:`~compas.datastructures.Mesh`
225225
A COMPAS mesh data structure.
226226
227227
Returns
@@ -237,7 +237,7 @@ def to_mesh(self):
237237
238238
Returns
239239
-------
240-
:class:`compas.datastructures.Mesh`
240+
:class:`~compas.datastructures.Mesh`
241241
242242
"""
243243
return Mesh.from_vertices_and_faces(self.vertices, self.faces)
@@ -258,7 +258,7 @@ def transform(self, T):
258258
259259
Parameters
260260
----------
261-
T : :class:`compas.geometry.Transformation`
261+
T : :class:`~compas.geometry.Transformation`
262262
A 4x4 transformation matrix.
263263
264264
Returns
@@ -273,7 +273,7 @@ def transformed(self, T):
273273
274274
Parameters
275275
----------
276-
T : :class:`compas.geometry.Transformation`
276+
T : :class:`~compas.geometry.Transformation`
277277
A 4x4 transformation matrix.
278278
279279
Returns

0 commit comments

Comments
 (0)