Ë
    :vžjµ!  ã            
       ó  — d Z ddlmZ ddlZddlmZ ddlmZm	Z	m
Z
mZmZmZ ddlmZmZ ddlmZ  ee«      Z	 	 	 	 dd	e	d
edz  dedefd„Zdd	e	dede
e   fd„Z	 	 dd	e	dedz  dede
e   fd„Z	 dd	e	dedz  defd„Zdd	edede
e   fd„Zy)zG
sample.py
------------

Randomly sample surface and volume of meshes.
é    )Ú	getLoggerNé   )Útransformations)Ú	ArrayLikeÚIntegerÚNDArrayÚNumberÚSeedÚfloat64)Úrandom_generatorÚspherical_to_vector)Úuv_to_interpolated_colorÚcountÚface_weightÚreturn_barycentricÚseedc                 ó’  — |€| j                   }t        j                  |«      }t        |«      j                  } ||«      |d   z  }t        j
                  ||«      }	| j                  | j                  dd…df      }
| j                  | j                  dd…dd…f      j                  «       }|t        j                  |
d«      j                  d«      z  }|
|	   }
||	   }|r®t        | j                  d«      r˜| j                  j                  | j                  dd…df      }| j                  j                  | j                  dd…dd…f      j                  «       }t        j                  |d«      j                  d«      }||z  }||	   }||	   } |t        |«      d	df«      }|j                  d¬
«      j                  d«      dkD  }||xx   dz  cc<   t        j                   |«      }|r4t        j"                  d|j                  d¬
«      z
  |dd…dd…df   f«      }||z  j                  d¬
«      }||
z   }|rƒt        | j                  d«      rG|z  j                  d¬
«      }|z   }| j                  j$                  j&                  }t)        ||«      }n| j                  j*                  |	   }|r||	|fS ||	|fS |r||	fS ||	fS )aÖ  
    Sample the surface of a mesh, returning the specified
    number of points

    For individual triangle sampling uses this method:
    http://mathworld.wolfram.com/TrianglePointPicking.html

    Parameters
    -----------
    mesh : trimesh.Trimesh
      Geometry to sample the surface of
    count : int
      Number of points to return
    face_weight : None or len(mesh.faces) float
      Weight faces by a factor other than face area.
      If None will be the same as face_weight=mesh.area
    sample_color : bool
      Option to calculate the color of the sampled points.
      Default is False.
    return_barycentric : bool
      If True will also return the barycentric coordinates
      of each sampled point.
    seed : None or int
      Seed for deterministic results, otherwise OS entropy.

    Returns
    ---------
    samples : (count, 3) float
      Points in space on the surface of mesh
    face_index : (count,) int
      Indices of faces for each sampled point
    colors : (count, 4) float
      Colors of each sampled point
      Returns only when the sample_color is True
    barycentric : (count, 3) float
      Coordinates on `mesh.faces[face_index]`
      Returned only when return_barycentric is True
    Néÿÿÿÿr   r   )r   é   )r   r   é   Úuv)r   r   r   r   )Úaxisg      ð?)Ú
area_facesÚnpÚcumsumr   ÚrandomÚsearchsortedÚverticesÚfacesÚcopyÚtileÚreshapeÚhasattrÚvisualr   ÚlenÚsumÚabsÚhstackÚmaterialÚimager   Úface_colors)Úmeshr   r   Úsample_colorr   r   Ú
weight_cumr   Ú	face_pickÚ
face_indexÚtri_originsÚtri_vectorsÚ
uv_originsÚ
uv_vectorsÚuv_origins_tileÚrandom_lengthsÚrandom_testÚbarycentricÚsample_vectorÚsamplesÚsample_uv_vectorÚ
uv_samplesÚtextureÚcolorss                           ú_/workspace/moltex-experiments/.pixi/envs/default/lib/python3.12/site-packages/trimesh/sample.pyÚsample_surfacer@      sÃ  € ð^ Ðð —o‘oˆô —‘˜;Ó'€Jä˜dÓ#×*Ñ*€Fñ �u“ 
¨2¡Ñ.€Iä—‘ ¨YÓ7€Jð —-‘- §
¡
ª1¨a¨4Ñ 0Ñ1€KØ—-‘- §
¡
ª1¨a©b¨5Ñ 1Ñ2×7Ñ7Ó9€KØ”2—7‘7˜;¨Ó/×7Ñ7¸
ÓCÑC€Kð ˜jÑ)€KØ˜jÑ)€Káœ §¡¨TÔ2Ø—[‘[—^‘^ D§J¡Jªq°!¨tÑ$4Ñ5ˆ
Ø—[‘[—^‘^ D§J¡Jªq°!±"¨uÑ$5Ñ6×;Ñ;Ó=ˆ
ÜŸ'™' *¨fÓ5×=Ñ=¸jÓIˆØ�oÑ%ˆ
Ø 
Ñ+ˆ
Ø 
Ñ+ˆ
ñ œS Ó-¨q°!Ð4Ó5€Nð !×$Ñ$¨!Ð$Ó,×4Ñ4°RÓ8¸3Ñ>€KØ�;Ó 3Ñ&ÓÜ—V‘V˜NÓ+€Náô —i‘i  ^×%7Ñ%7¸QÐ%7Ó%?Ñ!?ÀÒPQÒSTÐVWÐPWÑAXÐ YÓZˆð ! >Ñ1×6Ñ6¸AÐ6Ó>€Mð ˜kÑ)€GáÜ�4—;‘; Ô%Ø *¨^Ñ ;×@Ñ@ÀaÐ@ÓHÐØ)¨JÑ6ˆJØ—k‘k×*Ñ*×0Ñ0ˆGÜ-¨j¸'ÓB‰Fà—[‘[×,Ñ,¨ZÑ8ˆFáØ˜J¨°Ð;Ð;à˜
 FÐ*Ð*áØ˜
 KÐ/Ð/à�JÐÐó    Úreturnc                 ó°   — t        |«      j                  } ||df«      | j                  z  | j                  d   z   }| j	                  |«      }||   d| }|S )a«  
    Use rejection sampling to produce points randomly
    distributed in the volume of a mesh.


    Parameters
    -----------
    mesh : trimesh.Trimesh
      Geometry to sample
    count : int
      Number of points to return
    seed : None or int
      Seed for deterministic results, otherwise OS entropy.

    Returns
    ---------
    samples : (n, 3) float
      Points in the volume of the mesh where n <= count
    r   r   N)r   r   ÚextentsÚboundsÚcontains)r,   r   r   r   ÚpointsÚ	containedr:   s          r?   Úvolume_meshrI   Ž   s\   € ô( ˜dÓ#×*Ñ*€FÙ�e˜Q�ZÓ  4§<¡<Ñ/°4·;±;¸q±>ÑA€FØ—‘˜fÓ%€IØ�YÑ  Ð'€GØ€NrA   Ú	transformc                 óz   — t        |«      j                  |df«      dz
  | z  }|�t        j                  ||«      }|S )aû  
    Return random samples inside a rectangular volume,
    useful for sampling inside oriented bounding boxes.

    Parameters
    -----------
    extents :   (3,) float
      Side lengths of rectangular solid
    count : int
      Number of points to return
    transform : (4, 4) float
      Homogeneous transformation matrix
    seed : None or int
      Seed for deterministic results, otherwise OS entropy.

    Returns
    ---------
    samples : (count, 3) float
      Points in requested volume
    r   g      à?)r   r   r   Útransform_points)rD   r   rJ   r   r:   s        r?   Úvolume_rectangularrM   ©   sD   € ô4   Ó%×,Ñ,¨e°Q¨ZÓ8¸3Ñ>À'ÑI€GØÐÜ!×2Ñ2°7¸IÓFˆØ€NrA   Úradiusc                 ó*  — ddl m} |€%t        j                  | j                  d|z  z  «      }t        | |dz  |¬«      \  }} |||«      \  }}t        |«      |k\  r|d| ||   d| fS t        j                  dt        |«      › d|› d�«       |||   fS )	a,  
    Sample the surface of a mesh, returning samples which are
    VERY approximately evenly spaced. This is accomplished by
    sampling and then rejecting pairs that are too close together.

    Note that since it is using rejection sampling it may return
    fewer points than requested (i.e. n < count). If this is the
    case a log.warning will be emitted.

    Parameters
    -----------
    mesh : trimesh.Trimesh
      Geometry to sample the surface of
    count : int
      Number of points to return
    radius : None or float
      Removes samples below this radius
    seed : None or int
      Provides deterministic values

    Returns
    ---------
    samples : (n, 3) float
      Points in space on the surface of mesh
    face_index : (n,) int
      Indices of faces for each sampled point
    r   )Úremove_closeNr   )r   z	only got Ú/z	 samples!)	rG   rP   r   ÚsqrtÚarear@   r%   ÚlogÚwarning)r,   r   rN   r   rP   rG   ÚindexÚmasks           r?   Úsample_surface_evenrX   É   s­   € õ< %ð €~Ü—‘˜Ÿ™ a¨%¡iÑ0Ó1ˆô # 4¨°©¸Ô>�M€FˆEñ   ¨Ó/�L€FˆDô ˆ6ƒ{�eÒØ�f�uˆ~˜u T™{¨6¨EÐ2Ð2Ð2ô ‡K�K�)œC ›K˜=¨¨%¨°	Ð:Ô;à�5˜‘;ÐÐrA   c                 óâ   — t        |«      j                  d| f«      \  }}t        j                  dz  |z  }t        j                  d|z  dz
  «      }t        t        j                  ||f«      «      S )a¨  
    Correctly pick random points on the surface of a unit sphere

    Uses this method:
    http://mathworld.wolfram.com/SpherePointPicking.html

    Parameters
    -----------
    count : int
      Number of points to return
    seed : None or int
      Seed for deterministic results, otherwise OS entropy.

    Returns
    ----------
    points : (count, 3) float
      Random points on the surface of a unit sphere
    r   r   )r   r   r   ÚpiÚarccosr   Úcolumn_stack)r   r   ÚuÚvÚthetaÚphis         r?   Úsample_surface_spherera   ý   s`   € ô( ˜DÓ!×(Ñ(¨!¨U¨Ó4�D€A€qä�E‰E�A‰I˜‰M€EÜ
�)‰)�Q˜‘U˜a‘KÓ
 €CäœrŸ™°°s¨|Ó<Ó=Ð=rA   )NFFN)N)NN)Ú__doc__Úloggingr   Únumpyr   Ú r   Útypedr   r   r   r	   r
   r   Úutilr   r   r$   r   Ú__name__rT   Úboolr@   rI   rM   rX   Úintra   © rA   r?   Ú<module>rl      s  ðñõ ã å ß E× Eß 7Ý ,á�Ó€ð %)ØØ$Øñwàðwð ˜TÑ!ðwð
 ðwð ówñt˜Wð ¨Dð ¸GÀGÑ<Ló ð< #'Øñ	àðð ˜4Ñðð ð	ð
 ˆWÑóðB FJñ1Øð1Ø"(¨4¡-ð1Ø>Bó1ñh> ð >¨Dð >¸GÀGÑ<Lô >rA   