Oriented bounding box in 2 D or 3 D. More...
#include <OrientedBoundingBox.h>
Public Member Functions | |
| OrientedBoundingBox () | |
| Default-constructs an empty box (zero dimension, no axes). | |
| OrientedBoundingBox (const std::vector< std::pair< Point, Point > > &axis_pairs) | |
| Build the box from a set of axis end-points. | |
| bool | contains (const Point &pt, const Real tolerance=libMesh::TOLERANCE) const |
| Test whether a point lies inside or on the box. | |
| Point | centroid () const |
| Point | getAxisDirection (unsigned int i) const |
| Real | getAxisLength (unsigned int i) const |
| Point | getMinimalCorner () const |
| Point | getMaximalCorner () const |
| void | print (std::ostream &os) const |
| Print a summary (dimension, origin, axes). | |
| void | writeMesh (const std::filesystem::path &path, const libMesh::Parallel::Communicator &comm) const |
| Write the oriented box as a single libMesh element to a mesh file. | |
| void | writeRayAlongShortestAxis (const std::filesystem::path &ray_path, const libMesh::Parallel::Communicator &comm) const |
| Write a single-EDGE2 mesh representing a "ray" emanating from the box. | |
| Real | getProjectedLength (const Point &pt, unsigned int i) const |
| Get the length of the projection of a point onto axis i. | |
Private Attributes | |
| Point | _minimal_corner |
| shared minimal corner | |
| Point | _maximal_corner |
| shared maximal corner | |
| std::vector< Point > | _dirs |
| orthonormal basis vectors (size = _dim) | |
| std::vector< Real > | _len |
| length along each basis (size = _dim) | |
| unsigned int | _dim = 0u |
| spatial dimension (2 or 3) | |
Oriented bounding box in 2 D or 3 D.
An N-D (N = 2 or 3) oriented bounding box defined by one common origin, N orthonormal directions, and a length along each direction.
Construction is based on N "(min,max)" pairs that share a common min point:
Example (3-D): {{o, o+dx}, {o, o+dy}, {o, o+dz}}
The sequence of pairs is usually supplied in the order main axis, secondary axis, then minor axis (in other class).
Definition at line 44 of file OrientedBoundingBox.h.
|
default |
Default-constructs an empty box (zero dimension, no axes).
|
explicit |
Build the box from a set of axis end-points.
Each element in axis_pairs is a (origin, far-end) pair defining one axis. The first element's first point is taken as the shared origin. The vectors v_i = (axis_pairs[i].second - origin) are normalised to obtain an orthonormal basis; their norms become the edge lengths. If the supplied axes are not mutually orthogonal, construction fails with a run-time assertion.
Definition at line 26 of file OrientedBoundingBox.C.
| Point OrientedBoundingBox::centroid | ( | ) | const |
Definition at line 75 of file OrientedBoundingBox.C.
| bool OrientedBoundingBox::contains | ( | const Point & | pt, |
| const Real | tolerance = libMesh::TOLERANCE |
||
| ) | const |
Test whether a point lies inside or on the box.
| pt | Query point. |
| tolerance | Fuzzy tolerance applied along each axis (default: libMesh::TOLERANCE). |
true if the point projection along every axis falls in the range [0, len_i] within the specified tolerance. Definition at line 61 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::isOutsideBoundingBox().
| Point OrientedBoundingBox::getAxisDirection | ( | unsigned int | i | ) | const |
Definition at line 81 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::sideness().
| Real OrientedBoundingBox::getAxisLength | ( | unsigned int | i | ) | const |
Definition at line 88 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::rayStartOutsideOBB().
| Point OrientedBoundingBox::getMaximalCorner | ( | ) | const |
Definition at line 109 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::rayStartOutsideOBB().
| Point OrientedBoundingBox::getMinimalCorner | ( | ) | const |
Definition at line 103 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::rayStartOutsideOBB().
| Real OrientedBoundingBox::getProjectedLength | ( | const Point & | pt, |
| unsigned int | i | ||
| ) | const |
Get the length of the projection of a point onto axis i.
This computes the length of the projection of the point pt onto the orthonormal basis vector dirs[i], relative to the minimal corner.
| pt | Query point. |
| i | Axis index (0 for first, 1 for second, etc.). |
Definition at line 95 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::rayStartOutsideOBB().
| void OrientedBoundingBox::print | ( | std::ostream & | os | ) | const |
Print a summary (dimension, origin, axes).
Definition at line 53 of file OrientedBoundingBox.C.
| void OrientedBoundingBox::writeMesh | ( | const std::filesystem::path & | path, |
| const libMesh::Parallel::Communicator & | comm | ||
| ) | const |
Write the oriented box as a single libMesh element to a mesh file.
Builds one reference element (QUAD4 in 2-D, HEX8 in 3-D), maps its corners onto the oriented box, and delegates file output to libMesh's mesh writer. The output format is chosen from the file extension (use .e for ExodusII, which is always available). Writing is collective, so all ranks on comm must call it.
| path | Output path; extension selects the libMesh writer. |
| comm | Communicator the temporary mesh is built and written on. |
Definition at line 115 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::buildObbKdtreeAndMaxProjectedDiagonal().
| void OrientedBoundingBox::writeRayAlongShortestAxis | ( | const std::filesystem::path & | ray_path, |
| const libMesh::Parallel::Communicator & | comm | ||
| ) | const |
Write a single-EDGE2 mesh representing a "ray" emanating from the box.
(a) The ray originates at the centre of the face (2-D) or face-centre (3-D) orthogonal to the shortest axis. (b) It is aligned with that shortest axis and its length equals the corresponding edge length.
The output format is chosen from the file extension (use .e for ExodusII). Writing is collective, so all ranks on comm must call it.
| ray_path | Output path; extension selects the libMesh writer. |
| comm | Communicator the temporary mesh is built and written on. |
Definition at line 149 of file OrientedBoundingBox.C.
Referenced by AdaptiveRayContainmentCheck::buildObbKdtreeAndMaxProjectedDiagonal().
|
private |
spatial dimension (2 or 3)
Definition at line 145 of file OrientedBoundingBox.h.
Referenced by contains(), getAxisDirection(), getAxisLength(), getProjectedLength(), OrientedBoundingBox(), print(), writeMesh(), and writeRayAlongShortestAxis().
|
private |
orthonormal basis vectors (size = _dim)
Definition at line 143 of file OrientedBoundingBox.h.
Referenced by contains(), getAxisDirection(), getProjectedLength(), OrientedBoundingBox(), print(), writeMesh(), and writeRayAlongShortestAxis().
|
private |
length along each basis (size = _dim)
Definition at line 144 of file OrientedBoundingBox.h.
Referenced by contains(), getAxisLength(), OrientedBoundingBox(), print(), writeMesh(), and writeRayAlongShortestAxis().
|
private |
shared maximal corner
Definition at line 142 of file OrientedBoundingBox.h.
Referenced by centroid(), getMaximalCorner(), and OrientedBoundingBox().
|
private |
shared minimal corner
Definition at line 141 of file OrientedBoundingBox.h.
Referenced by centroid(), contains(), getMinimalCorner(), getProjectedLength(), OrientedBoundingBox(), print(), writeMesh(), and writeRayAlongShortestAxis().