
    jO                     "   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 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y# e$ rZdd
lmZ  ee      ZY dZ[cdZ[ww xY w)z6Basic morphology operations that create new encodings.    N   )util)log_time   encoding)ops)ndimage)ExceptionWrapperc                     t        | t        j                        r| }n5t        | 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      E/DATA/.local/lib/python3.12/site-packages/trimesh/voxel/morphology.py_denser      sQ    (BJJ'	Hcll	+HUVVUD!L    c                     t        | t        j                        r| }n5t        | 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      sQ    (BJJ'!	Hcll	+!00HUVV*r   c                 t    t        | j                        |k7  r t        d|t        | j                              y )NzExpected rank %d, got shape %s)lenshaper   strvaluer   s     r   r   r   +   s1    
5;;494U[[AQRR  r   c                     t        | j                        dk7  rt        d| j                        |-| j                  d   |k7  rt        d|| j                  d         y y )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   sg    
5;;1DU[[OTUU;;r?d"<dEKKPRO  # r   c                 h    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&     ##CMM/(QR2S$TUUr   c                 h    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226(3KLMMr   c                 j    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   ^   s1      !!&":EfE r   )baseorthographicholesc                     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7H777r   c                 j    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;      s-     W44VH15MXQWXYYr   c                 j    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=      s-     W33F8!4LWPVWXXr   c                 D   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FF5"''&4:FENN5!E%%eyAGnnUG,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    <      "		S
 
V 
V 
N 
N& 
 
(  $

	"
8.ZY&o  "-q!G	"s   A1 1B6B		B