Prusa Slicer 2.6.0
Loading...
Searching...
No Matches
igl::AABB< DerivedV, DIM > Class Template Reference

#include <src/libigl/igl/AABB.h>

+ Collaboration diagram for igl::AABB< DerivedV, DIM >:

Public Types

typedef DerivedV::Scalar Scalar
 
typedef Eigen::Matrix< Scalar, 1, DIM > RowVectorDIMS
 
typedef Eigen::Matrix< Scalar, DIM, 1 > VectorDIMS
 
typedef Eigen::Matrix< Scalar, Eigen::Dynamic, DIM > MatrixXDIMS
 

Public Member Functions

 AABB ()
 
 AABB (const AABB &other)
 
AABBoperator= (const AABB &other)
 
 AABB (AABB &&other)
 
IGL_INLINE void deinit ()
 
 ~AABB ()
 
template<typename DerivedEle , typename Derivedbb_mins , typename Derivedbb_maxs , typename Derivedelements >
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)
 
template<typename DerivedEle >
IGL_INLINE void init (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele)
 
template<typename DerivedEle , typename DerivedSI , typename DerivedI >
IGL_INLINE void init (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const Eigen::MatrixBase< DerivedSI > &SI, const Eigen::MatrixBase< DerivedI > &I)
 
IGL_INLINE bool is_leaf () const
 
template<typename DerivedEle , typename Derivedq >
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
 
IGL_INLINE int subtree_size () const
 
template<typename Derivedbb_mins , typename Derivedbb_maxs , typename Derivedelements >
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
 
template<typename DerivedEle >
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
 
template<typename DerivedEle >
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
 
template<typename DerivedEle >
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
 
template<typename DerivedEle >
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 > &hits) const
 
template<typename DerivedEle >
IGL_INLINE bool intersect_ray (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &origin, const RowVectorDIMS &dir, igl::Hit &hit) const
 
template<typename DerivedEle >
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 &hit) const
 
template<typename DerivedEle , typename DerivedP , typename DerivedsqrD , typename DerivedI , typename DerivedC >
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
 
template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
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
 
