
    Mi/                     R    S SK r S SKrSSKJr   " S S5      rS
S jrS rS\4S	 jrg)    N   )utilc                      \ rS rSr SS jrS r\S 5       r\R                  S 5       r\S 5       r	\	R                  S 5       r	\S	 5       r
\
R                  S
 5       r
\S 5       r\R                  S 5       rS rS rS rS rSrg)Camera   Nc                 ~   Uc-  S[         R                  " S5      R                  5        3U l        OXl        Uc  Uc  [	        S5      eSU l        X0l        X@l        Uc:  U R                  S-  R                  5       R                  [        R                  5      nX l        [        U5      U l        [        U5      U l        g)a  
Create a new Camera object that stores camera intrinsic
and extrinsic parameters.

TODO: skew is not supported
TODO: cx and cy that are not half of width and height

Parameters
------------
name : str or None
  Name for camera to be used as node name
resolution : (2,) int
  Pixel size in (height, width)
focal : (2,) float
  Focal length in pixels. Either pass this OR FOV
  but not both.  focal = (K[0][0], K[1][1])
fov : (2,) float
  Field of view (fovx, fovy) in degrees
z_near : float
  What is the closest
Ncamera_   z$either focal length or FOV required!Fg      >@)r   	unique_iduppername
ValueError_focal_computedfocalfovroundastypenpint64
resolutionfloatz_farz_near)selfr   r   r   r   r   r   s          o/var/www/eduai.edurigo.com/storigo/production/storigo_env/lib/python3.13/site-packages/trimesh/scene/cameras.py__init__Camera.__init__	   s    2 <!$.."3"9"9";!<=DI I;5=CDD  % 
 ((T/00299"((CJ$ 5\
Fm    c                 
   [        [        R                  " U R                  5      [        R                  " U R                  5      [        R                  " U R
                  5      [        R                  " U R                  5      S9$ )z*
Safely get a copy of the current camera.
)r   r   r   r   )r   copydeepcopyr   r   r   r   r   s    r   r    Camera.copy?   sQ     tyy)}}T__5--

+dhh'	
 	
r   c                     U R                   $ )zp
Get the camera resolution in pixels.

Returns
------------
resolution (2,) float
  Camera resolution in pixels
)_resolutionr"   s    r   r   Camera.resolutionJ   s     r   c                     [         R                  " U[         R                  S9nUR                  S:w  a  [	        S5      eSUR
                  l        Xl        U R                  (       a  SU l	        gSU l
        g)zs
Set the camera resolution in pixels.

Parameters
------------
resolution (2,) float
  Camera resolution in pixels
dtyper   zresolution must be (2,) floatFN)r   
asanyarrayr   shaper   flags	writeabler%   r   _focal_fovr   valuess     r   r   r&   V   s[     vRXX6<<4<==!&!DK DIr   c                     U R                   c^  U R                  S[        R                  " [        R                  " U R
                  S-  5      5      -  -  nSUR                  l        Xl         U R                   $ )zr
Get the focal length in pixels for the camera.

Returns
------------
focal : (2,) float
  Focal length in pixels
       @F)r/   r%   r   tanradiansr0   r-   r.   )r   r   s     r   r   Camera.focall   sX     ;;$$bffRZZ		C5P.Q(QRE$)EKK!K{{r   c                     Uc  SU l         gSU l        [        R                  " U[        R                  S9nUR
                  S:w  a  [        S5      eSUR                  l        Xl         SU l	        g)zs
Set the focal length in pixels for the camera.

Returns
------------
focal : (2,) float
  Focal length in pixels.
NFr(   r*   zfocal length must be (2,) float)
r/   r   r   r+   float64r,   r   r-   r.   r0   r1   s     r   r   r7   ~   s^     >DK
 $)D ]]6<F||t# !BCC%*FLL" KDIr   c                     [         R                  " S[         R                  S9nU R                  S   US'   U R                  S   US'   U R                  S-  USS	2S	4'   U$ )
zu
Get the intrinsic matrix for the Camera object.

Returns
-----------
K : (3, 3) float
  Intrinsic matrix for camera
   r(   r   r   r      r=   r=   r4   Nr   )r   eyer9   r   r   )r   Ks     r   r@   Camera.K   sY     FF1BJJ'**Q-$**Q-$??S("1"a%r   c                 @   Uc  g [         R                  " U[         R                  S9nUR                  S:w  a  [	        S5      e[         R
                  " UR                  5       / SQ   / SQ5      (       d  [	        S5      eUS   US   /U l        US S	2S	4   S	-  U l        g )
Nr(   )r;   r;   zmatrix must be (3,3)!)r=   r;   r
      r   )r   r   r   r   r=   z4matrix should only have focal length and resolution!r<   r>   r   )	r   r+   r9   r,   r   allcloseflattenr   r   r1   s     r   r@   rA      s    >vRZZ8<<6!455{{6>>+O<oNNSTT TlF4L1
 !Q-!+r   c                     U R                   c^  S[        R                  " [        R                  " U R                  S-  U R
                  -  5      5      -  nSUR                  l        Xl         U R                   $ )zi
Get the field of view in degrees.

Returns
-------------
fov : (2,) float
  XY field of view in degrees
r4   F)r0   r   degreesarctanr%   r/   r-   r.   )r   r   s     r   r   
Camera.fov   sY     99

299d.>.>.D-S#TUUC"'CIIIyyr   c                     Uc  SU l         gSU l        [        R                  " U[        R                  S9nUR
                  S:w  a  [        S5      eSUR                  l        Xl         SU l	        g)zq
Set the field of view in degrees.

Parameters
-------------
values : (2,) float
  Size of FOV to set in degrees
