예제 #1
0
def curves2d_from_offset(event=None):
    r"""
    @param display:
    """
    pnt2d_array = TColgp_Array1OfPnt2d(1, 5)
    pnt2d_array.SetValue(1, gp_Pnt2d(-4, 0))
    pnt2d_array.SetValue(2, gp_Pnt2d(-7, 2))
    pnt2d_array.SetValue(3, gp_Pnt2d(-6, 3))
    pnt2d_array.SetValue(4, gp_Pnt2d(-4, 3))
    pnt2d_array.SetValue(5, gp_Pnt2d(-3, 5))

    spline_1 = Geom2dAPI_PointsToBSpline(pnt2d_array).Curve()

    dist = 1
    offset_curve1 = Geom2d_OffsetCurve(spline_1, dist)
    result = offset_curve1.IsCN(2)
    print("Offset curve yellow is C2: %r" % result)
    dist2 = 1.5
    offset_curve2 = Geom2d_OffsetCurve(spline_1, dist2)
    result2 = offset_curve2.IsCN(2)
    print("Offset curve blue is C2: %r" % result2)

    display.DisplayShape(spline_1)
    display.DisplayShape(offset_curve1, color='YELLOW')
    display.DisplayShape(offset_curve2, color='BLUE', update=True)
예제 #2
0
def bspline():
    # the first bspline
    array = TColgp_Array1OfPnt2d(1, 5)
    array.SetValue(1, gp_Pnt2d(0, 0))
    array.SetValue(2, gp_Pnt2d(1, 2))
    array.SetValue(3, gp_Pnt2d(2, 3))
    array.SetValue(4, gp_Pnt2d(4, 3))
    array.SetValue(5, gp_Pnt2d(5, 5))
    bspline_1 = Geom2dAPI_PointsToBSpline(array).Curve()

    # the second one
    harray = TColgp_HArray1OfPnt2d(1, 5)
    harray.SetValue(1, gp_Pnt2d(0, 0))
    harray.SetValue(2, gp_Pnt2d(1, 2))
    harray.SetValue(3, gp_Pnt2d(2, 3))
    harray.SetValue(4, gp_Pnt2d(4, 3))
    harray.SetValue(5, gp_Pnt2d(5, 5))

    anInterpolation = Geom2dAPI_Interpolate(harray.GetHandle(), False, 0.01)
    anInterpolation.Perform()
    bspline_2 = anInterpolation.Curve()

    harray2 = TColgp_HArray1OfPnt2d(1, 5)
    harray2.SetValue(1, gp_Pnt2d(11, 0))
    harray2.SetValue(2, gp_Pnt2d(12, 2))
    harray2.SetValue(3, gp_Pnt2d(13, 3))
    harray2.SetValue(4, gp_Pnt2d(15, 3))
    harray2.SetValue(5, gp_Pnt2d(16, 5))

    anInterpolation2 = Geom2dAPI_Interpolate(harray2.GetHandle(), True, 0.01)
    anInterpolation2.Perform()
    bspline_3 = anInterpolation2.Curve()

    for j in range(array.Lower(), array.Upper() + 1):
        p = array.Value(j)
        display.DisplayShape(p, update=False)
    for j in range(harray.Lower(), harray.Upper() + 1):
        p = harray.Value(j)
        display.DisplayShape(p, update=False)
    for j in range(harray2.Lower(), harray2.Upper() + 1):
        p = harray2.Value(j)
        display.DisplayShape(p, update=False)

    display.DisplayShape(bspline_1, update=False)
    display.DisplayShape(bspline_2, update=False, color='GREEN')
    display.DisplayShape(bspline_3, update=True, color='BLUE')
예제 #3
0
  def __init__(self,
    knotVector=[], controlPoints=[], degree=3, center=False, axis=2):

    uniqueKnots = unique(knotVector)
    frequency = [ knotVector.count(knot) for knot in uniqueKnots ]

    knots = TColStd_Array1OfReal(0, len(uniqueKnots)-1)
    for i in range(len(uniqueKnots)):
      knots.SetValue(i, uniqueKnots[i])

    mults = TColStd_Array1OfInteger(0, len(frequency)-1)
    for i in range(len(frequency)):
      mults.SetValue(i,frequency[i])

    poles = TColgp_Array1OfPnt(0, len(controlPoints)-1)
    for i in range(len(controlPoints)):
      p = controlPoints[i]
      poles.SetValue(i, gp_Pnt(p[0],p[1],p[2]))

    poles2d = TColgp_Array1OfPnt2d(0, len(controlPoints)-1)
    plane = get_principal_plane(controlPoints)
    for i in range(len(controlPoints)):
      p = controlPoints[i]
      if plane == 0:
        poles2d.SetValue(i, gp_Pnt2d(p[1],p[2]))
      elif plane == 1:
        poles2d.SetValue(i, gp_Pnt2d(p[0],p[2]))
      elif plane == 2:
        poles2d.SetValue(i, gp_Pnt2d(p[0],p[1]))

    curve2d = Geom2d_BSplineCurve(poles2d, knots, mults, degree)
    if is_self_intersecting(curve2d.GetHandle()):
      from cadmium import CadmiumException
      raise CadmiumException('Self intersecting BSpline not allowed')

    curve = Geom_BSplineCurve(poles, knots, mults, degree)
    h_curve = Handle_Geom_BSplineCurve(curve)

    axes = [
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(1,0,0)),
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,1,0)),
      gp_Ax2(gp_Pnt(0,0,0),gp_Dir(0,0,1)),
    ]
    
    self.instance = BRepPrimAPI_MakeRevolution(axes[axis], h_curve)
    Solid.__init__(self, self.instance.Shape(), center=center)
