+
    åûj
u  ã                   óÂ   € R t ^ RIHt ^ RIt^ RIHtHtHt ^ RIH	t	H
t
 ^RIHtHt . ROtRR R lltRR R	 lltRR
 R lltRR R lltR R ltR R ltRR R lltR# )uá  Crop volume regions by boxes or by a matrix, resampled to a given output size.

The crops take channels-first volumes ``(B, C, D, H, W)``. A box is ``(B, 8, 3)``: eight ``(x, y, z)`` voxel
corners, the front face (smaller ``z``) and then the back face, each face top-left, top-right, bottom-right,
bottom-left, with **inclusive** coordinates as in the 2D crops of
:func:`~kornia.geometry.transform.crop_and_resize`. Sizes are ``(d, h, w)``. Every crop resamples by a
sourceâ†’destination voxel matrix through :func:`~kornia.geometry.transform.warp_affine3d`, into an output window that
starts at voxel ``(0, 0, 0)``. Pass ``align_corners=True``: at ``False`` the matrix is normalized for corner-aligned
voxels while ``grid_sample`` reads half-voxel ones, so the samples miss the box, and even a box of the output size is
interpolated rather than copied (`#4503 <https://github.com/kornia/kornia/issues/4503>`_). :func:`crop_and_resize3d`
and :func:`crop_by_boxes3d` default to ``False``. In eager mode the box crops reject, with ``AssertionError``, a box
whose four edges along an axis span different extents on it, one with a non-finite coordinate, and a pair of boxes
that no affine map relates, such as a box that is not a parallelepiped in :func:`crop_and_resize3d`. An axis-aligned
box may have a one-voxel axis where the output has one too; resizing a one-voxel axis to more voxels, or a longer one
to one voxel, raises ``torch.linalg.LinAlgError`` (`#4747 <https://github.com/kornia/kornia/issues/4747>`_).
For half-precision volumes, box crops keep the boxes and solved matrix in float32 through sampling, then return the
volume's dtype, so rounding the matrix does not move the sampled voxels.

Which function to use:

- A box resampled to a fixed ``(d, h, w)``: :func:`crop_and_resize3d`; mapped onto a second box whose size sets the
  output: :func:`crop_by_boxes3d`.
- A crop given as a sourceâ†’destination voxel matrix, ``(B, 3, 4)`` or ``(B, 4, 4)``: :func:`crop_by_transform_mat3d`.
- The central window of each volume: :func:`center_crop3d`.
- For images, use :func:`~kornia.geometry.transform.crop_and_resize` and the other 2D crops; in an augmentation
  pipeline, :class:`~kornia.augmentation.RandomCrop3D` or :class:`~kornia.augmentation.CenterCrop3D`.
)ÚTupleN)Ú_autocast_disabledÚ_samples_half_in_float32Úis_compiling)Ú_validate_bbox3dÚinfer_bbox_shape3d)Úget_perspective_transform3dÚwarp_affine3dc                óÈ   € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        \        3,          R\        R\
        R\         P                  /# )é   ÚtensorÚboxesÚsizeÚinterpolationÚalign_cornersÚreturn©ÚtorchÚTensorr   ÚintÚstrÚbool)Úformats   "Ú\C:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\geometry\transform\crop3d.pyÚ__annotate__r   :   sk   € ÷ Ayñ AyÜ�L‰LðAyä�<‰<ðAyô ””Sœ#�Õ
ðAyô ð	Ayô
 ðAyô ‡\�\ñAyó    c                ó”  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V\        P                  4      '       g   \        R\	        V4       24      h\        V\
        \        34      '       d   \        V4      ^8w  d   \        RV 24      h\        V P                  4      ^8w  d   \        RV P                   R24      hV^ ,          V^,          V^,          rvpTp\        P                  ! . ROV^,
          ^ ^ .V^,
          V^,
          ^ .^ V^,
          ^ .^ ^ V^,
          .V^,
          ^ V^,
          .V^,
          V^,
          V^,
          .^ V^,
          V^,
          ...V P                  V P                  R7      P                  VP                  ^ ,          RR4      p	\        WW•Wg3W44      # )	u	  Crop an eight-corner box from each volume and resample it to a fixed output size.

``patches = crop_and_resize3d(tensor, boxes, size)`` takes volumes ``(B, C, D, H, W)`` and boxes ``(B, 8, 3)``, one
per volume or ``(1, 8, 3)`` for all of them, and returns the ``(B, C, d, h, w)`` patches for ``size = (d, h, w)``.
Each box must be a parallelepiped, so that an affine map takes it onto the patch; with ``align_corners=True`` its
corners land on the corner voxels of the patch. Pass ``align_corners=True``, since the default
``False`` samples off the box (`#4503 <https://github.com/kornia/kornia/issues/4503>`_). For images, use
:func:`crop_and_resize`; to place the crop by a second box, :func:`crop_by_boxes3d`.

Convention:
    - input: ``(B, C, D, H, W)``; ``size`` is ``(d, h, w)``
    - ``boxes``: ``(B, 8, 3)`` corner points in ``(x, y, z)`` order, front face
      then back face, each face top-left, top-right, bottom-right, bottom-left â€”
      same ``(x, y)``/inclusive-pixel convention as :func:`crop_and_resize`, with
      ``z`` anchored at the top-left of the first depth slice (``z = 0``);
      reproducing the exact integer-voxel slice requires ``align_corners=True`` â€”
      the default ``False`` interpolates instead
    - align_corners: ``False`` by default
    - a single volume does not broadcast over a batch of boxes
    - a one-voxel axis of an axis-aligned box crops to a one-voxel axis of ``size``; a one-voxel axis on only one
      of the two raises ``torch.linalg.LinAlgError`` (`#4747 <https://github.com/kornia/kornia/issues/4747>`_)

Args:
    tensor: the 3D volume tensor with shape ``(B, C, D, H, W)``.
    boxes: a tensor with shape ``(B, 8, 3)`` containing the coordinates of the bounding boxes
        to be extracted, where each box is defined in the 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. The coordinates must be in x, y, z order.
    size: a tuple with the depth, height and width that will be
        used to resize the extracted patches.
    interpolation: Interpolation flag.
    align_corners: mode for grid_generation.

Returns:
    tensor containing the patches with shape ``(B, C, d, h, w)``.

Raises:
    AssertionError: if a box has a non-finite coordinate, edges along one axis that span different extents on
        it, or is not a parallelepiped.

See Also:
    - :func:`crop_and_resize`: the same for images and ``(B, 4, 2)`` boxes, where ``align_corners`` changes only
      ``'reflection'`` padding and, with ``mode='nearest'``, which pixel a sample exactly halfway takes.
    - :func:`crop_by_boxes3d`: maps the box onto a second box, whose size sets the output size.
    - :func:`center_crop3d`: the central window of each volume, with ``align_corners=True`` by default.

Example:
    >>> input = torch.arange(64, dtype=torch.float32).view(1, 1, 4, 4, 4)
    >>> input
    tensor([[[[[ 0.,  1.,  2.,  3.],
               [ 4.,  5.,  6.,  7.],
               [ 8.,  9., 10., 11.],
               [12., 13., 14., 15.]],
    <BLANKLINE>
              [[16., 17., 18., 19.],
               [20., 21., 22., 23.],
               [24., 25., 26., 27.],
               [28., 29., 30., 31.]],
    <BLANKLINE>
              [[32., 33., 34., 35.],
               [36., 37., 38., 39.],
               [40., 41., 42., 43.],
               [44., 45., 46., 47.]],
    <BLANKLINE>
              [[48., 49., 50., 51.],
               [52., 53., 54., 55.],
               [56., 57., 58., 59.],
               [60., 61., 62., 63.]]]]])
    >>> boxes = torch.tensor([[
    ...     [1., 1., 1.],
    ...     [3., 1., 1.],
    ...     [3., 3., 1.],
    ...     [1., 3., 1.],
    ...     [1., 1., 2.],
    ...     [3., 1., 2.],
    ...     [3., 3., 2.],
    ...     [1., 3., 2.],
    ... ]])  # 1x8x3
    >>> crop_and_resize3d(input, boxes, (2, 2, 2), align_corners=True)
    tensor([[[[[21.0000, 23.0000],
               [29.0000, 31.0000]],
    <BLANKLINE>
              [[37.0000, 39.0000],
               [45.0000, 47.0000]]]]])

