
    Mi                         S r SSKrSSKJrJr  SSKJrJrJ	r	J
r
JrJr  SSKJr     SS\S\\   4S	 jjrS\S
\	\   4S jr SS\S\\   S
\	\   4S jjrSS\S\\
   4S jjrS\S
\	\   4S jrg)zG
sample.py
------------

Randomly sample surface and volume of meshes.
    N   )transformationsutil)	ArrayLikeIntegerNDArrayNumberOptionalfloat64)uv_to_interpolated_colorcountface_weightc                 ~   Uc  U R                   n[        R                  " U5      nUc  [        R                  R                  nO)[        R                  R	                  U5      R                  nU" U5      US   -  n[        R
                  " XW5      nU R                  U R                  SS2S4      n	U R                  U R                  SS2SS24      R                  5       n
U
[        R                  " U	S5      R                  S5      -  n
X   n	X   n
U(       a  [        U R                  S5      (       a  U R                  R                  U R                  SS2S4      nU R                  R                  U R                  SS2SS24      R                  5       n[        R                  " US5      R                  S5      nX-  nX   nX   nU" [        U
5      S	S45      nUR                  SS
9R                  S5      S:  nX==   S-  ss'   [        R                   " U5      nX-  R                  SS
9nUU	-   nU(       a}  [        U R                  S5      (       aD  WU-  R                  SS
9nUW-   nU R                  R"                  R$                  n['        UU5      nOU R                  R(                  U   nUUU4$ UU4$ )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.
seed : None or int
  If passed as an integer will provide deterministic results
  otherwise pulls the seed from operating system 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
Nr   r   )r      )r   r      uv)r   r   r   r   )axisg      ?)
area_facesnpcumsumrandomdefault_rngsearchsortedverticesfacescopytilereshapehasattrvisualr   lensumabsmaterialimager   face_colors)meshr   r   sample_colorseed
weight_cumr   	face_pick
face_indextri_originstri_vectors
uv_origins
uv_vectorsuv_origins_tilerandom_lengthsrandom_testsample_vectorsamplessample_uv_vector
uv_samplestexturecolorss                         h/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/sample.pysample_surfacer<      s}   R  oo ;'J |!!&&t,33 u
2.I7J --

1a4 01K--

1ab5 12779K277;/77
CCK )K)KT22[[^^DJJq!t$45
[[^^DJJq!"u$56;;=
''*f5==jI%
+
+
 S-q!45N !$$!$,44R83>K3&VVN+N !166A6>M k)G4;;%% *^ ;@@a@H)J6Jkk**00G-j'BF[[,,Z8F
F**J    returnc                     [         R                  R                  US45      U R                  -  U R                  S   -   nU R	                  U5      nX#   SU nU$ )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

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   points	containedr6   s        r;   volume_meshrE   |   sT    $ iiqz*T\\9T[[^KFf%I'GNr=   	transformc                     [         R                  R                  US45      S-
  nX0-  nUb  [        R                  " X25      nU$ )al  
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

Returns
---------
samples : (count, 3) float
  Points in requested volume
r   g      ?)r   r   r   transform_points)r@   r   rF   r6   s       r;   volume_rectangularrI      sD    * iiqz*S0GG!227FNr=   radiusc                 2   SSK Jn  Uc&  [        R                  " U R                  SU-  -  5      n[        XS-  US9u  pVU" XR5      u  pW[        U5      U:  a  USU Xg   SU 4$ [        R                  R                  S[        U5       SU S35        XVU   4$ )	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!)
rC   rL   r   sqrtarear<   r"   r   logwarning)r(   r   rJ   r*   rL   rC   indexmasks           r;   sample_surface_evenrT      s    8 % ~a%i01 #4>MF  /LF 6{efu~u{6E222 	HHyVQugY?@;r=   c                    [         R                  R                  SU 45      u  p[         R                  S-  U-  n[         R                  " SU-  S-
  5      n[        R
                  " [         R                  " X445      5      nU$ )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

Returns
----------
points : (count, 3) float
  Random points on the surface of a unit sphere
r   r   )r   r   piarccosr   spherical_to_vectorcolumn_stack)r   uvthetaphirC   s         r;   sample_surface_spherer^      se    $ 99QJ'DAEEAIME
))QUaK
 C%%booul&CDFMr=   )NFN)N)NN)__doc__numpyr    r   r   typedr   r   r   r	   r
   r   r!   r   r<   rE   rI   rT   intr^    r=   r;   <module>re      s     # I I , (,	jj )$jZW )9 2 ?C(0(;W8/W /hv6F /d )9 r=   