示例#1
0
    def __init__(self):
        super(Sketch_CommandBSpline, self).__init__("BSplineCurve.")
        self.IndexCounter = 1
        self.myDegree = SKETCH_DEGREE
        self.tempPnt2d = gp.Origin2d()
        self.myFirstgp_Pnt = gp.Origin()
        self.tempPnt = gp.Origin()
        self.curEdge = TopoDS_Edge()

        self.myBSplineCurveAction = BSplineCurveAction.Nothing
        self.Poles2d = [gp.Origin2d()] * 2
        self.Poles = [gp.Origin()] * 2
        self.Multi, self.Knots = setQuasiUniformKnots(len(self.Poles),
                                                      self.myDegree)

        curgp_Array1CurvePoles2d = point_list_to_TColgp_Array1OfPnt2d(
            self.Poles2d)
        curgp_Array1CurveMulti = int_list_to_TColStd_Array1OfInteger(
            self.Multi)
        curgp_Array1CurveKnots = float_list_to_TColStd_Array1OfReal(self.Knots)
        self.myGeom2d_BSplineCurve = Geom2d_BSplineCurve(
            curgp_Array1CurvePoles2d, curgp_Array1CurveKnots,
            curgp_Array1CurveMulti, self.myDegree)

        curgp_Array1CurvePoles = point_list_to_TColgp_Array1OfPnt(self.Poles)
        self.myGeom_BSplineCurve = Geom_BSplineCurve(curgp_Array1CurvePoles,
                                                     curgp_Array1CurveKnots,
                                                     curgp_Array1CurveMulti,
                                                     self.myDegree)

        self.myRubberAIS_Shape = AIS_Shape(self.curEdge)
示例#2
0
文件: __init__.py 项目: ocastrup/OCX
 def __init__(self, controlpoints: numpy, knots: numpy, m: int, degree: int,
              periodic: bool):
     super().__init__()
     self.edge = TopAbs_EDGE
     array = []
     for pnt in controlpoints:
         p = OccPoint(pnt)
         array.append(p.Value())
     poles = point_list_to_TColgp_Array1OfPnt(array)
     # Normalise the knots and find multiplicities
     multp = OCCWrapper.OccMultiplicities(knots)
     uknots = multp.knots()
     multiplicity = multp.multiplcity()
     knotvector = TColStd_Array1OfReal(1, len(uknots))
     i = 1
     for v in uknots:
         knotvector.SetValue(i, v)
         i = i + 1
     mult = TColStd_Array1OfInteger(1, len(multiplicity))
     i = 1
     for m in multiplicity:
         mult.SetValue(i, int(m))
         i = i + 1
     mknurbs = Geom_BSplineCurve(poles, knotvector, mult, degree, periodic)
     mkedge = BRepBuilderAPI_MakeEdge(mknurbs)
     if not mkedge.IsDone():
         OCCWrapper.OccError(type(self), mkedge)
     else:
         self.done = True
         self.edge = mkedge.Edge()
     return
示例#3
0
def occ_curve_from_parameters(points, weights, knots, multiplicities, degree,
                              is_periodic):
    return Geom_BSplineCurve(
        array1_from_points1(points),
        array1_from_floats1(weights),
        array1_from_floats1(knots),
        array1_from_integers1(multiplicities),
        degree,
        is_periodic,
    )
示例#4
0
def _bspline(poles,
             knots,
             muls,
             degree: int,
             periodic: bool,
             weights=None,
             check_rational: bool = None):
    _poles = opencascade_array1_of_pnt(poles)
    if weights:
        _weigths = opencascade_array1_of_real(weights)
    _knots = opencascade_array1_of_real(knots)
    _muls = opencascade_array1_of_int(muls)

    if weights:
        crv = Geom_BSplineCurve(_poles, _knots, _weigths, _muls, degree,
                                periodic, check_rational)
    else:
        crv = Geom_BSplineCurve(_poles, _knots, _muls, degree, periodic)

    return Curve(crv)
示例#5
0
 def CreateBspline(self):
     curgp_Array1CurvePoles2d = point_list_to_TColgp_Array1OfPnt2d(
         self.Poles2d)
     curgp_Array1CurveMulti = int_list_to_TColStd_Array1OfInteger(
         self.Multi)
     curgp_Array1CurveKnots = float_list_to_TColStd_Array1OfReal(self.Knots)
     self.myGeom2d_BSplineCurve = Geom2d_BSplineCurve(
         curgp_Array1CurvePoles2d, curgp_Array1CurveKnots,
         curgp_Array1CurveMulti, self.myDegree)
     curgp_Array1CurvePoles = point_list_to_TColgp_Array1OfPnt(self.Poles)
     self.myGeom_BSplineCurve = Geom_BSplineCurve(curgp_Array1CurvePoles,
                                                  curgp_Array1CurveKnots,
                                                  curgp_Array1CurveMulti,
                                                  self.myDegree)
示例#6
0
def nurbs(p_list, u_list, w_list):
    """Construct NURBS curve from PythonOCC with numpy arrays

    Parameters
    ----------
    p_list: numpy.array
        The set of control points
    u_list: numpy.array
        The knots vector
    w_list: numpy.array
        The weighs vector
    """
    u_vals, u_mults = np.unique(u_list, return_counts=True)
    p = len(u_list) - len(p_list) - 1
    poles = np2occ_points(p_list)
    weighs = np2occ_auto(w_list)
    knots = np2occ_auto(u_vals)
    mults = np2occ_auto(u_mults)
    return Geom_BSplineCurve(poles, weighs, knots, mults, p)
示例#7
0
from OCC.Core.Geom import Geom_Circle,Geom_BSplineCurve
from OCC.Core.TColgp import TColgp_Array1OfPnt
from OCC.Core.TColStd import TColStd_Array1OfReal,TColStd_Array1OfInteger
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

# the first bezier curve
array = TColgp_Array1OfPnt(1, 4)
array.SetValue(1, gp_Pnt(0, 0,0))
array.SetValue(2, gp_Pnt(1, 0,0))
array.SetValue(3, gp_Pnt(1, 1,0))
array.SetValue(4, gp_Pnt(3, 3,0))
weights=TColStd_Array1OfReal(1,4)
knots=TColStd_Array1OfReal(1,3)
multiplicities=TColStd_Array1OfInteger(1,3)
multiplicities.SetValue(1,3)
multiplicities.SetValue(2,1)
multiplicities.SetValue(3,3)
knots.SetValue(1,0.0)
knots.SetValue(2,0.5)
knots.SetValue(3,1.0)
weights.SetValue(1,1.0)
weights.SetValue(2,1.0)
weights.SetValue(3,1.0)
weights.SetValue(4,1.0)

nurbs = Geom_BSplineCurve(array,weights,knots,multiplicities,2,False,True  )
print(nurbs.Period())
display.DisplayShape(nurbs, update=True, color='RED')
start_display()