コード例 #1
0
def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)),
                       40.)
    wire_1 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    # the use of the map function fails at producing the ThruSection
    # on py3k. Why ?
    # map(generatorA.AddWire, [wire_1, wire_2, wire_3, wire_4])
    # we have to use a loop
    for wir in [wire_1, wire_2, wire_3, wire_4]:
        generatorA.AddWire(wir)
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    #smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_1b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_3b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_4b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    # same here, the following line fails
    # map(generatorB.AddWire, [wire_1b, wire_2b, wire_3b, wire_4b])
    for wir in [wire_1b, wire_2b, wire_3b, wire_4b]:
        generatorB.AddWire(wir)
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
コード例 #2
0
def through_sections():
    #ruled
    circle_1 = gp_Circ(gp_Ax2(gp_Pnt(-100., 0., -100.), gp_Dir(0., 0., 1.)),
                       40.)
    wire_1 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1).Edge()).Wire()
    circle_2 = gp_Circ(gp_Ax2(gp_Pnt(-10., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2).Edge()).Wire()
    circle_3 = gp_Circ(gp_Ax2(gp_Pnt(-75., 0., 100.), gp_Dir(0., 0., 1.)), 40.)
    wire_3 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3).Edge()).Wire()
    circle_4 = gp_Circ(gp_Ax2(gp_Pnt(0., 0., 200.), gp_Dir(0., 0., 1.)), 40.)
    wire_4 = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4).Edge()).Wire()

    generatorA = BRepOffsetAPI_ThruSections(False, True)
    [generatorA.AddWire(w) for w in [wire_1, wire_2, wire_3, wire_4]]
    generatorA.Build()
    display.DisplayShape(generatorA.Shape())

    # smooth
    circle_1b = gp_Circ(gp_Ax2(gp_Pnt(100., 0., -100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_1b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_1b).Edge()).Wire()
    circle_2b = gp_Circ(gp_Ax2(gp_Pnt(210., 0., -0.), gp_Dir(0., 0., 1.)), 40.)
    wire_2b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_2b).Edge()).Wire()
    circle_3b = gp_Circ(gp_Ax2(gp_Pnt(275., 0., 100.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_3b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_3b).Edge()).Wire()
    circle_4b = gp_Circ(gp_Ax2(gp_Pnt(200., 0., 200.), gp_Dir(0., 0., 1.)),
                        40.)
    wire_4b = BRepBuilderAPI_MakeWire(
        BRepBuilderAPI_MakeEdge(circle_4b).Edge()).Wire()
    generatorB = BRepOffsetAPI_ThruSections(True, False)
    [generatorB.AddWire(w) for w in [wire_1b, wire_2b, wire_3b, wire_4b]]
    generatorB.Build()
    display.DisplayShape(generatorB.Shape(), update=True)
コード例 #3
0
ファイル: shapes.py プロジェクト: fragmuffin/cadquery
    def makeLoft(cls, listOfWire, ruled=False):
        """
            makes a loft from a list of wires
            The wires will be converted into faces when possible-- it is presumed that nobody ever actually
            wants to make an infinitely thin shell for a real FreeCADPart.
        """
        # the True flag requests building a solid instead of a shell.
        loft_builder = BRepOffsetAPI_ThruSections(True, ruled)

        for w in listOfWire:
            loft_builder.AddWire(w.wrapped)

        loft_builder.Build()

        return cls(loft_builder.Shape())
コード例 #4
0
ファイル: blade.py プロジェクト: ztotal/BladeX
    def _generate_tip(self, maxDeg):
        """
        Private method to generate the surface that closing the blade tip.

        :param int maxDeg: Define the maximal U degree of generated surface
        """
        self._import_occ_libs()

        generator = BRepOffsetAPI_ThruSections(False, False, 1e-10)
        generator.SetMaxDegree(maxDeg)
        # npoints_up == npoints_down
        npoints = len(self.blade_coordinates_down[-1][0])
        vertices_1 = TColgp_HArray1OfPnt(1, npoints)
        vertices_2 = TColgp_HArray1OfPnt(1, npoints)
        for j in range(npoints):
            vertices_1.SetValue(
                j + 1,
                gp_Pnt(1000 * self.blade_coordinates_down[-1][0][j],
                       1000 * self.blade_coordinates_down[-1][1][j],
                       1000 * self.blade_coordinates_down[-1][2][j]))

            vertices_2.SetValue(
                j + 1,
                gp_Pnt(1000 * self.blade_coordinates_up[-1][0][j],
                       1000 * self.blade_coordinates_up[-1][1][j],
                       1000 * self.blade_coordinates_up[-1][2][j]))

        # Initializes an algorithm for constructing a constrained
        # BSpline curve passing through the points of the blade last
        # section, with tolerance = 1e-9
        bspline_1 = GeomAPI_Interpolate(vertices_1.GetHandle(), False, 1e-9)
        bspline_1.Perform()

        bspline_2 = GeomAPI_Interpolate(vertices_2.GetHandle(), False, 1e-9)
        bspline_2.Perform()

        edge_1 = BRepBuilderAPI_MakeEdge(bspline_1.Curve()).Edge()
        edge_2 = BRepBuilderAPI_MakeEdge(bspline_2.Curve()).Edge()

        # Add BSpline wire to the generator constructor
        generator.AddWire(BRepBuilderAPI_MakeWire(edge_1).Wire())
        generator.AddWire(BRepBuilderAPI_MakeWire(edge_2).Wire())
        # Returns the shape built by the shape construction algorithm
        generator.Build()
        # Returns the Face generated by each edge of the first section
        self.generated_tip = generator.GeneratedFace(edge_1)
コード例 #5
0
ファイル: Construct.py プロジェクト: psavine42/OCCUtilsExt
def make_loft(elements,
              ruled=False,
              tolerance=TOLERANCE,
              continuity=GeomAbs_C2,
              check_compatibility=True):
    sections = BRepOffsetAPI_ThruSections(False, ruled, tolerance)
    for i in elements:
        if isinstance(i, TopoDS_Wire):
            sections.AddWire(i)
        elif isinstance(i, TopoDS_Vertex):
            sections.AddVertex(i)
        else:
            raise TypeError(
                'elements is a list of TopoDS_Wire or TopoDS_Vertex, found a %s fool'
                % i.__class__)

    sections.CheckCompatibility(check_compatibility)
    sections.SetContinuity(continuity)
    sections.Build()
    with assert_isdone(sections, 'failed lofting'):
        te = ShapeToTopology()
        loft = te(sections.Shape())
        return loft
コード例 #6
0
ファイル: blade.py プロジェクト: ztotal/BladeX
    def _generate_lower_face(self, maxDeg):
        """
        Private method to generate the blade lower face.

        :param int maxDeg: Define the maximal U degree of generated surface
        """
        self._import_occ_libs()
        # Initializes ThruSections algorithm for building a shell passing
        # through a set of sections (wires). The generated faces between
        # the edges of every two consecutive wires are smoothed out with
        # a precision criterion = 1e-10
        generator = BRepOffsetAPI_ThruSections(False, False, 1e-10)
        generator.SetMaxDegree(maxDeg)
        # Define upper edges (wires) for the face generation
        for i in range(self.n_sections):
            npoints = len(self.blade_coordinates_down[i][0])
            vertices = TColgp_HArray1OfPnt(1, npoints)
            for j in range(npoints):
                vertices.SetValue(
                    j + 1,
                    gp_Pnt(1000 * self.blade_coordinates_down[i][0][j],
                           1000 * self.blade_coordinates_down[i][1][j],
                           1000 * self.blade_coordinates_down[i][2][j]))
            # Initializes an algorithm for constructing a constrained
            # BSpline curve passing through the points of the blade i-th
            # section, with tolerance = 1e-9
            bspline = GeomAPI_Interpolate(vertices.GetHandle(), False, 1e-9)
            bspline.Perform()
            edge = BRepBuilderAPI_MakeEdge(bspline.Curve()).Edge()
            if i == 0:
                bound_root_edge = edge
            # Add BSpline wire to the generator constructor
            generator.AddWire(BRepBuilderAPI_MakeWire(edge).Wire())
        # Returns the shape built by the shape construction algorithm
        generator.Build()
        # Returns the Face generated by each edge of the first section
        self.generated_lower_face = generator.GeneratedFace(bound_root_edge)
コード例 #7
0
def AddSurfaceLoft(objs, continuity=GeomAbs_C2, check_compatibility=True,
                   solid=True, first_vertex=None, last_vertex=None,
                   max_degree=8, close_sections=True):
    """Create a lift surface through curve objects
    Parameters
    ----------
    objs : list of python classes
        Each obj is expected to have an obj.Curve attribute :
        see airconics.primitives.airfoil class

    continuity : OCC.GeomAbs.GeomAbs_XX type (default C2)
        The order of continuity (C^0, C^1, C^2, G^0, ....)

    check_compatibility : bool (default=True)
        Adds a surface compatibility check to the builder
    solid : bool (default=True)
        Creates a solid object from the loft if True

    first_vertex : TopoDS_Vertex (optional, default=None)
        The starting vertex of the surface to add to the 'ThruSections'
        algorithm
    last_vertex : TopoDS_Vertex (optional, default=None)
        The end vertex of the surface to add to the 'ThruSections'
        algorithm
    max_degree : int (default=8)
        The order of the fitted NURBS surface
    close_sections : bool (default=True):
        Connects the start and end point of the loft rib curves if true. This
        has the same effect as adding an airfoil trailing edge.
    Returns
    -------
    shape : TopoDS_Shape
        The generated loft surface

    Notes
    -----
    Uses OCC.BRepOffsetAPI.BRepOffsetAPI_ThruSections. This function is
    ORDER DEPENDANT, i.e. add elements in the order through which they should
    be lofted
    """
    assert (len(objs) >= 2), 'Loft Failed: Less than two input curves'
    # Note: This is to give a smooth loft.
    ruled = False
    pres3d = 1e-6
    args = [solid, ruled, pres3d]  # args (in order) for ThruSections
    generator = BRepOffsetAPI_ThruSections(*args)
    generator.SetMaxDegree(max_degree)
    #    from OCC.GeomAbs import GeomAbs_G1
    generator.SetParType(Approx_ChordLength)
    if first_vertex:
        generator.AddVertex(first_vertex)
    for obj in objs:
        try:
            # Check if this is an airconics object with a GeomBspline handle
            # as its 'Curve' attribute
            obj = obj.Curve
        #            edge = [make_edge(obj)]
        except:
            # Assume the object is already a geombspline handle
            pass
        #            try:
        #                # If working with an airconics object, the OCC curve is stored
        #                # in obj.Curve:
        edges = [make_edge(obj)]

        if close_sections:
            crv = obj.GetObject()
            if crv.IsClosed() is False:
                # Add Finite TE edge
                TE = make_edge(crv.Value(1), crv.Value(0))
                edges.append(TE)

        generator.AddWire(BRepBuilderAPI_MakeWire(*edges).Wire())
    #        else:
    #            generator
    if last_vertex:
        generator.AddVertex(last_vertex)

    generator.CheckCompatibility(check_compatibility)
    generator.SetContinuity(continuity)
    generator.Build()
    with assert_isdone(generator, 'failed lofting'):
        return generator.Shape()
コード例 #8
0
ファイル: GaussianBeam.py プロジェクト: tnakaicode/mypycode
        pnt = gp_Pnt (0, 0, z)
        axs = gp_Ax3 (pnt, gp_Dir(0, 0, 1))
        ax2 = axs.Ax2()
        px  = np.linspace(-1, 1, 100) * 100 
        py  = np.linspace(-1, 1, 100) * 100
        pxy = np.meshgrid (px, py)
        pz  = -1*(pxy[0]**2/(2*r_z) + pxy[1]**2/(2*r_z))
        pln = surf_spl(*pxy, pz, axs)
        wxy = Geom_Ellipse (ax2, w_z, w_z).Elips()
        wxy = BRepBuilderAPI_MakeWire(BRepBuilderAPI_MakeEdge (wxy).Edge()).Wire() 
        print (wxy, pln)
        api.AddWire(wxy)
        display.DisplayShape (pnt)
        display.DisplayShape (pln)
        display.DisplayShape (wxy)
    api.Build()
    surf_wxy = api.Shape()
    display.DisplayShape(surf_wxy)

    pnt = gp_Pnt (0, 0, 500)    
    axs = gp_Ax3 (pnt, gp_Dir(0, 0, 1))
    axs.Rotate(gp_Ax1(axs.Location(), axs.XDirection()), np.deg2rad(5))
    axs.Rotate(gp_Ax1(axs.Location(), axs.YDirection()), np.deg2rad(30))
    ax2 = axs.Ax2()
    px = np.linspace(-1, 1, 100) * 100 
    py = np.linspace(-1, 1, 100) * 100
    mesh = np.meshgrid (px, py)
    surf = mesh[0]**2/1000 + mesh[1]**2/1000
    #pln = make_plane (axs.Location(), dir_to_vec(axs.Direction()))
    pln = surf_spl(*mesh, surf, axs)
    display.DisplayShape (pln)