template<typename DerivedEle >
void init (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele)
 
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar squared_distance (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar squared_distance (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, Scalar low_sqr_d, Scalar up_sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar squared_distance (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, Scalar up_sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 
template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar squared_distance_helper (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, const Scalar, Eigen::PlainObjectBase< DerivedsqrD > &sqrD, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedC > &C) const
 
IGL_INLINE float squared_distance (Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &, Eigen::Matrix< float, 1, 2, 1, 1, 2 > const &, int &, Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &) const
 
IGL_INLINE float squared_distance (Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &, Eigen::Matrix< float, 1, 2, 1, 1, 2 > const &, float, float, int &, Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &) const
 
IGL_INLINE void init (Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &)
 
IGL_INLINE double squared_distance (Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &, Eigen::Matrix< double, 1, 2, 1, 1, 2 > const &, int &, Eigen::PlainObjectBase< Eigen::Matrix< double, 1, 2, 1, 1, 2 > > &) const
 
IGL_INLINE double squared_distance (Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &, Eigen::Matrix< double, 1, 2, 1, 1, 2 > const &, double, double, int &, Eigen::PlainObjectBase< Eigen::Matrix< double, 1, 2, 1, 1, 2 > > &) const
 
IGL_INLINE void init (Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const &)
 
IGL_INLINE void init (Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 0, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 0, -1, 3 > > const &)
 
IGL_INLINE float squared_distance (Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 0, -1, 3 > > const &, Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 0, -1, 3 > > const &, Eigen::Matrix< float, 1, 2, 1, 1, 2 > const &, float, float, int &, Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &) const
 

Public Attributes

AABBm_left
 
AABBm_right
 
Eigen::AlignedBox< Scalar, DIM > m_box
 
int m_primitive
 

Private Member Functions

template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE Scalar squared_distance_helper (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, const Scalar up_sqr_d, Eigen::PlainObjectBase< DerivedsqrD > &sqrD, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedC > &C) const
 
template<typename DerivedEle >
IGL_INLINE void leaf_squared_distance (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, const Scalar low_sqr_d, Scalar &sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 
template<typename DerivedEle >
IGL_INLINE void leaf_squared_distance (const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, Scalar &sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 
IGL_INLINE void set_min (const RowVectorDIMS &p, const Scalar sqr_d_candidate, const int i_candidate, const RowVectorDIMS &c_candidate, Scalar &sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
 

Friends

void swap (AABB &first, AABB &second)
 

Detailed Description

template<typename DerivedV, int DIM>
class igl::AABB< DerivedV, DIM >

Member Typedef Documentation

◆ MatrixXDIMS

template<typename DerivedV , int DIM>
typedef Eigen::Matrix<Scalar,Eigen::Dynamic,DIM> igl::AABB< DerivedV, DIM >::MatrixXDIMS

◆ RowVectorDIMS

template<typename DerivedV , int DIM>
typedef Eigen::Matrix<Scalar,1,DIM> igl::AABB< DerivedV, DIM >::RowVectorDIMS

◆ Scalar

template<typename DerivedV , int DIM>
typedef DerivedV::Scalar igl::AABB< DerivedV, DIM >::Scalar

◆ VectorDIMS

template<typename DerivedV , int DIM>
typedef Eigen::Matrix<Scalar,DIM,1> igl::AABB< DerivedV, DIM >::VectorDIMS

Constructor & Destructor Documentation

◆ AABB() [1/3]

template<typename DerivedV , int DIM>
igl::AABB< DerivedV, DIM >::AABB ( )
inline
41 :
42 m_left(NULL), m_right(NULL),
43 m_box(), m_primitive(-1)
44 //m_low_sqr_d(std::numeric_limits<double>::infinity()),
45 //m_depth(0)
46 {}
AABB * m_left
Definition AABB.h:34
int m_primitive
Definition AABB.h:38
AABB * m_right
Definition AABB.h:35
Eigen::AlignedBox< Scalar, DIM > m_box
Definition AABB.h:36

Referenced by igl::AABB< DerivedV, DIM >::operator=().

+ Here is the caller graph for this function:

◆ AABB() [2/3]

template<typename DerivedV , int DIM>
igl::AABB< DerivedV, DIM >::AABB ( const AABB< DerivedV, DIM > &  other)
inline
48 :
49 m_left(other.m_left ? new AABB(*other.m_left) : NULL),
50 m_right(other.m_right ? new AABB(*other.m_right) : NULL),
51 m_box(other.m_box),
53 //m_low_sqr_d(other.m_low_sqr_d),
54 //m_depth(std::max(
55 // m_left ? m_left->m_depth + 1 : 0,
56 // m_right ? m_right->m_depth + 1 : 0))
57 {
58 }
AABB()
Definition AABB.h:41

◆ AABB() [3/3]

template<typename DerivedV , int DIM>
igl::AABB< DerivedV, DIM >::AABB ( AABB< DerivedV, DIM > &&  other)
inline
80 :
81 // initialize via default constructor
82 AABB()
83 {
84 swap(*this,other);
85 }
friend void swap(AABB &first, AABB &second)
Definition AABB.h:60

References igl::AABB< DerivedV, DIM >::swap.

◆ ~AABB()

template<typename DerivedV , int DIM>
igl::AABB< DerivedV, DIM >::~AABB ( )
inline
98 {
99 deinit();
100 }
IGL_INLINE void deinit()
Definition AABB.h:88

References igl::AABB< DerivedV, DIM >::deinit().

+ Here is the call graph for this function:

Member Function Documentation

◆ deinit()

template<typename DerivedV , int DIM>
IGL_INLINE void igl::AABB< DerivedV, DIM >::deinit ( )
inline
89 {
90 m_primitive = -1;
92 delete m_left;
93 m_left = NULL;
94 delete m_right;
95 m_right = NULL;
96 }
An axis aligned box.
Definition AlignedBox.h:31

References igl::AABB< DerivedV, DIM >::m_box, igl::AABB< DerivedV, DIM >::m_left, igl::AABB< DerivedV, DIM >::m_primitive, and igl::AABB< DerivedV, DIM >::m_right.

Referenced by igl::AABB< DerivedV, DIM >::~AABB(), and igl::AABB< DerivedV, DIM >::operator=().

+ Here is the caller graph for this function:

◆ find()

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename Derivedq >
IGL_INLINE std::vector< int > igl::AABB< DerivedV, DIM >::find ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const Eigen::MatrixBase< Derivedq > &  q,
const bool  first = false 
) const
211{
212 using namespace std;
213 using namespace Eigen;
214 assert(q.size() == DIM &&
215 "Query dimension should match aabb dimension");
216 assert(Ele.cols() == V.cols()+1 &&
217 "AABB::find only makes sense for (d+1)-simplices");
218 const Scalar epsilon = igl::EPS<Scalar>();
219 // Check if outside bounding box
220 bool inside = m_box.contains(q.transpose());
221 if(!inside)
222 {
223 return std::vector<int>();
224 }
225 assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
226 if(is_leaf())
227 {
228 // Initialize to some value > -epsilon
229 Scalar a1=0,a2=0,a3=0,a4=0;
230 switch(DIM)
231 {
232 case 3:
233 {
234 // Barycentric coordinates
235 typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
236 const RowVector3S V1 = V.row(Ele(m_primitive,0));
237 const RowVector3S V2 = V.row(Ele(m_primitive,1));
238 const RowVector3S V3 = V.row(Ele(m_primitive,2));
239 const RowVector3S V4 = V.row(Ele(m_primitive,3));
240 a1 = volume_single(V2,V4,V3,(RowVector3S)q);
241 a2 = volume_single(V1,V3,V4,(RowVector3S)q);
242 a3 = volume_single(V1,V4,V2,(RowVector3S)q);
243 a4 = volume_single(V1,V2,V3,(RowVector3S)q);
244 break;
245 }
246 case 2:
247 {
248 // Barycentric coordinates
249 typedef Eigen::Matrix<Scalar,2,1> Vector2S;
250 const Vector2S V1 = V.row(Ele(m_primitive,0));
251 const Vector2S V2 = V.row(Ele(m_primitive,1));
252 const Vector2S V3 = V.row(Ele(m_primitive,2));
253 // Hack for now to keep templates simple. If becomes bottleneck
254 // consider using std::enable_if_t
255 const Vector2S q2 = q.head(2);
256 a1 = doublearea_single(V1,V2,q2);
257 a2 = doublearea_single(V2,V3,q2);
258 a3 = doublearea_single(V3,V1,q2);
259 break;
260 }
261 default:assert(false);
262 }
263 // Normalization is important for correcting sign
264 Scalar sum = a1+a2+a3+a4;
265 a1 /= sum;
266 a2 /= sum;
267 a3 /= sum;
268 a4 /= sum;
269 if(
270 a1>=-epsilon &&
271 a2>=-epsilon &&
272 a3>=-epsilon &&
273 a4>=-epsilon)
274 {
275 return std::vector<int>(1,m_primitive);
276 }else
277 {
278 return std::vector<int>();
279 }
280 }
281 std::vector<int> left = m_left->find(V,Ele,q,first);
282 if(first && !left.empty())
283 {
284 return left;
285 }
286 std::vector<int> right = m_right->find(V,Ele,q,first);
287 if(first)
288 {
289 return right;
290 }
291 left.insert(left.end(),right.begin(),right.end());
292 return left;
293}
EIGEN_DEVICE_FUNC TransposeReturnType transpose()
Definition Transpose.h:172
The matrix class, also used for vectors and row-vectors.
Definition Matrix.h:180
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
Definition AABB.cpp:206
IGL_INLINE bool is_leaf() const
Definition AABB.cpp:199
DerivedV::Scalar Scalar
Definition AABB.h:29
EIGEN_DEVICE_FUNC bool contains(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:182
Definition LDLT.h:16
constexpr double epsilon()
Definition DoubleSlider.hpp:28
bool inside(const Polygons &polygons, const Point &p)
IGL_INLINE VecA::Scalar volume_single(const VecA &a, const VecB &b, const VecC &c, const VecD &d)
Definition volume.cpp:61
IGL_INLINE void sum(const Eigen::SparseMatrix< T > &X, const int dim, Eigen::SparseVector< T > &S)
Definition sum.cpp:12
IGL_INLINE DerivedA::Scalar doublearea_single(const Eigen::MatrixBase< DerivedA > &A, const Eigen::MatrixBase< DerivedB > &B, const Eigen::MatrixBase< DerivedC > &C)
Definition doublearea.cpp:121
STL namespace.

References igl::doublearea_single(), igl::sum(), Eigen::DenseBase< Derived >::transpose(), and igl::volume_single().

Referenced by igl::in_element(), and igl::in_element().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [1/7]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
void igl::AABB< DerivedV, DIM >::init ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele 
)
97{
98 using namespace Eigen;
99 // deinit will be immediately called...
100 return init(V,Ele,MatrixXDIMS(),MatrixXDIMS(),VectorXi(),0);
101}
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)
Definition AABB.cpp:29
Eigen::Matrix< Scalar, Eigen::Dynamic, DIM > MatrixXDIMS
Definition AABB.h:32

◆ init() [2/7]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE void igl::AABB< DerivedV, DIM >::init ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele 
)

◆ init() [3/7]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename Derivedbb_mins , typename Derivedbb_maxs , typename Derivedelements >
IGL_INLINE void igl::AABB< DerivedV, DIM >::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 
)
36{
37 using namespace std;
38 using namespace Eigen;
39 deinit();
40 if(bb_mins.size() > 0)
41 {
42 assert(bb_mins.rows() == bb_maxs.rows() && "Serial tree arrays must match");
43 assert(bb_mins.cols() == V.cols() && "Serial tree array dim must match V");
44 assert(bb_mins.cols() == bb_maxs.cols() && "Serial tree arrays must match");
45 assert(bb_mins.rows() == elements.rows() &&
46 "Serial tree arrays must match");
47 // construct from serialization
48 m_box.extend(bb_mins.row(i).transpose());
49 m_box.extend(bb_maxs.row(i).transpose());
50 m_primitive = elements(i);
51 // Not leaf then recurse
52 if(m_primitive == -1)
53 {
54 m_left = new AABB();
55 m_left->init( V,Ele,bb_mins,bb_maxs,elements,2*i+1);
56 m_right = new AABB();
57 m_right->init( V,Ele,bb_mins,bb_maxs,elements,2*i+2);
58 //m_depth = std::max( m_left->m_depth, m_right->m_depth)+1;
59 }
60 }else
61 {
62 VectorXi allI = colon<int>(0,Ele.rows()-1);
63 MatrixXDIMS BC;
64 if(Ele.cols() == 1)
65 {
66 // points
67 BC = V;
68 }else
69 {
70 // Simplices
71 barycenter(V,Ele,BC);
72 }
73 MatrixXi SI(BC.rows(),BC.cols());
74 {
76 MatrixXi IS;
77 igl::sort(BC,1,true,_,IS);
78 // Need SI(i) to tell which place i would be sorted into
79 const int dim = IS.cols();
80 for(int i = 0;i<IS.rows();i++)
81 {
82 for(int d = 0;d<dim;d++)
83 {
84 SI(IS(i,d),d) = i;
85 }
86 }
87 }
88 init(V,Ele,SI,allI);
89 }
90}
#define _(msgid)
Definition getopt.c:87
EIGEN_DEVICE_FUNC AlignedBox & extend(const MatrixBase< Derived > &p)
Definition AlignedBox.h:200
IGL_INLINE void sort(const Eigen::DenseBase< DerivedX > &X, const int dim, const bool ascending, Eigen::PlainObjectBase< DerivedY > &Y, Eigen::PlainObjectBase< DerivedIX > &IX)
Definition sort.cpp:21
IGL_INLINE void barycenter(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedF > &F, Eigen::PlainObjectBase< DerivedBC > &BC)
Definition barycenter.cpp:14

References _, igl::barycenter(), Eigen::PlainObjectBase< Derived >::cols(), Eigen::PlainObjectBase< Derived >::rows(), igl::sort(), and Eigen::DenseBase< Derived >::transpose().

Referenced by igl::ambient_occlusion(), igl::point_mesh_squared_distance(), igl::shape_diameter_function(), igl::signed_distance(), igl::copyleft::cgal::signed_distance_isosurface(), and igl::swept_volume_signed_distance().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ init() [4/7]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename DerivedSI , typename DerivedI >
IGL_INLINE void igl::AABB< DerivedV, DIM >::init ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const Eigen::MatrixBase< DerivedSI > &  SI,
const Eigen::MatrixBase< DerivedI > &  I 
)
113{
114 using namespace Eigen;
115 using namespace std;
116 deinit();
117 if(V.size() == 0 || Ele.size() == 0 || I.size() == 0)
118 {
119 return;
120 }
121 assert(DIM == V.cols() && "V.cols() should matched declared dimension");
122 //const Scalar inf = numeric_limits<Scalar>::infinity();
124 // Compute bounding box
125 for(int i = 0;i<I.rows();i++)
126 {
127 for(int c = 0;c<Ele.cols();c++)
128 {
129 m_box.extend(V.row(Ele(I(i),c)).transpose());
130 m_box.extend(V.row(Ele(I(i),c)).transpose());
131 }
132 }
133 switch(I.size())
134 {
135 case 0:
136 {
137 assert(false);
138 }
139 case 1:
140 {
141 m_primitive = I(0);
142 break;
143 }
144 default:
145 {
146 // Compute longest direction
147 int max_d = -1;
148 m_box.diagonal().maxCoeff(&max_d);
149 // Can't use median on BC directly because many may have same value,
150 // but can use median on sorted BC indices
151 VectorXi SIdI(I.rows());
152 for(int i = 0;i<I.rows();i++)
153 {
154 SIdI(i) = SI(I(i),max_d);
155 }
156 // Pass by copy to avoid changing input
157 const auto median = [](VectorXi A)->int
158 {
159 size_t n = (A.size()-1)/2;
160 nth_element(A.data(),A.data()+n,A.data()+A.size());
161 return A(n);
162 };
163 const int med = median(SIdI);
164 VectorXi LI((I.rows()+1)/2),RI(I.rows()/2);
165 assert(LI.rows()+RI.rows() == I.rows());
166 // Distribute left and right
167 {
168 int li = 0;
169 int ri = 0;
170 for(int i = 0;i<I.rows();i++)
171 {
172 if(SIdI(i)<=med)
173 {
174 LI(li++) = I(i);
175 }else
176 {
177 RI(ri++) = I(i);
178 }
179 }
180 }
181 //m_depth = 0;
182 if(LI.rows()>0)
183 {
184 m_left = new AABB();
185 m_left->init(V,Ele,SI,LI);
186 //m_depth = std::max(m_depth, m_left->m_depth+1);
187 }
188 if(RI.rows()>0)
189 {
190 m_right = new AABB();
191 m_right->init(V,Ele,SI,RI);
192 //m_depth = std::max(m_depth, m_right->m_depth+1);
193 }
194 }
195 }
196}
EIGEN_DEVICE_FUNC CwiseBinaryOp< internal::scalar_difference_op< Scalar, Scalar >, const VectorType, const VectorType > diagonal() const
Definition AlignedBox.h:134
IGL_INLINE bool median(const Eigen::MatrixBase< DerivedV > &V, mType &m)
Definition median.cpp:15

References igl::median().

+ Here is the call graph for this function:

◆ init() [5/7]

IGL_INLINE void igl::AABB< Eigen::Matrix< double,-1, 3, 1,-1, 3 >, 2 >::init ( Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const  
)
1020{ assert(false);};

◆ init() [6/7]

IGL_INLINE void igl::AABB< Eigen::Matrix< float,-1, 3, 0,-1, 3 >, 2 >::init ( Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 0, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 0, -1, 3 > > const  
)
1021{assert(false);};

◆ init() [7/7]

IGL_INLINE void igl::AABB< Eigen::Matrix< float,-1, 3, 1,-1, 3 >, 2 >::init ( Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const  
)
1017{ assert(false);};

◆ intersect_ray() [1/3]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE bool igl::AABB< DerivedV, DIM >::intersect_ray ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS origin,
const RowVectorDIMS dir,
const Scalar  min_t,
igl::Hit hit 
) const
947{
949 //std::vector<igl::Hit> hits;
950 //intersect_ray(V,Ele,origin,dir,hits);
951 //if(hits.size() > 0)
952 //{
953 // hit = hits.front();
954 // return true;
955 //}else
956 //{
957 // return false;
958 //}
959 Scalar min_t = _min_t;
960 const Scalar t0 = 0;
961 {
962 Scalar _1,_2;
963 if(!ray_box_intersect(origin,dir,m_box,t0,min_t,_1,_2))
964 {
965 return false;
966 }
967 }
968 if(this->is_leaf())
969 {
970 // Actually process elements
971 assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
972 // Cheesecake way of hitting element
973 bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hit);
974 hit.id = m_primitive;
975 return ret;
976 }
977
978 // Doesn't seem like smartly choosing left before/after right makes a
979 // differnce
980 igl::Hit left_hit;
981 igl::Hit right_hit;
982 bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,min_t,left_hit);
983 if(left_ret && left_hit.t<min_t)
984 {
985 // It's scary that this line doesn't seem to matter....
986 min_t = left_hit.t;
987 hit = left_hit;
988 left_ret = true;
989 }else
990 {
991 left_ret = false;
992 }
993 bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,min_t,right_hit);
994 if(right_ret && right_hit.t<min_t)
995 {
996 min_t = right_hit.t;
997 hit = right_hit;
998 right_ret = true;
999 }else
1000 {
1001 right_ret = false;
1002 }
1003 return left_ret || right_ret;
1004}
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 > &hits) const
Definition AABB.cpp:838
float t
Definition Hit.h:22
IGL_INLINE bool ray_box_intersect(const Eigen::MatrixBase< Derivedsource > &source, const Eigen::MatrixBase< Deriveddir > &dir, const Eigen::AlignedBox< Scalar, 3 > &box, const Scalar &t0, const Scalar &t1, Scalar &tmin, Scalar &tmax)
Definition ray_box_intersect.cpp:15
int id
Definition Hit.h:19
IGL_INLINE bool ray_mesh_intersect(const Eigen::MatrixBase< Derivedsource > &source, const Eigen::MatrixBase< Deriveddir > &dir, const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedF > &F, std::vector< igl::Hit > &hits)
Definition ray_mesh_intersect.cpp:20
Definition Hit.h:18