예제 #4
0
    def __init__(self,
                 knotVector=[],
                 controlPoints=[],
                 degree=3,
                 thickness=10,
                 axis=0,
                 center=False):

        self.thickness = thickness

        wire = BRepBuilderAPI_MakeWire()

        uniqueKnots = unique(knotVector)
        frequency = [knotVector.count(knot) for knot in uniqueKnots]

        knots = TColStd_Array1OfReal(0, len(uniqueKnots) - 1)
        for i in range(len(uniqueKnots)):
            knots.SetValue(i, uniqueKnots[i])

        mults = TColStd_Array1OfInteger(0, len(frequency) - 1)
        for i in range(len(frequency)):
            mults.SetValue(i, frequency[i])

        poles = TColgp_Array1OfPnt(0, len(controlPoints) - 1)
        for i in range(len(controlPoints)):
            p = controlPoints[i]
            poles.SetValue(i, gp_Pnt(p[0], p[1], p[2]))

        poles2d = TColgp_Array1OfPnt2d(0, len(controlPoints) - 1)
        plane = get_principal_plane(controlPoints)
        for i in range(len(controlPoints)):
            p = controlPoints[i]
            if plane == 0:
                poles2d.SetValue(i, gp_Pnt2d(p[1], p[2]))
            elif plane == 1:
                poles2d.SetValue(i, gp_Pnt2d(p[0], p[2]))
            elif plane == 2:
                poles2d.SetValue(i, gp_Pnt2d(p[0], p[1]))

        curve2d = Geom2d_BSplineCurve(poles2d, knots, mults, degree)
        if is_self_intersecting(curve2d.GetHandle()):
            from cadmium import CadmiumException
            raise CadmiumException('Self intersecting BSpline not allowed')

        curve = Geom_BSplineCurve(poles, knots, mults, degree)

        me = BRepBuilderAPI_MakeEdge(curve.GetHandle())
        wire.Add(me.Edge())

        first = controlPoints[0]
        first = gp_Pnt(first[0], first[1], first[2])
        last = controlPoints[-1]
        last = gp_Pnt(last[0], last[1], last[2])

        if not first.IsEqual(last, 1.0e-9):
            closer = BRepBuilderAPI_MakeEdge(
                gp_Lin(first, gp_Dir(gp_Vec(first, last))), first, last)
            wire.Add(closer.Edge())

        face = BRepBuilderAPI_MakeFace(wire.Wire())
        if axis == 0:
            extrusion_vector = gp_Vec(self.thickness, 0, 0)
        elif axis == 1:
            extrusion_vector = gp_Vec(0, self.thickness, 0)
        elif axis == 2:
            extrusion_vector = gp_Vec(0, 0, self.thickness)

        self.instance = BRepPrimAPI_MakePrism(face.Shape(), extrusion_vector)
        Solid.__init__(self, self.instance.Shape(), center=center)
예제 #5
0
def variable_filleting(event=None):
    display.EraseAll()
    # Create Box
    Box = BRepPrimAPI_MakeBox(200, 200, 200).Shape()
    # Fillet
    Rake = BRepFilletAPI_MakeFillet(Box)
    ex = Topo(Box).edges()
    next(ex)
    next(ex)
    next(ex)

    Rake.Add(8, 50, next(ex))
    Rake.Build()
    if Rake.IsDone():
        evolvedBox = Rake.Shape()
        display.DisplayShape(evolvedBox)
    else:
        print("Rake not done.")
    # Create Cylinder
    Cylinder = BRepPrimAPI_MakeCylinder(
        gp_Ax2(gp_Pnt(-300, 0, 0), gp_Dir(0, 0, 1)), 100, 200).Shape()
    fillet = BRepFilletAPI_MakeFillet(Cylinder)

    TabPoint2 = TColgp_Array1OfPnt2d(0, 20)
    for i in range(0, 20):
        Point2d = gp_Pnt2d(i * 2 * pi / 19,
                           60 * cos(i * pi / 19 - pi / 2) + 10)
        TabPoint2.SetValue(i, Point2d)

    exp2 = Topo(Cylinder).edges()
    fillet.Add(TabPoint2, next(exp2))
    fillet.Build()
    if fillet.IsDone():
        LawEvolvedCylinder = fillet.Shape()
        display.DisplayShape(LawEvolvedCylinder)
    else:
        print("fillet not done.")  ## TODO : fillet not done
    P = gp_Pnt(350, 0, 0)
    Box2 = BRepPrimAPI_MakeBox(P, 200, 200, 200).Shape()
    afillet = BRepFilletAPI_MakeFillet(Box2)

    TabPoint = TColgp_Array1OfPnt2d(1, 6)
    P1 = gp_Pnt2d(0., 8.)
    P2 = gp_Pnt2d(0.2, 16.)
    P3 = gp_Pnt2d(0.4, 25.)
    P4 = gp_Pnt2d(0.6, 55.)
    P5 = gp_Pnt2d(0.8, 28.)
    P6 = gp_Pnt2d(1., 20.)
    TabPoint.SetValue(1, P1)
    TabPoint.SetValue(2, P2)
    TabPoint.SetValue(3, P3)
    TabPoint.SetValue(4, P4)
    TabPoint.SetValue(5, P5)
    TabPoint.SetValue(6, P6)

    exp = Topo(Box2).edges()
    next(exp)
    next(exp)
    next(exp)

    afillet.Add(TabPoint, next(exp))
    afillet.Build()
    if afillet.IsDone():
        LawEvolvedBox = afillet.Shape()
    else:
        print("aFillet not done.")
        display.DisplayShape(LawEvolvedBox)
    display.FitAll()