15#include <Eigen/Geometry>
29 template <
typename DerivedV,
int DIM>
37 typedef typename DerivedV::Scalar
Scalar;
52 Eigen::AlignedBox<Scalar,DIM>
m_box;
67 static_assert(DerivedV::ColsAtCompileTime == DIM || DerivedV::ColsAtCompileTime == Eigen::Dynamic,
"DerivedV::ColsAtCompileTime == DIM || DerivedV::ColsAtCompileTime == Eigen::Dynamic");
87 friend void swap(AABB& first, AABB& second)
119 m_box = Eigen::AlignedBox<Scalar,DIM>();
135 assert(
false &&
"I'm not my parent's child");
137 auto * grandparent =
m_parent->m_parent;
192 const std::vector<AABB<DerivedV,DIM>*> & leaves,
194 const int polish_rotate_passes=0);
213 const Eigen::AlignedBox<Scalar,DIM> & new_box,
399 AABB<DerivedV,DIM>* reining,
400 AABB<DerivedV,DIM>* grandparent,
401 AABB<DerivedV,DIM>* parent,
402 AABB<DerivedV,DIM>* challenger,
403 AABB<DerivedV,DIM>* sibling);
419 const Eigen::AlignedBox<Scalar,DIM> & box,
420 std::vector<
const AABB<DerivedV,DIM>*> & leaves)
const;
454 const Scalar sqr_d_candidate,
455 const int & i_candidate,
459 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
478 typename Derivedbb_mins,
479 typename Derivedbb_maxs,
480 typename Derivedelements>
482 const Eigen::MatrixBase<DerivedV> & V,
483 const Eigen::MatrixBase<DerivedEle> & Ele,
484 const Eigen::MatrixBase<Derivedbb_mins> & bb_mins,
485 const Eigen::MatrixBase<Derivedbb_maxs> & bb_maxs,
486 const Eigen::MatrixBase<Derivedelements> & elements,
493 template <
typename DerivedEle>
495 const Eigen::MatrixBase<DerivedV> & V,
496 const Eigen::MatrixBase<DerivedEle> & Ele);
508 template <
typename DerivedEle,
typename DerivedSI,
typename DerivedI>
510 const Eigen::MatrixBase<DerivedV> & V,
511 const Eigen::MatrixBase<DerivedEle> & Ele,
512 const Eigen::MatrixBase<DerivedSI> & SI,
513 const Eigen::MatrixBase<DerivedI>& I);
516 template <
typename DerivedEle>
518 const Eigen::MatrixBase<DerivedV> & V,
519 const Eigen::MatrixBase<DerivedEle> & Ele,
532 template <
typename DerivedEle,
typename Derivedq>
534 const Eigen::MatrixBase<DerivedV> & V,
535 const Eigen::MatrixBase<DerivedEle> & Ele,
536 const Eigen::MatrixBase<Derivedq> & q,
537 const bool first=
false)
const;
549 typename Derivedbb_mins,
550 typename Derivedbb_maxs,
551 typename Derivedelements>
553 Eigen::PlainObjectBase<Derivedbb_mins> & bb_mins,
554 Eigen::PlainObjectBase<Derivedbb_maxs> & bb_maxs,
555 Eigen::PlainObjectBase<Derivedelements> & elements,
556 const int i = 0)
const;
568 template <
typename DerivedEle>
570 const Eigen::MatrixBase<DerivedV> & V,
571 const Eigen::MatrixBase<DerivedEle> & Ele,
574 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
592 template <
typename DerivedEle>
594 const Eigen::MatrixBase<DerivedV> & V,
595 const Eigen::MatrixBase<DerivedEle> & Ele,
600 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
613 template <
typename DerivedEle>
615 const Eigen::MatrixBase<DerivedV> & V,
616 const Eigen::MatrixBase<DerivedEle> & Ele,
620 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
629 template <
typename DerivedEle>
631 const Eigen::MatrixBase<DerivedV> & V,
632 const Eigen::MatrixBase<DerivedEle> & Ele,
644 template <
typename DerivedEle>
646 const Eigen::MatrixBase<DerivedV> & V,
647 const Eigen::MatrixBase<DerivedEle> & Ele,
661 template <
typename DerivedEle>
663 const Eigen::MatrixBase<DerivedV> & V,
664 const Eigen::MatrixBase<DerivedEle> & Ele,
682 typename DerivedOrigin,
688 const Eigen::MatrixBase<DerivedV> & V,
689 const Eigen::MatrixBase<DerivedEle> & Ele,
690 const Eigen::MatrixBase<DerivedOrigin> & origin,
691 const Eigen::MatrixBase<DerivedDir> & dir,
693 Eigen::PlainObjectBase<DerivedI> & I,
694 Eigen::PlainObjectBase<DerivedT> & T,
695 Eigen::PlainObjectBase<DerivedUV> & UV);
698 typename DerivedOrigin,
701 const Eigen::MatrixBase<DerivedV> & V,
702 const Eigen::MatrixBase<DerivedEle> & Ele,
703 const Eigen::MatrixBase<DerivedOrigin> & origin,
704 const Eigen::MatrixBase<DerivedDir> & dir,
719 typename DerivedsqrD,
723 const Eigen::MatrixBase<DerivedV> & V,
724 const Eigen::MatrixBase<DerivedEle> & Ele,
725 const Eigen::MatrixBase<DerivedP> & P,
726 Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
727 Eigen::PlainObjectBase<DerivedI> & I,
728 Eigen::PlainObjectBase<DerivedC> & C)
const;
744 typename Derivedother_V,
745 typename Derivedother_Ele,
746 typename DerivedsqrD,
750 const Eigen::MatrixBase<DerivedV> & V,
751 const Eigen::MatrixBase<DerivedEle> & Ele,
752 const AABB<Derivedother_V,DIM> & other,
753 const Eigen::MatrixBase<Derivedother_V> & other_V,
754 const Eigen::MatrixBase<Derivedother_Ele> & other_Ele,
755 Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
756 Eigen::PlainObjectBase<DerivedI> & I,
757 Eigen::PlainObjectBase<DerivedC> & C)
const;
761 typename Derivedother_V,
762 typename Derivedother_Ele,
763 typename DerivedsqrD,
767 const Eigen::MatrixBase<DerivedV> & V,
768 const Eigen::MatrixBase<DerivedEle> & Ele,
769 const AABB<Derivedother_V,DIM> * other,
770 const Eigen::MatrixBase<Derivedother_V> & other_V,
771 const Eigen::MatrixBase<Derivedother_Ele>& other_Ele,
773 Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
774 Eigen::PlainObjectBase<DerivedI> & I,
775 Eigen::PlainObjectBase<DerivedC> & C)
const;
791 template <
typename DerivedEle>
793 const Eigen::MatrixBase<DerivedV> & V,
794 const Eigen::MatrixBase<DerivedEle> & Ele,
799 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
801 template <
typename DerivedEle>
803 const Eigen::MatrixBase<DerivedV> & V,
804 const Eigen::MatrixBase<DerivedEle> & Ele,
808 Eigen::PlainObjectBase<RowVectorDIMS> & c)
const;
817 template <
typename DerivedEle>
819 const Eigen::MatrixBase<DerivedV> & V,
820 const Eigen::MatrixBase<DerivedEle> & Ele,
835 template <
typename DerivedEle>
837 const Eigen::MatrixBase<DerivedV> & V,
838 const Eigen::MatrixBase<DerivedEle> & Ele,
846 EIGEN_MAKE_ALIGNED_OPERATOR_NEW
851#ifndef IGL_STATIC_LIBRARY
Implementation of semi-general purpose axis-aligned bounding box hierarchy.
Definition AABB.h:31
IGL_INLINE std::vector< int > find(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< Derivedq > &q, const bool first=false) const
Find the indices of elements containing given point: this makes sense when Ele is a co-dimension 0 si...
IGL_INLINE bool intersect_ray(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &origin, const RowVectorDIMS &dir, std::vector< igl::Hit< typename DerivedV::Scalar > > &hits) const
Intersect a ray with the mesh return all hits.
IGL_INLINE std::vector< AABB< DerivedV, DIM > * > gather_leaves()
Eigen::Matrix< Scalar, DIM, 1 > VectorDIMS
Fixed-size (DIM) (Column)Vector type using Scalar.
Definition AABB.h:41
IGL_INLINE Scalar rotate_across(const bool dry_run=false)
Try to swap this node with its cousins if it will decrease total internal surface area.
IGL_INLINE void init(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< Derivedbb_mins > &bb_mins, const Eigen::MatrixBase< Derivedbb_maxs > &bb_maxs, const Eigen::MatrixBase< Derivedelements > &elements, const int i=0)
Build an Axis-Aligned Bounding Box tree for a given mesh and given serialization of a previous AABB t...
IGL_INLINE void squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const AABB< Derivedother_V, DIM > &other, const Eigen::MatrixBase< Derivedother_V > &other_V, const Eigen::MatrixBase< Derivedother_Ele > &other_Ele, Eigen::PlainObjectBase< DerivedsqrD > &sqrD, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedC > &C) const
Compute the squared distance from all query points in P already stored in its own AABB hierarchy to t...
AABB * m_left
Pointer to "left" child node (nullptr if leaf).
Definition AABB.h:46
IGL_INLINE bool is_leaf() const
Return whether at leaf node.
IGL_INLINE bool intersect_ray(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &origin, const RowVectorDIMS &dir, const Scalar min_t, igl::Hit< typename DerivedV::Scalar > &hit) const
Intersect a ray with the mesh return first hit farther than min_t.
IGL_INLINE AABB< DerivedV, DIM > * update_primitive(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Scalar pad=0)
IGL_INLINE void intersect_ray(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< DerivedOrigin > &origin, const Eigen::MatrixBase< DerivedDir > &dir, std::vector< std::vector< igl::Hit< typename DerivedV::Scalar > > > &hits)
IGL_INLINE AABB< DerivedV, DIM > * insert_as_sibling(AABB *other)
Insert other as a sibling to this by creating a new internal node to be their shared parent.
IGL_INLINE bool intersect_ray(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &origin, const RowVectorDIMS &dir, igl::Hit< typename DerivedV::Scalar > &hit) const
Intersect a ray with the mesh return first hit.
int m_primitive
Index of single primitive in this node if full leaf, otherwise -1 for non-leaf.
Definition AABB.h:54
static IGL_INLINE Scalar rotate_up(const bool dry_run, AABB< DerivedV, DIM > *reining, AABB< DerivedV, DIM > *grandparent, AABB< DerivedV, DIM > *parent, AABB< DerivedV, DIM > *challenger, AABB< DerivedV, DIM > *sibling)
"Rotate" (swap) reining with challenger.
IGL_INLINE void squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< DerivedP > &P, Eigen::PlainObjectBase< DerivedsqrD > &sqrD, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedC > &C) const
Compute the squared distance from all query points in P to the closest points on the primitives store...
IGL_INLINE void refit_lineage()
DerivedV::Scalar Scalar
Scalar type of vertex positions (e.g., double).
Definition AABB.h:37
IGL_INLINE void init(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele)
Build an Axis-Aligned Bounding Box tree for a given mesh and given serialization of a previous AABB t...
IGL_INLINE AABB< DerivedV, DIM > * pad(const std::vector< AABB< DerivedV, DIM > * > &leaves, const Scalar pad, const int polish_rotate_passes=0)
Pad leaves by pad in each dimension.
IGL_INLINE int size() const
IGL_INLINE void init(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< DerivedSI > &SI, const Eigen::MatrixBase< DerivedI > &I)
Build an Axis-Aligned Bounding Box tree for a given mesh.
IGL_INLINE bool append_intersecting_leaves(const Eigen::AlignedBox< Scalar, DIM > &box, std::vector< const AABB< DerivedV, DIM > * > &leaves) const
IGL_INLINE Scalar squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
Compute squared distance to a query point.
friend void swap(AABB &first, AABB &second)
Definition AABB.h:87
IGL_INLINE AABB< DerivedV, DIM > * detach()
AABB * m_right
Pointer to "right" child node (nullptr if leaf).
Definition AABB.h:48
IGL_INLINE void intersect_ray(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< DerivedOrigin > &origin, const Eigen::MatrixBase< DerivedDir > &dir, const Scalar min_t, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedT > &T, Eigen::PlainObjectBase< DerivedUV > &UV)
Intersect a rays with the mesh return first hit for each.
IGL_INLINE int subtree_size() const
Number of nodes contained in subtree (is it?).
Eigen::Matrix< Scalar, Eigen::Dynamic, DIM > MatrixXDIMS
Fixed-width (DIM) Matrix type using Scalar.
Definition AABB.h:43
IGL_INLINE void rotate_lineage()
IGL_INLINE bool is_root() const
Return whether at root node.
IGL_INLINE Scalar squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, const Scalar low_sqr_d, const Scalar up_sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
Compute squared distance to a query point if within low_sqr_d and up_sqr_d.
Eigen::Matrix< Scalar, 1, DIM > RowVectorDIMS
Fixed-size (DIM) RowVector type using Scalar.
Definition AABB.h:39
IGL_INLINE Scalar squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, const Scalar up_sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
Compute squared distance to a query point (default low_sqr_d).
IGL_INLINE Scalar rotate(const bool dry_run=false)
Try to swap this node with its close relatives if it will decrease total internal surface area.
IGL_INLINE Scalar rotate_down(const bool dry_run=false)
Try to swap this node with one of its niblings if it will decrease total internal surface area.
IGL_INLINE void serialize(Eigen::PlainObjectBase< Derivedbb_mins > &bb_mins, Eigen::PlainObjectBase< Derivedbb_maxs > &bb_maxs, Eigen::PlainObjectBase< Derivedelements > &elements, const int i=0) const
Serialize this class into 3 arrays (so we can pass it pack to matlab).
IGL_INLINE int height() const
IGL_INLINE Scalar rotate_up(const bool dry_run=false)
Try to swap this node with its pibling if it will decrease total internal surface area.
Eigen::AlignedBox< Scalar, DIM > m_box
Axis-Aligned Bounding Box containing this node.
Definition AABB.h:52
IGL_INLINE void validate() const
Validate the subtree under this node by running a bunch of assertions.
IGL_INLINE AABB< DerivedV, DIM > * update(const Eigen::AlignedBox< Scalar, DIM > &new_box, const Scalar pad=0)
IGL_INLINE DerivedV::Scalar internal_surface_area() const
Compute sum of surface area of all internal (non-root, non-leaf) boxes.
IGL_INLINE AABB< DerivedV, DIM > * insert(AABB *other)
Insert a (probably a leaf) AABB other into this AABB tree.
IGL_INLINE std::vector< AABB< DerivedV, DIM > * > gather_leaves(const int m)
Get a vector of leaves indexed by their m_primitive id (these better be non-negative and tightly pack...
IGL_INLINE AABB< DerivedV, DIM > * root() const
Return the root node of this node's tree by following its parent.
IGL_INLINE void print(const int depth=0) const
print the memory addresses of the tree in a somewhat legible way
AABB * m_parent
Pointer to "parent" node (nullptr if root).
Definition AABB.h:50
#define IGL_INLINE
Definition igl_inline.h:15
Reimplementation of the embree::Hit struct from embree1.0.
Definition Hit.h:18