(H, W, focal, chunk=1024*32, rays=None, c2w=None, ndc=True,
near=0., far=1.,
use_viewdirs=False, c2w_staticcam=None, img_idx=torch.Tensor(0),
**kwargs)
| 351 | return all_ret |
| 352 | |
| 353 | def render(H, W, focal, chunk=1024*32, rays=None, c2w=None, ndc=True, |
| 354 | near=0., far=1., |
| 355 | use_viewdirs=False, c2w_staticcam=None, img_idx=torch.Tensor(0), |
| 356 | **kwargs): |
| 357 | if c2w is not None: |
| 358 | # special case to render full image |
| 359 | rays_o, rays_d = get_rays(H, W, focal, c2w) |
| 360 | else: |
| 361 | # use provided ray batch |
| 362 | rays_o, rays_d = rays |
| 363 | |
| 364 | if use_viewdirs: |
| 365 | # provide ray directions as input |
| 366 | viewdirs = rays_d |
| 367 | if c2w_staticcam is not None: |
| 368 | # special case to visualize effect of viewdirs |
| 369 | rays_o, rays_d = get_rays(H, W, focal, c2w_staticcam) |
| 370 | viewdirs = viewdirs / torch.norm(viewdirs, dim=-1, keepdim=True) |
| 371 | viewdirs = torch.reshape(viewdirs, [-1,3]).float() |
| 372 | |
| 373 | sh = rays_d.shape # [..., 3] |
| 374 | if ndc: |
| 375 | # for forward facing scenes |
| 376 | rays_o, rays_d = ndc_rays(H, W, focal, 1., rays_o, rays_d) |
| 377 | |
| 378 | # Create ray batch |
| 379 | rays_o = torch.reshape(rays_o, [-1,3]).float() |
| 380 | rays_d = torch.reshape(rays_d, [-1,3]).float() |
| 381 | near, far = near * torch.ones_like(rays_d[...,:1]), far * torch.ones_like(rays_d[...,:1]) |
| 382 | rays = torch.cat([rays_o, rays_d, near, far], -1) |
| 383 | if use_viewdirs: |
| 384 | rays = torch.cat([rays, viewdirs], -1) # [1024, 11] |
| 385 | |
| 386 | # for NeRFW, we need to add frame index as input |
| 387 | if img_idx.shape[0] != rays.shape[0]: |
| 388 | img_idx = img_idx.repeat(rays.shape[0],1) # [1024, 1] |
| 389 | rays = torch.cat([rays, img_idx], 1) # [1024, 12] |
| 390 | |
| 391 | # Render and reshape |
| 392 | all_ret = batchify_rays(rays, chunk, **kwargs) |
| 393 | for k in all_ret: |
| 394 | k_sh = list(sh[:-1]) + list(all_ret[k].shape[1:]) |
| 395 | all_ret[k] = torch.reshape(all_ret[k], k_sh) |
| 396 | |
| 397 | k_extract = ['rgb_map', 'disp_map', 'acc_map'] |
| 398 | ret_list = [all_ret[k] for k in k_extract] |
| 399 | ret_dict = {k : all_ret[k] for k in all_ret if k not in k_extract} |
| 400 | return ret_list + [ret_dict] |
| 401 | |
| 402 | ### This is for validation ### |
| 403 | def render_path(args, render_poses, hwf, chunk, render_kwargs, gt_imgs=None, savedir=None, render_factor=0, single_gt_img=False, img_ids=torch.Tensor(0)): |
no test coverage detected