當前位置: 首頁>>代碼示例>>Python>>正文


Python Part.BSplineCurve方法代碼示例

本文整理匯總了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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:25,代碼來源:gordonFP.py

示例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 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:25,代碼來源:approximate.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:19,代碼來源:pipeshellFP.py

示例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 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:22,代碼來源:nurbs_tools.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:23,代碼來源:nurbs_tools.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:27,代碼來源:BSplineAlgorithms.py

示例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 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:18,代碼來源:isocurves.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:13,代碼來源:nurbs_tools.py

示例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() 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:32,代碼來源:profile_editor.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:35,代碼來源:curve_to_script.py

示例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') 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:28,代碼來源:libS2R.py

示例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) 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:29,代碼來源:libS2R.py

示例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() 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:38,代碼來源:gordon_profile_FP.py

示例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() 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:37,代碼來源:approximate_extension.py

示例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 
開發者ID:tomate44,項目名稱:CurvesWB,代碼行數:7,代碼來源:ribbon.py


注:本文中的Part.BSplineCurve方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。