a
    d                     @   s>   d dl Z d dlZeejddddZd	eeejdddZdS )
    N)filename
pointcloudreturnc              	   C   s  t | ts(| dd dkr(td| t|sDtdt| t|jdksp|jd dkrptd|j|	dd}t
| d	}d
}|jd }t|D ]f}|| }tt| s|d8 }q|d  }|d  }	|d  }
|| d|	 d|
 d7 }q|d |d |d |d|  |d |d |d |d || W d   n1 sz0    Y  dS )aV  Utility function to save to disk a pointcloud in PLY format.

    Args:
        filename: the path to save the pointcloud.
        pointcloud: tensor containing the pointcloud to save.
          The tensor must be in the shape of :math:`(*, 3)` where the last
          component is assumed to be a 3d point coordinate :math:`(X, Y, Z)`.
    N.plyCInput filename must be a string in with the .ply  extension. Got {}z1Input pointcloud type is not a torch.Tensor. Got    z>Input pointcloud must be in the following shape HxWx3. Got {}.w r          
zply
zformat ascii 1.0
zcomment arraiy generated
zelement vertex %d
zproperty double x
zproperty double y
zproperty double z
zend_header
)
isinstancestr	TypeErrorformattorchZ	is_tensortypelenshapeZreshapeopenrangeboolisfiniteanyitemwrite)r   r   Zxyz_vecfZdata_strZ
num_pointsidxZxyzxyz r$   c/var/www/html/stable-diffusion-webui/venv/lib/python3.9/site-packages/kornia/utils/pointcloud_io.pysave_pointcloud_ply   s8    	








r&      )r   header_sizer   c           
   
   C   s   t | ts(| dd dkr(td| tj| s<tdt |trN|dks^td| dt	| x}g }|
 |d }|D ]@}| \}}}|tt|tt|tt|f qt|}	|	W  d   S 1 s0    Y  dS )	ak  Utility function to load from disk a pointcloud in PLY format.

    Args:
        filename: the path to the pointcloud.
        header_size: the size of the ply file header that will
          be skipped during loading.

    Return:
        tensor containing the loaded point with shape :math:`(*, 3)` where
        :math:`*` represents the number of points.
    r   Nr   r   z'Input filename is not an existing file.r   z2Input header_size must be a positive integer. Got .)r   r   r   r   ospathisfile
ValueErrorintr   	readlinessplitappendr   Ztensorfloat)
r   r(   r   ZpointslineslineZx_strZy_strZz_strr   r$   r$   r%   load_pointcloud_ply3   s    
0
r5   )r'   )r*   r   r   ZTensorr&   r.   r5   r$   r$   r$   r%   <module>   s   -