
    j                     "   d Z ddlZddlmZmZ ddlmZ ddlm	Z	 dde	fdZ
dd	Zd
 Z G d d      Z	 ej                   ej                  _         e
j                   ej                  _         ej                   ej                  _         y# e$ r Y yw xY w)zG
permutate.py
-------------

Randomly deform meshes in different ways.
    N   )transformationsutil)	triangles)Numbertranslation_scalec           	      N   t        j                  |      }t        j                  j	                  | j
                        j                  d      }t        j                  ||      }t        j                  | d      } |di t        j                  |j                  d            }|S )a  
    Return a permutated variant of a mesh by randomly reordering faces
    and rotatating + translating a mesh by a random matrix.

    Parameters
    ----------
    mesh : trimesh.Trimesh
      Mesh, will not be altered by this function

    Returns
    ----------
    permutated : trimesh.Trimesh
      Mesh with same faces as input mesh but reordered
      and rigidly transformed in space.
    )	translate)   Trimesh)r   r   r    )r   random_rotation_matrixnprandompermutationr   reshapetransform_pointsr   
type_namedtriangles_module	to_kwargs)meshr   matrixr   	mesh_type
permutateds         >/DATA/.local/lib/python3.12/site-packages/trimesh/permutate.py	transformr      s    " 33>OPF 		%%dnn5==gFI00FCI i0IW-77	8I8I*8UVWJ    c                    || j                   dz  }t        j                  j                  | j                  j                        dz
  |z  }| j                  j                         |z   }t        j                  j                  || j                           }t        j                  | d      } |di t        j                  |      }|S )a  
    Add gaussian noise to every vertex of a mesh, making
    no effort to maintain topology or sanity.

    Parameters
    ----------
    mesh : trimesh.Trimesh
      Input geometry, will not be altered
    magnitude : float
      What is the maximum distance per axis we can displace a vertex.
      If None, value defaults to (mesh.scale / 100.0)

    Returns
    ----------
    permutated : trimesh.Trimesh
      Input mesh with noise applied
    g      Y@g      ?r   r   )scaler   r   verticesshapecopyr   facesr   r   r   r   )r   	magnituder   vertices_noiser   r   r   s          r   noiser'   /   s    $ JJ&	iit}}223c9YFF]]'')F2N 		%%nTZZ&@AIi0IC-77	BCJr   c           
      ^   t         j                  j                  | j                  j                        dz   }||j	                  d      j                  d      z  }|j                  d      | j                  z  j	                  d      }t        j                  t        |            t        | j                        z   }t        j                  | j                  |f      }t        j                  t        j                  | j                  ddddgf   |f      t        j                  | j                  ddddgf   |f      t        j                  | j                  ddddgf   |f      f      }t         j                  j                  |      }t        j                  | d	      } |||
      }|S )a  
    Subdivide each face of a mesh into three faces with the new vertex
    randomly placed inside the old face.

    This produces a mesh with exactly the same surface area and volume
    but with different tessellation.

    Parameters
    ------------
    mesh : trimesh.Trimesh
      Input geometry

    Returns
    ----------
    permutated : trimesh.Trimesh
      Mesh with remeshed facets
    g?r   )axis)r   r   )r   r   r   Nr      r   )r!   r$   )r   r   r$   r"   sumr   r   arangelenr!   vstackcolumn_stackr   r   r   )r   barycentricvertex_facevertex_face_idr!   r$   r   r   s           r   tessellationr3   P   s[   ( ))""4::#3#34t;K;???*227;;K &&z2T^^CHHaHPKYYs;/03t}}3EEN yy$--56HIIOOTZZAq6	2NCDOOTZZAq6	2NCDOOTZZAq6	2NCD	
E II!!%(Ei0IHE:Jr   c                   (    e Zd Zd ZddZddZd Zy)
Permutatorc                     || _         y)zL
        A convenience object to get permutated versions of a mesh.
        N)_mesh)selfr   s     r   __init__zPermutator.__init__~   s     
r   c                 0    t        | j                  |      S )N)r   )r   r7   )r8   r   s     r   r   zPermutator.transform   s    7HIIr   Nc                 .    t        | j                  |      S N)r'   r7   )r8   r%   s     r   r'   zPermutator.noise   s    TZZ++r   c                 ,    t        | j                        S r<   )r3   r7   )r8   s    r   r3   zPermutator.tessellation   s    DJJ''r   )i  r<   )__name__
__module____qualname__r9   r   r'   r3   r   r   r   r5   r5   }   s    J,(r   r5   )g     @@r<   )__doc__numpyr    r   r   r   r   typedr   r   r'   r3   r5   AttributeErrorr   r   r   <module>rF      s     # + v @B*Z( ("	$}}J#,#4#4J &2&:&:J# 		s   AB BB