(H, W, focal, c2w)
| 16 | |
| 17 | |
| 18 | def get_rays_np(H, W, focal, c2w): |
| 19 | i, j = np.meshgrid(np.arange(W, dtype=np.float32), np.arange(H, dtype=np.float32), indexing='xy') |
| 20 | dirs = np.stack([(i-W*.5)/focal, -(j-H*.5)/focal, -np.ones_like(i)], -1) |
| 21 | # Rotate ray directions from camera frame to the world frame |
| 22 | rays_d = np.sum(dirs[..., np.newaxis, :] * c2w[:3,:3], -1) # dot product, equals to: [c2w.dot(dir) for dir in dirs] |
| 23 | # Translate camera frame's origin to the world frame. It is the origin of all rays. |
| 24 | rays_o = np.broadcast_to(c2w[:3,-1], np.shape(rays_d)) |
| 25 | return rays_o, rays_d |
| 26 | |
| 27 | def ndc_rays(H, W, focal, near, rays_o, rays_d): |
| 28 | # Shift ray origins to near plane |
nothing calls this directly
no outgoing calls
no test coverage detected