pytorch3d.renderer.implicit.utils
utils
- class pytorch3d.renderer.implicit.utils.RayBundle(origins: Tensor, directions: Tensor, lengths: Tensor, xys: Tensor)[source]
Bases:
NamedTuple
Parametrizes points along projection rays by storing:
- origins: A tensor of shape (…, 3) denoting the
origins of the sampling rays in world coords.
- directions: A tensor of shape (…, 3) containing the direction
vectors of sampling rays in world coords. They don’t have to be normalized; they define unit vectors in the respective 1D coordinate systems; see documentation for
ray_bundle_to_ray_points()
for the conversion formula.- lengths: A tensor of shape (…, num_points_per_ray)
containing the lengths at which the rays are sampled.
xys: A tensor of shape (…, 2), the xy-locations (xys) of the ray pixels
- origins: Tensor
Alias for field number 0
- directions: Tensor
Alias for field number 1
- lengths: Tensor
Alias for field number 2
- xys: Tensor
Alias for field number 3
- class pytorch3d.renderer.implicit.utils.HeterogeneousRayBundle(origins: Tensor, directions: Tensor, lengths: Tensor, xys: Tensor, camera_ids: LongTensor | None = None, camera_counts: LongTensor | None = None)[source]
Bases:
object
- Members:
- origins: A tensor of shape (…, 3) denoting the
origins of the sampling rays in world coords.
- directions: A tensor of shape (…, 3) containing the direction
vectors of sampling rays in world coords. They don’t have to be normalized; they define unit vectors in the respective 1D coordinate systems; see documentation for
ray_bundle_to_ray_points()
for the conversion formula.- lengths: A tensor of shape (…, num_points_per_ray)
containing the lengths at which the rays are sampled.
xys: A tensor of shape (…, 2), the xy-locations (xys) of the ray pixels camera_ids: A tensor of shape (N, ) which indicates which camera
was used to sample the rays. N is the number of unique sampled cameras.
- camera_counts: A tensor of shape (N, ) which how many times the
coresponding camera in camera_ids was sampled. sum(camera_counts)==total_number_of_rays
If we sample cameras of ids [0, 3, 5, 3, 1, 0, 0] that would be stored as camera_ids=[1, 3, 5, 0] and camera_counts=[1, 2, 1, 3]. camera_ids is a set like object with no particular ordering of elements. ith element of camera_ids coresponds to the ith element of camera_counts.
- origins: Tensor
- directions: Tensor
- lengths: Tensor
- xys: Tensor
- camera_ids: LongTensor | None = None
- camera_counts: LongTensor | None = None
- pytorch3d.renderer.implicit.utils.ray_bundle_to_ray_points(ray_bundle: RayBundle | HeterogeneousRayBundle) Tensor [source]
Converts rays parametrized with a ray_bundle (an instance of the RayBundle named tuple or HeterogeneousRayBundle dataclass) to 3D points by extending each ray according to the corresponding length.
- E.g. for 2 dimensional tensors ray_bundle.origins, ray_bundle.directions
and ray_bundle.lengths, the ray point at position [i, j] is:
ray_bundle.points[i, j, :] = ( ray_bundle.origins[i, :] + ray_bundle.directions[i, :] * ray_bundle.lengths[i, j] )
Note that both the directions and magnitudes of the vectors in ray_bundle.directions matter.
- Parameters:
ray_bundle – A RayBundle or HeterogeneousRayBundle object with fields: origins: A tensor of shape (…, 3) directions: A tensor of shape (…, 3) lengths: A tensor of shape (…, num_points_per_ray)
- Returns:
rays_points –
- A tensor of shape (…, num_points_per_ray, 3)
containing the points sampled along each ray.
- pytorch3d.renderer.implicit.utils.ray_bundle_variables_to_ray_points(rays_origins: Tensor, rays_directions: Tensor, rays_lengths: Tensor) Tensor [source]
Converts rays parametrized with origins and directions to 3D points by extending each ray according to the corresponding ray length:
E.g. for 2 dimensional input tensors rays_origins, rays_directions and rays_lengths, the ray point at position [i, j] is:
rays_points[i, j, :] = ( rays_origins[i, :] + rays_directions[i, :] * rays_lengths[i, j] )
Note that both the directions and magnitudes of the vectors in rays_directions matter.
- Parameters:
rays_origins – A tensor of shape (…, 3)
rays_directions – A tensor of shape (…, 3)
rays_lengths – A tensor of shape (…, num_points_per_ray)
- Returns:
rays_points –
- A tensor of shape (…, num_points_per_ray, 3)
containing the points sampled along each ray.