o
    oi                     @   s   d dl mZmZmZ d dlmZmZmZ d dlZd dl	m
Z
 d dlmZmZmZ d dlmZ d dlmZ d dlmZ G d	d
 d
e
ZG dd deZdS )    )AnyDictOptional)float16float32float64N)_AugmentationBase)_transform_input3d_transform_input3d_by_shape_validate_input_dtype)Tensor)Boxes3D)Keypoints3Dc                	   @   sZ   e Zd ZdZdeddfddZdddded	ee d
edefddZdedefddZ	dS )AugmentationBase3Da  AugmentationBase3D base class for customized augmentation implementations.

    Args:
        p: probability for applying an augmentation. This param controls the augmentation probabilities
          element-wise for a batch.
        p_batch: probability for applying an augmentation to a batch. This param controls the augmentation
          probabilities batch-wise.
        same_on_batch: apply the same transformation across the batch.

    inputreturnNc                 C   s6   t |tttgd t|jdkrtd|j ddS )z3Check if the input tensor is formatted as expected.accepted_dtypes   zExpect (B, C, D, H, W). Got .N)r   r   r   r   lenshapeRuntimeErrorselfr    r   P/home/ubuntu/.local/lib/python3.10/site-packages/kornia/augmentation/_3d/base.pyvalidate_tensor*   s   z"AugmentationBase3D.validate_tensorT)r   match_channelr   r   c                C   s0   t |tttgd |du rt|S t|||dS )zVConvert any incoming (D, H, W), (C, D, H, W) and (B, C, D, H, W) into (B, C, D, H, W).r   N)reference_shaper   )r   r   r   r   r	   r
   )r   r   r   r   r   r   r   transform_tensor0   s   z#AugmentationBase3D.transform_tensorc                 C   s   t d|S )zReturn 4x4 identity matrix.   )korniaeye_liker   r   r   r   identity_matrix8   s   z"AugmentationBase3D.identity_matrix)
__name__
__module____qualname____doc__r   r   r   boolr    r$   r   r   r   r   r      s
    &r   c                   @   s  e Zd ZU dZee ed< edee fddZdede	e
ef de	e
ef defd	d
Zdede	e
ef de	e
ef defddZ	ddede	e
ef de	e
ef dee def
ddZ	ddede	e
ef de	e
ef dee def
ddZ	ddede	e
ef de	e
ef dee def
ddZ	ddede	e
ef de	e
ef dee def
ddZ	ddede	e
ef de	e
ef dee def
ddZ	ddede	e
ef dee	e
ef  defddZdS )RigidAffineAugmentationBase3Da  AugmentationBase2D base class for rigid/affine augmentation implementations.

    RigidAffineAugmentationBase2D enables routined transformation with given transformation matrices
    for different data types like masks, boxes, and keypoints.

    Args:
        p: probability for applying an augmentation. This param controls the augmentation probabilities
          element-wise for a batch.
        p_batch: probability for applying an augmentation to a batch. This param controls the augmentation
          probabilities batch-wise.
        same_on_batch: apply the same transformation across the batch.
        keepdim: whether to keep the output shape the same as input ``True`` or broadcast it to the batch
          form ``False``.

    _transform_matrixr   c                 C   s   | j S N)r+   )r   r   r   r   transform_matrixP   s   z.RigidAffineAugmentationBase3D.transform_matrixr   paramsflagsc                 C      t r,   NotImplementedError)r   r   r.   r/   r   r   r   compute_transformationT   s   z4RigidAffineAugmentationBase3D.compute_transformationc                 C   sx   |d }|dk}|  |}| s| |}|S | r&| j|||d}|S | |}||f| j|| ||d}|S )zIGenerate transformation matrices with the given input and param settings.
batch_probg      ?)r.   r/   )r    anyr$   allr3   	index_put)r   r   r.   r/   r4   to_apply	in_tensortrans_matrixr   r   r   generate_transformation_matrixW   s   


z<RigidAffineAugmentationBase3D.generate_transformation_matrixN	transformc                 C   r0   r,   r1   r   r   r.   r/   r<   r   r   r   inverse_inputsg      z,RigidAffineAugmentationBase3D.inverse_inputsc                 C   r0   r,   r1   r=   r   r   r   inverse_masksl   r?   z+RigidAffineAugmentationBase3D.inverse_masksc                 C   r0   r,   r1   r=   r   r   r   inverse_boxesq   r?   z+RigidAffineAugmentationBase3D.inverse_boxesc                 C   r0   r,   r1   r=   r   r   r   inverse_keypointsv   r?   z/RigidAffineAugmentationBase3D.inverse_keypointsc                 C   r0   r,   r1   r=   r   r   r   inverse_classes{   r?   z-RigidAffineAugmentationBase3D.inverse_classesr9   c                 C   s6   |d u r| j }| |||}| ||||}|| _|S r,   )r/   r;   transform_inputsr+   )r   r9   r.   r/   r:   outputr   r   r   
apply_func   s   z(RigidAffineAugmentationBase3D.apply_funcr,   )r%   r&   r'   r(   r   r   __annotations__propertyr-   r   strr   r3   r;   r>   r@   r   rA   r   rB   rC   rF   r   r   r   r   r*   =   s   
 **















r*   )typingr   r   r   torchr   r   r   r"   kornia.augmentation.baser   kornia.augmentation.utilsr	   r
   r   kornia.corer   kornia.geometry.boxesr   kornia.geometry.keypointsr   r   r*   r   r   r   r   <module>   s   