+
    úäûj÷  ã                   óˆ   € ^ RI HtHtHtHt ^ RIt^ RIHt ^ RI	H
t
 ^ RIHt ^ RIHt ^ RIHt ^ RIHtHt  ! R	 R
]
4      tR# )é    )ÚAnyÚDictÚOptionalÚUnionN)Úrandom_generator)ÚGeometricAugmentationBase3D)Ú_constant_tensor)ÚResample)Ú_to_device_nonblocking)Úget_perspective_transform3dÚwarp_perspective3dc                   ó¢   a a€ ] tR t^t oRtR]P                  P                  RRRR3V3R lV 3R llltV3R lR lt	RV3R lR	 llt
R
tVtV ;t# )ÚRandomPerspective3Da(  Warp 3D volumes with a random perspective transform, applied per sample with probability ``p`` (default 0.5).

``output = RandomPerspective3D(distortion_scale, ...)(input)`` projectively warps volumes of shape
``(B, C, D, H, W)``.

Args:
    p: probability of applying the transformation to each sample.
    distortion_scale: it controls the degree of distortion and ranges from 0 to 1.
    resample: resample mode from "nearest" (0) or "bilinear" (1).
    same_on_batch: apply the same transformation across the batch.
    align_corners: interpolation flag.
    keepdim: whether to keep the output shape the same as input (True) or broadcast it
      to the batch form (False).

Shape:
    - Input: ``(C, D, H, W)`` or ``(B, C, D, H, W)``
    - Output: ``(B, C, D, H, W)``

Note:
    Input torch.Tensor must be float and normalized into [0, 1] for the best differentiability support.

Convention:
    See :class:`~kornia.augmentation.GeometricAugmentationBase3D` for the shared 3D geometry contract.

    - ``distortion_scale=0`` generates identical source and destination corners. The default bilinear,
      ``align_corners=False`` perspective warp nevertheless does not reproduce its input, even a constant one;
      use ``align_corners=True`` for an identity warp up to floating-point roundoff in ``float32`` and
      ``float64``. The false-setting normalization defect is tracked in
      `#4503 <https://github.com/kornia/kornia/issues/4503>`_.
    - the default interpolation is bilinear and the default ``align_corners`` is ``False``.
    - a spatial dimension of 1 gets a unit source extent and no corner offset, so its single
      slice, row or column maps onto itself. At ``distortion_scale=0`` the transform matrix is
      the identity; output identity still requires ``align_corners=True`` as described above.

See Also:
    - :class:`RandomAffine3D`: samples an affine rather than projective warp.
    - :class:`RandomPerspective`: warps 2D images from sampled perspective endpoints.

Examples:
    >>> import torch
    >>> rng = torch.manual_seed(0)
    >>> inputs= torch.tensor([[[
    ...    [[1., 0., 0.],
    ...     [0., 1., 0.],
    ...     [0., 0., 1.]],
    ...    [[1., 0., 0.],
    ...     [0., 1., 0.],
    ...     [0., 0., 1.]],
    ...    [[1., 0., 0.],
    ...     [0., 1., 0.],
    ...     [0., 0., 1.]]
    ... ]]])
    >>> aug = RandomPerspective3D(0.5, p=1., align_corners=True)
    >>> aug(inputs)
    tensor([[[[[0.3976, 0.2651, 0.0000],
               [0.5507, 0.4657, 0.1153],
               [0.0000, 0.0000, 0.0000]],
    <BLANKLINE>
              [[0.0901, 0.1390, 0.0000],
               [0.3668, 0.5174, 0.0000],
               [0.0000, 0.0000, 0.0000]],
    <BLANKLINE>
              [[0.0000, 0.0000, 0.0000],
               [0.0000, 0.0000, 0.0000],
               [0.0000, 0.0000, 0.0000]]]]])

To apply the exact augmenation again, you may take the advantage of the previous parameter state:
    >>> input = torch.rand(1, 3, 32, 32, 32)
    >>> aug = RandomPerspective3D(0.5, p=1.)
    >>> (aug(input) == aug(input, params=aug._params)).all()
    tensor(True)

g      à?Fc                ó†   <€ V ^8„  d   QhRS[ S[P                  S[3,          RS[ S[S[S[3,          RS[RS[RS[RS[RR/# )	é   Údistortion_scaleÚresampleÚsame_on_batchÚalign_cornersÚpÚkeepdimÚreturnN)r   ÚtorchÚTensorÚfloatÚstrÚintr
   Úbool)ÚformatÚ__classdict__s   "€ÚiC:\Ai_Coding\apps\studio\ComfyUI\.venv\Lib\site-packages\kornia\augmentation\_3d\geometric\perspective.pyÚ__annotate__Ú RandomPerspective3D.__annotate__i   st   ø€ ÷ Lñ Lá¡§¡©eÐ 3Õ4ðLñ ™™S¡(Ð*Õ+ðLñ ð	Lñ
 ðLñ ðLñ ðLð 
ñLó    c                óž   <€ \         SV `  WSVR 7       R\        P                  ! V4      RV/V n        \
        P                  ! V4      V n        R# ))r   r   r   r   r   N)ÚsuperÚ__init__r
   ÚgetÚflagsÚrgÚPerspectiveGenerator3DÚ_param_generator)Úselfr   r   r   r   r   r   Ú	__class__s   &&&&&&&€r!   r'   ÚRandomPerspective3D.__init__i   sD   ø€ ô 	‰Ñ˜1À7ÐÔKØ ¤(§,¢,¨xÓ"8¸/È=ÐYˆŒ
Ü "× 9Ò 9Ð:JÓ KˆÖr$   c                óš   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[ P                  /# )r   ÚinputÚparamsr)   r   )r   r   r   r   r   )r   r    s   "€r!   r"   r#   v   sT   ø€ ÷ xñ xÙ—\‘\ðxÙ+/±±U·\±\Ð0AÕ+BðxÙKOÑPSÑUXÐPXÍ>ðxá	�‰ñxr$   c           
     ó  € VR ,          VR,          rTVP                   R,          VP                   R,          rv\        V\        P                  4      '       dË   VP                  p\        P
                  ! \        P                  ! WxR7      ^8„  \        . ROV\        P                  R7      \        . ROV\        P                  R7      4      p	\        P
                  ! VP                  V4      ^8H  V	\        P                  ! ^VR7      4      p
VRV
3,          VRV
3,          rTMA\        V\        4      '       d,   V^8X  d%   V^8”  d   . ROM. ROp
VRV
3,          VRV
3,          rT\        \        WE4      VP                  VP                  4      # )	Ústart_pointsÚ
end_points)Údevice)r6   Údtype:NNNéÿÿÿÿéýÿÿÿ)r   é   é   é   é   é   é   r   )r   r<   r   r=   r:   r;   r?   r>   )ÚshapeÚ
isinstancer   r   r6   ÚwhereÚ	as_tensorr	   ÚlongÚtoÚaranger   r   r   r7   )r-   r1   r2   r)   r4   r5   ÚwidthÚdepthr6   Úsingleton_orderÚorders   &&&&       r!   Úcompute_transformationÚ*RandomPerspective3D.compute_transformationv   s7  € ð $*¨.Õ#9¸6À,Õ;O�jØ—{‘{ 2•¨¯©°B­ˆuô �eœUŸ\™\×*Ò*à!×(Ñ(ˆFÜ#ŸkškÜ—’ Ô5¸Ñ9Ü Ò!9À&ÔPU×PZÑPZÔ[Ü Ò!9À&ÔPU×PZÑPZÔ[óˆOô
 —K’K §¡¨Ó 0°AÑ 5°ÌÏÊÐUVÐ_eÔHfÓgˆEØ'3°A°u°HÕ'=¸zÈ!ÈUÈ(Õ?S™*Ü˜œs×#Ò#¨°¬
Ø05¸´	Ó,Ò?WˆEØ'3°A°u°HÕ'=¸zÈ!ÈUÈ(Õ?S˜*Ü%Ô&AÀ,Ó&[Ð]b×]iÑ]iÐkp×kvÑkvÓwÐwr$   c          
      óÄ   <€ V ^8„  d   QhRS[ P                  RS[S[S[ P                  3,          RS[S[S[3,          RS[S[ P                  ,          RS[ P                  /# )r   r1   r2   r)   Ú	transformr   )r   r   r   r   r   r   )r   r    s   "€r!   r"   r#   Œ   sd   ø€ ÷ 
ñ 
á�|‰|ð
ñ ‘S™%Ÿ,™,Ð&Õ'ð
ñ ‘C™�H�~ð	
ñ
 ™EŸL™LÕ)ð
ñ 
�‰ñ
r$   c                óH  € \        V\        P                  4      '       g   \        R \	        V4       24      h\        VVVP                  R,          VP                  R,          VP                  R,          3VR,          P                  P                  4       VR,          R7      # )z1Expected the transform to be a torch.Tensor. Got r   r   )r)   r   r9   éþÿÿÿr8   )	rA   r   r   Ú	TypeErrorÚtyper   r@   ÚnameÚlower)r-   r1   r2   r)   rN   s   &&&&&r!   Úapply_transformÚ#RandomPerspective3D.apply_transformŒ   s„   € ô ˜)¤U§\¡\×2Ò2ÜÐOÔPTÐU^ÓP_ÐO`ÐaÓbÐbä!ØØØ�[‰[˜�_˜eŸk™k¨"�o¨u¯{©{¸2­Ð?Ø˜
Õ#×(Ñ(×.Ñ.Ó0Ø Õ0ô
ð 	
r$   )r,   r)   )N)Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__r
   ÚBILINEARrS   r'   rK   rU   Ú__static_attributes__Ú__classdictcell__Ú__classcell__)r.   r    s   @@r!   r   r      sS   ù‡ € ñHðX 8;Ø.6×.?Ñ.?×.DÑ.DØ#Ø#ØØ÷Lõ L÷xð x÷,
÷ 
ò 
r$   r   )Útypingr   r   r   r   r   Úkornia.augmentationr   r*   Ú&kornia.augmentation._3d.geometric.baser   Ú!kornia.augmentation.utils.helpersr	   Úkornia.constantsr
   Úkornia.core.utilsr   Úkornia.geometryr   r   r   © r$   r!   Ú<module>rh      s1   ð÷$ .Ó -ã å 6Ý NÝ >Ý %Ý 4ß Kô~
Ð5ö ~
r$   