class_docstr: 3D boxes containing N or BxN boxes.
  
  Args:
      boxes: 3D boxes, shape of :math:`(N,8,3)` or :math:`(B,N,8,3)`. See below for more details.
      raise_if_not_floating_point: flag to control floating point casting behaviour when `boxes` is not a floating
          point tensor. True to raise an error when `boxes` isn't a floating point tensor, False to cast to float.
  
  Note:
      **3D boxes format** is defined as a floating data type tensor of shape ``Nx8x3`` or ``BxNx8x3`` where each box
      is a `hexahedron <https://en.wikipedia.org/wiki/Hexahedron>`_ defined by it's 8 vertices coordinates.
      Coordinates must be in ``x, y, z`` order. The height, width and depth of a box is defined as
      ``width = xmax - xmin + 1``, ``height = ymax - ymin + 1`` and ``depth = zmax - zmin + 1``. Examples of
      `hexahedrons <https://en.wikipedia.org/wiki/Hexahedron>`_ are cubes and rhombohedrons.
class_docstr_tok: ["3D","boxes","containing","N","or","BxN","boxes",".","Args",":","boxes",":","3D","boxes",",","shape","of",":","math",":","`","(","N,8,3",")","`","or",":","math",":","`","(","B",",","N,8,3",")","`",".","See","below","for","more","details",".","raise_if_not_floating_point",":","flag","to","control","floating","point","casting","behaviour","when","`","boxes","`","is","not","a","floating","point","tensor",".","True","to","raise","an","error","when","`","boxes","`","is","n't","a","floating","point","tensor",",","False","to","cast","to","float",".","Note",":","*","*","3D","boxes","format","*","*","is","defined","as","a","floating","data","type","tensor","of","shape","``","Nx8x3","``","or","``","BxNx8x3","``","where","each","box","is","a","`","hexahedron","<","https",":","\/\/en.wikipedia.org\/wiki\/Hexahedron",">","`","_","defined","by","it","'s","8","vertices","coordinates",".","Coordinates","must","be","in","``","x",",","y",",","z","``","order",".","The","height",",","width","and","depth","of","a","box","is","defined","as","``","width","=","xmax","-","xmin","+","1","``",",","``","height","=","ymax","-","ymin","+","1","``","and","``","depth","=","zmax","-","zmin","+","1","``",".","Examples","of","`","hexahedrons","<","https",":","\/\/en.wikipedia.org\/wiki\/Hexahedron",">","`","_","are","cubes","and","rhombohedrons","."]
docstr: Cast :class:`Boxes3D` to a tensor. ``mode`` controls which 3D boxes format should be use to represent
  boxes in the tensor.
  
  Args:
      mode: The format in which the boxes are provided.
  
          * 'xyzxyz': boxes are assumed to be in the format ``xmin, ymin, zmin, xmax, ymax, zmax`` where
            ``width = xmax - xmin``, ``height = ymax - ymin`` and ``depth = zmax - zmin``.
          * 'xyzxyz_plus': similar to 'xyzxyz' mode but where box width, length and depth are defined as
             ``width = xmax - xmin + 1``, ``height = ymax - ymin + 1`` and ``depth = zmax - zmin + 1``.
          * 'xyzwhd': boxes are assumed to be in the format ``xmin, ymin, zmin, width, height, depth`` where
            ``width = xmax - xmin``, ``height = ymax - ymin`` and ``depth = zmax - zmin``.
          * 'vertices': boxes are defined by their vertices points in the following ``clockwise`` order:
            *front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,
            back-top-right, back-bottom-right,  back-bottom-left*. Vertices coordinates are in (x,y, z) order.
            Finally, box width, height and depth are defined as ``width = xmax - xmin``, ``height = ymax - ymin``
            and ``depth = zmax - zmin``.
          * 'vertices_plus': similar to 'vertices' mode but where box width, length and depth are defined as
            ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``.
  
  Returns:
      3D Boxes tensor in the ``mode`` format. The shape depends with the ``mode`` value:
  
          * 'vertices' or 'verticies_plus': :math:`(N, 8, 3)` or :math:`(B, N, 8, 3)`.
          * Any other value: :math:`(N, 6)` or :math:`(B, N, 6)`.
  
  Note:
      It is currently non-differentiable due to a bug. See github issue
      `#1304 <https://github.com/kornia/kornia/issues/1396>`_.
  
  Examples:
      >>> boxes_xyzxyz = torch.as_tensor([[0, 3, 6, 1, 4, 8], [5, 1, 3, 8, 4, 9]])
      >>> boxes = Boxes3D.from_tensor(boxes_xyzxyz, mode='xyzxyz')
      >>> assert (boxes.to_tensor(mode='xyzxyz') == boxes_xyzxyz).all()