ú-Input tensor type is not a torch.Tensor. Got z,Input boxes type is not a torch.Tensor. Got ú1Input size must be a tuple/list of length 3. Got ú6Only tensor with shape (B, C, D, H, W) supported. Got Ú.)ÚdtypeÚdevice©é    r$   r$   éÿÿÿÿ)Ú
isinstancer   r   Ú	TypeErrorÚtypeÚtupleÚlistÚlenÚ
ValueErrorÚshapeÚAssertionErrorr   r!   r"   ÚexpandÚ_crop_by_boxes3d_to_size)
r   r   r   r   r   Údst_dÚdst_hÚdst_wÚ
points_srcÚ
points_dsts
   &&&&&     r   Úcrop_and_resize3dr6   :   sª  € ôz �fœuŸ|™|×-Ò-ÜÐGÌÈVËÀ~ÐVÓWÐWÜ�eœeŸl™l×,Ò,ÜÐFÄtÈEÃ{ÀmÐTÓUÐUÜ�dœU¤D˜M×*Ò*¬c°$«i¸1¬nÜÐLÈTÈFÐSÓTÐTÜ
ˆ6�<‰<Ó˜AÔÜÐUÐV\×VbÑVbÐUcÐcdÐeÓfÐfà˜q�' 4¨¥7¨D°­G�%€Eð
  %€Jô
  %Ÿ|š|ò Ø˜•˜A˜qÐ!Ø˜•˜E A�I qÐ)Ø�E˜A•I˜qÐ!Ø�A�u˜q•yÐ!Ø˜•˜A˜u q�yÐ)Ø˜•˜E A�I u¨q¥yÐ1Ø�E˜A•I˜u q�yÐ)ð	ð	
