AABB.cpp 39 KB

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