不同于布尔运算的交并补 ,此处进行的是对已有的图形的快速分割(splitter)以及合并(glue)
分割(splitter)
- 1.以边分面
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace
from OCC.Display.SimpleGui import init_display
from OCC.Core.GEOMAlgo import GEOMAlgo_Splitter
from OCC.Core.gp import gp_Dir, gp_Pln, gp_Pnt
from OCC.Extend.TopologyUtils import TopologyExplorer
display, start_display, add_menu, add_function_to_menu = init_display()
p0 = gp_Pnt()
vnorm = gp_Dir(1, 0, 0)
pln = gp_Pln(p0, vnorm)
face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
p1 = gp_Pnt(0, 0, 15)
p2 = gp_Pnt(0, 0, -15)
edge = BRepBuilderAPI_MakeEdge(p1, p2).Edge()
# 启动分割函数
splitter = GEOMAlgo_Splitter()
# 将面作为参数,将边edge作为分割工具。
splitter.AddArgument(face)
splitter.AddTool(edge)
splitter.Perform()
# 显示分割后的面
for shape in TopologyExplorer(splitter.Shape()).faces():
display.DisplayShape(shape,update=True)
# 显示使用的工具:边
display.DisplayShape(edge,update=True)
start_display()
- 2.以面分面
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display
from OCC.Core.GEOMAlgo import GEOMAlgo_Splitter
from OCC.Core.gp import gp_Dir, gp_Pln, gp_Pnt
from OCC.Extend.TopologyUtils import TopologyExplorer
display, start_display, add_menu, add_function_to_menu = init_display()
# 第一个面
p0 = gp_Pnt(5,5,5,)
vnorm = gp_Dir(1, 1, 1)
pln = gp_Pln(p0, vnorm)
face1 = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
# 工具面
p0 = gp_Pnt(5,5,5,)
vnorm = gp_Dir(1, 1, 0)
pln = gp_Pln(p0, vnorm)
face2 = BRepBuilderAPI_MakeFace(pln, -20, 20, -20, 20).Face()
# 启动分割函数
splitter = GEOMAlgo_Splitter()
# 将face1作为参数,将面face2作为分割工具。
splitter.AddArgument(face1)
splitter.AddTool(face2)
splitter.Perform()
# 显示分割后的face
for shape in TopologyExplorer(splitter.Shape()).faces():
display.DisplayShape(shape,update=True)
# 显示使用的工具:面
display.DisplayShape(face2,update=True,transparency=0.5,color=rgb_color(1,0.2,0))
start_display()
- 3.以面分体
from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeEdge, BRepBuilderAPI_MakeFace
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakeBox
from OCC.Display.OCCViewer import rgb_color
from OCC.Display.SimpleGui import init_display
from OCC.Core.GEOMAlgo import GEOMAlgo_Splitter
from OCC.Core.gp import gp_Dir, gp_Pln, gp_Pnt
from OCC.Extend.TopologyUtils import TopologyExplorer
display, start_display, add_menu, add_function_to_menu = init_display()
p0 = gp_Pnt(5,5,5,)
vnorm = gp_Dir(1, 1, 1)
pln = gp_Pln(p0, vnorm)
face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10, 10).Face()
box=BRepPrimAPI_MakeBox (10,10,10).Shape()
# 启动分割函数
splitter = GEOMAlgo_Splitter()
# 将box作为参数,将面face作为分割工具。
splitter.AddArgument(box)
splitter.AddTool(face)
splitter.Perform()
# 显示分割后的体
for shape in TopologyExplorer(splitter.Shape()).solids():
display.DisplayShape(shape,update=True)
# 显示使用的工具:面
display.DisplayShape(face,update=True,transparency=0.5,color=rgb_color(1,0.2,0))
start_display()
合并(glue)
参考链接:
https://github.com/tpaviot/pythonocc-demos/blob/master/examples/core_topology_glue.py
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END
暂无评论内容