Ray-casting point-in-solid engine over a closed surface mesh represented as a collection of SurfaceElement wrappers. More...
#include <AdaptiveRayContainmentCheck.h>
Public Member Functions | |
| AdaptiveRayContainmentCheck (const std::vector< std::unique_ptr< SurfaceElement > > &bd_elements, const std::vector< Point > ¢roids, const SurfaceGeometry::RayDirectionOptions &ray_options, const Real eps_on_surface=libMesh::TOLERANCE, const int leaf_max_size=10, const FileName &obb_file_name="", const FileName &ray_file_name="", const libMesh::Parallel::Communicator *comm=nullptr) | |
| SurfaceGeometry::SurfaceSide | sideness (const Point &p) const |
| Main function: Determine if a point is inside the geometry. | |
| const Point & | rayDirection () const |
| The resolved ray direction actually used for shooting: the (normalized) user direction for a user-selected ray, or the PCA-selected direction for an auto ray. | |
Private Member Functions | |
| bool | rayIntersectGeometry (const Point &ray_start, const Point &ray_end, const SurfaceElement *elem) const |
| Ray-element intersection (e.g., ray-line for 2D, ray-triangle for 3D) | |
| bool | isOutsideBoundingBox (const Point &query_point) const |
| Check if point is outside global bounding box. | |
| bool | isOutsideRayBBox (const Point &orig, const Point &dir, const Ball &ball) const |
| Check if element center is outside ray bounding box. | |
| bool | isOutsideBoundingRegion (const Point &orig, const Point &dir, const Ball &ball) const |
| Check if element center is outside ray bounding circle/sphere. | |
| BoundingBox | computeGlobalBoundingBox () |
| Compute the global bounding box of all boundary elements. | |
| void | preparePCASVD () |
| void | initializeRayDirection () |
| Finalizes the ray direction and the matching bounding box. | |
| std::optional< SurfaceGeometry::SurfaceSide > | sidenessFromRayPair (const Point &p, const std::array< Point, 2 > &ray_starts) const |
| Determine sideness from a pair of opposite rays. | |
| bool | isOnSurface (const Point &p) const |
True if p lies on the surface (within _eps_on_surface), i.e. | |
| int | countCrossings (const Point &ray_start, const Point &ray_end, const bool use_primary_direction=true) const |
Count how many times the segment from ray_start to ray_end crosses the surface. | |
| template<typename CrossingTest > | |
| int | countFilteredCrossings (const Point &ray_start, const Point &ray_end, const bool use_primary_direction, CrossingTest is_crossing) const |
| Shared traversal for the 2D and 3D crossing counts: walk the candidate elements (KD-tree candidates for the primary direction, all elements otherwise), apply the ray-bbox and bounding-region pruning, and count those for which is_crossing(surface) is true. | |
| int | countCrossings2D (const Point &ray_start, const Point &ray_end, const bool use_primary_direction) const |
| 2D crossing count using a half-open side-based crossing rule: an edge is counted when its two endpoints lie on strictly opposite sides of the ray line (a vertex or collinear edge exactly on the line is thus counted consistently, with no tolerance) and the crossing is on the ray_start side of the query point. | |
| Point | rayStartOutsideAABB (const Point &point, const Point &unit_direction, const bool inverted) const |
Ray start strictly outside the global AABB along unit_direction, for any direction. | |
| Point | rayStartOutsideOBB (const Point &point, const Point &ray_direction, const unsigned int obb_axis, const bool inverted=false) const |
| Computes the starting point of an OBB-based ray (auto/PCA policy) for a given query point. | |
| Point | projectPointOntoPlane (const Point &point_to_project, const Point &plane_point, const Point &plane_normal) const |
Orthogonally project point_to_project onto the plane defined by plane_point and unit normal plane_normal. | |
| void | buildObbKdtreeAndMaxProjectedDiagonal (const Real expand_box_length) |
| Constructs an oriented bounding box (OBB) using the results of PCA and the KD-tree. | |
| std::vector< unsigned int > | collectCandidateElementIDs (const Point &query_point) const |
| Use the kd-tree to collect candidate element IDs to check intersections. | |
Private Attributes | |
| Point | _centroid_nodal_points |
| The centroid of the boundary elements' node points (prepare inside this class). | |
| std::vector< Point > | _projected_centroids |
| Projected centroids of the elements in the boundary mesh. | |
| std::unique_ptr< KDTree > | _kd_tree |
| The KDTree is constructed using the projected centroids of the elements in the boundary mesh. | |
| Real | _max_projected_diag_length |
| The maximum diagonal length of the projected bounding box from the boundary elements. | |
| const std::vector< std::unique_ptr< SurfaceElement > > & | _bd_elements |
| pass into the constructor for the surface elements | |
| const std::vector< Point > & | _centroids |
| pass into the constructor for the surface element centroids | |
| int | _dim = -1 |
| The dimension of the embedding mesh. | |
| std::size_t | _num_elements = 0 |
| The number of elements in the boundary mesh. | |
| Point | _ray_direction |
| Ray shooting direction. | |
| Real | _eps_on_surface |
| Epsilon value for checking if a point is on the surface of the geometry. | |
| int | _leaf_max_size |
| Configures KDTree leaf node size for performance tuning. | |
| FileName | _obb_file_name |
| The file name for the OBB. | |
| FileName | _ray_file_name |
| The file name for the ray. | |
| const libMesh::Parallel::Communicator * | _comm = nullptr |
| Communicator used only for writing the debug OBB/ray mesh files. | |
| OrientedBoundingBox | _obb_bounds |
| The oriented bounding box (OBB). | |
| BoundingBox | _bounds |
| The bounding box AABB. | |
| bool | _auto_ray_direction = false |
| Whether the ray direction is auto-selected via PCA (true) or user-selected (false). | |
| bool | _build_obb = false |
| When the ray direction is auto-selected (PCA) we build an Oriented Bounding Box (OBB); a user-selected ray uses only the global Axis-Aligned Bounding Box (AABB) instead. | |
| Point | _plane_origin = Point(0.0, 0.0, 0.0) |
| The origin of the plane used to ensure that every projected point is correctly aligned and lies on the same plane. | |
| Point | _max_variance_vector |
| max variance vector | |
| Point | _second_variance_vector |
| second max variance vector | |
| Point | _min_variance_vector |
| min variance vector (only used for 3D) | |
Ray-casting point-in-solid engine over a closed surface mesh represented as a collection of SurfaceElement wrappers.
The shooting direction follows one of two explicit policies (RayDirectionMode):
Definition at line 36 of file AdaptiveRayContainmentCheck.h.
| AdaptiveRayContainmentCheck::AdaptiveRayContainmentCheck | ( | const std::vector< std::unique_ptr< SurfaceElement > > & | bd_elements, |
| const std::vector< Point > & | centroids, | ||
| const SurfaceGeometry::RayDirectionOptions & | ray_options, | ||
| const Real | eps_on_surface = libMesh::TOLERANCE, |
||
| const int | leaf_max_size = 10, |
||
| const FileName & | obb_file_name = "", |
||
| const FileName & | ray_file_name = "", |
||
| const libMesh::Parallel::Communicator * | comm = nullptr |
||
| ) |
Definition at line 19 of file AdaptiveRayContainmentCheck.C.
|
private |
Constructs an oriented bounding box (OBB) using the results of PCA and the KD-tree.
During this process, it also finds the maximum projected diagonal length.
Definition at line 506 of file AdaptiveRayContainmentCheck.C.
Referenced by AdaptiveRayContainmentCheck().
|
private |
Use the kd-tree to collect candidate element IDs to check intersections.
Definition at line 616 of file AdaptiveRayContainmentCheck.C.
Referenced by countFilteredCrossings(), and isOnSurface().
|
private |
Compute the global bounding box of all boundary elements.
Definition at line 310 of file AdaptiveRayContainmentCheck.C.
Referenced by initializeRayDirection().
|
private |
Count how many times the segment from ray_start to ray_end crosses the surface.
The primary direction uses KD-tree candidates; PCA fallback directions scan all elements because the KD-tree projection is aligned only with the primary direction. Callers must rule out the on-surface case (via isOnSurface) before interpreting the count.
Definition at line 196 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness(), and sidenessFromRayPair().
|
private |
2D crossing count using a half-open side-based crossing rule: an edge is counted when its two endpoints lie on strictly opposite sides of the ray line (a vertex or collinear edge exactly on the line is thus counted consistently, with no tolerance) and the crossing is on the ray_start side of the query point.
See countCrossings() for the parameters.
Definition at line 213 of file AdaptiveRayContainmentCheck.C.
Referenced by countCrossings().
|
private |
Shared traversal for the 2D and 3D crossing counts: walk the candidate elements (KD-tree candidates for the primary direction, all elements otherwise), apply the ray-bbox and bounding-region pruning, and count those for which is_crossing(surface) is true.
The per-dimension crossing test is supplied by the caller so the pruning loop lives in exactly one place. Defined in the .C: only the two in-file callers instantiate it.
Definition at line 167 of file AdaptiveRayContainmentCheck.C.
Referenced by countCrossings(), and countCrossings2D().
|
private |
Finalizes the ray direction and the matching bounding box.
Finalize the ray direction (auto -> PCA, user -> as given) and its bounding box.
For an auto ray it sets _ray_direction to the PCA-selected direction and requests the OBB; for a user-selected ray it retains the user's direction and builds the global AABB.
Definition at line 376 of file AdaptiveRayContainmentCheck.C.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
True if p lies on the surface (within _eps_on_surface), i.e.
some candidate element contains it. This is a property of p alone, independent of any ray direction.
Definition at line 157 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness().
|
private |
Check if point is outside global bounding box.
Definition at line 259 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness().
|
private |
Check if element center is outside ray bounding circle/sphere.
Definition at line 290 of file AdaptiveRayContainmentCheck.C.
Referenced by countFilteredCrossings().
|
private |
Check if element center is outside ray bounding box.
Definition at line 266 of file AdaptiveRayContainmentCheck.C.
Referenced by countFilteredCrossings().
|
private |
Definition at line 430 of file AdaptiveRayContainmentCheck.C.
Referenced by AdaptiveRayContainmentCheck().
|
private |
Orthogonally project point_to_project onto the plane defined by plane_point and unit normal plane_normal.
plane_normal is assumed to be a unit vector.
Definition at line 419 of file AdaptiveRayContainmentCheck.C.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), collectCandidateElementIDs(), and rayStartOutsideOBB().
|
inline |
The resolved ray direction actually used for shooting: the (normalized) user direction for a user-selected ray, or the PCA-selected direction for an auto ray.
Definition at line 53 of file AdaptiveRayContainmentCheck.h.
|
private |
Ray-element intersection (e.g., ray-line for 2D, ray-triangle for 3D)
Definition at line 250 of file AdaptiveRayContainmentCheck.C.
Referenced by countCrossings().
|
private |
Ray start strictly outside the global AABB along unit_direction, for any direction.
The 8 AABB corners are projected onto the direction to find the box extent, and the start is placed just past the far side (a scale-aware padding), moving only the distance needed. inverted shoots from the opposite side. unit_direction must be normalized.
Definition at line 391 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness().
|
private |
Computes the starting point of an OBB-based ray (auto/PCA policy) for a given query point.
The point is projected onto the OBB face normal to ray_direction, selected by obb_axis, and displaced along that same direction so the ray originates outside the geometry.
Definition at line 332 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness().
| SurfaceGeometry::SurfaceSide AdaptiveRayContainmentCheck::sideness | ( | const Point & | p | ) | const |
Main function: Determine if a point is inside the geometry.
Definition at line 78 of file AdaptiveRayContainmentCheck.C.
|
private |
Determine sideness from a pair of opposite rays.
A conflicting parity returns std::nullopt so the caller can apply the selected ambiguity policy.
Definition at line 132 of file AdaptiveRayContainmentCheck.C.
Referenced by sideness().
|
private |
Whether the ray direction is auto-selected via PCA (true) or user-selected (false).
Set once in the constructor from the SurfaceGeometry::RayDirectionOptions mode. Only an auto ray runs PCA and may have its direction chosen automatically.
Definition at line 112 of file AdaptiveRayContainmentCheck.h.
Referenced by AdaptiveRayContainmentCheck(), initializeRayDirection(), and sideness().
|
private |
pass into the constructor for the surface elements
Definition at line 73 of file AdaptiveRayContainmentCheck.h.
Referenced by AdaptiveRayContainmentCheck(), buildObbKdtreeAndMaxProjectedDiagonal(), computeGlobalBoundingBox(), countFilteredCrossings(), isOnSurface(), and preparePCASVD().
|
private |
The bounding box AABB.
Definition at line 107 of file AdaptiveRayContainmentCheck.h.
Referenced by initializeRayDirection(), isOutsideBoundingBox(), and rayStartOutsideAABB().
|
private |
When the ray direction is auto-selected (PCA) we build an Oriented Bounding Box (OBB); a user-selected ray uses only the global Axis-Aligned Bounding Box (AABB) instead.
Definition at line 116 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), initializeRayDirection(), isOutsideBoundingBox(), and rayStartOutsideOBB().
|
private |
The centroid of the boundary elements' node points (prepare inside this class).
Definition at line 58 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), and preparePCASVD().
|
private |
pass into the constructor for the surface element centroids
Definition at line 76 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
Communicator used only for writing the debug OBB/ray mesh files.
Null when no debug output is requested.
Definition at line 101 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
The dimension of the embedding mesh.
Definition at line 79 of file AdaptiveRayContainmentCheck.h.
Referenced by AdaptiveRayContainmentCheck(), buildObbKdtreeAndMaxProjectedDiagonal(), collectCandidateElementIDs(), countCrossings(), initializeRayDirection(), isOutsideBoundingRegion(), isOutsideRayBBox(), rayStartOutsideOBB(), and sideness().
|
private |
Epsilon value for checking if a point is on the surface of the geometry.
Definition at line 88 of file AdaptiveRayContainmentCheck.h.
Referenced by computeGlobalBoundingBox(), isOnSurface(), isOutsideBoundingBox(), rayStartOutsideAABB(), and rayStartOutsideOBB().
|
private |
The KDTree is constructed using the projected centroids of the elements in the boundary mesh.
(prepare inside this class)
Definition at line 67 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), and collectCandidateElementIDs().
|
private |
Configures KDTree leaf node size for performance tuning.
Definition at line 91 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
The maximum diagonal length of the projected bounding box from the boundary elements.
Definition at line 70 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), and collectCandidateElementIDs().
|
private |
max variance vector
Definition at line 123 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), and preparePCASVD().
|
private |
min variance vector (only used for 3D)
Definition at line 129 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), initializeRayDirection(), and preparePCASVD().
|
private |
The number of elements in the boundary mesh.
Definition at line 82 of file AdaptiveRayContainmentCheck.h.
Referenced by AdaptiveRayContainmentCheck(), buildObbKdtreeAndMaxProjectedDiagonal(), and countFilteredCrossings().
|
private |
The oriented bounding box (OBB).
Definition at line 104 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), isOutsideBoundingBox(), rayStartOutsideOBB(), and sideness().
|
private |
The file name for the OBB.
Definition at line 94 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
The origin of the plane used to ensure that every projected point is correctly aligned and lies on the same plane.
This is for fast k-d tree searching to select the candidate elements to check the intersection.
Definition at line 120 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), and collectCandidateElementIDs().
|
private |
Projected centroids of the elements in the boundary mesh.
(prepare inside this class) This is used to construct the KDTree in this struct for fast searching.
Definition at line 63 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
Ray shooting direction.
Definition at line 85 of file AdaptiveRayContainmentCheck.h.
Referenced by AdaptiveRayContainmentCheck(), buildObbKdtreeAndMaxProjectedDiagonal(), collectCandidateElementIDs(), initializeRayDirection(), rayDirection(), and sideness().
|
private |
The file name for the ray.
Definition at line 97 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
second max variance vector
Definition at line 126 of file AdaptiveRayContainmentCheck.h.
Referenced by buildObbKdtreeAndMaxProjectedDiagonal(), initializeRayDirection(), and preparePCASVD().