open3d.t.geometry.RaycastingScene

class open3d.t.geometry.RaycastingScene

A scene class with basic ray casting and closest point queries.

The RaycastingScene allows to compute ray intersections with triangle meshes or compute the closest point on the surface of a mesh with respect to one or more query points. It builds an internal acceleration structure to speed up those queries.

This class supports only the CPU device.

The following shows how to create a scene and compute ray intersections:

import open3d as o3d
import matplotlib.pyplot as plt

cube = o3d.t.geometry.TriangleMesh.from_legacy(
                                    o3d.geometry.TriangleMesh.create_box())

# Create scene and add the cube mesh
scene = o3d.t.geometry.RaycastingScene()
scene.add_triangles(cube)

# Rays are 6D vectors with origin and ray direction.
# Here we use a helper function to create rays for a pinhole camera.
rays = scene.create_rays_pinhole(fov_deg=60,
                                 center=[0.5,0.5,0.5],
                                 eye=[-1,-1,-1],
                                 up=[0,0,1],
                                 width_px=320,
                                 height_px=240)

# Compute the ray intersections.
ans = scene.cast_rays(rays)

# Visualize the hit distance (depth)
plt.imshow(ans['t_hit'].numpy())
__init__(self: open3d.cpu.pybind.t.geometry.RaycastingScene, nthreads: int = 0) → None

Create a RaycastingScene.

Parameters

nthreads (int) – The number of threads to use for building the scene. Set to 0 for automatic.

add_triangles(*args, **kwargs)

Overloaded function.

  1. add_triangles(self: open3d.cpu.pybind.t.geometry.RaycastingScene, vertex_positions: open3d.cpu.pybind.core.Tensor, triangle_indices: open3d.cpu.pybind.core.Tensor) -> int

Add a triangle mesh to the scene.

Parameters
Returns

The geometry ID of the added mesh.

  1. add_triangles(self: open3d.cpu.pybind.t.geometry.RaycastingScene, mesh: open3d.cpu.pybind.t.geometry.TriangleMesh) -> int

Add a triangle mesh to the scene.

Parameters

mesh (open3d.t.geometry.TriangleMesh) – A triangle mesh.

Returns

The geometry ID of the added mesh.