ð �l‰lØ�}‰}ô ÷ �fˆZ×Ñ˜aÕ  " bÓ)ð ô" $ F¸
ÈEÐDYÐ[hÓxÐxr   c          
      ó¨   € V ^8„  d   QhR\         P                  R\        \        \        \        3,          R\        R\
        R\         P                  /# )r   r   r   r   r   r   r   )r   s   "r   r   r   ¾   sN   € ÷ Nñ NÜ�L‰LðNÜ %¤c¬3´ mÕ 4ðNÜEHðNÜfjðNä
‡\�\ñNr   c                ó^  € \        V \        P                  4      '       g   \        R\	        V 4       24      h\        V P                  4      ^8w  d   \        RV P                   R24      h\        V\        \        34      '       d   \        V4      ^8w  d   \        RV 24      hVw  rEpV P                  RR w  rxp	V^,          p
V^,          pV^,          pV^,          pV^,          pV	^,          p\        Wü,
          4      p\        Wë,
          4      p\        WÚ,
          4      pVV,           ^,
          pVV,           ^,
          pVV,           ^,
          p\        P                  ! VVV.VVV.VVV.VVV.VVV.VVV.VVV.VVV...V P                  R7      p\        P                  ! . ROV^,
          ^ ^ .V^,
          V^,
          ^ .^ V^,
          ^ .^ ^ V^,
          .V^,
          ^ V^,
          .V^,
          V^,
          V^,
          .^ V^,
          V^,
          ...V P                  R7      P                  VP                  ^ ,          R	R	4      p\        P                  ! V P                   \        P"                  4      p\%        V VP'                  V4      VP'                  V4      WEV3VV4      # )
a  Crop the central window of each volume to a given size.

``patches = center_crop3d(tensor, size)`` takes volumes ``(B, C, D, H, W)`` and returns their central
``(B, C, d, h, w)`` windows for ``size = (d, h, w)``: with the default ``align_corners=True``, a sub-volume of the
input, with the extra voxel of an odd margin at the back/bottom/right. A ``size`` larger than the input pads with
zeros. For images, use :func:`center_crop`; for a crop at any box, :func:`crop_and_resize3d`.

Convention:
    - input: ``(B, C, D, H, W)``; ``size`` is ``(d, h, w)``
    - align_corners: ``True`` by default
    - offset: the crop starts at the integer voxel ``int(D / 2 - d / 2)`` (likewise for the height and width),
      as in :class:`~kornia.augmentation.CenterCrop3D`, so with the default ``align_corners=True`` the output is a
      sub-volume of the input. With an odd margin the extra voxel is left at the back/bottom/right.
      ``align_corners=False`` resamples off the voxel grid even for an even margin (see
      :func:`crop_and_resize3d`, `#4503 <https://github.com/kornia/kornia/issues/4503>`_).
    - a ``size`` may have one-voxel axes (`#4747 <https://github.com/kornia/kornia/issues/4747>`_)

Args:
    tensor: the 3D volume tensor with shape ``(B, C, D, H, W)``.
    size: a tuple with the expected depth, height and width
        of the output patch.
    interpolation: Interpolation flag.
    align_corners : mode for grid_generation.

Returns:
    the central windows, with shape ``(B, C, d, h, w)``.

See Also:
    - :func:`center_crop`: the central window of each image.
    - :func:`crop_and_resize3d`: a window at any box, resampled to a fixed size.
    - :class:`~kornia.augmentation.CenterCrop3D`: the same windows as an augmentation, for augmentation pipelines;
      it raises for a ``size`` larger than the input instead of padding.

Examples:
    >>> input = torch.arange(64, dtype=torch.float32).view(1, 1, 4, 4, 4)
    >>> input
    tensor([[[[[ 0.,  1.,  2.,  3.],
               [ 4.,  5.,  6.,  7.],
               [ 8.,  9., 10., 11.],
               [12., 13., 14., 15.]],
    <BLANKLINE>
              [[16., 17., 18., 19.],
               [20., 21., 22., 23.],
               [24., 25., 26., 27.],
               [28., 29., 30., 31.]],
    <BLANKLINE>
              [[32., 33., 34., 35.],
               [36., 37., 38., 39.],
               [40., 41., 42., 43.],
               [44., 45., 46., 47.]],
    <BLANKLINE>
              [[48., 49., 50., 51.],
               [52., 53., 54., 55.],
               [56., 57., 58., 59.],
               [60., 61., 62., 63.]]]]])
    >>> center_crop3d(input, (2, 2, 2), align_corners=True)
    tensor([[[[[21.0000, 22.0000],
               [25.0000, 26.0000]],
    <BLANKLINE>
              [[37.0000, 38.0000],
               [41.0000, 42.0000]]]]])

r   r   r    r   N)r"   éýÿÿÿr#   r%   )r&   r   r   r'   r(   r+   r-   r.   r)   r*   r,   r   r   r"   r/   Úpromote_typesr!   Úfloat32r0   Úto)r   r   r   r   r1   r2   r3   Úsrc_dÚsrc_hÚsrc_wÚ
dst_d_halfÚ
dst_h_halfÚ
dst_w_halfÚ
src_d_halfÚ
src_h_halfÚ
src_w_halfÚstart_xÚstart_yÚstart_zÚend_xÚend_yÚend_zr4   r5   Ú	box_dtypes   &&&&                     r   Úcenter_crop3drM   ¾   s¹  € ôD �fœeŸl™l×+Ò+ÜÐGÌÈVËÀ~ÐVÓWÐWä
ˆ6�<‰<Ó˜AÔÜÐUÐV\×VbÑVbÐUcÐcdÐeÓfÐfä�dœU¤D˜M×*Ò*¬c°$«i¸1¬nÜÐLÈTÈFÐSÓTÐTð Ñ€E�%Ø Ÿ,™, r sÐ+Ñ€E�%ð ˜•€JØ˜•€JØ˜•€JØ˜•€JØ˜•€JØ˜•€Jô �*Õ)Ó*€GÜ�*Õ)Ó*€GÜ�*Õ)Ó*€Gà�e�O˜aÕ€EØ�e�O˜aÕ€EØ�e�O˜aÕ€Eô  %Ÿ|š|ð ˜' 7Ð+Ø˜ Ð)Ø˜˜wÐ'Ø˜% Ð)Ø˜' 5Ð)Ø˜ Ð'Ø˜˜uÐ%Ø˜% Ð'ð	ð	
ð �}‰}ô €Jô&  %Ÿ|š|ò Ø˜•˜A˜qÐ!Ø˜•˜E A�I qÐ)Ø�E˜A•I˜qÐ!Ø�A�u˜q•yÐ!Ø˜•˜A˜u q�yÐ)Ø˜•˜E A�I u¨q¥yÐ1Ø�E˜A•I˜u q�yÐ)ð	ð	
ð �}‰}ô ÷ �fˆZ×Ñ˜aÕ  " bÓ)ð ô" ×#Ò# F§L¡L´%·-±-Ó@€IÜ#ØØ�‰�iÓ Ø�‰�iÓ Ø	�uÐØØóð r   c                ó°   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        R\        R\         P                  /# )r   r   Úsrc_boxÚdst_boxr   r   r   )r   r   r   r   )r   s   "r   r   r   O  sd   € ÷ jfñ jfÜ�L‰Lðjfä�\‰\ðjfô �\‰\ðjfô ð	jfô
 ðjfô ‡\�\ñjfr   c           	     óÜ  € \        V4      pV^ ,          P                  ^ ,          ^ 8X  d   \        WVRW44      # V^ ,          V^ ,          ^ ,          8H  P                  4       '       d]   V^,          V^,          ^ ,          8H  P                  4       '       d/   V^,          V^,          ^ ,          8H  P                  4       '       g+   \	        RV^ ,           RV^,           RV^,           R24      h\        V^ ,          ^ ,          P                  4       4      \        V^,          ^ ,          P                  4       4      \        V^,          ^ ,          P                  4       4      3p\        WW&W44      # )u…  Crop volumes by mapping a source box onto a destination box, whose size sets the output size.

