15#ifndef AABBTREE_BOX_HXX
16#define AABBTREE_BOX_HXX
27 template <
typename Real, Integer N>
class Ray;
48 template <
typename Real, Integer N>
50 static_assert(std::is_floating_point<Real>::value,
"Box Real type must be a floating-point type.");
51 static_assert(N > 0,
"Box dimension must be positive.");
54 constexpr static Real
EPS{std::numeric_limits<Real>::epsilon()};
55 constexpr static Real
INF{std::numeric_limits<Real>::infinity()};
106 template <
typename = std::enable_if<N == 1>>
118 template <
typename = std::enable_if<N == 2>>
119 Box(Real
const x_min, Real
const y_min, Real
const x_max, Real
const y_max)
133 template <
typename = std::enable_if<N == 3>>
135 Real
const x_min, Real
const y_min, Real
const z_min,
136 Real
const x_max, Real
const y_max, Real
const z_max
137 ) :
m_min(x_min, y_min, z_min),
m_max(x_max, y_max, z_max) {}
144 template<
typename OtherReal>
161 template<
typename NewReal>
164 if constexpr (std::is_same<Real, NewReal>::value) {
return *
this;}
197 for (
Integer i{0}; i < N; ++i) {
233 return std::distance(sizes.data(), std::max_element(sizes.data(), sizes.data() + N));
246 for (
Integer i{0}; i < N; ++i) {
247 if (Real
const tmp_length{
m_max(i) -
m_min(i)}; max_length < tmp_length)
248 {max_length = tmp_length; mid_point = 0.5*(
m_max(i) +
m_min(i)); axis = i;}
261 ipos = Eigen::Vector<Integer, N>::LinSpaced(N, 0, N - 1);
262 std::sort(ipos.data(), ipos.data() + N, [&sizes](
Integer i,
Integer j) {return sizes[i] > sizes[j];});
291 for (
Integer i{0}; i < N; ++i) {
343 return (b_out.
m_min.array() <= b_out.
m_max.array()).all();
375 template <
typename Transform>
390 template <
typename Transform>
411 Real
const mi {
m_min(dim) };
412 Real
const ma {
m_max(dim) };
413 bool const on_left { ma < x + tol };
414 bool const on_right { x - tol < mi };
415 if (on_left && on_right) {
429 return (
m_min.array() <= p.array()).all() &&
430 (p.array() <=
m_max.array()).all();
440 return (
m_min.array() <= p.array()).all() && (p.array() <=
m_max.array()).all();
449 return (
m_min.array() <= b.
m_min.array()).all() &&
458 template<
typename Derived>
487 for (
Integer i{0}; i < N; ++i) {
488 if (
m_min[i] > p[i]) {Real aux{
m_min[i] - p[i]}; dist2 += aux*aux;}
489 else if (p[i] >
m_max[i]) {Real aux{p[i] -
m_max[i]}; dist2 += aux*aux;}
506 return (p - c).squaredNorm();
537 for (
Integer i{0}; i < N; ++i) {
538 Real
const aux1{ std::abs(
m_min[i] - p[i])};
539 Real
const aux2{ std::abs(
m_max[i] - p[i])};
540 Real
const aux3{ std::max(aux1,aux2)};
555 for (
Integer i{0}; i < N; ++i) {
556 Real
const aux1{ std::abs(
m_min[i] - p[i])};
557 Real
const aux2{ std::abs(
m_max[i] - p[i])};
560 return (f - p).squaredNorm();
592 for (
Integer i{0}; i < N; ++i) {
596 if (aux < 0.0) {
continue;}
614 for (
Integer i{0}; i < N; ++ i) {
621 return (p2 - p1).squaredNorm();
651 Real dist2{ Real(0)};
652 for (
Integer i{0}; i < N; ++i) {
670 return (p2 - p1).squaredNorm();
809 void print(std::ostream & os)
const {
811 "────────────────────────────────────────────────────────────────────────────────\n" <<
813 "\tmin = " <<
m_min.transpose() <<
'\n' <<
814 "\tmax = " <<
m_max.transpose() <<
'\n' <<
815 "────────────────────────────────────────────────────────────────────────────────\n";
827 template <
typename Real, Integer N>
A class representing an axis-aligned bounding box (AABB) in N-dimensional space.
Definition Box.hxx:49
Box & extend(Point const &p)
Definition Box.hxx:459
Box()
Definition Box.hxx:76
Real squared_interior_distance(Box const &b) const
Definition Box.hxx:589
Box & extend(Box const &b)
Definition Box.hxx:471
Point m_max
Definition Box.hxx:64
static constexpr Real INF
Definition Box.hxx:55
Box transformed(Transform const &t) const
Definition Box.hxx:376
Real squared_exterior_distance(Point const &p) const
Definition Box.hxx:535
void set_degenerate(Point const &p)
Definition Box.hxx:312
bool is_empty() const
Definition Box.hxx:207
Real squared_exterior_distance(Ray< Real, N > const &r, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Box.hxx:779
Box(Real const x_min, Real const y_min, Real const z_min, Real const x_max, Real const y_max, Real const z_max)
Definition Box.hxx:134
static constexpr Real EPS
Definition Box.hxx:54
Real squared_exterior_distance(Box const &b, Point &p1, Point &p2) const
Definition Box.hxx:667
bool intersect(Ray< Real, N > const &r, Point &c, Point &f, Real tol=DUMMY_TOL) const
Definition Box.hxx:711
Real baricenter(Integer i) const
Definition Box.hxx:276
void reorder()
Definition Box.hxx:196
void set_empty()
Definition Box.hxx:320
Real squared_exterior_distance(Ray< Real, N > const &r, Real tol=DUMMY_TOL) const
Definition Box.hxx:767
bool contains(Box const &b) const
Definition Box.hxx:448
Box(Real const x_min, Real const y_min, Real const x_max, Real const y_max)
Definition Box.hxx:119
Real exterior_distance(Box const &b) const
Definition Box.hxx:679
Real surface() const
Definition Box.hxx:288
static constexpr Real DUMMY_TOL
Definition Box.hxx:56
Box & translate(Vector const &t)
Definition Box.hxx:359
Real exterior_distance(Ray< Real, N > const &r, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Box.hxx:802
Side which_side(Real const x, Real const tol, Integer const dim) const
Definition Box.hxx:410
Real squared_exterior_distance(Point const &p, Point &f) const
Definition Box.hxx:554
Box(Real const x_min, Real const x_max)
Definition Box.hxx:107
Box< NewReal, N > cast() const
Definition Box.hxx:162
Real squared_interior_distance(Point const &p) const
Definition Box.hxx:484
Real squared_interior_distance(Box const &b, Point &p1, Point &p2) const
Definition Box.hxx:612
Real interior_distance(Point const &p) const
Definition Box.hxx:515
Real exterior_distance(Point const &p) const
Definition Box.hxx:569
void sort_axes_length(Vector &sizes, Eigen::Vector< Integer, N > &ipos) const
Definition Box.hxx:258
Box & operator=(Box const &b)=default
bool contains(Point const &p) const
Definition Box.hxx:428
bool intersects(Ray< Real, N > const &r, Real tol=DUMMY_TOL) const
Definition Box.hxx:700
Real interior_distance(Point const &p, Point &c) const
Definition Box.hxx:526
Point const & min() const
Definition Box.hxx:172
Box & transform(Transform const &t)
Definition Box.hxx:391
AABBtree::BoxUniquePtrList< Real, N > BoxUniquePtrList
Definition Box.hxx:61
bool is_degenerate(Real const tol) const
Definition Box.hxx:223
Box(Box const &b)
Definition Box.hxx:82
AABBtree::Vector< Real, N > Vector
Definition Box.hxx:59
Real squared_interior_distance(Point const &p, Point &c) const
Definition Box.hxx:503
Real interior_distance(Ray< Real, N > const &r, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Box.hxx:757
Box(Point const &p)
Definition Box.hxx:97
Point baricenter() const
Definition Box.hxx:269
bool intersect(Box const &b_in, Box &b_out) const
Definition Box.hxx:340
AABBtree::BoxUniquePtr< Real, N > BoxUniquePtr
Definition Box.hxx:60
Real exterior_distance(Ray< Real, N > const &r, Real tol=DUMMY_TOL) const
Definition Box.hxx:789
Integer longest_axis() const
Definition Box.hxx:230
Real squared_interior_distance(Ray< Real, N > const &r, Point &p1, Point &p2, Real tol=DUMMY_TOL) const
Definition Box.hxx:734
AABBtree::Point< Real, N > Point
Definition Box.hxx:58
Side
Definition Box.hxx:401
@ RIGHT
Definition Box.hxx:401
@ INSIDE
Definition Box.hxx:401
@ LEFT
Definition Box.hxx:401
Real squared_exterior_distance(Box const &b) const
Definition Box.hxx:650
Box(Point const &t_min, Point const &t_max)
Definition Box.hxx:91
bool is_approx(Box const &b, Real const tol) const
Definition Box.hxx:215
Point m_min
Definition Box.hxx:63
Real squared_interior_distance(Ray< Real, N > const &r, Real tol=DUMMY_TOL) const
Definition Box.hxx:721
Integer longest_axis(Real &max_length, Real &mid_point) const
Definition Box.hxx:242
Point & min()
Definition Box.hxx:178
Point & max()
Definition Box.hxx:190
Vector diagonal() const
Definition Box.hxx:306
Real interior_distance(Box const &b) const
Definition Box.hxx:630
void print(std::ostream &os) const
Definition Box.hxx:809
bool intersects(Box const &b) const
Definition Box.hxx:330
bool intersects(Point const &p) const
Definition Box.hxx:439
Real interior_distance(Ray< Real, N > const &r, Real tol=DUMMY_TOL) const
Definition Box.hxx:744
Real exterior_distance(Box const &b, Point &p1, Point &p2) const
Definition Box.hxx:691
Real exterior_distance(Point const &p, Point &f) const
Definition Box.hxx:580
Point const & max() const
Definition Box.hxx:184
Real interior_distance(Box const &b, Point &p1, Point &p2) const
Definition Box.hxx:641
Real volume() const
Definition Box.hxx:282
Box(Box< OtherReal, N > const &b)
Definition Box.hxx:145
Box translated(Vector const &t) const
Definition Box.hxx:366
Box merged(Box const &b) const
Definition Box.hxx:351
A mathematical ray in N-dimensional space.
Definition Ray.hxx:39
bool intersects(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:239
Real squared_interior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:340
Real interior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:406
bool intersect(Box< Real, N > const &b, Point &c, Point &f, Real tol=DUMMY_TOL) const
Definition Ray.hxx:266
Real exterior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:495
Real squared_exterior_distance(Box< Real, N > const &b, Real tol=DUMMY_TOL) const
Definition Ray.hxx:429
Namespace for the AABBtree library.
Definition AABBtree.hh:70
Eigen::Vector< Real, N > Point
Definition AABBtree.hh:91
std::ostream & operator<<(std::ostream &os, Box< Real, N > const &b)
Definition Box.hxx:828
std::unique_ptr< Box< Real, N > > BoxUniquePtr
Definition AABBtree.hh:88
std::vector< BoxUniquePtr< Real, N > > BoxUniquePtrList
Definition AABBtree.hh:89
Eigen::Vector< Real, N > Vector
Definition AABBtree.hh:90
AABBTREE_DEFAULT_INTEGER_TYPE Integer
The Integer type used in the AABBtree class.
Definition AABBtree.hh:78