예제 #1
0
    def bbox(cls, shapes, optimal=False, tolerance=0):
        """ Compute the bounding box of the shape or list of shapes

        Parameters
        ----------
        shapes: Shape, TopoDS_Shape or list of them
            The shapes to compute the bounding box for

        Returns
        -------
        bbox: BBox
            The boudning g

        """
        from .occ_shape import coerce_shape
        if not shapes:
            return BBox()
        bbox = Bnd_Box()
        bbox.SetGap(tolerance)
        if not isinstance(shapes, (list, tuple, set)):
            shapes = [shapes]
        add = BRepBndLib.AddOptimal_ if optimal else BRepBndLib.Add_
        for s in shapes:
            add(coerce_shape(s), bbox)
        pmin, pmax = bbox.CornerMin(), bbox.CornerMax()
        return BBox(*(pmin.X(), pmin.Y(), pmin.Z(), pmax.X(), pmax.Y(),
                      pmax.Z()))
예제 #2
0
 def get_bounding_box(self, shape=None):
     shape = shape or self.shape
     if not shape:
         return BBox()
     bbox = Bnd_Box()
     BRepBndLib.Add_(shape, bbox)
     pmin, pmax = bbox.CornerMin(), bbox.CornerMax()
     return BBox(*(pmin.X(), pmin.Y(), pmin.Z(), pmax.X(), pmax.Y(),
                   pmax.Z()))
예제 #3
0
    def get_bounding_box(self, shapes):
        """ Compute the bounding box for the given list of shapes. Return values
        are in 3d coordinate space.

        Parameters
        ----------
        shapes: List
            A list of TopoDS_Shape to compute a bbox for

        Returns
        -------
        bbox: Tuple
            A tuple of (xmin, ymin, zmin, xmax, ymax, zmax).

        """
        bbox = Bnd_Box()
        for shape in shapes:
            BRepBndLib.Add_(shape, bbox)
        try:
            pmin = bbox.CornerMin()
            pmax = bbox.CornerMax()
        except RuntimeError:
            return (0, 0, 0, 0, 0, 0)
        return (pmin.X(), pmin.Y(), pmin.Z(), pmax.X(), pmax.Y(), pmax.Z())