class_docstr: Differentiable rendering module for the Pulsar renderer.
  
  Set the maximum number of balls to a reasonable value. It is used to determine
  several buffer sizes. It is no problem to render less balls than this number,
  but never more.
  
  When optimizing for sphere positions, sphere radiuses or camera parameters you
  have to use higher gamma values (closer to one) and larger sphere sizes: spheres
  can only 'move' to areas that they cover, and only with higher gamma values exists
  a gradient w.r.t. their color depending on their position.
  
  Args:
      * width: result image width in pixels.
      * height: result image height in pixels.
      * max_num_balls: the maximum number of balls this renderer will handle.
      * orthogonal_projection: use an orthogonal instead of perspective projection.
          Default: False.
      * right_handed_system: use a right-handed instead of a left-handed coordinate
          system. This is relevant for compatibility with other drawing or scanning
          systems. Pulsar by default assumes a left-handed world and camera coordinate
          system as known from mathematics with x-axis to the right, y axis up and z
          axis for increasing depth along the optical axis. In the image coordinate
          system, only the y axis is pointing down, leading still to a left-handed
          system. If you set this to True, it is assuming a right-handed world and
          camera coordinate system with x axis to the right, y axis to the top and
          z axis decreasing along the optical axis. Again, the image coordinate
          system has a flipped y axis, remaining a right-handed system.
          Default: False.
      * background_normalized_depth: the normalized depth the background is placed
          at.
          This is on a scale from 0. to 1. between the specified min and max depth
          (see the forward function). The value 0. is the most furthest depth whereas
          1. is the closest. Be careful when setting the background too far front - it
          may hide elements in your scene. Default: EPS.
      * n_channels: the number of image content channels to use. This is usually three
          for regular color representations, but can be a higher or lower number.
          Default: 3.
      * n_track: the number of spheres to track for gradient calculation per pixel.
          Only the closest n_track spheres will receive gradients. Default: 5.
class_docstr_tok: ["Differentiable","rendering","module","for","the","Pulsar","renderer",".","Set","the","maximum","number","of","balls","to","a","reasonable","value",".","It","is","used","to","determine","several","buffer","sizes",".","It","is","no","problem","to","render","less","balls","than","this","number",",","but","never","more",".","When","optimizing","for","sphere","positions",",","sphere","radiuses","or","camera","parameters","you","have","to","use","higher","gamma","values","(","closer","to","one",")","and","larger","sphere","sizes",":","spheres","can","only","'move","'","to","areas","that","they","cover",",","and","only","with","higher","gamma","values","exists","a","gradient","w.r.t",".","their","color","depending","on","their","position",".","Args",":","*","width",":","result","image","width","in","pixels",".","*","height",":","result","image","height","in","pixels",".","*","max_num_balls",":","the","maximum","number","of","balls","this","renderer","will","handle",".","*","orthogonal_projection",":","use","an","orthogonal","instead","of","perspective","projection",".","Default",":","False",".","*","right_handed_system",":","use","a","right-handed","instead","of","a","left-handed","coordinate","system",".","This","is","relevant","for","compatibility","with","other","drawing","or","scanning","systems",".","Pulsar","by","default","assumes","a","left-handed","world","and","camera","coordinate","system","as","known","from","mathematics","with","x-axis","to","the","right",",","y","axis","up","and","z","axis","for","increasing","depth","along","the","optical","axis",".","In","the","image","coordinate","system",",","only","the","y","axis","is","pointing","down",",","leading","still","to","a","left-handed","system",".","If","you","set","this","to","True",",","it","is","assuming","a","right-handed","world","and","camera","coordinate","system","with","x","axis","to","the","right",",","y","axis","to","the","top","and","z","axis","decreasing","along","the","optical","axis",".","Again",",","the","image","coordinate","system","has","a","flipped","y","axis",",","remaining","a","right-handed","system",".","Default",":","False",".","*","background_normalized_depth",":","the","normalized","depth","the","background","is","placed","at",".","This","is","on","a","scale","from","0.","to","1.","between","the","specified","min","and","max","depth","(","see","the","forward","function",")",".","The","value","0.","is","the","most","furthest","depth","whereas","1.","is","the","closest",".","Be","careful","when","setting","the","background","too","far","front","-","it","may","hide","elements","in","your","scene",".","Default",":","EPS",".","*","n_channels",":","the","number","of","image","content","channels","to","use",".","This","is","usually","three","for","regular","color","representations",",","but","can","be","a","higher","or","lower","number",".","Default",":","3",".","*","n_track",":","the","number","of","spheres","to","track","for","gradient","calculation","per","pixel",".","Only","the","closest","n_track","spheres","will","receive","gradients",".","Default",":","5","."]
docstr: Transform 8 component camera parameter vector(s) to the internal camera
  representation.
  
  The input vectors consists of:
      * 3 components for camera position,
      * 3 components for camera rotation (three rotation angles) or
        6 components as described in "On the Continuity of Rotation
        Representations in Neural Networks" (Zhou et al.),
      * focal length,
      * the sensor width in world coordinates,
      * [optional] the principal point offset in x and y.
  
  The sensor height is inferred by pixel size and sensor width to obtain
  quadratic pixels.
  
  Args:
      * cam_params: [Bx]{8, 10, 11, 13}, input tensors as described above.
      * width: number of pixels in x direction.
      * height: number of pixels in y direction.
      * orthogonal: bool, whether an orthogonal projection is used
            (does not use focal length).
      * right_handed: bool, whether to use a right handed system
            (negative z in camera direction).
      * first_R_then_T: bool, whether to first rotate, then translate
            the camera (PyTorch3D convention).
  
  Returns:
      * pos_vec: the position vector in 3D,
      * pixel_0_0_center: the center of the upper left pixel in world coordinates,
      * pixel_vec_x: the step to move one pixel on the image x axis
             in world coordinates,
      * pixel_vec_y: the step to move one pixel on the image y axis
             in world coordinates,
      * focal_length: the focal lengths,
      * principal_point_offsets: the principal point offsets in x, y.
