
    Mi%                        S SK rSSKJrJrJr  SSKJr  SSKJ	r	  SSK
JrJrJrJrJr  SSKJr  SS	KJr  \	 SS
\S\\   S\S\R&                  4S jj5       r SS\S
\S\S\S\\R&                     4
S jjr\	 SS
\S\\   S\R&                  4S jj5       r\	   SS
\\   S\\   S\\   S\R&                  4S jj5       r\R2                  " \\\S9r SS
\\   S\S\\R&                     4S jjrg)     N   )groupingremeshutil)transformations)log_time)	ArrayLikeIntegerNumberOptionalVoxelizationMethodsType   )base)encodingpitchmax_iteredge_factorreturnc           
         X-  nUc  [         R                  R                  U R                  U R                  SS2S4      U R                  U R                  SS2S4      -
  SS9R                  5       n[        [        [         R                  " [         R                  " XT-  5      5      5      S5      n[        R                  " U R                  U R                  XBSS9u  pgn[         R                  " Xa-  5      R                  [        5      n	[        R                  " U	5      u  pX   nUR!                  SS9nX-  n["        R$                  " [&        R(                  " X-
  5      [*        R,                  " XS9S9$ )	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                  p/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/voxel/creation.pyvoxelize_subdivider>      s@   . "Hyy~~MM$**QT*+dmmDJJq!t<L.MMTU & 

#% 	 s277277<+B#CDEqI **tzzHVZKA4 ((19

$
$S
)C  ++C0F [N!%%1%-L"*O>>  !>?((uP     pointradiusfillc                    SSK Jn  [        R                  " U[        R                  S9R                  S5      n[        U[        5      (       d  [        S5      e[        R                  " XS-   U-  -
  XS-   U-  -   45      n[        U R                  R                  U5      5      n[        U5      S:X  a  gU R                  U V	s/ s H  o/PM     sn	SS	9n
U
R                  U* 5        [!        X40 UD6nUR"                  SS2S4   nUR$                  R&                  n[        R(                  " U* U-  5      R+                  [        R,                  5      n[        R.                  " X>-
  S5      n[        R.                  " X-   S
-   UR0                  -
  S5      n[        R2                  " U[        R4                  " UU4SS9SS9nX-  nUUS   U-
  US   U-   S
-   2US
   U-
  US
   U-   S
-   2US   U-
  US   U-   S
-   24   nXU-  -
  nU(       Ga  UR7                  U) 5      u  nnUR9                  U) 5      n[;        S
US
-   5       Vs/ s H8  n[        R<                  " UUU:H  -  R?                  5       UR0                  5      PM:     nnU RA                  [        RB                  " U5      U-  U-   5      n[        RD                  " U5      S   S
-   n[        RF                  " URI                  5       U5      R                  UR0                  5      n[        RJ                  " UU5      n[L        RN                  " U[P        RR                  " U5      5      $ s  sn	f s  snf )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   )*scipyrD   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-   r0   translation_matrix)r2   r@   r   rA   rB   kwargsrD   boundsr(   flocalvoxoriginmatrixcenterprepadpostpadvoxelslocal_originregionsndistanceirepresentativesrd   rf   internals                              r=   local_voxelizer}   D   s   @  MM%rzz2::1=E fc""IJJ ^^	3,%'	'3,%1G)GHF
 $$11&9:E 5zQLLu-u!#u-dL;E 
UF# U
4V
4C]]2A2q5!F\\F XXvgo&--bhh7F ZZ+Fjj1,v||;Q?GVVFBHHfg%6R@zRF
F q	FVAY/!33q	FVAY/!33q	FVAY/!33	5F
 E>)L ]]F7+
116': 1a!e_
$ h'Q,7??A8>>R$ 	 
 ==O!<u!D|!ST"1%)777??,e4<<W]]Kvx0>>&""7"7"EFFS .@
s   M?Mper_cellc                    Uc&  [         R                  " SS/[         R                  S9nO2[         R                  " U[         R                  S9R                  S5      n[	        U5      nU R
                  SS2SS24   R                  5       nUS==   USU-   -  -  ss'   US==   U-  ss'   X-  n[        R                  " X4S9n[         R                  " [        U5      5      U R
                  S   S   U-
  -  n[         R                  " XV45      n[         R                  " U5      / SQ-  nU R                  R                  XW5      S   n[         R                  " X-  5      R!                  [         R                  5      n	U	R#                  SS	9n
X-  n	[$        R&                  " U	5      nX-  n[(        R*                  " U[,        R.                  " XS
95      $ )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   rE   r   g      ?r   )step)r   r   r   r   r   )r   arrayrZ   rO   floatrl   copyr   grid_arangeonesrV   column_stack	ones_likerayintersects_locationr)   r*   r,   r.   r/   r   r-   r0   r1   )r2   r   r~   rl   r   ray_orizray_dirhitsru   r;   r   r<   s                r=   voxelize_rayr      s   * 88QF"((388HBHH5==a@ %LE [[BQB$$&F
1I#.))I
1IIDv1G
GQ!2U!:;Aoowl+Gll7#i/G 88''9!<D XXdl#**2884F ::1:%L
F''/H"*O>>"((uP r?   	dimensionrl   c                 p   SSK Jn  UcN  Uc  U R                  nOUu  pxX-
  n[        [        R
                  " [        R                  " U5      U-  5      5      nUb8  SU;   a  [        S5      e[        R                  " U5      R                  5       US'   UR                  " SSU0UD6n	UR                  X	5      $ )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#   rQ   rM   rh   Binvoxervoxelize_mesh)
r2   r   r   rl   binvoxer_kwargsr   r   minsmaxsbinvoxers
             r=   voxelize_binvoxr      s    H (>llGJDkGw% 789	_,JKK*,--*?*G*G*I'FFoFH//r?   )r   	subdivider   methodc                     [        U4XS.UD6$ )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.
)r2   r   )
voxelizers)r2   r   r   rk   s       r=   voxelizer     s    > f?4???r?   )
   g       @)T)N)NNN)r   )numpyr    r   r   r   r   r0   	constantsr   typedr	   r
   r   r   r   r   r   r.   r-   r>   boolr}   r   r   FunctionRegistryr   r   r   r?   r=   <module>r      s    % % $   Q Q   
QT55#+G#45HN5	^^5 
5z ^G^G ^G 	^G
 ^G dnn^GB 
9=::#+I#6:	^^: 
:z 
 ##'"&	30F30  30 Y	30 
^^30 
30l "" 2?
 '2@F@ $@
 dnn@r?   