def plot_3d(self): print("ok") self.display.DisplayShape(gp_Pnt()) pln_x = make_plane(gp_Pnt(self.sig[0], 0, 0), gp_Vec(1, 0, 0)) self.display.DisplayShape(pln_x, color="RED", transparency=0.5) pln_y = make_plane(gp_Pnt(0, self.sig[1], 0), gp_Vec(0, 1, 0)) self.display.DisplayShape(pln_y, color="GREEN", transparency=0.5) pln_z = make_plane(gp_Pnt(0, 0, self.sig[2]), gp_Vec(0, 0, 1)) self.display.DisplayShape(pln_z, color="BLUE", transparency=0.5) for i, data in enumerate(self.dat): xyz = data[0], data[1], data[2] self.display.DisplayShape(gp_Pnt(*xyz))
def __init__(self, axs=gp_Ax3()): self.rot = axs self.axs = gp_Ax3(self.rot.Ax2()) self.rim = make_edge(gp_Circ(self.axs.Ax2(), 100)) self.pln = dispocc.make_plane_axs(self.axs) self.surf = make_plane(self.axs.Location(), dir_to_vec(self.axs.Direction()), -500, 500, -500, 500)
def set_surface(filename): if os.path.exists(filename): shp = read_step_file(filename) for face in Topo(shp).faces(): surf = face else: surf = make_plane() return surf
def set_obj(meta, xyz, dx, dy, pln_set=[-200, 200, -200, 200], indx=1): vx = gp_Vec(*dx).Normalized() vy = gp_Vec(*dy).Normalized() vz = vx.Crossed(vy) meta["pnt"] = gp_Pnt(*xyz) meta["xyz"] = [vx, vy, vz] meta["pln"] = make_plane(meta["pnt"], meta["xyz"][2], *pln_set) meta["pts"] = shape_to_pts(meta["pln"]) meta["frm"] = set_wire(meta["pts"]) meta["idx"] = indx
def Reflect(self): h_surf = BRep_Tool.Surface(self.tar.srf) g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction()) ray = Geom_Line(g_line) if GeomAPI_IntCS(ray, h_surf).NbPoints(): self.tar.beam = reflect(self.ini.beam, self.tar.srf) else: pln = make_plane(self.tar.axs.Location(), dir_to_vec(self.tar.axs.Direction()), 500, -500, 500, -500) self.tar.beam = reflect(self.ini.beam, pln)
def reflect(beam, face, axs=gp_Ax3()): p0, v0 = beam.Location(), dir_to_vec(beam.Direction()) h_surf = BRep_Tool.Surface(face) ray = Geom_Line(gp_Lin(p0, vec_to_dir(v0))) if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0: print("Out of Surface", axs.Location()) pln = make_plane(axs.Location(), dir_to_vec(axs.Direction()), 500, -500, 500, -500) h_surf = BRep_Tool.Surface(pln) GeomAPI_IntCS(ray, h_surf).IsDone() uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1) u, v, w = uvw p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy) vz = vx.Crossed(vy) vx.Normalize() vy.Normalize() vz.Normalize() v1 = v0.Mirrored(gp_Ax2(p1, vec_to_dir(vz), vec_to_dir(vx))) return gp_Ax3(p1, vec_to_dir(v1), beam.XDirection().Reversed())
def Reflect(self, beam=gp_Ax3(), surf=make_plane()): h_surf = BRep_Tool.Surface(surf) ray = Geom_Line(beam.Location(), beam.Direction()) if GeomAPI_IntCS(ray, h_surf).NbPoints() == 0: beam_v1 = beam else: GeomAPI_IntCS(ray, h_surf).IsDone() uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1) u, v, w = uvw p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(h_surf, u, v, p1, vx, vy) vz = vx.Crossed(vy) vx.Normalize() vy.Normalize() vz.Normalize() norm = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) beam_v0 = beam beam_v0.SetLocation(p1) beam_v1 = beam_v0.Mirrored(norm.Ax2()) beam_v1.XReverse() return beam_v1
def Reflect(self): h_surf = BRep_Tool.Surface(self.tar.srf) g_line = gp_Lin(self.ini.beam.Location(), self.ini.beam.Direction()) ray = Geom_Line(g_line) if GeomAPI_IntCS(ray, h_surf).NbPoints(): self.tar.beam = reflect(self.ini.beam, self.tar.srf) else: pln = make_plane(self.tar.axs.Location(), dir_to_vec(self.tar.axs.Direction()), 500, -500, 500, -500) h_surf = BRep_Tool.Surface(pln) self.tar.beam = reflect(self.ini.beam, pln) print(self.ini.beam.Location()) print(self.tar.beam.Location()) GeomAPI_IntCS(ray, h_surf).IsDone() uvw = GeomAPI_IntCS(ray, h_surf).Parameters(1) u, v, w = uvw print(u, v, w) vz, v1, v2, r1, r2 = axs_curvature(h_surf, u, v) tar_surf_axs = gp_Ax3(self.tar.beam.Location(), vec_to_dir(vz), vec_to_dir(v1)) tar_surf = wavefront([r1, r2], tar_surf_axs) self.display.DisplayShape(tar_surf, color="BLUE") self.display.DisplayShape(axs_pln(tar_surf_axs)) self.GO_Prop(w) h_tar_wave = BRep_Tool.Surface(self.ini_wave) vz, v1, v2, r1, r2 = axs_curvature(h_tar_wave, u, v) tar_wave_axs = self.tar.beam.Translated(gp_Vec(0, 0, 0)) tar_wave_axs.SetXDirection(vec_to_dir(v1)) self.tar.wave = wavefront([r1, r2], tar_wave_axs) self.display.DisplayShape(self.tar.wave, color="RED") self.display.DisplayShape(axs_pln(tar_wave_axs))
def show_plane(self, axs=gp_Ax3(), scale=100): pnt = axs.Location() vec = dir_to_vec(axs.Direction()) pln = make_plane(pnt, vec, -scale, scale, -scale, scale) self.display.DisplayShape(pln)
STEPControl_ShellBasedSurfaceModel translates an Open CASCADE shape into a STEP shell_based_surface_model entity. STEPControl_GeometricCurveSet translates an Open CASCADE shape into a STEP geometric_curve_set entity. """ label = self.shape_tool.AddShape(shape) self.step.Transfer(self.h_doc, STEPControl_AsIs) def Write(self, filename=None): if not filename: filename = self.name path, ext = os.path.splitext(filename) if not ext: ext = ".stp" status = self.step.Write(path + ext) assert (status == IFSelect_RetDone) if __name__ == "__main__": display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape(gp_Pnt()) root = ExportCAFMethod(name="root") root.Add(make_vertex(gp_Pnt()), name="pnt") root.Add(make_plane(center=gp_Pnt(0, 0, 0)), name="pln0") root.Add(make_plane(center=gp_Pnt(0, 0, 100)), name="pln1") root.Add(make_plane(center=gp_Pnt(0, 0, 200)), name="pln2") root.Add(make_circle(gp_Pnt(0, 0, 0), 100), name="circle") root.Add(make_box(100, 100, 100), name="box001") root.Write() display.FitAll() # start_display()
from OCC.Extend.TopologyUtils import TopologyExplorer, WireExplorer from OCC.Extend.DataExchange import read_iges_file from OCC.Extend.ShapeFactory import make_edge, make_n_sided from OCCUtils.Construct import make_plane def geom_plate(): p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(10, 0, 0) p3 = gp_Pnt(10, 0, 9) p4 = gp_Pnt(0, 1, 1) p5 = gp_Pnt(5, 5, 0) edge = [p1, p2, p3, p4] edge.append(edge[0]) poly = [make_edge(edge[i], edge[i + 1]) for i in range(len(edge) - 1)] face = make_n_sided(poly) return face if __name__ == "__main__": display, start_display, add_menu, add_function_to_menu = init_display() display.DisplayShape(geom_plate()) display.DisplayShape(make_plane(extent_x_max=10, extent_x_min=-10, extent_y_min=-10, extent_y_max=10), transparency=0.9) display.FitAll() start_display()
from OCC.Display.SimpleGui import init_display display, start_display, add_menu, add_functionto_menu = init_display() # Defining the points p1 = gp_Pnt(0, 0, 0) p2 = gp_Pnt(5, 5, 0) p3 = gp_Pnt(-5, 5, 0) # Making the edges ed1 = BRepBuilderAPI_MakeEdge(p3, p2).Edge() ed2 = BRepBuilderAPI_MakeEdge(p2, p1).Edge() # Making the 2dFillet f2 = ChFi2d_AnaFilletAlgo() f2.Init(ed1, ed2, gp_Pln()) f2.Perform(1.0) # radius fillet2d = f2.Result(ed1, ed2) pln1 = make_plane(gp_Pnt(+200, 0, 0), gp_Vec(1, 0, 1)) pln2 = make_plane(gp_Pnt(-200, 0, 0), gp_Vec(-1, 0, 1)) f3 = ChFi3d_FilBuilder(pln1) # Create and display a wire w = make_wire([ed1, fillet2d, ed2]) #display.DisplayShape(w) display.DisplayShape(ed1, color="BLUE") display.DisplayShape(fillet2d) display.DisplayShape(ed2, color="BLUE") display.FitAll() start_display()
parser.add_option("--dir", dest="dir", default="./") parser.add_option("--pxyz", dest="pxyz", default=[0.0, 0.0, 0.0], type="float", nargs=3) opt, argc = parser.parse_args(argvs) print(opt, argc) obj = plotocc(view=False) face1 = read_step_file("./stp_surf/gen_surf_030.stp") axis1 = gp_Ax3(gp_Pnt(0, 0, 0.0), gp_Dir(0, 0, 1)) face1.Location(set_loc(gp_Ax3(), axis1)) face2 = read_step_file("./stp_surf/gen_surf_030.stp") axis2 = gp_Ax3(gp_Pnt(0, 0, 3.5), gp_Dir(0, 0, 1)) face2.Location(set_loc(gp_Ax3(), axis2)) face3 = make_plane() axis3 = gp_Ax3(gp_Pnt(0, 0, 5.5), gp_Dir(0, 0, 1)) face3.Location(set_loc(gp_Ax3(), axis3)) axs = gp_Ax3() ax1 = gp_Ax3(gp_Pnt(0, 0, -10), axs.Direction()) vec = gp_Vec(gp_Pnt(0, 0, -10), gp_Pnt(0, 0, 10)) face = obj.make_EllipWire(rxy=[50.0, 50.0], axs=ax1, skin=0) body = BRepPrimAPI_MakePrism(face, vec).Shape() lens = make_lens1(body, face1, face2, face3) obj.create_tempdir(flag=1) for shp in lens: obj.export_stp(shp)
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3 from OCC.Core.gp import gp_Pln from OCC.Core.BRep import BRep_Tool from OCC.Core.GeomLProp import GeomLProp_SurfaceTool, GeomLProp_CurveTool from OCC.Core.GeomAPI import GeomAPI_IntCS, GeomAPI_PointsToBSpline from OCC.Core.TColgp import TColgp_Array1OfPnt from OCCUtils.Construct import make_plane from particle.base import spl_curv_pts if __name__ == '__main__': p0 = gp_Pnt(10, 10, 50) p1 = gp_Pnt(-20, -20, -50) pts, crv = spl_curv_pts([p0, p1]) pln = make_plane(vec_normal=gp_Vec(0, 1, 1)) h_surf = BRep_Tool.Surface(pln) api = GeomAPI_IntCS(crv, h_surf) print(api.IsDone()) print(api.NbSegments()) uvw = api.Parameters(1) u, v, w = uvw pnt_crv = gp_Pnt() pnt_1st = gp_Pnt() pnt_2nd = gp_Pnt() pnt_srf = gp_Pnt() GeomLProp_CurveTool.Value(crv, w, pnt_crv) GeomLProp_CurveTool.Value(crv, 0, pnt_1st) GeomLProp_CurveTool.Value(crv, 1, pnt_2nd) GeomLProp_SurfaceTool.Value(h_surf, u, v, pnt_srf)