
    Mi/                     .   S SK rSSKJrJr   S SKJrJr  S SKJ	r	  SSKJrJr  SSKJr  SS	KJr  SS
KJr  SSKJr       SS jrSS jrSS jr SS jr  SS\S\S\\   4S jjrS rS r g! \
 a  rSSKJr  \" \5      r\\\srr	r SrCNsSrCff = f)    N   )	ArrayLikeOptional)
coo_matrixeye)spsolve)ExceptionWrapper)graph	triangles)Trimesh)index_sparsemass_properties)unitizec                 t   Uc  [        U 5      nU(       a  U R                  nU R                  R                  5       R	                  [
        R                  5      nU R                  R                  5       R	                  [
        R                  5      nU(       a,  UR                  S   n	[        U	5      U[        U	5      U-
  -  -   n
[        U5       H`  nU(       d  UR                  U5      U-
  nXqU-  -  nO[        W
U5      nU(       d  M;  [        R                  " Xx   SS9S   nUWU-  S-  -  nMb     Xpl        U $ )a*  
Smooth a mesh in-place using laplacian smoothing.
Articles
1 - "Improved Laplacian Smoothing of Noisy Surface Meshes"
   J. Vollmer, R. Mencl, and H. Muller
2 - "Implicit Fairing of Irregular Meshes using Diffusion
   and Curvature Flow". M. Desbrun,  M. Meyer,
   P. Schroder, A.H.B. Caltech
Parameters
------------
mesh : trimesh.Trimesh
Mesh to be smoothed in place
lamb : float
Diffusion speed constant
If   0.0, no diffusion
If > 0.0, diffusion occurs
implicit_time_integration: boolean
if False: explicit time integration
    -lamb <= 1.0 - Stability Limit (Article 1)
if True: implicit time integration
    -lamb no limit (Article 2)
iterations : int
Number of passes to run filter
laplacian_operator : None or scipy.sparse.coo.coo_matrix
Sparse matrix laplacian operator
Will be autogenerated if None
r   Tskip_inertiavolumegUUUUUU?)laplacian_calculationr   verticescopyviewnpndarrayfacesshaper   rangedotr   r   r   )meshlamb
iterationsimplicit_time_integrationvolume_constraintlaplacian_operatorvol_inir   r   dlapAA_indexr   vol_news                 k/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/smoothing.pyfilter_laplacianr+      s!   J !248 ++ }}!!#((4HJJOO""2::.E !!''*YT-?!?@@ 
#($((2X=Cs
"H r8,H //dSG 7*	::H# $( MK    c                    Uc  [        U 5      nU R                  R                  5       R                  [        R
                  5      nUR                  5       n[        U5       HS  nUR                  5       nUR                  U5      nXQU-  SU-
  U-  -   -
  n	XRU	-  SU-
  UR                  U	5      -  -   -  nMU     XPl        U $ )az  
Smooth a mesh in-place using laplacian smoothing
and Humphrey filtering.
Articles
"Improved Laplacian Smoothing of Noisy Surface Meshes"
J. Vollmer, R. Mencl, and H. Muller
Parameters
------------
mesh : trimesh.Trimesh
  Mesh to be smoothed in place
alpha : float
  Controls shrinkage, range is 0.0 - 1.0
  If 0.0, not considered
  If 1.0, no smoothing
beta : float
  Controls how aggressive smoothing is
  If 0.0, no smoothing
  If 1.0, full aggressiveness
iterations : int
  Number of passes to run filter
laplacian_operator : None or scipy.sparse.coo.coo_matrix
  Sparse matrix laplacian operator
  Will be autogenerated if None
      ?r   r   r   r   r   r   r   r   )
r   alphabetar!   r$   r   originalr(   vert_qvert_bs
             r*   filter_humphreyr5   c   s    4 !248 }}!!#((4H}}H 
#%))(3X-u0FFG6MS4Z3E3I3I&3Q$QQQ	 $ MKr,   c                    Uc  [        U 5      nU R                  R                  5       R                  [        R
                  5      n[        U5       H0  nUR                  U5      U-
  nUS-  S:X  a	  XQU-  -  nM)  XRU-  -  nM2     XPl        U $ )aL  
Smooth a mesh in-place using laplacian smoothing
and taubin filtering.
Articles
"Improved Laplacian Smoothing of Noisy Surface Meshes"
J. Vollmer, R. Mencl, and H. Muller
Parameters
------------
mesh : trimesh.Trimesh
  Mesh to be smoothed in place.
lamb : float
  Controls shrinkage, range is 0.0 - 1.0
nu : float
  Controls dilation, range is 0.0 - 1.0
  Nu shall be between 0.0 < 1.0/lambda - 1.0/nu < 0.1
iterations : int
  Number of passes to run the filter
laplacian_operator : None or scipy.sparse.coo.coo_matrix
  Sparse matrix laplacian operator
  Will be autogenerated if None
   r   r/   )r   r    nur!   r$   r   indexr   s           r*   filter_taubinr:      s    . !248 }}!!#((4H z" $$X.919>s
"HS H # MKr,   c                    Uc  [        U 5      nU(       a  U R                  nU R                  R                  5       R	                  [
        R                  5      nU R                  R                  5       R	                  [
        R                  5      nS[
        R                  " U R                  5      S-  -  n[        U5       GH  n	[        U 5      n
UR                  U5      nXk-
  n[
        R                  " X-  R                  [
        R                  " S5      5      5      nS[
        R                  " SU5      -  n[
        R                  " SU-  [
        R                   " SX-  [
        R"                  " U5      -  5      5      nUR                  U5      nXnX-
  -  -  nU(       d  M  [%        Xg   SS9S	   nU	S
:X  a  ['        XgU
UU5      nXjW-  WU-
  -  -  nGM     X`l        U $ )a  
Smooth a mesh in-place using laplacian smoothing using a
mutable diffusion laplacian.

Articles
  Barroqueiro, B., Andrade-Campos, A., Dias-de-Oliveira,
  J., and Valente, R. (January 21, 2021).
  "Bridging between topology optimization and additive
   manufacturing via Laplacian smoothing." ASME. J. Mech. Des.


Parameters
------------
mesh : trimesh.Trimesh
  Mesh to be smoothed in place
lamb : float
  Diffusion speed constant
  If   0.0, no diffusion
  If > 0.0, diffusion occurs
iterations : int
  Number of passes to run filter
laplacian_operator : None or scipy.sparse.coo.coo_matrix
  Sparse matrix laplacian operator
  Will be autogenerated if None
g{Gz?      ?)   r   r.   g-q=g?Tr   r   r   )r   r   r   r   r   r   r   r   max
area_facesr   get_vertices_normalsr   absonesmaximumminimummeanr   dilate_slope)r   r    r!   r#   r$   v_inir   r   epsr(   normalsqipi_qiadillamberr   volslopes                     r*   filter_mut_dif_laplacianrP      s   < !248  }}!!#((4HJJOO""2::.E
"&&)S0
1C 
#&t,##H-vvw++BGGFO<=RZZt,,C$J

3bggdm8S(TU !$$X.cn-- !(/EhOC{$XgsCH%53;77H' $, MKr,   r   equal_weightpinned_verticesc                 &   U(       Ga	  [         R                  " U R                  5      nUb  SUR                  [        R
                  " UR                  U5      '   [        R                  " UR                  U45      Ul        [        R                  " UR                  U45      Ul        [        R                  " UR                  [        R                  " [        U5      [        S945      Ul        UR                  SUR                  SS9-  5      nU$ U R                  nUb  U H  nU/XE'   M
     U R                  R!                  [        R"                  5      n[        R                  " U5      n[        R                  " [%        U5       VVs/ s H  u  pXU/[        U5      -  PM     snn5      n	[        R                  " S5      n
[%        U5       VVs/ s HR  u  pXS[        R&                  " S[        R(                  " [        R*                  " Xe   Xh   -
  S-  U
5      5      5      -  PMT     nnn[        R                  " U Vs/ s H  oUUR                  5       -  PM     sn5      n[-        XU44[        U5      /S-  S	9nU$ s  snnf s  snnf s  snf )
a(  
Calculate a sparse matrix for laplacian operations.

Note that setting equal_weight to False significantly hampers performance.

Parameters
-------------
mesh : trimesh.Trimesh
  Input geometry
equal_weight : bool
  If True, all neighbors will be considered equally
  If False, all neighbors will be weighted by inverse distance
pinned_vertices : None or list of ints
  If None, no vertices are pinned
  If list, vertices will be pinned, such that they will not be moved
Returns
----------
laplacian : scipy.sparse.coo.coo_matrix
  Laplacian operator
F)dtyper.   r   )axisr=   gư>r7   )r   )r
   edges_to_cooedgesdatar   isinrowconcatenatecolrB   lenboolmultiplysumvertex_neighborsr   r   r   	enumeraterC   sqrtr   r   )r   rQ   rR   	laplacian	neighborsir   r\   nrZ   rB   normsrX   s                r*   r   r     s   2 &&tzz2	&FKINN2779==/BCNNIMM?+KLIMNNIMM?+KLIM^^_)=T!JKIN &&sY]]]-B'BC	D = ))	 &$ !s	 % ==%%bjj1 nnY'nny7KL7KtqqcCFl7KLM wwqz
 "),
 - jjrwwrvvx{X[/HQ.NPT'UVWX, 	 
 ~~E:Eq1557{E:; Cj1#h-19LM	# M
 ;s   J
AJJc                     U R                   nU R                  nU R                  n[        [	        U5      U5      R                  U5      n[        U5      $ )z
Compute Vertex normals using equal weighting of neighbors faces.
Parameters
  -------------
  mesh : trimesh.Trimesh
    Input geometry
  Returns
  ----------
  vertices_normals: array
    Vertices normals
)r   r   face_normalsr   r]   r   r   )r   r   r   rj   vert_normalss        r*   r@   r@   Q  sK     }}HJJE $$L  Hu599,GL<  r,   c                 <    XU-  -   n[        XQ   SS9S   nXFU-
  -  $ )az  
Get the derivate of dilation scalar by the volume variation by finite differences
Thus, Vertices += vertex_normals*dilate_slope*(Initial_Volume - Srinked_Volume)
Parameters
  -------------
  mesh : trimesh.Trimesh
    Input geometry
  vertices: mesh.vertices
  faces: mesh.faces
  normals: array
    vertices normals
  Returns
  ----------
  dilate_slope: float
    derivative
Tr   r   r   )r   r   rI   vrH   	vertices2v2s          r*   rF   rF   k  s1    & S=(I	)	=h	GBFr,   )r<   
   FTN)g?r<   rp   N)r<   r<   rp   N)r<   rp   TN)TN)!numpyr   typedr   r   scipy.sparser   r   scipy.sparse.linalgr   ImportErrorE
exceptionsr	   wrapper r
   r   baser   geometryr   r   utilr   r+   r5   r:   rP   r^   r   r@   rF    r,   r*   <module>r~      s     &9,+   " & 
 
#K\+\)Z OSCP +/K
KK i(K\!4G  9,q!G&C*	9s   A/ /B5BB