Open3D (C++ API)  0.18.0+252c867
Data Structures | Public Member Functions | Static Public Member Functions
open3d::t::geometry::RaycastingScene Class Reference

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

#include <RaycastingScene.h>

Data Structures

struct  Impl
 

Public Member Functions

 RaycastingScene (int64_t nthreads=0)
 Default Constructor. More...
 
 ~RaycastingScene ()
 
uint32_t AddTriangles (const core::Tensor &vertex_positions, const core::Tensor &triangle_indices)
 Add a triangle mesh to the scene. More...
 
uint32_t AddTriangles (const TriangleMesh &mesh)
 Add a triangle mesh to the scene. More...
 
std::unordered_map< std::string, core::TensorCastRays (const core::Tensor &rays, const int nthreads=0)
 Computes the first intersection of the rays with the scene. More...
 
core::Tensor TestOcclusions (const core::Tensor &rays, const float tnear=0.f, const float tfar=std::numeric_limits< float >::infinity(), const int nthreads=0)
 Checks if the rays have any intersection with the scene. More...
 
core::Tensor CountIntersections (const core::Tensor &rays, const int nthreads=0)
 Computes the number of intersection of the rays with the scene. More...
 
std::unordered_map< std::string, core::TensorListIntersections (const core::Tensor &rays, const int nthreads=0)
 Lists the intersections of the rays with the scene. More...
 
std::unordered_map< std::string, core::TensorComputeClosestPoints (const core::Tensor &query_points, const int nthreads=0)
 Computes the closest points on the surfaces of the scene. More...
 
core::Tensor ComputeDistance (const core::Tensor &query_points, const int nthreads=0)
 Computes the distance to the surface of the scene. More...
 
core::Tensor ComputeSignedDistance (const core::Tensor &query_points, const int nthreads=0, const int nsamples=1)
 Computes the signed distance to the surface of the scene. More...
 
core::Tensor ComputeOccupancy (const core::Tensor &query_points, const int nthreads=0, const int nsamples=1)
 Computes the occupancy at the query point positions. More...
 

Static Public Member Functions

static core::Tensor CreateRaysPinhole (const core::Tensor &intrinsic_matrix, const core::Tensor &extrinsic_matrix, int width_px, int height_px)
 Creates rays for the given camera parameters. More...
 
static core::Tensor CreateRaysPinhole (double fov_deg, const core::Tensor &center, const core::Tensor &eye, const core::Tensor &up, int width_px, int height_px)
 Creates rays for the given camera parameters. More...
 
static uint32_t INVALID_ID ()
 The value for invalid IDs. More...
 

Detailed Description

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.

Constructor & Destructor Documentation

◆ RaycastingScene()

open3d::t::geometry::RaycastingScene::RaycastingScene ( int64_t  nthreads = 0)

Default Constructor.

◆ ~RaycastingScene()

open3d::t::geometry::RaycastingScene::~RaycastingScene ( )

Member Function Documentation

◆ AddTriangles() [1/2]

uint32_t open3d::t::geometry::RaycastingScene::AddTriangles ( const core::Tensor vertex_positions,
const core::Tensor triangle_indices 
)

Add a triangle mesh to the scene.

Parameters
vertex_positionsVertices as Tensor of dim {N,3} and dtype float.
triangle_indicesTriangles as Tensor of dim {M,3} and dtype uint32_t.
Returns
The geometry ID of the added mesh.

◆ AddTriangles() [2/2]

uint32_t open3d::t::geometry::RaycastingScene::AddTriangles ( const TriangleMesh mesh)

Add a triangle mesh to the scene.

Parameters
meshA triangle mesh.
Returns
The geometry ID of the added mesh.

◆ CastRays()

std::unordered_map< std::string, core::Tensor > open3d::t::geometry::RaycastingScene::CastRays ( const core::Tensor rays,
const int  nthreads = 0 
)

Computes the first intersection of the rays with the scene.

Parameters
raysA 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.
nthreadsThe number of threads to use. Set to 0 for automatic.
Returns
The returned dictionary contains:
  • 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}.

◆ ComputeClosestPoints()

std::unordered_map< std::string, core::Tensor > open3d::t::geometry::RaycastingScene::ComputeClosestPoints ( const core::Tensor query_points,
const int  nthreads = 0 
)

Computes the closest points on the surfaces of the scene.

Parameters
query_pointsA 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].
nthreadsThe 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}.

◆ ComputeDistance()

core::Tensor open3d::t::geometry::RaycastingScene::ComputeDistance ( const core::Tensor query_points,
const int  nthreads = 0 
)

Computes the distance to the surface of the scene.

Parameters
query_pointsA 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].
nthreadsThe number of threads to use. Set to 0 for automatic.
Returns
A tensor with the distances to the surface. The shape is {..}.

