def __init__(self): plotocc.__init__(self) axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) shp = self.make_PolyWire(num=15, skin=None, axs=axs) self.export_stp(shp) print(shp, shp.Location().Transformation()) loc = shp.Location() loc_inv = loc.Inverted() shp.Located(loc_inv) print(shp, shp.Location().Transformation()) self.export_stp(shp) axs = gp_Ax3(gp_Pnt(0, 0, 1), gp_Dir(0, 0, 1)) shp = self.make_PolyWire(num=15, skin=0, axs=axs) print(shp, shp.Location().Transformation()) axs = gp_Ax3(gp_Pnt(0, 0, 3), gp_Dir(0, 0, 1)) shp = self.make_StarWire(num=15, skin=1, axs=axs, radi=[1.1, 1.0]) print(shp, shp.Location().Transformation()) axs = gp_Ax3(gp_Pnt(0, 0, 5), gp_Dir(0, 1, 1)) shp = self.make_StarWire(num=15, skin=0, axs=axs, radi=[0.9, 1.0]) print(shp, shp.Location()) self.export_stp(shp) print(shp) loc = shp.Location() loc_inv = loc.Inverted() shp = shp.Located(loc_inv) print(loc.Transformation()) print(loc_inv.Transformation()) self.export_stp(shp.Reversed())
def __init__(self, show=None): if show != None: plotocc.__init__(self) self.pt = np.linspace(0, 2 * np.pi, 100) self.hz = 15.0 self.rt = 2.0 self.r_xy = 30.0 self.radi = 100 self.px = 30.0 * np.cos(self.pt) self.py = 30.0 * np.sin(self.pt) self.pz = 15 * np.cos(5 * self.pt) curv_pts, curv_shp = spl_curv(self.px, self.py, self.pz) crv1_pts, crv1_shp = self.sin_curv_x(10, 30, pos=-10, scale=2) crv2_pts, crv2_shp = self.sin_curv_x(20, 40, pos=+10, scale=1) crv3_pts, crv3_shp = self.sin_curv_y(0, 30, pos=0) api = GeomFill_BSplineCurves(crv1_shp, crv2_shp, GeomFill_CoonsStyle) # self.show_pts_1d(curv_pts) # self.display.DisplayShape(curv_shp) #self.show_pts_1d(crv1_pts) #self.show_pts_1d(crv2_pts) #self.show_pts_1d(crv3_pts) self.display.DisplayShape(crv1_shp) self.display.DisplayShape(crv2_shp) self.display.DisplayShape(api.Surface())
def __init__(self): plotocc.__init__(self) self.shell = read_step_file(self.tmpdir + "SurfUV.stp") print(self.shell) top = TopExp_Explorer(self.shell, TopAbs_FACE) self.face = top.Current() print(top.Depth()) print(self.face) self.surf = BRep_Tool.Surface(self.face) u0, u1, v0, v1 = shapeanalysis_GetFaceUVBounds(self.face) print(u0, u1, v0, v1) sas = ShapeAnalysis_Surface(self.surf) print(sas.Value(u0, v0)) print(sas.Value(u0, v1)) print(sas.Value(u1, v0)) print(sas.Value(u1, v1)) u = u0 while u <= u1: v = v0 while v <= v1: p = sas.Value(u, v) self.display.DisplayShape(p, update=False) v += 1 / 3 u += 1 / 4
def __init__(self): plotocc.__init__(self) self.compound = TopoDS_Compound() self.builder = BRep_Builder() self.builder.MakeCompound(self.compound) mmat = math_Matrix(1, 4, 1, 3, 0.0) mmat.SetDiag(1.0) print(mmat.Determinant()) print(mmat.DumpToString()) mvec = math_Vector(1, 3) print(mvec.Norm()) print(mvec.DumpToString())
def __init__(self): plotocc.__init__(self) self.b1 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[100, 100, 105]) self.b2 = gen_ellipsoid(axs=gp_Ax3( gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)), rxyz=[210, 210, 210]) self.base = BRepAlgoAPI_Cut(self.b2, self.b1).Shape() self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0)) print(self.b1) top = Topo(self.base) print(top.number_of_faces())
def __init__(self): plotocc.__init__(self) self.prop = GProp_GProps() self.base = make_box(100, 100, 100) self.base_vol = self.cal_vol(self.base) self.splitter = BOPAlgo_Splitter() self.splitter.AddArgument(self.base) print(self.cal_vol(self.base)) from OCC.Display.qtDisplay import qtViewer3d self.app = self.get_app() self.wi = self.app.topLevelWidgets()[0] self.vi = self.wi.findChild(qtViewer3d, "qt_viewer_3d") self.on_select()
def __init__(self): plotocc.__init__(self) self.axs = gp_Ax3() p_array = TColgp_Array1OfPnt(1, 100) for idx, pt in enumerate(np.linspace(-2.0, 2.0, 100)): pnt = gp_Pnt(300 * np.sin(pt), 100 * np.cos(3 * pt), 0) p_array.SetValue(idx + 1, pnt) api = GeomAPI_PointsToBSpline(p_array) self.curv = api.Curve() print(self.curv) api = BRepOffsetAPI_ThruSections() api.SetSmoothing(True) num_list = [ 3, 3, 3, 3, 3, 6, 6, 6, 6, 6, 6, 6, 6, 6, 7, 7, 7, 7, 7, 7, 7, 7, 4, 4, 4 ] p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() for idx, pt in enumerate(np.linspace(0.0, 0.5, len(num_list))): GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2) v3 = v1.Crossed(v2) axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2)) poly = self.make_PolyWire(num=num_list[idx], radi=20, axs=axis) api.AddWire(poly) self.show_axs_pln(axis, scale=10) self.display.DisplayShape(poly) api.Build() self.display.DisplayShape(api.Shape()) write_step_file(api.Shape(), "./tmp/ThruPipe_Hex.stp") api = BRepOffsetAPI_ThruSections() # api.SetSmoothing(True) p1, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() for idx, pt in enumerate(np.linspace(0.55, 1.0, 20)): GeomLProp_CurveTool.D2(self.curv, pt, p1, v1, v2) v3 = v1.Crossed(v2) axis = gp_Ax3(p1, vec_to_dir(v1), vec_to_dir(v2)) shft = 90 * pt poly = self.make_Ellip(rxy=[15, 10], shft=shft, axs=axis) api.AddWire(poly) self.display.DisplayShape(poly) api.Build() self.display.DisplayShape(api.Shape()) write_step_file(api.Shape(), "./tmp/ThruPipe_Ellip.stp")
def __init__(self): plotocc.__init__(self) self.compound = TopoDS_Compound() self.builder = BRep_Builder() self.builder.MakeCompound(self.compound) box = BRepPrimAPI_MakeBox(100, 200, 300).Shape() self.display.DisplayShape(box) con = BRepPrimAPI_MakeCone(gp_Ax2(gp_Pnt(500, 0, 0), gp_Dir(0, 0, 1)), 100, 200, 300).Shape() self.display.DisplayShape(con) # https://www.opencascade.com/doc/occt-7.4.0/refman/html/class_graphic3d___camera.html self.camera = self.display.View.Camera() print(self.camera.Scale(), dir_to_vec(self.camera.OrthogonalizedUp())) print(self.camera.ViewDimensions())
def __init__(self): plotocc.__init__(self) self.axs = gp_Ax3() self.circle = Geom_Circle(gp_Circ(self.axs.Ax2(), 100)) p0, v1, v2 = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_CurveTool.D2(self.circle, 0, p0, v1, v2) self.poly_axs = gp_Ax3(p0, vec_to_dir(v1)) for num in range(4, 9): self.poly = self.make_PolyWire( num=num, radi=20.0, axs=self.poly_axs) self.base = self.make_Thru(50) self.display.DisplayShape( self.base, transparency=0.7, color="BLUE") write_step_file(self.base, self.tmpdir + "ThruSurf_{:d}.stp".format(num))
def __init__(self): plotocc.__init__(self) self.b1 = self.get_face(gen_ellipsoid(rxyz=[100, 100, 105])) self.b2 = self.get_face(gen_ellipsoid(rxyz=[210, 210, 210])) self.beam = gp_Ax3(gp_Pnt(0, 150, 0), gp_Dir(1, 1.5, 0)) print(self.b1) h_surf = BRep_Tool.Surface(self.b2) ray = Geom_Line(self.beam.Axis()) self.RayTrace = GeomAPI_IntCS(ray, h_surf) print(self.RayTrace.NbPoints()) self.num = 0 self.pts = [self.beam.Location()] for i in range(5): self.beam = self.reflect_b1(num=1) self.beam = self.reflect_b1(num=2) self.beam = self.reflect_b2(num=1) self.beam = self.reflect_b2(num=2)
def __init__(self): plotocc.__init__(self) print(gxyz.shape) for i, xyz in enumerate(gxyz): print(i, *xyz) self.display.DisplayShape(gp_Pnt(*xyz)) e_array = [] for e in xyz_max: x, y, z = e e = gp_Pnt(float(x), float(y), float(z)) e_array.append(e) e_array.append(e_array[0]) poly = make_polygon(e_array) n_sided = BRepFill_Filling() for e in Topo(poly).edges(): n_sided.Add(e, GeomAbs_C0) for pt in gxyz: x, y, z = pt if (x < xmax) and (x > xmin) and (y < ymax) and (y > ymin) and ( z < zmax) and (z > zmin): n_sided.Add(gp_Pnt(x, y, z)) n_sided.Build() face = n_sided.Face() #face = make_n_sided(edges, p_array) # THICKEN SURFACE thickness = 0.15 solid = BRepOffset_MakeOffset(face, thickness, 1.0E-5, BRepOffset_Skin, False, False, GeomAbs_Intersection, True) # The last True is important to make solid # solid.MakeOffsetShape() # solid.MakeThickSolid() #aShape = solid.Shape() self.display.DisplayShape(poly) self.display.DisplayShape(face) #display.DisplayShape(aShape, update=True) #write_step_file(aShape, "./tmp/gyroid.stp") self.export_stp(solid.Shape())
def __init__(self): plotocc.__init__(self) axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1)) shp = self.make_PolyWire(num=15, skin=None, axs=axs) self.display.DisplayShape(shp) self.export_stp(shp) axs = gp_Ax3(gp_Pnt(0, 0, 1), gp_Dir(0, 0, 1)) shp = self.make_PolyWire(num=15, skin=0, axs=axs) self.display.DisplayShape(shp) self.export_stp(shp) axs = gp_Ax3(gp_Pnt(0, 0, 3), gp_Dir(0, 0, 1)) shp = self.make_StarWire(num=15, skin=1, axs=axs, radi=[1.1, 1.0]) self.display.DisplayShape(shp) self.export_stp(shp) axs = gp_Ax3(gp_Pnt(0, 0, 5), gp_Dir(0, 1, 1)) shp = self.make_StarWire(num=15, skin=1, axs=axs, radi=[0.9, 1.0]) self.display.DisplayShape(shp) self.export_stp(shp)
def __init__(self): plotocc.__init__(self) self.compound = TopoDS_Compound() self.builder = BRep_Builder() self.builder.MakeCompound(self.compound) self.beam = gp_Ax3() self.beam.SetLocation(gp_Pnt(0.5, 0.5, 0.0)) self.beam.SetDirection(gp_Dir(0.0, 0.5, 1.0)) self.beam_line = line_from_axs(self.beam, length=20) self.builder.Add(self.compound, self.beam_line) ax = gp_Ax3(gp_Pnt(0, 0, 10), gp_Dir(0, 0, -1)) px = np.linspace(-1, 1, 10) * 10 py = np.linspace(-1, 1, 10) * 10 mesh = np.meshgrid(px, py) surf = mesh[0]**2 / 100 + mesh[1]**2 / 150 self.surf = spl_face(*mesh, surf, ax) self.surf_bound = self.make_PolySurf(radi=5, axs=ax) self.beam_glin = Geom_Line(self.beam.Location(), self.beam.Direction()) self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf)) print(self.ics.NbPoints()) # print(self.ics.Point(1)) self.ics = GeomAPI_IntCS(self.beam_glin, BRep_Tool.Surface(self.surf_bound)) print(self.ics.NbPoints()) #self.display.DisplayShape(self.surf, transparency=0.7) self.display.DisplayShape(self.surf_bound, transparency=0.7) self.plns = TopoDS_Shell() self.builder.MakeShell(self.plns) for ix in np.linspace(0, 1, 5): for iy in np.linspace(0, 1, 5): p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(self.surf), ix, iy, p1, vx, vy) vz = vx.Crossed(vy) axs = gp_Ax3(p1, vec_to_dir(vz), vec_to_dir(vx)) pln = self.make_PolyPlane(axs=axs, radi=2.5, shft=15.0) print(pln) self.builder.Add(self.compound, make_vertex(p1)) self.builder.Add(self.plns, pln) self.builder.Add(self.compound, self.plns) for face in Topo(self.plns).faces(): self.ics.Perform(self.beam_glin, BRep_Tool.Surface(face)) uvw = self.ics.Parameters(1) u, v, w = uvw p1, vx, vy = gp_Pnt(), gp_Vec(), gp_Vec() GeomLProp_SurfaceTool.D1(BRep_Tool.Surface(face), u, v, p1, vx, vy) vz = vx.Crossed(vy) if u > 0 and v > 0: print(u, v) print(p1) print(self.ics.Point(1)) self.display.DisplayShape(p1) self.display.DisplayShape(face, color="BLUE") else: print(u, v)
def __init__(self): plotocc.__init__(self) self.build_surf() write_step_file(self.bspl_face, self.tmpdir + "SurfUV.stp")