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

Function get_rays

run_nerf_helpers.py:162–171  ·  view source on GitHub ↗
(H, W, focal, c2w)

Source from the content-addressed store, hash-verified

160
161# Ray helpers
162def get_rays(H, W, focal, c2w):
163 i, j = torch.meshgrid(torch.linspace(0, W-1, W), torch.linspace(0, H-1, H)) # pytorch's meshgrid has indexing='ij'
164 i = i.t()
165 j = j.t()
166 dirs = torch.stack([(i-W*.5)/focal, -(j-H*.5)/focal, -torch.ones_like(i)], -1)
167 # Rotate ray directions from camera frame to the world frame
168 rays_d = torch.sum(dirs[..., np.newaxis, :] * c2w[:3,:3], -1) # dot product, equals to: [c2w.dot(dir) for dir in dirs]
169 # Translate camera frame's origin to the world frame. It is the origin of all rays.
170 rays_o = c2w[:3,-1].expand(rays_d.shape)
171 return rays_o, rays_d
172
173
174def get_rays_np(H, W, focal, c2w):

Callers 1

renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected