AABB.cpp 42 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697989910010110210310410510610710810911011111211311411511611711811912012112212312412512612712812913013113213313413513613713813914014114214314414514614714814915015115215315415515615715815916016116216316416516616716816917017117217317417517617717817918018118218318418518618718818919019119219319419519619719819920020120220320420520620720820921021121221321421521621721821922022122222322422522622722822923023123223323423523623723823924024124224324424524624724824925025125225325425525625725825926026126226326426526626726826927027127227327427527627727827928028128228328428528628728828929029129229329429529629729829930030130230330430530630730830931031131231331431531631731831932032132232332432532632732832933033133233333433533633733833934034134234334434534634734834935035135235335435535635735835936036136236336436536636736836937037137237337437537637737837938038138238338438538638738838939039139239339439539639739839940040140240340440540640740840941041141241341441541641741841942042142242342442542642742842943043143243343443543643743843944044144244344444544644744844945045145245345445545645745845946046146246346446546646746846947047147247347447547647747847948048148248348448548648748848949049149249349449549649749849950050150250350450550650750850951051151251351451551651751851952052152252352452552652752852953053153253353453553653753853954054154254354454554654754854955055155255355455555655755855956056156256356456556656756856957057157257357457557657757857958058158258358458558658758858959059159259359459559659759859960060160260360460560660760860961061161261361461561661761861962062162262362462562662762862963063163263363463563663763863964064164264364464564664764864965065165265365465565665765865966066166266366466566666766866967067167267367467567667767867968068168268368468568668768868969069169269369469569669769869970070170270370470570670770870971071171271371471571671771871972072172272372472572672772872973073173273373473573673773873974074174274374474574674774874975075175275375475575675775875976076176276376476576676776876977077177277377477577677777877978078178278378478578678778878979079179279379479579679779879980080180280380480580680780880981081181281381481581681781881982082182282382482582682782882983083183283383483583683783883984084184284384484584684784884985085185285385485585685785885986086186286386486586686786886987087187287387487587687787887988088188288388488588688788888989089189289389489589689789889990090190290390490590690790890991091191291391491591691791891992092192292392492592692792892993093193293393493593693793893994094194294394494594694794894995095195295395495595695795895996096196296396496596696796896997097197297397497597697797897998098198298398498598698798898999099199299399499599699799899910001001100210031004100510061007100810091010101110121013101410151016101710181019102010211022102310241025102610271028102910301031103210331034103510361037103810391040104110421043104410451046104710481049105010511052105310541055105610571058105910601061106210631064106510661067
  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 "colon.h"
  12. #include "doublearea.h"
  13. #include "point_simplex_squared_distance.h"
  14. #include "project_to_line_segment.h"
  15. #include "sort.h"
  16. #include "volume.h"
  17. #include "ray_box_intersect.h"
  18. #include "ray_mesh_intersect.h"
  19. #include <iostream>
  20. #include <iomanip>
  21. #include <limits>
  22. #include <list>
  23. #include <queue>
  24. #include <stack>
  25. template <typename DerivedV, int DIM>
  26. template <typename DerivedEle, typename Derivedbb_mins, typename Derivedbb_maxs, typename Derivedelements>
  27. IGL_INLINE void igl::AABB<DerivedV,DIM>::init(
  28. const Eigen::MatrixBase<DerivedV> & V,
  29. const Eigen::MatrixBase<DerivedEle> & Ele,
  30. const Eigen::MatrixBase<Derivedbb_mins> & bb_mins,
  31. const Eigen::MatrixBase<Derivedbb_maxs> & bb_maxs,
  32. const Eigen::MatrixBase<Derivedelements> & elements,
  33. const int i)
  34. {
  35. using namespace std;
  36. using namespace Eigen;
  37. deinit();
  38. if(bb_mins.size() > 0)
  39. {
  40. assert(bb_mins.rows() == bb_maxs.rows() && "Serial tree arrays must match");
  41. assert(bb_mins.cols() == V.cols() && "Serial tree array dim must match V");
  42. assert(bb_mins.cols() == bb_maxs.cols() && "Serial tree arrays must match");
  43. assert(bb_mins.rows() == elements.rows() &&
  44. "Serial tree arrays must match");
  45. // construct from serialization
  46. m_box.extend(bb_mins.row(i).transpose());
  47. m_box.extend(bb_maxs.row(i).transpose());
  48. m_primitive = elements(i);
  49. // Not leaf then recurse
  50. if(m_primitive == -1)
  51. {
  52. m_left = new AABB();
  53. m_left->init( V,Ele,bb_mins,bb_maxs,elements,2*i+1);
  54. m_right = new AABB();
  55. m_right->init( V,Ele,bb_mins,bb_maxs,elements,2*i+2);
  56. //m_depth = std::max( m_left->m_depth, m_right->m_depth)+1;
  57. }
  58. }else
  59. {
  60. VectorXi allI = colon<int>(0,Ele.rows()-1);
  61. MatrixXDIMS BC;
  62. if(Ele.cols() == 1)
  63. {
  64. // points
  65. BC = V;
  66. }else
  67. {
  68. // Simplices
  69. barycenter(V,Ele,BC);
  70. }
  71. MatrixXi SI(BC.rows(),BC.cols());
  72. {
  73. MatrixXDIMS _;
  74. MatrixXi IS;
  75. igl::sort(BC,1,true,_,IS);
  76. // Need SI(i) to tell which place i would be sorted into
  77. const int dim = IS.cols();
  78. for(int i = 0;i<IS.rows();i++)
  79. {
  80. for(int d = 0;d<dim;d++)
  81. {
  82. SI(IS(i,d),d) = i;
  83. }
  84. }
  85. }
  86. init(V,Ele,SI,allI);
  87. }
  88. }
  89. template <typename DerivedV, int DIM>
  90. template <typename DerivedEle>
  91. void igl::AABB<DerivedV,DIM>::init(
  92. const Eigen::MatrixBase<DerivedV> & V,
  93. const Eigen::MatrixBase<DerivedEle> & 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. template <
  101. typename DerivedEle,
  102. typename DerivedSI,
  103. typename DerivedI>
  104. IGL_INLINE void igl::AABB<DerivedV,DIM>::init(
  105. const Eigen::MatrixBase<DerivedV> & V,
  106. const Eigen::MatrixBase<DerivedEle> & Ele,
  107. const Eigen::MatrixBase<DerivedSI> & SI,
  108. const Eigen::MatrixBase<DerivedI> & I)
  109. {
  110. using namespace Eigen;
  111. using namespace std;
  112. deinit();
  113. if(V.size() == 0 || Ele.size() == 0 || I.size() == 0)
  114. {
  115. return;
  116. }
  117. assert(DIM == V.cols() && "V.cols() should matched declared dimension");
  118. //const Scalar inf = numeric_limits<Scalar>::infinity();
  119. m_box = AlignedBox<Scalar,DIM>();
  120. // Compute bounding box
  121. for(int i = 0;i<I.rows();i++)
  122. {
  123. for(int c = 0;c<Ele.cols();c++)
  124. {
  125. m_box.extend(V.row(Ele(I(i),c)).transpose());
  126. m_box.extend(V.row(Ele(I(i),c)).transpose());
  127. }
  128. }
  129. switch(I.size())
  130. {
  131. case 0:
  132. {
  133. assert(false);
  134. }
  135. case 1:
  136. {
  137. m_primitive = I(0);
  138. break;
  139. }
  140. default:
  141. {
  142. // Compute longest direction
  143. int max_d = -1;
  144. m_box.diagonal().maxCoeff(&max_d);
  145. // Can't use median on BC directly because many may have same value,
  146. // but can use median on sorted BC indices
  147. VectorXi SIdI(I.rows());
  148. for(int i = 0;i<I.rows();i++)
  149. {
  150. SIdI(i) = SI(I(i),max_d);
  151. }
  152. // Pass by copy to avoid changing input
  153. const auto median = [](VectorXi A)->int
  154. {
  155. size_t n = (A.size()-1)/2;
  156. nth_element(A.data(),A.data()+n,A.data()+A.size());
  157. return A(n);
  158. };
  159. const int med = median(SIdI);
  160. VectorXi LI((I.rows()+1)/2),RI(I.rows()/2);
  161. assert(LI.rows()+RI.rows() == I.rows());
  162. // Distribute left and right
  163. {
  164. int li = 0;
  165. int ri = 0;
  166. for(int i = 0;i<I.rows();i++)
  167. {
  168. if(SIdI(i)<=med)
  169. {
  170. LI(li++) = I(i);
  171. }else
  172. {
  173. RI(ri++) = I(i);
  174. }
  175. }
  176. }
  177. //m_depth = 0;
  178. if(LI.rows()>0)
  179. {
  180. m_left = new AABB();
  181. m_left->init(V,Ele,SI,LI);
  182. //m_depth = std::max(m_depth, m_left->m_depth+1);
  183. }
  184. if(RI.rows()>0)
  185. {
  186. m_right = new AABB();
  187. m_right->init(V,Ele,SI,RI);
  188. //m_depth = std::max(m_depth, m_right->m_depth+1);
  189. }
  190. }
  191. }
  192. }
  193. template <typename DerivedV, int DIM>
  194. IGL_INLINE bool igl::AABB<DerivedV,DIM>::is_leaf() const
  195. {
  196. return m_primitive != -1;
  197. }
  198. template <typename DerivedV, int DIM>
  199. template <typename DerivedEle, typename Derivedq>
  200. IGL_INLINE std::vector<int> igl::AABB<DerivedV,DIM>::find(
  201. const Eigen::MatrixBase<DerivedV> & V,
  202. const Eigen::MatrixBase<DerivedEle> & Ele,
  203. const Eigen::MatrixBase<Derivedq> & q,
  204. const bool first) const
  205. {
  206. using namespace std;
  207. using namespace Eigen;
  208. assert(q.size() == DIM &&
  209. "Query dimension should match aabb dimension");
  210. assert(Ele.cols() == V.cols()+1 &&
  211. "AABB::find only makes sense for (d+1)-simplices");
  212. const Scalar epsilon = igl::EPS<Scalar>();
  213. // Check if outside bounding box
  214. bool inside = m_box.contains(q.transpose());
  215. if(!inside)
  216. {
  217. return std::vector<int>();
  218. }
  219. assert(m_primitive==-1 || (m_left == NULL && m_right == NULL));
  220. if(is_leaf())
  221. {
  222. // Initialize to some value > -epsilon
  223. Scalar a1=0,a2=0,a3=0,a4=0;
  224. switch(DIM)
  225. {
  226. case 3:
  227. {
  228. // Barycentric coordinates
  229. typedef Eigen::Matrix<Scalar,1,3> RowVector3S;
  230. const RowVector3S V1 = V.row(Ele(m_primitive,0));
  231. const RowVector3S V2 = V.row(Ele(m_primitive,1));
  232. const RowVector3S V3 = V.row(Ele(m_primitive,2));
  233. const RowVector3S V4 = V.row(Ele(m_primitive,3));
  234. a1 = volume_single(V2,V4,V3,(RowVector3S)q);
  235. a2 = volume_single(V1,V3,V4,(RowVector3S)q);
  236. a3 = volume_single(V1,V4,V2,(RowVector3S)q);
  237. a4 = volume_single(V1,V2,V3,(RowVector3S)q);
  238. break;
  239. }
  240. case 2:
  241. {
  242. // Barycentric coordinates
  243. typedef Eigen::Matrix<Scalar,2,1> Vector2S;
  244. const Vector2S V1 = V.row(Ele(m_primitive,0));
  245. const Vector2S V2 = V.row(Ele(m_primitive,1));
  246. const Vector2S V3 = V.row(Ele(m_primitive,2));
  247. // Hack for now to keep templates simple. If becomes bottleneck
  248. // consider using std::enable_if_t
  249. const Vector2S q2 = q.head(2);
  250. a1 = doublearea_single(V1,V2,q2);
  251. a2 = doublearea_single(V2,V3,q2);
  252. a3 = doublearea_single(V3,V1,q2);
  253. break;
  254. }
  255. default:assert(false);
  256. }
  257. // Normalization is important for correcting sign
  258. Scalar sum = a1+a2+a3+a4;
  259. a1 /= sum;
  260. a2 /= sum;
  261. a3 /= sum;
  262. a4 /= sum;
  263. if(
  264. a1>=-epsilon &&
  265. a2>=-epsilon &&
  266. a3>=-epsilon &&
  267. a4>=-epsilon)
  268. {
  269. return std::vector<int>(1,m_primitive);
  270. }else
  271. {
  272. return std::vector<int>();
  273. }
  274. }
  275. std::vector<int> left = m_left->find(V,Ele,q,first);
  276. if(first && !left.empty())
  277. {
  278. return left;
  279. }
  280. std::vector<int> right = m_right->find(V,Ele,q,first);
  281. if(first)
  282. {
  283. return right;
  284. }
  285. left.insert(left.end(),right.begin(),right.end());
  286. return left;
  287. }
  288. template <typename DerivedV, int DIM>
  289. IGL_INLINE int igl::AABB<DerivedV,DIM>::subtree_size() const
  290. {
  291. // 1 for self
  292. int n = 1;
  293. int n_left = 0,n_right = 0;
  294. if(m_left != NULL)
  295. {
  296. n_left = m_left->subtree_size();
  297. }
  298. if(m_right != NULL)
  299. {
  300. n_right = m_right->subtree_size();
  301. }
  302. n += 2*std::max(n_left,n_right);
  303. return n;
  304. }
  305. template <typename DerivedV, int DIM>
  306. template <typename Derivedbb_mins, typename Derivedbb_maxs, typename Derivedelements>
  307. IGL_INLINE void igl::AABB<DerivedV,DIM>::serialize(
  308. Eigen::PlainObjectBase<Derivedbb_mins> & bb_mins,
  309. Eigen::PlainObjectBase<Derivedbb_maxs> & bb_maxs,
  310. Eigen::PlainObjectBase<Derivedelements> & elements,
  311. const int i) const
  312. {
  313. using namespace std;
  314. using namespace Eigen;
  315. // Calling for root then resize output
  316. if(i==0)
  317. {
  318. const int m = subtree_size();
  319. //cout<<"m: "<<m<<endl;
  320. bb_mins.resize(m,DIM);
  321. bb_maxs.resize(m,DIM);
  322. elements.resize(m,1);
  323. }
  324. //cout<<i<<" ";
  325. bb_mins.row(i) = m_box.min();
  326. bb_maxs.row(i) = m_box.max();
  327. elements(i) = m_primitive;
  328. if(m_left != NULL)
  329. {
  330. m_left->serialize(bb_mins,bb_maxs,elements,2*i+1);
  331. }
  332. if(m_right != NULL)
  333. {
  334. m_right->serialize(bb_mins,bb_maxs,elements,2*i+2);
  335. }
  336. }
  337. template <typename DerivedV, int DIM>
  338. template <typename DerivedEle>
  339. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  340. igl::AABB<DerivedV,DIM>::squared_distance(
  341. const Eigen::MatrixBase<DerivedV> & V,
  342. const Eigen::MatrixBase<DerivedEle> & Ele,
  343. const RowVectorDIMS & p,
  344. int & i,
  345. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  346. {
  347. return squared_distance(V,Ele,p,std::numeric_limits<Scalar>::infinity(),i,c);
  348. }
  349. template <typename DerivedV, int DIM>
  350. template <typename DerivedEle>
  351. IGL_INLINE typename igl::AABB<DerivedV,DIM>::Scalar
  352. igl::AABB<DerivedV,DIM>::squared_distance(
  353. const Eigen::MatrixBase<DerivedV> & V,
  354. const Eigen::MatrixBase<DerivedEle> & Ele,
  355. const RowVectorDIMS & p,
  356. Scalar low_sqr_d,
  357. Scalar up_sqr_d,
  358. int & i,
  359. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  360. {
  361. using namespace Eigen;
  362. using namespace std;
  363. //assert(low_sqr_d <= up_sqr_d);
  364. if(low_sqr_d > up_sqr_d)
  365. {
  366. return low_sqr_d;
  367. }
  368. Scalar sqr_d = up_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,low_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,low_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,low_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_up_sqr_d =
  409. m_left->m_box.squaredExteriorDistance(p.transpose());
  410. Scalar right_up_sqr_d =
  411. m_right->m_box.squaredExteriorDistance(p.transpose());
  412. if(left_up_sqr_d < right_up_sqr_d)
  413. {
  414. if(!looked_left && left_up_sqr_d<sqr_d)
  415. {
  416. look_left();
  417. }
  418. if( !looked_right && right_up_sqr_d<sqr_d)
  419. {
  420. look_right();
  421. }
  422. }else
  423. {
  424. if( !looked_right && right_up_sqr_d<sqr_d)
  425. {
  426. look_right();
  427. }
  428. if(!looked_left && left_up_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 up_sqr_d,
  444. int & i,
  445. Eigen::PlainObjectBase<RowVectorDIMS> & c) const
  446. {
  447. return squared_distance(V,Ele,p,0.0,up_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 up_sqr_d = std::numeric_limits<double>::infinity();
  509. squared_distance_helper(
  510. V,Ele,&other,other_V,other_Ele,0,up_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 /*up_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_low_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_low_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_low_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_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_sqr_d);
  588. return 0;
  589. }
  590. // FORCE DOWN TO OTHER LEAF EVAL
  591. //if(min_squared_distance(this,other) < other->m_low_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_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_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. // > low_sqr_d = [&sqrD,&low_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(low_sqr_d(other->m_left),low_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_low_sqr_d =
  675. // Eigen::Matrix<Scalar,Eigen::Dynamic,1>::Constant(other_list.size(),1,up_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_low_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_low_sqr_d(t) = max_squared_distance(this_tree,other_tree);
  684. }
  685. if(this_list.size() ==2 &&
  686. ( this_low_sqr_d(0) > this_low_sqr_d(1))
  687. )
  688. {
  689. std::swap(this_list[0],this_list[1]);
  690. //std::swap(this_low_sqr_d(0),this_low_sqr_d(1));
  691. }
  692. const Scalar sqr_d = this_low_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 = low_sqr_d(other_tree);
  697. //const Scalar mc = other_low_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_low_sqr_d)
  705. {
  706. //cout<<"before: "<<other_low_sqr_d(child)<<endl;
  707. //other_low_sqr_d(child) = std::min(
  708. // other_low_sqr_d(child),
  709. // this_tree->squared_distance_helper(
  710. // V,Ele,other_tree,other_V,other_Ele,other_low_sqr_d(child),sqrD,I,C));
  711. //cout<<"after: "<<other_low_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_low_sqr_d.maxCoeff();
  718. //const auto mm = low_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_low_sqr_d = std::max(other->m_left->m_low_sqr_d,other->m_right->m_low_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 low_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(low_sqr_d > sqr_d)
  743. {
  744. sqr_d = low_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. //// This doesn't quite make sense to check with bounds
  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<> template<> IGL_INLINE float AABB<Eigen::Matrix<float, -1, 3, 1, -1, 3>, 2>::squared_distance( 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, 2, 1, 1, 2> const&, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 2, 1, 1, 2> >&) const { assert(false);return -1;};
  969. template<> template<> IGL_INLINE float igl::AABB<Eigen::Matrix<float, -1, 3, 1, -1, 3>, 2>::squared_distance( 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, 2, 1, 1, 2> const&, float, float, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 2, 1, 1, 2> >&) const { assert(false);return -1;};
  970. template<> template<> IGL_INLINE void igl::AABB<Eigen::Matrix<float, -1, 3, 1, -1, 3>, 2>::init (Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&) { assert(false);};
  971. template<> template<> IGL_INLINE double AABB<Eigen::Matrix<double, -1, 3, 1, -1, 3>, 2>::squared_distance( Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::Matrix<double, 1, 2, 1, 1, 2> const&, int&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> >&) const { assert(false);return -1;};
  972. template<> template<> IGL_INLINE double igl::AABB<Eigen::Matrix<double, -1, 3, 1, -1, 3>, 2>::squared_distance( Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::Matrix<double, 1, 2, 1, 1, 2> const&, double, double, int&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 2, 1, 1, 2> >&) const { assert(false);return -1;};
  973. template<> template<> IGL_INLINE void igl::AABB<Eigen::Matrix<double, -1, 3, 1, -1, 3>, 2>::init (Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&) { assert(false);};
  974. template<> template<> IGL_INLINE void igl::AABB<Eigen::Matrix<float, -1, 3, 0, -1, 3>, 2>::init(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&) {assert(false);};
  975. template<> template<> IGL_INLINE float igl::AABB<Eigen::Matrix<float, -1, 3, 0, -1, 3>, 2>::squared_distance(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::Matrix<float, 1, 2, 1, 1, 2> const&, float, float, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 2, 1, 1, 2> >&) const { assert(false);return -1;};
  976. }
  977. #ifdef IGL_STATIC_LIBRARY
  978. // Explicit template instantiation
  979. // generated by autoexplicit.sh
  980. // generated by autoexplicit.sh
  981. template float igl::AABB<Eigen::Matrix<float, -1, 3, 0, -1, 3>, 3>::squared_distance<Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::Matrix<float, 1, 3, 1, 1, 3> const&, float, float, int&, Eigen::PlainObjectBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> >&) const;
  982. // generated by autoexplicit.sh
  983. // generated by autoexplicit.sh
  984. template void igl::AABB<Eigen::Matrix<float, -1, 3, 0, -1, 3>, 3>::init<Eigen::Matrix<int, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&);
  985. // generated by autoexplicit.sh
  986. 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;
  987. // generated by autoexplicit.sh
  988. 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;
  989. // generated by autoexplicit.sh
  990. 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;
  991. // generated by autoexplicit.sh
  992. 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;
  993. // generated by autoexplicit.sh
  994. 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);
  995. // generated by autoexplicit.sh
  996. 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);
  997. // generated by autoexplicit.sh
  998. 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;
  999. // generated by autoexplicit.sh
  1000. 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;
  1001. // generated by autoexplicit.sh
  1002. 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;
  1003. // generated by autoexplicit.sh
  1004. 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;
  1005. // generated by autoexplicit.sh
  1006. 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;
  1007. // generated by autoexplicit.sh
  1008. 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;
  1009. // generated by autoexplicit.sh
  1010. 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;
  1011. // generated by autoexplicit.sh
  1012. 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;
  1013. // generated by autoexplicit.sh
  1014. 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;
  1015. // generated by autoexplicit.sh
  1016. 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&);
  1017. // generated by autoexplicit.sh
  1018. 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&);
  1019. // generated by autoexplicit.sh
  1020. 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&);
  1021. 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&, double, int&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&) const;
  1022. #endif