Example #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)
Example #2
0
def extrusion_to_ruled_surfaces(extrusion, cap=True):
    from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections
    from youbastard.geometry.Extrusion import Extrusion
    from youbastard.geo_functions import assembly_polylines3d
    #from OCC.Display.SimpleGui import init_display
    #display, start_display, add_menu, add_function_to_menu = init_display()
    dico = {}
    for k in extrusion.keys():
        array_of_polylines = extrusion[k]
        generator = BRepOffsetAPI_ThruSections(False, True)
        for pol in array_of_polylines:
            wire = wire_from_polyline(pol)
            generator.AddWire(wire.Wire())
            #dico[k].append(wire.Shape())
        generator.Build()
        dico[k] = generator
    if cap:
        first_cap_polylines = []
        last_cap_polylines = []
        for k in extrusion.keys():
            first_cap_polylines.append(extrusion[k][0])
            last_cap_polylines.append(extrusion[k][-1])
        ordered_first = assembly_polylines3d(first_cap_polylines)
        ordered_last = assembly_polylines3d(last_cap_polylines)
        print ordered_first
        dico['first_tip'] = face_polyline3d(ordered_first)
        dico['last_tip'] = face_polyline3d(ordered_last)
    return dico
Example #3
0
 def make_Thru(self, num=50):
     api = BRepOffsetAPI_ThruSections()
     print(self.poly.Location().Transformation())
     for idx, phi in enumerate(np.linspace(0, 2 * np.pi, num)):
         ax = self.poly_axs.Rotated(self.axs.Axis(), phi)
         poly_i = self.poly.Located(set_loc(gp_Ax3(), ax))
         # print(poly_i.Location().Transformation())
         api.AddWire(poly_i)
         self.display.DisplayShape(poly_i)
     api.Build()
     return api.Shape()
Example #4
0
    def gen_through(self):
        obj = BRepOffsetAPI_ThruSections()

        ax2_1 = gp_Ax2(gp_Pnt(0, 0, 0), gp_Dir(0, 0, 1))
        crl_1 = gp_Circ(ax2_1, 100)
        obj.AddWire(crl_1)

        ax2_2 = gp_Ax2(gp_Pnt(0, 0, 100), gp_Dir(0, 0, 1))
        crl_2 = gp_Circ(ax2_2, 200)
        obj.AddWire(crl_2)

        obj.Build()
        self.display.DisplayShape(obj.Shape())
Example #5
0
File: blade.py Project: o4fr/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, False, 1e-9)
        bspline_1.Perform()

        bspline_2 = GeomAPI_Interpolate(vertices_2, 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)
Example #6
0
def make_loft(elements, ruled=False, tolerance=TOLERANCE, continuity=GeomAbs_C2, check_compatibility=True):
    from OCC.Core.BRepOffsetAPI import BRepOffsetAPI_ThruSections
    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
Example #7
0
def getShapeSkin(pntStart, wires, pntEnd):

    # Initialize and build
    skiner = BRepOffsetAPI_ThruSections()
    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()
Example #8
0
    def loft(self, solid=True, ruled=True, precision=0.000001):
        wires = collect_wires(self)

        self.children = []

        generator = BRepOffsetAPI_ThruSections(solid, ruled, precision)

        for w in wires:
            debug("wire: %s" % (str(w), ))
            generator.AddWire(w)
        generator.Build()

        shape = generator.Shape()
        scls = SCLShape(shape)
        sclp = SCLPart3(self)
        sclp.set_shape(scls)
        name = get_inc_name("loft")
        sclp.set_name(name)
        debug("Creating loft %s" % (name, ))
        self.add_child_context(sclp)
Example #9
0
File: blade.py Project: o4fr/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, 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)
Example #10
0
    def getDaoSkinningSurface(self, offset):

        limitPoints = self.getCached('getDaoOffsetPoints', offset)
        beginPoint = limitPoints['Begin']
        endPoint = limitPoints['End']

        skinner = BRepOffsetAPI_ThruSections(True)
        skinner.SetSmoothing(True)

        beginVertex = BRepBuilderAPI_MakeVertex(beginPoint).Vertex()
        skinner.AddVertex(beginVertex)

        ks = self.aSkinningSlicesKs
        for i in range(len(ks)):
            sliceWire = self.getCached('getDaoSliceWire', offset, ks[i])
            skinner.AddWire(sliceWire)

        endVertex = BRepBuilderAPI_MakeVertex(endPoint).Vertex()
        skinner.AddVertex(endVertex)

        skinner.Build()
        surface = skinner.Shape()

        return surface
Example #11
0
        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)
Example #12
0
 def through_section(sec_a, sec_b, solid_):
     generator_sec = BRepOffsetAPI_ThruSections(solid_, False)
     generator_sec.AddWire(sec_a)
     generator_sec.AddWire(sec_b)
     generator_sec.Build()
     return generator_sec.Shape()
