MCPcopy Create free account
hub / github.com/LeapLabTHU/ActiveNeRF / render

Function render

run_nerf.py:68–133  ·  view source on GitHub ↗

Render rays Args: H: int. Height of image in pixels. W: int. Width of image in pixels. focal: float. Focal length of pinhole camera. chunk: int. Maximum number of rays to process simultaneously. Used to control maximum memory usage. Does not affect final res

(H, W, focal, chunk=1024*32, rays=None, c2w=None, ndc=True,
                  near=0., far=1.,
                  use_viewdirs=False, c2w_staticcam=None,
                  **kwargs)

Source from the content-addressed store, hash-verified

66
67
68def render(H, W, focal, chunk=1024*32, rays=None, c2w=None, ndc=True,
69 near=0., far=1.,
70 use_viewdirs=False, c2w_staticcam=None,
71 **kwargs):
72 """Render rays
73 Args:
74 H: int. Height of image in pixels.
75 W: int. Width of image in pixels.
76 focal: float. Focal length of pinhole camera.
77 chunk: int. Maximum number of rays to process simultaneously. Used to
78 control maximum memory usage. Does not affect final results.
79 rays: array of shape [2, batch_size, 3]. Ray origin and direction for
80 each example in batch.
81 c2w: array of shape [3, 4]. Camera-to-world transformation matrix.
82 ndc: bool. If True, represent ray origin, direction in NDC coordinates.
83 near: float or array of shape [batch_size]. Nearest distance for a ray.
84 far: float or array of shape [batch_size]. Farthest distance for a ray.
85 use_viewdirs: bool. If True, use viewing direction of a point in space in model.
86 c2w_staticcam: array of shape [3, 4]. If not None, use this transformation matrix for
87 camera while using other c2w argument for viewing directions.
88 Returns:
89 rgb_map: [batch_size, 3]. Predicted RGB values for rays.
90 disp_map: [batch_size]. Disparity map. Inverse of depth.
91 acc_map: [batch_size]. Accumulated opacity (alpha) along a ray.
92 extras: dict with everything returned by render_rays().
93 """
94 if c2w is not None:
95 # special case to render full image
96 rays_o, rays_d = get_rays(H, W, focal, c2w)
97 else:
98 # use provided ray batch
99 rays_o, rays_d = rays
100
101 if use_viewdirs:
102 # provide ray directions as input
103 viewdirs = rays_d
104 if c2w_staticcam is not None:
105 # special case to visualize effect of viewdirs
106 rays_o, rays_d = get_rays(H, W, focal, c2w_staticcam)
107 viewdirs = viewdirs / torch.norm(viewdirs, dim=-1, keepdim=True)
108 viewdirs = torch.reshape(viewdirs, [-1,3]).float()
109
110 sh = rays_d.shape # [..., 3]
111 if ndc:
112 # for forward facing scenes
113 rays_o, rays_d = ndc_rays(H, W, focal, 1., rays_o, rays_d)
114
115 # Create ray batch
116 rays_o = torch.reshape(rays_o, [-1,3]).float()
117 rays_d = torch.reshape(rays_d, [-1,3]).float()
118
119 near, far = near * torch.ones_like(rays_d[...,:1]), far * torch.ones_like(rays_d[...,:1])
120 rays = torch.cat([rays_o, rays_d, near, far], -1)
121 if use_viewdirs:
122 rays = torch.cat([rays, viewdirs], -1)
123
124 # Render and reshape
125 all_ret = batchify_rays(rays, chunk, **kwargs)

Callers 3

render_pathFunction · 0.85
choose_new_kFunction · 0.85
trainFunction · 0.85

Calls 3

get_raysFunction · 0.85
ndc_raysFunction · 0.85
batchify_raysFunction · 0.85

Tested by

no test coverage detected