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 build_points_network(self): """ Creates a list of gp_Pnt points from a bspline surface """ # get face uv bounds umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(self.bspl_face) print(umin, umax, vmin, vmax) pnts = [] sas = ShapeAnalysis_Surface(self.bspl_surf) u = umin while u < umax: v = vmin while v < vmax: p = sas.Value(u, v) print("u=", u, " v=", v, "->X=", p.X(), " Y=", p.Y(), " Z=", p.Z()) self.display.DisplayShape(p, update=False) pnts.append(p) v += 0.1 u += 0.1
def generate_TCP(): global tool_tcp_pnts, tool_tcp_vxs, tool_tcp_vys, tool_tcp_vzs tool_tcp_pnts = [] tool_tcp_vxs = [] tool_tcp_vys = [] tool_tcp_vzs = [] numperface = 1 num1 = round(abs(math.sqrt(numperface))) num2 = round(abs(math.sqrt(numperface))) numofrots = 8 for sur in surf: umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(sur) bsur = BRepAdaptor_Surface(sur, True) for i in range(0, num1 + 1): for j in range(0, num2 + 1): u = umin + i * (umax - umin) / num1 v = vmin + j * (vmax - vmin) / num2 point, Vx, Vy, Vz = get_point(bsur, u, v) flag = 0 for apoint in tool_tcp_pnts: if abs(point.Distance(apoint)) < 0.1: flag = 1 break if flag == 0: for k in range(0, numofrots): ang = 2 * math.pi / numofrots tool_tcp_pnts.append(point) Vx = Vx.Rotated(gp_Ax1(point, gp_Dir(Vz)), ang) tool_tcp_vxs.append(Vx) Vy = Vy.Rotated(gp_Ax1(point, gp_Dir(Vz)), ang) tool_tcp_vys.append(Vy) tool_tcp_vzs.append(Vz) display_coord(tool_tcp_pnts, tool_tcp_vxs, tool_tcp_vys, tool_tcp_vzs) display.DisplayMessage(gp_Pnt(100, 100, 100), 'TCP #:' + str(len(tool_tcp_pnts)), height=None, message_color=(1, 1, 1), update=True)
def build_points_network(bspl_srf): """ Creates a list of gp_Pnt points from a bspline surface """ # first create a face face = BRepBuilderAPI_MakeFace(bspl_srf, 1e-6).Face() # get face uv bounds umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(face) print(umin, umax, vmin, vmax) pnts = [] sas = ShapeAnalysis_Surface(bspl_srf) u = umin while u < umax: v = vmin while v < vmax: p = sas.Value(u, v) print("u=", u, " v=", v, "->X=", p.X(), " Y=", p.Y(), " Z=", p.Z()) pnts.append(p) v += 0.1 u += 0.1 return pnts
from OCC.Core.gp import gp_Pnt from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace from OCC.Core.TColgp import TColgp_Array2OfPnt from OCC.Core.GeomAPI import GeomAPI_PointsToBSplineSurface from OCC.Core.GeomAbs import GeomAbs_C2 from OCC.Core.ShapeAnalysis import ShapeAnalysis_Surface, shapeanalysis_GetFaceUVBounds p1 = gp_Pnt(-15, 200, 10) p2 = gp_Pnt(5, 204, 0) p3 = gp_Pnt(15, 200, 0) p4 = gp_Pnt(-15, 20, 15) p5 = gp_Pnt(-5, 20, 0) p6 = gp_Pnt(15, 20, 35) array = TColgp_Array2OfPnt(1, 3, 1, 2) array.SetValue(1, 1, p1) array.SetValue(2, 1, p2) array.SetValue(3, 1, p3) array.SetValue(1, 2, p4) array.SetValue(2, 2, p5) array.SetValue(3, 2, p6) bspl_surf = GeomAPI_PointsToBSplineSurface(array, 3, 8, GeomAbs_C2, 0.001).Surface() face = BRepBuilderAPI_MakeFace(bspl_surf, 1e-6).Face() umin, umax, vmin, vmax = shapeanalysis_GetFaceUVBounds(face) print(umin, umax, vmin, vmax)