Пример #1
0
def convert_2dcurve(curve, convert_2bs=False):
    curve_t = curve.Edge()
    d1_feat = {
        "type": edge_map[curve.GetType()],
        "interval": [curve.FirstParameter(),
                     curve.LastParameter()]
    }
    c_type = d1_feat["type"]

    if c_type == "Line":
        c = curve.Line()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["direction"] = list(c.Direction().Coord())
    elif c_type == "Circle":
        c = curve.Circle()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["radius"] = c.Radius()
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
    elif c_type == "Ellipse":
        c = curve.Ellipse()
        d1_feat["focus1"] = list(c.Focus1().Coord())
        d1_feat["focus2"] = list(c.Focus2().Coord())
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
        d1_feat["maj_radius"] = c.MajorRadius()
        d1_feat["min_radius"] = c.MinorRadius()
    elif c_type == "BSpline":
        if not convert_2bs:
            c = curve.BSpline()
        else:
            c = curve
        c.SetNotPeriodic()
        d1_feat["rational"] = c.IsRational()
        d1_feat["closed"] = c.IsClosed()
        d1_feat["continuity"] = c.Continuity()
        d1_feat["degree"] = c.Degree()
        p = TColgp_Array1OfPnt2d(1, c.NbPoles())
        c.Poles(p)
        points = []
        for pi in range(p.Length()):
            points.append(list(p.Value(pi + 1).Coord()))
        d1_feat["poles"] = points

        k = TColStd_Array1OfReal(1, c.NbPoles() + c.Degree() + 1)
        c.KnotSequence(k)
        knots = []
        for ki in range(k.Length()):
            knots.append(k.Value(ki + 1))
        d1_feat["knots"] = knots

        w = TColStd_Array1OfReal(1, c.NbPoles())
        c.Weights(w)
        weights = []
        for wi in range(w.Length()):
            weights.append(w.Value(wi + 1))
        d1_feat["weights"] = weights
    else:
        print("Unsupported type 2d", c_type)
    return d1_feat
 def test_const_Standard_Real_byref(self):
     '''
     Test wrapper for const Standard_Real &
     '''
     t = TColStd_Array1OfReal(1, 10)
     t.SetValue(3, 3.14)
     self.assertEqual(t.Value(3), 3.14)
Пример #3
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
Пример #4
0
def array1_from_floats1(numbers: List[float]) -> TColStd_Array1OfReal:
    """Construct a one-dimensional float array from a list of floats.

    Parameters
    ----------
    numbers : list[float]

    Returns
    -------
    TColStd_Array1OfReal

    """
    array = TColStd_Array1OfReal(1, len(numbers))
    for index, number in enumerate(numbers):
        array.SetValue(index + 1, number)
    return array
Пример #5
0
def to_tcolstd_array1_real(array):
    """
    Convert the 1-D array of floats to OCC data.

    :param array_like array: Array of floats.

    :return: OCC array of floats.
    :rtype: TColStd_Array1OfReal
    """
    flts = [float(x) for x in array]
    n = len(flts)
    array = TColStd_Array1OfReal(1, n)
    for i, x in enumerate(flts, 1):
        array.SetValue(i, x)

    return array
Пример #6
0
def float_list_to_TColStd_Array1OfReal(li):
    pts = TColStd_Array1OfReal(1, len(li))
    for n, i in enumerate(li):
        pts.SetValue(n + 1, i)
    return pts
from OCC.Display.SimpleGui import init_display
display, start_display, add_menu, add_function_to_menu = init_display()

myFirstgp_Pnt2d=gp.Origin2d()
mySecondgp_Pnt2d=gp_Pnt2d(-10,2)
myThirdgp_Pnt2d=gp_Pnt2d(5,7)
myFourthgp_Pnt2d=gp_Pnt2d(5,15)
myDegree=2

