示例#1
0
def sew_shapes(shapes, tolerance=0.001):
    sew = BRepBuilderAPI_Sewing(tolerance)
    for shp in shapes:
        if isinstance(shp, list):
            for i in shp:
                sew.Add(i)
        else:
            sew.Add(shp)
    sew.Perform()
    print("n degenerated shapes", sew.NbDegeneratedShapes())
    print("n deleted faces:", sew.NbDeletedFaces())
    print("n free edges", sew.NbFreeEdges())
    print("n multiple edges:", sew.NbMultipleEdges())
    result = ShapeToTopology()(sew.SewedShape())
    return result
示例#2
0
class SewShape(object):
    """
    Sew the shape.

    :param afem.topology.entities.Shape shape: The context shape to sew.
    :param float tol: Sewing tolerance. If *None* is provided then the
        average tolerance of the shape will be used. If no shape is
        provided, then a default value of 1.0e-7 is used.
    :param float min_tol: Minimum tolerance.
    :param float max_tol: Maximum tolerance.
    :param bool cut_free_edges: Option for cutting of free edges.
    :param bool non_manifold: Option for non-manifold processing.

    .. note::

        If *shape* is *None* then the user is expected to manually load the
        shape and perform the operation.
    """
    def __init__(self,
                 shape=None,
                 tol=None,
                 min_tol=None,
                 max_tol=None,
                 cut_free_edges=False,
                 non_manifold=False):
        if tol is None:
            if shape is None:
                tol = 1.0e-7
            else:
                tol = shape.tol_max

        self._tool = BRepBuilderAPI_Sewing(tol, True, True, cut_free_edges,
                                           non_manifold)

        if min_tol is not None:
            self._tool.SetMinTolerance(min_tol)
        if max_tol is not None:
            self._tool.SetMaxTolerance(max_tol)

        if shape is not None:
            self._tool.Load(shape.object)
            self._tool.Perform()

    def load(self, shape):
        """
        Load the context shape to sew.

        :param afem.topology.entities.Shape shape: The shape.

        :return: None.
        """
        self._tool.Load(shape.object)

    def add(self, shape):
        """
        Add a shape to be sewed or controlled.

        :param afem.topology.entities.Shape shape: The shape.

        :return: None.
        """
        self._tool.Add(shape.object)

    def perform(self):
        """
        Perform the sewing operation.

        :return: None.
        """
        self._tool.Perform()

    @property
    def sewed_shape(self):
        """
        :return: The sewed shape. May be a null shape if nothing is
            constructed.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.SewedShape())

    @property
    def n_free_edges(self):
        """
        :return: Number of free edges.
        :rtype: int
        """
        return self._tool.NbFreeEdges()

    @property
    def free_edges(self):
        """
        :return: Free edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.FreeEdge(i))
            edges.append(e)
        return edges

    @property
    def n_multiple_edges(self):
        """
        :return: Number of edges connected to more than two faces.
        :rtype: int
        """
        return self._tool.NbMultipleEdges()

    @property
    def multiple_edges(self):
        """
        :return: Multiple edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.MultipleEdge(i))
            edges.append(e)
        return edges

    @property
    def n_manifold_edges(self):
        """
        :return: Number of manifold edges.
        :rtype: int
        """
        return self._tool.NbContigousEdges()

    @property
    def manifold_edges(self):
        """
        :return: Manifold edges.
        :rtype: list(afem.topology.entities.Edge)
        """
        edges = []
        for i in range(1, self.n_free_edges + 1):
            e = Edge(self._tool.ContigousEdge(i))
            edges.append(e)
        return edges

    def is_modified(self, shape):
        """
        Check to see if input shape has been modified.

        :param afem.topology.entities.Shape shape: The shape.

        :return: *True* if modified, *False* if not.
        :rtype: bool
        """
        self._tool.IsModified(shape.object)

    def modified(self, shape):
        """
        Get a modified shape.

        :param afem.topology.entities.Shape shape: The shape.

        :return: The modified shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.Modified(shape.object))

    def is_modified_subshape(self, subshape):
        """
        Check to see if input sub-shape has been modified.

        :param afem.topology.entities.Shape subshape: The sub-shape.

        :return: *True* if modified, *False* if not.
        :rtype: bool
        """
        self._tool.IsModifiedSubShape(subshape.object)

    def modified_subshape(self, subshape):
        """
        Get a modified sub-shape.

        :param afem.topology.entities.Shape subshape: The sub-shape.

        :return: The modified sub-shape.
        :rtype: afem.topology.entities.Shape
        """
        return Shape.wrap(self._tool.ModifiedSubShape(subshape.object))