예제 #1
0
def _loft(arr, smooth=False, shell=False, maxdegree=4):
    builder = BRepOffsetAPI_ThruSections(not shell, not smooth)
    builder.SetMaxDegree(maxdegree)

    for v in arr:
        if v.Shape().ShapeType() == TopAbs_FACE:
            raise Exception("Loft argument must be array of Wires or Edges")

    for r in arr:
        builder.AddWire(r.Wire_orEdgeToWire())

    return Shape(builder.Shape())
예제 #2
0
파일: blade.py 프로젝트: 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)
예제 #3
0
파일: blade.py 프로젝트: 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)
예제 #4
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))