class_docstr: A class which extends Pinhole camera by considering radial, tangential and
  thin-prism distortion. For the fisheye camera model, k1, k2, ..., k_n_radial are
  polynomial coefficents to model radial distortions. Two common types of radial
  distortions are barrel and pincusion radial distortions.
  
  a = x / z, b = y / z, r = (a*a+b*b)^(1/2)
  th = atan(r)
  [x_r]  = (th+ k0 * th^3 + k1* th^5 + ...) [a/r]
  [y_r]                                     [b/r]                    [1]
  
  
  The tangential distortion parameters are p1 and p2. The primary cause is
  due to the lens assembly not being centered over and parallel to the image plane.
  tangentialDistortion = [(2 x_r^2 + rd^2)*p_0 + 2*x_r*y_r*p_1]
                         [(2 y_r^2 + rd^2)*p_1 + 2*x_r*y_r*p_0]      [2]
  where rd^2 = x_r^2 + y_r^2
  
  The thin-prism distortion is modeled with s1, s2, s3, s4 coefficients
  thinPrismDistortion = [s0 * rd^2 + s1 rd^4]
                        [s2 * rd^2 + s3 rd^4]                        [3]
  
  The projection
  proj = diag(f, f) * uvDistorted + [cu; cv]
  uvDistorted = [x_r]  + tangentialDistortion  + thinPrismDistortion [4]
                [y_r]
  f is the focal length and cu, cv are principal points in x, y axis.
class_docstr_tok: ["A","class","which","extends","Pinhole","camera","by","considering","radial",",","tangential","and","thin-prism","distortion",".","For","the","fisheye","camera","model",",","k1",",","k2",",","...",",","k_n_radial","are","polynomial","coefficents","to","model","radial","distortions",".","Two","common","types","of","radial","distortions","are","barrel","and","pincusion","radial","distortions",".","a","=","x","\/","z",",","b","=","y","\/","z",",","r","=","(","a","*","a+b","*","b",")","^","(","1\/2",")","th","=","atan","(","r",")","[","x_r","]","=","(","th+","k0","*","th^3","+","k1","*","th^5","+","...",")","[","a\/r","]","[","y_r","]","[","b\/r","]","[","1","]","The","tangential","distortion","parameters","are","p1","and","p2",".","The","primary","cause","is","due","to","the","lens","assembly","not","being","centered","over","and","parallel","to","the","image","plane",".","tangentialDistortion","=","[","(","2","x_r^2","+","rd^2",")","*","p_0","+","2","*","x_r","*","y_r","*","p_1","]","[","(","2","y_r^2","+","rd^2",")","*","p_1","+","2","*","x_r","*","y_r","*","p_0","]","[","2","]","where","rd^2","=","x_r^2","+","y_r^2","The","thin-prism","distortion","is","modeled","with","s1",",","s2",",","s3",",","s4","coefficients","thinPrismDistortion","=","[","s0","*","rd^2","+","s1","rd^4","]","[","s2","*","rd^2","+","s3","rd^4","]","[","3","]","The","projection","proj","=","diag","(","f",",","f",")","*","uvDistorted","+","[","cu",";","cv","]","uvDistorted","=","[","x_r","]","+","tangentialDistortion","+","thinPrismDistortion","[","4","]","[","y_r","]","f","is","the","focal","length","and","cu",",","cv","are","principal","points","in","x",",","y","axis","."]
docstr: Helper function to compute the angle theta from the norm of the vector [x_r; y_r]
  
  Args:
      radial_params: k1, k2, ..., k_num_radial, (num_radial)
      th_radial_desired: desired angle of shape (...), E.g., (P), (1, P), (M, P)
  
  Returns:
      th: angle theta (in radians) of shape (...), E.g., (P), (1, P), (M, P)
docstr_tok: ["Helper","function","to","compute","the","angle","theta","from","the","norm","of","the","vector","[","x_r",";","y_r","]","Args",":","radial_params",":","k1",",","k2",",","...",",","k_num_radial",",","(","num_radial",")","th_radial_desired",":","desired","angle","of","shape","(","...",")",",","E.g.",",","(","P",")",",","(","1",",","P",")",",","(","M",",","P",")","Returns",":","th",":","angle","theta","(","in","radians",")","of","shape","(","...",")",",","E.g.",",","(","P",")",",","(","1",",","P",")",",","(","M",",","P",")"]
code: def _get_theta_from_norm_xr_yr(
      self, radial_params, th_radial_desired
  ) -> torch.Tensor:
      """
      Helper function to compute the angle theta from the norm of the vector [x_r; y_r]
  
      Args:
          radial_params: k1, k2, ..., k_num_radial, (num_radial)
          th_radial_desired: desired angle of shape (...), E.g., (P), (1, P), (M, P)
  
      Returns:
          th: angle theta (in radians) of shape (...), E.g., (P), (1, P), (M, P)
      """
      sh = list(th_radial_desired.shape)
      th = th_radial_desired
      c = torch.tensor(
          [2.0 * i + 3 for i in range(self.num_radial)],
          device=self.device,
      )
      for _ in range(self.num_distortion_iters):
          theta_sq = th * th
          th_radial = 1.0
          dthD_dth = 1.0
  
          # compute the theta polynomial and its derivative wrt theta
          t = theta_sq
          theta_pow = torch.stack(
              [t, t**2, t**3, t**4, t**5, t**6], dim=-1
          )
          th_radial = th_radial + torch.sum(
              theta_pow * radial_params, dim=-1
          )
  
          dthD_dth = dthD_dth + torch.sum(
              c * radial_params * theta_pow, dim=-1
          )
          th_radial = th_radial * th
  
          # compute the correction
          step = torch.zeros(*sh, device=self.device)
          # make sure don't divide by zero
          nonzero_mask = dthD_dth.abs() > self.epsilon
          step = (
              step
              + nonzero_mask
              * (th_radial_desired - th_radial)
              / dthD_dth
          )
          # if derivative is close to zero, apply small correction in the appropriate
          # direction to avoid numerical explosions
          close_to_zero_mask = dthD_dth.abs() <= self.epsilon
          dir_mask = (th_radial_desired - th_radial) * dthD_dth > 0.0
          boolean_mask = close_to_zero_mask & dir_mask
          step = step + 10.0 * self.epsilon * boolean_mask
          step = step - 10 * self.epsilon * (
              ~nonzero_mask & ~boolean_mask
          )
  
          # apply correction
          th = th + step
          # revert to within 180 degrees FOV to avoid numerical overflow
          idw = th.abs() >= math.pi / 2.0
          th[idw] = 0.999 * math.pi / 2.0
      return th
  
file_path: pytorch3d/pytorch3d/renderer/fisheyecameras.py
imports: import math
  from typing import List, Optional, Tuple, Union
  import torch
  from pytorch3d.common.datatypes import Device
  from pytorch3d.renderer.cameras import _R, _T, CamerasBase
label_desc: Use image node_id 8 for calling the FishEyeCameras obj's underlying member method code with example usage: obj._get_theta_from_norm_xr_yr(radial_params, th_radial_desired) and returns: th