|
Lagrange
|
A ray caster built on top of Embree that operates directly on SurfaceMesh and SimpleScene objects. More...
#include <lagrange/raycasting/RayCaster.h>
Classes | |
| struct | Impl |
Public Types | |
| using | Pointf = Eigen::Vector3f |
| 3D point type. | |
| using | Directionf = Eigen::Vector3f |
| 3D direction type. | |
| template<typename Scalar> | |
| using | Affine = Eigen::Transform<Scalar, 3, Eigen::Affine> |
| 4x4 affine transform type (column-major). | |
| using | Hit = RayHit |
| Hit result type. | |
Batch types for ray packets of size 4. | |
| using | Point4f = Eigen::Matrix<float, 4, 3, Eigen::RowMajor> |
| using | Direction4f = Eigen::Matrix<float, 4, 3, Eigen::RowMajor> |
| using | Float4 = Eigen::Vector<float, 4> |
| using | Mask4 = Eigen::Vector<bool, 4> |
| using | RayHit4 = RayHitN<4> |
| using | ClosestPointHit4 = ClosestPointHitN<4> |
Batch types for ray packets of size 8. | |
| using | Point8f = Eigen::Matrix<float, 8, 3, Eigen::RowMajor> |
| using | Direction8f = Eigen::Matrix<float, 8, 3, Eigen::RowMajor> |
| using | Float8 = Eigen::Vector<float, 8> |
| using | Mask8 = Eigen::Vector<bool, 8> |
| using | RayHit8 = RayHitN<8> |
| using | ClosestPointHit8 = ClosestPointHitN<8> |
Batch types for ray packets of size 16. | |
| using | Point16f = Eigen::Matrix<float, 16, 3, Eigen::RowMajor> |
| using | Direction16f = Eigen::Matrix<float, 16, 3, Eigen::RowMajor> |
| using | Float16 = Eigen::Vector<float, 16> |
| using | Mask16 = Eigen::Vector<bool, 16> |
| using | RayHit16 = RayHitN<16> |
| using | ClosestPointHit16 = ClosestPointHitN<16> |
Public Member Functions | |
Construction | |
| RayCaster (BitField< SceneFlags > scene_flags=SceneFlags::Robust, BuildQuality build_quality=BuildQuality::Medium) | |
| Construct a RayCaster with the given Embree scene configuration. | |
| ~RayCaster () | |
| Destructor. | |
| RayCaster (RayCaster &&other) noexcept | |
| Move constructor. | |
| RayCaster & | operator= (RayCaster &&other) noexcept |
| Move assignment. | |
| RayCaster (const RayCaster &)=delete | |
| Non-copyable. | |
| RayCaster & | operator= (const RayCaster &)=delete |
| Non-copyable. | |
Scene population | |
| template<typename Scalar, typename Index> | |
| uint32_t | add_mesh (SurfaceMesh< Scalar, Index > mesh, const std::optional< Affine< Scalar > > &transform=Affine< Scalar >::Identity()) |
| Add a single mesh to the scene. | |
| uint32_t | add_instance (uint32_t mesh_index, const Eigen::Affine3f &transform) |
| Add a single instance of an existing source mesh to the scene with a given affine transform. | |
| template<typename Scalar, typename Index> | |
| void | add_scene (scene::SimpleScene< Scalar, Index, 3 > simple_scene) |
| Add all meshes and instances from a SimpleScene. | |
| void | commit_updates () |
| Notify the raycaster that all pending updates have been made and the BVH can be rebuilt. | |
Scene modification | |
| template<typename Scalar, typename Index> | |
| void | update_mesh (uint32_t mesh_index, const SurfaceMesh< Scalar, Index > &mesh) |
| Replace a mesh in the scene. | |
| template<typename Scalar, typename Index> | |
| void | update_vertices (uint32_t mesh_index, const SurfaceMesh< Scalar, Index > &mesh) |
| Notify the raycaster that vertices of a mesh have been modified externally. | |
| template<typename Scalar> | |
| void | update_vertices (uint32_t mesh_index, span< const Scalar > vertices) |
| Notify the raycaster that vertices of a mesh have been modified externally. | |
| Eigen::Affine3f | get_transform (uint32_t mesh_index, uint32_t instance_index) const |
| Get the affine transform of a given mesh instance. | |
| void | update_transform (uint32_t mesh_index, uint32_t instance_index, const Eigen::Affine3f &transform) |
| Update the affine transform of a given mesh instance. | |
| bool | get_visibility (uint32_t mesh_index, uint32_t instance_index) |
| Get the visibility flag of a given mesh instance. | |
| void | update_visibility (uint32_t mesh_index, uint32_t instance_index, bool visible) |
| Update the visibility of a given mesh instance. | |
Filtering | |
| auto | get_intersection_filter (uint32_t mesh_index) const -> std::function< bool(uint32_t instance_index, uint32_t facet_index)> |
| Get the intersection filter function currently bound to a given mesh. | |
| void | set_intersection_filter (uint32_t mesh_index, std::function< bool(uint32_t instance_index, uint32_t facet_index)> &&filter) |
| Set an intersection filter that is called for every hit on (every instance of) a mesh during an intersection query. | |
| auto | get_occlusion_filter (uint32_t mesh_index) const -> std::function< bool(uint32_t instance_index, uint32_t facet_index)> |
| Get the occlusion filter function currently bound to a given mesh. | |
| void | set_occlusion_filter (uint32_t mesh_index, std::function< bool(uint32_t instance_index, uint32_t facet_index)> &&filter) |
| Set an occlusion filter that is called for every hit on (every instance of) a mesh during an occlusion query. | |
Closest point queries | |
| std::optional< ClosestPointHit > | closest_point (const Pointf &query_point) const |
| Find the closest point on the scene to a query point. | |
| ClosestPointHit4 | closest_point4 (const Point4f &query_points, const std::variant< Mask4, size_t > &active) const |
| Find the closest point on the scene for a packet of up to 4 query points. | |
| ClosestPointHit8 | closest_point8 (const Point8f &query_points, const std::variant< Mask8, size_t > &active) const |
| Find the closest point on the scene for a packet of up to 8 query points. | |
| ClosestPointHit16 | closest_point16 (const Point16f &query_points, const std::variant< Mask16, size_t > &active) const |
| Find the closest point on the scene for a packet of up to 16 query points. | |
Closest vertex queries | |
| std::optional< ClosestPointHit > | closest_vertex (const Pointf &query_point) const |
| Find the closest vertex on the scene to a query point. | |
| ClosestPointHit4 | closest_vertex4 (const Point4f &query_points, const std::variant< Mask4, size_t > &active) const |
| Find the closest vertex on the scene for a packet of up to 4 query points. | |
| ClosestPointHit8 | closest_vertex8 (const Point8f &query_points, const std::variant< Mask8, size_t > &active) const |
| Find the closest vertex on the scene for a packet of up to 8 query points. | |
| ClosestPointHit16 | closest_vertex16 (const Point16f &query_points, const std::variant< Mask16, size_t > &active) const |
| Find the closest vertex on the scene for a packet of up to 16 query points. | |
Single-ray queries | |
| std::optional< RayHit > | cast (const Pointf &origin, const Directionf &direction, float tmin=0, float tmax=std::numeric_limits< float >::infinity()) const |
| Cast a single ray and find the closest intersection. | |
| bool | occluded (const Pointf &origin, const Directionf &direction, float tmin=0, float tmax=std::numeric_limits< float >::infinity()) const |
| Test whether a single ray hits anything in the scene (occlusion query). | |
Ray packet queries (4-wide SIMD) | |
| RayHit4 | cast4 (const Point4f &origins, const Direction4f &directions, const std::variant< Mask4, size_t > &active=size_t(4), const Float4 &tmin=Float4::Zero(), const Float4 &tmax=Float4::Constant(std::numeric_limits< float >::infinity())) const |
| Cast a packet of up to 4 rays and find the closest intersections. | |
| uint32_t | occluded4 (const Point4f &origins, const Direction4f &directions, const std::variant< Mask4, size_t > &active=size_t(4), const Float4 &tmin=Float4::Zero(), const Float4 &tmax=Float4::Constant(std::numeric_limits< float >::infinity())) const |
| Test a packet of up to 4 rays for occlusion. | |
Ray packet queries (8-wide SIMD) | |
| RayHit8 | cast8 (const Point8f &origins, const Direction8f &directions, const std::variant< Mask8, size_t > &active=size_t(8), const Float8 &tmin=Float8::Zero(), const Float8 &tmax=Float8::Constant(std::numeric_limits< float >::infinity())) const |
| Cast a packet of up to 8 rays and find the closest intersections. | |
| uint32_t | occluded8 (const Point8f &origins, const Direction8f &directions, const std::variant< Mask8, size_t > &active=size_t(8), const Float8 &tmin=Float8::Zero(), const Float8 &tmax=Float8::Constant(std::numeric_limits< float >::infinity())) const |
| Test a packet of up to 8 rays for occlusion. | |
Ray packet queries (16-wide SIMD) | |
| RayHit16 | cast16 (const Point16f &origins, const Direction16f &directions, const std::variant< Mask16, size_t > &active=size_t(16), const Float16 &tmin=Float16::Zero(), const Float16 &tmax=Float16::Constant(std::numeric_limits< float >::infinity())) const |
| Cast a packet of up to 16 rays and find the closest intersections. | |
| uint32_t | occluded16 (const Point16f &origins, const Direction16f &directions, const std::variant< Mask16, size_t > &active=size_t(16), const Float16 &tmin=Float16::Zero(), const Float16 &tmax=Float16::Constant(std::numeric_limits< float >::infinity())) const |
| Test a packet of up to 16 rays for occlusion. | |
A ray caster built on top of Embree that operates directly on SurfaceMesh and SimpleScene objects.
Supports single-ray and SIMD ray-packet queries (packets of 4, 8, and 16 rays) for efficient vectorized intersection and occlusion testing.
|
explicit |
Construct a RayCaster with the given Embree scene configuration.
| [in] | scene_flags | Embree scene flags. |
| [in] | build_quality | Embree BVH build quality. |
| uint32_t add_mesh | ( | SurfaceMesh< Scalar, Index > | mesh, |
| const std::optional< Affine< Scalar > > & | transform = Affine<Scalar>::Identity() ) |
Add a single mesh to the scene.
The mesh must be a triangle mesh. If the optional transform is provided, a single instance of the mesh is created with that transform. By default, the mesh is added with an identity transform (i.e., a single instance with no transformation).
| [in] | mesh | Triangle mesh to add. The mesh data is moved to the raycaster and buffers are converted to the appropriate types. |
| [in] | transform | Optional affine transformation applied to this instance. If not provided, the mesh is not instantiated. |
| Scalar | Mesh scalar type. |
| Index | Mesh index type. |
| uint32_t add_instance | ( | uint32_t | mesh_index, |
| const Eigen::Affine3f & | transform ) |
Add a single instance of an existing source mesh to the scene with a given affine transform.
| [in] | mesh_index | Index of the source mesh. |
| [in] | transform | Affine transformation applied to this instance. |
| void add_scene | ( | scene::SimpleScene< Scalar, Index, 3 > | simple_scene | ) |
Add all meshes and instances from a SimpleScene.
| [in] | simple_scene | Scene containing meshes and their instances. The scene data is moved to the raycaster and mesh buffers are converted to the appropriate types. |
| Scalar | Scene scalar type. |
| Index | Scene index type. |
| void commit_updates | ( | ) |
Notify the raycaster that all pending updates have been made and the BVH can be rebuilt.
This must be called explicitly by the user before doing any ray-tracing or closest point queries.
| void update_mesh | ( | uint32_t | mesh_index, |
| const SurfaceMesh< Scalar, Index > & | mesh ) |
Replace a mesh in the scene.
All instances of the old mesh will reference the new mesh. Triggers a full BVH rebuild.
| [in] | mesh_index | Index of the mesh to replace. |
| [in] | mesh | New triangle mesh. |
| Scalar | Mesh scalar type. |
| Index | Mesh index type. |
| void update_vertices | ( | uint32_t | mesh_index, |
| const SurfaceMesh< Scalar, Index > & | mesh ) |
Notify the raycaster that vertices of a mesh have been modified externally.
The number and order of vertices must not change.
| [in] | mesh_index | Index of the mesh whose vertices changed. |
| [in] | mesh | The modified mesh with updated vertex positions. |
| Scalar | Mesh scalar type. |
| Index | Mesh index type. |
| void update_vertices | ( | uint32_t | mesh_index, |
| span< const Scalar > | vertices ) |
Notify the raycaster that vertices of a mesh have been modified externally.
The number and order of vertices must not change.
| [in] | mesh_index | Index of the mesh whose vertices changed. |
| [in] | vertices | Updated vertex positions. |
| Scalar | Positions scalar type. |
| Eigen::Affine3f get_transform | ( | uint32_t | mesh_index, |
| uint32_t | instance_index ) const |
Get the affine transform of a given mesh instance.
| [in] | mesh_index | Index of the source mesh. |
| [in] | instance_index | Local instance index relative to other instances of the same source mesh. |
| void update_transform | ( | uint32_t | mesh_index, |
| uint32_t | instance_index, | ||
| const Eigen::Affine3f & | transform ) |
Update the affine transform of a given mesh instance.
| [in] | mesh_index | Index of the source mesh. |
| [in] | instance_index | Local instance index relative to other instances of the same source mesh. |
| [in] | transform | New affine transform to apply. |
| bool get_visibility | ( | uint32_t | mesh_index, |
| uint32_t | instance_index ) |
Get the visibility flag of a given mesh instance.
| [in] | mesh_index | Index of the source mesh. |
| [in] | instance_index | Local instance index relative to the source mesh. |
| void update_visibility | ( | uint32_t | mesh_index, |
| uint32_t | instance_index, | ||
| bool | visible ) |
Update the visibility of a given mesh instance.
| [in] | mesh_index | Index of the source mesh. |
| [in] | instance_index | Local instance index relative to the source mesh. |
| [in] | visible | True to make the instance visible, false to hide it. |
| auto get_intersection_filter | ( | uint32_t | mesh_index | ) | const -> std::function<bool(uint32_t instance_index, uint32_t facet_index)> |
Get the intersection filter function currently bound to a given mesh.
| [in] | mesh_index | Index of the mesh. |
| void set_intersection_filter | ( | uint32_t | mesh_index, |
| std::function< bool(uint32_t instance_index, uint32_t facet_index)> && | filter ) |
Set an intersection filter that is called for every hit on (every instance of) a mesh during an intersection query.
The filter should return true to accept the hit, false to reject it.
| [in] | mesh_index | Index of the mesh. |
| [in] | filter | Filter function, or an empty function to disable filtering. |
| auto get_occlusion_filter | ( | uint32_t | mesh_index | ) | const -> std::function<bool(uint32_t instance_index, uint32_t facet_index)> |
Get the occlusion filter function currently bound to a given mesh.
| [in] | mesh_index | Index of the mesh. |
| void set_occlusion_filter | ( | uint32_t | mesh_index, |
| std::function< bool(uint32_t instance_index, uint32_t facet_index)> && | filter ) |
Set an occlusion filter that is called for every hit on (every instance of) a mesh during an occlusion query.
The filter should return true to accept the hit, false to reject it.
| [in] | mesh_index | Index of the mesh. |
| [in] | filter | Filter function, or an empty function to disable filtering. |
| std::optional< ClosestPointHit > closest_point | ( | const Pointf & | query_point | ) | const |
Find the closest point on the scene to a query point.
| [in] | query_point | The query point in world space. |
| RayCaster::ClosestPointHit4 closest_point4 | ( | const Point4f & | query_points, |
| const std::variant< Mask4, size_t > & | active ) const |
Find the closest point on the scene for a packet of up to 4 query points.
| [in] | query_points | Query points, one per row (4x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| RayCaster::ClosestPointHit8 closest_point8 | ( | const Point8f & | query_points, |
| const std::variant< Mask8, size_t > & | active ) const |
Find the closest point on the scene for a packet of up to 8 query points.
| [in] | query_points | Query points, one per row (8x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| RayCaster::ClosestPointHit16 closest_point16 | ( | const Point16f & | query_points, |
| const std::variant< Mask16, size_t > & | active ) const |
Find the closest point on the scene for a packet of up to 16 query points.
| [in] | query_points | Query points, one per row (16x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| std::optional< ClosestPointHit > closest_vertex | ( | const Pointf & | query_point | ) | const |
Find the closest vertex on the scene to a query point.
Unlike closest_point(), this snaps the result to the nearest triangle vertex rather than returning the closest surface point.
| [in] | query_point | The query point in world space. |
| RayCaster::ClosestPointHit4 closest_vertex4 | ( | const Point4f & | query_points, |
| const std::variant< Mask4, size_t > & | active ) const |
Find the closest vertex on the scene for a packet of up to 4 query points.
| [in] | query_points | Query points, one per row (4x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| RayCaster::ClosestPointHit8 closest_vertex8 | ( | const Point8f & | query_points, |
| const std::variant< Mask8, size_t > & | active ) const |
Find the closest vertex on the scene for a packet of up to 8 query points.
| [in] | query_points | Query points, one per row (8x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| RayCaster::ClosestPointHit16 closest_vertex16 | ( | const Point16f & | query_points, |
| const std::variant< Mask16, size_t > & | active ) const |
Find the closest vertex on the scene for a packet of up to 16 query points.
| [in] | query_points | Query points, one per row (16x3). |
| [in] | active | Either a per-point activity mask (true = active, false = inactive), or the number of active points starting from the top (e.g. 3 means points 0, 1, and 2 are active, point 3 and beyond are inactive). |
| std::optional< RayHit > cast | ( | const Pointf & | origin, |
| const Directionf & | direction, | ||
| float | tmin = 0, | ||
| float | tmax = std::numeric_limits<float>::infinity() ) const |
Cast a single ray and find the closest intersection.
| [in] | origin | Ray origin. |
| [in] | direction | Ray direction (does not need to be normalized). |
| [in] | tmin | Minimum parametric distance. |
| [in] | tmax | Maximum parametric distance. |
| bool occluded | ( | const Pointf & | origin, |
| const Directionf & | direction, | ||
| float | tmin = 0, | ||
| float | tmax = std::numeric_limits<float>::infinity() ) const |
Test whether a single ray hits anything in the scene (occlusion query).
| [in] | origin | Ray origin. |
| [in] | direction | Ray direction (does not need to be normalized). |
| [in] | tmin | Minimum parametric distance. |
| [in] | tmax | Maximum parametric distance. |
| RayCaster::RayHit4 cast4 | ( | const Point4f & | origins, |
| const Direction4f & | directions, | ||
| const std::variant< Mask4, size_t > & | active = size_t(4), | ||
| const Float4 & | tmin = Float4::Zero(), | ||
| const Float4 & | tmax = Float4::Constant(std::numeric_limits<float>::infinity()) ) const |
Cast a packet of up to 4 rays and find the closest intersections.
| [in] | origins | Ray origins, one per row (4x3). |
| [in] | directions | Ray directions, one per row (4x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 is inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |
| uint32_t occluded4 | ( | const Point4f & | origins, |
| const Direction4f & | directions, | ||
| const std::variant< Mask4, size_t > & | active = size_t(4), | ||
| const Float4 & | tmin = Float4::Zero(), | ||
| const Float4 & | tmax = Float4::Constant(std::numeric_limits<float>::infinity()) ) const |
Test a packet of up to 4 rays for occlusion.
| [in] | origins | Ray origins, one per row (4x3). |
| [in] | directions | Ray directions, one per row (4x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 is inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |
| RayCaster::RayHit8 cast8 | ( | const Point8f & | origins, |
| const Direction8f & | directions, | ||
| const std::variant< Mask8, size_t > & | active = size_t(8), | ||
| const Float8 & | tmin = Float8::Zero(), | ||
| const Float8 & | tmax = Float8::Constant(std::numeric_limits<float>::infinity()) ) const |
Cast a packet of up to 8 rays and find the closest intersections.
| [in] | origins | Ray origins, one per row (8x3). |
| [in] | directions | Ray directions, one per row (8x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 and beyond are inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |
| uint32_t occluded8 | ( | const Point8f & | origins, |
| const Direction8f & | directions, | ||
| const std::variant< Mask8, size_t > & | active = size_t(8), | ||
| const Float8 & | tmin = Float8::Zero(), | ||
| const Float8 & | tmax = Float8::Constant(std::numeric_limits<float>::infinity()) ) const |
Test a packet of up to 8 rays for occlusion.
| [in] | origins | Ray origins, one per row (8x3). |
| [in] | directions | Ray directions, one per row (8x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 and beyond are inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |
| RayCaster::RayHit16 cast16 | ( | const Point16f & | origins, |
| const Direction16f & | directions, | ||
| const std::variant< Mask16, size_t > & | active = size_t(16), | ||
| const Float16 & | tmin = Float16::Zero(), | ||
| const Float16 & | tmax = Float16::Constant(std::numeric_limits<float>::infinity()) ) const |
Cast a packet of up to 16 rays and find the closest intersections.
| [in] | origins | Ray origins, one per row (16x3). |
| [in] | directions | Ray directions, one per row (16x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 and beyond are inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |
| uint32_t occluded16 | ( | const Point16f & | origins, |
| const Direction16f & | directions, | ||
| const std::variant< Mask16, size_t > & | active = size_t(16), | ||
| const Float16 & | tmin = Float16::Zero(), | ||
| const Float16 & | tmax = Float16::Constant(std::numeric_limits<float>::infinity()) ) const |
Test a packet of up to 16 rays for occlusion.
| [in] | origins | Ray origins, one per row (16x3). |
| [in] | directions | Ray directions, one per row (16x3). |
| [in] | active | Either a per-ray activity mask (true = active, false = inactive), or the number of active rays starting from the top (e.g. 3 means rays 0, 1, and 2 are active, ray 3 and beyond are inactive). |
| [in] | tmin | Per-ray minimum parametric distances. |
| [in] | tmax | Per-ray maximum parametric distances. |