Ë
    :vžjµ%  ã                   óÐ  — d dl 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mZmZmZ ddlmZ dd	lmZ e		 dd
ededz  dedej$                  fd„«       Z	 dded
edededej$                  dz  f
d„Ze		 dd
ededz  dej$                  fd„«       Ze		 	 	 dd
edz  dedz  dedz  dej$                  fd„«       Z ej0                  eee¬«      Z	 dd
edz  dedej$                  dz  fd„Zy) é    Né   )ÚgroupingÚremeshÚutil)Útransformations)Úlog_time)Ú	ArrayLikeÚIntegerÚNumberÚVoxelizationMethodsTypeé   )Úbase)ÚencodingÚpitchÚmax_iterÚedge_factorÚreturnc           
      ó  — ||z  }|€¬t         j                  j                  | j                  | j                  dd…df      | j                  | j                  dd…df      z
  d¬«      j                  «       }t        t        t        j                  t        j                  ||z  «      «      «      d«      }t        j                  | j                  | j                  ||d¬«      \  }}}t        j                  ||z  «      j                  t        «      }	t        j                  |	«      \  }
}|	|
   }|j!                  d¬«      }||z  }t#        j$                  t'        j(                  ||z
  «      t+        j,                  ||¬«      ¬«      S )	aÄ  
    Voxelize a surface by subdividing a mesh until every edge is
    shorter than: (pitch / edge_factor)

    Parameters
    -----------
    mesh : trimesh.Trimesh
      Source mesh
    pitch
      Side length of a single voxel cube
    max_iter
      Cap maximum subdivisions or None for no limit.
    edge_factor
      Proportion of pitch maximum edge length.

    Returns
    -----------
    VoxelGrid instance representing the voxelized mesh.
    Nr   r   ©ÚaxisT)Úmax_edger   Úreturn_index©ÚscaleÚ	translate)Ú	transform)ÚnpÚlinalgÚnormÚverticesÚedgesÚmaxÚintÚceilÚlog2r   Úsubdivide_to_sizeÚfacesÚroundÚastyper   Úunique_rowsÚminr   Ú	VoxelGridÚencÚSparseBinaryEncodingÚtrÚscale_and_translate)Úmeshr   r   r   r   Úlongest_edgeÚvÚ_fÚ_idxÚhitÚuniqueÚ_inverseÚoccupied_indexÚorigin_indexÚorigin_positions                  úg/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/voxel/creation.pyÚvoxelize_subdivider=      sT  € ð. �{Ñ"€HàÐÜ—y‘y—~‘~Ø�M‰M˜$Ÿ*™*¢Q¨ TÑ*Ñ+¨d¯m©m¸D¿J¹JÂqÈ!ÀtÑ<LÑ.MÑMÐTUð &ó 
ç
‰#‹%ð 	ô ”sœ2Ÿ7™7¤2§7¡7¨<¸(Ñ+BÓ#CÓDÓEÀqÓIˆô ×*Ñ*Ø�‰�t—z‘z¨H¸xÐVZô�K€A€rˆ4ô �(‰(�1�u‘9Ó
×
$Ñ
$¤SÓ
)€Cô  ×+Ñ+¨CÓ0Ñ€FˆHð ˜‘[€Nà!×%Ñ%¨1Ð%Ó-€LØ" UÑ*€Oä�>‰>Ü× Ñ  °,Ñ!>Ó?Ü×(Ñ(¨uÀÔPôð ó    ÚpointÚradiusÚfillc                 óœ  — ddl m} t        j                  |t        j                  ¬«      j                  d«      }t        |t        «      st        d«      ‚t        j                  ||dz   |z  z
  ||dz   |z  z   f«      }t        | j                  j                  |«      «      }t        |«      dk(  ry| j                  |D �	cg c]  }	|	g‘Œ c}	d¬	«      }
