Esempio n. 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()))
def get_boundingbox(shape, tol=1e-6, use_mesh=True):
    """ return the bounding box of the TopoDS_Shape `shape`
    Parameters
    ----------
    shape : TopoDS_Shape or a subclass such as TopoDS_Face
        the shape to compute the bounding box from
    tol: float
        tolerance of the computed boundingbox
    use_mesh : bool
        a flag that tells whether or not the shape has first to be meshed before the bbox
        computation. This produces more accurate results
    """
    bbox = Bnd_Box()
    bbox.SetGap(tol)
    if use_mesh:
        mesh = BRepMesh_IncrementalMesh()
        mesh.SetParallelDefault(True)
        mesh.SetShape(shape)
        mesh.Perform()
        if not mesh.IsDone():
            raise AssertionError("Mesh not done.")
    brepbndlib_Add(shape, bbox, use_mesh)

    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    return xmin, ymin, zmin, xmax, ymax, zmax, xmax - xmin, ymax - ymin, zmax - zmin
Esempio n. 3
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()))
def get_boundingbox(shape, tol=TOLERANCE):
    '''
    :param shape: TopoDS_Shape such as TopoDS_Face
    :param tol: tolerance
    :return: xmin, ymin, zmin, xmax, ymax, zmax
    '''
    bbox = Bnd_Box()
    bbox.SetGap(tol)
    brepbndlib_Add(shape, bbox)
    xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
    return xmin, ymin, zmin, xmax, ymax, zmax
Esempio n. 5
0
def compute_bbox(shp, *kwargs):
    print("Compute bbox for %s " % shp)
    for shape in shp:
        bbox = Bnd_Box()
        brepbndlib_Add(shape, bbox)
        xmin, ymin, zmin, xmax, ymax, zmax = bbox.Get()
        dx = xmax - xmin
        dy = ymax - ymin
        dz = zmax - zmin
        print("Selected shape bounding box : dx=%f, dy=%f, dz=%f." %
              (dx, dy, dz))
        print("               bounding box center: x=%f, y=%f, z=%f" %
              (xmin + dx / 2., ymin + dy / 2., zmin + dz / 2.))
def point_in_boundingbox(solid, pnt, tolerance=1e-5):
    """returns True if *pnt* lies in *boundingbox*, False if not
    this is a much speedier test than checking the TopoDS_Solid
    Args:
        solid   TopoDS_Solid
        pnt:    gp_Pnt

    Returns: bool
    """
    bbox = Bnd_Box()
    bbox.SetGap(tolerance)
    brepbndlib_Add(solid, bbox)
    return not bbox.IsOut(pnt)
Esempio n. 7
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())