MCPcopy Index your code
hub / github.com/ActiveVisionLab/DFNet / render

Function render

script/models/rendering.py:353–400  ·  view source on GitHub ↗
(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)

Source from the content-addressed store, hash-verified

351 return all_ret
352
353def 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 ###
403def 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)):

Callers 10

eval_on_batchFunction · 0.90
train_on_batchFunction · 0.90
save_val_result_7ScenesFunction · 0.90
render_nerfw_imgsFunction · 0.90
render_virtual_imgsFunction · 0.90
eval_on_batchFunction · 0.90
train_on_feature_batchFunction · 0.90
train_on_batchFunction · 0.90
train_on_epoch_nerfwFunction · 0.85
render_pathFunction · 0.85

Calls 3

get_raysFunction · 0.85
ndc_raysFunction · 0.85
batchify_raysFunction · 0.85

Tested by

no test coverage detected