本文整理汇总了Python中Part.BSplineCurve方法的典型用法代码示例。如果您正苦于以下问题:Python Part.BSplineCurve方法的具体用法?Python Part.BSplineCurve怎么用?Python Part.BSplineCurve使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Part
的用法示例。
在下文中一共展示了Part.BSplineCurve方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: debug
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def debug(o):
if isinstance(o,Part.BSplineCurve):
FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
FreeCAD.Console.PrintWarning("Degree: %d\n"%(o.Degree))
FreeCAD.Console.PrintWarning("NbPoles: %d\n"%(o.NbPoles))
FreeCAD.Console.PrintWarning("Knots: %d (%0.2f - %0.2f)\n"%(o.NbKnots, o.FirstParameter, o.LastParameter))
FreeCAD.Console.PrintWarning("Mults: %s\n"%(o.getMultiplicities()))
FreeCAD.Console.PrintWarning("Periodic: %s\n"%(o.isPeriodic()))
elif isinstance(o,Part.BSplineSurface):
FreeCAD.Console.PrintWarning("\nBSplineSurface\n************\n")
try:
u = o.uIso(o.UKnotSequence[0])
debug(u)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute uIso curve\n")
try:
v = o.vIso(o.VKnotSequence[0])
debug(v)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute vIso curve\n")
FreeCAD.Console.PrintWarning("************\n")
else:
FreeCAD.Console.PrintMessage("%s\n"%o)
示例2: buildCurve
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def buildCurve(self, obj):
pts = self.Points[obj.FirstIndex:obj.LastIndex+1]
bs = Part.BSplineCurve()
if (obj.Method == "Parametrization") and (obj.Parametrization == "Curvilinear") and (hasattr(obj.PointObject,"Distance")):
params = []
try:
dis = obj.PointObject.Distance
except:
dis = 1.0
for i in range(len(pts)):
params.append(1.0 * i * dis)
lv = pts[-1].sub(pts[-2])
params[-1] = params[-2] + lv.Length
bs.interpolate(Points = pts, Parameters = params, Tolerance = obj.ApproxTolerance)
elif obj.Method == "Parametrization":
bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, ParamType = obj.Parametrization)
elif obj.Method == "Smoothing Algorithm":
bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, LengthWeight = obj.LengthWeight, CurvatureWeight = obj.CurvatureWeight , TorsionWeight = obj.TorsionWeight)
if obj.ClampEnds:
bs.setPole(1,self.Points[0])
bs.setPole(int(bs.NbPoles),self.Points[-1])
self.curve = bs
示例3: getRails
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def getRails(self, shapes):
nbvert = len(shapes[0].Vertexes)
edges = []
for i in range(nbvert):
pts = []
for s in shapes:
pts.append(s.Vertexes[i].Point)
try:
bs = Part.BSplineCurve()
bs.interpolate(pts)
edges.append(bs.toShape())
debug("Rail %d : BSpline curve"%i)
except Part.OCCError:
po = Part.makePolygon(pts)
edges.append(po)
debug("Rail %d : Polygon"%i)
return(edges)
示例4: bspline_copy
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def bspline_copy(bs, reverse = False, scale = 1.0):
"""Copy a BSplineCurve, with knotvector optionally reversed and scaled
newbspline = bspline_copy(bspline, reverse = False, scale = 1.0)
Part.BSplineCurve.buildFromPolesMultsKnots( poles, mults , knots, periodic, degree, weights, CheckRational )"""
mults = bs.getMultiplicities()
weights = bs.getWeights()
poles = bs.getPoles()
knots = bs.getKnots()
perio = bs.isPeriodic()
ratio = bs.isRational()
if scale:
knots = knotSeqScale(knots, scale)
if reverse:
mults.reverse()
weights.reverse()
poles.reverse()
knots = knotSeqReverse(knots)
bspline = Part.BSplineCurve()
bspline.buildFromPolesMultsKnots(poles, mults , knots, perio, bs.Degree, weights, ratio)
return bspline
示例5: compute
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def compute(self):
nbPoles = self.cont1 + self.cont2 + 2
e = self.getChord()
if not e:
self.Curve = None
return
try:
poles = e.discretize(nbPoles)
except Part.OCCError:
self.Curve = None
return
degree = nbPoles - 1
if degree > self.maxDegree:
degree = self.maxDegree
knots, mults = createKnotsMults(degree, nbPoles)
weights = [1.0 for k in range(nbPoles)]
be = Part.BSplineCurve()
be.buildFromPolesMultsKnots(poles, mults , knots, False, degree, weights, False)
nc = curvematch(self.edge1, be, self.param1, self.cont1, self.scale1)
rev = bspline_copy(nc, True, False)
self.Curve = curvematch(self.edge2, rev, self.param2, self.cont2, self.scale2)
示例6: debug
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def debug(o):
if not DEBUG:
return()
if isinstance(o,Part.BSplineCurve):
FreeCAD.Console.PrintWarning("\nBSplineCurve\n")
FreeCAD.Console.PrintWarning("Degree: %d\n"%(o.Degree))
FreeCAD.Console.PrintWarning("NbPoles: %d\n"%(o.NbPoles))
FreeCAD.Console.PrintWarning("Knots: %d (%0.2f - %0.2f)\n"%(o.NbKnots, o.FirstParameter, o.LastParameter))
FreeCAD.Console.PrintWarning("Mults: %s\n"%(o.getMultiplicities()))
FreeCAD.Console.PrintWarning("Periodic: %s\n"%(o.isPeriodic()))
elif isinstance(o,Part.BSplineSurface):
FreeCAD.Console.PrintWarning("\nBSplineSurface\n************\n")
try:
u = o.uIso(o.UKnotSequence[0])
debug(u)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute uIso curve\n")
try:
v = o.vIso(o.VKnotSequence[0])
debug(v)
except Part.OCCError:
FreeCAD.Console.PrintError("Failed to compute vIso curve\n")
FreeCAD.Console.PrintWarning("************\n")
else:
FreeCAD.Console.PrintMessage("%s\n"%o)
示例7: __init__
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def __init__(self, edge = None):
if edge == None:
v1 = FreeCAD.Vector(0,0,0)
v2 = FreeCAD.Vector(1,0,0)
b = Part.BezierCurve()
b.setPoles([v1,v2])
self.curve = b
elif isinstance(edge, Part.Edge):
c = edge.Curve
if isinstance(c, (Part.BezierCurve, Part.BSplineCurve)):
self.curve = c
else:
bs = c.toBSpline()
self.curve = bs
elif isinstance(edge, (Part.BezierCurve, Part.BSplineCurve)):
self.curve = edge
示例8: __init__
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def __init__(self, e1 = None, e2 = None):
self.param1 = 0.0
self.param2 = 0.0
self.cont1 = 1
self.cont2 = 1
self.scale1 = 1.0
self.scale2 = 1.0
self.Curve = None
self.autoScale = True
self.maxDegree = 25 # int(Part.BSplineCurve().MaxDegree)
self.setEdges(e1,e2)
示例9: __init__
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def __init__(self, points=[], fp = None):
self.points = list()
self.curve = Part.BSplineCurve()
self.fp = fp
self.root_inserted = False
self.periodic = False
self.param_factor = 1.0
#self.support = None # Not yet implemented
for p in points:
if isinstance(p,FreeCAD.Vector):
self.points.append(MarkerOnShape([p]))
elif isinstance(p,(tuple,list)):
self.points.append(MarkerOnShape([p[0]],p[1]))
elif isinstance(p,(MarkerOnShape, ConnectionMarker)):
self.points.append(p)
else:
FreeCAD.Console.PrintError("InterpoCurveEditor : bad input")
# Setup coin objects
if self.fp:
self.guidoc = self.fp.ViewObject.Document
else:
if not FreeCADGui.ActiveDocument:
appdoc = FreeCAD.newDocument("New")
self.guidoc = FreeCADGui.ActiveDocument
self.view = self.guidoc.ActiveView
self.rm = self.view.getViewer().getSoRenderManager()
self.sg = self.view.getSceneGraph()
self.setup_InteractionSeparator()
self.update_curve()
示例10: curve_to_script
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def curve_to_script(i,c):
com = ["import FreeCAD",
"from FreeCAD import Vector",
"import Part",""]
if isinstance(c,Part.BSplineCurve):
com.append("poles%d = %r"%(i,c.getPoles()))
com.append("weights%d = %r"%(i,c.getWeights()))
com.append("knots%d = %r"%(i,c.getKnots()))
com.append("mults%d = %r"%(i,c.getMultiplicities()))
com.append("periodic%d = %r"%(i,c.isPeriodic()))
com.append("degree%d = %s"%(i,c.Degree))
com.append("rational%d = %r"%(i,c.isRational()))
com.append("bs%d = Part.BSplineCurve()"%i)
#com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, )"%(i,i,i,i,i,i))
com.append("bs%d.buildFromPolesMultsKnots(poles%d, mults%d, knots%d, periodic%d, degree%d, weights%d, rational%d)"%(i,i,i,i,i,i,i,i))
com.append('obj%d = FreeCAD.ActiveDocument.addObject("Part::Spline","BSplineCurve%d")'%(i,i))
com.append('obj%d.Shape = bs%d.toShape()'%(i,i))
elif isinstance(c,Part.BezierCurve):
com.append("poles%d = %r"%(i,c.getPoles()))
#com.append("degree%d = %s"%(i,c.Degree))
com.append("be%d = Part.BezierCurve()"%i)
com.append("be%d.increase(%s)"%(i,c.Degree))
com.append("be%d.setPoles(poles%d)"%(i,i))
if c.isRational():
w = c.getWeights()
for j in range(len(w)):
com.append("be%d.setWeight(%i,%f)"%(i,j+1,w[j]))
com.append('obj%d = FreeCAD.ActiveDocument.addObject("Part::Spline","BezierCurve%d")'%(i,i))
com.append('obj%d.Shape = be%d.toShape()'%(i,i))
com.append("")
for s in com:
FreeCADGui.doCommand(s)
示例11: setProfiles
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def setProfiles(self, plist):
data = []
self.knots1, self.knots2 = [],[]
for pro in plist:
pts = pro.discretize(100)
bspline = Part.BSplineCurve()
bspline.approximate(Points = pts, ParamType = 'Chordlength') # 'Uniform' 'Centripetal'
bs = Part.Edge(bspline) #, pro.FirstParameter, pro.LastParameter)
data.append(self.getContactParams(bs))
sortedProfs = sorted(data,key=itemgetter(0)) # Sort profiles on rail1ContactParam
self.profiles = []
for datum in sortedProfs:
self.knots1.append(datum[0])
self.knots2.append(datum[1])
p = profile(datum[2])
p.Rail1Param = datum[0]
p.Rail2Param = datum[1]
p.FirstParameter = datum[3]
p.LastParameter = datum[4]
self.getLocalProfile(p)
self.profiles.append(p)
FreeCAD.Console.PrintMessage("\n Profile : %f - %f\n"%(p.Rail1Param,p.Rail2Param))
if len(plist) == 1:
self.extend = True
FreeCAD.Console.PrintMessage('\n1 Profile given\n')
FreeCAD.Console.PrintMessage('\nProfiles sorted\n')
示例12: buildInterpoCurves
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def buildInterpoCurves(self):
c1 = []
c2 = []
k = range(len(self.profiles))
for i in range(self.profileSamples):
pts1 = []
pts2 = []
for pro in self.profiles:
fp = pro.FirstParameter
lp = pro.LastParameter
prange = lp-fp
t = fp + 1.0 * prange * i / (self.profileSamples - 1)
pts1.append(pro.localCurve1.valueAt(t))
pts2.append(pro.localCurve2.valueAt(t))
#k1 = self.parameterization(pts1, self.parametrization, False)
#k2 = self.parameterization(pts2, self.parametrization, False)
#FreeCAD.Console.PrintMessage('\nParameters : %s\n'%str(k))
ic1 = Part.BSplineCurve()
ic1.interpolate(Points = pts1, Parameters = k) #, Tangents = v, TangentFlags = b)
#ic1.approximate(Points = pts1, DegMin = 1, DegMax = 1, Tolerance = 1.0, Parameters = k)
ic2 = Part.BSplineCurve()
#c2.buildFromPolesMultsKnots(pts[1],m,self.knots2,False,1)
ic2.interpolate(Points = pts2, Parameters = k) #, Tangents = v, TangentFlags = b)
#ic2.approximate(Points = pts2, DegMin = 1, DegMax = 1, Tolerance = 1.0, Parameters = k)
c1.append(ic1)
c2.append(ic2)
self.interpoCurves = (c1,c2)
示例13: execute
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def execute(self, obj):
try:
o = FreeCADGui.ActiveDocument.getInEdit().Object
if o == obj:
return
except:
FreeCAD.Console.PrintWarning("execute is disabled during editing\n")
pts = self.get_points(obj)
if pts:
if len(pts) < 2:
FreeCAD.Console.PrintError("%s : Not enough points\n"%obj.Label)
return(False)
else:
obj.Data = pts
else:
pts = obj.Data
tans = [FreeCAD.Vector()]*len(pts)
flags = [False]*len(pts)
for i in range(len(obj.Tangents)):
tans[i] = obj.Tangents[i]
for i in range(len(obj.Flags)):
flags[i] = obj.Flags[i]
#if not (len(obj.LinearSegments) == len(pts)-1):
#FreeCAD.Console.PrintError("%s : Points and LinearSegments mismatch\n"%obj.Label)
if len(obj.LinearSegments) > 0:
for i,b in enumerate(obj.LinearSegments):
if b:
tans[i] = pts[i+1]-pts[i]
tans[i+1] = tans[i]
flags[i] = True
flags[i+1] = True
params = profile_editor.parameterization(pts,obj.Parametrization,obj.Periodic)
curve = Part.BSplineCurve()
curve.interpolate(Points=pts, Parameters=params, PeriodicFlag=obj.Periodic, Tolerance=obj.Tolerance, Tangents=tans, TangentFlags=flags)
obj.Shape = curve.toShape()
示例14: approximate
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def approximate(self, obj, input_shape):
pts = False
input_edges = None
if isinstance(input_shape,(list, tuple)):
#debug(isinstance(input_shape[0],Base.Vector))
if isinstance(input_shape[0],Base.Vector):
pts = input_shape
elif isinstance(input_shape[0],Part.Edge):
input_edges = input_shape
else:
input_edges = input_shape.Edges
if not obj.Active:
return Part.Compound(input_shape)
edges = list()
if input_edges:
for e in input_edges:
pts = e.discretize(obj.Samples)
bs = Part.BSplineCurve()
bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, ParamType = obj.Parametrization)
edges.append(bs.toShape())
se = Part.sortEdges(edges)
wires = []
for el in se:
if len(el) > 1:
wires.append(Part.Wire(el))
else:
wires.append(el[0])
if len(wires) > 1:
return Part.Compound(wires)
else:
return wires[0]
elif pts:
bs = Part.BSplineCurve()
bs.approximate(Points = pts, DegMin = obj.DegreeMin, DegMax = obj.DegreeMax, Tolerance = obj.ApproxTolerance, Continuity = obj.Continuity, ParamType = obj.Parametrization)
return bs.toShape()
示例15: __init__
# 需要导入模块: import Part [as 别名]
# 或者: from Part import BSplineCurve [as 别名]
def __init__(self):
self.param = list()
self.value = list()
self.bs = Part.BSplineCurve()
self.must_increase = True