◆ ComputeOccupancy()

core::Tensor open3d::t::geometry::RaycastingScene::ComputeOccupancy ( const core::Tensor query_points,
const int  nthreads = 0,
const int  nsamples = 1 
)

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_pointsA 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].
nthreadsThe number of threads to use. Set to 0 for automatic.
nsamplesThe number of rays used for determining the inside. This must be an odd number. The default is 1. Use a higher value if you notice errors in the occupancy values. Errors can occur when rays hit exactly an edge or vertex in the scene.
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.

◆ ComputeSignedDistance()

core::Tensor open3d::t::geometry::RaycastingScene::ComputeSignedDistance ( const core::Tensor query_points,
const int  nthreads = 0,
const int  nsamples = 1 
)

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_pointsA 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].
nthreadsThe number of threads to use. Set to 0 for automatic.
nsamplesThe number of rays used for determining the inside. This must be an odd number. The default is 1. Use a higher value if you notice sign flipping, which can occur when rays hit exactly an edge or vertex in the scene.
Returns
A tensor with the signed distances to the surface. The shape is {..}. Negative distances mean a point is inside a closed surface.

◆ CountIntersections()

core::Tensor open3d::t::geometry::RaycastingScene::CountIntersections ( const core::Tensor rays,
const int  nthreads = 0 
)

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

Parameters
raysA 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.
nthreadsThe number of threads to use. Set to 0 for automatic.
Returns
A tensor with the number of intersections. The shape is {..}.

◆ CreateRaysPinhole() [1/2]

core::Tensor open3d::t::geometry::RaycastingScene::CreateRaysPinhole ( const core::Tensor intrinsic_matrix,
const core::Tensor extrinsic_matrix,
int  width_px,
int  height_px 
)
static

Creates rays for the given camera parameters.

Parameters
intrinsic_matrixThe upper triangular intrinsic matrix with shape {3,3}.
extrinsic_matrixThe 4x4 world to camera SE(3) transformation matrix.
width_pxThe width of the image in pixels.
height_pxThe height of the image in pixels.
Returns
A tensor of shape {height_px, width_px, 6} with the rays.

◆ CreateRaysPinhole() [2/2]

core::Tensor open3d::t::geometry::RaycastingScene::CreateRaysPinhole ( double  fov_deg,
const core::Tensor center,
const core::Tensor eye,
const core::Tensor up,
int  width_px,
int  height_px 
)
static

Creates rays for the given camera parameters.

Parameters
fov_degThe horizontal field of view in degree.
centerThe point the camera is looking at with shape {3}.
eyeThe position of the camera with shape {3}.
upThe up-vector with shape {3}.
width_pxThe width of the image in pixels.
height_pxThe height of the image in pixels.
Returns
A tensor of shape {height_px, width_px, 6} with the rays.

◆ INVALID_ID()

uint32_t open3d::t::geometry::RaycastingScene::INVALID_ID ( )
static

The value for invalid IDs.

◆ ListIntersections()

std::unordered_map< std::string, core::Tensor > open3d::t::geometry::RaycastingScene::ListIntersections ( const core::Tensor rays,
const int  nthreads = 0 
)

Lists the intersections of the rays with the scene.

Parameters
raysA tensor with >=2 dims, shape {.., 6}, and Dtype Float32 describing the rays; {..} can be any number of dimensions. 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 although it should be normalised if t_hit is to be calculated in coordinate units.
nthreadsThe number of threads to use. Set to 0 for automatic.
Returns
The returned dictionary contains: ///
  • ray_splits A tensor with ray intersection splits. Can be used to iterate over all intersections for each ray. The shape is {num_rays + 1}.
  • ray_ids A tensor with ray IDs. The shape is {num_intersections}.
  • t_hit A tensor with the distance to the hit. The shape is {num_intersections}.
  • geometry_ids A tensor with the geometry IDs. The shape is {num_intersections}.
  • primitive_ids A tensor with the primitive IDs, which corresponds to the triangle index. The shape is {num_intersections}.
  • primitive_uvs A tensor with the barycentric coordinates of the intersection points within the triangles. The shape is {num_intersections, 2}.

◆ TestOcclusions()

core::Tensor open3d::t::geometry::RaycastingScene::TestOcclusions ( const core::Tensor rays,
const float  tnear = 0.f,
const float  tfar = std::numeric_limits<float>::infinity(),
const int  nthreads = 0 
)

Checks if the rays have any intersection with the scene.

Parameters
raysA 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.
tnearThe tnear offset for the rays. The default is 0.
tfarThe tfar value for the ray. The default is infinity.
nthreadsThe 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).

The documentation for this class was generated from the following files: