Exemplo n.º 1
0
 def _bounding_box(self, obj, tol=1e-5):
     bbox = Bnd_Box()
     if self.optimal:
         BRepTools.Clean_s(obj)
         BRepBndLib.AddOptimal_s(obj, bbox)
     else:
         BRepBndLib.Add_s(obj, bbox)
     values = bbox.Get()
     return (values[0], values[3], values[1], values[4], values[2], values[5])
Exemplo n.º 2
0
 def _bounding_box(self, obj, tol=1e-6):
     bbox = Bnd_Box()
     if self.optimal:
         BRepTools.Clean_s(obj)
         BRepBndLib.AddOptimal_s(obj, bbox)
     else:
         BRepBndLib.Add_s(obj, bbox)
     if not bbox.IsVoid():
         values = bbox.Get()
         return (values[0], values[3], values[1], values[4], values[2],
                 values[5])
     else:
         c = self._center_of_mass(obj)
         bb = (c[0] - tol, c[0] + tol, c[1] - tol, c[1] + tol, c[2] - tol,
               c[2] + tol)
         print("\nVoid Bounding Box", bb)
         return bb
Exemplo n.º 3
0
    def add(
        self,
        obj: Union[Tuple[float, float, float], Vector, "BoundBox"],
        tol: float = 1e-8,
    ) -> "BoundBox":
        """Returns a modified (expanded) bounding box

        obj can be one of several things:
            1. a 3-tuple corresponding to x,y, and z amounts to add
            2. a vector, containing the x,y,z values to add
            3. another bounding box, where a new box will be created that
               encloses both.

        This bounding box is not changed.
        """

        tmp = Bnd_Box()
        tmp.SetGap(tol)
        tmp.Add(self.wrapped)

        if isinstance(obj, tuple):
            tmp.Update(*obj)
        elif isinstance(obj, Vector):
            tmp.Update(*obj.toTuple())
        elif isinstance(obj, BoundBox):
            tmp.Add(obj.wrapped)

        return BoundBox(tmp)
Exemplo n.º 4
0
    def __init__(self, bb: Bnd_Box) -> None:
        self.wrapped = bb
        XMin, YMin, ZMin, XMax, YMax, ZMax = bb.Get()

        self.xmin = XMin
        self.xmax = XMax
        self.xlen = XMax - XMin
        self.ymin = YMin
        self.ymax = YMax
        self.ylen = YMax - YMin
        self.zmin = ZMin
        self.zmax = ZMax
        self.zlen = ZMax - ZMin

        self.center = Vector((XMax + XMin) / 2, (YMax + YMin) / 2,
                             (ZMax + ZMin) / 2)

        self.DiagonalLength = self.wrapped.SquareExtent()**0.5
Exemplo n.º 5
0
    def _fromTopoDS(
        cls: Type["BoundBox"],
        shape: TopoDS_Shape,
        tol: Optional[float] = None,
        optimal: bool = True,
    ):
        """
        Constructs a bounding box from a TopoDS_Shape
        """
        tol = TOL if tol is None else tol  # tol = TOL (by default)
        bbox = Bnd_Box()

        if optimal:
            BRepBndLib.AddOptimal_s(
                shape, bbox
            )  # this is 'exact' but expensive - not yet wrapped by PythonOCC
        else:
            mesh = BRepMesh_IncrementalMesh(shape, tol, True)
            mesh.Perform()
            # this is adds +margin but is faster
            BRepBndLib.Add_s(shape, bbox, True)

        return cls(bbox)
Exemplo n.º 6
0
 def _bounding_box(self, obj, tol=1e-5):
     bbox = Bnd_Box()
     BRepBndLib.AddOptimal_s(obj, bbox)
     values = bbox.Get()
     return (values[0], values[3], values[1], values[4], values[2],
             values[5])