
    l0j&                         d Z ddlZddlZddlmZmZ ddlmZ ddlm	Z	 ddl
mZ ddlmZmZmZmZmZ dd	lmZ  G d
 de          Z G d de          ZdS )zT
parent.py
-------------

The base class for Trimesh, PointCloud, and Scene objects
    N   )boundscaching)transformations)cache_decorator)tol)Any	ArrayLikeDictNDArrayOptional)ABCc                   *   e Zd ZU dZeed<   eej        de	e
j                 fd                        Zeej        de	e
j                 fd                        Zej        dedefd            Zeej        defd                        Zd	 Zej        d
             Zej        d             Zej        d             Zej        dd            Zd ZdefdZd Zd Zedefd            Zedee          fd            Z!e!j"        de ddfd            Z!dS )Geometryz
    `Geometry` is the parent class for all geometry.

    By decorating a method with `abc.abstractmethod` it means
    the objects that inherit from `Geometry` MUST implement
    those methods.
    metadatareturnc                     d S N selfs    Q/home/wildlama/miniconda3/envs/lam/lib/python3.11/site-packages/trimesh/parent.pyr   zGeometry.bounds    	     	    c                     d S r   r   r   s    r   extentszGeometry.extents%   r   r   matrixc                     d S r   r   )r   r   s     r   apply_transformzGeometry.apply_transform*       r   c                     d S r   r   r   s    r   is_emptyzGeometry.is_empty.   r   r   c                 4    | j                                         S )z
        Get a hash of the current geometry.

        Returns
        ---------
        hash : int
          Hash of current graph and geometry.
        )_data__hash__r   s    r   r%   zGeometry.__hash__3   s     z""$$$r   c                     d S r   r   r   s    r   copyzGeometry.copy>   r    r   c                     d S r   r   r   s    r   showzGeometry.showB   r    r   c                     d S r   r   r   others     r   __add__zGeometry.__add__F   r    r   Nc                     d S r   r   )r   file_obj	file_types      r   exportzGeometry.exportJ   r    r   c                    g }t          | d          r"|                    d| j        j                    t          | d          r"|                    d| j        j                    t          | d          rDt          | j        t                    r*|                    dt          | j                              dt          |           j
        v r/|                    t          | j                  dd	                    d
| j        v r&| j        d
         }|                    d| d           d                    t          |           j
        d                    |                    S )z
        Print quick summary of the current geometry without
        computing properties.

        Returns
        -----------
        repr : str
          Human readable quick look at the geometry.
        verticeszvertices.shape=faceszfaces.shape=geometryzlen(geometry)=Voxelr   	file_namezname=``z<trimesh.{}({})>z, )hasattrappendr3   shaper4   
isinstancer5   dictlentype__name__strr   formatjoin)r   elementsdisplays      r   __repr__zGeometry.__repr__N   sS    4$$ 	EOOCdm.ACCDDD4!! 	?OO=4:+;==>>>4$$ 	CDM4)H)H 	COOAS-?-?AABBBd4jj)))OOC
OOAbD1222$-''mK0GOO/W///000!((d)<dii>Q>QRRRr   translationc                 @   t          j        |t           j                  }|j        dk    r(|                     t          j        |                    S |j        dk    rt          d          t          j        d          }||dddf<   |                     |          S )	z
        Translate the current mesh.

        Parameters
        ----------
        translation : (3,) float
          Translation in XYZ
        )dtype)   )offset)   z!Translation must be (3,) or (2,)!   NrM   )	np
asanyarrayfloat64r<   r   tfplanar_matrix
ValueErroreye)r   rH   r   s      r   apply_translationzGeometry.apply_translationj   s     mKrzBBB$$''(8(L(L(LMMM$&&@AAA #rr1u##F+++r   c                 V    t          j        |          }|                     |          S )z
        Scale the mesh.

        Parameters
        ----------
        scaling : float or (3,) float
          Scale factor to apply to the mesh
        )scale)rR   scale_and_translater   )r   scalingr   s      r   apply_scalezGeometry.apply_scale   s+     'g666##F+++r   c                 h    |dk    r| S |                       t          |           |                    S )aR  
        Concatenate the geometry allowing concatenation with
        built in `sum()` function:
          `sum(Iterable[trimesh.Trimesh])`

        Parameters
        ------------
        other : Geometry
          Geometry or 0

        Returns
        ----------
        concat : Geometry
          Geometry of combined result
        r   )r-   r@   r+   s     r   __radd__zGeometry.__radd__   s4    " A::K||JDJJu--...r   c                     | j         dS t          | j         dz                                  dz            }|t          j        k     rdS |S )a  
        A loosely specified "order of magnitude scale" for the
        geometry which always returns a value and can be used
        to make code more robust to large scaling differences.

        It returns the diagonal of the axis aligned bounding box
        or if anything is invalid or undefined, `1.0`.

        Returns
        ----------
        scale : float
          Approximate order of magnitude scale of the geometry.
        Ng      ?rK   g      ?)r   floatsumr   zero)r   rX   s     r   rX   zGeometry.scale   sN      <3 t|Q++--455383r   c                 8    | j                             dd          S )z
        Definition of units for the mesh.

        Returns
        ----------
        units : str
          Unit system mesh is in, or None if not defined
        unitsN)r   getr   s    r   rc   zGeometry.units   s     }  $///r   valuec                 |    t          |                                                                          | j        d<   dS )z7
        Define the units of the current mesh.
        rc   N)rB   lowerstripr   )r   re   s     r   rc   zGeometry.units   s4    
 "%U!1!1!3!3!9!9!;!;gr   r   )#rA   
