def slicer(event=None): # Param Zmin, Zmax, deltaZ = -100, 100, 5 # Note: the shape can also come from a shape selected from InteractiveViewer if 'display' in dir(): shape = display.GetSelectedShape() else: # Create the shape to slice shape = BRepPrimAPI_MakeSphere(60.).Shape() # Define the direction D = gp_Dir(0., 0., 1.) # the z direction # Perform slice sections = [] init_time = time.time() # for total time computation for z in range(Zmin, Zmax, deltaZ): # Create Plane defined by a point and the perpendicular direction P = gp_Pnt(0, 0, z) Pln = gp_Pln(P, D) face = BRepBuilderAPI_MakeFace(Pln).Shape() # Computes Shape/Plane intersection section_shp = BRepAlgoAPI_Section(shape, face) if section_shp.IsDone(): sections.append(section_shp) total_time = time.time() - init_time print("%.3fs necessary to perform slice." % total_time) display.EraseAll() display.DisplayShape(shape) for section_ in sections: display.DisplayShape(section_.Shape()) display.FitAll()
def plane_shape_intersection(plane_face, shape): edges = [] section = BRepAlgoAPI_Section(shape, plane_face) section.Approximation(True) section.Build() section_edges = section.SectionEdges() while (section_edges.IsEmpty() != True): edges.append(section_edges.First()) section_edges.RemoveFirst() return edges
def plane_shape_intersection(plane_face, shape): edges = [] section = BRepAlgoAPI_Section(shape, plane_face) section.Approximation(True) section.Build() section_edges = section.SectionEdges() while (section_edges.IsEmpty() != True): edges.append(section_edges.First()) display.DisplayShape(section_edges.First(), color='BLACK', update=False) section_edges.RemoveFirst() return edges
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 vectorized_slicer(li): # Create Plane defined by a point and the perpendicular direction z_values, shape = li _slices = [] for z in z_values: #print 'slicing index:', z, 'sliced by process:', os.getpid() plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shape, face) section.Build() if section.IsDone(): _slices.append(section.Shape()) return _slices
def inter_objects(self): from OCC.Core.GProp import GProp_GProps from OCC.Core.BRepGProp import brepgprop_VolumeProperties, brepgprop_SurfaceProperties, \ brepgprop_LinearProperties from OCC.Core.BRepAlgoAPI import BRepAlgoAPI_Fuse, BRepAlgoAPI_Common, BRepAlgoAPI_Section, BRepAlgoAPI_Cut # print('Start_inter_analyse') inter_mass = 0 props = GProp_GProps() # print(self.names_models) names = [] for name in self.modules: names.append(name) if len(names) > 1: for i in range(len(names) - 1): for j in range(i + 1, len(names)): # print(self.names_models[i], self.names_models[j]) if self.names_models[i] == self.names_models[j]: continue body_inter = BRepAlgoAPI_Section( self.modules[self.names_models[i]], self.modules[self.names_models[j]]).Shape() brepgprop_LinearProperties(body_inter, props) mass = props.Mass() # print(mass) if mass > 0: inter_mass += mass # self.start_display() return inter_mass
def inter_objects(self): # print('Start_inter_analyse') self.inter_mass = 0 props = GProp_GProps() # print(self.names_models) for i in range(len(self.names_models) - 1): for j in range(i + 1, len(self.names_models)): # self.display.DisplayShape(self.modules[self.names_models[i]], color='RED', transparency=0.9) # self.display.DisplayShape(self.modules[self.names_models[j]], color='RED', transparency=0.9) print(self.names_models[i], self.names_models[j]) if self.names_models[i] == self.names_models[j]: continue body_inter = BRepAlgoAPI_Section( self.modules[self.names_models[i]], self.modules[self.names_models[j]]).Shape() # self.display.DisplayShape(body_inter, color='WHITE') brepgprop_LinearProperties(body_inter, props) mass = props.Mass() print(mass) if mass > 0: self.inter_mass += mass self.valume_inter_obj[self.names_models[i]][ self.names_models[j]] = mass #self.start_display() return self.inter_mass
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 _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 GetSectionShape(z, shapes): # the mid z value of the storey, list of the storey shapes if isinstance(shapes, list): shapes_compound, if_all_compound = list_of_shapes_to_compound(shapes) plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shapes_compound, face) section.Build() if section.IsDone(): print("Successfully get the section shape") return section.Shape() else: print("ERROR, the section shape cannot be built") else: plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0., 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shapes, face) section.Build() if section.IsDone(): print("Successfully get the section shape") return section.Shape()
def glue_solids(self, S2): bbox = Bnd_Box() brepbndlib_Add(S2, bbox) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() p0 = gp_Pnt(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin + 0.1) vnorm = gp_Dir(0, 0, 1) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -(xmax - xmin) / 2 - 1, (xmax - xmin) / 2 + 1, -(ymax - ymin) / 2 - 1, (ymax - ymin) / 2 + 1).Face() facesS_2 = BRepAlgoAPI_Section(face, S2).Shape() return self.max_counter(facesS_2)
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 inter_objects(self): # print('Start_inter_analyse') inter_mass = 0 props = GProp_GProps() # print(self.names_models) for i in range(len(self.names_models) - 1): for j in range(i + 1, len(self.names_models)): # print(self.names_models[i], self.names_models[j]) if self.names_models[i] == self.names_models[j]: continue body_inter = BRepAlgoAPI_Section( self.modules[self.names_models[i]], self.modules[self.names_models[j]]).Shape() brepgprop_LinearProperties(body_inter, props) mass = props.Mass() # print(mass) if mass > 0: inter_mass += mass # self.start_display() return inter_mass
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)
def glue_solids(event=None): display.EraseAll() display.Context.RemoveAll(True) # Without common edges S1 = BRepPrimAPI_MakeBox(gp_Pnt(500., 500., 0.), gp_Pnt(100., 250., 300.)).Shape() # S2 = BRepPrimAPI_MakeBox(gp_Pnt(300., 300., 300.), gp_Pnt(600., 600., 600.)).Shape() S2 = read_step_file(os.path.join('..', 'part_of_sattelate', 'pribore', 'Camara_WS16.STEP')) bbox = Bnd_Box() brepbndlib_Add(S2, bbox) xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get() print(bbox.Get()) p0 = gp_Pnt(xmin + (xmax - xmin) / 2, ymin + (ymax - ymin) / 2, zmin+0.01) vnorm = gp_Dir(0, 0, 1) pln = gp_Pln(p0, vnorm) face = BRepBuilderAPI_MakeFace(pln, -(xmax - xmin) / 2 - 1, (xmax - xmin) / 2 + 1, -(ymax - ymin) / 2 - 1, (ymax - ymin) / 2 + 1).Face() # face = BRepBuilderAPI_MakeFace(pln, -10, 10, -10,10).Face() '''planeZ = BRepBuilderAPI_MakeFace( gp_Pln(gp_Pnt(xmin, ymin, zmin), gp_Pnt(xmax, ymax, zmin), gp_Pnt(xmin, ymax, zmin))).Face()''' facesS_2 = BRepAlgoAPI_Section(face, S2).Shape() # print(facesS_2) display.DisplayShape(face, update=True) display.DisplayShape(S2, update=True) display.DisplayShape(facesS_2, update=True) section_edges = list(Topo(facesS_2).edges()) print(len(section_edges)) '''toptool_seq_shape = TopTools_SequenceOfShape() for edge in section_edges: toptool_seq_shape.Append(edge)''' Wire_c = BRepBuilderAPI_MakeWire() prep_list = [] Wire_c.Add(section_edges[0]) prep_list.append(section_edges[0]) ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX) # no need for a loop since we know for a fact that # the edge has only one start and one end c = ex.Current() cv = topods_Vertex(c) v0 = BRep_Tool_Pnt(cv) ex.Next() c = ex.Current() cv = topods_Vertex(c) v1 = BRep_Tool_Pnt(cv) section_edges.pop(0) flag = 0 wires = [] while len(section_edges) > 0: new_list = [] for edges in section_edges: #Wire_c.Add(edges) ex = TopExp_Explorer(edges, TopAbs_VERTEX) c = ex.Current() cv = topods_Vertex(c) End_1 = BRep_Tool_Pnt(cv) ex.Next() c = ex.Current() cv = topods_Vertex(c) End_2 = BRep_Tool_Pnt(cv) if End_1.X() == v0.X() and End_1.Y() == v0.Y() and End_1.Z() == v0.Z(): Wire_c.Add(edges) v0 = End_2 flag = 0 elif End_1.X() == v1.X() and End_1.Y() == v1.Y() and End_1.Z() == v1.Z(): Wire_c.Add(edges) v1 = End_2 flag = 0 elif End_2.X() == v0.X() and End_2.Y() == v0.Y() and End_2.Z() == v0.Z(): Wire_c.Add(edges) v0 = End_1 flag = 0 elif End_2.X() == v1.X() and End_2.Y() == v1.Y() and End_2.Z() == v1.Z(): Wire_c.Add(edges) v1 = End_1 flag = 0 else: new_list.append(edges) flag += 1 section_edges = new_list if flag >= 5: print('number_ostalos', len(section_edges)) wires.append(Wire_c.Wire()) #wir = Wire_c.Wire() print('ttttt') Wire_c = BRepBuilderAPI_MakeWire() Wire_c.Add(section_edges[0]) ex = TopExp_Explorer(section_edges[0], TopAbs_VERTEX) # no need for a loop since we know for a fact that # the edge has only one start and one end c = ex.Current() cv = topods_Vertex(c) v0 = BRep_Tool_Pnt(cv) ex.Next() c = ex.Current() cv = topods_Vertex(c) v1 = BRep_Tool_Pnt(cv) section_edges.pop(0) flag = 0 # wires.append(Wire_c.Wire()) wires.append(bild_wire(Wire_c)) props = GProp_GProps() yellow_wire = wires[0] brown_face = BRepBuilderAPI_MakeFace(yellow_wire) brown_face = brown_face.Face() brepgprop_SurfaceProperties(brown_face, props) face_surf = props.Mass() print(face_surf) #display.DisplayColoredShape(brown_face.Face(), 'BLUE') areas = [] props = GProp_GProps() for wire in wires: brown_face = BRepBuilderAPI_MakeFace(wire) brown_face = brown_face.Face() #props = GProp_GProps() brepgprop_SurfaceProperties(brown_face, props) areas.append(props.Mass()) print(areas) print(len(wires))
def peeping_frame(self, model): facesS_2 = BRepAlgoAPI_Section(self.frame, self.modules[model]).Shape() return self.max_counter(facesS_2)
builder = BRep_Builder() breptools_Read(cylinder_head, './core_example/cylinder_head.brep', builder) return cylinder_head if __name__ == '__main__': shp = get_brep() xyz_min_max = get_boundingbox(shp) p1 = gp_Pnt(*xyz_min_max[0:3]) p2 = gp_Pnt(*xyz_min_max[3:]) box = make_box(p1, p2) obj = plotocc() obj.display.DisplayShape(box, transparency=0.9) obj.display.DisplayShape(shp) z_delta = abs(xyz_min_max[2] - xyz_min_max[5]) for z in np.linspace(xyz_min_max[2], xyz_min_max[5], 5): print(z) plane = gp_Pln(gp_Pnt(0., 0., z), gp_Dir(0., 0.0, 1.)) face = BRepBuilderAPI_MakeFace(plane).Shape() # Computes Shape/Plane intersection section = BRepAlgoAPI_Section(shp, face) section.Build() if section.IsDone(): obj.display.DisplayShape(section.Shape(), color="BLUE") obj.export_stp(section.Shape()) obj.show_axs_pln(scale=75) obj.show()
ordered = [s[::-1] for s in ordered[::-1]] if ordered[0] == first: ordered = ordered 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():