MCPcopy Create free account
hub / github.com/ActiveVisionLab/DFNet / ndc_rays

Function ndc_rays

script/models/ray_utils.py:27–44  ·  view source on GitHub ↗
(H, W, focal, near, rays_o, rays_d)

Source from the content-addressed store, hash-verified

25 return rays_o, rays_d
26
27def ndc_rays(H, W, focal, near, rays_o, rays_d):
28 # Shift ray origins to near plane
29 t = -(near + rays_o[...,2]) / rays_d[...,2] # t_n = −(n + o_z)/d_z move o to the ray's intersection with near plane
30 rays_o = rays_o + t[...,None] * rays_d
31
32 # Projection Formular (20)
33 o0 = -1./(W/(2.*focal)) * rays_o[...,0] / rays_o[...,2]
34 o1 = -1./(H/(2.*focal)) * rays_o[...,1] / rays_o[...,2]
35 o2 = 1. + 2. * near / rays_o[...,2]
36 # Formular (21)
37 d0 = -1./(W/(2.*focal)) * (rays_d[...,0]/rays_d[...,2] - rays_o[...,0]/rays_o[...,2])
38 d1 = -1./(H/(2.*focal)) * (rays_d[...,1]/rays_d[...,2] - rays_o[...,1]/rays_o[...,2])
39 d2 = -2. * near / rays_o[...,2]
40
41 rays_o = torch.stack([o0,o1,o2], -1) # o'
42 rays_d = torch.stack([d0,d1,d2], -1) # d'
43
44 return rays_o, rays_d

Callers 1

renderFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected