class_docstr: Warp an image with given dense displacement field (DDF).
class_docstr_tok: ["Warp","an","image","with","given","dense","displacement","field","(","DDF",")","."]
code: def get_reference_grid(
      self, ddf: torch.Tensor, jitter: bool = False, seed: int = 0
  ) -> torch.Tensor:
      if (
          self.ref_grid is not None
          and self.ref_grid.shape[0] == ddf.shape[0]
          and self.ref_grid.shape[1:] == ddf.shape[2:]
      ):
          return self.ref_grid  # type: ignore
      mesh_points = [torch.arange(0, dim) for dim in ddf.shape[2:]]
      grid = torch.stack(
          meshgrid_ij(*mesh_points), dim=0
      )  # (spatial_dims, ...)
      grid = torch.stack(
          [grid] * ddf.shape[0], dim=0
      )  # (batch, spatial_dims, ...)
      self.ref_grid = grid.to(ddf)
      if jitter:
          # Define reference grid on non-integer values
          with torch.random.fork_rng(enabled=seed):
              torch.random.manual_seed(seed)
              grid += torch.rand_like(grid)
      self.ref_grid.requires_grad = False
      return self.ref_grid
  
file_path: MONAI/monai/networks/blocks/warp.py
imports: from __future__ import annotations
  import warnings
  import torch
  from torch import nn
  from torch.nn import functional
  from monai.config.deviceconfig import USE_COMPILED
  from monai.networks.layers.spatial_transforms import grid_pull
  from monai.networks.utils import meshgrid_ij
  from monai.utils import GridSampleMode, GridSamplePadMode, optional_import
label_desc: Use image node_id 2 for calling the Warp obj's underlying member method code with example usage: obj.get_reference_grid(ddf, jitter, seed) and returns: self, self