NTr(   r*   zfov length must be (2,) intF)
r0   r   r   r+   r9   r,   r   r-   r.   r/   r1   s     r   r   rI      s^     >DI
 $(D ]]6<F||t# !>??%*FLL"IDKr   c                     [        U 5      $ )z
Calculate ray direction vectors.

Will return one ray per pixel, as set in self.resolution.

Returns
--------------
vectors : (n, 3) float
  Ray direction vectors in camera frame with z == -1
)camera_to_raysr"   s    r   to_raysCamera.to_rays   s     d##r   c                 B    [         R                  " [        U 5      * 5      $ )z
Get ray spherical coordinates in radians.


Returns
--------------
angles : (n, 2) float
  Ray spherical coordinate angles in radians.
)r   rH   ray_pixel_coordsr"   s    r   anglesCamera.angles   s     yy*40011r   c                 2    [        U4SU R                  0UD6$ )a  
Generate transform for a camera to keep a list
of points in the camera's field of view.

Parameters
-------------
points : (n, 3) float
  Points in space
rotation : None, or (4, 4) float
  Rotation matrix for initial rotation
distance : None or float
  Distance from camera to center
center : None, or (3,) float
  Center of field of view.

Returns
--------------
transform : (4, 4) float
  Transformation matrix from world to camera
r   )look_atr   )r   pointskwargss      r   rT   Camera.look_at   s    * v64886v66r   c                 :    SU R                    SU R                   3$ )Nz<trimesh.scene.Camera> FOV: z Resolution: )r   r   r"   s    r   __repr__Camera.__repr__  s    -dhhZ}T__DUVVr   )
r/   r   r0   r%   r   r   r   r   r   r   )NNNNg{Gz?g     @@)__name__
__module____qualname____firstlineno__r   r    propertyr   setterr   r@   r   rM   rQ   rT   rY   __static_attributes__ r   r   r   r      s    SY4$l	
 	  	   *  " \\ 2   XX, ,   	ZZ 2$
27.Wr   r   c                 R   Uc  [         R                  " S5      nO#[         R                  " U[         R                  S9n[         R                  " U [         R                  S9n USS2SS24   R                  nUR                  U R                  5      R                  nUc)  UR                  SS9S[         R                  " USS9-  -   nOUR                  U5      nXx-  n[         R                  " [         R                  " U5      S-  5      n	UcU  [         R                  " [         R                  " USS2SS	24   5      U	-  USS2S	4   SS2[         R                  4   -   5      nUb  X5-  nUSS2SS24   R                  U5      n
UR                  5       nXUSS2S	4   -  -   USS2S4'   U$ )
ac  
Generate transform for a camera to keep a list
of points in the camera's field of view.

Examples
------------
```python
points = np.array([0, 0, 0], [1, 1, 1])
scene.camera_transform = scene.camera.look_at(points)
```

Parameters
-------------
points : (n, 3) float
  Points in space
fov : (2,) float
  Field of view, in DEGREES
rotation : None, or (4, 4) float
  Rotation matrix for initial rotation
distance : None or float
  Distance from camera to center
center : None, or (3,) float
  Center of field of view.

Returns
--------------
transform : (4, 4) float
  Transformation matrix from world to camera
N   r(   r;   r   )axisg      ?r4   r   )r   r?   r+   r9   Tdotminptpr5   r6   maxabsnewaxisr    )rU   r   rotationdistancecenterpadrinvpoints_ccenter_ctfovcenter_wcam_poses               r   rT   rT     s   > 66!9==<]]64F BQBFDxx!##H~<<Q<'#xa0H*HH 88F# H 66"**S/C'(D66"&&!RaR%1D88AqD>!RZZ-;XXY
 BQB##H-H}}HHRaRUO!;;HRaRUOOr   c                    U R                   n[        R                  " U R                  5      S-  n[        R                  " U5      nUSSU-  -
  -  nU* nUu  pVUu  px[
        R                  " Xv/XX//U R                   S9n	[
        R                  " SUS   S-
  /US   S-
  S//US9R                  [        R                  5      n
U	R                  U
R                  :X  d   eX4$ )aZ  
Get the x-y coordinates of rays in camera coordinates at
z == -1.

One coordinate pair will be given for each pixel as defined in
camera.resolution. If reshaped, the returned array corresponds
to pixels of the rendered image.

Examples
------------
```python
xy = ray_pixel_coords(camera).reshape(
  tuple(camera.coordinates) + (2,))
top_left == xy[0, 0]
bottom_right == xy[-1, -1]
```

Parameters
--------------
camera : trimesh.scene.Camera
  Camera object to generate rays from

Returns
--------------
xy : (n, 2) float
  x-y coordinates of intersection of each camera ray
  with the z == -1 frame
r4   r=   g      ?)boundscountr   )
r   r   r6   r   r5   r   grid_linspacer   r   r,   )camerareshalf_fov	right_topleft_bottomrighttopleftbottomxypixelss              r   rP   rP   [  s    < 

Czz&**%+Hx IcCi I*K JELD 
		e_-V5F5F
B
 CFQJ#a&1*a1fRXX  88v||###:r   r{   c                     [        U 5      u  p[        R                  " [        R                  " U[        R
                  " USS2SS24   5      * 45      5      nX24$ )a  
Calculate the trimesh.scene.Camera object to direction vectors.

Will return one ray per pixel, as set in camera.resolution.

Parameters
--------------
camera : trimesh.scene.Camera

Returns
--------------
vectors : (n, 3) float
  Ray direction vectors in camera frame with z == -1
Nr=   )rP   r   unitizer   column_stack	ones_like)r{   r   r   vectorss       r   rL   rL     sL      "&)JBll2??BbBQBi1H0H+IJKG?r   )NNNN)	r    numpyr    r   r   rT   rP   rL   rb   r   r   <module>r      s6      KW KW\BJ6r6 r   