Skip to content

Commit fa34dc7

Browse files
committed
add docs
1 parent 87f6e38 commit fa34dc7

File tree

5 files changed

+94
-1
lines changed

5 files changed

+94
-1
lines changed
131 KB
Loading

docs/examples/booleans_split.py

Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
from compas.geometry import Point
2+
from compas.geometry import Box
3+
from compas.geometry import Sphere
4+
from compas.datastructures import Mesh
5+
from compas.colors import Color
6+
from random import random
7+
8+
from compas_view2.app import App
9+
10+
from compas_cgal.booleans import split
11+
from compas.topology import connected_components
12+
13+
# ==============================================================================
14+
# Make a box and a sphere
15+
# ==============================================================================
16+
17+
box = Box.from_width_height_depth(2, 2, 2)
18+
box = Mesh.from_shape(box)
19+
box.quads_to_triangles()
20+
21+
A = box.to_vertices_and_faces()
22+
23+
sphere = Sphere(Point(1, 1, 1), 1)
24+
sphere = Mesh.from_shape(sphere, u=20, v=20)
25+
sphere.quads_to_triangles()
26+
27+
B = sphere.to_vertices_and_faces()
28+
29+
# ==============================================================================
30+
# Compute the mesh split
31+
# ==============================================================================
32+
33+
V, F = split(A, B)
34+
35+
mesh = Mesh.from_vertices_and_faces(V, F)
36+
37+
# ==============================================================================
38+
# Seperate disjoint faces and visualize
39+
# ==============================================================================
40+
41+
viewer = App()
42+
43+
fa = mesh.face_adjacency()
44+
parts = connected_components(fa)
45+
for face_indexes in connected_components(fa):
46+
mesh = Mesh.from_vertices_and_faces(V, F[face_indexes])
47+
mesh.remove_unused_vertices()
48+
viewer.add(mesh, facecolor=Color.from_i(random()))
49+
50+
viewer.run()

docs/examples/mesh_split.rst

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
********************************************************************************
2+
Mesh Split
3+
********************************************************************************
4+
5+
.. figure:: /_images/cgal_boolean_split.jpg
6+
:figclass: figure
7+
:class: figure-img img-fluid
8+
9+
10+
.. literalinclude:: booleans_split.py
11+
:language: python

src/compas_cgal/__init__.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
booleans.boolean_union
1616
booleans.boolean_difference
1717
booleans.boolean_intersection
18+
booleans.split
1819
1920
Intersections
2021
=============

src/compas_cgal/booleans.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,37 @@ def boolean_intersection(A, B):
165165

166166
@plugin(category='booleans', pluggable_name='split_mesh_mesh')
167167
def split(A, B):
168-
"""
168+
"""Split one mesh with another.
169+
170+
Parameters
171+
----------
172+
A : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
173+
Mesh A.
174+
B : tuple[Sequence[[float, float, float] | :class:`~compas.geometry.Point`], Sequence[[int, int, int]]]
175+
Mesh B.
176+
operation : Literal['union', 'difference', 'intersection']
177+
The type of boolean operation.
178+
179+
Returns
180+
-------
181+
NDArray[(Any, 3), np.float64]
182+
The vertices of the boolean mesh.
183+
NDArray[(Any, 3), np.int32]
184+
The faces of the boolean mesh.
185+
186+
Examples
187+
--------
188+
>>> from compas.geometry import Box, Sphere, Polyhedron
189+
>>> from compas_cgal.booleans import split
190+
191+
>>> box = Box.from_width_height_depth(1, 1, 1)
192+
>>> sphere = Sphere([1, 1, 1], 0.5)
193+
194+
>>> A = box.to_vertices_and_faces(triangulated=True)
195+
>>> B = sphere.to_vertices_and_faces(u=32, v=32, triangulated=True)
196+
197+
>>> V, F = split(A, B)
198+
>>> mesh = Mesh.from_vertices_and_faces(V, F)
199+
169200
"""
170201
return _boolean(A, B, 'split')

0 commit comments

Comments
 (0)