pytorch3d.implicitron.models.renderer.ray_tracing

ray_tracing

class pytorch3d.implicitron.models.renderer.ray_tracing.RayTracing(*args, **kwargs)[source]

Bases: Configurable, Module

Finds the intersection points of rays with the implicit surface defined by a signed distance function (SDF). The algorithm follows the pipeline: 1. Initialise start and end points on rays by the intersections with

the circumscribing sphere.

  1. Run sphere tracing from both ends.

  2. Divide the untraced segments of non-convergent rays into uniform

    intervals and find the one with the sign transition.

  3. Run the secant method to estimate the point of the sign transition.

Parameters:
  • object_bounding_sphere – The radius of the initial sphere circumscribing the object.

  • sdf_threshold – Absolute SDF value small enough for the sphere tracer to consider it a surface.

  • line_search_step – Length of the backward correction on sphere tracing iterations.

  • line_step_iters – Number of backward correction iterations.

  • sphere_tracing_iters – Maximum number of sphere tracing iterations (the actual number of iterations may be smaller if all ray intersections are found).

  • n_steps – Number of intervals sampled for unconvergent rays.

  • n_secant_steps – Number of iterations in the secant algorithm.

object_bounding_sphere: float = 1.0
sdf_threshold: float = 5e-05
line_search_step: float = 0.5
line_step_iters: int = 1
sphere_tracing_iters: int = 10
n_steps: int = 100
n_secant_steps: int = 8
forward(sdf: Callable[[Tensor], Tensor], cam_loc: Tensor, object_mask: BoolTensor, ray_directions: Tensor) Tuple[Tensor, Tensor, Tensor][source]
Parameters:
  • sdf – A callable that takes a (N, 3) tensor of points and returns a tensor of (N,) SDF values.

  • cam_loc – A tensor of (B, N, 3) ray origins.

  • object_mask – A (N, 3) tensor of indicators whether a sampled pixel corresponds to the rendered object or background.

  • ray_directions – A tensor of (B, N, 3) ray directions.

Returns:

curr_start_points

A tensor of (B*N, 3) found intersection points

with the implicit surface.

network_object_mask: A tensor of (B*N,) indicators denoting whether

intersections were found.

acc_start_dis: A tensor of (B*N,) distances from the ray origins

to intersrection points.

sphere_tracing(batch_size: int, num_pixels: int, sdf: Callable[[Tensor], Tensor], cam_loc: Tensor, ray_directions: Tensor, mask_intersect: Tensor, sphere_intersections: Tensor) Tuple[Any, Any, Any, Any, Any, Any][source]

Run sphere tracing algorithm for max iterations from both sides of unit sphere intersection

Parameters:
  • batch_size

  • num_pixels

  • sdf

  • cam_loc

  • ray_directions

  • mask_intersect

  • sphere_intersections

Returns:

curr_start_points – unfinished_mask_start: acc_start_dis: acc_end_dis: min_dis: max_dis:

ray_sampler(sdf: Callable[[Tensor], Tensor], cam_loc: Tensor, object_mask: Tensor, ray_directions: Tensor, sampler_min_max: Tensor, sampler_mask: Tensor) Tuple[Tensor, Tensor, Tensor][source]

Sample the ray in a given range and run secant on rays which have sign transition.

Parameters:
  • sdf

  • cam_loc

  • object_mask

  • ray_directions

  • sampler_min_max

  • sampler_mask

Returns:

secant(sdf_low: Tensor, sdf_high: Tensor, z_low: Tensor, z_high: Tensor, cam_loc: Tensor, ray_directions: Tensor, sdf: Module) Tensor[source]

Runs the secant method for interval [z_low, z_high] for n_secant_steps

minimal_sdf_points(sdf: Callable[[Tensor], Tensor], cam_loc: Tensor, ray_directions: Tensor, mask: Tensor, min_dis: Tensor, max_dis: Tensor) Tuple[Tensor, Tensor][source]

Find points with minimal SDF value on rays for P_out pixels