def cut_solid_parts(array): from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section from OCC.Core.BRepFeat import BRepFeat_SplitShape from OCC.TopTools import TopTools_ListIteratorOfListOfShape from OCC.Extend.TopologyUtils import TopologyExplorer from OCC.Core.TopoDS import TopoDS_Face #array contains several parts for i, si in enumerate(array): #for ki in si.dico: shpi = si.solid split = BRepFeat_SplitShape(shpi) for j, sj in enumerate(array): if i != j: shpj = sj.solid sect = BRepAlgoAPI_Section(shpi, shpj, False) sect.ComputePCurveOn1(True) sect.Approximation(True) sect.SetFuzzyValue(1.e-12) sect.Build() shpsect = sect.Shape() for edg in TopologyExplorer(shpsect).edges(): face = TopoDS_Face() if sect.HasAncestorFaceOn1(edg, face): split.Add(edg, face) split.Build() lst = TopTools_ListIteratorOfListOfShape(split.Modified(shpi)) while lst.More(): for face in TopologyExplorer(lst.Value()).faces(): array[i].splitsolid.append(face) lst.Next()
def _section(a, b, pretty): algo = BRepAlgoAPI_Section(a.Shape(), b.Shape()) if pretty: algo.ComputePCurveOn1(True) algo.Approximation(True) algo.Build() if not algo.IsDone(): printf("warn: section algotithm failed\n") return Shape(algo.Shape())
def section(event=None): torus = BRepPrimAPI_MakeTorus(120, 20).Shape() radius = 120.0 sections = [] for i in range(-3, 4): # Create Sphere sphere = BRepPrimAPI_MakeSphere(gp_Pnt(26 * 3 * i, 0, 0), radius).Shape() # Computes Torus/Sphere section section_shp = BRepAlgoAPI_Section(torus, sphere, False) section_shp.ComputePCurveOn1(True) section_shp.Approximation(True) section_shp.Build() sections.append(section_shp) rnd = JupyterRenderer() rnd.DisplayShape(torus) rnd.Display()
def split_shape(event=None): S = BRepPrimAPI_MakeBox(gp_Pnt(-100, -60, -80), 150, 200, 170).Shape() asect = BRepAlgoAPI_Section(S, gp_Pln(1, 2, 1, -15), False) asect.ComputePCurveOn1(True) asect.Approximation(True) asect.Build() R = asect.Shape() asplit = BRepFeat_SplitShape(S) for edg in TopologyExplorer(R).edges(): face = TopoDS_Face() if asect.HasAncestorFaceOn1(edg, face): asplit.Add(edg, face) asplit.Build() display.EraseAll() display.DisplayShape(asplit.Shape()) display.FitAll()
def split_shells_by_solid(array, solid, display): from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Section from OCC.Core.BRepFeat import BRepFeat_SplitShape from OCC.TopTools import TopTools_ListIteratorOfListOfShape from OCC.Extend.TopologyUtils import TopologyExplorer from OCC.Core.TopoDS import TopoDS_Face for i, si in enumerate(array): for ki in si.dico: print ki sfi = si.dico[ki] split = BRepFeat_SplitShape(sfi.Shape()) sect = BRepAlgoAPI_Section(solid, sfi.Shape(), False) sect.ComputePCurveOn1(True) sect.Approximation(True) sect.SetFuzzyValue(1.e-12) sect.Build() shpsect = sect.Shape() for edg in TopologyExplorer(shpsect).edges(): face = TopoDS_Face() if sect.HasAncestorFaceOn1(edg, face): split.Add(edg, face) split.Build() ais_shape = display.DisplayColoredShape(split.Shape(), color='RED') display.Context.SetTransparency(ais_shape, 0.5)
else: ordered = ordered[::-1] pol = [ordered[0][0], ordered[0][1]] for s in ordered[1:]: pol.append(s[1]) return Polyline3D(pol) from dactylos.cad_functions import polyline3d_to_edges for f in faces1: #display.DisplayColoredShape(faces1[f],'BLUE') #iterator = TopTools_ListIteratorOfListOfShape(explorer) section = BRepAlgoAPI_Section(faces1[f].Shape(), faces_ax[faces_ax.keys()[0]].Shape(), False) #section.SetFuzzyValue(1.e-18) section.ComputePCurveOn1(True) section.ComputePCurveOn2(True) section.Approximation(True) section.Build() #dumpTopology(section.Shape()) display.DisplayColoredShape(section.Shape(), 'GREEN') all_points = [] all_edges = [] for edg in Topo(section.Shape()).edges(): brt = BRep_Tool() print '--- edge -----' edge_points = [] tpedg = Topo(edg) for v in tpedg.vertices(): pnt = brt.Pnt(topods_Vertex(v)) edge_points.append(Point([pnt.X(), pnt.Y(), pnt.Z()]))