curgp_Array1CurvePoles2d = TColgp_Array1OfPnt2d(1, 4)
curgp_Array1CurvePoles2d.SetValue(1, myFirstgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(2, mySecondgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(3, myThirdgp_Pnt2d)
curgp_Array1CurvePoles2d.SetValue(4, myFourthgp_Pnt2d)

curgp_Array1CurveWeights2d = TColStd_Array1OfReal(1, 4)
curgp_Array1CurveWeights2d.SetValue(1, 1.0)
curgp_Array1CurveWeights2d.SetValue(2, 1.0)
curgp_Array1CurveWeights2d.SetValue(3, 1.0)
curgp_Array1CurveWeights2d.SetValue(4, 1.0)

curgp_Array1CurveMulti2d = TColStd_Array1OfInteger(1, 3)
curgp_Array1CurveMulti2d.SetValue(1, 3)
curgp_Array1CurveMulti2d.SetValue(2, 1)
curgp_Array1CurveMulti2d.SetValue(3, 3)

curgp_Array1CurveKnots2d = TColStd_Array1OfReal(1, 3)
curgp_Array1CurveKnots2d.SetValue(1, 0.0)
curgp_Array1CurveKnots2d.SetValue(2, 1.0)
curgp_Array1CurveKnots2d.SetValue(3, 2.0)
Пример #8
0
def convert_surface(surf, convert_2bs=False):
    surf_t = surf.Face()
    d2_feat = {"type": surf_map[surf.GetType()]}

    s_type = d2_feat["type"]

    if s_type == "Plane":
        s = surf.Plane()
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["z_axis"] = list(s.Axis().Direction().Coord())
        d2_feat["x_axis"] = list(s.XAxis().Direction().Coord())
        d2_feat["y_axis"] = list(s.YAxis().Direction().Coord())
        d2_feat["coefficients"] = list(s.Coefficients())

    elif s_type == "Cylinder":
        s = surf.Cylinder()
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["z_axis"] = list(s.Axis().Direction().Coord())
        d2_feat["x_axis"] = list(s.XAxis().Direction().Coord())
        d2_feat["y_axis"] = list(s.YAxis().Direction().Coord())
        d2_feat["coefficients"] = list(s.Coefficients())
        d2_feat["radius"] = s.Radius()

    elif s_type == "Cone":
        s = surf.Cone()
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["z_axis"] = list(s.Axis().Direction().Coord())
        d2_feat["x_axis"] = list(s.XAxis().Direction().Coord())
        d2_feat["y_axis"] = list(s.YAxis().Direction().Coord())
        d2_feat["coefficients"] = list(s.Coefficients())
        d2_feat["radius"] = s.RefRadius()
        d2_feat["angle"] = s.SemiAngle()
        d2_feat["apex"] = list(s.Apex().Coord())

    elif s_type == "Sphere":
        s = surf.Sphere()
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["x_axis"] = list(s.XAxis().Direction().Coord())
        d2_feat["y_axis"] = list(s.YAxis().Direction().Coord())
        d2_feat["coefficients"] = list(s.Coefficients())
        d2_feat["radius"] = s.Radius()

    elif s_type == "Torus":
        s = surf.Torus()
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["z_axis"] = list(s.Axis().Direction().Coord())
        d2_feat["x_axis"] = list(s.XAxis().Direction().Coord())
        d2_feat["y_axis"] = list(s.YAxis().Direction().Coord())
        d2_feat["max_radius"] = s.MajorRadius()
        d2_feat["min_radius"] = s.MinorRadius()

    elif s_type == "Bezier":
        print("BEZIER SURF")

    elif s_type == "BSpline":
        if not convert_2bs:
            c = surf.BSpline()
        else:
            c = surf

        _round = lambda x: round(x, 15)
        d2_feat["trim_domain"] = list(map(_round, breptools_UVBounds(surf_t)))
        d2_feat["face_domain"] = list(map(_round, c.Bounds()))
        d2_feat[
            "is_trimmed"] = d2_feat["trim_domain"] != d2_feat["face_domain"]
        c.SetUNotPeriodic()
        c.SetVNotPeriodic()
        d2_feat["u_rational"] = c.IsURational()
        d2_feat["v_rational"] = c.IsVRational()
        d2_feat["u_closed"] = c.IsUClosed()
        d2_feat["v_closed"] = c.IsVClosed()
        d2_feat["continuity"] = c.Continuity()
        d2_feat["u_degree"] = c.UDegree()
        d2_feat["v_degree"] = c.VDegree()

        p = TColgp_Array2OfPnt(1, c.NbUPoles(), 1, c.NbVPoles())
        c.Poles(p)
        points = []
        for pi in range(p.ColLength()):
            elems = []
            for pj in range(p.RowLength()):
                elems.append(list(p.Value(pi + 1, pj + 1).Coord()))
            points.append(elems)
        d2_feat["poles"] = points

        k = TColStd_Array1OfReal(1, c.NbUPoles() + c.UDegree() + 1)
        c.UKnotSequence(k)
        knots = []
        for ki in range(k.Length()):
            knots.append(k.Value(ki + 1))
        d2_feat["u_knots"] = knots

        k = TColStd_Array1OfReal(1, c.NbVPoles() + c.VDegree() + 1)
        c.VKnotSequence(k)
        knots = []
        for ki in range(k.Length()):
            knots.append(k.Value(ki + 1))
        d2_feat["v_knots"] = knots

        w = TColStd_Array2OfReal(1, c.NbUPoles(), 1, c.NbVPoles())
        c.Weights(w)
        weights = []
        for wi in range(w.ColLength()):
            elems = []
            for wj in range(w.RowLength()):
                elems.append(w.Value(wi + 1, wj + 1))
            weights.append(elems)
        d2_feat["weights"] = weights

        scale_factor = 1.0

    elif s_type == "Revolution":
        s = surf.AxeOfRevolution()
        c = surf.BasisCurve()
        d1_feat = convert_curve(c)
        d2_feat["location"] = list(s.Location().Coord())
        d2_feat["z_axis"] = list(s.Direction().Coord())
        d2_feat["curve"] = d1_feat

    elif s_type == "Extrusion":
        c = surf.BasisCurve()
        d1_feat = convert_curve(c)
        d2_feat["direction"] = list(surf.Direction().Coord())
        d2_feat["curve"] = d1_feat

    else:
        print("Unsupported type", s_type)

    return d2_feat
Пример #9
0
def convert_curve(curve):
    d1_feat = {"type": edge_map[curve.GetType()]}
    c_type = d1_feat["type"]
    if c_type == "Line":
        c = curve.Line()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["direction"] = list(c.Direction().Coord())
        scale_factor = 1000.0
        #occ_node_s = occ_brt.Pnt(topods_Vertex(list(occ_topo.vertices())[elemNodeTags[0][0]-1 - occ_offset]))
        #occ_node_e = occ_brt.Pnt(topods_Vertex(list(occ_topo.vertices())[elemNodeTags[0][-1]-1 - occ_offset]))
        #print(occ_node_s.Coord(), curve.Value(curve.FirstParameter()).Coord(), v_nodes[elemNodeTags[0][0]-1], occ_node_e.Coord(), curve.Value(curve.LastParameter()).Coord(), v_nodes[elemNodeTags[0][-1]-1])
        #print(c.Location().Coord(), c.Direction().Coord())
        #print("E", np.allclose(np.array(curve.Value(curve.LastParameter()).Coord()), np.array(c.Location().Coord())+curve.LastParameter()*np.array(c.Direction().Coord())))
        #print("S", np.allclose(np.array(curve.Value(curve.FirstParameter()).Coord()), np.array(c.Location().Coord())+curve.FirstParameter()*np.array(c.Direction().Coord())))
        #print(e, nodeTags, nodeCoords, nodeParams, gmsh.model.getType(e[0], e[1]), elemTypes, elemTags, elemNodeTags)
    elif c_type == "Circle":
        c = curve.Circle()
        d1_feat["location"] = list(c.Location().Coord())
        d1_feat["z_axis"] = list(c.Axis().Direction().Coord())
        d1_feat["radius"] = c.Radius()
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
        scale_factor = 1.0
        #print(c.Location().Coord(), c.Axis().Direction().Coord(), c.Radius())
    elif c_type == "Ellipse":
        c = curve.Ellipse()
        d1_feat["focus1"] = list(c.Focus1().Coord())
        d1_feat["focus2"] = list(c.Focus2().Coord())
        d1_feat["x_axis"] = list(c.XAxis().Direction().Coord())
        d1_feat["y_axis"] = list(c.YAxis().Direction().Coord())
        d1_feat["z_axis"] = list(c.Axis().Direction().Coord())
        d1_feat["maj_radius"] = c.MajorRadius()
        d1_feat["min_radius"] = c.MinorRadius()
        scale_factor = 1.0
        #print(c.Focus1().Coord(), c.Focus2().Coord(), c.XAxis().Direction().Coord(), c.YAxis().Direction().Coord(), c.Axis().Direction().Coord(), c.MajorRadius(), c.MinorRadius())
    elif c_type == "BSpline":
        c = curve.BSpline().GetObject()
        #print(dir(c))
        c.SetNotPeriodic()
        d1_feat["rational"] = c.IsRational()
        d1_feat["closed"] = c.IsClosed()
        #d1_feat["periodic"] = c.IsPeriodic()
        d1_feat["continuity"] = c.Continuity()
        d1_feat["degree"] = c.Degree()
        p = TColgp_Array1OfPnt(1, c.NbPoles())
        c.Poles(p)
        points = []
        for pi in range(p.Length()):
            points.append(list(p.Value(pi + 1).Coord()))
        d1_feat["poles"] = points

        k = TColStd_Array1OfReal(1, c.NbPoles() + c.Degree() + 1)
        c.KnotSequence(k)
        knots = []
        for ki in range(k.Length()):
            knots.append(k.Value(ki + 1))
        d1_feat["knots"] = knots

        w = TColStd_Array1OfReal(1, c.NbPoles())
        c.Weights(w)
        weights = []
        for wi in range(w.Length()):
            weights.append(w.Value(wi + 1))
        d1_feat["weights"] = weights

        scale_factor = 1.0
        #print(c.Knots())
        #d1_feat[""] =
        #d1_feat[""] =
        #d1_feat[""] =
        #d1_feat[""] =
        #print(c.IsRational(), c.IsClosed(), c.IsPeriodic(), c.Continuity(), c.Degree())
    else:
        print("Unsupported type", c_type)
    return d1_feat
Пример #10
0
def opencascade_array1_of_real(arr):
    ret = TColStd_Array1OfReal(1, len(arr))
    for i in range(len(arr)):
        ret.SetValue(i + 1, float(arr[i]))
    return ret
Пример #11
0
from __future__ import print_function

from OCC.Core.gp import gp_Pnt2d,gp_Pnt,gp_Circ,gp_Ax2
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())