
    Ti                         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        _         dS # e$ r Y dS w xY w)zG
permutate.py
-------------

Randomly deform meshes in different ways.
    N   )transformationsutil)	triangles)Number     @@translation_scalec           	      L   t          j        |          }t          j                            | j                                      d          }t          j        ||          }t          j	        | d          } |di t          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         K/DATA/AppData/hermes/venv/lib/python3.11/site-packages/trimesh/permutate.py	transformr      s    " 3>OPPPF 	%%dn55==gFFI0FCCI i00IWW-7	8I8I*8U8UVVWWJ    c                 f   |
| j         dz  }t          j                            | j        j                  dz
  |z  }| j                                        |z   }t          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
    Ng      Y@g      ?r   r   )scaler   r   verticesshapecopyr   facesr   r   r   r   )r   	magnituder   vertices_noiser   r   r   s          r   noiser(   /   s    $ J&	it}233c9YFF]''))F2N 	%%nTZ&@AAIi00ICC-7	BBCCJr   c           
      H   t           j                            | j        j                  dz   }||                    d                              d          z  }|                    d          | j        z                      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                            |          }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   tessellationr4   P   s{   ( )""4:#344t;K;???**227;;;K &&z22T^CHHaHPPKYs;//003t}3E3EEN y$-566HIOTZAq6	2NCDDOTZAq6	2NCDDOTZAq6	2NCDD	
 E I!!%((Ei00IHE:::Jr   c                   *    e Zd Zd ZddZddZd ZdS )	
Permutatorc                     || _         dS )zL
        A convenience object to get permutated versions of a mesh.
        N)_mesh)selfr   s     r   __init__zPermutator.__init__~   s     


r     c                 .    t          | j        |          S )N)r	   )r   r8   )r9   r	   s     r   r   zPermutator.transform   s    7HIIIIr   Nc                 ,    t          | j        |          S N)r(   r8   )r9   r&   s     r   r(   zPermutator.noise   s    TZ+++r   c                 *    t          | j                  S r>   )r4   r8   )r9   s    r   r4   zPermutator.tessellation   s    DJ'''r   )r;   r>   )__name__
__module____qualname__r:   r   r(   r4   r   r   r   r6   r6   }   s^          J J J J, , , ,( ( ( ( (r   r6   )r   r>   )__doc__numpyr    r   r   r   r   typedr   r   r(   r4   r6   AttributeErrorr   r   r   <module>rH      s        # # # # # # # # + + + + + +       v    @   B* * *Z( ( ( ( ( ( ( ("	$}J#,#4J &2&:J### 	 	 	DD	s   3A, ,A54A5