``patches = crop_by_boxes3d(tensor, src_box, dst_box)`` takes volumes ``(B, C, D, H, W)`` and two boxes per
volume, ``(B, 8, 3)`` each (both ``(1, 8, 3)`` for all volumes), warps each volume by the affine map that takes
the corners of ``src_box`` onto those of ``dst_box``, which must exist, as it does for any two parallelepipeds or
two translated copies of one box, and returns the ``(B, C, d, h, w)`` window that starts at voxel ``(0, 0, 0)``,
where ``(d, h, w)`` is the inclusive size of ``dst_box``; every ``dst_box`` in the batch must have that size. Pass
``align_corners=True``: the default ``False`` samples off the box
(`#4503 <https://github.com/kornia/kornia/issues/4503>`_). When the output size is known, :func:`crop_and_resize3d`
takes it instead of a second box; for images, use :func:`crop_by_boxes`.

Convention:
    - input: ``(B, C, D, H, W)``
    - ``src_box``/``dst_box``: ``(B, 8, 3)`` corner points in ``(x, y, z)``
      order, front face then back face, each face top-left, top-right,
      bottom-right, bottom-left â€” same convention as :func:`crop_and_resize3d`;
      ``dst_box`` determines the output resolution
    - align_corners: ``False`` by default
    - an empty batch has no ``dst_box`` to read a size from and returns ``(0, C, 0, 0, 0)``

Args:
    tensor : the 3D volume tensor with shape ``(B, C, D, H, W)``.
    src_box : a tensor with shape ``(B, 8, 3)`` containing the coordinates of the bounding boxes
        to be extracted, where each box is defined in the 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. The coordinates must be in x, y, z order.
    dst_box: a tensor with shape ``(B, 8, 3)`` containing the coordinates of the bounding boxes
        to be placed, where each box is defined in the 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. The coordinates must be in x, y, z order.
    interpolation: Interpolation flag.
    align_corners: mode for grid_generation.

Returns:
    the patches, with shape ``(B, C, d, h, w)`` for the size ``(d, h, w)`` of ``dst_box``.

Raises:
    AssertionError: if the boxes of ``dst_box`` differ in size, a box has a non-finite coordinate or edges along
        one axis that span different extents on it, or no affine map takes a ``src_box`` onto its ``dst_box``.

See Also:
    - :func:`crop_by_boxes`: the same for images and ``(B, 4, 2)`` boxes.
    - :func:`crop_and_resize3d`: takes the output size as ``size`` and places the box at the patch corners.
    - :func:`crop_by_transform_mat3d`: takes the sourceâ†’destination matrix itself.

Examples:
    >>> input = torch.tensor([[[
    ...         [[ 0.,  1.,  2.,  3.],
    ...          [ 4.,  5.,  6.,  7.],
    ...          [ 8.,  9., 10., 11.],
    ...          [12., 13., 14., 15.]],
    ...         [[16., 17., 18., 19.],
    ...          [20., 21., 22., 23.],
    ...          [24., 25., 26., 27.],
    ...          [28., 29., 30., 31.]],
    ...         [[32., 33., 34., 35.],
    ...          [36., 37., 38., 39.],
    ...          [40., 41., 42., 43.],
    ...          [44., 45., 46., 47.]]]]])
    >>> src_box = torch.tensor([[
    ...     [1., 1., 1.],
    ...     [3., 1., 1.],
    ...     [3., 3., 1.],
    ...     [1., 3., 1.],
    ...     [1., 1., 2.],
    ...     [3., 1., 2.],
    ...     [3., 3., 2.],
    ...     [1., 3., 2.],
    ... ]])  # 1x8x3
    >>> dst_box = torch.tensor([[
    ...     [0., 0., 0.],
    ...     [2., 0., 0.],
    ...     [2., 2., 0.],
    ...     [0., 2., 0.],
    ...     [0., 0., 1.],
    ...     [2., 0., 1.],
    ...     [2., 2., 1.],
    ...     [0., 2., 1.],
    ... ]])  # 1x8x3
    >>> crop_by_boxes3d(input, src_box, dst_box, interpolation='nearest', align_corners=True)
    tensor([[[[[21., 22., 23.],
               [25., 26., 27.],
               [29., 30., 31.]],
    <BLANKLINE>
              [[37., 38., 39.],
               [41., 42., 43.],
               [45., 46., 47.]]]]])

