
    Ti                     P    d dl ZddlmZmZ ddlmZ ddlmZ  G d d          Z	dS )    N   )cachingutil)transformations)Optionalc                   L   e Zd ZdZddeej                 fdZd Ze	d             Z
e	d             Zej        d             Zej        d	             Zej        d
             Zej        d             Zd Zd Zd Zd Zd Zej        d             Zd Zej        d             ZdS )	Transformz
    Class for caching metadata associated with 4x4 transformations.

    The transformation matrix is used to define relevant properties
    for the voxels, including pitch and origin.
    N	datastorec                    t          j        |t           j                  }|j        dk    s!t          j        |dddf         g d          st          d          |t          j                    | _        nAt          |t          j                  r|| _        nt          t          |           d          || j        d<   t          j        | j        j        	          | _        dS )
a  
        Initialize with a transform.

        Parameters
        -----------
        matrix : (4, 4) float
          Homogeneous transformation matrix
        datastore
          If passed store the actual values in a reference to
          another datastore.
        dtype   r      N)r   r   r      zmatrix is invalid!z != caching.DataStoretransform_matrix)id_function)np
asanyarrayfloat64shapeallclose
ValueErrorr   	DataStore_data
isinstancetypeCache__hash___cache)selfmatrixr
   s      R/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/voxel/transforms.py__init__zTransform.__init__   s     vRZ888<6!!VAqqqD\<<<)P)P!1222  *,,DJJ	7#455 	H"DJJYFFFGGG)/
%&m
0CDDD    c                 4    | j                                         S )z
        Get the hash of the current transformation matrix.

        Returns
        ------------
        hash : str
          Hash of transformation matrix
        )r   r   r!   s    r#   r   zTransform.__hash__,   s     z""$$$r%   c                 0    | j         d         dddf         S )z
        Get the translation component of the matrix

        Returns
        ------------
        translation : (3,) float
          Cartesian translation
        r   Nr   r   r'   s    r#   translationzTransform.translation7   s     z,-bqb!e44r%   c                     | j         d         S )z
        Get the homogeneous transformation matrix.

        Returns
        -------------
        matrix : (4, 4) float
          Transformation matrix
        r   r)   r'   s    r#   r"   zTransform.matrixC   s     z,--r%   c                     t          j        |t           j                  }|j        dk    rt	          d          || j        d<   dS )z
        Set the homogeneous transformation matrix.

        Parameters
        -------------
        matrix : (4, 4) float
          Transformation matrix
        r   r   zmatrix must be (4, 4)!r   N)r   r   r   r   r   r   )r!   valuess     r#   r"   zTransform.matrixO   sI     vRZ888<6!!5666)/
%&&&r%   c                     | j         }t          j        |ddddf                   }t          j        |ddddf         |t          j        d          z  |dz  dz             st          d          |S )z
        Get the scale factor of the current transformation.

        Returns
        -------------
        scale : (3,) float
          Scale factor from the matrix
        Nr   ư>:0yE>z&transform features a shear or rotation)r"   r   diagr   eyeRuntimeError)r!   r"   scales      r#   r4   zTransform.scale^   s{     rr2A2v''{6"1"bqb&>526!99+<edlT>QRR 	IGHHHr%   c           	          | j         }t          j        |d         |dd          t          j        t          j        |                    dz  dz             st          d          |S )Nr   r   r/   r0   z&transform features non-uniform scaling)r4   r   r   r   maxabsr3   r!   r4   s     r#   pitchzTransform.pitchp   s]    
}U1XuQRRy"&2G2G$2NQU2UVV 	IGHHHr%   c                 n    t           j                            | j        d         ddddf                   S )z"Volume of a transformed unit cube.r   Nr   )r   linalgdetr   r'   s    r#   unit_volumezTransform.unit_volumew   s1     y}}TZ(:;BQBFCDDDr%   c                 D    t          j        || j                  | _        | S ).Mutate the transform in-place and return self.)r   matmulr"   )r!   r"   s     r#   apply_transformzTransform.apply_transform|   s    i44r%   c                 8    | j         dddfxx         |z  cc<   | S r?   Nr   r"   )r!   r*   s     r#   apply_translationzTransform.apply_translation   s-    BQBEk)r%   c                 4    | j         ddxx         |z  cc<   | S rC   rD   r8   s     r#   apply_scalezTransform.apply_scale   s#    BQB5 r%   c                     | j         r|                                S t          j        |                    dd          | j                                      |j                  S )a  
        Apply the transformation to points (not in-place).

        Parameters
        ----------
        points: (n, 3) float
          Points in cartesian space

        Returns
        ----------
        transformed : (n, 3) float
          Points transformed by matrix
        r   )is_identitycopytrtransform_pointsreshaper"   r   r!   pointss     r#   rM   zTransform.transform_points   sW      	!;;== "6>>"a#8#8$+FFNNL
 
 	
r%   c                     | j         r|S t          j        |                    dd          | j                                      |j                  S )z:Apply the inverse transformation to points (not in-place).rI   r   )rJ   rL   rM   rN   inverse_matrixr   rO   s     r#   inverse_transform_pointsz"Transform.inverse_transform_points   sM     	M"6>>"a#8#8$:MNNVVL
 
 	
r%   c                 f    t           j                            | j                  }d|j        _        |S )NF)r   r;   invr"   flags	writeable)r!   rU   s     r#   rR   zTransform.inverse_matrix   s&    immDK((#	
r%   c                 ,    t          | j                  S )NrD   )r	   r"   r'   s    r#   rK   zTransform.copy   s    ,,,,r%   c                 \    t          j        | j        t          j        d          d          S )zO
        Flags this transformation being sufficiently close to eye(4).
        r   r0   )r   r   r"   r   r2   r'   s    r#   rJ   zTransform.is_identity   s"    
 }T["&))T:::r%   )N)__name__
__module____qualname____doc__r   r   r   r$   r   propertyr*   r"   settercache_decoratorr4   r9   r=   rA   rE   rG   rM   rS   rR   rK   rJ    r%   r#   r	   r	      s        E E(73D*E E E E E8	% 	% 	% 	5 	5 X	5 	. 	. X	. ]0 0 ]0   "    E E E  
  
  

 
 
(
 
 
   
- - - ; ; ; ; ;r%   r	   )
numpyr    r   r   r   rL   typedr   r	   ra   r%   r#   <module>re      s                $ $ $ $ $ $      m; m; m; m; m; m; m; m; m; m;r%   