Example #13
0
class LoftShape(object):
    """
    Loft a shape using a sequence of sections.

    :param sections: The sections of the loft. These
        are usually wires but the first and last section can be vertices.
        Edges are converted to wires before adding to the loft tool.
    :type sections: collections.Sequence(afem.topology.entities.Vertex or
        afem.topology.entities.Edge or afem.topology.entities.Wire)
    :param bool is_solid: If *True* the tool will build a solid, otherwise
        it will build a shell.
    :param bool make_ruled: If *True* the faces between sections will be ruled
        surfaces, otherwise they are smoothed out by approximation.
    :param float pres3d: Defines the precision for the approximation algorithm.
    :param bool check_compatibility: Option to check the orientation of the
        sections to avoid twisted results and update to have the same number
        of edges.
    :param bool use_smoothing: Option to use approximation algorithm.
    :param OCC.Core.Approx.Approx_ParametrizationType par_type: Parametrization
        type.

    :param OCC.Core.GeomAbs.GeomAbs_Shape continuity: The desired continuity.
    :param int max_degree: The maximum degree for the approximation
        algorithm.

    :raise TypeError: If any of the sections cannot be added to the tool
        because they are of the wrong type.
    """
    def __init__(self,
                 sections,
                 is_solid=False,
                 make_ruled=False,
                 pres3d=1.0e-6,
                 check_compatibility=None,
                 use_smoothing=None,
                 par_type=None,
                 continuity=None,
                 max_degree=None):
        self._tool = BRepOffsetAPI_ThruSections(is_solid, make_ruled, pres3d)

        if check_compatibility is not None:
            self._tool.CheckCompatibility(check_compatibility)

        if use_smoothing is not None:
            self._tool.SetSmoothing(use_smoothing)

        if par_type is not None:
            self._tool.SetParType(par_type)

        if continuity is not None:
            self._tool.SetContinuity(continuity)

        if max_degree is not None:
            self._tool.SetMaxDegree(max_degree)

        for section in sections:
            if section.is_vertex:
                self._tool.AddVertex(section.object)
            elif section.is_edge:
                wire = Wire.by_edge(section)
                self._tool.AddWire(wire.object)
            elif section.is_wire:
                self._tool.AddWire(section.object)
            else:
                raise TypeError('Invalid shape type in loft.')

        self._tool.Build()

    @property
    def is_done(self):
        """
        :return: *True* if done, *False* if not.
        :rtype: bool
        """
        return self._tool.IsDone()

    @property
    def shape(self):
        """
        :return: The lofted shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.Shape())

    @property
    def first_shape(self):
        """
        :return: The first/bottom shape of the loft if a solid was
            constructed.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.FirstShape())

    @property
    def last_shape(self):
        """
        :return: The last/top shape of the loft if a solid was constructed.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.LastShape())

    @property
    def max_degree(self):
        """
        :return: The max degree used in the approximation algorithm
        :rtype: int
        """
        return self._tool.MaxDegree()

    def generated_face(self, edge):
        """
        Get a face(s) generated by the edge. If the ruled option was used,
        then this returns each face generated by the edge. If the smoothing
        option was used, then this returns the face generated by the edge.

        :param afem.topology.entities.Edge edge: The edge.

        :return: The face(s) generated by the edge.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.GeneratedFace(edge.object))
Example #14
0
    #for p in pp[:-1]:
    #    pt = BRepBuilderAPI_MakeVertex(gp_Pnt(p[0], p[1], p[2])).Shape()
    #    display.DisplayShape(pt)

    # display the wires
    #display.DisplayShape(wire_extrados.Shape(), update=True)
    #display.DisplayShape(wire_intrados.Shape(), update=True)
    display.DisplayShape(wire.Shape(), update=True)

    generator_extrados.AddWire(wire_extrados.Wire())
    generator_intrados.AddWire(wire_intrados.Wire())
    generator_trailing_edge.AddWire(wire_trailing_edge.Wire())
    generator.AddWire(wire.Wire())

#start_display()
generator_extrados.Build()
extrados_shape = generator_extrados.Shape()
generator_intrados.Build()
intrados_shape = generator_intrados.Shape()
generator_trailing_edge.Build()
trailing_edge_shape = generator_trailing_edge.Shape()
intrados_trailing_edge = generator_trailing_edge.Shape()
display.DisplayShape(extrados_shape)
display.DisplayShape(intrados_shape)
display.DisplayShape(trailing_edge_shape)

generator.Build()
#display.DisplayShape(generator.Shape())
step_writer = STEPControl_Writer()
step_writer.Transfer(extrados_shape, STEPControl_AsIs)
step_writer.Transfer(intrados_shape, STEPControl_AsIs)