in_element.cpp 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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 "in_element.h"
  9. template <typename DerivedV, typename DerivedQ, int DIM>
  10. IGL_INLINE void igl::in_element(
  11. const Eigen::PlainObjectBase<DerivedV> & V,
  12. const Eigen::MatrixXi & Ele,
  13. const Eigen::PlainObjectBase<DerivedQ> & Q,
  14. const AABB<DerivedV,DIM> & aabb,
  15. Eigen::VectorXi & I)
  16. {
  17. using namespace std;
  18. using namespace Eigen;
  19. const int Qr = Q.rows();
  20. I.setConstant(Qr,1,-1);
  21. #pragma omp parallel for if (Qr>10000)
  22. for(int e = 0;e<Qr;e++)
  23. {
  24. // find all
  25. const auto R = aabb.find(V,Ele,Q.row(e).eval(),true);
  26. if(!R.empty())
  27. {
  28. I(e) = R[0];
  29. }
  30. }
  31. }
  32. template <typename DerivedV, typename DerivedQ, int DIM, typename Scalar>
  33. IGL_INLINE void igl::in_element(
  34. const Eigen::PlainObjectBase<DerivedV> & V,
  35. const Eigen::MatrixXi & Ele,
  36. const Eigen::PlainObjectBase<DerivedQ> & Q,
  37. const AABB<DerivedV,DIM> & aabb,
  38. Eigen::SparseMatrix<Scalar> & I)
  39. {
  40. using namespace std;
  41. using namespace Eigen;
  42. using namespace igl;
  43. const int Qr = Q.rows();
  44. std::vector<Triplet<Scalar> > IJV;
  45. IJV.reserve(Qr);
  46. #pragma omp parallel for if (Qr>10000)
  47. for(int e = 0;e<Qr;e++)
  48. {
  49. // find all
  50. const auto R = aabb.find(V,Ele,Q.row(e).eval(),false);
  51. for(const auto r : R)
  52. {
  53. #pragma omp critical
  54. IJV.push_back(Triplet<Scalar>(e,r,1));
  55. }
  56. }
  57. I.resize(Qr,Ele.rows());
  58. I.setFromTriplets(IJV.begin(),IJV.end());
  59. }