@@ -245,8 +245,8 @@ def project_cov3d_ewa(
245245 viewmat : Tensor ,
246246 fx : float ,
247247 fy : float ,
248- tan_fovx : float ,
249- tan_fovy : float ,
248+ lim_x : Tuple [ float , float ] ,
249+ lim_y : Tuple [ float , float ] ,
250250 is_valid : Optional [Tensor ] = None ,
251251) -> Tuple [Tensor , Tensor ]:
252252 assert mean3d .shape [- 1 ] == 3 , mean3d .shape
@@ -263,10 +263,8 @@ def project_cov3d_ewa(
263263 rz = 1.0 / t [..., 2 ] # (...,)
264264 rz2 = rz ** 2 # (...,)
265265
266- lim_x = 1.3 * torch .tensor ([tan_fovx ], device = mean3d .device )
267- lim_y = 1.3 * torch .tensor ([tan_fovy ], device = mean3d .device )
268- x_clamp = t [..., 2 ] * torch .clamp (t [..., 0 ] * rz , min = - lim_x , max = lim_x )
269- y_clamp = t [..., 2 ] * torch .clamp (t [..., 1 ] * rz , min = - lim_y , max = lim_y )
266+ x_clamp = t [..., 2 ] * torch .clamp (t [..., 0 ] * rz , min = - lim_x [1 ], max = lim_x [0 ])
267+ y_clamp = t [..., 2 ] * torch .clamp (t [..., 1 ] * rz , min = - lim_y [1 ], max = lim_y [0 ])
270268 t = torch .stack ([x_clamp , y_clamp , t [..., 2 ]], dim = - 1 )
271269
272270 O = torch .zeros_like (rz )
@@ -352,7 +350,7 @@ def project_pix(fxfy, p_view, center, eps=1e-6):
352350 return torch .stack ([u , v ], dim = - 1 )
353351
354352
355- def clip_near_plane (p , viewmat , clip_thresh = 0.01 ):
353+ def clip_near_plane (p , viewmat , clip_thresh = 0.01 ) -> Tuple [ Tensor , Tensor ] :
356354 R = viewmat [:3 , :3 ]
357355 T = viewmat [:3 , 3 ]
358356 p_view = torch .einsum ("ij,nj->ni" , R , p ) + T [None ]
@@ -404,10 +402,12 @@ def project_gaussians_forward(
404402 fx , fy , cx , cy = intrins
405403 tan_fovx = 0.5 * img_size [0 ] / fx
406404 tan_fovy = 0.5 * img_size [1 ] / fy
405+ lim_x = ((img_size [0 ] - cx ) / fx + 0.3 * tan_fovx , cx / fx + 0.3 * tan_fovx )
406+ lim_y = ((img_size [1 ] - cy ) / fy + 0.3 * tan_fovy , cy / fy + 0.3 * tan_fovy )
407407 p_view , is_close = clip_near_plane (means3d , viewmat , clip_thresh )
408408 cov3d = scale_rot_to_cov3d (scales , glob_scale , quats )
409409 cov2d , compensation = project_cov3d_ewa (
410- means3d , cov3d , viewmat , fx , fy , tan_fovx , tan_fovy , ~ is_close
410+ means3d , cov3d , viewmat , fx , fy , lim_x , lim_y , ~ is_close
411411 )
412412 conic , radius , det_valid = compute_cov2d_bounds (cov2d , ~ is_close )
413413 xys = project_pix ((fx , fy ), p_view , (cx , cy ))
0 commit comments