![]() |
ACloudViewer
3.9.4
A Modern Library for 3D Data Processing
|
A scene class with basic ray casting and closest point queries. More...
#include <RaycastingScene.h>
Classes | |
| struct | CPUImpl |
| struct | Impl |
Public Member Functions | |
| RaycastingScene (int64_t nthreads=0, const core::Device &device=core::Device("CPU: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::Tensor > | CastRays (const core::Tensor &rays, const int nthreads=0) const |
| 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::Tensor > | ListIntersections (const core::Tensor &rays, const int nthreads=0) |
| Lists the intersections of the rays with the scene. More... | |
| std::unordered_map< std::string, core::Tensor > | ComputeClosestPoints (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 ¢er, 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... | |
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.
Definition at line 30 of file RaycastingScene.h.
| cloudViewer::t::geometry::RaycastingScene::RaycastingScene | ( | int64_t | nthreads = 0, |
| const core::Device & | device = core::Device("CPU:0") |
||
| ) |
Default Constructor.
Definition at line 1197 of file RaycastingScene.cpp.
References cloudViewer::core::Device::IsSYCL(), NULL, and patch::to_string().
| cloudViewer::t::geometry::RaycastingScene::~RaycastingScene | ( | ) |
Definition at line 1232 of file RaycastingScene.cpp.
| uint32_t cloudViewer::t::geometry::RaycastingScene::AddTriangles | ( | const core::Tensor & | vertex_positions, |
| const core::Tensor & | triangle_indices | ||
| ) |
Add a triangle mesh to the scene.
| vertex_positions | Vertices as Tensor of dim {N,3} and dtype float. |
| triangle_indices | Triangles as Tensor of dim {M,3} and dtype uint32_t. |
Definition at line 1237 of file RaycastingScene.cpp.
References AssertTensorDevice, AssertTensorDtype, AssertTensorShape, cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Tensor::GetLength(), cloudViewer::utility::nullopt, and cloudViewer::core::UInt32.
Referenced by cloudViewer::t::geometry::TriangleMesh::ComputeMetrics(), cloudViewer::t::geometry::TriangleMesh::ProjectImagesToAlbedo(), and cloudViewer::t::geometry::pybind_raycasting_scene().
| uint32_t cloudViewer::t::geometry::RaycastingScene::AddTriangles | ( | const TriangleMesh & | mesh | ) |
Add a triangle mesh to the scene.
| mesh | A triangle mesh. |
Definition at line 1310 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::GetLength(), cloudViewer::t::geometry::TriangleMesh::GetTriangleIndices(), cloudViewer::t::geometry::TriangleMesh::GetVertexPositions(), LogError, max(), cloudViewer::core::Tensor::To(), and cloudViewer::core::UInt32.
| std::unordered_map< std::string, core::Tensor > cloudViewer::t::geometry::RaycastingScene::CastRays | ( | const core::Tensor & | rays, |
| const int | nthreads = 0 |
||
| ) | const |
Computes the first intersection of the rays with the scene.
| rays | 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 | The number of threads to use. Set to 0 for automatic. |
Definition at line 1321 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Tensor::GetDevice(), cloudViewer::core::Tensor::GetShape(), cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back(), result, and cloudViewer::core::UInt32.
Referenced by cloudViewer::t::geometry::TriangleMesh::ProjectImagesToAlbedo(), and cloudViewer::t::geometry::pybind_raycasting_scene().
| std::unordered_map< std::string, core::Tensor > cloudViewer::t::geometry::RaycastingScene::ComputeClosestPoints | ( | const core::Tensor & | query_points, |
| const int | nthreads = 0 |
||
| ) |
Computes the closest points on the surfaces of the scene.
| query_points | 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 | The number of threads to use. Set to 0 for automatic. |
Definition at line 1462 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Tensor::GetShape(), cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back(), result, and cloudViewer::core::UInt32.
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
| core::Tensor cloudViewer::t::geometry::RaycastingScene::ComputeDistance | ( | const core::Tensor & | query_points, |
| const int | nthreads = 0 |
||
| ) |
Computes the distance to the surface of the scene.
| query_points | 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 | The number of threads to use. Set to 0 for automatic. |
Definition at line 1492 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Tensor::GetDataPtr(), cloudViewer::core::Tensor::GetShape(), and cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back().
Referenced by cloudViewer::t::geometry::TriangleMesh::ComputeMetrics(), and cloudViewer::t::geometry::pybind_raycasting_scene().
| core::Tensor cloudViewer::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.
| query_points | 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 | The number of threads to use. Set to 0 for automatic. |
| nsamples | The 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. |
Definition at line 1614 of file RaycastingScene.cpp.
References cloudViewer::core::Float32, LogError, and result.
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
| core::Tensor cloudViewer::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.
| query_points | 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 | The number of threads to use. Set to 0 for automatic. |
| nsamples | The 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. |
Definition at line 1586 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Tensor::GetShape(), LogError, and cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back().
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
| core::Tensor cloudViewer::t::geometry::RaycastingScene::CountIntersections | ( | const core::Tensor & | rays, |
| const int | nthreads = 0 |
||
| ) |
Computes the number of intersection of the rays with the scene.
| rays | 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 | The number of threads to use. Set to 0 for automatic. |
Definition at line 1376 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Tensor::GetDataPtr(), cloudViewer::core::Tensor::GetShape(), and cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back().
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
|
static |
Creates rays for the given camera parameters.
| intrinsic_matrix | The upper triangular intrinsic matrix with shape {3,3}. |
| extrinsic_matrix | The 4x4 world to camera SE(3) transformation matrix. |
| width_px | The width of the image in pixels. |
| height_px | The height of the image in pixels. |
Definition at line 1629 of file RaycastingScene.cpp.
References AssertTensorDevice, AssertTensorShape, cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Float64, and cloudViewer::core::Tensor::To().
Referenced by cloudViewer::t::geometry::TriangleMesh::ProjectImagesToAlbedo(), and cloudViewer::t::geometry::pybind_raycasting_scene().
|
static |
Creates rays for the given camera parameters.
| fov_deg | The horizontal field of view in degree. |
| center | The point the camera is looking at with shape {3}. |
| eye | The position of the camera with shape {3}. |
| up | The up-vector with shape {3}. |
| width_px | The width of the image in pixels. |
| height_px | The height of the image in pixels. |
Definition at line 1673 of file RaycastingScene.cpp.
References AssertTensorDevice, AssertTensorShape, cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float64, cloudViewer::core::Tensor::GetDataPtr(), M_PI, and cloudViewer::core::Tensor::To().
|
static |
The value for invalid IDs.
Definition at line 1727 of file RaycastingScene.cpp.
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
| std::unordered_map< std::string, core::Tensor > cloudViewer::t::geometry::RaycastingScene::ListIntersections | ( | const core::Tensor & | rays, |
| const int | nthreads = 0 |
||
| ) |
Lists the intersections of the rays with the scene.
| rays | A 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. |
| nthreads | The number of threads to use. Set to 0 for automatic. |
Definition at line 1396 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Float32, cloudViewer::core::Tensor::GetDataPtr(), cloudViewer::core::Tensor::GetShape(), cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back(), result, cloudViewer::core::Tensor::To(), cloudViewer::core::UInt32, and cloudViewer::core::Zeros().
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().
| core::Tensor cloudViewer::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.
| rays | 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 | The tnear offset for the rays. The default is 0. |
| tfar | The tfar value for the ray. The default is infinity. |
| nthreads | The number of threads to use. Set to 0 for automatic. |
Definition at line 1355 of file RaycastingScene.cpp.
References cloudViewer::core::Tensor::Contiguous(), cloudViewer::core::Tensor::GetDevice(), cloudViewer::core::Tensor::GetShape(), cloudViewer::core::SmallVectorTemplateBase< T, bool >::pop_back(), and result.
Referenced by cloudViewer::t::geometry::pybind_raycasting_scene().