docstr_tok: ["Transform","8","component","camera","parameter","vector","(","s",")","to","the","internal","camera","representation",".","The","input","vectors","consists","of",":","*","3","components","for","camera","position",",","*","3","components","for","camera","rotation","(","three","rotation","angles",")","or","6","components","as","described","in","``","On","the","Continuity","of","Rotation","Representations","in","Neural","Networks","''","(","Zhou","et","al",".",")",",","*","focal","length",",","*","the","sensor","width","in","world","coordinates",",","*","[","optional","]","the","principal","point","offset","in","x","and","y",".","The","sensor","height","is","inferred","by","pixel","size","and","sensor","width","to","obtain","quadratic","pixels",".","Args",":","*","cam_params",":","[","Bx","]","{","8",",","10",",","11",",","13","}",",","input","tensors","as","described","above",".","*","width",":","number","of","pixels","in","x","direction",".","*","height",":","number","of","pixels","in","y","direction",".","*","orthogonal",":","bool",",","whether","an","orthogonal","projection","is","used","(","does","not","use","focal","length",")",".","*","right_handed",":","bool",",","whether","to","use","a","right","handed","system","(","negative","z","in","camera","direction",")",".","*","first_R_then_T",":","bool",",","whether","to","first","rotate",",","then","translate","the","camera","(","PyTorch3D","convention",")",".","Returns",":","*","pos_vec",":","the","position","vector","in","3D",",","*","pixel_0_0_center",":","the","center","of","the","upper","left","pixel","in","world","coordinates",",","*","pixel_vec_x",":","the","step","to","move","one","pixel","on","the","image","x","axis","in","world","coordinates",",","*","pixel_vec_y",":","the","step","to","move","one","pixel","on","the","image","y","axis","in","world","coordinates",",","*","focal_length",":","the","focal","lengths",",","*","principal_point_offsets",":","the","principal","point","offsets","in","x",",","y","."]
code: def _transform_cam_params(
      cam_params: torch.Tensor,
      width: int,
      height: int,
      orthogonal: bool,
      right_handed: bool,
      first_R_then_T: bool = False,
  ) -> Tuple[
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
      torch.Tensor,
  ]:
      """
      Transform 8 component camera parameter vector(s) to the internal camera
      representation.
  
      The input vectors consists of:
          * 3 components for camera position,
          * 3 components for camera rotation (three rotation angles) or
            6 components as described in "On the Continuity of Rotation
            Representations in Neural Networks" (Zhou et al.),
          * focal length,
          * the sensor width in world coordinates,
          * [optional] the principal point offset in x and y.
  
      The sensor height is inferred by pixel size and sensor width to obtain
      quadratic pixels.
  
      Args:
          * cam_params: [Bx]{8, 10, 11, 13}, input tensors as described above.
          * width: number of pixels in x direction.
          * height: number of pixels in y direction.
          * orthogonal: bool, whether an orthogonal projection is used
                (does not use focal length).
          * right_handed: bool, whether to use a right handed system
                (negative z in camera direction).
          * first_R_then_T: bool, whether to first rotate, then translate
                the camera (PyTorch3D convention).
  
      Returns:
          * pos_vec: the position vector in 3D,
          * pixel_0_0_center: the center of the upper left pixel in world coordinates,
          * pixel_vec_x: the step to move one pixel on the image x axis
                 in world coordinates,
          * pixel_vec_y: the step to move one pixel on the image y axis
                 in world coordinates,
          * focal_length: the focal lengths,
          * principal_point_offsets: the principal point offsets in x, y.
      """
      global AXANGLE_WARNING_EMITTED
      # Set up all direction vectors, i.e., the sensor direction of all axes.
      assert width > 0
      assert height > 0
      batch_processing = True
      if cam_params.ndimension() == 1:
          batch_processing = False
          cam_params = cam_params[None, :]
      batch_size = cam_params.size(0)
      continuous_rep = True
      if cam_params.shape[1] in [8, 10]:
          if cam_params.requires_grad and not AXANGLE_WARNING_EMITTED:
              warnings.warn(
                  "Using an axis angle representation for camera rotations. "
                  "This has discontinuities and should not be used for optimization. "
                  "Alternatively, use a six-component representation as described in "
                  "'On the Continuity of Rotation Representations in Neural Networks'"
                  " (Zhou et al.). "
                  "The `pytorch3d.transforms` module provides "
                  "facilities for using this representation."
              )
              AXANGLE_WARNING_EMITTED = True
          continuous_rep = False
      else:
          assert cam_params.shape[1] in [11, 13]
      pos_vec: torch.Tensor = cam_params[:, :3]
      principal_point_offsets: torch.Tensor = torch.zeros(
          (cam_params.shape[0], 2),
          dtype=torch.int32,
          device=cam_params.device,
      )
      if continuous_rep:
          rot_vec = cam_params[:, 3:9]
          focal_length: torch.Tensor = cam_params[:, 9:10]
          sensor_size_x = cam_params[:, 10:11]
          if cam_params.shape[1] == 13:
              principal_point_offsets: torch.Tensor = cam_params[
                  :, 11:13
              ].to(torch.int32)
      else:
          rot_vec = cam_params[:, 3:6]
          focal_length: torch.Tensor = cam_params[:, 6:7]
          sensor_size_x = cam_params[:, 7:8]
          if cam_params.shape[1] == 10:
              principal_point_offsets: torch.Tensor = cam_params[
                  :, 8:10
              ].to(torch.int32)
      # Always get quadratic pixels.
      pixel_size_x = sensor_size_x / float(width)
      sensor_size_y = height * pixel_size_x
      if continuous_rep:
          rot_mat = rotation_6d_to_matrix(rot_vec)
      else:
          rot_mat = axis_angle_to_matrix(rot_vec)
      if first_R_then_T:
          pos_vec = torch.matmul(rot_mat, pos_vec[..., None])[:, :, 0]
      sensor_dir_x = torch.matmul(
          rot_mat,
          torch.tensor(
              [1.0, 0.0, 0.0],
              dtype=torch.float32,
              device=rot_mat.device,
          ).repeat(batch_size, 1)[:, :, None],
      )[:, :, 0]
      sensor_dir_y = torch.matmul(
          rot_mat,
          torch.tensor(
              [0.0, -1.0, 0.0],
              dtype=torch.float32,
              device=rot_mat.device,
          ).repeat(batch_size, 1)[:, :, None],
      )[:, :, 0]
      sensor_dir_z = torch.matmul(
          rot_mat,
          torch.tensor(
              [0.0, 0.0, 1.0],
              dtype=torch.float32,
              device=rot_mat.device,
          ).repeat(batch_size, 1)[:, :, None],
      )[:, :, 0]
      if right_handed:
          sensor_dir_z *= -1
      if orthogonal:
          sensor_center = pos_vec
      else:
          sensor_center = pos_vec + focal_length * sensor_dir_z
      sensor_luc = (  # Sensor left upper corner.
          sensor_center
          - sensor_dir_x * (sensor_size_x / 2.0)
          - sensor_dir_y * (sensor_size_y / 2.0)
      )
      pixel_size_x = sensor_size_x / float(width)
      pixel_size_y = sensor_size_y / float(height)
      pixel_vec_x: torch.Tensor = sensor_dir_x * pixel_size_x
      pixel_vec_y: torch.Tensor = sensor_dir_y * pixel_size_y
      pixel_0_0_center = (
          sensor_luc + 0.5 * pixel_vec_x + 0.5 * pixel_vec_y
      )
      # Reduce dimension.
      focal_length: torch.Tensor = focal_length[:, 0]
      if batch_processing:
          return (
              pos_vec,
              pixel_0_0_center,
              pixel_vec_x,
              pixel_vec_y,
              focal_length,
              principal_point_offsets,
          )
      else:
          return (
              pos_vec[0],
              pixel_0_0_center[0],
              pixel_vec_x[0],
              pixel_vec_y[0],
              focal_length[0],
              principal_point_offsets[0],
          )
  
file_path: pytorch3d/pytorch3d/renderer/points/pulsar/renderer.py
imports: import logging
  import warnings
  from typing import Optional, Tuple, Union
  import torch
  from pytorch3d import _C
  from pytorch3d.transforms import axis_angle_to_matrix, rotation_6d_to_matrix
label_desc: Use image node_id 4 for calling the Renderer obj's underlying member method code with example usage: obj._transform_cam_params(cam_params, width, height, orthogonal, right_handed, first_R_then_T) and returns: pos_vec,  pixel_0_0_center,  pixel_vec_x,  pixel_vec_y,  focal_length,  principal_point_offsets, pos_vec,  pixel_0_0_center,  pixel_vec_x,  pixel_vec_y,  focal_length,  principal_point_offsets