|
j                  | «       t!        |
|fi |¤Ž}|j"                  dd…df   }|j$                  j&                  }t        j(                  | |z  «      j+                  t        j,                  «      }t        j.                  ||z
  d«      }t        j.                  ||z   d
z   |j0                  z
  d«      }t        j2                  |t        j4                  ||fd¬«      d¬«      }||z  }||d   |z
  |d   |z   d
z   …|d
   |z
  |d
   |z   d
z   …|d   |z
  |d   |z   d
z   …f   }|||z  z
  }|�r|j7                  | «      \  }}|j9                  | «      }t;        d
|d
z   «      D �cg c]6  }t        j<                  |||k(  z  j?                  «       |j0                  «      ‘Œ8 }}| jA                  t        jB                  |«      |z  |z   «      }t        jD                  |«      d   d
z   }t        jF                  |jI                  «       |«      j                  |j0                  «      }t        jJ                  ||«      }tM        jN                  |tQ        jR                  |«      «      S c c}	w c c}w )að  
    Voxelize a mesh in the region of a cube around a point. When fill=True,
    uses proximity.contains to fill the resulting voxels so may be meaningless
    for non-watertight meshes. Useful to reduce memory cost for small values of
    pitch as opposed to global voxelization.

    Parameters
    -----------
    mesh : trimesh.Trimesh
      Source geometry
    point : (3, ) float
      Point in space to voxelize around
    pitch
      Side length of a single voxel cube
    radius
      Number of voxel cubes to return in each direction.
    kwargs
      Parameters to pass to voxelize_subdivide

    Returns
    -----------
    voxels : VoxelGrid instance with resolution (m, m, m) where m=2*radius+1
        or None if the volume is empty
    r   )Úndimage©Údtypeé   z.radius needs to be an integer number of cubes!g      à?NT)Úappendr   éÿÿÿÿr   Úconstant)Úmoder   )*ÚscipyrC   r   Ú
asanyarrayÚfloat64ÚreshapeÚ
isinstancer#   Ú
ValueErrorÚconcatenateÚlistÚtriangles_treeÚintersectionÚlenÚsubmeshÚapply_translationr=   r   r   Údenser(   r)   Úint64ÚmaximumÚshapeÚpadÚstackÚlabelÚdistance_transform_cdtÚrangeÚunravel_indexÚargmaxÚcontainsÚasarrayÚwhereÚisinÚflattenÚ
logical_orr   r,   r/   Útranslation_matrix)r1   r?   r   r@   rA   ÚkwargsrC   Úboundsr'   ÚfÚlocalÚvoxÚoriginÚmatrixÚcenterÚprepadÚpostpadÚvoxelsÚlocal_originÚregionsÚnÚdistanceÚiÚrepresentativesrc   re   Úinternals                              r<   Úlocal_voxelizer|   D   s)  € õ@ ô �M‰M˜%¤r§z¡zÔ2×:Ñ:¸1Ó=€Eô �fœcÔ"ÜÐIÓJÐJô �^‰^Ø	�&˜3‘, %Ñ'Ñ	'¨°&¸3±,À%Ñ1GÑ)GÐHó€Fô
 �×$Ñ$×1Ñ1°&Ó9Ó:€Eô ˆ5ƒz�Q‚Øà�L‰L¡uÓ-¡u !˜1š# uÑ-°dˆLÓ;€Eð 
×Ñ˜U˜FÔ#ô ˜U EÑ
4¨VÑ
4€CØ�]‰]˜2˜A˜2˜q˜5Ñ!€FØ�\‰\×Ñ€Fô �X‰X�v�g ‘oÓ&×-Ñ-¬b¯h©hÓ7€Fô �Z‰Z˜ ™¨Ó+€FÜ�j‰j˜ &™¨1Ñ,¨v¯|©|Ñ;¸QÓ?€Gä�V‰V�FœBŸH™H f¨gÐ%6¸RÔ@ÀzÔR€FØ
ˆfÑ€Fð Øˆq‰	�FÑ˜V A™Y¨Ñ/°!Ñ3Ð3Øˆq‰	�FÑ˜V A™Y¨Ñ/°!Ñ3Ð3Øˆq‰	�FÑ˜V A™Y¨Ñ/°!Ñ3Ð3ð	5ñ€Fð
 ˜6 E™>Ñ)€Lò Ø—]‘] F 7Ó+‰