References igl::Hit::id, igl::ray_box_intersect(), igl::ray_mesh_intersect(), and igl::Hit::t.

+ Here is the call graph for this function:

◆ intersect_ray() [2/3]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE bool igl::AABB< DerivedV, DIM >::intersect_ray ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS origin,
const RowVectorDIMS dir,
igl::Hit hit 
) const
887{
888 // FIXME: Needs a proper path
889#if /*false*/ 0
890 // BFS
891 std::queue<const AABB *> Q;
892 // Or DFS
893 //std::stack<const AABB *> Q;
894 Q.push(this);
895 bool any_hit = false;
896 hit.t = std::numeric_limits<Scalar>::infinity();
897 while(!Q.empty())
898 {
899 const AABB * tree = Q.front();
900 //const AABB * tree = Q.top();
901 Q.pop();
902 {
903 Scalar _1,_2;
905 origin,dir,tree->m_box,Scalar(0),Scalar(hit.t),_1,_2))
906 {
907 continue;
908 }
909 }
910 if(tree->is_leaf())
911 {
912 // Actually process elements
913 assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
914 igl::Hit leaf_hit;
915 if(
916 ray_mesh_intersect(origin,dir,V,Ele.row(tree->m_primitive),leaf_hit)&&
917 leaf_hit.t < hit.t)
918 {
919 // correct the id
920 leaf_hit.id = tree->m_primitive;
921 hit = leaf_hit;
922 }
923 continue;
924 }
925 // Add children to queue
926 Q.push(tree->m_left);
927 Q.push(tree->m_right);
928 }
929 return any_hit;
930#else
931 // DFS
932 return intersect_ray(
933 V,Ele,origin,dir,std::numeric_limits<Scalar>::infinity(),hit);
934#endif
935}

