Exemple #1
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
 def test_const_Standard_Integer_byref(self):
     '''
     Test wrapper for const Standard_Integer &
     '''
     t = TColStd_Array1OfInteger(1, 2)
     t.SetValue(1, 3)
     t.SetValue(2, 33)
     self.assertEqual(t.Value(1), 3)
     self.assertEqual(t.Value(2), 33)
Exemple #3
0
def array1_from_integers1(numbers: List[int]) -> TColStd_Array1OfInteger:
    """Construct a one-dimensional integer array from a list of integers.

    Parameters
    ----------
    numbers : list[int]

    Returns
    -------
    TColStd_Array1OfInteger

    """
    array = TColStd_Array1OfInteger(1, len(numbers))
    for index, number in enumerate(numbers):
        array.SetValue(index + 1, number)
    return array
Exemple #4
0
def to_tcolstd_array1_integer(array):
    """
    Convert the 1-D array of integers to OCC data.

    :param array_like array: Array of integers.

    :return: OCC array of integers.
    :rtype: TColStd_Array1OfInteger
    """
    ints = [int(x) for x in array]
    n = len(ints)
    array = TColStd_Array1OfInteger(1, n)
    for i, x in enumerate(ints, 1):
        array.SetValue(i, x)

    return array
 def test_create_mesh_datasource(self):
     # create data
     coord_data = [
         gp_Pnt(0, 0, 0),
         gp_Pnt(0, 1, 0),
         gp_Pnt(0, 1, -1),
         gp_Pnt(1, 0, 0),
         gp_Pnt(1, 1, 0),
     ]
     ele2_node_data = [[0, 1, 4, 3], [1, 2, 4]]
     # create data source
     a_data_source = MeshDS_DataSource(coord_data, ele2_node_data)
     # check node ids and number of elements
     node_ids = TColStd_Array1OfInteger(1, 4)
     is_ok, nb_nodes = a_data_source.GetNodesByElement(1, node_ids)
     self.assertTrue(is_ok)
     self.assertEqual(nb_nodes, 4)
     self.assertEqual(node_ids.Value(1), 1)
     self.assertEqual(node_ids.Value(2), 2)
     self.assertEqual(node_ids.Value(3), 5)
     self.assertEqual(node_ids.Value(4), 4)
     is_ok, nb_nodes = a_data_source.GetNodesByElement(2, node_ids)
     self.assertTrue(is_ok)
     self.assertEqual(nb_nodes, 3)
     self.assertEqual(node_ids.Value(1), 2)
     self.assertEqual(node_ids.Value(2), 3)
     self.assertEqual(node_ids.Value(3), 5)
     # check normal of elements
     is_ok, nx, ny, nz = a_data_source.GetNormal(1, 3)
     self.assertEqual(nx, 0.0)
     self.assertEqual(ny, 0.0)
     self.assertEqual(nz, -1.0)
     is_ok, nx, ny, nz = a_data_source.GetNormal(2, 3)
     self.assertEqual(nx, 0.0)
     self.assertEqual(ny, -1.0)
     self.assertEqual(nz, 0.0)
     # check normal of nodes
     is_ok, nx, ny, nz = a_data_source.GetNodeNormal(1, 1)
     self.assertEqual(nx, 0.0)
     self.assertEqual(ny, 0.0)
     self.assertEqual(nz, -1.0)
     is_ok, nx, ny, nz = a_data_source.GetNodeNormal(1, 2)
     self.assertEqual(nx, 0.0)
     # floating point number comparison, rounded to 12 decimals
     self.assertEqual(round(ny, 12), -round(sqrt(2) / 2, 12))
     self.assertEqual(round(nz, 12), -round(sqrt(2) / 2, 12))
Exemple #6
0
def int_list_to_TColStd_Array1OfInteger(li):
    pts = TColStd_Array1OfInteger(1, len(li))
    for n, i in enumerate(li):
        pts.SetValue(n + 1, i)
    return pts
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)



myGeom2d_BSplineCurve = Geom2d_BSplineCurve(curgp_Array1CurvePoles2d, curgp_Array1CurveKnots2d, curgp_Array1CurveMulti2d, myDegree)

knots:TColStd_Array1OfReal=myGeom2d_BSplineCurve.Knots()
mults:TColStd_Array1OfInteger=myGeom2d_BSplineCurve.Multiplicities()
Exemple #8
0
def opencascade_array1_of_int(arr):
    ret = TColStd_Array1OfInteger(1, len(arr))
    for i in range(len(arr)):
        ret.SetValue(i + 1, int(arr[i]))
    return ret
Exemple #9
0
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())
display.DisplayShape(nurbs, update=True, color='RED')
start_display()