code: def to_tensor(self, mode: str = "xyzxyz") -> torch.Tensor:
      r"""Cast :class:`Boxes3D` to a tensor. ``mode`` controls which 3D boxes format should be use to represent
      boxes in the tensor.
  
      Args:
          mode: The format in which the boxes are provided.
  
              * 'xyzxyz': boxes are assumed to be in the format ``xmin, ymin, zmin, xmax, ymax, zmax`` where
                ``width = xmax - xmin``, ``height = ymax - ymin`` and ``depth = zmax - zmin``.
              * 'xyzxyz_plus': similar to 'xyzxyz' mode but where box width, length and depth are defined as
                 ``width = xmax - xmin + 1``, ``height = ymax - ymin + 1`` and ``depth = zmax - zmin + 1``.
              * 'xyzwhd': boxes are assumed to be in the format ``xmin, ymin, zmin, width, height, depth`` where
                ``width = xmax - xmin``, ``height = ymax - ymin`` and ``depth = zmax - zmin``.
              * 'vertices': boxes are defined by their vertices points in the following ``clockwise`` order:
                *front-top-left, front-top-right, front-bottom-right, front-bottom-left, back-top-left,
                back-top-right, back-bottom-right,  back-bottom-left*. Vertices coordinates are in (x,y, z) order.
                Finally, box width, height and depth are defined as ``width = xmax - xmin``, ``height = ymax - ymin``
                and ``depth = zmax - zmin``.
              * 'vertices_plus': similar to 'vertices' mode but where box width, length and depth are defined as
                ``width = xmax - xmin + 1`` and ``height = ymax - ymin + 1``.
  
      Returns:
          3D Boxes tensor in the ``mode`` format. The shape depends with the ``mode`` value:
  
              * 'vertices' or 'verticies_plus': :math:`(N, 8, 3)` or :math:`(B, N, 8, 3)`.
              * Any other value: :math:`(N, 6)` or :math:`(B, N, 6)`.
  
      Note:
          It is currently non-differentiable due to a bug. See github issue
          `#1304 <https://github.com/kornia/kornia/issues/1396>`_.
  
      Examples:
          >>> boxes_xyzxyz = torch.as_tensor([[0, 3, 6, 1, 4, 8], [5, 1, 3, 8, 4, 9]])
          >>> boxes = Boxes3D.from_tensor(boxes_xyzxyz, mode='xyzxyz')
          >>> assert (boxes.to_tensor(mode='xyzxyz') == boxes_xyzxyz).all()
      """
      if self._data.requires_grad:
          raise RuntimeError(
              "Boxes3D.to_tensor doesn't support computing gradients since they aren't accurate. "
              "Please, create boxes from tensors with `requires_grad=False`. "
              "This is a known bug. Help is needed to fix it. For more information, "
              "see https://github.com/kornia/kornia/issues/1396."
          )
  
      batched_boxes = (
          self._data if self._is_batched else self._data.unsqueeze(0)
      )
  
      # Create boxes in xyzxyz_plus format.
      boxes = stack(
          [batched_boxes.amin(dim=-2), batched_boxes.amax(dim=-2)],
          dim=-2,
      ).view(batched_boxes.shape[0], batched_boxes.shape[1], 6)
  
      mode = mode.lower()
      if mode in ("xyzxyz", "xyzxyz_plus"):
          pass
      elif mode in ("xyzwhd", "vertices", "vertices_plus"):
          width = boxes[..., 3] - boxes[..., 0] + 1
          height = boxes[..., 4] - boxes[..., 1] + 1
          depth = boxes[..., 5] - boxes[..., 2] + 1
          boxes[..., 3] = width
          boxes[..., 4] = height
          boxes[..., 5] = depth
      else:
          raise ValueError(f"Unknown mode {mode}")
  
      if mode in ("xyzxyz", "vertices"):
          offset = torch.as_tensor(
              [0, 0, 0, 1, 1, 1], device=boxes.device, dtype=boxes.dtype
          )
          boxes = boxes + offset
  
      if mode.startswith("vertices"):
          xmin, ymin, zmin = boxes[..., 0], boxes[..., 1], boxes[..., 2]
          width, height, depth = (
              boxes[..., 3],
              boxes[..., 4],
              boxes[..., 5],
          )
  
          boxes = _boxes3d_to_polygons3d(
              xmin, ymin, zmin, width, height, depth
          )
  
      boxes = boxes if self._is_batched else boxes.squeeze(0)
      return boxes
  
imports: from __future__ import annotations
  from typing import Optional, cast
  import torch
  from torch import Size
  from kornia.core import Tensor, stack, zeros
  from kornia.geometry.bbox import validate_bbox
  from kornia.geometry.linalg import transform_points
  from kornia.utils import eye_like
label_desc: Use image node_id 7 for calling the Boxes3D obj's underlying member method code with example usage: obj.to_tensor(mode) and returns: boxes