__module____qualname____doc__r   __annotations__propertyabcabstractmethodr   rO   rQ   r   r   r
   r	   r   boolr"   r%   r'   r)   r-   r1   rG   rV   r[   r]   r   r_   rX   r   rB   rc   setterr   r   r   r   r      se          NNN
+     X ,     X 	i C     $     X	% 	% 	% 	   	   	   	   S S S8,Y , , , ,*, , ,/ / /. u    _2 	0x} 	0 	0 	0 X	0 \<3 <4 < < < \< < <r   r   c                       e Zd ZdZej        d             Zej        d             Zej        d             Zej        d             Z	ej        d             Z
d ZdS )	
Geometry3Dz
    The `Geometry3D` object is the parent object of geometry objects
    which are three dimensional, including Trimesh, PointCloud,
    and Scene objects.
    c                     ddl m} t          j        d          }| j                            d          |dddf<   |                    || j        d	          S )
a  
        An axis aligned bounding box for the current mesh.

        Returns
        ----------
        aabb : trimesh.primitives.Box
          Box object with transform and extents defined
          representing the axis aligned bounding box of the mesh
        r   )
primitivesrN   r   )axisNrM   F	transformr   mutable) ru   rO   rU   r   meanBoxr   )r   ru   rx   s      r   bounding_boxzGeometry3D.bounding_box   sc     	!     F1II	;+++33	"1"a%~~	4<QV~WWWr   c                     ddl m}m}  |j        |           \  }}|                    t
          j                            |          |d          S )a  
        An oriented bounding box for the current mesh.

        Returns
        ---------
        obb : trimesh.primitives.Box
          Box object with transform and extents defined
          representing the minimum volume oriented
          bounding box of the mesh
        r   r   ru   Frw   )rz   r   ru   oriented_boundsr|   rO   linalginv)r   r   ru   	to_originr   s        r   bounding_box_orientedz Geometry3D.bounding_box_oriented   sc     	)(((((((3V3D99	7~~immI..  
 
 	
r   c                 r    ddl m}m} |                    |           \  }}|                    ||d          S )a  
        A minimum volume bounding sphere for the current mesh.

        Note that the Sphere primitive returned has an unpadded
        exact `sphere_radius` so while the distance of every vertex
        of the current mesh from sphere_center will be less than
        sphere_radius, the faceted sphere primitive may not
        contain every vertex.

        Returns
        --------
        minball : trimesh.primitives.Sphere
          Sphere primitive containing current mesh
        r   )nsphereru   F)centerradiusry   )rz   r   ru   minimum_nsphereSphere)r   r   ru   r   r   s        r   bounding_spherezGeometry3D.bounding_sphere   sN      	*))))))) 0066  vu MMMr   c                 P    ddl m}m}  |j        |           } |j        dddi|S )z
        A minimum volume bounding cylinder for the current mesh.

        Returns
        --------
        mincyl : trimesh.primitives.Cylinder
          Cylinder primitive containing current mesh
        r   r   ry   Fr   )rz   r   ru   minimum_cylinderCylinder)r   r   ru   kwargss       r   bounding_cylinderzGeometry3D.bounding_cylinder  sL     	)(((((((((.."z";;5;F;;;r   c                 v    | j         | j        | j        g}t          j        d |D                       }||         S )aM  
        The minimum volume primitive (box, sphere, or cylinder) that
        bounds the mesh.

        Returns
        ---------
        bounding_primitive : object
          Smallest primitive which bounds the mesh:
          trimesh.primitives.Sphere
          trimesh.primitives.Box
          trimesh.primitives.Cylinder
        c                     g | ]	}|j         
S r   )volume).0is     r   
<listcomp>z1Geometry3D.bounding_primitive.<locals>.<listcomp>5  s    :::Q:::r   )r   r   r   rO   argmin)r   options
volume_mins      r   bounding_primitivezGeometry3D.bounding_primitive"  sH     & "

 Y::':::;;
z""r   c                 j   t           j        rt          | d          r| j        }t	          j        | fi |\  }}|                     |           t           j        rYt          | d          r-t          | dd          rt          j	        | j        |          sJ t          j
        | j        |          sJ |S )a  
        Apply the oriented bounding box transform to the current mesh.

        This will result in a mesh with an AABB centered at the
        origin and the same dimensions as the OBB.

        Parameters
        ------------
        kwargs
          Passed through to `bounds.oriented_bounds`

        Returns
        ----------
        matrix : (4, 4) float
          Transformation matrix that was applied
          to mesh to move it into OBB frame
        r   is_watertightF)r   strictr:   r   r   r   r   getattrrO   iscloseallcloser   )r   r   r   r   r   s        r   	apply_obbzGeometry3D.apply_obb8  s    & : 	!'$11 	![F !0@@@@V$$$: 	6tX&& 774%+P+P 7z$+v66666;t|W55555r   N)rA   ri   rj   rk   r   r   r}   r   r   r   r   r   r   r   r   rs   rs      s          X X X$ 
 
 
$ N N N( < < < # # #*" " " " "r   rs   )rk   rn   numpyrO   rz   r   r   r   rR   r   	constantsr   typedr	   r
   r   r   r   utilr   r   rs   r   r   r   <module>r      s!    


             # # # # # # $ $ $ $ $ $       : : : : : : : : : : : : : :      z< z< z< z< z<s z< z< z<zI I I I I I I I I Ir   