class_docstr: Warp a patch by depth.
  
  .. math::
      P_{src}^{\{dst\}} = K_{dst} * T_{src}^{\{dst\}}
  
      I_{src} = \\omega(I_{dst}, P_{src}^{\{dst\}}, D_{src})
  
  Args:
      pinholes_dst: the pinhole models for the destination frame.
      height: the height of the image to warp.
      width: the width of the image to warp.
      mode: interpolation mode to calculate output values ``'bilinear'`` | ``'nearest'``.
      padding_mode: padding mode for outside grid values ``'zeros'`` | ``'border'`` | ``'reflection'``.
      align_corners: interpolation flag.
class_docstr_tok: ["Warp","a","patch","by","depth",".","..","math",":",":","P_","{","src","}","^","{","\\","{","dst\\","}","}","=","K_","{","dst","}","*","T_","{","src","}","^","{","\\","{","dst\\","}","}","I_","{","src","}","=","\\\\omega","(","I_","{","dst","}",",","P_","{","src","}","^","{","\\","{","dst\\","}","}",",","D_","{","src","}",")","Args",":","pinholes_dst",":","the","pinhole","models","for","the","destination","frame",".","height",":","the","height","of","the","image","to","warp",".","width",":","the","width","of","the","image","to","warp",".","mode",":","interpolation","mode","to","calculate","output","values","``","'bilinear","'","``","|","``","'nearest","'","``",".","padding_mode",":","padding","mode","for","outside","grid","values","``","'zeros","'","``","|","``","'border","'","``","|","``","'reflection","'","``",".","align_corners",":","interpolation","flag","."]
docstr: Compute a grid for warping a given the depth from the reference pinhole camera.
  
  The function `compute_projection_matrix` has to be called beforehand in order to have precomputed the relative
  projection matrices encoding the relative pose and the intrinsics between the reference and a non reference
  camera.
docstr_tok: ["Compute","a","grid","for","warping","a","given","the","depth","from","the","reference","pinhole","camera",".","The","function","`","compute_projection_matrix","`","has","to","be","called","beforehand","in","order","to","have","precomputed","the","relative","projection","matrices","encoding","the","relative","pose","and","the","intrinsics","between","the","reference","and","a","non","reference","camera","."]
code: def warp_grid(self, depth_src: Tensor) -> Tensor:
      """Compute a grid for warping a given the depth from the reference pinhole camera.
  
      The function `compute_projection_matrix` has to be called beforehand in order to have precomputed the relative
      projection matrices encoding the relative pose and the intrinsics between the reference and a non reference
      camera.
      """
      # TODO: add type and value checkings
      if self._dst_proj_src is None or self._pinhole_src is None:
          raise ValueError("Please, call compute_projection_matrix.")
  
      if len(depth_src.shape) != 4:
          raise ValueError(
              f"Input depth_src has to be in the shape of Bx1xHxW. Got {depth_src.shape}"
          )
  
      # unpack depth attributes
      batch_size, _, _, _ = depth_src.shape
      device: torch.device = depth_src.device
      dtype: torch.dtype = depth_src.dtype
  
      # expand the base coordinate grid according to the input batch size
      pixel_coords: Tensor = self.grid.to(
          device=device, dtype=dtype
      ).expand(
          batch_size, -1, -1, -1
      )  # BxHxWx3
  
      # reproject the pixel coordinates to the camera frame
      cam_coords_src: Tensor = pixel2cam(
          depth_src,
          self._pinhole_src.intrinsics_inverse().to(
              device=device, dtype=dtype
          ),
          pixel_coords,
      )  # BxHxWx3
  
      # reproject the camera coordinates to the pixel
      pixel_coords_src: Tensor = cam2pixel(
          cam_coords_src,
          self._dst_proj_src.to(device=device, dtype=dtype),
      )  # (B*N)xHxWx2
  
      # normalize between -1 and 1 the coordinates
      pixel_coords_src_norm: Tensor = normalize_pixel_coordinates(
          pixel_coords_src, self.height, self.width
      )
      return pixel_coords_src_norm
  
imports: from __future__ import annotations
  from typing import Optional
  import torch
  import kornia.core
  from kornia.core import Module, Tensor, tensor
  from kornia.core.check import KORNIA_CHECK, KORNIA_CHECK_IS_TENSOR, KORNIA_CHECK_SHAPE
  from kornia.filters.sobel import spatial_gradient
  from kornia.utils import create_meshgrid
  from kornia.utils.helpers import deprecated
  from .camera import PinholeCamera, cam2pixel, pixel2cam, project_points, unproject_points
  from .conversions import normalize_pixel_coordinates, normalize_points_with_intrinsics
  from .linalg import compose_transformations, convert_points_to_homogeneous, inverse_transformation, transform_points
label_desc: Use image node_id 6 for calling the DepthWarper obj's underlying member method code with example usage: obj.warp_grid(depth_src) and returns: pixel_coords_src_norm