
    MiM5                         S SK rSSKJr  SSKJr  SSKJrJrJ	r	J
r
  S rS r\r  SS\S	\
\\4   S
\	\   4S jjrS rSS jrSS jr\R$                  4S jrS rSS jrSS jrSS jrg)    N   )util)log)	ArrayLikeNumberOptionalUnionc                 <  ^^^ U R                   m[        R                  " [        R                  " S T 5       SS06SS9m[        R                  " U 5      mUUU4S jnU" SS9n[        S[        T5      5       H  n[        R                  " X!" U5      5      nM!     U$ )	Nc              3   N   #    U  H  n[         R                  " U5      v   M     g 7f)N)nparange).0ss     k/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/voxel/ops.py	<genexpr>$fill_orthographic.<locals>.<genexpr>   s     2EqbiillEs   #%indexingijaxisc                    > TSU 4   nUR                  5       nTU    UT'   [        R                  " X SS9nUR                  5       nSUT'   [        R                  " X SS9n[        R                  " X:  X:*  5      $ )N.T)r   keepdimsr   )copyr   minmaxlogical_and)r   base_local_indiceslocal_indicesminsmaxsemptyindicesshapes        r   	fill_axis$fill_orthographic.<locals>.fill_axis   s    $S$Y/*//1$T{evvm>*//1!evvm>~~&&
 	
    r      )r$   r   stackmeshgridlogical_notrangelenr   )denser%   filledr   r"   r#   r$   s       @@@r   fill_orthographicr0      s    KKEhh
2E2BTBG NN5!E
 AFaU$	$8 %Mr'   c                    [         R                  " U [         R                  S9n [        R                  " U S5      (       d  [        S5      eU R                  5       S-   n[         R                  " XU4[        5      n[         R                  " U S5      nSU[        UR                  5      '   [        U5       GHu  nSn[        SUS-
  5       H  n/ n[         R                  " X$USS	24   X$USS24   5      n[         R                  " [         R                  " U5      5      S   S-   n[!        U5      n	U	S
-  S:  =(       a    U	S
:  nU	S
:  a  M  [        SXS
-  -
  S
5       H  n
SX$XgU
   XzS-      24'   M     M     U(       d  M  [        SUS-
  5       H  n/ n[         R                  " X$SS	2U4   X$SS2U4   5      n[         R                  " [         R                  " U5      5      S   S-   n[!        U5      n	U	S
:  a  Mm  [        SXS
-  -
  S
5       H  n
SX$Xz   XzS-      2U4'   M     M     GMx     [         R"                  " [         R                  " U5      5      nUS-  nU$ )z
Given a sparse surface voxelization, fill in between columns.

Parameters
--------------
sparse_indices: (n, 3) int, location of filled cells

Returns
--------------
filled: (m, 3) int, location of filled cells
dtyper      zincorrect shaper5   r(   Fr   Nr      )r   
asanyarrayint64r   is_shape
ValueErrorr   zerosbooladdtupleTr,   equalwherer+   r-   column_stack)sparse_indices	max_valuegridvoxels_sparsei
check_dir2jidxeqcr   kr/   s                r   	fill_baserN   #   s0    ]]>BN==11*++ ""$q(I88Y95t<DFF>1-M#$D}	 9
q)a-(AC $!SbSy/41ab>:B((2>>"-.q1A5CCAa%1.QJ1u1aa%i+23q6CAJ../ , )  q)a-(AC$#2#qy/412q>:B((2>>"-.q1A5CCA1u1aa%i+23U+Q./ , )% < __RXXd^,F
aKFMr'   matrixpitch	thresholdc                 d   SSK Jn  SSKJn  Ub  [        R
                  " U 5      U:  n O[        R
                  " U [        S9n [        R                  " U 5      nSn[        R                  " XVSSS	9n[        US
5      (       a  UR                  nOUR                  n[        R
                  " U5      nUR                  S:X  a  U4S-  nU" USUS9n[        U5      S:X  a  [        R                  " S5        Uu  pSnO[        U5      S:X  a  Uu  pp[        R                   " W	Xa-  5      n	U" U	W
WS9nU$ )a  
Convert an (n, m, p) matrix into a mesh, using marching_cubes.

Parameters
-----------
matrix : (n, m, p) bool
  Occupancy array
pitch : float or length-3 tuple of floats, optional
  Voxel spacing in each dimension
threshold : float or None, optional
  If specified, converts the input into a boolean
  matrix by considering values above `threshold` as True


Returns
----------
mesh : trimesh.Trimesh
  Mesh generated by meshing voxels using
  the marching cubes algorithm in skimage
r   )measurer   TrimeshNr2   r(   constant)	pad_widthmodeconstant_valuesmarching_cubes_lewinerr5   g      ?)volumelevelspacingz0using old marching cubes, may not be watertight!r6   )verticesfacesvertex_normals)skimagerS   baserU   r   r7   r<   r+   padhasattrrZ   marching_cubessizer-   r   warningsubtract)rO   rP   rQ   rS   rU   
rev_matrixrW   funcmeshedr^   r_   normals_valsmeshs                 r   matrix_to_marching_cubesro   c   s!   2  v&2vT2'J I
QJ
 w011--%% MM% EzzQ1F 6{aFG 	V	*0' {{8Y%67HHE'JDKr'   c                    [         R                  " U [         R                  S9n [        R                  " U S5      (       d  [        S5      eU R                  SS9S-   n[         R                  " [         R                  " U5      [        S9n[         R                  " [         R                  " USS 5      US   S/5      nX-  R                  SS9nS	X$'   UR                  U5      nU$ )
z
Take a sparse (n,3) list of integer indexes of filled cells,
turn it into a dense (m,o,p) matrix.

Parameters
-----------
sparse : (n, 3) int
  Index of filled cells

Returns
------------
dense : (m, o, p) bool
  Matrix of filled cells
r2   r4   zsparse must be (n,3)!r   r   r(   Nr   T)r   r7   r8   r   r9   r:   r   r;   prodr<   arraysumreshape)sparser$   rO   
multiplierindexr.   s         r   sparse_to_matrixrx      s      ]]62F==))011JJAJ"EXXbggenD1F27759-uQx;<J %%1%-EFMNN5!ELr'   c                 R   [         R                  " U [         R                  S9n [         R                  " U[        S9nU R	                  SS9nX-
  U-  R                  5       R                  [         R                  5      n[        U5      n[        XAS9nU=R                  U-  sl
        U$ )z
Mesh points by assuming they fill a voxel box, and then
running marching cubes on them

Parameters
------------
points : (n, 3) float
  Points in 3D space

Returns
-------------
mesh : trimesh.Trimesh
  Points meshed using marching cubes
r2   r   r   )rP   )r   r7   float64floatr   roundastyper8   rx   ro   r^   )pointsrP   originrw   rO   rn   s         r   points_to_marching_cubesr      s      ]]64FMM%u-E ZZQZFo&--/66rxx@E e$F $F8DMMVMKr'   c                 `   SSK Jn  SSKJn  [        R
                  " U [        R                  S9n UR                  5       nUR                  [        U5      5        [        R                  " U S[        UR                  5      45      R                  S5      nU[        R                  " UR                  [        U 5      S45      -  n[        R                  " UR                  [        U 5      S45      nU[        R                  " [        R                   " [        U 5      5      [        UR                  5      -  [        UR                  5      5      SS2S4   -  nU(       Ga  [        R"                  " UR$                  5      R'                  [(        5      n	[        R                  " U	[        U 5      S45      n
[        R                  " [        R                   " [        U 5      5      [        UR                  5      5      n[        R"                  " X-  5      R'                  [(        5      n[+        [-        [.        U5      5      nX   nX-   n[        R0                  " U Vs/ s H  n[/        U5      U;  PM     sn5      nO"[        R2                  " [        U5      [4        S9nSnUb}  [        R6                  " U5      nUR8                  S:X  a  US   R                  [        U 5      SS	9nUR8                  S:X  a+  [        U5      [        U 5      :X  a  UR                  S
SS	9U   nU" XxU   US9nU$ s  snf )a  
Return a Trimesh object with a box at every center.

Doesn't do anything nice or fancy.

Parameters
-----------
centers : (n, 3) float
  Center of boxes that are occupied
pitch : float
  The edge length of a voxel
colors : (3,) or (4,) or (n,3) or (n, 4) float
  Color of boxes
remove_internal_faces : bool
  If True, removes internal faces shared between adjacent boxes

Returns
---------
rough : Trimesh
  Mesh object representing inputs
r   )
primitivesrT   r2   r(   r4   Nr   r      )r^   r_   face_colors) r   rb   rU   r   r7   rz   Boxapply_scaler{   tiler-   r^   rt   r_   repeatr   r|   face_normalsr}   intsetmapr>   rr   onesr<   asarrayndim)centersrP   colorsremove_internal_facesr   rU   bvfbase_normalsr   face_voxel_idxvoxel_coords	voxel_setvoxel_face_coordsneighbor_coordsrL   	keep_maskr   rn   s                       r   multiboxr      sR   ,  mmG2::6G 	AMM%,
!S_-.66w?Ac'lA.	//A
#g,*+A299S\*S_<c!''l	KAtG	TTAxx/66s;ww|c'lA->? IIc'l#S\
 xx077<E<01	 )8+:HHQAeAhi7QR	GGCF$/	KF#;;!D\((WA(>F;;!Fs7| ; ---3I>KAy\{KDK Rs   L+c           	      Z   SSK n[        R                  " U R                  SS9U R	                  SS9UR                  SS9UR	                  SS9/5      nUR                  SS9S-
  n[        [        R                  " USS9S-   5      nUR                  X-
  R                  [        R                  " [        U 5      [        S9US9nUR                  X-
  R                  [        R                  " [        U5      [        S9US9nU" Xx5      n	[        R                  " U	R                  5      U-   n
U
$ )aV  
Find common rows between two arrays very quickly
using 3D boolean sparse matrices.

Parameters
-----------
a: (n, d)  int, coordinates in space
b: (m, d)  int, coordinates in space
operation: numpy operation function, ie:
              np.logical_and
              np.logical_or

Returns
-----------
coords: (q, d) int, coordinates in space
r   Nr   r(   r   r2   )datar$   )ru   r   rr   r   r   r>   ptpCOOr?   r   r-   r<   rB   coords)ar   	operationru   extremar   rf   sp_asp_bappliedr   s              r   boolean_sparser   <  s    &  hh1quu!u}aeeemQUUPQU]STG[[a[ 1$Fa(1,-D ::qznn2773q6+Fd:SD::qznn2773q6+Fd:SD #G__W^^,v5FMr'   c                    U R                   n[        U5      n/ n/ n[        [        U5      5       H  n[        [        U5      5      [        [        US-   U5      5      -   n[        R
                  " XS9n[        R                  " U5      u  nUS   n	US   n
UR                  X/5        UR                  [        X5      5        M     U [        U5         [        R                  " U[        5      4$ )Nr(   r   r   r   )r$   r-   r,   r>   r   anynonzeroappendslicerr   r   )r   r$   ndimspaddingslicesdimr   r/   r#   pad_left	pad_rights              r   strip_arrayr   c  s    JJEJEGFSZ U3Z 5sQw)>#??(ZZ'
1:BK	,-eH01 ! f# 666r'   c                 F   [         R                  " U 5      n U R                  SS S:w  a  [        S5      e[         R                  " U [         R
                  S9nUb  U[        U5      -  nUb5  [         R                  " U5      nUR                  S:w  a  [        S5      eX2-  nU$ )aC  
Convert indices of an (n,m,p) matrix into a set of voxel center points.

Parameters
----------
indices: (q, 3) int, index of voxel matrix (n,m,p)
pitch: float, what pitch was the voxel matrix computed with
origin: (3,) float, what is the origin of the voxel matrix

Returns
----------
points: (q, 3) float, list of points
r(   Nr5   zshape of indices must be (q, 3)r2   shape of origin must be (3,))r   r7   r$   r:   rr   rz   r{   )r#   rP   r   r~   s       r   indices_to_pointsr   s  s     mmG$G}}QRD :;;XXgRZZ0F%,v&<<4;<<Mr'   c                 n    [         R                  " [         R                  " U 5      5      n[        X1US9nU$ )a+  
Convert an (n,m,p) matrix into a set of points for each voxel center.

Parameters
-----------
matrix: (n,m,p) bool, voxel matrix
pitch: float, what pitch was the voxel matrix computed with
origin: (3,) float, what is the origin of the voxel matrix

Returns
----------
points: (q, 3) list of points
)r#   rP   r   )r   rB   r   r   )rO   rP   r   r#   r~   s        r   matrix_to_pointsr     s,     oobjj01GwFKFMr'   c                    [         R                  " U [         R                  S9n U R                  U R                  S   S4:w  a  [	        S5      eUb5  [         R
                  " U5      nUR                  S:w  a  [	        S5      eX-  n Ub  X-  n [         R
                  " U[         R                  S9n[        U5      n[         R                  " U 5      R                  [        5      nU$ )aI  
Convert center points of an (n,m,p) matrix into its indices.

Parameters
----------
points : (q, 3) float
  Center points of voxel matrix (n,m,p)
pitch : float
  What pitch was the voxel matrix computed with
origin : (3,) float
  What is the origin of the voxel matrix

Returns
----------
indices : (q, 3) int
  List of indices
r2   r   r5   zshape of points must be (q, 3)r   r   )
r   rr   rz   r$   r:   r7   r{   r|   r}   r   )r~   rP   r   r#   s       r   points_to_indicesr     s    $ XXfBJJ/F||Q++9::v&<<4;<<]]64F%LEhhv%%c*GNr'   )      ?N)r   )r   NF)NN)numpyr   r   r   	constantsr   typedr   r   r   r	   r0   rN   fill_voxelizationro   rx   r   r   r   r   r   r   r   r    r'   r   <module>r      s       6 66:z  
 '*"&HH"#H HV>DJZ $&>> $N7 <&"r'   