zJCropping depth, height and width must be exact same in a batch. Got depth z	, height z and width r    r#   )r   r-   r0   Úallr.   r   Úitem)r   rO   rP   r   r   ÚbboxÚout_sizes   &&&&&  r   Úcrop_by_boxes3drV   O  s+  € ô@ ˜gÓ&€DØˆA…w‡}�}�QÕ˜1ÔÜ'¨¸À)È]ÓjÐjØ�!�W˜˜Q� �
Ñ"×'Ñ'×)Ò)¨t°A­w¸$¸q½'À!½*Ñ/D×.IÑ.I×.KÒ.KÐQUÐVWÕQXÐ\`ÐabÕ\cÐdeÕ\fÑQf×PkÑPk×PmÒPmÜðØ˜a�˜	 ¨4°­7¨)°;¸tÀA½w¸iÀqðJó
ð 	
ô
 �D˜•G˜A•J—O‘OÓ%Ó&¬¨D°­G°A­J¯O©OÓ,=Ó(>ÄÀDÈÅGÈAÅJÇOÁOÓDUÓ@VÐW€HÜ# F°WÈÓeÐer   c                óè   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\        \        \        \        3,          R\        R\
        R\         P                  /# )r   r   rO   rP   rU   r   r   r   r   )r   s   "r   r   r   ¼  si   € ÷ ,!ñ ,!Ü�L‰Lð,!ä�\‰\ð,!ô �\‰\ð,!ô ”Cœœc�MÕ"ð	,!ô
 ð,!ô ð,!ô ‡\�\ñ,!r   c                 óÖ  € \        V4      '       d   \        V4      '       g   \        R 4      h\        V P                  4      ^8w  d   \        RV P                   R24      hV P                  p\        V 4      pV'       d   \        P                  MV P                  pV P                  V4      p VP                  V4      VP                  V4      r!^V9   d   \        W4      w  ršMYr©\        Wš4      pV'       d
   ^V9  d   TMVP                  p\        WW¼4       VP                  V P                  ^ ,          RR4      P                  V 4      p\        WW4VR7      pVP                  V4      # )z:Boxes must have finite coordinates, got non-finite values.r   r    )Úmoder   r%   )r   r.   r+   r-   r!   r   r   r;   r<   Ú_widen_one_voxel_axesr   Ú_check_boxes_related_by_affiner/   Útype_asÚcrop_by_transform_mat3d)r   rO   rP   rU   r   r   Ú	out_dtypeÚ
half_inputÚ
work_dtypeÚ	solve_srcÚ	solve_dstÚdst_trans_srcÚtolerance_dtypeÚpatchess   &&&&&&        r   r0   r0   ¼  s2  € ô ˜W×%Ò%Ô*:¸7×*CÒ*CÜÐYÓZÐZä
ˆ6�<‰<Ó˜AÔÜÐUÐV\×VbÑVbÐUcÐcdÐeÓfÐfð —‘€Iô *¨&Ó1€Jß",”—’°&·,±,€JØ�Y‰Y�zÓ"€FØ—z‘z *Ó-¨w¯z©z¸*Ó/EˆWàˆH„}Ü4°WÓFÑˆ	�9à&�9Ü"=¸iÓ"S€Mç#-°!¸8Ô2C‘iÈ×I\ÑI\€OÜ" 7°]ÔTà!×(Ñ(¨¯©°a­¸"¸bÓA×IÑIÈ&ÓQ€Mä3Ø˜xÈ=ô€Gð �:‰:�iÓ Ð r   c                ó®   € V ^8„  d   QhR\         P                  R\         P                  R\        \         P                  \         P                  3,          /# )r   rO   rP   r   )r   r   r   )r   s   "r   r   r   ë  sA   € ÷ .ñ .¤5§<¡<ð .¼%¿,¹,ð .Ì5ÔQV×Q]ÑQ]Ô_d×_kÑ_kÐQkÕKlñ .r   c                 óâ  € V P                   VP                   8w  d   W3# \        P                  ! . RO. RO. RO. RO. RO. R	O. R
O. RO.V P                  V P                  R7      pV R. RO3,          V R,          8H  P                  RR7      pVR. RO3,          VR,          8H  P                  RR7      pW#V,          P                  V P                  4      R,          ,          pW,           W,           3# )r$   )r"   r!   ºNNN)Údimr#   )é   r$   r$   )rj   rj   r$   )r$   rj   r$   )r$   r$   rj   )rj   r$   rj   )rj   rj   rj   )r$   rj   rj   )rj   é   é   )rh   :Nrj   Nr%   )rh   Nrh   )r-   r   r   r"   r!   rR   r<   )rO   rP   ÚfarÚsrc_flatÚdst_flatÚoffsets   &&    r   rZ   rZ   ë  sÌ   € ð ‡}�}˜Ÿ™Ô%àÐÐä
�,Š,Ú	’Išyª)²YÂ	Ê9ÒV_Ð`Ø�~‰~Ø�m‰mô€Cð ˜š9˜Õ%¨°­Ñ7×<Ñ<ÀÐ<ÓD€HØ˜š9˜Õ%¨°­Ñ7×<Ñ<ÀÐ<ÓD€HØ˜xÕ'×+Ñ+¨G¯M©MÓ:¸:ÕFÕF€FØÕ˜WÕ-Ð-Ð-r   c          
      óœ   € V ^8„  d   QhR\         P                  R\         P                  R\         P                  R\         P                  RR/# )r   rO   rP   rc   rd   r   N)r   r   r!   )r   s   "r   r   r     sF   € ÷ 
ñ 
Ü�\‰\ð
Ü$)§L¡Lð
ÜAFÇÁð
Ü`e×`kÑ`kð
à	ñ
r   c                 ó  € \         P                  P                  4       '       g   \        4       '       d   R # \         P                  ! VP
                  \         P                  4      pVR,          P                  4       P                  V4      pV P                  4       P                  V4      VP                  4       P                  V4      rvVR,          P                  RR4      VR	,          P                  RR4      r˜\        VP                  P                  4      ;_uu_ 4        Wh,          V	,           V,
          P                  4       P                  R