cast_rays(self: open3d.cpu.pybind.t.geometry.RaycastingScene, rays: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → Dict[str, open3d.cpu.pybind.core.Tensor]

Computes the first intersection of the rays with the scene.

Parameters
  • rays (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 6}, and Dtype Float32 describing the rays. {..} can be any number of dimensions, e.g., to organize rays for creating an image the shape can be {height, width, 6}. The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not necessary to normalize the direction but the returned hit distance uses the length of the direction vector as unit.

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A dictionary which contains the following keys

t_hit

A tensor with the distance to the first hit. The shape is {..}. If there is no intersection the hit distance is inf.

geometry_ids

A tensor with the geometry IDs. The shape is {..}. If there is no intersection the ID is INVALID_ID.

primitive_ids

A tensor with the primitive IDs, which corresponds to the triangle index. The shape is {..}. If there is no intersection the ID is INVALID_ID.

primitive_uvs

A tensor with the barycentric coordinates of the hit points within the hit triangles. The shape is {.., 2}.

primitive_normals

A tensor with the normals of the hit triangles. The shape is {.., 3}.

compute_closest_points(self: open3d.cpu.pybind.t.geometry.RaycastingScene, query_points: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → Dict[str, open3d.cpu.pybind.core.Tensor]

Computes the closest points on the surfaces of the scene.

Parameters
  • query_points (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 3}, and Dtype Float32 describing the query points. {..} can be any number of dimensions, e.g., to organize the query_point to create a 3D grid the shape can be {depth, height, width, 3}. The last dimension must be 3 and has the format [x, y, z].

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

The returned dictionary contains

points

A tensor with the closest surface points. The shape is {..}.

geometry_ids

A tensor with the geometry IDs. The shape is {..}.

primitive_ids

A tensor with the primitive IDs, which corresponds to the triangle index. The shape is {..}.

primitive_uvs

A tensor with the barycentric coordinates of the closest points within the triangles. The shape is {.., 2}.

primitive_normals

A tensor with the normals of the closest triangle . The shape is {.., 3}.

compute_distance(self: open3d.cpu.pybind.t.geometry.RaycastingScene, query_points: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → open3d.cpu.pybind.core.Tensor

Computes the distance to the surface of the scene.

Parameters
  • query_points (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 3}, and Dtype Float32 describing the query points. {..} can be any number of dimensions, e.g., to organize the query points to create a 3D grid the shape can be {depth, height, width, 3}. The last dimension must be 3 and has the format [x, y, z].

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A tensor with the distances to the surface. The shape is {..}.

compute_occupancy(self: open3d.cpu.pybind.t.geometry.RaycastingScene, query_points: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → open3d.cpu.pybind.core.Tensor

Computes the occupancy at the query point positions.

This function computes whether the query points are inside or outside. The function assumes that all meshes are watertight and that there are no intersections between meshes, i.e., inside and outside must be well defined. The function determines if a point is inside by counting the intersections of a rays starting at the query points.

Parameters
  • query_points (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 3}, and Dtype Float32 describing the query points. {..} can be any number of dimensions, e.g., to organize the query points to create a 3D grid the shape can be {depth, height, width, 3}. The last dimension must be 3 and has the format [x, y, z].

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A tensor with the occupancy values. The shape is {..}. Values are either 0 or 1. A point is occupied or inside if the value is 1.

compute_signed_distance(self: open3d.cpu.pybind.t.geometry.RaycastingScene, query_points: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → open3d.cpu.pybind.core.Tensor

Computes the signed distance to the surface of the scene.

This function computes the signed distance to the meshes in the scene. The function assumes that all meshes are watertight and that there are no intersections between meshes, i.e., inside and outside must be well defined. The function determines the sign of the distance by counting the intersections of a rays starting at the query points.

Parameters
  • query_points (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 3}, and Dtype Float32 describing the query_points. {..} can be any number of dimensions, e.g., to organize the query points to create a 3D grid the shape can be {depth, height, width, 3}. The last dimension must be 3 and has the format [x, y, z].

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A tensor with the signed distances to the surface. The shape is {..}. Negative distances mean a point is inside a closed surface.

count_intersections(self: open3d.cpu.pybind.t.geometry.RaycastingScene, rays: open3d.cpu.pybind.core.Tensor, nthreads: int = 0) → open3d.cpu.pybind.core.Tensor

Computes the number of intersection of the rays with the scene.

Parameters
  • rays (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 6}, and Dtype Float32 describing the rays. {..} can be any number of dimensions, e.g., to organize rays for creating an image the shape can be {height, width, 6}. The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not necessary to normalize the direction.

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A tensor with the number of intersections. The shape is {..}.

static create_rays_pinhole(*args, **kwargs)

Overloaded function.

  1. create_rays_pinhole(intrinsic_matrix: open3d.cpu.pybind.core.Tensor, extrinsic_matrix: open3d.cpu.pybind.core.Tensor, width_px: int, height_px: int) -> open3d.cpu.pybind.core.Tensor

Creates rays for the given camera parameters.

Parameters
  • intrinsic_matrix (open3d.core.Tensor) – The upper triangular intrinsic matrix with shape {3,3}.

  • extrinsic_matrix (open3d.core.Tensor) – The 4x4 world to camera SE(3) transformation matrix.

  • width_px (int) – The width of the image in pixels.

  • height_px (int) – The height of the image in pixels.

Returns

A tensor of shape {height_px, width_px, 6} with the rays.

  1. create_rays_pinhole(fov_deg: float, center: open3d.cpu.pybind.core.Tensor, eye: open3d.cpu.pybind.core.Tensor, up: open3d.cpu.pybind.core.Tensor, width_px: int, height_px: int) -> open3d.cpu.pybind.core.Tensor

Creates rays for the given camera parameters.

Parameters
  • fov_deg (float) – The horizontal field of view in degree.

  • center (open3d.core.Tensor) – The point the camera is looking at with shape {3}.

  • eye (open3d.core.Tensor) – The position of the camera with shape {3}.

  • up (open3d.core.Tensor) – The up-vector with shape {3}.

  • width_px (int) – The width of the image in pixels.

  • height_px (int) – The height of the image in pixels.

Returns

A tensor of shape {height_px, width_px, 6} with the rays.

test_occlusions(self: open3d.cpu.pybind.t.geometry.RaycastingScene, rays: open3d.cpu.pybind.core.Tensor, tnear: float = 0.0, tfar: float = inf, nthreads: int = 0) → open3d.cpu.pybind.core.Tensor

Checks if the rays have any intersection with the scene.

Parameters
  • rays (open3d.core.Tensor) – A tensor with >=2 dims, shape {.., 6}, and Dtype Float32 describing the rays. {..} can be any number of dimensions, e.g., to organize rays for creating an image the shape can be {height, width, 6}. The last dimension must be 6 and has the format [ox, oy, oz, dx, dy, dz] with [ox,oy,oz] as the origin and [dx,dy,dz] as the direction. It is not necessary to normalize the direction.

  • tnear (float) – The tnear offset for the rays. The default is 0.

  • tfar (float) – The tfar value for the ray. The default is infinity.

  • nthreads (int) – The number of threads to use. Set to 0 for automatic.

Returns

A boolean tensor which indicates if the ray is occluded by the scene (true) or not (false).

INVALID_ID = 4294967295