References igl::Hit::id, igl::AABB< DerivedV, DIM >::is_leaf(), igl::AABB< DerivedV, DIM >::m_box, igl::AABB< DerivedV, DIM >::m_left, igl::AABB< DerivedV, DIM >::m_primitive, igl::AABB< DerivedV, DIM >::m_right, igl::ray_box_intersect(), igl::ray_mesh_intersect(), and igl::Hit::t.

+ Here is the call graph for this function:

◆ intersect_ray() [3/3]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE bool igl::AABB< DerivedV, DIM >::intersect_ray ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS origin,
const RowVectorDIMS dir,
std::vector< igl::Hit > &  hits 
) const
844{
845 hits.clear();
846 const Scalar t0 = 0;
847 const Scalar t1 = std::numeric_limits<Scalar>::infinity();
848 {
849 Scalar _1,_2;
850 if(!ray_box_intersect(origin,dir,m_box,t0,t1,_1,_2))
851 {
852 return false;
853 }
854 }
855 if(this->is_leaf())
856 {
857 // Actually process elements
858 assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
859 // Cheesecake way of hitting element
860 bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hits);
861 // Since we only gave ray_mesh_intersect a single face, it will have set
862 // any hits to id=0. Set these to this primitive's id
863 for(auto & hit : hits)
864 {
865 hit.id = m_primitive;
866 }
867 return ret;
868 }
869 std::vector<igl::Hit> left_hits;
870 std::vector<igl::Hit> right_hits;
871 const bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,left_hits);
872 const bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,right_hits);
873 hits.insert(hits.end(),left_hits.begin(),left_hits.end());
874 hits.insert(hits.end(),right_hits.begin(),right_hits.end());
875 return left_ret || right_ret;
876}

References igl::ray_box_intersect(), and igl::ray_mesh_intersect().

Referenced by igl::ambient_occlusion(), and igl::shape_diameter_function().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ is_leaf()

template<typename DerivedV , int DIM>
IGL_INLINE bool igl::AABB< DerivedV, DIM >::is_leaf
200{
201 return m_primitive != -1;
202}

Referenced by igl::AABB< DerivedV, DIM >::intersect_ray(), and igl::AABB< DerivedV, DIM >::squared_distance_helper().

+ Here is the caller graph for this function:

◆ leaf_squared_distance() [1/2]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE void igl::AABB< DerivedV, DIM >::leaf_squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
const Scalar  low_sqr_d,
Scalar sqr_d,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
private
776{
777 using namespace Eigen;
778 using namespace std;
779 if(low_sqr_d > sqr_d)
780 {
781 sqr_d = low_sqr_d;
782 return;
783 }
784 RowVectorDIMS c_candidate;
785 Scalar sqr_d_candidate;
786 igl::point_simplex_squared_distance<DIM>(
787 p,V,Ele,m_primitive,sqr_d_candidate,c_candidate);
788 set_min(p,sqr_d_candidate,m_primitive,c_candidate,sqr_d,i,c);
789}
IGL_INLINE void set_min(const RowVectorDIMS &p, const Scalar sqr_d_candidate, const int i_candidate, const RowVectorDIMS &c_candidate, Scalar &sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
Definition AABB.cpp:806
Eigen::Matrix< Scalar, 1, DIM > RowVectorDIMS
Definition AABB.h:30

◆ leaf_squared_distance() [2/2]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE void igl::AABB< DerivedV, DIM >::leaf_squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
Scalar sqr_d,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
private
800{
801 return leaf_squared_distance(V,Ele,p,0,sqr_d,i,c);
802}
IGL_INLINE void leaf_squared_distance(const Eigen::MatrixBase< DerivedV > &V, const Eigen::MatrixBase< DerivedEle > &Ele, const RowVectorDIMS &p, const Scalar low_sqr_d, Scalar &sqr_d, int &i, Eigen::PlainObjectBase< RowVectorDIMS > &c) const
Definition AABB.cpp:768

◆ operator=()

template<typename DerivedV , int DIM>
AABB & igl::AABB< DerivedV, DIM >::operator= ( const AABB< DerivedV, DIM > &  other)
inline
72 {
73 this->deinit();
74 m_left = other.m_left ? new AABB(*other.m_left) : NULL;
75 m_right = other.m_right ? new AABB(*other.m_right) : NULL;
76 m_box = other.m_box;
77 m_primitive = other.m_primitive;
78 return *this;
79 }

References igl::AABB< DerivedV, DIM >::AABB(), igl::AABB< DerivedV, DIM >::deinit(), igl::AABB< DerivedV, DIM >::m_box, igl::AABB< DerivedV, DIM >::m_left, igl::AABB< DerivedV, DIM >::m_primitive, and igl::AABB< DerivedV, DIM >::m_right.

+ Here is the call graph for this function:

◆ serialize()

template<typename DerivedV , int DIM>
template<typename Derivedbb_mins , typename Derivedbb_maxs , typename Derivedelements >
IGL_INLINE void igl::AABB< DerivedV, DIM >::serialize ( Eigen::PlainObjectBase< Derivedbb_mins > &  bb_mins,
Eigen::PlainObjectBase< Derivedbb_maxs > &  bb_maxs,
Eigen::PlainObjectBase< Derivedelements > &  elements,
const int  i = 0 
) const
321{
322 using namespace std;
323 using namespace Eigen;
324 // Calling for root then resize output
325 if(i==0)
326 {
327 const int m = subtree_size();
328 //cout<<"m: "<<m<<endl;
329 bb_mins.resize(m,DIM);
330 bb_maxs.resize(m,DIM);
331 elements.resize(m,1);
332 }
333 //cout<<i<<" ";
334 bb_mins.row(i) = m_box.min();
335 bb_maxs.row(i) = m_box.max();
336 elements(i) = m_primitive;
337 if(m_left != NULL)
338 {
339 m_left->serialize(bb_mins,bb_maxs,elements,2*i+1);
340 }
341 if(m_right != NULL)
342 {
343 m_right->serialize(bb_mins,bb_maxs,elements,2*i+2);
344 }
345}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resize(Index rows, Index cols)
Definition PlainObjectBase.h:279
IGL_INLINE int subtree_size() const
Definition AABB.cpp:296
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
Definition AABB.cpp:316
EIGEN_DEVICE_FUNC const VectorType &() min() const
Definition AlignedBox.h:106
EIGEN_DEVICE_FUNC const VectorType &() max() const
Definition AlignedBox.h:110

References Eigen::PlainObjectBase< Derived >::resize().

+ Here is the call graph for this function:

◆ set_min()

template<typename DerivedV , int DIM>
IGL_INLINE void igl::AABB< DerivedV, DIM >::set_min ( const RowVectorDIMS p,
const Scalar  sqr_d_candidate,
const int  i_candidate,
const RowVectorDIMS c_candidate,
Scalar sqr_d,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
private
818{
819#ifndef NDEBUG
820 //std::cout<<matlab_format(c_candidate,"c_candidate")<<std::endl;
822 // const Scalar pc_norm = (p-c_candidate).squaredNorm();
823 // const Scalar diff = fabs(sqr_d_candidate - pc_norm);
824 // assert(diff<=1e-10 && "distance should match norm of difference");
825#endif
826 if(sqr_d_candidate < sqr_d)
827 {
828 i = i_candidate;
829 c = c_candidate;
830 sqr_d = sqr_d_candidate;
831 }
832}

◆ squared_distance() [1/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE void igl::AABB< DerivedV, DIM >::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
515{
516 assert(other_Ele.cols() == 1 &&
517 "Only implemented for other as list of points");
518 assert(other_V.cols() == V.cols() && "other must match this dimension");
519 sqrD.setConstant(other_Ele.rows(),1,std::numeric_limits<double>::infinity());
520 I.resize(other_Ele.rows(),1);
521 C.resize(other_Ele.rows(),other_V.cols());
522 // All points in other_V currently think they need to check against root of
523 // this. The point of using another AABB is to quickly prune chunks of
524 // other_V so that most points just check some subtree of this.
525
526 // This holds a conservative estimate of max(sqr_D) where sqr_D is the
527 // current best minimum squared distance for all points in this subtree
528 double up_sqr_d = std::numeric_limits<double>::infinity();
530 V,Ele,&other,other_V,other_Ele,0,up_sqr_d,sqrD,I,C);
531}
EIGEN_DEVICE_FUNC Derived & setConstant(Index size, const Scalar &val)
Definition CwiseNullaryOp.h:341
IGL_INLINE Scalar squared_distance_helper(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, const Scalar up_sqr_d, Eigen::PlainObjectBase< DerivedsqrD > &sqrD, Eigen::PlainObjectBase< DerivedI > &I, Eigen::PlainObjectBase< DerivedC > &C) const

References Eigen::PlainObjectBase< Derived >::resize(), and Eigen::PlainObjectBase< Derived >::setConstant().

+ Here is the call graph for this function:

◆ squared_distance() [2/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename DerivedP , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE void igl::AABB< DerivedV, DIM >::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
479{
480 assert(P.cols() == V.cols() && "cols in P should match dim of cols in V");
481 sqrD.resize(P.rows(),1);
482 I.resize(P.rows(),1);
483 C.resizeLike(P);
484 // O( #P * log #Ele ), where log #Ele is really the depth of this AABB
485 // hierarchy
486 //for(int p = 0;p<P.rows();p++)
487 igl::parallel_for(P.rows(),[&](int p)
488 {
489 RowVectorDIMS Pp = P.row(p), c;
490 int Ip;
491 sqrD(p) = squared_distance(V,Ele,Pp,Ip,c);
492 I(p) = Ip;
493 C.row(p).head(DIM) = c;
494 },
495 10000);
496}
EIGEN_DEVICE_FUNC EIGEN_STRONG_INLINE void resizeLike(const EigenBase< OtherDerived > &_other)
Definition PlainObjectBase.h:362
bool parallel_for(const Index loop_size, const FunctionType &func, const size_t min_parallel=0)
Definition parallel_for.h:99

References igl::parallel_for(), Eigen::PlainObjectBase< Derived >::resize(), and Eigen::PlainObjectBase< Derived >::resizeLike().

+ Here is the call graph for this function:

◆ squared_distance() [3/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE Scalar igl::AABB< DerivedV, DIM >::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

◆ squared_distance() [4/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE Scalar igl::AABB< DerivedV, DIM >::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

◆ squared_distance() [5/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar igl::AABB< DerivedV, DIM >::squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
356{
357 return squared_distance(V,Ele,p,std::numeric_limits<Scalar>::infinity(),i,c);
358}
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

◆ squared_distance() [6/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE Scalar igl::AABB< DerivedV, DIM >::squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const

◆ squared_distance() [7/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar igl::AABB< DerivedV, DIM >::squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
Scalar  low_sqr_d,
Scalar  up_sqr_d,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
372{
373 using namespace Eigen;
374 using namespace std;
375 //assert(low_sqr_d <= up_sqr_d);
376 if(low_sqr_d > up_sqr_d)
377 {
378 return low_sqr_d;
379 }
380 Scalar sqr_d = up_sqr_d;
381 //assert(DIM == 3 && "Code has only been tested for DIM == 3");
382 assert((Ele.cols() == 3 || Ele.cols() == 2 || Ele.cols() == 1)
383 && "Code has only been tested for simplex sizes 3,2,1");
384
385 assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
386 if(is_leaf())
387 {
388 leaf_squared_distance(V,Ele,p,low_sqr_d,sqr_d,i,c);
389 }else
390 {
391 bool looked_left = false;
392 bool looked_right = false;
393 const auto & look_left = [&]()
394 {
395 int i_left;
396 RowVectorDIMS c_left = c;
397 Scalar sqr_d_left =
398 m_left->squared_distance(V,Ele,p,low_sqr_d,sqr_d,i_left,c_left);
399 this->set_min(p,sqr_d_left,i_left,c_left,sqr_d,i,c);
400 looked_left = true;
401 };
402 const auto & look_right = [&]()
403 {
404 int i_right;
405 RowVectorDIMS c_right = c;
406 Scalar sqr_d_right =
407 m_right->squared_distance(V,Ele,p,low_sqr_d,sqr_d,i_right,c_right);
408 this->set_min(p,sqr_d_right,i_right,c_right,sqr_d,i,c);
409 looked_right = true;
410 };
411
412 // must look left or right if in box
413 if(m_left->m_box.contains(p.transpose()))
414 {
415 look_left();
416 }
417 if(m_right->m_box.contains(p.transpose()))
418 {
419 look_right();
420 }
421 // if haven't looked left and could be less than current min, then look
422 Scalar left_up_sqr_d =
423 m_left->m_box.squaredExteriorDistance(p.transpose());
424 Scalar right_up_sqr_d =
425 m_right->m_box.squaredExteriorDistance(p.transpose());
426 if(left_up_sqr_d < right_up_sqr_d)
427 {
428 if(!looked_left && left_up_sqr_d<sqr_d)
429 {
430 look_left();
431 }
432 if( !looked_right && right_up_sqr_d<sqr_d)
433 {
434 look_right();
435 }
436 }else
437 {
438 if( !looked_right && right_up_sqr_d<sqr_d)
439 {
440 look_right();
441 }
442 if(!looked_left && left_up_sqr_d<sqr_d)
443 {
444 look_left();
445 }
446 }
447 }
448 return sqr_d;
449}
EIGEN_DEVICE_FUNC Scalar squaredExteriorDistance(const MatrixBase< Derived > &p) const
Definition AlignedBox.h:314

◆ squared_distance() [8/13]

template<typename DerivedV , int DIM>
template<typename DerivedEle >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar igl::AABB< DerivedV, DIM >::squared_distance ( const Eigen::MatrixBase< DerivedV > &  V,
const Eigen::MatrixBase< DerivedEle > &  Ele,
const RowVectorDIMS p,
Scalar  up_sqr_d,
int &  i,
Eigen::PlainObjectBase< RowVectorDIMS > &  c 
) const
461{
462 return squared_distance(V,Ele,p,0.0,up_sqr_d,i,c);
463}

◆ squared_distance() [9/13]

IGL_INLINE double igl::AABB< Eigen::Matrix< double,-1, 3, 1,-1, 3 >, 2 >::squared_distance ( Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const ,
Eigen::Matrix< double, 1, 2, 1, 1, 2 > const ,
double  ,
double  ,
int &  ,
Eigen::PlainObjectBase< Eigen::Matrix< double, 1, 2, 1, 1, 2 > > &   
) const
1019{ assert(false);return -1;};

◆ squared_distance() [10/13]

IGL_INLINE double igl::AABB< Eigen::Matrix< double,-1, 3, 1,-1, 3 >, 2 >::squared_distance ( Eigen::MatrixBase< Eigen::Matrix< double, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const ,
Eigen::Matrix< double, 1, 2, 1, 1, 2 > const ,
int &  ,
Eigen::PlainObjectBase< Eigen::Matrix< double, 1, 2, 1, 1, 2 > > &   
) const
1018{ assert(false);return -1;};

◆ squared_distance() [11/13]

IGL_INLINE float igl::AABB< Eigen::Matrix< float,-1, 3, 0,-1, 3 >, 2 >::squared_distance ( Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 0, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 0, -1, 3 > > const ,
Eigen::Matrix< float, 1, 2, 1, 1, 2 > const ,
float  ,
float  ,
int &  ,
Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &   
) const
1022{ assert(false);return -1;};

◆ squared_distance() [12/13]

IGL_INLINE float igl::AABB< Eigen::Matrix< float,-1, 3, 1,-1, 3 >, 2 >::squared_distance ( Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const ,
Eigen::Matrix< float, 1, 2, 1, 1, 2 > const ,
float  ,
float  ,
int &  ,
Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &   
) const
1016{ assert(false);return -1;};

◆ squared_distance() [13/13]

IGL_INLINE float igl::AABB< Eigen::Matrix< float,-1, 3, 1,-1, 3 >, 2 >::squared_distance ( Eigen::MatrixBase< Eigen::Matrix< float, -1, 3, 1, -1, 3 > > const ,
Eigen::MatrixBase< Eigen::Matrix< int, -1, 3, 1, -1, 3 > > const ,
Eigen::Matrix< float, 1, 2, 1, 1, 2 > const ,
int &  ,
Eigen::PlainObjectBase< Eigen::Matrix< float, 1, 2, 1, 1, 2 > > &   
) const
1015{ assert(false);return -1;};

◆ squared_distance_helper() [1/2]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE Scalar igl::AABB< DerivedV, DIM >::squared_distance_helper ( 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,
const Scalar  up_sqr_d,
Eigen::PlainObjectBase< DerivedsqrD > &  sqrD,
Eigen::PlainObjectBase< DerivedI > &  I,
Eigen::PlainObjectBase< DerivedC > &  C 
) const
private

◆ squared_distance_helper() [2/2]

template<typename DerivedV , int DIM>
template<typename DerivedEle , typename Derivedother_V , typename Derivedother_Ele , typename DerivedsqrD , typename DerivedI , typename DerivedC >
IGL_INLINE igl::AABB< DerivedV, DIM >::Scalar igl::AABB< DerivedV, DIM >::squared_distance_helper ( 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,
const Scalar  ,
Eigen::PlainObjectBase< DerivedsqrD > &  sqrD,
Eigen::PlainObjectBase< DerivedI > &  I,
Eigen::PlainObjectBase< DerivedC > &  C 
) const
552{
553 using namespace std;
554 using namespace Eigen;
555
556 // This implementation is a bit disappointing. There's no major speed up. Any
557 // performance gains seem to come from accidental cache coherency and
558 // diminish for larger "other" (the opposite of what was intended).
559
560 // Base case
561 if(other->is_leaf() && this->is_leaf())
562 {
563 Scalar sqr_d = sqrD(other->m_primitive);
564 int i = I(other->m_primitive);
565 RowVectorDIMS c = C.row( other->m_primitive);
566 RowVectorDIMS p = other_V.row(other->m_primitive);
567 leaf_squared_distance(V,Ele,p,sqr_d,i,c);
568 sqrD( other->m_primitive) = sqr_d;
569 I( other->m_primitive) = i;
570 C.row(other->m_primitive) = c;
571 //cout<<"leaf: "<<sqr_d<<endl;
572 //other->m_low_sqr_d = sqr_d;
573 return sqr_d;
574 }
575
576 if(other->is_leaf())
577 {
578 Scalar sqr_d = sqrD(other->m_primitive);
579 int i = I(other->m_primitive);
580 RowVectorDIMS c = C.row( other->m_primitive);
581 RowVectorDIMS p = other_V.row(other->m_primitive);
582 sqr_d = squared_distance(V,Ele,p,sqr_d,i,c);
583 sqrD( other->m_primitive) = sqr_d;
584 I( other->m_primitive) = i;
585 C.row(other->m_primitive) = c;
586 //other->m_low_sqr_d = sqr_d;
587 return sqr_d;
588 }
589
592 //const auto & min_squared_distance = [&](
593 // const AABB<DerivedV,DIM> * A,
594 // const AABB<Derivedother_V,DIM> * B)->Scalar
595 //{
596 // return A->m_box.squaredExteriorDistance(B->m_box);
597 //};
598
599 if(this->is_leaf())
600 {
601 //if(min_squared_distance(this,other) < other->m_low_sqr_d)
602 if(true)
603 {
605 V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
607 V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
608 }else
609 {
610 // This is never reached...
611 }
613 //other->m_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_sqr_d);
614 return 0;
615 }
616
617 // FORCE DOWN TO OTHER LEAF EVAL
618 //if(min_squared_distance(this,other) < other->m_low_sqr_d)
619 if(true)
620 {
621 if(true)
622 {
624 V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
626 V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
627 }else // this direction never seems to be faster
628 {
630 V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
632 V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
633 }
634 }else
635 {
636 // this is never reached ... :-(
637 }
639 //other->m_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_sqr_d);
640
641 return 0;
642#if 0 // False
643
644 // _Very_ conservative approximation of maximum squared distance between
645 // primitives inside this and other's bounding boxes
646 const auto & max_squared_distance = [](
647 const AABB<DerivedV,DIM> * A,
648 const AABB<Derivedother_V,DIM> * B)->Scalar
649 {
650 AlignedBox<Scalar,DIM> combo = A->m_box;
651 combo.extend(B->m_box);
652 return combo.diagonal().squaredNorm();
653 };
654
656 //if(other->is_leaf())
657 //{
658 // double sqr_d = sqrD(other->m_primitive);
659 // int i = I(other->m_primitive);
660 // RowVectorDIMS c = C.row(m_primitive);
661 // RowVectorDIMS p = other_V.row(m_primitive);
662 // leaf_squared_distance(V,Ele,p,sqr_d,i,c);
663 // sqrD(other->m_primitive) = sqr_d;
664 // I(other->m_primitive) = i;
665 // C.row(m_primitive) = c;
666 // return;
667 //}
668 std::vector<const AABB<DerivedV,DIM> * > this_list;
669 if(this->is_leaf())
670 {
671 this_list.push_back(this);
672 }else
673 {
674 assert(this->m_left);
675 this_list.push_back(this->m_left);
676 assert(this->m_right);
677 this_list.push_back(this->m_right);
678 }
679 std::vector<AABB<Derivedother_V,DIM> *> other_list;
680 if(other->is_leaf())
681 {
682 other_list.push_back(other);
683 }else
684 {
685 assert(other->m_left);
686 other_list.push_back(other->m_left);
687 assert(other->m_right);
688 other_list.push_back(other->m_right);
689 }
690
691 //const std::function<Scalar(
692 // const AABB<Derivedother_V,DIM> * other)
693 // > low_sqr_d = [&sqrD,&low_sqr_d](const AABB<Derivedother_V,DIM> * other)->Scalar
694 // {
695 // if(other->is_leaf())
696 // {
697 // return sqrD(other->m_primitive);
698 // }else
699 // {
700 // return std::max(low_sqr_d(other->m_left),low_sqr_d(other->m_right));
701 // }
702 // };
703
706 //Eigen::Matrix<Scalar,Eigen::Dynamic,1> other_low_sqr_d =
707 // Eigen::Matrix<Scalar,Eigen::Dynamic,1>::Constant(other_list.size(),1,up_sqr_d);
708 for(size_t child = 0;child<other_list.size();child++)
709 {
710 auto other_tree = other_list[child];
711
712 Eigen::Matrix<Scalar,Eigen::Dynamic,1> this_low_sqr_d(this_list.size(),1);
713 for(size_t t = 0;t<this_list.size();t++)
714 {
715 const auto this_tree = this_list[t];
716 this_low_sqr_d(t) = max_squared_distance(this_tree,other_tree);
717 }
718 if(this_list.size() ==2 &&
719 ( this_low_sqr_d(0) > this_low_sqr_d(1))
720 )
721 {
722 std::swap(this_list[0],this_list[1]);
723 //std::swap(this_low_sqr_d(0),this_low_sqr_d(1));
724 }
725 const Scalar sqr_d = this_low_sqr_d.minCoeff();
726
727
728 for(size_t t = 0;t<this_list.size();t++)
729 {
730 const auto this_tree = this_list[t];
731
732 //const auto mm = low_sqr_d(other_tree);
733 //const Scalar mc = other_low_sqr_d(child);
734 //assert(mc == mm);
735 // Only look left/right in this_list if can possible decrease somebody's
736 // distance in this_tree.
737 const Scalar min_this_other = min_squared_distance(this_tree,other_tree);
738 if(
739 min_this_other < sqr_d &&
740 min_this_other < other_tree->m_low_sqr_d)
741 {
742 //cout<<"before: "<<other_low_sqr_d(child)<<endl;
743 //other_low_sqr_d(child) = std::min(
744 // other_low_sqr_d(child),
745 // this_tree->squared_distance_helper(
746 // V,Ele,other_tree,other_V,other_Ele,other_low_sqr_d(child),sqrD,I,C));
747 //cout<<"after: "<<other_low_sqr_d(child)<<endl;
748 this_tree->squared_distance_helper(
749 V,Ele,other_tree,other_V,other_Ele,0,sqrD,I,C);
750 }
751 }
752 }
753 //const Scalar ret = other_low_sqr_d.maxCoeff();
754 //const auto mm = low_sqr_d(other);
755 //assert(mm == ret);
756 //cout<<"non-leaf: "<<ret<<endl;
757 //return ret;
758 if(!other->is_leaf())
759 {
760 other->m_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_sqr_d);
761 }
762 return 0;
763#endif
764}

References Eigen::AlignedBox< _Scalar, _AmbientDim >::diagonal(), Eigen::AlignedBox< _Scalar, _AmbientDim >::extend(), igl::AABB< DerivedV, DIM >::is_leaf(), igl::AABB< DerivedV, DIM >::m_box, igl::AABB< DerivedV, DIM >::m_left, igl::AABB< DerivedV, DIM >::m_primitive, and igl::AABB< DerivedV, DIM >::m_right.

+ Here is the call graph for this function:

◆ subtree_size()

template<typename DerivedV , int DIM>
IGL_INLINE int igl::AABB< DerivedV, DIM >::subtree_size
297{
298 // 1 for self
299 int n = 1;
300 int n_left = 0,n_right = 0;
301 if(m_left != NULL)
302 {
303 n_left = m_left->subtree_size();
304 }
305 if(m_right != NULL)
306 {
307 n_right = m_right->subtree_size();
308 }
309 n += 2*std::max(n_left,n_right);
310 return n;
311}

Friends And Related Symbol Documentation

◆ swap

template<typename DerivedV , int DIM>
void swap ( AABB< DerivedV, DIM > &  first,
AABB< DerivedV, DIM > &  second 
)
friend
61 {
62 // Enable ADL
63 using std::swap;
64 swap(first.m_left,second.m_left);
65 swap(first.m_right,second.m_right);
66 swap(first.m_box,second.m_box);
67 swap(first.m_primitive,second.m_primitive);
68 //swap(first.m_low_sqr_d,second.m_low_sqr_d);
69 //swap(first.m_depth,second.m_depth);
70 }

Referenced by igl::AABB< DerivedV, DIM >::AABB().

Member Data Documentation

◆ m_box

◆ m_left

◆ m_primitive

◆ m_right


The documentation for this class was generated from the following files: