
    TiO                     :   d Z ddlZddlmZ ddlmZ ddlmZ ddlm	Z	 	 dd	l
mZ n## e$ rZdd
lmZ  ee          ZY dZ[ndZ[ww xY wddZddZd ZddZed             Zed             Zed             Z ej        eee          ZddZd Zd ZddZdS )z6Basic morphology operations that create new encodings.    N   )util)log_time   encoding)ops)ndimage)ExceptionWrapperc                     t          | t          j                  r| }n4t          | t          j                  r| j        }nt          d|           |rt          ||           |S )N-encoding must be np.ndarray or Encoding, got )
isinstancenpndarrayencEncodingdense
ValueError_assert_rank)r   rankr   s      R/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/voxel/morphology.py_denser      sp    (BJ'' W	Hcl	+	+ WUUUVVV "UD!!!L    c                     t          | t          j                  r| }n4t          | t          j                  r| j        }nt          d|           t          |d           |S )Nr      )r   r   r   r   r   sparse_indicesr   _assert_sparse_rank)r   r   r   s      r   _sparse_indicesr      sj    (BJ'' W!	Hcl	+	+ W!0UUUVVV***r   c                 |    t          | j                  |k    r#t          d|t          | j                            d S )NzExpected rank %d, got shape %s)lenshaper   strvaluer   s     r   r   r   +   s<    
5;494U[AQAQRRR  r   c                     t          | j                  dk    rt          d| j                  |-| j        d         |k    rt          d|| j        d                   d S d S )Nr   z)sparse_indices must be rank 2, got shape z*sparse_indices.shape[1] must be %d, got %d)r    r!   r   r#   s     r   r   r   0   su    
5;1TU[TTUUU;r?d""<dEKPRO   ""r   c                 l    t          j        t          j        t	          | d                              S )z
    Given a sparse surface voxelization, fill in between columns.

    Parameters
    --------------
    encoding: Encoding object or sparse array with shape (?, 3)

    Returns
    --------------
    A new filled encoding object.
    r   r   )r   SparseBinaryEncodingr	   	fill_baser   r   s    r   r*   r*   :   s-     #CM/(QR2S2S2S$T$TUUUr   c                 l    t          j        t          j        t	          | d                              S )a  
    Fill the given encoding by orthographic projection method.

    Any voxel in the dense representation with no free ray along the x, y, z
    axes in each direction is assigned filled. This is likely faster than fill
    holes, and is more stable with regards to small holes.

    Parameters
    --------------
    encoding: Encoding object or dense rank-3 array.

    Returns
    --------------
    A new filled encoding object.
    r   r(   )r   DenseEncodingr	   fill_orthographicr   r   s    r   r-   r-   J   s-    " S26(3K3K3KLLMMMr   c                 h    t          j        t          j        t	          | d          fi |          S )a  
    Encoding wrapper around scipy.ndimage.morphology.binary_fill_holes.

    https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.binary_fill_holes.html#scipy.ndimage.morphology.binary_fill_holes

    Parameters
    --------------
    encoding: Encoding object or dense rank-3 array.
    **kwargs: see scipy.ndimage.morphology.binary_fill_holes.

    Returns
    --------------
    A new filled in encoding object.
    r   r(   )r   r,   r
   binary_fill_holesr   r   kwargss     r   
fill_holesr2   ^   s<      !&":":":EEfEE  r   )baseorthographicholesr3   c                      t          |fd| i|S )a7  
    Fill the given encoding using the specified implementation.

    See `fillers` for available implementations or to add your own, e.g. via
    `fillers['custom_key'] = custom_fn`.

    `custom_fn` should have signature `(encoding, **kwargs) -> filled_encoding`
    and should not modify encoding.

    Parameters
    --------------
    encoding: Encoding object (left unchanged).
    method: method present in `fillers`.
    **kwargs: additional kwargs passed to the specified implementation.

    Returns
    --------------
    A new filled Encoding object.
    r   )fillers)r   methodr1   s      r   fillr9   z   s    ( 677H7777r   c                 h    t          j        t          j        t	          | d          fi |          S )z
    Encoding wrapper around scipy.ndimage.morphology.binary_dilation.

    https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.binary_dilation.html#scipy.ndimage.morphology.binary_dilation
    r   r(   )r   r,   r
   binary_dilationr   r0   s     r   r;   r;      s6     W4VH15M5M5MXXQWXXYYYr   c                 h    t          j        t          j        t	          | d          fi |          S )z
    Encoding wrapper around scipy.ndimage.morphology.binary_closing.

    https://docs.scipy.org/doc/scipy-0.15.1/reference/generated/scipy.ndimage.morphology.binary_closing.html#scipy.ndimage.morphology.binary_closing
    r   r(   )r   r,   r
   binary_closingr   r0   s     r   r=   r=      s6     W3F8!4L4L4LWWPVWWXXXr   c                 H   t          | d          }t          j        |t          j        dt                    d          }t          j        |          }t          j        ||          }t          j        ||          dd	dd	dd	f         }t          j
        |          S )
a\  
    Get elements on the surface of encoding.

    A surface element is any one in encoding that is adjacent to an empty
    voxel.

    Parameters
    --------------
    encoding: Encoding or dense rank-3 array
    structure: adjacency structure. If None, square connectivity is used.

    Returns
    --------------
    new surface Encoding.
    r   r(   )r   r   )dtypeconstant)mode)	structurer   r&   )r   r   padonesintlogical_notr
   r;   logical_andr   r,   )r   rB   r   emptydilatedsurfaces         r   rJ   rJ      s      8!$$$EF5"'&444:FFFEN5!!E%eyAAAGnUG,,QrT1R42-=>GW%%%r   )N)r3   )__doc__numpyr    r   	constantsr   r   r   r	   scipyr
   BaseExceptionE
exceptionsr   r   r   r   r   r*   r-   r2   FunctionRegistryr7   r9   r;   r=   rJ    r   r   <module>rU      s   < <                                  " " " "------q!!GGGGGG	"	 	 	 		 	 	 	S S S
    
V V 
V 
N N 
N& 
  
(  $
	"
  8 8 8 8.Z Z ZY Y Y& & & & & &s   ' AAA