AABB.cpp 35 KB

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