AABB.cpp 38 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798991001011021031041051061071081091101111121131141151161171181191201211221231241251261271281291301311321331341351361371381391401411421431441451461471481491501511521531541551561571581591601611621631641651661671681691701711721731741751761771781791801811821831841851861871881891901911921931941951961971981992002012022032042052062072082092102112122132142152162172182192202212222232242252262272282292302312322332342352362372382392402412422432442452462472482492502512522532542552562572582592602612622632642652662672682692702712722732742752762772782792802812822832842852862872882892902912922932942952962972982993003013023033043053063073083093103113123133143153163173183193203213223233243253263273283293303313323333343353363373383393403413423433443453463473483493503513523533543553563573583593603613623633643653663673683693703713723733743753763773783793803813823833843853863873883893903913923933943953963973983994004014024034044054064074084094104114124134144154164174184194204214224234244254264274284294304314324334344354364374384394404414424434444454464474484494504514524534544554564574584594604614624634644654664674684694704714724734744754764774784794804814824834844854864874884894904914924934944954964974984995005015025035045055065075085095105115125135145155165175185195205215225235245255265275285295305315325335345355365375385395405415425435445455465475485495505515525535545555565575585595605615625635645655665675685695705715725735745755765775785795805815825835845855865875885895905915925935945955965975985996006016026036046056066076086096106116126136146156166176186196206216226236246256266276286296306316326336346356366376386396406416426436446456466476486496506516526536546556566576586596606616626636646656666676686696706716726736746756766776786796806816826836846856866876886896906916926936946956966976986997007017027037047057067077087097107117127137147157167177187197207217227237247257267277287297307317327337347357367377387397407417427437447457467477487497507517527537547557567577587597607617627637647657667677687697707717727737747757767777787797807817827837847857867877887897907917927937947957967977987998008018028038048058068078088098108118128138148158168178188198208218228238248258268278288298308318328338348358368378388398408418428438448458468478488498508518528538548558568578588598608618628638648658668678688698708718728738748758768778788798808818828838848858868878888898908918928938948958968978988999009019029039049059069079089099109119129139149159169179189199209219229239249259269279289299309319329339349359369379389399409419429439449459469479489499509519529539549559569579589599609619629639649659669679689699709719729739749759769779789799809819829839849859869879889899909919929939949959969979989991000100110021003100410051006100710081009101010111012101310141015101610171018101910201021102210231024102510261027102810291030103110321033103410351036103710381039104010411042104310441045104610471048104910501051105210531054105510561057
  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. using namespace Eigen;
  363. using namespace std;
  364. if(max_sqr_d > min_sqr_d)
  365. {
  366. return max_sqr_d;
  367. }
  368. Scalar sqr_d = min_sqr_d;
  369. //assert(DIM == 3 && "Code has only been tested for DIM == 3");
  370. assert((Ele.cols() == 3 || Ele.cols() == 2 || Ele.cols() == 1)
  371. && "Code has only been tested for simplex sizes 3,2,1");
  372. assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
  373. if(is_leaf())
  374. {
  375. leaf_squared_distance(V,Ele,p,max_sqr_d,sqr_d,i,c);
  376. }else
  377. {
  378. bool looked_left = false;
  379. bool looked_right = false;
  380. const auto & look_left = [&]()
  381. {
  382. int i_left;
  383. RowVectorDIMS c_left = c;
  384. Scalar sqr_d_left =
  385. m_left->squared_distance(V,Ele,p,max_sqr_d,sqr_d,i_left,c_left);
  386. this->set_min(p,sqr_d_left,i_left,c_left,sqr_d,i,c);
  387. looked_left = true;
  388. };
  389. const auto & look_right = [&]()
  390. {
  391. int i_right;
  392. Eigen::PlainObjectBase<RowVectorDIMS> c_right = c;
  393. Scalar sqr_d_right =
  394. m_right->squared_distance(V,Ele,p,max_sqr_d,sqr_d,i_right,c_right);
  395. this->set_min(p,sqr_d_right,i_right,c_right,sqr_d,i,c);
  396. looked_right = true;
  397. };
  398. // must look left or right if in box
  399. if(m_left->m_box.contains(p.transpose()))
  400. {
  401. look_left();
  402. }
  403. if(m_right->m_box.contains(p.transpose()))
  404. {
  405. look_right();
  406. }
  407. // if haven't looked left and could be less than current min, then look
  408. Scalar left_min_sqr_d =
  409. m_left->m_box.squaredExteriorDistance(p.transpose());
  410. Scalar right_min_sqr_d =
  411. m_right->m_box.squaredExteriorDistance(p.transpose());
  412. if(left_min_sqr_d < right_min_sqr_d)
  413. {
  414. if(!looked_left && left_min_sqr_d<sqr_d)
  415. {
  416. look_left();
  417. }
  418. if( !looked_right && right_min_sqr_d<sqr_d)
  419. {
  420. look_right();
  421. }
  422. }else
  423. {
  424. if( !looked_right && right_min_sqr_d<sqr_d)
  425. {
  426. look_right();
  427. }
  428. if(!looked_left && left_min_sqr_d<sqr_d)
  429. {
  430. look_left();
  431. }
  432. }
  433. }
  434. return sqr_d;
  435. }
  436. template <typename DerivedV, int DIM>
  437. template <typename DerivedEle>
  438. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  439. igl::AABB<DerivedV,DIM>::squared_distance(
  440. const Eigen::MatrixBase<DerivedV> & V,
  441. const Eigen::MatrixBase<DerivedEle> & Ele,
  442. const RowVectorDIMS & p,
  443. Scalar min_sqr_d,
  444. int & i,
  445. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  446. {
  447. return squared_distance(V,Ele,p,0.0,min_sqr_d,i,c);
  448. }
  449. template <typename DerivedV, int DIM>
  450. template <
  451. typename DerivedEle,
  452. typename DerivedP,
  453. typename DerivedsqrD,
  454. typename DerivedI,
  455. typename DerivedC>
  456. IGL_INLINE void igl::AABB<DerivedV,DIM>::squared_distance(
  457. const Eigen::MatrixBase<DerivedV> & V,
  458. const Eigen::MatrixBase<DerivedEle> & Ele,
  459. const Eigen::MatrixBase<DerivedP> & P,
  460. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  461. Eigen::PlainObjectBase<DerivedI> & I,
  462. Eigen::PlainObjectBase<DerivedC> & C) const
  463. {
  464. assert(P.cols() == V.cols() && "cols in P should match dim of cols in V");
  465. sqrD.resize(P.rows(),1);
  466. I.resize(P.rows(),1);
  467. C.resizeLike(P);
  468. // O( #P * log #Ele ), where log #Ele is really the depth of this AABB
  469. // hierarchy
  470. for(int p = 0;p<P.rows();p++)
  471. {
  472. RowVectorDIMS Pp = P.row(p), c;
  473. int Ip;
  474. sqrD(p) = squared_distance(V,Ele,Pp,Ip,c);
  475. I(p) = Ip;
  476. C.row(p).head(DIM) = c;
  477. }
  478. }
  479. template <typename DerivedV, int DIM>
  480. template <
  481. typename DerivedEle,
  482. typename Derivedother_V,
  483. typename Derivedother_Ele,
  484. typename DerivedsqrD,
  485. typename DerivedI,
  486. typename DerivedC>
  487. IGL_INLINE void igl::AABB<DerivedV,DIM>::squared_distance(
  488. const Eigen::MatrixBase<DerivedV> & V,
  489. const Eigen::MatrixBase<DerivedEle> & Ele,
  490. const AABB<Derivedother_V,DIM> & other,
  491. const Eigen::MatrixBase<Derivedother_V> & other_V,
  492. const Eigen::MatrixBase<Derivedother_Ele> & other_Ele,
  493. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  494. Eigen::PlainObjectBase<DerivedI> & I,
  495. Eigen::PlainObjectBase<DerivedC> & C) const
  496. {
  497. assert(other_Ele.cols() == 1 &&
  498. "Only implemented for other as list of points");
  499. assert(other_V.cols() == V.cols() && "other must match this dimension");
  500. sqrD.setConstant(other_Ele.rows(),1,std::numeric_limits<double>::infinity());
  501. I.resize(other_Ele.rows(),1);
  502. C.resize(other_Ele.rows(),other_V.cols());
  503. // All points in other_V currently think they need to check against root of
  504. // this. The point of using another AABB is to quickly prune chunks of
  505. // other_V so that most points just check some subtree of this.
  506. // This holds a conservative estimate of max(sqr_D) where sqr_D is the
  507. // current best minimum squared distance for all points in this subtree
  508. double min_sqr_d = std::numeric_limits<double>::infinity();
  509. squared_distance_helper(
  510. V,Ele,&other,other_V,other_Ele,0,min_sqr_d,sqrD,I,C);
  511. }
  512. template <typename DerivedV, int DIM>
  513. template <
  514. typename DerivedEle,
  515. typename Derivedother_V,
  516. typename Derivedother_Ele,
  517. typename DerivedsqrD,
  518. typename DerivedI,
  519. typename DerivedC>
  520. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  521. igl::AABB<DerivedV,DIM>::squared_distance_helper(
  522. const Eigen::MatrixBase<DerivedV> & V,
  523. const Eigen::MatrixBase<DerivedEle> & Ele,
  524. const AABB<Derivedother_V,DIM> * other,
  525. const Eigen::MatrixBase<Derivedother_V> & other_V,
  526. const Eigen::MatrixBase<Derivedother_Ele> & other_Ele,
  527. const Scalar /*min_sqr_d*/,
  528. Eigen::PlainObjectBase<DerivedsqrD> & sqrD,
  529. Eigen::PlainObjectBase<DerivedI> & I,
  530. Eigen::PlainObjectBase<DerivedC> & C) const
  531. {
  532. using namespace std;
  533. using namespace Eigen;
  534. // This implementation is a bit disappointing. There's no major speed up. Any
  535. // performance gains seem to come from accidental cache coherency and
  536. // diminish for larger "other" (the opposite of what was intended).
  537. // Base case
  538. if(other->is_leaf() && this->is_leaf())
  539. {
  540. Scalar sqr_d = sqrD(other->m_primitive);
  541. int i = I(other->m_primitive);
  542. RowVectorDIMS c = C.row( other->m_primitive);
  543. RowVectorDIMS p = other_V.row(other->m_primitive);
  544. leaf_squared_distance(V,Ele,p,sqr_d,i,c);
  545. sqrD( other->m_primitive) = sqr_d;
  546. I( other->m_primitive) = i;
  547. C.row(other->m_primitive) = c;
  548. //cout<<"leaf: "<<sqr_d<<endl;
  549. //other->m_max_sqr_d = sqr_d;
  550. return sqr_d;
  551. }
  552. if(other->is_leaf())
  553. {
  554. Scalar sqr_d = sqrD(other->m_primitive);
  555. int i = I(other->m_primitive);
  556. RowVectorDIMS c = C.row( other->m_primitive);
  557. RowVectorDIMS p = other_V.row(other->m_primitive);
  558. sqr_d = squared_distance(V,Ele,p,sqr_d,i,c);
  559. sqrD( other->m_primitive) = sqr_d;
  560. I( other->m_primitive) = i;
  561. C.row(other->m_primitive) = c;
  562. //other->m_max_sqr_d = sqr_d;
  563. return sqr_d;
  564. }
  565. //// Exact minimum squared distance between arbitary primitives inside this and
  566. //// othre's bounding boxes
  567. //const auto & min_squared_distance = [&](
  568. // const AABB<DerivedV,DIM> * A,
  569. // const AABB<Derivedother_V,DIM> * B)->Scalar
  570. //{
  571. // return A->m_box.squaredExteriorDistance(B->m_box);
  572. //};
  573. if(this->is_leaf())
  574. {
  575. //if(min_squared_distance(this,other) < other->m_max_sqr_d)
  576. if(true)
  577. {
  578. this->squared_distance_helper(
  579. V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
  580. this->squared_distance_helper(
  581. V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
  582. }else
  583. {
  584. // This is never reached...
  585. }
  586. //// we know other is not a leaf
  587. //other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  588. return 0;
  589. }
  590. // FORCE DOWN TO OTHER LEAF EVAL
  591. //if(min_squared_distance(this,other) < other->m_max_sqr_d)
  592. if(true)
  593. {
  594. if(true)
  595. {
  596. this->squared_distance_helper(
  597. V,Ele,other->m_left,other_V,other_Ele,0,sqrD,I,C);
  598. this->squared_distance_helper(
  599. V,Ele,other->m_right,other_V,other_Ele,0,sqrD,I,C);
  600. }else // this direction never seems to be faster
  601. {
  602. this->m_left->squared_distance_helper(
  603. V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
  604. this->m_right->squared_distance_helper(
  605. V,Ele,other,other_V,other_Ele,0,sqrD,I,C);
  606. }
  607. }else
  608. {
  609. // this is never reached ... :-(
  610. }
  611. //// we know other is not a leaf
  612. //other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  613. return 0;
  614. #if 0 // False
  615. // _Very_ conservative approximation of maximum squared distance between
  616. // primitives inside this and other's bounding boxes
  617. const auto & max_squared_distance = [](
  618. const AABB<DerivedV,DIM> * A,
  619. const AABB<Derivedother_V,DIM> * B)->Scalar
  620. {
  621. AlignedBox<Scalar,DIM> combo = A->m_box;
  622. combo.extend(B->m_box);
  623. return combo.diagonal().squaredNorm();
  624. };
  625. //// other base-case
  626. //if(other->is_leaf())
  627. //{
  628. // double sqr_d = sqrD(other->m_primitive);
  629. // int i = I(other->m_primitive);
  630. // RowVectorDIMS c = C.row(m_primitive);
  631. // RowVectorDIMS p = other_V.row(m_primitive);
  632. // leaf_squared_distance(V,Ele,p,sqr_d,i,c);
  633. // sqrD(other->m_primitive) = sqr_d;
  634. // I(other->m_primitive) = i;
  635. // C.row(m_primitive) = c;
  636. // return;
  637. //}
  638. std::vector<const AABB<DerivedV,DIM> * > this_list;
  639. if(this->is_leaf())
  640. {
  641. this_list.push_back(this);
  642. }else
  643. {
  644. assert(this->m_left);
  645. this_list.push_back(this->m_left);
  646. assert(this->m_right);
  647. this_list.push_back(this->m_right);
  648. }
  649. std::vector<AABB<Derivedother_V,DIM> *> other_list;
  650. if(other->is_leaf())
  651. {
  652. other_list.push_back(other);
  653. }else
  654. {
  655. assert(other->m_left);
  656. other_list.push_back(other->m_left);
  657. assert(other->m_right);
  658. other_list.push_back(other->m_right);
  659. }
  660. //const std::function<Scalar(
  661. // const AABB<Derivedother_V,DIM> * other)
  662. // > max_sqr_d = [&sqrD,&max_sqr_d](const AABB<Derivedother_V,DIM> * other)->Scalar
  663. // {
  664. // if(other->is_leaf())
  665. // {
  666. // return sqrD(other->m_primitive);
  667. // }else
  668. // {
  669. // return std::max(max_sqr_d(other->m_left),max_sqr_d(other->m_right));
  670. // }
  671. // };
  672. //// Potentially recurse on all pairs, if minimum distance is less than running
  673. //// bound
  674. //Eigen::Matrix<Scalar,Eigen::Dynamic,1> other_max_sqr_d =
  675. // Eigen::Matrix<Scalar,Eigen::Dynamic,1>::Constant(other_list.size(),1,min_sqr_d);
  676. for(size_t child = 0;child<other_list.size();child++)
  677. {
  678. auto other_tree = other_list[child];
  679. Eigen::Matrix<Scalar,Eigen::Dynamic,1> this_max_sqr_d(this_list.size(),1);
  680. for(size_t t = 0;t<this_list.size();t++)
  681. {
  682. const auto this_tree = this_list[t];
  683. this_max_sqr_d(t) = max_squared_distance(this_tree,other_tree);
  684. }
  685. if(this_list.size() ==2 &&
  686. ( this_max_sqr_d(0) > this_max_sqr_d(1))
  687. )
  688. {
  689. std::swap(this_list[0],this_list[1]);
  690. //std::swap(this_max_sqr_d(0),this_max_sqr_d(1));
  691. }
  692. const Scalar sqr_d = this_max_sqr_d.minCoeff();
  693. for(size_t t = 0;t<this_list.size();t++)
  694. {
  695. const auto this_tree = this_list[t];
  696. //const auto mm = max_sqr_d(other_tree);
  697. //const Scalar mc = other_max_sqr_d(child);
  698. //assert(mc == mm);
  699. // Only look left/right in this_list if can possible decrease somebody's
  700. // distance in this_tree.
  701. const Scalar min_this_other = min_squared_distance(this_tree,other_tree);
  702. if(
  703. min_this_other < sqr_d &&
  704. min_this_other < other_tree->m_max_sqr_d)
  705. {
  706. //cout<<"before: "<<other_max_sqr_d(child)<<endl;
  707. //other_max_sqr_d(child) = std::min(
  708. // other_max_sqr_d(child),
  709. // this_tree->squared_distance_helper(
  710. // V,Ele,other_tree,other_V,other_Ele,other_max_sqr_d(child),sqrD,I,C));
  711. //cout<<"after: "<<other_max_sqr_d(child)<<endl;
  712. this_tree->squared_distance_helper(
  713. V,Ele,other_tree,other_V,other_Ele,0,sqrD,I,C);
  714. }
  715. }
  716. }
  717. //const Scalar ret = other_max_sqr_d.maxCoeff();
  718. //const auto mm = max_sqr_d(other);
  719. //assert(mm == ret);
  720. //cout<<"non-leaf: "<<ret<<endl;
  721. //return ret;
  722. if(!other->is_leaf())
  723. {
  724. other->m_max_sqr_d = std::max(other->m_left->m_max_sqr_d,other->m_right->m_max_sqr_d);
  725. }
  726. return 0;
  727. #endif
  728. }
  729. template <typename DerivedV, int DIM>
  730. template <typename DerivedEle>
  731. IGL_INLINE void igl::AABB<DerivedV,DIM>::leaf_squared_distance(
  732. const Eigen::MatrixBase<DerivedV> & V,
  733. const Eigen::MatrixBase<DerivedEle> & Ele,
  734. const RowVectorDIMS & p,
  735. const Scalar max_sqr_d,
  736. Scalar & sqr_d,
  737. int & i,
  738. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  739. {
  740. using namespace Eigen;
  741. using namespace std;
  742. if(max_sqr_d > sqr_d)
  743. {
  744. sqr_d = max_sqr_d;
  745. return;
  746. }
  747. RowVectorDIMS c_candidate;
  748. Scalar sqr_d_candidate;
  749. igl::point_simplex_squared_distance<DIM>(
  750. p,V,Ele,m_primitive,sqr_d_candidate,c_candidate);
  751. set_min(p,sqr_d_candidate,m_primitive,c_candidate,sqr_d,i,c);
  752. }
  753. template <typename DerivedV, int DIM>
  754. template <typename DerivedEle>
  755. IGL_INLINE void igl::AABB<DerivedV,DIM>::leaf_squared_distance(
  756. const Eigen::MatrixBase<DerivedV> & V,
  757. const Eigen::MatrixBase<DerivedEle> & Ele,
  758. const RowVectorDIMS & p,
  759. Scalar & sqr_d,
  760. int & i,
  761. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  762. {
  763. return leaf_squared_distance(V,Ele,p,0,sqr_d,i,c);
  764. }
  765. template <typename DerivedV, int DIM>
  766. IGL_INLINE void igl::AABB<DerivedV,DIM>::set_min(
  767. const RowVectorDIMS &
  768. #ifndef NDEBUG
  769. p
  770. #endif
  771. ,
  772. const Scalar sqr_d_candidate,
  773. const int i_candidate,
  774. const RowVectorDIMS & c_candidate,
  775. Scalar & sqr_d,
  776. int & i,
  777. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  778. {
  779. #ifndef NDEBUG
  780. //std::cout<<matlab_format(c_candidate,"c_candidate")<<std::endl;
  781. const Scalar pc_norm = (p-c_candidate).squaredNorm();
  782. const Scalar diff = fabs(sqr_d_candidate - pc_norm);
  783. assert(diff<=1e-10 && "distance should match norm of difference");
  784. #endif
  785. if(sqr_d_candidate < sqr_d)
  786. {
  787. i = i_candidate;
  788. c = c_candidate;
  789. sqr_d = sqr_d_candidate;
  790. }
  791. }
  792. template <typename DerivedV, int DIM>
  793. template <typename DerivedEle>
  794. IGL_INLINE bool
  795. igl::AABB<DerivedV,DIM>::intersect_ray(
  796. const Eigen::MatrixBase<DerivedV> & V,
  797. const Eigen::MatrixBase<DerivedEle> & Ele,
  798. const RowVectorDIMS & origin,
  799. const RowVectorDIMS & dir,
  800. std::vector<igl::Hit> & hits) const
  801. {
  802. hits.clear();
  803. const Scalar t0 = 0;
  804. const Scalar t1 = std::numeric_limits<Scalar>::infinity();
  805. {
  806. Scalar _1,_2;
  807. if(!ray_box_intersect(origin,dir,m_box,t0,t1,_1,_2))
  808. {
  809. return false;
  810. }
  811. }
  812. if(this->is_leaf())
  813. {
  814. // Actually process elements
  815. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  816. // Cheesecake way of hitting element
  817. bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hits);
  818. // Since we only gave ray_mesh_intersect a single face, it will have set
  819. // any hits to id=0. Set these to this primitive's id
  820. for(auto & hit : hits)
  821. {
  822. hit.id = m_primitive;
  823. }
  824. return ret;
  825. }
  826. std::vector<igl::Hit> left_hits;
  827. std::vector<igl::Hit> right_hits;
  828. const bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,left_hits);
  829. const bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,right_hits);
  830. hits.insert(hits.end(),left_hits.begin(),left_hits.end());
  831. hits.insert(hits.end(),right_hits.begin(),right_hits.end());
  832. return left_ret || right_ret;
  833. }
  834. template <typename DerivedV, int DIM>
  835. template <typename DerivedEle>
  836. IGL_INLINE bool
  837. igl::AABB<DerivedV,DIM>::intersect_ray(
  838. const Eigen::MatrixBase<DerivedV> & V,
  839. const Eigen::MatrixBase<DerivedEle> & Ele,
  840. const RowVectorDIMS & origin,
  841. const RowVectorDIMS & dir,
  842. igl::Hit & hit) const
  843. {
  844. #if false
  845. // BFS
  846. std::queue<const AABB *> Q;
  847. // Or DFS
  848. //std::stack<const AABB *> Q;
  849. Q.push(this);
  850. bool any_hit = false;
  851. hit.t = std::numeric_limits<Scalar>::infinity();
  852. while(!Q.empty())
  853. {
  854. const AABB * tree = Q.front();
  855. //const AABB * tree = Q.top();
  856. Q.pop();
  857. {
  858. Scalar _1,_2;
  859. if(!ray_box_intersect(
  860. origin,dir,tree->m_box,Scalar(0),Scalar(hit.t),_1,_2))
  861. {
  862. continue;
  863. }
  864. }
  865. if(tree->is_leaf())
  866. {
  867. // Actually process elements
  868. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  869. igl::Hit leaf_hit;
  870. if(
  871. ray_mesh_intersect(origin,dir,V,Ele.row(tree->m_primitive),leaf_hit)&&
  872. leaf_hit.t < hit.t)
  873. {
  874. // correct the id
  875. leaf_hit.id = tree->m_primitive;
  876. hit = leaf_hit;
  877. }
  878. continue;
  879. }
  880. // Add children to queue
  881. Q.push(tree->m_left);
  882. Q.push(tree->m_right);
  883. }
  884. return any_hit;
  885. #else
  886. // DFS
  887. return intersect_ray(
  888. V,Ele,origin,dir,std::numeric_limits<Scalar>::infinity(),hit);
  889. #endif
  890. }
  891. template <typename DerivedV, int DIM>
  892. template <typename DerivedEle>
  893. IGL_INLINE bool
  894. igl::AABB<DerivedV,DIM>::intersect_ray(
  895. const Eigen::MatrixBase<DerivedV> & V,
  896. const Eigen::MatrixBase<DerivedEle> & Ele,
  897. const RowVectorDIMS & origin,
  898. const RowVectorDIMS & dir,
  899. const Scalar _min_t,
  900. igl::Hit & hit) const
  901. {
  902. //// Naive, slow
  903. //std::vector<igl::Hit> hits;
  904. //intersect_ray(V,Ele,origin,dir,hits);
  905. //if(hits.size() > 0)
  906. //{
  907. // hit = hits.front();
  908. // return true;
  909. //}else
  910. //{
  911. // return false;
  912. //}
  913. Scalar min_t = _min_t;
  914. const Scalar t0 = 0;
  915. {
  916. Scalar _1,_2;
  917. if(!ray_box_intersect(origin,dir,m_box,t0,min_t,_1,_2))
  918. {
  919. return false;
  920. }
  921. }
  922. if(this->is_leaf())
  923. {
  924. // Actually process elements
  925. assert((Ele.size() == 0 || Ele.cols() == 3) && "Elements should be triangles");
  926. // Cheesecake way of hitting element
  927. bool ret = ray_mesh_intersect(origin,dir,V,Ele.row(m_primitive),hit);
  928. hit.id = m_primitive;
  929. return ret;
  930. }
  931. // Doesn't seem like smartly choosing left before/after right makes a
  932. // differnce
  933. igl::Hit left_hit;
  934. igl::Hit right_hit;
  935. bool left_ret = m_left->intersect_ray(V,Ele,origin,dir,min_t,left_hit);
  936. if(left_ret && left_hit.t<min_t)
  937. {
  938. // It's scary that this line doesn't seem to matter....
  939. min_t = left_hit.t;
  940. hit = left_hit;
  941. left_ret = true;
  942. }else
  943. {
  944. left_ret = false;
  945. }
  946. bool right_ret = m_right->intersect_ray(V,Ele,origin,dir,min_t,right_hit);
  947. if(right_ret && right_hit.t<min_t)
  948. {
  949. min_t = right_hit.t;
  950. hit = right_hit;
  951. right_ret = true;
  952. }else
  953. {
  954. right_ret = false;
  955. }
  956. return left_ret || right_ret;
  957. }
  958. // This is a bullshit template because AABB annoyingly needs templates for bad
  959. // combinations of 3D V with DIM=2 AABB
  960. //
  961. // _Define_ as a no-op rather than monkeying around with the proper code above
  962. //
  963. // Meanwhile, GCC seems to have a bug. Let's see if GCC likes using explicit
  964. // namespace block instead. https://stackoverflow.com/a/25594681/148668
  965. namespace igl
  966. {
  967. template<>
  968. template<>
  969. IGL_INLINE float AABB<Eigen::Matrix<float, -1, 3, 1, -1, 3>, 2>::squared_distance(
  970. Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&,
  971. Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&,
  972. Eigen::Matrix<float, 1, 2, 1, 1, 2> const&,
  973. int&,
  974. Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 2, 1, 1, 2> >&) const { return -1;};
  975. }
  976. #ifdef IGL_STATIC_LIBRARY
  977. // Explicit template instantiation
  978. 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;
  979. // generated by autoexplicit.sh
  980. 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;
  981. // generated by autoexplicit.sh
  982. 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;
  983. // generated by autoexplicit.sh
  984. 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;
  985. // generated by autoexplicit.sh
  986. 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);
  987. // generated by autoexplicit.sh
  988. 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);
  989. // generated by autoexplicit.sh
  990. 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;
  991. // generated by autoexplicit.sh
  992. 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;
  993. // generated by autoexplicit.sh
  994. 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;
  995. // generated by autoexplicit.sh
  996. 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;
  997. // generated by autoexplicit.sh
  998. 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;
  999. // generated by autoexplicit.sh
  1000. 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;
  1001. // generated by autoexplicit.sh
  1002. 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;
  1003. // generated by autoexplicit.sh
  1004. 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;
  1005. // generated by autoexplicit.sh
  1006. 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;
  1007. // generated by autoexplicit.sh
  1008. 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&);
  1009. // generated by autoexplicit.sh
  1010. 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&);
  1011. // generated by autoexplicit.sh
  1012. 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&);
  1013. #endif