AABB.cpp 34 KB

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