AABB.cpp 34 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "AABB.h"
  9. #include "EPS.h"
  10. #include "barycenter.h"
  11. #include "barycentric_coordinates.h"
  12. #include "colon.h"
  13. #include "doublearea.h"
  14. #include "matlab_format.h"
  15. #include "point_simplex_squared_distance.h"
  16. #include "project_to_line_segment.h"
  17. #include "sort.h"
  18. #include "volume.h"
  19. #include "ray_box_intersect.h"
  20. #include "ray_mesh_intersect.h"
  21. #include <iostream>
  22. #include <iomanip>
  23. #include <limits>
  24. #include <list>
  25. #include <queue>
  26. #include <stack>
  27. template <typename DerivedV, int DIM>
  28. template <typename Derivedbb_mins, typename Derivedbb_maxs>
  29. IGL_INLINE void igl::AABB<DerivedV,DIM>::init(
  30. const Eigen::PlainObjectBase<DerivedV> & V,
  31. const Eigen::MatrixXi & Ele,
  32. const Eigen::PlainObjectBase<Derivedbb_mins> & bb_mins,
  33. const Eigen::PlainObjectBase<Derivedbb_maxs> & bb_maxs,
  34. const Eigen::VectorXi & elements,
  35. const int i)
  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. {
  75. MatrixXDIMS _;
  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. }
  91. template <typename DerivedV, int DIM>
  92. void igl::AABB<DerivedV,DIM>::init(
  93. const Eigen::PlainObjectBase<DerivedV> & V,
  94. const Eigen::MatrixXi & Ele)
  95. {
  96. using namespace Eigen;
  97. // deinit will be immediately called...
  98. return init(V,Ele,MatrixXDIMS(),MatrixXDIMS(),VectorXi(),0);
  99. }
  100. template <typename DerivedV, int DIM>
  101. IGL_INLINE void igl::AABB<DerivedV,DIM>::init(
  102. const Eigen::PlainObjectBase<DerivedV> & V,
  103. const Eigen::MatrixXi & Ele,
  104. const Eigen::MatrixXi & SI,
  105. const Eigen::VectorXi & I)
  106. {
  107. using namespace Eigen;
  108. using namespace std;
  109. deinit();
  110. if(V.size() == 0 || Ele.size() == 0 || I.size() == 0)
  111. {
  112. return;
  113. }
  114. assert(DIM == V.cols() && "V.cols() should matched declared dimension");
  115. //const Scalar inf = numeric_limits<Scalar>::infinity();
  116. m_box = AlignedBox<Scalar,DIM>();
  117. // Compute bounding box
  118. for(int i = 0;i<I.rows();i++)
  119. {
  120. for(int c = 0;c<Ele.cols();c++)
  121. {
  122. m_box.extend(V.row(Ele(I(i),c)).transpose());
  123. m_box.extend(V.row(Ele(I(i),c)).transpose());
  124. }
  125. }
  126. switch(I.size())
  127. {
  128. case 0:
  129. {
  130. assert(false);
  131. }
  132. case 1:
  133. {
  134. m_primitive = I(0);
  135. break;
  136. }
  137. default:
  138. {
  139. // Compute longest direction
  140. int max_d = -1;
  141. m_box.diagonal().maxCoeff(&max_d);
  142. // Can't use median on BC directly because many may have same value,
  143. // but can use median on sorted BC indices
  144. VectorXi SIdI(I.rows());
  145. for(int i = 0;i<I.rows();i++)
  146. {
  147. SIdI(i) = SI(I(i),max_d);
  148. }
  149. // Since later I use <= I think I don't need to worry about odd/even
  150. // Pass by copy to avoid changing input
  151. const auto median = [](VectorXi A)->Scalar
  152. {
  153. size_t n = A.size()/2;
  154. nth_element(A.data(),A.data()+n,A.data()+A.size());
  155. if(A.rows() % 2 == 1)
  156. {
  157. return A(n);
  158. }else
  159. {
  160. nth_element(A.data(),A.data()+n-1,A.data()+A.size());
  161. return 0.5*(A(n)+A(n-1));
  162. }
  163. };
  164. const Scalar med = median(SIdI);
  165. VectorXi LI((I.rows()+1)/2),RI(I.rows()/2);
  166. assert(LI.rows()+RI.rows() == I.rows());
  167. // Distribute left and right
  168. {
  169. int li = 0;
  170. int ri = 0;
  171. for(int i = 0;i<I.rows();i++)
  172. {
  173. if(SIdI(i)<=med)
  174. {
  175. LI(li++) = I(i);
  176. }else
  177. {
  178. RI(ri++) = I(i);
  179. }
  180. }
  181. }
  182. //m_depth = 0;
  183. if(LI.rows()>0)
  184. {
  185. m_left = new AABB();
  186. m_left->init(V,Ele,SI,LI);
  187. //m_depth = std::max(m_depth, m_left->m_depth+1);
  188. }
  189. if(RI.rows()>0)
  190. {
  191. m_right = new AABB();
  192. m_right->init(V,Ele,SI,RI);
  193. //m_depth = std::max(m_depth, m_right->m_depth+1);
  194. }
  195. }
  196. }
  197. }
  198. template <typename DerivedV, int DIM>
  199. IGL_INLINE bool igl::AABB<DerivedV,DIM>::is_leaf() const
  200. {
  201. return m_primitive != -1;
  202. }
  203. template <typename DerivedV, int DIM>
  204. template <typename Derivedq>
  205. IGL_INLINE std::vector<int> igl::AABB<DerivedV,DIM>::find(
  206. const Eigen::PlainObjectBase<DerivedV> & V,
  207. const Eigen::MatrixXi & Ele,
  208. const Eigen::PlainObjectBase<Derivedq> & q,
  209. const bool first) const
  210. {
  211. using namespace std;
  212. using namespace Eigen;
  213. assert(q.size() == DIM &&
  214. "Query dimension should match aabb dimension");
  215. assert(Ele.cols() == V.cols()+1 &&
  216. "AABB::find only makes sense for (d+1)-simplices");
  217. const Scalar epsilon = igl::EPS<Scalar>();
  218. // Check if outside bounding box
  219. bool inside = m_box.contains(q.transpose());
  220. if(!inside)
  221. {
  222. return std::vector<int>();
  223. }
  224. assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
  225. if(is_leaf())
  226. {
  227. // Initialize to some value > -epsilon
  228. Scalar a1=0,a2=0,a3=0,a4=0;
  229. switch(DIM)
  230. {
  231. case 3:
  232. {
  233. // Barycentric coordinates
  234. typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
  235. const RowVector3S V1 = V.row(Ele(m_primitive,0));
  236. const RowVector3S V2 = V.row(Ele(m_primitive,1));
  237. const RowVector3S V3 = V.row(Ele(m_primitive,2));
  238. const RowVector3S V4 = V.row(Ele(m_primitive,3));
  239. a1 = volume_single(V2,V4,V3,(RowVector3S)q);
  240. a2 = volume_single(V1,V3,V4,(RowVector3S)q);
  241. a3 = volume_single(V1,V4,V2,(RowVector3S)q);
  242. a4 = volume_single(V1,V2,V3,(RowVector3S)q);
  243. break;
  244. }
  245. case 2:
  246. {
  247. // Barycentric coordinates
  248. typedef Eigen::Matrix<Scalar,2,1> Vector2S;
  249. const Vector2S V1 = V.row(Ele(m_primitive,0));
  250. const Vector2S V2 = V.row(Ele(m_primitive,1));
  251. const Vector2S V3 = V.row(Ele(m_primitive,2));
  252. // Hack for now to keep templates simple. If becomes bottleneck
  253. // consider using std::enable_if_t
  254. const Vector2S q2 = q.head(2);
  255. a1 = doublearea_single(V1,V2,q2);
  256. a2 = doublearea_single(V2,V3,q2);
  257. a3 = doublearea_single(V3,V1,q2);
  258. break;
  259. }
  260. default:assert(false);
  261. }
  262. // Normalization is important for correcting sign
  263. Scalar sum = a1+a2+a3+a4;
  264. a1 /= sum;
  265. a2 /= sum;
  266. a3 /= sum;
  267. a4 /= sum;
  268. if(
  269. a1>=-epsilon &&
  270. a2>=-epsilon &&
  271. a3>=-epsilon &&
  272. a4>=-epsilon)
  273. {
  274. return std::vector<int>(1,m_primitive);
  275. }else
  276. {
  277. return std::vector<int>();
  278. }
  279. }
  280. std::vector<int> left = m_left->find(V,Ele,q,first);
  281. if(first && !left.empty())
  282. {
  283. return left;
  284. }
  285. std::vector<int> right = m_right->find(V,Ele,q,first);
  286. if(first)
  287. {
  288. return right;
  289. }
  290. left.insert(left.end(),right.begin(),right.end());
  291. return left;
  292. }
  293. template <typename DerivedV, int DIM>
  294. IGL_INLINE int igl::AABB<DerivedV,DIM>::subtree_size() const
  295. {
  296. // 1 for self
  297. int n = 1;
  298. int n_left = 0,n_right = 0;
  299. if(m_left != NULL)
  300. {
  301. n_left = m_left->subtree_size();
  302. }
  303. if(m_right != NULL)
  304. {
  305. n_right = m_right->subtree_size();
  306. }
  307. n += 2*std::max(n_left,n_right);
  308. return n;
  309. }
  310. template <typename DerivedV, int DIM>
  311. template <typename Derivedbb_mins, typename Derivedbb_maxs>
  312. IGL_INLINE void igl::AABB<DerivedV,DIM>::serialize(
  313. Eigen::PlainObjectBase<Derivedbb_mins> & bb_mins,
  314. Eigen::PlainObjectBase<Derivedbb_maxs> & bb_maxs,
  315. Eigen::VectorXi & elements,
  316. const int i) const
  317. {
  318. using namespace std;
  319. using namespace Eigen;
  320. // Calling for root then resize output
  321. if(i==0)
  322. {
  323. const int m = subtree_size();
  324. //cout<<"m: "<<m<<endl;
  325. bb_mins.resize(m,DIM);
  326. bb_maxs.resize(m,DIM);
  327. elements.resize(m,1);
  328. }
  329. //cout<<i<<" ";
  330. bb_mins.row(i) = m_box.min();
  331. bb_maxs.row(i) = m_box.max();
  332. elements(i) = m_primitive;
  333. if(m_left != NULL)
  334. {
  335. m_left->serialize(bb_mins,bb_maxs,elements,2*i+1);
  336. }
  337. if(m_right != NULL)
  338. {
  339. m_right->serialize(bb_mins,bb_maxs,elements,2*i+2);
  340. }
  341. }
  342. template <typename DerivedV, int DIM>
  343. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  344. igl::AABB<DerivedV,DIM>::squared_distance(
  345. const Eigen::PlainObjectBase<DerivedV> & V,
  346. const Eigen::MatrixXi & Ele,
  347. const RowVectorDIMS & p,
  348. int & i,
  349. RowVectorDIMS & c) const
  350. {
  351. return squared_distance(V,Ele,p,std::numeric_limits<Scalar>::infinity(),i,c);
  352. }
  353. template <typename DerivedV, int DIM>
  354. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  355. igl::AABB<DerivedV,DIM>::squared_distance(
  356. const Eigen::PlainObjectBase<DerivedV> & V,
  357. const Eigen::MatrixXi & Ele,
  358. const RowVectorDIMS & p,
  359. Scalar min_sqr_d,
  360. int & i,
  361. RowVectorDIMS & c) const
  362. {
  363. using namespace Eigen;
  364. using namespace std;
  365. Scalar sqr_d = min_sqr_d;
  366. //assert(DIM == 3 && "Code has only been tested for DIM == 3");
  367. assert((Ele.cols() == 3 || Ele.cols() == 2 || Ele.cols() == 1)
  368. && "Code has only been tested for simplex sizes 3,2,1");
  369. assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
  370. if(is_leaf())
  371. {
  372. leaf_squared_distance(V,Ele,p,sqr_d,i,c);
  373. }else
  374. {
  375. bool looked_left = false;
  376. bool looked_right = false;
  377. const auto & look_left = [&]()
  378. {
  379. int i_left;
  380. RowVectorDIMS c_left = c;
  381. Scalar sqr_d_left = m_left->squared_distance(V,Ele,p,sqr_d,i_left,c_left);
  382. this->set_min(p,sqr_d_left,i_left,c_left,sqr_d,i,c);
  383. looked_left = true;
  384. };
  385. const auto & look_right = [&]()
  386. {
  387. int i_right;
  388. RowVectorDIMS c_right = c;
  389. Scalar sqr_d_right =
  390. m_right->squared_distance(V,Ele,p,sqr_d,i_right,c_right);
  391. this->set_min(p,sqr_d_right,i_right,c_right,sqr_d,i,c);
  392. looked_right = true;
  393. };
  394. // must look left or right if in box
  395. if(m_left->m_box.contains(p.transpose()))
  396. {
  397. look_left();
  398. }
  399. if(m_right->m_box.contains(p.transpose()))
  400. {
  401. look_right();
  402. }
  403. // if haven't looked left and could be less than current min, then look
  404. Scalar left_min_sqr_d =
  405. m_left->m_box.squaredExteriorDistance(p.transpose());
  406. Scalar right_min_sqr_d =
  407. m_right->m_box.squaredExteriorDistance(p.transpose());
  408. if(left_min_sqr_d < right_min_sqr_d)
  409. {
  410. if(!looked_left && left_min_sqr_d<sqr_d)
  411. {
  412. look_left();
  413. }
  414. if( !looked_right && right_min_sqr_d<sqr_d)
  415. {
  416. look_right();
  417. }
  418. }else
  419. {
  420. if( !looked_right && right_min_sqr_d<sqr_d)
  421. {
  422. look_right();
  423. }
  424. if(!looked_left && left_min_sqr_d<sqr_d)
  425. {
  426. look_left();
  427. }
  428. }
  429. }
  430. return sqr_d;
  431. }
  432. template <typename DerivedV, int DIM>
  433. template <
  434. typename DerivedP,
  435. typename DerivedsqrD,
  436. typename DerivedI,
  437. typename DerivedC>
  438. IGL_INLINE void igl::AABB<DerivedV,DIM>::squared_distance(
  439. const Eigen::PlainObjectBase<DerivedV> & V,
  440. const Eigen::MatrixXi & Ele,
  441. const Eigen::PlainObjectBase<DerivedP> & P,
  442. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  443. Eigen::PlainObjectBase<DerivedI> & I,
  444. Eigen::PlainObjectBase<DerivedC> & C) const
  445. {
  446. assert(P.cols() == V.cols() && "cols in P should match dim of cols in V");
  447. sqrD.resize(P.rows(),1);
  448. I.resize(P.rows(),1);
  449. C.resize(P.rows(),P.cols());
  450. // O( #P * log #Ele ), where log #Ele is really the depth of this AABB
  451. // hierarchy
  452. for(int p = 0;p<P.rows();p++)
  453. {
  454. RowVectorDIMS Pp = P.row(p), c;
  455. int Ip;
  456. sqrD(p) = squared_distance(V,Ele,Pp,Ip,c);
  457. I(p) = Ip;
  458. C.row(p).head(DIM) = c;
  459. }
  460. }
  461. template <typename DerivedV, int DIM>
  462. template <
  463. typename Derivedother_V,
  464. typename DerivedsqrD,
  465. typename DerivedI,
  466. typename DerivedC>
  467. IGL_INLINE void igl::AABB<DerivedV,DIM>::squared_distance(
  468. const Eigen::PlainObjectBase<DerivedV> & V,
  469. const Eigen::MatrixXi & Ele,
  470. const AABB<Derivedother_V,DIM> & other,
  471. const Eigen::PlainObjectBase<Derivedother_V> & other_V,
  472. const Eigen::MatrixXi & other_Ele,
  473. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  474. Eigen::PlainObjectBase<DerivedI> & I,
  475. Eigen::PlainObjectBase<DerivedC> & C) const
  476. {
  477. assert(other_Ele.cols() == 1 &&
  478. "Only implemented for other as list of points");
  479. assert(other_V.cols() == V.cols() && "other must match this dimension");
  480. sqrD.setConstant(other_Ele.rows(),1,std::numeric_limits<double>::infinity());
  481. I.resize(other_Ele.rows(),1);
  482. C.resize(other_Ele.rows(),other_V.cols());
  483. // All points in other_V currently think they need to check against root of
  484. // this. The point of using another AABB is to quickly prune chunks of
  485. // other_V so that most points just check some subtree of this.
  486. // This holds a conservative estimate of max(sqr_D) where sqr_D is the
  487. // current best minimum squared distance for all points in this subtree
  488. double min_sqr_d = std::numeric_limits<double>::infinity();
  489. squared_distance_helper(
  490. V,Ele,&other,other_V,other_Ele,min_sqr_d,sqrD,I,C);
  491. }
  492. template <typename DerivedV, int DIM>
  493. template <
  494. typename Derivedother_V,
  495. typename DerivedsqrD,
  496. typename DerivedI,
  497. typename DerivedC>
  498. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  499. igl::AABB<DerivedV,DIM>::squared_distance_helper(
  500. const Eigen::PlainObjectBase<DerivedV> & V,
  501. const Eigen::MatrixXi & Ele,
  502. const AABB<Derivedother_V,DIM> * other,
  503. const Eigen::PlainObjectBase<Derivedother_V> & other_V,
  504. const Eigen::MatrixXi & other_Ele,
  505. const Scalar /*min_sqr_d*/,
  506. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  507. Eigen::PlainObjectBase<DerivedI> & I,
  508. Eigen::PlainObjectBase<DerivedC> & C) const
  509. {
  510. using namespace std;
  511. using namespace Eigen;
  512. // This implementation is a bit disappointing. There's no major speed up. Any
  513. // performance gains seem to come from accidental cache coherency and
  514. // diminish for larger "other" (the opposite of what was intended).
  515. // Base case
  516. if(other->is_leaf() && this->is_leaf())
  517. {
  518. Scalar sqr_d = sqrD(other->m_primitive);
  519. int i = I(other->m_primitive);
  520. RowVectorDIMS c = C.row( other->m_primitive);
  521. RowVectorDIMS p = other_V.row(other->m_primitive);
  522. leaf_squared_distance(V,Ele,p,sqr_d,i,c);
  523. sqrD( other->m_primitive) = sqr_d;
  524. I( other->m_primitive) = i;
  525. C.row(other->m_primitive) = c;
  526. //cout<<"leaf: "<<sqr_d<<endl;
  527. //other->m_max_sqr_d = sqr_d;
  528. return sqr_d;
  529. }
  530. if(other->is_leaf())
  531. {
  532. Scalar sqr_d = sqrD(other->m_primitive);
  533. int i = I(other->m_primitive);
  534. RowVectorDIMS c = C.row( other->m_primitive);
  535. RowVectorDIMS p = other_V.row(other->m_primitive);
  536. sqr_d = squared_distance(V,Ele,p,sqr_d,i,c);
  537. sqrD( other->m_primitive) = sqr_d;
  538. I( other->m_primitive) = i;
  539. C.row(other->m_primitive) = c;
  540. //other->m_max_sqr_d = sqr_d;
  541. return sqr_d;
  542. }
  543. //// Exact minimum squared distance between arbitary primitives inside this and
  544. //// othre's bounding boxes
  545. //const auto & min_squared_distance = [&](
  546. // const AABB<DerivedV,DIM> * A,
  547. // const AABB<Derivedother_V,DIM> * B)->Scalar
  548. //{
  549. // return A->m_box.squaredExteriorDistance(B->m_box);
  550. //};
  551. if(this->is_leaf())
  552. {
  553. //if(min_squared_distance(this,other) < other->m_max_sqr_d)
  554. if(true)
  555. {
  556. this->squared_distance_helper(
  557. V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
  558. this->squared_distance_helper(
  559. V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
  560. }else
  561. {
  562. // This is never reached...
  563. }
  564. //// we know other is not a leaf
  565. //other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  566. return 0;
  567. }
  568. // FORCE DOWN TO OTHER LEAF EVAL
  569. //if(min_squared_distance(this,other) < other->m_max_sqr_d)
  570. if(true)
  571. {
  572. if(true)
  573. {
  574. this->squared_distance_helper(
  575. V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
  576. this->squared_distance_helper(
  577. V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
  578. }else // this direction never seems to be faster
  579. {
  580. this->m_left->squared_distance_helper(
  581. V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
  582. this->m_right->squared_distance_helper(
  583. V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
  584. }
  585. }else
  586. {
  587. // this is never reached ... :-(
  588. }
  589. //// we know other is not a leaf
  590. //other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  591. return 0;
  592. #if 0 // False
  593. // _Very_ conservative approximation of maximum squared distance between
  594. // primitives inside this and other's bounding boxes
  595. const auto & max_squared_distance = [](
  596. const AABB<DerivedV,DIM> * A,
  597. const AABB<Derivedother_V,DIM> * B)->Scalar
  598. {
  599. AlignedBox<Scalar,DIM> combo = A->m_box;
  600. combo.extend(B->m_box);
  601. return combo.diagonal().squaredNorm();
  602. };
  603. //// other base-case
  604. //if(other->is_leaf())
  605. //{
  606. // double sqr_d = sqrD(other->m_primitive);
  607. // int i = I(other->m_primitive);
  608. // RowVectorDIMS c = C.row(m_primitive);
  609. // RowVectorDIMS p = other_V.row(m_primitive);
  610. // leaf_squared_distance(V,Ele,p,sqr_d,i,c);
  611. // sqrD(other->m_primitive) = sqr_d;
  612. // I(other->m_primitive) = i;
  613. // C.row(m_primitive) = c;
  614. // return;
  615. //}
  616. std::vector<const AABB<DerivedV,DIM> * > this_list;
  617. if(this->is_leaf())
  618. {
  619. this_list.push_back(this);
  620. }else
  621. {
  622. assert(this->m_left);
  623. this_list.push_back(this->m_left);
  624. assert(this->m_right);
  625. this_list.push_back(this->m_right);
  626. }
  627. std::vector<AABB<Derivedother_V,DIM> *> other_list;
  628. if(other->is_leaf())
  629. {
  630. other_list.push_back(other);
  631. }else
  632. {
  633. assert(other->m_left);
  634. other_list.push_back(other->m_left);
  635. assert(other->m_right);
  636. other_list.push_back(other->m_right);
  637. }
  638. //const std::function<Scalar(
  639. // const AABB<Derivedother_V,DIM> * other)
  640. // > max_sqr_d = [&sqrD,&max_sqr_d](const AABB<Derivedother_V,DIM> * other)->Scalar
  641. // {
  642. // if(other->is_leaf())
  643. // {
  644. // return sqrD(other->m_primitive);
  645. // }else
  646. // {
  647. // return std::max(max_sqr_d(other->m_left),max_sqr_d(other->m_right));
  648. // }
  649. // };
  650. //// Potentially recurse on all pairs, if minimum distance is less than running
  651. //// bound
  652. //Eigen::Matrix<Scalar,Eigen::Dynamic,1> other_max_sqr_d =
  653. // Eigen::Matrix<Scalar,Eigen::Dynamic,1>::Constant(other_list.size(),1,min_sqr_d);
  654. for(size_t child = 0;child<other_list.size();child++)
  655. {
  656. auto other_tree = other_list[child];
  657. Eigen::Matrix<Scalar,Eigen::Dynamic,1> this_max_sqr_d(this_list.size(),1);
  658. for(size_t t = 0;t<this_list.size();t++)
  659. {
  660. const auto this_tree = this_list[t];
  661. this_max_sqr_d(t) = max_squared_distance(this_tree,other_tree);
  662. }
  663. if(this_list.size() ==2 &&
  664. ( this_max_sqr_d(0) > this_max_sqr_d(1))
  665. )
  666. {
  667. std::swap(this_list[0],this_list[1]);
  668. //std::swap(this_max_sqr_d(0),this_max_sqr_d(1));
  669. }
  670. const Scalar sqr_d = this_max_sqr_d.minCoeff();
  671. for(size_t t = 0;t<this_list.size();t++)
  672. {
  673. const auto this_tree = this_list[t];
  674. //const auto mm = max_sqr_d(other_tree);
  675. //const Scalar mc = other_max_sqr_d(child);
  676. //assert(mc == mm);
  677. // Only look left/right in this_list if can possible decrease somebody's
  678. // distance in this_tree.
  679. const Scalar min_this_other = min_squared_distance(this_tree,other_tree);
  680. if(
  681. min_this_other < sqr_d &&
  682. min_this_other < other_tree->m_max_sqr_d)
  683. {
  684. //cout<<"before: "<<other_max_sqr_d(child)<<endl;
  685. //other_max_sqr_d(child) = std::min(
  686. // other_max_sqr_d(child),
  687. // this_tree->squared_distance_helper(
  688. // V,Ele,other_tree,other_V,other_Ele,other_max_sqr_d(child),sqrD,I,C));
  689. //cout<<"after: "<<other_max_sqr_d(child)<<endl;
  690. this_tree->squared_distance_helper(
  691. V,Ele,other_tree,other_V,other_Ele,0,sqrD,I,C);
  692. }
  693. }
  694. }
  695. //const Scalar ret = other_max_sqr_d.maxCoeff();
  696. //const auto mm = max_sqr_d(other);
  697. //assert(mm == ret);
  698. //cout<<"non-leaf: "<<ret<<endl;
  699. //return ret;
  700. if(!other->is_leaf())
  701. {
  702. other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  703. }
  704. return 0;
  705. #endif
  706. }
  707. template <typename DerivedV, int DIM>
  708. IGL_INLINE void igl::AABB<DerivedV,DIM>::leaf_squared_distance(
  709. const Eigen::PlainObjectBase<DerivedV> & V,
  710. const Eigen::MatrixXi & Ele,
  711. const RowVectorDIMS & p,
  712. Scalar & sqr_d,
  713. int & i,
  714. RowVectorDIMS & c) const
  715. {
  716. using namespace Eigen;
  717. using namespace std;
  718. RowVectorDIMS c_candidate;
  719. Scalar sqr_d_candidate;
  720. igl::point_simplex_squared_distance<DIM>(
  721. p,V,Ele,m_primitive,sqr_d_candidate,c_candidate);
  722. set_min(p,sqr_d_candidate,m_primitive,c_candidate,sqr_d,i,c);
  723. }
  724. template <typename DerivedV, int DIM>
  725. IGL_INLINE void igl::AABB<DerivedV,DIM>::set_min(
  726. const RowVectorDIMS &
  727. #ifndef NDEBUG
  728. p
  729. #endif
  730. ,
  731. const Scalar sqr_d_candidate,
  732. const int i_candidate,
  733. const RowVectorDIMS & c_candidate,
  734. Scalar & sqr_d,
  735. int & i,
  736. RowVectorDIMS & c) const
  737. {
  738. #ifndef NDEBUG
  739. //std::cout<<matlab_format(c_candidate,"c_candidate")<<std::endl;
  740. const Scalar pc_norm = (p-c_candidate).squaredNorm();
  741. const Scalar diff = fabs(sqr_d_candidate - pc_norm);
  742. assert(diff<=1e-10 && "distance should match norm of difference");
  743. #endif
  744. if(sqr_d_candidate < sqr_d)
  745. {
  746. i = i_candidate;
  747. c = c_candidate;
  748. sqr_d = sqr_d_candidate;
  749. }
  750. }
  751. template <typename DerivedV, int DIM>
  752. IGL_INLINE bool
  753. igl::AABB<DerivedV,DIM>::intersect_ray(
  754. const Eigen::PlainObjectBase<DerivedV> & V,
  755. const Eigen::MatrixXi & Ele,
  756. const RowVectorDIMS & origin,
  757. const RowVectorDIMS & dir,
  758. std::vector<igl::Hit> & hits) const
  759. {
  760. hits.clear();
  761. const Scalar t0 = 0;
  762. const Scalar t1 = std::numeric_limits<Scalar>::infinity();
  763. {
  764. Scalar _1,_2;
  765. if(!ray_box_intersect(origin,dir,m_box,t0,t1,_1,_2))
  766. {
  767. return false;
  768. }
  769. }
  770. if(this->is_leaf())
  771. {
  772. // Actually process elements
  773. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  774. // Cheesecake way of hitting element
  775. bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hits);
  776. // Since we only gave ray_mesh_intersect a single face, it will have set
  777. // any hits to id=0. Set these to this primitive's id
  778. for(auto & hit : hits)
  779. {
  780. hit.id = m_primitive;
  781. }
  782. return ret;
  783. }
  784. std::vector<igl::Hit> left_hits;
  785. std::vector<igl::Hit> right_hits;
  786. const bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,left_hits);
  787. const bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,right_hits);
  788. hits.insert(hits.end(),left_hits.begin(),left_hits.end());
  789. hits.insert(hits.end(),right_hits.begin(),right_hits.end());
  790. return left_ret || right_ret;
  791. }
  792. template <typename DerivedV, int DIM>
  793. IGL_INLINE bool
  794. igl::AABB<DerivedV,DIM>::intersect_ray(
  795. const Eigen::PlainObjectBase<DerivedV> & V,
  796. const Eigen::MatrixXi & Ele,
  797. const RowVectorDIMS & origin,
  798. const RowVectorDIMS & dir,
  799. igl::Hit & hit) const
  800. {
  801. #if false
  802. // BFS
  803. std::queue<const AABB *> Q;
  804. // Or DFS
  805. //std::stack<const AABB *> Q;
  806. Q.push(this);
  807. bool any_hit = false;
  808. hit.t = std::numeric_limits<Scalar>::infinity();
  809. while(!Q.empty())
  810. {
  811. const AABB * tree = Q.front();
  812. //const AABB * tree = Q.top();
  813. Q.pop();
  814. {
  815. Scalar _1,_2;
  816. if(!ray_box_intersect(
  817. origin,dir,tree->m_box,Scalar(0),Scalar(hit.t),_1,_2))
  818. {
  819. continue;
  820. }
  821. }
  822. if(tree->is_leaf())
  823. {
  824. // Actually process elements
  825. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  826. igl::Hit leaf_hit;
  827. if(
  828. ray_mesh_intersect(origin,dir,V,Ele.row(tree->m_primitive),leaf_hit)&&
  829. leaf_hit.t < hit.t)
  830. {
  831. // correct the id
  832. leaf_hit.id = tree->m_primitive;
  833. hit = leaf_hit;
  834. }
  835. continue;
  836. }
  837. // Add children to queue
  838. Q.push(tree->m_left);
  839. Q.push(tree->m_right);
  840. }
  841. return any_hit;
  842. #else
  843. // DFS
  844. return intersect_ray(
  845. V,Ele,origin,dir,std::numeric_limits<Scalar>::infinity(),hit);
  846. #endif
  847. }
  848. template <typename DerivedV, int DIM>
  849. IGL_INLINE bool
  850. igl::AABB<DerivedV,DIM>::intersect_ray(
  851. const Eigen::PlainObjectBase<DerivedV> & V,
  852. const Eigen::MatrixXi & Ele,
  853. const RowVectorDIMS & origin,
  854. const RowVectorDIMS & dir,
  855. const Scalar _min_t,
  856. igl::Hit & hit) const
  857. {
  858. //// Naive, slow
  859. //std::vector<igl::Hit> hits;
  860. //intersect_ray(V,Ele,origin,dir,hits);
  861. //if(hits.size() > 0)
  862. //{
  863. // hit = hits.front();
  864. // return true;
  865. //}else
  866. //{
  867. // return false;
  868. //}
  869. Scalar min_t = _min_t;
  870. const Scalar t0 = 0;
  871. {
  872. Scalar _1,_2;
  873. if(!ray_box_intersect(origin,dir,m_box,t0,min_t,_1,_2))
  874. {
  875. return false;
  876. }
  877. }
  878. if(this->is_leaf())
  879. {
  880. // Actually process elements
  881. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  882. // Cheesecake way of hitting element
  883. bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hit);
  884. hit.id = m_primitive;
  885. return ret;
  886. }
  887. // Doesn't seem like smartly choosing left before/after right makes a
  888. // differnce
  889. igl::Hit left_hit;
  890. igl::Hit right_hit;
  891. bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,min_t,left_hit);
  892. if(left_ret && left_hit.t<min_t)
  893. {
  894. // It's scary that this line doesn't seem to matter....
  895. min_t = left_hit.t;
  896. hit = left_hit;
  897. left_ret = true;
  898. }else
  899. {
  900. left_ret = false;
  901. }
  902. bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,min_t,right_hit);
  903. if(right_ret && right_hit.t<min_t)
  904. {
  905. min_t = right_hit.t;
  906. hit = right_hit;
  907. right_ret = true;
  908. }else
  909. {
  910. right_ret = false;
  911. }
  912. return left_ret || right_ret;
  913. }
  914. #ifdef IGL_STATIC_LIBRARY
  915. // Explicit template specialization
  916. // generated by autoexplicit.sh
  917. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&) const;
  918. // generated by autoexplicit.sh
  919. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<long, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> >&) const;
  920. // generated by autoexplicit.sh
  921. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::init(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&);
  922. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::init(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&);
  923. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&) const;
  924. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&) const;
  925. template double igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::squared_distance(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, 1, 3, 1, 1, 3> const&, int&, Eigen::Matrix<double, 1, 3, 1, 1, 3>&) const;
  926. template double igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::squared_distance(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::Matrix<double, 1, 2, 1, 1, 2> const&, int&, Eigen::Matrix<double, 1, 2, 1, 1, 2>&) const;
  927. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&) const;
  928. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::squared_distance<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1>, Eigen::Matrix<int, -1, 1, 0, -1, 1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&) const;
  929. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::init<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int);
  930. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::init<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, 1, 0, -1, 1> const&, int);
  931. template std::vector<int, std::allocator<int> > igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::find<Eigen::Matrix<double, 1, -1, 1, 1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > const&, bool) const;
  932. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 2>::serialize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&, int) const;
  933. template std::vector<int, std::allocator<int> > igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::find<Eigen::Matrix<double, 1, -1, 1, 1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, -1, 1, 1, -1> > const&, bool) const;
  934. template void igl::AABB<Eigen::Matrix<double, -1, -1, 0, -1, -1>, 3>::serialize<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::Matrix<int, -1, 1, 0, -1, 1>&, int) const;
  935. #endif