def ask_point_uv(xyz, face, uvrange): """ This is a general function which gives the uv coordiates from the xyz coordinates. The uv value is not normlized. """ gpPnt = gp_Pnt(float(xyz[0]), float(xyz[1]), float(xyz[2])) surface = BRep_Tool().Surface(face) ### Handle_Geom_Surface sas = ShapeAnalysis_Surface(surface) gpPnt2D = sas.ValueOfUV(gpPnt, 0.01) uv = list(gpPnt2D.Coord()) # print(uvrange) # print(uv) geom_surface = surface.GetObject() tol = 0.001 if geom_surface.IsUPeriodic() == True: # print (geom_surface.UPeriod()) if uv[0] < uvrange[0] and uvrange[0] - uv[0] > tol: uv[0] = uv[0] + geom_surface.UPeriod() if uv[0] > uvrange[1] and uv[0] - uvrange[1] > tol: uv[0] = uv[0] - geom_surface.UPeriod() if geom_surface.IsVPeriodic() == True: if uv[1] < uvrange[2] and uvrange[2] - uv[1] > tol: uv[1] = uv[1] + geom_surface.VPeriod() if uv[1] > uvrange[3] and uv[1] - uvrange[3] > tol: uv[1] = uv[1] - geom_surface.VPeriod() # print(uv) return uv
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 point_to_parameter(self, pt): ''' returns the uv value of a point on a surface @param pt: ''' sas = ShapeAnalysis_Surface(self.surface_handle) uv = sas.ValueOfUV(pt, self.tolerance) return uv.Coord()
def uv_from_projected_point_on_face(face, pt): ''' returns the uv coordinate from a projected point on a face ''' srf = BRep_Tool().Surface(face) sas = ShapeAnalysis_Surface(srf) uv = sas.ValueOfUV(pt, 1e-2) print('distance', sas.Value(uv).Distance(pt)) return uv.Coord()
def project_to_UV(self): assert self.face != None surface = BRep_Tool.Surface(self.face) analysis_surface = ShapeAnalysis_Surface(surface) xyz = gp_Pnt(self.x, self.y, self.z) uv = analysis_surface.ValueOfUV(xyz, 0.0001) self.u = uv.X() self.v = uv.Y() if self.face.Orientation() == TopAbs_REVERSED: self.reverse_u()
def ask_point_uv2(xyz, face): """ This is a general function which gives the uv coordiates from the xyz coordinates. The uv value is not normlized. """ gpPnt = gp_Pnt(float(xyz[0]), float(xyz[1]), float(xyz[2])) surface = BRep_Tool().Surface(face) ### Handle_Geom_Surface sas = ShapeAnalysis_Surface(surface) gpPnt2D = sas.ValueOfUV(gpPnt, 0.01) uv = list(gpPnt2D.Coord()) return uv
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 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
def is_closed(self): sa = ShapeAnalysis_Surface(self.surface_handle) # sa.GetBoxUF() return sa.IsUClosed(), sa.IsVClosed()
def is_closed(self): sa = ShapeAnalysis_Surface(self.surface) return sa.IsUClosed(), sa.IsVClosed()