code: def ray_to_samples(
      ray_batch,
      samples_per_ray,
      lindisp=False,
      perturb=0.0,
      device="cpu",
      append_t=None,
  ):
      """
      reference: https://github.com/yenchenlin/nerf-pytorch
      """
      rays_per_batch = ray_batch["origin"].shape[0]
      rays_o, rays_d = (
          ray_batch["origin"],
          ray_batch["direction"],
      )  # [rays_per_batch, 3] each
      near, far = ray_batch["near"], ray_batch["far"]  # [-1,1]
      assert near.shape[0] == far.shape[0] == rays_per_batch
  
      t_vals = torch.linspace(
          0.0, 1.0, steps=samples_per_ray, device=device
      )
      if not lindisp:
          z_vals = near * (1.0 - t_vals) + far * (t_vals)
      else:
          z_vals = 1.0 / (
              1.0 / near * (1.0 - t_vals) + 1.0 / far * (t_vals)
          )
  
      if perturb > 0.0:
          # get intervals between samples
          mids = 0.5 * (z_vals[..., 1:] + z_vals[..., :-1])
          upper = torch.cat([mids, z_vals[..., -1:]], -1)
          lower = torch.cat([z_vals[..., :1], mids], -1)
          # stratified samples in those intervals
          t_rand = torch.clip(
              torch.rand(z_vals.shape, device=device),
              min=PERTURB_EPSILON,
              max=1 - PERTURB_EPSILON,
          )
  
          z_vals = lower + (upper - lower) * t_rand
  
      pts = (
          rays_o[..., None, :]
          + rays_d[..., None, :] * z_vals[..., :, None]
      )  # [rays_per_batch, samples_per_ray, 3]
      dirs = torch.stack([rays_d] * samples_per_ray, axis=1)
      if append_t is not None:
          pts = torch.cat([pts, append_t.to(device)], dim=-1)
      return pts, dirs, z_vals
  
file_path: ml-neuman/utils/ray_utils.py
imports: import numpy
  import torch
  import igl
  from geometry.pcd_projector import PointCloudProjectorNp
  from utils.constant import DEFAULT_GEO_THRESH, PERTURB_EPSILON
label_desc: Use image node_id 7 for calling a global function with example usage: ray_to_samples(ray_batch, samples_per_ray, lindisp, perturb, device, append_t) and returns: pts,  dirs,  z_vals