4      p
VP                  4       VP                  4       ,          V	P                  4       ,           VP                  4       ,           P                  R
4      pR R R 4       \        \         P                   ! V4      P"                  \         P                   ! \         P                  4      P"                  4      R,          X,          p\%        X
V8„  P'                  4       4      '       d-   \)        RV
P                  4       P+                  4       R R24      hR #   + '       g   i     LÄ; i)Ng      à?zŒBoxes must be related by an affine map, as two parallelepipeds are: the affine map the crop warps by misses the corners of dst_box by up to z.3gz voxels.)rh   ºNrk   N).rs   r%   éþÿÿÿ).:rk   NN)rt   r%   )r   ÚjitÚis_scriptingr   r:   r!   r;   Údetachr<   Ú	transposer   r"   r(   ÚabsÚamaxÚmaxÚfinfoÚepsr   Úanyr.   rS   )rO   rP   rc   rd   r`   ÚmatÚsrcÚdstÚlinearÚtranslationÚmissÚscaleÚ	tolerances   &&&&         r   r[   r[     s¸  € ô �9‰9×!Ñ!×#Ò#¬¯ªÙÜ×$Ò$ ]×%8Ñ%8¼%¿-¹-ÓH€JØ
˜Õ
×
%Ñ
%Ó
'×
*Ñ
*¨:Ó
6€CØ�~‰~Ó×"Ñ" :Ó.°·±Ó0@×0CÑ0CÀJÓ0OˆØ˜g�,×0Ñ0°°RÓ8¸#¸g½,×:PÑ:PÐQSÐUWÓ:XˆKä	˜CŸJ™JŸO™O×	,Õ	,Ø•˜{Õ*¨SÕ0×5Ñ5Ó7×<Ñ<¸XÓFˆØ—‘“˜VŸZ™Z›\Õ)¨K¯O©OÓ,=Õ=ÀÇÁÃ	ÕI×OÑOÐPXÓYˆ÷ 
-ô ”E—K’K Ó0×4Ñ4´e·k²kÄ%Ç-Á-Ó6P×6TÑ6TÓUÐY\Õ\Ð_dÕd€IÜˆT�IÑ×"Ñ"Ó$×%Ò%Üð6Ø6:·h±h³j·o±oÓ6GÈÐ5LÈHðVó
ð 	
ñ &÷	 
-×	,ús   Ä!BI/É/I?	c                óÔ   € V ^8„  d   QhR\         P                  R\         P                  R\        \        \        \        3,          R\        R\        R\
        R\         P                  /# )r   r   Ú	transformrU   rY   Úpadding_moder   r   r   )r   s   "r   r   r   !  se   € ÷ 6ñ 6Ü�L‰Lð6ä�|‰|ð6ô ”Cœœc�MÕ"ð6ô ð	6ô
 ð6ô ð6ô ‡\�\ñ6r   c           	     óx   € VP                  V P                  ^ ,          RR4      p\        WR,          W#WER7      pV# )uq  Crop volumes by a sourceâ†’destination voxel matrix into a given output size.

``patches = crop_by_transform_mat3d(tensor, transform, out_size)`` takes volumes ``(B, C, D, H, W)`` and a
sourceâ†’destination voxel matrix per volume, ``(B, 3, 4)`` or ``(B, 4, 4)`` (a batch of 1 serves every volume, which
:func:`warp_affine3d` alone does not allow), and returns the ``(B, C, d, h, w)`` window that starts at voxel
``(0, 0, 0)`` for ``out_size = (d, h, w)``. It warps with :func:`warp_affine3d` and uses only the top three rows,
so a projective last row is ignored. Unlike :func:`crop_by_transform_mat`, it does not cast the matrix: its dtype
must be the volume's. For images, use :func:`crop_by_transform_mat`; to build the matrix from boxes,
:func:`crop_by_boxes3d`.

Convention:
    - input: ``(B, C, D, H, W)``; ``out_size`` is ``(d, h, w)``
    - ``transform`` is the sourceâ†’destination **pixel** transform, accepted as
      either ``(B, 3, 4)`` affine or ``(B, 4, 4)`` homogeneous; only the top
      three rows are used, so a projective last row is ignored (unlike the 2D
      :func:`crop_by_transform_mat`)
    - align_corners: ``True`` by default; ``False`` warps by a matrix normalized for corner-aligned voxels
      (`#4503 <https://github.com/kornia/kornia/issues/4503>`_)

Args:
    tensor: the 3D volume tensor with shape ``(B, C, D, H, W)``.
    transform: the source->destination pixel transform, either affine with
      shape ``(B, 3, 4)`` or homogeneous with shape ``(B, 4, 4)``.
    out_size: size of the output image (depth, height, width).
    mode: interpolation mode to calculate output values
      ``'bilinear'`` | ``'nearest'``.
    padding_mode: padding mode for outside grid values
      ``'zeros'`` | ``'border'`` | ``'reflection'``.
    align_corners: mode for grid_generation.

Returns:
    the patches, with shape ``(B, C, d, h, w)``.

See Also:
    - :func:`crop_by_transform_mat`: the same for images, which also applies a projective row.
    - :func:`warp_affine3d`: the warp it calls, which takes one ``(B, 3, 4)`` matrix per volume.
    - :func:`crop_by_boxes3d`: builds the matrix from a source and a destination box.

)Úflagsr‰   r   r%   )rh   rs   rh   )r/   r-   r	   )r   rˆ   rU   rY   r‰   r   rc   re   s   &&&&&&  r   r]   r]   !  s>   € ð` ×$Ñ$ V§\¡\°!¥_°b¸"Ó=€Mä)Ø˜hÕ'¨ÈLô€Gð €Nr   )rM   r6   rV   r]   )ÚbilinearF)rŒ   T)rŒ   ÚzerosT)Ú__doc__Útypingr   r   Úkornia.core.utilsr   r   r   Úkornia.geometry.bboxr   r   Úimgwarpr   r	   Ú__all__r6   rM   rV   r0   rZ   r[   r]   © r   r   Ú<module>r•      sT   ðñ$õ8 ã ç XÑ Xß Eç ?â
^€÷Ay÷HN÷bjf÷Z,!õ^.õ.
÷>6ñ 6r   