Exemple #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)
    def test_surface_from_curves(self):
        '''Test: surfaces from curves'''
        array = []
        array.append(gp_Pnt(-4, 0, 2))
        array.append(gp_Pnt(-7, 2, 2))
        array.append(gp_Pnt(-6, 3, 1))
        array.append(gp_Pnt(-4, 3, -1))
        array.append(gp_Pnt(-3, 5, -2))

        aaa = point_list_to_TColgp_Array1OfPnt(array)
        SPL1 = GeomAPI_PointsToBSpline(aaa).Curve()

        a2 = []
        a2.append(gp_Pnt(-4, 0, 2))
        a2.append(gp_Pnt(-2, 2, 0))
        a2.append(gp_Pnt(2, 3, -1))
        a2.append(gp_Pnt(3, 7, -2))
        a2.append(gp_Pnt(4, 9, -1))
        bbb = point_list_to_TColgp_Array1OfPnt(a2)
        SPL2 = GeomAPI_PointsToBSpline(bbb).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)

        SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
        SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
        aGeomFill2 = GeomFill_BSplineCurves(SPL3, SPL4, GeomFill_CoonsStyle)

        SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
        SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
        aGeomFill3 = GeomFill_BSplineCurves(SPL5, SPL6, GeomFill_CurvedStyle)

        aBSplineSurface1 = aGeomFill1.Surface()
        aBSplineSurface2 = aGeomFill2.Surface()
        aBSplineSurface3 = aGeomFill3.Surface()
Exemple #3
0
def surface_from_curves():
    '''
    @param display:
    '''
    # First spline
    array = []
    array.append(gp_Pnt(-4, 0, 2))
    array.append(gp_Pnt(-7, 2, 2))
    array.append(gp_Pnt(-6, 3, 1))
    array.append(gp_Pnt(-4, 3, -1))
    array.append(gp_Pnt(-3, 5, -2))

    pt_list1 = point_list_to_TColgp_Array1OfPnt(array)
    SPL1 = GeomAPI_PointsToBSpline(pt_list1).Curve()

    # Second spline
    a2 = []
    a2.append(gp_Pnt(-4, 0, 2))
    a2.append(gp_Pnt(-2, 2, 0))
    a2.append(gp_Pnt(2, 3, -1))
    a2.append(gp_Pnt(3, 7, -2))
    a2.append(gp_Pnt(4, 9, -1))
    pt_list2 = point_list_to_TColgp_Array1OfPnt(a2)
    SPL2 = GeomAPI_PointsToBSpline(pt_list2).Curve()

    # Fill with StretchStyle
    aGeomFill1 = GeomFill_BSplineCurves(SPL1,
                                        SPL2,
                                        GeomFill_StretchStyle)

    SPL3 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(10, 0, 0)))
    SPL4 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(10, 0, 0)))
    # Fill with CoonsStyle
    aGeomFill2 = GeomFill_BSplineCurves(SPL3,
                                        SPL4,
                                        GeomFill_CoonsStyle)
    SPL5 = Geom_BSplineCurve.DownCast(SPL1.Translated(gp_Vec(20, 0, 0)))
    SPL6 = Geom_BSplineCurve.DownCast(SPL2.Translated(gp_Vec(20, 0, 0)))
    # Fill with CurvedStyle
    aGeomFill3 = GeomFill_BSplineCurves(SPL5,
                                        SPL6,
                                        GeomFill_CurvedStyle)

    aBSplineSurface1 = aGeomFill1.Surface()
    aBSplineSurface2 = aGeomFill2.Surface()
    aBSplineSurface3 = aGeomFill3.Surface()
    
    display.DisplayShape(make_face(aBSplineSurface1, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface2, 1e-6))
    display.DisplayShape(make_face(aBSplineSurface3, 1e-6), update=True)
Exemple #4
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)
Exemple #5
0
 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
Exemple #6
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,
    )
Exemple #7
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)
 def test_downcast_curve(self) -> None:
     """Test if a GeomCurve can be DownCasted to a GeomLine"""
     edge = BRepBuilderAPI_MakeEdge(gp_Pnt(0, 0, 0), gp_Pnt(1, 0, 0)).Edge()
     curve, _, _ = BRep_Tool_Curve(edge)
     self.assertTrue(isinstance(curve, Geom_Curve))
     # The edge is internally a line, so we should be able to downcast it
     line = Geom_Line.DownCast(curve)
     self.assertTrue(isinstance(line, Geom_Curve))
     # Hence, it should not be possible to downcast it as a B-Spline curve
     bspline = Geom_BSplineCurve.DownCast(curve)
     self.assertTrue(bspline is None)
Exemple #9
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)
Exemple #10
0
class Sketch_CommandBSpline(Sketch_Command):
    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)

    def Action(self):
        self.myBSplineCurveAction = BSplineCurveAction.Input_1Point

    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)

    def MouseInputEvent(self, thePnt2d: gp_Pnt2d, buttons, modifier):
        self.curPnt2d = self.myAnalyserSnap.MouseInput(thePnt2d)

        if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
            self.myFirstgp_Pnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                            self.curPnt2d.Y())
            self.myFirstgp_Pnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                             self.curPnt2d)
            self.myFirstPoint.SetPnt(self.myFirstgp_Pnt)
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.myFirstPoint)

            self.Poles2d[0] = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y())
            self.Poles[0] = gp_Pnt(self.myFirstgp_Pnt.X(),
                                   self.myFirstgp_Pnt.Y(),
                                   self.myFirstgp_Pnt.Z())
            self.CreateBspline()

            self.bspline = Sketch_Bspline(self.myContext,
                                          self.curCoordinateSystem)
            self.bspline.AddPoles(self.curPnt2d)

            # self.myContext.Display(self.myRubberLine, True)
            self.myBSplineCurveAction = BSplineCurveAction.Input_2Point
            self.IndexCounter = 2

        elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
            self.Poles2d[1] = gp_Pnt2d(self.curPnt2d.X(), self.curPnt2d.Y())
            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.Poles[1] = gp_Pnt(self.tempPnt.X(), self.tempPnt.Y(),
                                   self.tempPnt.Z())
            self.mySecondPoint.SetPnt(self.tempPnt)
            self.CreateBspline()

            ME = BRepBuilderAPI_MakeEdge(self.myFirstgp_Pnt,
                                         self.mySecondPoint.Pnt())
            if ME.IsDone():
                self.bspline.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                self.myRubberAIS_Shape.Set(self.curEdge)
                # self.myContext.Remove(self.myRubberLine, True)
                self.myContext.Display(self.myRubberAIS_Shape, True)

                self.IndexCounter += 1

                self.Poles2d.append(self.curPnt2d)
                self.Poles.append(self.tempPnt)
                self.Multi, self.Knots = setQuasiUniformKnots(
                    len(self.Poles), self.myDegree)
                self.CreateBspline()

                self.myBSplineCurveAction = BSplineCurveAction.Input_OtherPoints
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
            self.Poles2d[self.IndexCounter - 1] = gp_Pnt2d(
                self.curPnt2d.X(), self.curPnt2d.Y())
            self.tempPnt = elclib.To3d(self.curCoordinateSystem.Ax2(),
                                       self.curPnt2d)
            self.Poles[self.IndexCounter - 1] = gp_Pnt(self.tempPnt.X(),
                                                       self.tempPnt.Y(),
                                                       self.tempPnt.Z())
            self.CreateBspline()

            self.mySecondPoint.SetPnt(self.tempPnt)
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
            if ME.IsDone():
                self.bspline.AddPoles(self.curPnt2d)
                self.curEdge = ME.Edge()
                if self.IndexCounter > MAXIMUMPOLES:
                    self.closeBSpline()
                else:
                    self.myRubberAIS_Shape.Set(self.curEdge)
                    self.myContext.Redisplay(self.myRubberAIS_Shape, True)

                    self.Poles2d.append(self.curPnt2d)
                    self.Poles.append(self.tempPnt)
                    self.Multi, self.Knots = setQuasiUniformKnots(
                        len(self.Poles), self.myDegree)
                    self.CreateBspline()
                    self.tempPnt2d = gp_Pnt2d(self.curPnt2d.X(),
                                              self.curPnt2d.Y())
                    self.IndexCounter += 1
        return False

    def MouseMoveEvent(self, thePnt2d: gp_Pnt2d, buttons, modifiers):
        self.curPnt2d = self.myAnalyserSnap.MouseMove(thePnt2d)
        if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
            # self.mySecondPoint.SetPnt(elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            # self.myRubberLine.SetPoints(self.myFirstPoint, self.mySecondPoint)
            # self.myContext.Redisplay(self.myRubberLine, True)
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
            self.myGeom2d_BSplineCurve.SetPole(self.IndexCounter,
                                               self.curPnt2d)
            self.mySecondPoint.SetPnt(
                elclib.To3d(self.curCoordinateSystem.Ax2(), self.curPnt2d))
            self.myGeom_BSplineCurve.SetPole(self.IndexCounter,
                                             self.mySecondPoint.Pnt())
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
            if ME.IsDone():
                self.curEdge = ME.Edge()
                self.myRubberAIS_Shape.Set(self.curEdge)
                self.myContext.Redisplay(self.myRubberAIS_Shape, True)
            else:
                self.IndexCounter -= 1

    def CancelEvent(self):
        if self.myBSplineCurveAction == BSplineCurveAction.Nothing:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_1Point:
            pass
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_2Point:
            self.bspline.RemoveLabel()
            del self.bspline
        elif self.myBSplineCurveAction == BSplineCurveAction.Input_OtherPoints:
            if len(self.Poles) <= 3:
                self.bspline.RemoveLabel()
                del self.bspline
                self.myContext.Remove(self.myRubberAIS_Shape, True)
            # remove the last pole
            del self.Poles2d[-1]
            del self.Poles[-1]
            self.Multi, self.Knots = setQuasiUniformKnots(
                len(self.Poles), self.myDegree)
            self.CreateBspline()
            ME = BRepBuilderAPI_MakeEdge(self.myGeom_BSplineCurve)
            if ME.IsDone():
                self.curEdge = ME.Edge()
                self.closeBSpline()
                self.IndexCounter -= 1
        self.myBSplineCurveAction = BSplineCurveAction.Nothing

    def GetTypeOfMethod(self):
        return Sketch_ObjectTypeOfMethod.BSpline_Method

    def closeBSpline(self):
        self.myContext.Remove(self.myRubberAIS_Shape, True)
        self.bspline_node = BsplineNode(self.bspline.GetName(), self.rootNode)
        self.bspline.SetKnots(self.Knots)
        self.bspline.SetMultiplicities(self.Multi)
        self.bspline.SetDegree(self.myDegree)
        self.bspline.Compute()
        self.bspline_node.setSketchObject(self.bspline)
        self.AddObject(self.bspline.GetGeometry2d(),
                       self.bspline.GetAIS_Object(),
                       Sketch_GeometryType.CurveSketchObject)
        self.Poles2d = [gp.Origin2d()] * 2
        self.Poles = [gp.Origin()] * 2
        self.Multi, self.Knots = setQuasiUniformKnots(len(self.Poles),
                                                      self.myDegree)
        self.myBSplineCurveAction = BSplineCurveAction.Input_1Point
Exemple #11
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()