pynif3d.camera

class pynif3d.camera.CameraRayGenerator(height, width, focal_x, focal_y, center_x=None, center_y=None)

Bases: torch.nn.modules.module.Module

Generates rays for each pixel of a pinhole camera model. Takes the spatial dimensions of the camera’s image plane along with focal lengths and camera pose to generate a ray for each pixel.

Usage:

ray_generator = CameraRayGenerator(image_height, image_width, focal_x, focal_y)
ray_directions, ray_origins, view_directions = ray_generator(camera_poses)

Initializes internal Module state, shared by both nn.Module and ScriptModule.

forward(camera_poses)
Parameters

camera_poses (torch.Tensor) – Tensor containing the Rt pose matrices. Its shape is (N, 3, 4) or (3, 4).

Returns

Tuple containing:
  • rays_o (torch.Tensor): The origin coordinates of the rays. Its shape is (batch_size, 3, height, width).

  • rays_d (torch.Tensor): The non-normalized direction vector of the rays. Its shape is (batch_size, 3, height, width).

  • view_dirs (torch.Tensor): The unit-normalized direction vector of the rays. Its shape is (batch_size, 3, height, width).

Return type

tuple

training: bool
class pynif3d.camera.SphereRayTracer(sdf_model, **kwargs)

Bases: torch.nn.modules.module.Module

Determines the intersection between a set of rays and a surface defined by an implicit representation using the sphere tracing algorithm.

Usage:

# Assume an SDF model (torch.nn.Module) is given.
ray_tracer = SphereRayTracer(sdf_model)
points, z_vals, mask_not_converged = ray_tracer(ray_directions, ray_origins)
Parameters
  • sdf_model (instance) – Instance of an SDF model.

  • kwargs (dict) –

    • sdf_threshold (float): The SDF threshold that is used to determine whether points are close enough to the surface or not. The closer they are, the lower the SDF value becomes.

    • n_iterations (int): The number of iterations that the sphere tracing algorithm is run for.

    • n_fix_iterations (int): The number of iterations that the algorithm for correcting overshooting SDF values is run for.

fix_overshoot(points, z_vals, rays_d, rays_o, sdf_vals, next_sdf_vals)
forward(rays_d, rays_o, z_vals=None)
Parameters
  • rays_d (torch.Tensor) – Tensor containing the ray directions. Its shape is (batch_size, n_rays, 3) or (n_rays, 3).

  • rays_o (torch.Tensor) – Tensor containing the ray origins. Its shape is (batch_size, n_rays, 3) or (n_rays, 3).

  • z_vals (torch.Tensor) – Tensor containing the initial Z values. Its shape is (batch_size, n_rays) or (n_rays,).

Returns

Tuple containing the intersection points (as a torch.Tensor with

shape (2, n_rays, 3)), the Z values along the ray (as a torch.Tensor with shape (2, n_rays,)) and a mask specifying which points the algorithm has not converged for (as a torch.Tensor with shape (2, n_rays,)). Note that the first channel encodes the intersection information between the ray and the sphere that is processed at each iteration of the algorithm.

Return type

tuple

training: bool