o
    i                     @   s8  d dl Z d dlmZmZ d dlmZ d dlZd dlm	Z	 d dl
mZ d dlmZ d dlmZmZ d dlmZ dd	d
ddd
ddd
dZ	d+dededee fddZ										d,dededeej deej deeeef  dee d ed! d"ed# d$eed  d%ee d&ee d'ed d(dfd)d*ZdS )-    N)LiteralOptional) run_renderer_in_chunk_w_trj_mode)
Prediction)save_gaussian_ply)hcatvcat)vis_depth_map_tensorZ28Zveryfast)crfpresetZ23mediumZ18slow)lowr   high   
prediction
export_dirgs_views_intervalc                 C   s   | j }t| jd|j}d}tjtj	
|ddd tj	
|d|dd}|d u r8t|jd d	 d
}t|||dd|ddddd
 d S )Nr   gs_plyTexist_okzgs_ply/04dz.ply   r   Fg?)
	gaussians	save_pathZ	ctx_depthZshift_and_scaleZsave_sh_dc_onlyr   Zinv_opacityZprune_by_depth_percentZprune_border_gsZmatch_3dgs_mcmc_dev)r   torch
from_numpydepth	unsqueezetomeansosmakedirspathjoinmaxshaper   )r   r   r   gs_worldZ
pred_depthidxr    r*   >/data/cameron/da3_repo/src/depth_anything_3/utils/export/gs.pyexport_to_gs_ply!   s&   
r,      extendRGB+EDr   Tr   
extrinsics
intrinsicsout_image_hw
chunk_sizetrj_mode)originalZsmoothinterpolateZinterpolate_smoothwanderZ
dolly_zoomr.   Zwobble_inter
color_mode)zRGB+Dr/   	vis_depthenable_tqdmoutput_namevideo_qualityreturnc                    s  | j }|d ur
|}n)t| jd|j}| jr3| j}|d ur3|d d d d d ddf  |  < |d ur9|nt| j	d|j}|d urO|\}}n
| j
jdd  \}}|jd dkrbd}t|||||f||d||	d	\}}dt| d	 d
t| d ddg}tjtj|ddd t|jd D ]i}|| }|d urt|d }|dkrtnt t fddt||D }t|ddd  dddd  }d}tj||d}|
d u r|dd| n|
}
tj|d|
 d}|j |dd||d qd S )Nr      r   r7   T)	r   r0   r1   Zimage_shaper3   r4   Zuse_shr8   r:   z-crfr
   z-presetr   z-pix_fmtZyuv420pgs_videor   r   c                    s   g | ]	\}} ||qS r*   r*   ).0cdZcat_fnr*   r+   
<listcomp>   s    z&export_to_gs_video.<locals>.<listcomp>         )fpsr   _z	gs_video/z.mp4Zlibx264F)codecaudiorI   ffmpeg_params)!r   r   r   r0   r   r    r!   	is_metricscale_factorr1   r   r'   r   VIDEO_QUALITY_MAPr"   r#   r$   r%   ranger	   r   r   stackziplistclampbytepermutecpunumpympyZImageSequenceClipZwrite_videofile)r   r   r0   r1   r2   r3   r4   r8   r9   r:   r;   r<   r(   Z	tgt_extrsrO   Z	tgt_intrsHWcolorr   rM   r)   Zvideo_iZdepth_iframesrI   clipr   r*   rD   r+   export_to_gs_video=   sr   $



	&r`   )r   )
NNNr-   r.   r/   r   TNr   )r"   typingr   r   Zmoviepy.editorZeditorrZ   r   Z(depth_anything_3.model.utils.gs_rendererr   depth_anything_3.specsr   Z$depth_anything_3.utils.gsply_helpersr   Z%depth_anything_3.utils.layout_helpersr   r   Z depth_anything_3.utils.visualizer	   rP   strintr,   Tensortupleboolr`   r*   r*   r*   r+   <module>   s|   


