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

Function get_rays

script/models/ray_utils.py:5–15  ·  view source on GitHub ↗
(H, W, focal, c2w)

Source from the content-addressed store, hash-verified

3
4# Ray helpers
5def get_rays(H, W, focal, c2w):
6 i, j = torch.meshgrid(torch.linspace(0, W-1, W), torch.linspace(0, H-1, H), indexing='ij') # pytorch's meshgrid has indexing='ij'
7 i = i.t()
8 j = j.t()
9 dirs = torch.stack([(i-W*.5)/focal, -(j-H*.5)/focal, -torch.ones_like(i)], -1)
10
11 # Rotate ray directions from camera frame to the world frame
12 rays_d = torch.sum(dirs[..., np.newaxis, :] * c2w[:3,:3], -1) # dot product, equals to: [c2w.dot(dir) for dir in dirs]
13 # Translate camera frame's origin to the world frame. It is the origin of all rays.
14 rays_o = c2w[:3,-1].expand(rays_d.shape)
15 return rays_o, rays_d # rays_o (100,100,3), rays_d (100,100,3)
16
17
18def get_rays_np(H, W, focal, c2w):

Callers 5

prepare_batch_renderFunction · 0.90
prepare_batch_renderFunction · 0.90
train_on_feature_batchFunction · 0.90
train_on_epoch_nerfwFunction · 0.85
renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected