Ë
    :vž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      úi/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/voxel/morphology.pyÚ_denser      sQ   € Ü�(œBŸJ™JÔ'Ø‰Ü	�HœcŸl™lÔ	+Ø—‘‰äÐHÈÈÐUÓVÐVÙÜ�U˜DÔ!Ø€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   € Ü�(œBŸJ™JÔ'Ø!‰Ü	�HœcŸl™lÔ	+Ø!×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ÒÜÐ9¸4ÄÀ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ÒÜÐDÀUÇ[Á[ÀOÐTÓUÐUØÐØ�;‰;�r‰?˜dÒ"ÜØ<¸dÀEÇKÁKÐPRÁOóð ð #ð 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&   € ô ×#Ñ#¤C§M¡M´/À(ÐQRÔ2SÓ$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Ñ2´6¸(ÈÔ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   € ô  ×ÑÜ×!Ñ!¤&¨¸Ô":ÑE¸fÑ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Ñ7 HÐ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Ñ4´V¸HÈ1Ô5MÑXÐQWÑ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Ñ3´F¸8È!Ô4LÑWÐPVÑ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ä�F‰F�5œ"Ÿ'™' &´Ô4¸:ÔF€EÜ�N‰N˜5Ó!€EÜ×%Ñ% e°yÔA€GÜ�n‰n˜U GÓ,¨Q¨r¨T°1°R°4¸¸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