def test_list(self):
     '''
     Test python lists features
     '''
     P1 = gp_Pnt(1, 2, 3)
     P2 = gp_Pnt(2, 3, 4)
     P3 = gp_Pnt(5, 7, 8)
     l = [P1, P2]
     self.assertEqual(P1 in l, True)
     self.assertNotEqual(P3 in l, True)
     self.assertEqual(l.index(P1), 0)
     self.assertEqual(l.index(P2), 1)
     # Do the same for Vertices (TopoDS_Shape has
     # a HashCode() method overloaded
     V1 = BRepBuilderAPI_MakeVertex(P1).Vertex()
     V2 = BRepBuilderAPI_MakeVertex(P2).Vertex()
     V3 = BRepBuilderAPI_MakeVertex(P3) .Vertex()
     vl = [V1, V2]
     self.assertEqual(V1 in vl, True)
     self.assertNotEqual(V3 in vl, True)
     # index test()
     self.assertEqual(vl.index(V1), 0)
     self.assertEqual(vl.index(V2), 1)
     # reverse() test
     vl.reverse()
     self.assertEqual(vl.index(V1), 1)
     self.assertEqual(vl.index(V2), 0)
 def test_dict(self):
     '''
     Test python dict features
     '''
     P1 = gp_Pnt(1, 2, 3)
     P2 = gp_Pnt(2, 3, 4)
     d = {P1: 'P1', P2: 'P2'}
     self.assertEqual(d[P1] == 'P1', True)
     self.assertEqual(d[P2] == 'P2', True)
 def test_downcast_curve(self):
     """ 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)
 def test_surfaces_from_revolution(self):
     '''Test: surfaces from revolution'''
     array = []
     array.append(gp_Pnt(0, 0, 1))
     array.append(gp_Pnt(1, 2, 2))
     array.append(gp_Pnt(2, 3, 3))
     array.append(gp_Pnt(4, 3, 4))
     array.append(gp_Pnt(5, 5, 5))
     aCurve = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array)).Curve()
     SOR = Geom_SurfaceOfRevolution(aCurve, gp_OX())
     edge = make_edge(aCurve)
     self.assertFalse(edge.IsNull())
     face = make_face(SOR)
     self.assertFalse(face.IsNull())
    def test_project_point_on_curve(self):
        '''Test: project point on curve'''
        P = gp_Pnt(1., 2., 3.)
        radius = 5.

        C = Geom_Circle(gp_XOY(), radius)
        PPC = GeomAPI_ProjectPointOnCurve(P, C)
        N = PPC.NearestPoint()
        self.assertIsInstance(N, gp_Pnt)
        NbResults = PPC.NbPoints()
        edg = make_edge(C)
        self.assertFalse(edg.IsNull())

        if NbResults > 0:
            for i in range(1, NbResults+1):
                Q = PPC.Point(i)
                self.assertIsInstance(Q, gp_Pnt)
                distance = PPC.Distance(i)
                # in any case, it should be > 1
                self.assertGreater(distance, 1.)

        pstring = "N : at Distance : " + repr(PPC.LowerDistance())

        for i in range(1, NbResults+1):
            Q = PPC.Point(i)
            self.assertIsInstance(Q, gp_Pnt)
            distance = PPC.Distance(i)
            # in any case, it should be > 1
            self.assertGreater(distance, 1.)
            pstring = "Q" + repr(i) + ": at Distance :" + repr(PPC.Distance(i))
            print(pstring)
Esempio n. 6
0
def center_boundingbox(shape):
    """ compute the center point of a TopoDS_Shape, based on its bounding box

    Parameters
    ----------

    shape : TopoDS_Shape instance or a subclass like TopoDS_Face

    Returns
    -------

    gp_Pnt

    """
    xmin, ymin, zmin, xmax, ymax, zmax = get_boundingbox(shape, 1e-6)
    return midpoint(gp_Pnt(xmin, ymin, zmin), gp_Pnt(xmax, ymax, zmax))
 def test_repr_overload(self):
     """ Test if repr string is properly returned
     """
     p = gp_Pnt(1,2,3)
     assert str(p) == "class<'gp_Pnt'>"
     shp = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
     assert "class<'TopoDS_Shape'; Type:Solid; id:" in str(shp)
 def test_repr_overload(self):
     """ Test if repr string is properly returned
     """
     p = gp_Pnt(1, 2, 3)
     self.assertEqual(str(p), "class<'gp_Pnt'>")
     shp = BRepPrimAPI_MakeBox(10, 20, 30).Shape()
     self.assertTrue("class<'TopoDS_Solid'; id:" in str(shp))
Esempio n. 9
0
    def DisplayMessage(self, point, text_to_write, height=None, message_color=None, update=False):
        """
        :point: a gp_Pnt or gp_Pnt2d instance
        :text_to_write: a string
        :message_color: triple with the range 0-1
        """
        aPresentation = Prs3d_Presentation(self._struc_mgr)
        text_aspect = Prs3d_TextAspect()

        if message_color is not None:
            text_aspect.SetColor(rgb_color(*message_color))
        if height is not None:
            text_aspect.SetHeight(height)
        if isinstance(point, gp_Pnt2d):
            point = gp_Pnt(point.X(), point.Y(), 0)
        Prs3d_Text.Draw(aPresentation.GetHandle(),
                        text_aspect.GetHandle(),
                        to_string(text_to_write),
                        point)
        aPresentation.Display()
        # @TODO: it would be more coherent if a AIS_InteractiveObject
        # is be returned
        if update:
            self.Repaint()
        return aPresentation
def make_vertex(pnt):
    if isinstance(pnt, gp_Pnt2d):
        vertex = BRepBuilderAPI_MakeVertex(gp_Pnt(pnt.X(), pnt.Y(), 0))
    else:
        vertex = BRepBuilderAPI_MakeVertex(pnt)
    vertex.Build()
    return vertex.Shape()
 def test_ft1(self):
     """ Test: Standard_Integer & by reference transformator """
     p = gp_Pnt(1, 2, 3.2)
     p_coord = p.Coord()
     self.assertEqual(p_coord[0], 1.)
     self.assertEqual(p_coord[1], 2.)
     self.assertEqual(p_coord[2], 3.2)
 def test_memory_handle_getobject(self):
     """
     See https://github.com/tpaviot/pythonocc-generator/pull/24
     This commit tries to fix the issue tpaviot/pythonocc-core#292.
     When we got a handle from ann API function and called GetObject()
     the lifetime of the object was determined only by the handle.
     This lead to crashes, when only a reference to the object was stored.
     The commit registers the handle with its object to prevent premature
     destruction.
     This test case ensures everything is ok. Following lines used to crash
     on pythonocc-0.16.5
     """
     a = gp_Pnt(0., 0., 0.)
     b = gp_Pnt(100., 100., 100.)
     line3 = GC_MakeSegment(a, b).Value()
     self.assertEqual(line3.FirstParameter(), 0.)
     self.assertEqual(GC_MakeSegment(a, b).Value().FirstParameter(), 0.)
     self.assertTrue(b.IsEqual(line3.EndPoint(), 0.01))
     self.assertTrue(b.IsEqual(GC_MakeSegment(a, b).Value().EndPoint(), 0.01))
    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()
        self.assertTrue(aBSplineSurface1 is not None)
        aBSplineSurface2 = aGeomFill2.Surface()
        self.assertTrue(aBSplineSurface2 is not None)
        aBSplineSurface3 = aGeomFill3.Surface()
        self.assertTrue(aBSplineSurface3 is not None)
 def test_axis(self):
     '''Test: axis'''
     P1 = gp_Pnt(2, 3, 4)
     D = gp_Dir(4, 5, 6)
     A = gp_Ax3(P1, D)
     IsDirectA = A.Direct()
     self.assertTrue(IsDirectA)
     AXDirection = A.XDirection()
     self.assertIsInstance(AXDirection, gp_Dir)
     AYDirection = A.YDirection()
     self.assertIsInstance(AXDirection, gp_Dir)
     P2 = gp_Pnt(5, 3, 4)
     A2 = gp_Ax3(P2, D)
     A2.YReverse()
     # axis3 is now left handed
     IsDirectA2 = A2.Direct()
     self.assertFalse(IsDirectA2)
     A2XDirection = A2.XDirection()
     self.assertTrue(isinstance(A2XDirection, gp_Dir))
     A2YDirection = A2.YDirection()
     self.assertTrue(isinstance(A2YDirection, gp_Dir))
 def test_inherit_topods_shape(self):
     t = self
     class InheritEdge(TopoDS_Edge):
         def __init__(self, edge):
             # following constructor creates an empy TopoDS_Edge
             super(InheritEdge, self).__init__()
             # we need to copy the base shape using the following three
             # lines
             t.assertTrue(self.IsNull())
             self.TShape(edge.TShape())
             self.Location(edge.Location())
             self.Orientation(edge.Orientation())
             t.assertFalse(self.IsNull())
             # then it becomes possible to extend the base class
     # create a line, compute its length
     base_edge = BRepBuilderAPI_MakeEdge(gp_Pnt(100., 0., 0.),
                                         gp_Pnt(150., 0., 0.)).Edge()
     inherited_edge = InheritEdge(base_edge)
     g1 = GProp_GProps()
     brepgprop_LinearProperties(inherited_edge, g1)
     length = g1.Mass()
     self.assertEqual(length, 50.)
    def test_pipes(self):
        '''Test: pipes'''
        a1 = []
        a1.append(gp_Pnt(-4, 0, 2))
        a1.append(gp_Pnt(-5, 1, 0))
        a1.append(gp_Pnt(-6, 2, -2))
        a1.append(gp_Pnt(-5, 4, -7))
        a1.append(gp_Pnt(-3, 5, -12))

        xxx = point_list_to_TColgp_Array1OfPnt(a1)
        SPL1 = GeomAPI_PointsToBSpline(xxx).Curve()

        aPipe = GeomFill_Pipe(SPL1, True)
        aPipe.Perform(False, False)
        aSurface = aPipe.Surface()
        self.assertIsNotNone(aSurface)

        E = GC_MakeEllipse(gp_XOY(), 2, 1).Value()
        aPipe2 = GeomFill_Pipe(SPL1, E, GeomFill_IsConstantNormal)
        aPipe2.Perform(False, False)
        aSurface2 = aPipe2.Surface()
        aSurface2.Translate(gp_Vec(5, 0, 0))

        TC1 = GC_MakeSegment(gp_Pnt(1, 1, 1), gp_Pnt(2, 2, 2)).Value()
        TC2 = GC_MakeSegment(gp_Pnt(1, 1, 0), gp_Pnt(3, 2, 1)).Value()
        aPipe3 = GeomFill_Pipe(SPL1, TC1, TC2)
        aPipe3.Perform(False, False)
        aSurface3 = aPipe3.Surface()
        aSurface3.Translate(gp_Vec(10, 0, 0))

        for _, mode in enumerate([GeomFill_IsConstantNormal,
                                  GeomFill_IsCorrectedFrenet,
                                  GeomFill_IsDarboux,
                                  GeomFill_IsFrenet,
                                  GeomFill_IsGuideAC,
                                  GeomFill_IsGuideACWithContact,
                                  GeomFill_IsGuidePlan,
                                  GeomFill_IsGuidePlanWithContact]):
            E = GC_MakeEllipse(gp_XOY(), 2, 1).Value()
            aPipe2 = GeomFill_Pipe(SPL1, TC1, TC2, mode)
            aPipe2.Perform(False, False)
            aSurface2 = aPipe2.Surface()
            aSurface2.Translate(gp_Vec(5, 5, 0))
 def test_shape_conversion_as_py_none(self):
     # see issue #600 and PR #614
     # a null topods_shape should be returned as Py_None by the TopoDS transformer
     # the following test case returns a null topods_shape
     box = BRepPrimAPI_MakeBox(1., 1., 1.).Shape()
     hlr = HLRBRep_Algo()
     hlr.Add(box)
     projector = HLRAlgo_Projector(gp_Ax2(gp_Pnt(), gp_Dir(-1.75, 1.1, 5)))
     hlr.Projector(projector)
     hlr.Update()
     hlr.Hide()
     hlr_shapes = HLRBRep_HLRToShape(hlr)
     visible_smooth_edges = hlr_shapes.Rg1LineVCompound()
     self.assertTrue(visible_smooth_edges is None)
 def test_hash_eq_operator(self):
     ''' test that the == wrapper is ok
     '''
     # test Standard
     s = Standard_Transient()
     s2 = Standard_Transient()
     self.assertFalse(s == s2)
     self.assertTrue(s == s)
     # test list.index, that uses __eq__ method
     p1 = gp_Pnt(0., 0., 0.)
     line = gp_Lin(p1, gp_Dir(1., 0., 0.))
     items = [p1, line]
     res = items.index(line)
     self.assertEqual(res, 1.)
    def test_surfaces_from_offsets(self):
        '''Test: surfaces from offsets'''
        array1 = []
        array1.append(gp_Pnt(-4, 5, 5))
        array1.append(gp_Pnt(-3, 6, 6))
        array1.append(gp_Pnt(-1, 7, 7))
        array1.append(gp_Pnt(0, 8, 8))
        array1.append(gp_Pnt(2, 9, 9))
        SPL1 = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array1)).Curve()

        array2 = []
        array2.append(gp_Pnt(-4, 5, 2))
        array2.append(gp_Pnt(-3, 6, 3))
        array2.append(gp_Pnt(-1, 7, 4))
        array2.append(gp_Pnt(0, 8, 5))
        array2.append(gp_Pnt(2, 9, 6))
        SPL2 = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array2)).Curve()

        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)
        aGeomSurface = aGeomFill1.Surface()

        offset = 1
        GOS = Geom_OffsetSurface(aGeomSurface, offset)
        offset = 2
        GOS1 = Geom_OffsetSurface(aGeomSurface, offset)
        offset = 3
        GOS2 = Geom_OffsetSurface(aGeomSurface, offset)

        face1 = make_face(aGeomSurface)
        self.assertTrue(face1 is not None)
        face2 = make_face(GOS)
        self.assertTrue(face2 is not None)
        face3 = make_face(GOS1)
        self.assertTrue(face3 is not None)
        face4 = make_face(GOS2)
        self.assertTrue(face4 is not None)
Esempio n. 20
0
def midpoint(pntA, pntB):
    """ computes the point that lies in the middle between pntA and pntB

    Parameters
    ----------

    pntA, pntB : gp_Pnt

    Returns
    -------

    gp_Pnt

    """
    vec1 = gp_Vec(pntA.XYZ())
    vec2 = gp_Vec(pntB.XYZ())
    veccie = (vec1 + vec2) * 0.5
    return gp_Pnt(veccie.XYZ())
    def test_array_iterator(self):
        P0 = gp_Pnt(1, 2, 3)
        list_of_points = TColgp_Array1OfPnt(5, 8)
        self.assertEqual(len(list_of_points), 4)

        # set item
        list_of_points[1] = P0

        # then get item
        self.assertEqual(list_of_points[1].Coord(), (1.0, 2.0, 3.0))
        with self.assertRaises(IndexError):
            list_of_points[4]
        # iterator creation
        it = iter(list_of_points)
        next(it)

        # test loop over iterable
        for pnt in list_of_points:
            self.assertTrue(isinstance(pnt, gp_Pnt))
 def test_point_from_projections(self):
     '''Test: point from projections'''
     P = gp_Pnt(7., 8., 9.)
     radius = 5
     SP = Geom_SphericalSurface(gp_Ax3(gp_XOY()), radius)
     PPS = GeomAPI_ProjectPointOnSurf(P, SP)
     N = PPS.NearestPoint()
     self.assertTrue(isinstance(N, gp_Pnt))
     NbResults = PPS.NbPoints()
     if NbResults > 0:
         for i in range(1, NbResults+1):
             Q = PPS.Point(i)
             self.assertTrue(isinstance(Q, gp_Pnt))
             distance = PPS.Distance(i)
             # in any case, it should be > 1
             self.assertGreater(distance, 1.)
     lower_d = PPS.LowerDistance()
     self.assertGreater(lower_d, 1.)
     if NbResults > 0:
         for i in range(1, NbResults+1):
             Q = PPS.Point(i)
             distance = PPS.Distance(i)
             pstring = "Q" + repr(i) + ": at Distance :" + repr(PPS.Distance(i))
Esempio n. 23
0
    def DisplayVector(self, vec, pnt, update=False):
        """ displays a vector as an arrow
        """
        if self._inited:
            aPresentation = Prs3d_Presentation(self._struc_mgr)

            pnt_as_vec = gp_Vec(pnt.X(), pnt.Y(), pnt.Z())
            start = pnt_as_vec + vec
            pnt_start = gp_Pnt(start.X(), start.Y(), start.Z())

            Prs3d_Arrow.Draw(
                aPresentation.GetHandle(),
                pnt_start,
                gp_Dir(vec),
                math.radians(20),
                vec.Magnitude()
            )
            aPresentation.Display()
            # it would be more coherent if a AIS_InteractiveObject
            # would be returned
            if update:
                self.Repaint()
            return aPresentation
Esempio n. 24
0
    skiner.SetSmoothing(True)
    #skiner.SetMaxDegree(5)

    vstart = BRepBuilderAPI_MakeVertex(pntStart).Vertex()
    skiner.AddVertex(vstart)

    for wire in wires:
        skiner.AddWire(wire)

    vend = BRepBuilderAPI_MakeVertex(pntEnd).Vertex()
    skiner.AddVertex(vend)

    skiner.Build()

    return skiner.Shape()


if __name__ == '__main__':

    SceneScreenInit()
    SceneDrawAxis('axis')

    circle = GC_MakeCircle(gp_Pnt(0, 3, 5), gp_Pnt(0, -3, 5),
                           gp_Pnt(3, 0, 5)).Value()
    edge = BRepBuilderAPI_MakeEdge(circle).Edge()
    wire = BRepBuilderAPI_MakeWire(edge).Wire()
    shape = getShapeSkin(gp_Pnt(0, 0, 0), [wire], gp_Pnt(0, 0, 8))
    SceneDrawShape('skin', shape)

    SceneScreenStart()
Esempio n. 25
0
import argparse

sys.path.append(os.path.join("../"))
from src.plyfile import PlyData

from OCC.Display.SimpleGui import init_display
from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir
from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3
from OCC.Core.gp import gp_Pln, gp_Trsf, gp_Lin, gp_Elips
from OCC.Extend.DataExchange import read_iges_file, read_step_file, read_stl_file
from OCC.Extend.DataExchange import write_iges_file, write_step_file, write_stl_file

if __name__ == "__main__":
    argvs = sys.argv
    parser = argparse.ArgumentParser()
    parser.add_argument("--file", dest="file", default="../cadfile/buckling")
    opt = parser.parse_args()
    print(opt, argvs)

    ply_file = opt.file + ".ply"
    ply_data = PlyData.read(ply_file)
    print(ply_data["vertex"])
    print(ply_data["face"])

    display, start_display, add_menu, add_function_to_menu = init_display()

    display.DisplayShape(gp_Pnt())

    display.FitAll()
    start_display()
def edge(event=None):
    # The blud edge
    BlueEdge = BRepBuilderAPI_MakeEdge(gp_Pnt(-80, -50, -20),
                                       gp_Pnt(-30, -60, -60))
    V1 = BRepBuilderAPI_MakeVertex(gp_Pnt(-20, 10, -30))
    V2 = BRepBuilderAPI_MakeVertex(gp_Pnt(10, 7, -25))
    YellowEdge = BRepBuilderAPI_MakeEdge(V1.Vertex(), V2.Vertex())

    #The white edge
    line = gp_Lin(gp_Ax1(gp_Pnt(10, 10, 10), gp_Dir(1, 0, 0)))
    WhiteEdge = BRepBuilderAPI_MakeEdge(line, -20, 10)

    #The red edge
    Elips = gp_Elips(gp_Ax2(gp_Pnt(10, 0, 0), gp_Dir(1, 1, 1)), 60, 30)
    RedEdge = BRepBuilderAPI_MakeEdge(Elips, 0, math.pi / 2)

    # The green edge and the both extreme vertex
    P1 = gp_Pnt(-15, 200, 10)
    P2 = gp_Pnt(5, 204, 0)
    P3 = gp_Pnt(15, 200, 0)
    P4 = gp_Pnt(-15, 20, 15)
    P5 = gp_Pnt(-5, 20, 0)
    P6 = gp_Pnt(15, 20, 0)
    P7 = gp_Pnt(24, 120, 0)
    P8 = gp_Pnt(-24, 120, 12.5)
    array = TColgp_Array1OfPnt(1, 8)
    array.SetValue(1, P1)
    array.SetValue(2, P2)
    array.SetValue(3, P3)
    array.SetValue(4, P4)
    array.SetValue(5, P5)
    array.SetValue(6, P6)
    array.SetValue(7, P7)
    array.SetValue(8, P8)
    curve = Geom_BezierCurve(array)
    ME = BRepBuilderAPI_MakeEdge(curve.GetHandle())
    GreenEdge = ME
    V3 = ME.Vertex1()
    V4 = ME.Vertex2()

    display.DisplayColoredShape(BlueEdge.Edge(), 'BLUE')
    display.DisplayShape(V1.Vertex())
    display.DisplayShape(V2.Vertex())
    display.DisplayColoredShape(WhiteEdge.Edge(), 'WHITE')
    display.DisplayColoredShape(YellowEdge.Edge(), 'YELLOW')
    display.DisplayColoredShape(RedEdge.Edge(), 'RED')
    display.DisplayColoredShape(GreenEdge.Edge(), 'GREEN')
    display.DisplayShape(V3)
    display.DisplayShape(V4, update=True)
Esempio n. 27
0
    def Locate_centre_face2(self, number, name_body, angle, x_drive, y_drive):
        from OCC.Core.BRepBuilderAPI import BRepBuilderAPI_MakeFace, BRepBuilderAPI_MakeWire, BRepBuilderAPI_MakeEdge, \
            BRepBuilderAPI_Copy
        from OCC.Core.Bnd import Bnd_Box
        from OCC.Core.BRepBndLib import brepbndlib_Add
        from OCC.Core.gp import gp_Pnt, gp_Trsf, gp_Vec, gp_Pln, gp_Dir, gp_Ax3, gp_Ax1
        from OCC.Core.TopLoc import TopLoc_Location

        cp = BRepBuilderAPI_Copy(self.reserv_models[name_body])
        cp.Perform(self.reserv_models[name_body])
        shape = cp.Shape()

        # move to zero
        bbox = Bnd_Box()
        brepbndlib_Add(shape, bbox)
        xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(-xmin - (xmax - xmin) / 2, -ymin - (ymax - ymin) / 2,
                   -zmin))
        shape.Move(TopLoc_Location(trsf))

        # Process vector of rotation to face
        x, y = 1, 1

        x = -self.walls[number][1][1]
        y = self.walls[number][1][0]

        z = 0
        P0 = gp_Pnt(0, 0, 0)
        P1 = gp_Pnt(0, 0, 1)
        P2 = gp_Pnt(self.walls[number][1][0], self.walls[number][1][1],
                    self.walls[number][1][2])

        # rotation to Ax z
        v_x = gp_Vec(P0, gp_Pnt(0, 1, 0))
        v_r = gp_Vec(P0, gp_Pnt(x, y, z))
        trsf = gp_Trsf()
        #print(v_r.Angle(v_x))
        trsf.SetRotation(gp_Ax1(P0, gp_Dir(0, 0, 1)), v_r.Angle(v_x))
        shape.Move(TopLoc_Location(trsf))

        # rotation in parallel to face
        v0 = gp_Vec(P0, P1)
        v1 = gp_Vec(P0, P2)
        # print(v1.Angle(v0))
        trsf = gp_Trsf()
        trsf.SetRotation(gp_Ax1(P0, gp_Dir(x, y, z)), v1.Angle(v0))
        # move to face
        shape.Move(TopLoc_Location(trsf))
        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][0][0], self.walls[number][0][1],
                   self.walls[number][0][2]))
        shape.Move(TopLoc_Location(trsf))

        # Rotation by given angle
        trsf = gp_Trsf()
        trsf.SetRotation(
            gp_Ax1(
                P0,
                gp_Dir(self.walls[number][1][0], self.walls[number][1][1],
                       self.walls[number][1][2])), angle)
        shape.Move(TopLoc_Location(trsf))

        # initional x, y
        offset_y, offset_x = self.rot_point(xmax - xmin, ymax - ymin, angle)

        limit_x = self.walls[number][3][0] / 2 - offset_x
        limit_y = self.walls[number][3][1] / 2 - offset_y

        move_x = int(limit_x * x_drive)
        move_y = int(limit_y * y_drive)

        # Move to x and y
        x_axy = self.walls[number][1][1] * self.walls[number][2][
            2] - self.walls[number][1][2] * self.walls[number][2][1]
        y_axy = -(self.walls[number][1][0] * self.walls[number][2][2] -
                  self.walls[number][1][2] * self.walls[number][2][0])
        z_axy = self.walls[number][1][0] * self.walls[number][2][
            1] - self.walls[number][1][1] * self.walls[number][2][0]

        x_axy *= move_y
        y_axy *= move_y
        z_axy *= move_y

        trsf = gp_Trsf()
        trsf.SetTranslation(gp_Vec(x_axy, y_axy, z_axy))
        shape.Move(TopLoc_Location(trsf))

        trsf = gp_Trsf()
        trsf.SetTranslation(
            gp_Vec(self.walls[number][2][0] * move_x,
                   self.walls[number][2][1] * move_x,
                   self.walls[number][2][2] * move_x))
        shape.Move(TopLoc_Location(trsf))
        # print(name_body, shape)

        self.modules[name_body] = shape
Esempio n. 28
0
 def d0(self, arg):
     assert (self.is_edge())
     adaptor = self.AdaptorCurve()
     pnt = gp_Pnt()
     self.AdaptorCurve().D0(arg, pnt)
     return point3(pnt.X(), pnt.Y(), pnt.Z())
Esempio n. 29
0
    def getDeskBounds(self, pnt1, pnt2):
        dr = self.makeDraw()

        x1, y1, z1 = pnt1.X(), pnt1.Y(), pnt1.Z()
        x2, y2, z2 = pnt2.X(), pnt2.Y(), pnt2.Z()

        dr.nm('boundsLine', 1)

        dr.add(
            self.getDeskLine(gp_Pnt(x1, y1, z1), gp_Pnt(x1, y2, z1),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x1, y2, z1), gp_Pnt(x2, y2, z1),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y2, z1), gp_Pnt(x2, y1, z1),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y1, z1), gp_Pnt(x1, y1, z1),
                             'InfoStyle'))

        dr.add(
            self.getDeskLine(gp_Pnt(x1, y1, z1), gp_Pnt(x1, y1, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x1, y2, z1), gp_Pnt(x1, y2, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y1, z1), gp_Pnt(x2, y1, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y2, z1), gp_Pnt(x2, y2, z2),
                             'InfoStyle'))

        dr.add(
            self.getDeskLine(gp_Pnt(x1, y1, z2), gp_Pnt(x1, y2, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x1, y2, z2), gp_Pnt(x2, y2, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y2, z2), gp_Pnt(x2, y1, z2),
                             'InfoStyle'))
        dr.add(
            self.getDeskLine(gp_Pnt(x2, y1, z2), gp_Pnt(x1, y1, z2),
                             'InfoStyle'))

        return dr
Esempio n. 30
0
    def DisplayShape(self,
                     shapes,
                     material=None,
                     texture=None,
                     color=None,
                     transparency=None,
                     update=False):
        """ display one or a set of displayable objects
        """
        ais_shapes = []  # the list of all displayed shapes

        if issubclass(shapes.__class__, gp_Pnt):
            # if a gp_Pnt is passed, first convert to vertex
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(
                gp_Pnt(shapes.X(), shapes.Y(), 0))
            shapes = [vertex.Shape()]
        elif isinstance(shapes, Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
        elif isinstance(shapes, Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
        elif isinstance(shapes, Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
        # if only one shapes, create a list with a single shape
        if not isinstance(shapes, list):
            shapes = [shapes]
        # build AIS_Shapes list
        for shape in shapes:
            if material or texture:
                if texture:
                    shape_to_display = AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties(
                    )
                    shape_to_display.SetTextureFileName(
                        TCollection_AsciiString(filename))
                    shape_to_display.SetTextureMapOn()
                    shape_to_display.SetTextureScale(True, toScaleU, toScaleV)
                    shape_to_display.SetTextureRepeat(True, toRepeatU,
                                                      toRepeatV)
                    shape_to_display.SetTextureOrigin(True, originU, originV)
                    shape_to_display.SetDisplayMode(3)
                elif material:
                    shape_to_display = AIS_Shape(shape)
                    shape_to_display.SetMaterial(
                        Graphic3d_MaterialAspect(material))
            else:
                # TODO: can we use .Set to attach all TopoDS_Shapes
                # to this AIS_Shape instance?
                shape_to_display = AIS_Shape(shape)

            ais_shapes.append(shape_to_display)

        # if not SOLO:
        #     # computing graphic properties is expensive
        #     # if an iterable is found, so cluster all TopoDS_Shape under
        #     # an AIS_MultipleConnectedInteractive
        #     #shape_to_display = AIS_MultipleConnectedInteractive()
        #     for ais_shp in ais_shapes:
        #         # TODO : following line crashes with oce-0.18
        #         # why ? fix ?
        #         #shape_to_display.Connect(i)
        #         self.Context.Display(ais_shp, False)
        # set the graphic properties
        if material is None:
            #The default material is too shiny to show the object
            #color well, so I set it to something less reflective
            for shape_to_display in ais_shapes:
                shape_to_display.SetMaterial(
                    Graphic3d_MaterialAspect(Graphic3d_NOM_NEON_GNC))
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            elif isinstance(color, int):
                color = Quantity_Color(color)
            for shp in ais_shapes:
                self.Context.SetColor(shp, color, False)
        if transparency:
            for shape_to_display in ais_shapes:
                shape_to_display.SetTransparency(transparency)
        # display the shapes
        for shape_to_display in ais_shapes:
            self.Context.Display(shape_to_display, False)
        if update:
            # especially this call takes up a lot of time...
            self.FitAll()
            self.Repaint()

        return ais_shapes
Esempio n. 31
0
    anAxes = gp_Ax2(p, gp_Dir(aZDir), gp_Dir(aXDir))
    anAxes.SetLocation(
        gp_Pnt(p.XYZ() - ax * aHalfX - ay * aHalfY - az * aHalfZ))
    aBox = BRepPrimAPI_MakeBox(anAxes, 2.0 * aHalfX, 2.0 * aHalfY,
                               2.0 * aHalfZ).Shape()
    return aBox


# compute the oriented bounding box of a point cloud
obb1 = Bnd_OBB()
n = 10
for _ in range(n):
    x = random.uniform(100, 500)
    y = random.uniform(100, 500)
    z = random.uniform(100, 500)
    p = BRepBuilderAPI_MakeVertex(gp_Pnt(x, y, z)).Shape()
    display.DisplayShape(p)
    brepbndlib_AddOBB(p, obb1)
obb_shape1 = ConvertBndToShape(obb1)
display.DisplayShape(obb_shape1, transparency=0.5)

# then loads a brep file and computes the optimal bounding box
from OCC.Core.BRepTools import breptools_Read
from OCC.Core.TopoDS import TopoDS_Shape
from OCC.Core.BRep import BRep_Builder

cylinder_head = TopoDS_Shape()
builder = BRep_Builder()
breptools_Read(cylinder_head, '../assets/models/cylinder_head.brep', builder)
obb2 = Bnd_OBB()
brepbndlib_AddOBB(cylinder_head, obb2, True, True, True)
Esempio n. 32
0
 def d1(self, arg):
     assert (self.is_edge())
     adaptor = self.AdaptorCurve()
     pnt, vec = gp_Pnt(), gp_Vec()
     self.AdaptorCurve().D1(arg, pnt, vec)
     return vector3((vec.X(), vec.Y(), vec.Z()))
Esempio n. 33
0
import numpy as np
import matplotlib.pyplot as plt
import sys
import time
import os
from optparse import OptionParser

from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Pnt2d, gp_Pln, gp_Dir
from OCC.Core.BRepPrimAPI import BRepPrimAPI_MakePrism

sys.path.append(os.path.join('../'))
from src.base import plotocc

obj = plotocc()

pts = []
pts.append(gp_Pnt(0, 0, 0))
pts.append(gp_Pnt(0, 1, 0.1))
pts.append(gp_Pnt(1, 1, -0.1))
pts.append(gp_Pnt(1, 0, 0))
pts.append(pts[0])

face = obj.make_FaceByOrder(pts)
sold = BRepPrimAPI_MakePrism(face, gp_Vec(0, 0, 2)).Shape()

obj.display.DisplayShape(sold)
obj.export_stp(sold)
obj.show()
Esempio n. 34
0
def mirror_plane(ax, ay, az):
    trsf = gp_Trsf()
    trsf.SetMirror(gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(ax, ay, az)))
    return Transformation(trsf)
 def display_normals(lay):
     for la in lay:
         rayz = BRepBuilderAPI_MakeEdge(la[0], gp_Pnt((gp_Vec(la[0].XYZ())\
          + la[3]*10).XYZ())).Edge()
         display.DisplayShape(rayz, color='BLUE1', update=False)
 def generate_layer_path(faces, nozz_dia, direc, sur_nozz_dia=0):
     slices = []
     counter1 = 0
     layer = []
     frames = []
     counter2 = 0
     edge_clearance = (nozz_dia + sur_nozz_dia) / 2
     xmin, ymin, zzz, xmax, ymax, zzz =\
      Slicing.get_surfaces_boundingbox(faces)
     new_surfaces = Slicing.sort_surfaces(faces, direc)
     if direc == 'X':
         imin = xmin
         imax = xmax
     elif direc == 'Y':
         imin = ymin
         imax = ymax
     for i in numpy.arange(imin + edge_clearance, imax - edge_clearance,
                           nozz_dia):
         if direc == 'X':
             plane = gp_Pln(gp_Pnt(i, 0., 0), gp_Dir(1., 0., 0.))
         elif direc == 'Y':
             plane = gp_Pln(gp_Pnt(0., i, 0), gp_Dir(0., 1., 0.))
         face = BRepBuilderAPI_MakeFace(plane).Face()
         slices.append([])
         for surface in new_surfaces:
             slices[counter1].extend(Slicing.plane_shape_intersection(face,\
              surface))
         counter1 = counter1 + 1
     for s in slices:
         frames.append([])
         for j in range(0, len(s)):
             curve = BRepAdaptor_Curve(s[j])
             umin = curve.FirstParameter()
             umax = curve.LastParameter()
             if direc == 'X':
                 umin_value = curve.Value(umin).Y()
                 umax_value = curve.Value(umax).Y()
             elif direc == 'Y':
                 umin_value = curve.Value(umin).X()
                 umax_value = curve.Value(umax).X()
             if umin_value > umax_value:
                 umax = curve.FirstParameter()
                 umin = curve.LastParameter()
             length = GCPnts_AbscissaPoint().Length(curve)
             if j == 0:
                 kmin = umin + (umax - umin) * edge_clearance / length
             else:
                 kmin = umin
             if j == len(s) - 1:
                 kmax = umax - (umax - umin) * edge_clearance / length
             else:
                 kmax = umax - (umax - umin) * min_point_dist / length
             length = GCPnts_AbscissaPoint().Length(curve, kmin, kmax)
             density = length / min_point_dist
             if density < 1:
                 density = 1
             for k in numpy.arange(kmin, kmax, (kmax - kmin) / density):
                 if k == kmax:
                     break
                 frames[counter2].append(
                     Slicing.get_point_on_curve(curve, k))
             frames[counter2].append(Slicing.get_point_on_curve(
                 curve, kmax))
         if counter2 % 2 != 0:
             frames[counter2].reverse()
         layer.extend(frames[counter2])
         counter2 = counter2 + 1
     return layer
Esempio n. 37
0
# discretize the wire and interpolate using a C2
wireAdaptor = BRepAdaptor_CompCurve(wire)
curve = BRepAdaptor_HCompCurve(wireAdaptor)
tol = 1e-7
max_segments = 200
max_degrees = 12
approx = Approx_Curve3d(curve, tol, GeomAbs_C2, max_segments, max_degrees)
if (approx.IsDone() and approx.HasResult()):
    an_approximated_curve = approx.Curve()

# there are two ways to project a point on this curve,
# they both give the same restult

# 1st solution: using GeomAPI_ProjectPointOnCurve
point_to_project = gp_Pnt(1., 2., 3.)
projection = GeomAPI_ProjectPointOnCurve(point_to_project,
                                         an_approximated_curve)
# get the results of the projection
projected_point = projection.NearestPoint()
# the number of possible results
nb_results = projection.NbPoints()
print("NbResults : %i" % nb_results)
print("Distance :", projection.LowerDistance())

# 2nd solution : using ShapeAnalysis_Curve().Project
tolerance = 1e-7
proj = gp_Pnt()
distance, parameter = ShapeAnalysis_Curve().Project(an_approximated_curve,
                                                    point_to_project,
                                                    tolerance, proj)
Esempio n. 38
0
# imports from Display and Extend
from OCC.Display.WebGl.jupyter_renderer import JupyterRenderer

# Creation of the Jupyter Renderer

# In[3]:

my_renderer = JupyterRenderer()

# Generation of the bspline profile using an array of 5 points. The spline is interpolated through these points.

# In[4]:

# the bspline profile
array = TColgp_Array1OfPnt(1, 5)
array.SetValue(1, gp_Pnt(0, 0, 0))
array.SetValue(2, gp_Pnt(1, 2, 0))
array.SetValue(3, gp_Pnt(2, 3, 0))
array.SetValue(4, gp_Pnt(4, 3, 0))
array.SetValue(5, gp_Pnt(5, 5, 0))
bspline = GeomAPI_PointsToBSpline(array).Curve()
profile = BRepBuilderAPI_MakeEdge(bspline).Edge()

# Generation of the linear path.

# In[5]:

# the linear path
starting_point = gp_Pnt(0., 0., 0.)
end_point = gp_Pnt(0., 0., 6.)
vec = gp_Vec(starting_point, end_point)
Esempio n. 39
0
 def __init__(self, p: numpy):
     self.gp = gp_Pnt(p[0], p[1], p[2])
def get_faceted_L_shape(x, y, z):
    pnt_A = gp_Pnt(x + 0, y + 0, z + 0)
    pnt_B = gp_Pnt(x + 20, y + 0, z + 0)
    pnt_C = gp_Pnt(x + 20, y + 10, z + 0)
    pnt_D = gp_Pnt(x + 0, y + 10, z + 0)
    pnt_E = gp_Pnt(x + 0, y + 0, z + 20)
    pnt_F = gp_Pnt(x + 10, y + 0, z + 20)
    pnt_G = gp_Pnt(x + 10, y + 10, z + 20)
    pnt_H = gp_Pnt(x + 0, y + 10, z + 20)
    pnt_I = gp_Pnt(x + 10, y + 0, z + 10)
    pnt_J = gp_Pnt(x + 10, y + 10, z + 10)
    pnt_K = gp_Pnt(x + 20, y + 0, z + 10)
    pnt_L = gp_Pnt(x + 20, y + 10, z + 10)

    face_1 = make_face_from_4_points(pnt_A, pnt_B, pnt_C, pnt_D)
    face_2 = make_face_from_4_points(pnt_B, pnt_C, pnt_L, pnt_K)
    face_3 = make_face_from_4_points(pnt_E, pnt_F, pnt_G, pnt_H)
    face_4 = make_face_from_4_points(pnt_A, pnt_E, pnt_H, pnt_D)
    face_5 = make_face_from_4_points(pnt_G, pnt_F, pnt_I, pnt_J)
    face_6 = make_face_from_4_points(pnt_I, pnt_K, pnt_L, pnt_J)

    polygon_1 = BRepBuilderAPI_MakePolygon()
    polygon_1.Add(pnt_A)
    polygon_1.Add(pnt_B)
    polygon_1.Add(pnt_K)
    polygon_1.Add(pnt_I)
    polygon_1.Add(pnt_F)
    polygon_1.Add(pnt_E)
    polygon_1.Close()

    face_7 = BRepBuilderAPI_MakeFace(polygon_1.Wire()).Face()
    polygon_2 = BRepBuilderAPI_MakePolygon()
    polygon_2.Add(pnt_D)
    polygon_2.Add(pnt_H)
    polygon_2.Add(pnt_G)
    polygon_2.Add(pnt_J)
    polygon_2.Add(pnt_L)
    polygon_2.Add(pnt_C)
    polygon_2.Close()
    face_8 = BRepBuilderAPI_MakeFace(polygon_2.Wire()).Face()

    sew = BRepBuilderAPI_Sewing()
    for face in [
            face_1, face_2, face_3, face_4, face_5, face_6, face_7, face_8
    ]:
        sew.Add(face)
    sew.Perform()

    return sew.SewedShape()
def constrained_filling(event=None):

    # left
    pts1 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0),
                                             gp_Pnt(0, 1, 0.3),
                                             gp_Pnt(0, 2, -0.3),
                                             gp_Pnt(0, 3, 0.15),
                                             gp_Pnt(0, 4, 0)))
    # front
    pts2 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 0, 0.0),
                                             gp_Pnt(1, 0, -0.3),
                                             gp_Pnt(2, 0, 0.15),
                                             gp_Pnt(3, 0, 0),
                                             gp_Pnt(4, 0, 0)))
    # back
    pts3 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(0, 4, 0),
                                             gp_Pnt(1, 4, 0.3),
                                             gp_Pnt(2, 4, -0.15),
                                             gp_Pnt(3, 4, 0),
                                             gp_Pnt(4, 4, 1)))
    # rechts
    pts4 = point_list_to_TColgp_Array1OfPnt((gp_Pnt(4, 0, 0),
                                             gp_Pnt(4, 1, 0),
                                             gp_Pnt(4, 2, 2),
                                             gp_Pnt(4, 3, -0.15),
                                             gp_Pnt(4, 4, 1)))

    spl1, b1 = get_simple_bound(pts1)
    spl2, b2 = get_simple_bound(pts2)
    spl3, b3 = get_simple_bound(pts3)
    spl4, b4 = get_simple_bound(pts4)

    # build the constrained surface
    bConstrainedFilling = GeomFill_ConstrainedFilling(8, 2)
    bConstrainedFilling.Init(b1, b2, b3, b4, False)
    srf1 = bConstrainedFilling.Surface()

    display.EraseAll()
    for i in [spl1, spl2, spl3, spl4]:
        edg = BRepBuilderAPI_MakeEdge(i)
        edg.Build()
        _edg = edg.Shape()
        display.DisplayShape(_edg)

    f = BRepBuilderAPI_MakeFace(srf1, 1e-6)
    f.Build()
    shp = f.Shape()
    return shp
Esempio n. 42
0
def fill_surface():
    n_sided = BRepFill_Filling()

    n_sided.SetResolParam(4, 30, 5, True)
    # Sets the parameters used for resolution.
    # The default values of these parameters have been chosen for a good ratio quality/performance.
    #
    # Degree: it is the order of energy criterion to minimize for computing the deformation of the surface.
    #   The default value is 3.
    #   The recommanded value is i+2
    #   where i is the maximum order of the constraints.
    #
    # NbPtsOnCur: it is the average number of points for discretisation of the edges.
    #
    # NbIter: it is the maximum number of iterations of the process.
    #   For each iteration the number of discretisation points is increased.
    #
    # Anisotropie:

    n_sided.SetConstrParam()
    # Sets the values of Tolerances used to control the constraint.
    # Tol2d:
    # Tol3d:
    #   it is the maximum distance allowed between the support surface and the constraints
    # TolAng: it is the maximum angle allowed between the normal of the surface and the constraints
    # TolCurv: it is the maximum difference of curvature allowed between the surface and the constraint

    p0 = gp_Pnt(-20, -20, 0)
    p1 = gp_Pnt(+20, -20, 10)
    p2 = gp_Pnt(+20, +20, 0)
    p3 = gp_Pnt(-20, +20, 0)
    p4 = gp_Pnt(-10, -10, +5)
    p5 = gp_Pnt(-10, +10, -5)
    p6 = gp_Pnt(+10, -10, -10)
    p7 = gp_Pnt(+10, +10, +10)
    p8 = gp_Pnt(-15, -15, +2)
    p9 = gp_Pnt(-15, +15, -15)
    p10 = gp_Pnt(+15, -15, -2)
    p11 = gp_Pnt(+15, +15, +50)

    n_sided.Add(make_edge(p0, p1), GeomAbs_C0)
    n_sided.Add(make_edge(p1, p2), GeomAbs_C0)
    n_sided.Add(make_edge(p2, p3), GeomAbs_C0)
    n_sided.Add(make_edge(p3, p0), GeomAbs_C0)
    n_sided.Add(p4)
    n_sided.Add(p5)
    n_sided.Add(p6)
    n_sided.Add(p7)
    n_sided.Add(p8)
    n_sided.Add(p9)
    n_sided.Add(p10)
    n_sided.Add(p11)
    n_sided.Build()
    write_step_file(n_sided.Face(), "./tmp/FillSurf.stp")
    return n_sided.Face()
Esempio n. 43
0
import time
import os

from OCC.Core.gp import gp_Pnt, gp_Vec, gp_Dir
from OCC.Core.gp import gp_Ax1, gp_Ax2, gp_Ax3
from OCC.Core.gp import gp_XYZ
from OCC.Core.gp import gp_Lin

from src.base import create_tempnum
from src.model import model, model_base
from src.jsonfile import write_json

obj = model(cfgfile="./cfg/model.json")
print(obj.cfg["name"])

md0 = obj.set_model(name="surf0")
md1 = obj.set_model(name="surf1")
md2 = obj.set_model(name="surf")
md2.pts, md2.rim = obj.make_PolyWire(skin=None)
md3 = model_base(meta={"name": "surf3"})
md3.axs.Translate(gp_Pnt(), gp_Pnt(0, 0, 100))

meta = {}
meta["surf1"] = md1.export_dict()
meta["surf2"] = md2.export_dict()
meta["surf3"] = md3.export_dict()
write_json(create_tempnum("model", obj.tmpdir, ext=".json"), meta)

obj.display.DisplayShape(md1.rim)
obj.show()
    def test_distances(self):
        """Test: distances"""
        array1 = []
        array1.append(gp_Pnt(-5, 1, 2))
        array1.append(gp_Pnt(-5, 2, 2))
        array1.append(gp_Pnt(-5.3, 3, 1))
        array1.append(gp_Pnt(-5, 4, 1))
        array1.append(gp_Pnt(-5, 5, 2))
        SPL1 = GeomAPI_PointsToBSpline(
            point_list_to_TColgp_Array1OfPnt(array1)).Curve()
        array2 = []
        array2.append(gp_Pnt(4, 1, 2))
        array2.append(gp_Pnt(4, 2, 2))
        array2.append(gp_Pnt(3.7, 3, 1))
        array2.append(gp_Pnt(4, 4, 1))
        array2.append(gp_Pnt(4, 5, 2))
        SPL2 = GeomAPI_PointsToBSpline(
            point_list_to_TColgp_Array1OfPnt(array2)).Curve()
        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)
        aSurf1 = aGeomFill1.Surface()

        array3 = TColgp_Array2OfPnt(1, 5, 1, 5)
        array3.SetValue(1, 1, gp_Pnt(-4, -4, 5))
        array3.SetValue(1, 2, gp_Pnt(-4, -2, 5))
        array3.SetValue(1, 3, gp_Pnt(-4, 0, 4))
        array3.SetValue(1, 4, gp_Pnt(-4, 2, 5))
        array3.SetValue(1, 5, gp_Pnt(-4, 4, 5))

        array3.SetValue(2, 1, gp_Pnt(-2, -4, 4))
        array3.SetValue(2, 2, gp_Pnt(-2, -2, 4))
        array3.SetValue(2, 3, gp_Pnt(-2, 0, 4))
        array3.SetValue(2, 4, gp_Pnt(-2, 2, 4))
        array3.SetValue(2, 5, gp_Pnt(-2, 5, 4))

        array3.SetValue(3, 1, gp_Pnt(0, -4, 3.5))
        array3.SetValue(3, 2, gp_Pnt(0, -2, 3.5))
        array3.SetValue(3, 3, gp_Pnt(0, 0, 3.5))
        array3.SetValue(3, 4, gp_Pnt(0, 2, 3.5))
        array3.SetValue(3, 5, gp_Pnt(0, 5, 3.5))

        array3.SetValue(4, 1, gp_Pnt(2, -4, 4))
        array3.SetValue(4, 2, gp_Pnt(2, -2, 4))
        array3.SetValue(4, 3, gp_Pnt(2, 0, 3.5))
        array3.SetValue(4, 4, gp_Pnt(2, 2, 5))
        array3.SetValue(4, 5, gp_Pnt(2, 5, 4))

        array3.SetValue(5, 1, gp_Pnt(4, -4, 5))
        array3.SetValue(5, 2, gp_Pnt(4, -2, 5))
        array3.SetValue(5, 3, gp_Pnt(4, 0, 5))
        array3.SetValue(5, 4, gp_Pnt(4, 2, 6))
        array3.SetValue(5, 5, gp_Pnt(4, 5, 5))

        aSurf2 = GeomAPI_PointsToBSplineSurface(array3).Surface()
        ESS = GeomAPI_ExtremaSurfaceSurface(aSurf1, aSurf2)
        dist = ESS.LowerDistance()
        self.assertGreater(dist, 1.20)
        self.assertLess(dist, 1.25)
        a, b = gp_Pnt(), gp_Pnt()
        ESS.NearestPoints(a, b)

        NbExtrema = ESS.NbExtrema()
        for k in range(1, NbExtrema + 1):
            P3, P4 = gp_Pnt(), gp_Pnt()
            ESS.Points(k, P3, P4)
            aCurve = GC_MakeSegment(P3, P4).Value()
            self.assertFalse(aCurve is None)
Esempio n. 45
0
    print(api.Area())

    loc = set_loc(gp_Ax3(), axs)
    mat = gp_Mat(rxyz[0], 0, 0, 0, rxyz[1], 0, 0, 0, rxyz[2])
    gtrf = gp_GTrsf(mat, gp_XYZ(0, 0, 0))
    ellips = BRepBuilderAPI_GTransform(sphere, gtrf).Shape()
    ellips.Location(loc)
    return ellips


if __name__ == '__main__':
    obj = plotocc(touch=True)
    # obj.show_axs_pln(scale=20)
    # obj.show_ball()

    axs = gp_Ax3(gp_Pnt(0, 0, 0), gp_Dir(1, 1, 1))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    axs = gp_Ax3(gp_Pnt(30, 0, 0), gp_Dir(1, 1, 0))
    elp = gen_ellipsoid(axs, [10, 20, 30])
    obj.display.DisplayShape(elp, transparency=0.7, color="BLUE")
    obj.show_axs_pln(axs, scale=20)

    #elp = gen_ellipsoid_geom(axs, [10, 20, 30])

    top_api = Topo(elp)
    print(top_api.number_of_faces())
    for face in top_api.faces():
        elp_face = face
tubemesh = Mesh.from_obj(compas.get('tubemesh.obj'))
tubemesh.quads_to_triangles()

print(tubemesh.number_of_vertices())
print(tubemesh.number_of_faces())

# ==============================================================================
# To OCC
# ==============================================================================

shell = TopoDS_Shell()
builder = BRep_Builder()
builder.MakeShell(shell)

vertexdict = {vertex: BRepBuilderAPI_MakeVertex(gp_Pnt(* tubemesh.vertex_attributes(vertex, 'xyz'))) for vertex in tubemesh.vertices()}

for face in tubemesh.faces():
    wire = BRepBuilderAPI_MakeWire()
    for u, v in tubemesh.face_halfedges(face):
        edge = BRepBuilderAPI_MakeEdge(vertexdict[u].Vertex(), vertexdict[v].Vertex())
        wire.Add(edge.Edge())
    face = BRepBuilderAPI_MakeFace(wire.Wire()).Face()
    builder.Add(shell, face)

# ==============================================================================
# Explore
# ==============================================================================

polygons = []
Esempio n. 47
0
    def DisplayShape(self, shapes, material=None, texture=None, color=None, transparency=None, update=False):
        """ display one or a set of displayable objects
        """
        SOLO = False  # assume multiple instances by default
        # if a gp_Pnt is passed, first convert to vertex
        if issubclass(shapes.__class__, gp_Pnt):
            vertex = BRepBuilderAPI_MakeVertex(shapes)
            shapes = [vertex.Shape()]
            SOLO = True
        elif isinstance(shapes, gp_Pnt2d):
            vertex = BRepBuilderAPI_MakeVertex(gp_Pnt(shapes.X(), shapes.Y(), 0))
            shapes = [vertex.Shape()]
            SOLO = True
        # if a Geom_Curve is passed
        elif callable(getattr(shapes, "GetHandle", None)):
            handle = shapes.GetHandle()
            if issubclass(handle.__class__, Handle_Geom_Curve):
                edge = BRepBuilderAPI_MakeEdge(handle)
                shapes = [edge.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom2d_Curve):
                edge2d = BRepBuilderAPI_MakeEdge2d(handle)
                shapes = [edge2d.Shape()]
                SOLO = True
            elif issubclass(handle.__class__, Handle_Geom_Surface):
                bounds = True
                toldegen = 1e-6
                face = BRepBuilderAPI_MakeFace()
                face.Init(handle, bounds, toldegen)
                face.Build()
                shapes = [face.Shape()]
                SOLO = True
        elif isinstance(shapes, Handle_Geom_Surface):
            bounds = True
            toldegen = 1e-6
            face = BRepBuilderAPI_MakeFace()
            face.Init(shapes, bounds, toldegen)
            face.Build()
            shapes = [face.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom_Curve):
            edge = BRepBuilderAPI_MakeEdge(shapes)
            shapes = [edge.Shape()]
            SOLO = True
        elif isinstance(shapes, Handle_Geom2d_Curve):
            edge2d = BRepBuilderAPI_MakeEdge2d(shapes)
            shapes = [edge2d.Shape()]
            SOLO = True
        elif issubclass(shapes.__class__, TopoDS_Shape):
            shapes = [shapes]
            SOLO = True

        ais_shapes = []

        for shape in shapes:
            if material or texture:
                if texture:
                    self.View.SetSurfaceDetail(V3d_TEX_ALL)
                    shape_to_display = AIS_TexturedShape(shape)
                    filename, toScaleU, toScaleV, toRepeatU, toRepeatV, originU, originV = texture.GetProperties()
                    shape_to_display.SetTextureFileName(TCollection_AsciiString(filename))
                    shape_to_display.SetTextureMapOn()
                    shape_to_display.SetTextureScale(True, toScaleU, toScaleV)
                    shape_to_display.SetTextureRepeat(True, toRepeatU, toRepeatV)
                    shape_to_display.SetTextureOrigin(True, originU, originV)
                    shape_to_display.SetDisplayMode(3)
                elif material:
                    shape_to_display = AIS_Shape(shape)
                    shape_to_display.SetMaterial(material)
            else:
                # TODO: can we use .Set to attach all TopoDS_Shapes
                # to this AIS_Shape instance?
                shape_to_display = AIS_Shape(shape)

            ais_shapes.append(shape_to_display.GetHandle())

        if not SOLO:
            # computing graphic properties is expensive
            # if an iterable is found, so cluster all TopoDS_Shape under
            # an AIS_MultipleConnectedInteractive
            #shape_to_display = AIS_MultipleConnectedInteractive()
            for ais_shp in ais_shapes:
                # TODO : following line crashes with oce-0.18
                # why ? fix ?
                #shape_to_display.Connect(i)
                self.Context.Display(ais_shp, False)
            shape_to_display = ais_shapes
            return shape_to_display
        # set the graphic properties
        if material is None:
            #The default material is too shiny to show the object
            #color well, so I set it to something less reflective
            shape_to_display.SetMaterial(Graphic3d_NOM_NEON_GNC)
        if color:
            if isinstance(color, str):
                color = get_color_from_name(color)
            for shp in ais_shapes:
                self.Context.SetColor(shp, color, False)
        if transparency:
            shape_to_display.SetTransparency(transparency)
        if update:
            # only update when explicitely told to do so
            self.Context.Display(shape_to_display.GetHandle(), False)
            # especially this call takes up a lot of time...
            self.FitAll()
            self.Repaint()
        else:
            self.Context.Display(shape_to_display.GetHandle(), False)

        if SOLO:
            return ais_shapes[0]
        else:
            return shape_to_display
Esempio n. 48
0
 def togp(n_):
     return gp_Pnt(float(n_[0]), float(n_[1]), float(n_[2]))
    def test_distances(self):
        '''Test: distances'''
        array1 = []
        array1.append(gp_Pnt(-5, 1, 2))
        array1.append(gp_Pnt(-5, 2, 2))
        array1.append(gp_Pnt(-5.3, 3, 1))
        array1.append(gp_Pnt(-5, 4, 1))
        array1.append(gp_Pnt(-5, 5, 2))
        SPL1 = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array1)).Curve()
        array2 = []
        array2.append(gp_Pnt(4, 1, 2))
        array2.append(gp_Pnt(4, 2, 2))
        array2.append(gp_Pnt(3.7, 3, 1))
        array2.append(gp_Pnt(4, 4, 1))
        array2.append(gp_Pnt(4, 5, 2))
        SPL2 = GeomAPI_PointsToBSpline(point_list_to_TColgp_Array1OfPnt(array2)).Curve()
        aGeomFill1 = GeomFill_BSplineCurves(SPL1, SPL2, GeomFill_StretchStyle)
        aSurf1 = aGeomFill1.Surface()

        array3 = TColgp_Array2OfPnt(1, 5, 1, 5)
        array3.SetValue(1, 1, gp_Pnt(-4, -4, 5))
        array3.SetValue(1, 2, gp_Pnt(-4, -2, 5))
        array3.SetValue(1, 3, gp_Pnt(-4, 0, 4))
        array3.SetValue(1, 4, gp_Pnt(-4, 2, 5))
        array3.SetValue(1, 5, gp_Pnt(-4, 4, 5))

        array3.SetValue(2, 1, gp_Pnt(-2, -4, 4))
        array3.SetValue(2, 2, gp_Pnt(-2, -2, 4))
        array3.SetValue(2, 3, gp_Pnt(-2, 0, 4))
        array3.SetValue(2, 4, gp_Pnt(-2, 2, 4))
        array3.SetValue(2, 5, gp_Pnt(-2, 5, 4))

        array3.SetValue(3, 1, gp_Pnt(0, -4, 3.5))
        array3.SetValue(3, 2, gp_Pnt(0, -2, 3.5))
        array3.SetValue(3, 3, gp_Pnt(0, 0, 3.5))
        array3.SetValue(3, 4, gp_Pnt(0, 2, 3.5))
        array3.SetValue(3, 5, gp_Pnt(0, 5, 3.5))

        array3.SetValue(4, 1, gp_Pnt(2, -4, 4))
        array3.SetValue(4, 2, gp_Pnt(2, -2, 4))
        array3.SetValue(4, 3, gp_Pnt(2, 0, 3.5))
        array3.SetValue(4, 4, gp_Pnt(2, 2, 5))
        array3.SetValue(4, 5, gp_Pnt(2, 5, 4))

        array3.SetValue(5, 1, gp_Pnt(4, -4, 5))
        array3.SetValue(5, 2, gp_Pnt(4, -2, 5))
        array3.SetValue(5, 3, gp_Pnt(4, 0, 5))
        array3.SetValue(5, 4, gp_Pnt(4, 2, 6))
        array3.SetValue(5, 5, gp_Pnt(4, 5, 5))

        aSurf2 = GeomAPI_PointsToBSplineSurface(array3).Surface()
        ESS = GeomAPI_ExtremaSurfaceSurface(aSurf1, aSurf2)
        dist = ESS.LowerDistance()
        self.assertGreater(dist, 1.25)
        self.assertLess(dist, 1.26)
        a, b = gp_Pnt(), gp_Pnt()
        ESS.NearestPoints(a, b)

        NbExtrema = ESS.NbExtrema()
        for k in range(1, NbExtrema + 1):
            P3, P4 = gp_Pnt(), gp_Pnt()
            ESS.Points(k, P3, P4)
            aCurve = GC_MakeSegment(P3, P4).Value()
            self.assertFalse(aCurve is None)
Esempio n. 50
0
def get_bounding_box_center(bbox):
    bbmin = [0.] * 3
    bbmax = [0.] * 3
    bbmin[0], bbmin[1], bbmin[2], bbmax[0], bbmax[1], bbmax[2] = bbox.Get()
    return gp.gp_Pnt(*map(lambda xy: (xy[0] + xy[1]) / 2., zip(bbmin, bbmax)))
def brep_feat_rib(event=None):
    mkw = BRepBuilderAPI_MakeWire()

    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 0.), gp_Pnt(200., 0.,
                                                           0.)).Edge())
    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 0.), gp_Pnt(200., 0.,
                                                             50.)).Edge())
    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(200., 0., 50.), gp_Pnt(50., 0.,
                                                              50.)).Edge())
    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 50.), gp_Pnt(50., 0.,
                                                             200.)).Edge())
    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(50., 0., 200.), gp_Pnt(0., 0.,
                                                              200.)).Edge())
    mkw.Add(
        BRepBuilderAPI_MakeEdge(gp_Pnt(0., 0., 200.), gp_Pnt(0., 0.,
                                                             0.)).Edge())

    S = BRepPrimAPI_MakePrism(
        BRepBuilderAPI_MakeFace(mkw.Wire()).Face(),
        gp_Vec(gp_Pnt(0., 0., 0.), gp_Pnt(0., 100., 0.)))
    display.EraseAll()
    #    display.DisplayShape(S.Shape())

    W = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(gp_Pnt(50., 45., 100.), gp_Pnt(100., 45.,
                                                               50.)).Edge())

    aplane = Geom_Plane(0., 1., 0., -45.)

    aform = BRepFeat_MakeLinearForm(S.Shape(), W.Wire(), aplane.GetHandle(),
                                    gp_Vec(0., 10., 0.), gp_Vec(0., 0., 0.), 1,
                                    True)
    aform.Perform()
    display.DisplayShape(aform.Shape())
    display.FitAll()
    def test_bezier_surfaces(self):
        """Test: Bezier surfaces"""
        array1 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array2 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array3 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array4 = TColgp_Array2OfPnt(1, 3, 1, 3)

        array1.SetValue(1, 1, gp_Pnt(1, 1, 1))
        array1.SetValue(1, 2, gp_Pnt(2, 1, 2))
        array1.SetValue(1, 3, gp_Pnt(3, 1, 1))
        array1.SetValue(2, 1, gp_Pnt(1, 2, 1))
        array1.SetValue(2, 2, gp_Pnt(2, 2, 2))
        array1.SetValue(2, 3, gp_Pnt(3, 2, 0))
        array1.SetValue(3, 1, gp_Pnt(1, 3, 2))
        array1.SetValue(3, 2, gp_Pnt(2, 3, 1))
        array1.SetValue(3, 3, gp_Pnt(3, 3, 0))

        array2.SetValue(1, 1, gp_Pnt(3, 1, 1))
        array2.SetValue(1, 2, gp_Pnt(4, 1, 1))
        array2.SetValue(1, 3, gp_Pnt(5, 1, 2))
        array2.SetValue(2, 1, gp_Pnt(3, 2, 0))
        array2.SetValue(2, 2, gp_Pnt(4, 2, 1))
        array2.SetValue(2, 3, gp_Pnt(5, 2, 2))
        array2.SetValue(3, 1, gp_Pnt(3, 3, 0))
        array2.SetValue(3, 2, gp_Pnt(4, 3, 0))
        array2.SetValue(3, 3, gp_Pnt(5, 3, 1))

        array3.SetValue(1, 1, gp_Pnt(1, 3, 2))
        array3.SetValue(1, 2, gp_Pnt(2, 3, 1))
        array3.SetValue(1, 3, gp_Pnt(3, 3, 0))
        array3.SetValue(2, 1, gp_Pnt(1, 4, 1))
        array3.SetValue(2, 2, gp_Pnt(2, 4, 0))
        array3.SetValue(2, 3, gp_Pnt(3, 4, 1))
        array3.SetValue(3, 1, gp_Pnt(1, 5, 1))
        array3.SetValue(3, 2, gp_Pnt(2, 5, 1))
        array3.SetValue(3, 3, gp_Pnt(3, 5, 2))

        array4.SetValue(1, 1, gp_Pnt(3, 3, 0))
        array4.SetValue(1, 2, gp_Pnt(4, 3, 0))
        array4.SetValue(1, 3, gp_Pnt(5, 3, 1))
        array4.SetValue(2, 1, gp_Pnt(3, 4, 1))
        array4.SetValue(2, 2, gp_Pnt(4, 4, 1))
        array4.SetValue(2, 3, gp_Pnt(5, 4, 1))
        array4.SetValue(3, 1, gp_Pnt(3, 5, 2))
        array4.SetValue(3, 2, gp_Pnt(4, 5, 2))
        array4.SetValue(3, 3, gp_Pnt(5, 5, 1))

        BZ1, BZ2, BZ3, BZ4 = map(Geom_BezierSurface,
                                 [array1, array2, array3, array4])
        bezierarray = TColGeom_Array2OfBezierSurface(1, 2, 1, 2)
        bezierarray.SetValue(1, 1, BZ1)
        bezierarray.SetValue(1, 2, BZ2)
        bezierarray.SetValue(2, 1, BZ3)
        bezierarray.SetValue(2, 2, BZ4)

        BB = GeomConvert_CompBezierSurfacesToBSplineSurface(bezierarray)
        self.assertTrue(BB.IsDone())
        poles = BB.Poles().Array2()
        uknots = BB.UKnots().Array1()
        vknots = BB.VKnots().Array1()
        umult = BB.UMultiplicities().Array1()
        vmult = BB.VMultiplicities().Array1()
        udeg = BB.UDegree()
        vdeg = BB.VDegree()

        BSPLSURF = Geom_BSplineSurface(poles, uknots, vknots, umult, vmult,
                                       udeg, vdeg, False, False)
        BSPLSURF.Translate(gp_Vec(0, 0, 2))
Esempio n. 53
0
def mirrorO(x=0, y=0, z=0):
    trsf = gp_Trsf()
    trsf.SetMirror(gp_Pnt(x, y, z))
    return Transformation(trsf)
Esempio n. 54
0
        label = self.shape_tool.AddShape(shape)
        self.writer.Transfer(self.doc, STEPControl_AsIs)

    def Write(self, filename=None):
        if not filename:
            filename = self.name
        path, ext = os.path.splitext(filename)
        if not ext:
            ext = ".stp"
        status = self.writer.Write(path + ext)
        assert (status == IFSelect_RetDone)


if __name__ == "__main__":
    display, start_display, add_menu, add_function_to_menu = init_display()
    display.DisplayShape(gp_Pnt())
    root = ExportCAFMethod(name="root")
    root.Add(make_vertex(gp_Pnt()), name="pnt")
    root.Add(make_plane(center=gp_Pnt(0, 0, 0)), name="pln0")
    root.Add(make_plane(center=gp_Pnt(0, 0, 100)), name="pln1")
    root.Add(make_circle(gp_Pnt(0, 0, 0), 100), name="circle")
    root.Write()

    display.FitAll()

    box = BRepPrimAPI_MakeBox(10, 10, 10).Solid()
    writer = STEPControl_Writer()
    fp = writer.WS().TransferWriter().FinderProcess()

    print(fp)
Esempio n. 55
0
def mirror_axis(ax, ay, az):
    trsf = gp_Trsf()
    trsf.SetMirror(gp_Ax1(gp_Pnt(0, 0, 0), gp_Dir(gp_Vec(ax, ay, az))))
    return Transformation(trsf)
    def test_bezier_surfaces(self):
        '''Test: Bezier surfaces'''
        array1 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array2 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array3 = TColgp_Array2OfPnt(1, 3, 1, 3)
        array4 = TColgp_Array2OfPnt(1, 3, 1, 3)

        array1.SetValue(1, 1, gp_Pnt(1, 1, 1))
        array1.SetValue(1, 2, gp_Pnt(2, 1, 2))
        array1.SetValue(1, 3, gp_Pnt(3, 1, 1))
        array1.SetValue(2, 1, gp_Pnt(1, 2, 1))
        array1.SetValue(2, 2, gp_Pnt(2, 2, 2))
        array1.SetValue(2, 3, gp_Pnt(3, 2, 0))
        array1.SetValue(3, 1, gp_Pnt(1, 3, 2))
        array1.SetValue(3, 2, gp_Pnt(2, 3, 1))
        array1.SetValue(3, 3, gp_Pnt(3, 3, 0))

        array2.SetValue(1, 1, gp_Pnt(3, 1, 1))
        array2.SetValue(1, 2, gp_Pnt(4, 1, 1))
        array2.SetValue(1, 3, gp_Pnt(5, 1, 2))
        array2.SetValue(2, 1, gp_Pnt(3, 2, 0))
        array2.SetValue(2, 2, gp_Pnt(4, 2, 1))
        array2.SetValue(2, 3, gp_Pnt(5, 2, 2))
        array2.SetValue(3, 1, gp_Pnt(3, 3, 0))
        array2.SetValue(3, 2, gp_Pnt(4, 3, 0))
        array2.SetValue(3, 3, gp_Pnt(5, 3, 1))

        array3.SetValue(1, 1, gp_Pnt(1, 3, 2))
        array3.SetValue(1, 2, gp_Pnt(2, 3, 1))
        array3.SetValue(1, 3, gp_Pnt(3, 3, 0))
        array3.SetValue(2, 1, gp_Pnt(1, 4, 1))
        array3.SetValue(2, 2, gp_Pnt(2, 4, 0))
        array3.SetValue(2, 3, gp_Pnt(3, 4, 1))
        array3.SetValue(3, 1, gp_Pnt(1, 5, 1))
        array3.SetValue(3, 2, gp_Pnt(2, 5, 1))
        array3.SetValue(3, 3, gp_Pnt(3, 5, 2))

        array4.SetValue(1, 1, gp_Pnt(3, 3, 0))
        array4.SetValue(1, 2, gp_Pnt(4, 3, 0))
        array4.SetValue(1, 3, gp_Pnt(5, 3, 1))
        array4.SetValue(2, 1, gp_Pnt(3, 4, 1))
        array4.SetValue(2, 2, gp_Pnt(4, 4, 1))
        array4.SetValue(2, 3, gp_Pnt(5, 4, 1))
        array4.SetValue(3, 1, gp_Pnt(3, 5, 2))
        array4.SetValue(3, 2, gp_Pnt(4, 5, 2))
        array4.SetValue(3, 3, gp_Pnt(5, 5, 1))

        BZ1, BZ2, BZ3, BZ4 = map(Geom_BezierSurface, [array1, array2,
                                                      array3, array4])

        bezierarray = TColGeom_Array2OfBezierSurface(1, 2, 1, 2)
        bezierarray.SetValue(1, 1, BZ1)
        bezierarray.SetValue(1, 2, BZ2)
        bezierarray.SetValue(2, 1, BZ3)
        bezierarray.SetValue(2, 2, BZ4)

        BB = GeomConvert_CompBezierSurfacesToBSplineSurface(bezierarray)
        self.assertTrue(BB.IsDone())
        poles = BB.Poles().Array2()
        uknots = BB.UKnots().Array1()
        vknots = BB.VKnots().Array1()
        umult = BB.UMultiplicities().Array1()
        vmult = BB.VMultiplicities().Array1()
        udeg = BB.UDegree()
        vdeg = BB.VDegree()

        BSPLSURF = Geom_BSplineSurface(poles, uknots, vknots, umult, vmult, udeg, vdeg, False, False)
        BSPLSURF.Translate(gp_Vec(0, 0, 2))