ˆ�Ø×1Ñ1°6°'Ó:ˆô ˜1˜a !™e”_ó
á$�ô ×Ñ˜h¨'°Q©,Ñ7×?Ñ?ÓAÀ8Ç>Á>ÕRØ$ð 	ð 
ð —=‘=¤§¡¨OÓ!<¸uÑ!DÀ|Ñ!SÓTˆÜ—‘˜Ó" 1Ñ%¨Ñ)ˆÜ—7‘7˜7Ÿ?™?Ó,¨eÓ4×<Ñ<¸W¿]¹]ÓKˆÜ—‘˜v xÓ0ˆä�>‰>˜&¤"×"7Ñ"7¸Ó"EÓFÐFùòS .ùò@
s   Ã
MÉ;M	Úper_cellc                 ó¼  — |€(t        j                  ddgt         j                  ¬«      }n4t        j                  |t         j                  ¬«      j                  d«      }t	        |«      }| j
                  dd…dd…f   j                  «       }|dxx   |d|z   z  z  cc<   |dxx   |z  cc<   ||z  }t        j                  ||¬«      }t        j                  t        |«      «      | j
                  d   d   |z
  z  }t        j                  ||f«      }t        j                  |«      g d¢z  }| j                  j                  ||«      d   }t        j                  ||z  «      j!                  t         j                  «      }	|	j#                  d¬	«      }
|	|
z  }	t%        j&                  |	«      }|
|z  }t)        j*                  |t-        j.                  ||¬
«      «      S )a=  
    Voxelize a mesh using ray queries.

    Parameters
    -------------
    mesh
      Mesh to be voxelized
    pitch
      Length of voxel cube
    per_cell : (2,) int
      How many ray queries to make per cell

    Returns
    -------------
    grid
      VoxelGrid instance representing the voxelized mesh.
    Nr   rD   r   g      ð?r   )Ústep)r   r   r   r   r   )r   ÚarrayrY   rN   Úfloatrk   Úcopyr   Úgrid_arangeÚonesrU   Úcolumn_stackÚ	ones_likeÚrayÚintersects_locationr(   r)   r+   r-   r.   r   r,   r/   r0   )r1   r   r}   rk   r   Úray_oriÚzÚray_dirÚhitsrt   r:   r   r;   s                r<   Úvoxelize_rayr�   ¥   s•  € ð* Ðä—8‘8˜Q ˜F¬"¯(©(Ô3‰ä—8‘8˜H¬B¯H©HÔ5×=Ñ=¸aÓ@ˆô �%‹L€Eð �[‰[š˜B˜Q˜B˜Ñ×$Ñ$Ó&€Fà
ˆ1ƒI�˜# ™.Ñ)Ñ)ƒIà
ˆ1ƒI�ÑƒIà�8Ñ€Dä×Ñ˜v¨DÔ1€Gä
�‰”�G“Ó §¡¨Q¡°Ñ!2°UÑ!:Ñ;€AÜ�o‰o˜w¨˜lÓ+€Gä�l‰l˜7Ó#¢iÑ/€Gð �8‰8×'Ñ'¨°Ó9¸!Ñ<€Dô �X‰X�d˜U‘lÓ#×*Ñ*¬2¯8©8Ó4€Fð —:‘: 1�:Ó%€LØ
ˆlÑ€FÜ×'Ñ'¨Ó/€HØ" UÑ*€OÜ�>‰>Ø”"×(Ñ(¨uÀÔPóð r>   Ú	dimensionrk   c                 óf  — ddl m} |€M|€| j                  }n
|\  }}||z
  }t        t	        j
                  t	        j                  |«      |z  «      «      }|�5d|v rt        d«      ‚t	        j                  |«      j                  «       |d<    |j                  dd|i|¤Ž}	|j                  | |	«      S )a"  
    Voxelize via binvox tool.

    Parameters
    --------------
    mesh : trimesh.Trimesh
      Mesh to voxelize
    pitch : float
      Side length of each voxel. Ignored if dimension is provided
    dimension: int
      Number of voxels along each dimension. If not provided, this is
        calculated based on pitch and bounds/mesh extents
    bounds: (2, 3) float
      min/max values of the returned `VoxelGrid` in each instance. Uses
      `mesh.bounds` if not provided.
    **binvoxer_kwargs:
      Passed to `trimesh.exchange.binvox.Binvoxer`.
      Should not contain `bounding_box` if bounds is not None.

    Returns
    --------------
    grid
      `VoxelGrid` instance

    Raises
    --------------
    `ValueError` if `bounds is not None and 'bounding_box' in binvoxer_kwargs`.
    r   )ÚbinvoxÚbounding_boxz+Cannot provide both bounds and bounding_boxrŽ   © )Útrimesh.exchanger�   Úextentsr#   r   r$   r"   rP   rL   rg   ÚBinvoxerÚvoxelize_mesh)
r1   r   rŽ   rk   Úbinvoxer_kwargsr�   r”   ÚminsÚmaxsÚbinvoxers
             r<   Úvoxelize_binvoxr›   ã   s¯   € õH (àÐàˆ>Ø—l‘l‰Gà‰JˆD�$Ø˜T‘kˆGÜœŸ™¤§¡ w£°%Ñ 7Ó8Ó9ˆ	ØÐØ˜_Ñ,ÜÐJÓKÐKÜ*,¯-©-¸Ó*?×*GÑ*GÓ*Iˆ˜Ñ'àˆv�‰ÑF¨ÐF°oÑF€HØ×Ñ  hÓ/Ð/r>   )r‡   Ú	subdivider�   Úmethodc                 ó    — t        |f| |dœ|¤ŽS )a_  
    Voxelize the given mesh using the specified implementation.

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

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

    Parameters
    --------------
    mesh
      Geometry to voxelize
    pitch
      Side length of each voxel.
    method
      Which voxelization method to use.
    kwargs
      Passed through to the specified implementation.

    Returns
    --------------
    grid
      A VoxelGrid instance.
    )r1   r   )Ú
voxelizers)r1   r   r�   rj   s       r<   Úvoxelizer      s   € ô> �fÐ? 4¨uÑ?¸Ñ?Ð?r>   )é
   g       @)T)N)NNN)rœ   )Únumpyr   Ú r   r   r   r   r/   Ú	constantsr   Útypedr	   r
   r   r   r   r   r-   r,   r=   Úboolr|   r�   r›   ÚFunctionRegistryrŸ   r    r’   r>   r<   Ú<module>r¨      s“  ðÛ ç %Ñ %Ý $Ý  ß GÓ GÝ Ý ð 
àNQñ5Øð5Ø#*¨T¡>ð5ØEKð5à	‡^�^ò5ó 
ð5ðz ñ^Gàð^Gð ð^Gð ð	^Gð
 ð^Gð 
‡^�^�dÑó^GðB 
à6:ñ:Øð:Ø#,¨tÑ#3ð:à	‡^�^ò:ó 
ð:ðz 
ð  Ø $Ø#ñ	30à�D‰=ð30ð ˜‰~ð30ð ˜Ñð	30ð 
‡^�^ò30ó 
ð30ðl #ˆT×"Ñ"ØÐ 2¸?ô€
ð '2ñ@à�D‰=ð@ð $ð@ð
 
‡^�^�dÑô@r>   