Skip to content

Commit 5a7b4d4

Browse files
committed
explore the updated boolean API ( Generalized Fuse )
1 parent fdfb6e6 commit 5a7b4d4

2 files changed

Lines changed: 54 additions & 0 deletions

File tree

OCCUtils/boolean.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
2+
import logging
3+
from typing import Iterable
4+
5+
from OCC.Core.BOPAlgo import BOPAlgo_MakerVolume
6+
from OCC.Core.TopTools import TopTools_ListOfShape
7+
from OCC.Core.TopoDS import TopoDS_Shape
8+
9+
log = logging.getLogger("OCCUtils")
10+
11+
12+
def common_volume(shapes):
13+
# type: (Iterable) -> TopoDS_Shape
14+
mv = BOPAlgo_MakerVolume()
15+
ls = TopTools_ListOfShape()
16+
for i in shapes:
17+
ls.Append(i)
18+
mv.SetArguments(ls)
19+
mv.Perform()
20+
21+
log.debug("error status: {}".format(mv.ErrorStatus()))
22+
23+
return mv.Shape()

examples/occutils_boolean.py

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
from OCC.Core.gp import gp_Pln
2+
from OCC.Core.gp import gp_Pnt, gp_Vec
3+
from OCC.Display.SimpleGui import init_display
4+
from OCCUtils import Topo
5+
from OCCUtils.Construct import make_box, make_face
6+
from OCCUtils.Construct import vec_to_dir
7+
from OCCUtils.boolean import common_volume
8+
9+
10+
def test_common_volume():
11+
display, start_display, add_menu, add_function_to_menu = init_display()
12+
13+
box = make_box(100, 100, 100)
14+
15+
p, v = gp_Pnt(50, 50, 50), gp_Vec(0, 0, -1)
16+
pln = gp_Pln(p, vec_to_dir(v))
17+
fc = make_face(pln, -1000, 1000, -1000, 1000) # limited, not infinite plane
18+
19+
display.DisplayShape(fc, transparency=0.5)
20+
common_shape = common_volume([box, fc])
21+
22+
solids = Topo(common_shape).solids()
23+
display.DisplayShape(next(solids), transparency=0.5)
24+
display.DisplayColoredShape(next(solids), "BLACK")
25+
26+
display.FitAll()
27+
start_display()
28+
29+
30+
if __name__ == "__main__":
31+
test_common_volume()

0 commit comments

Comments
 (0)