in_element.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. const int Qr = Q.rows();
  43. std::vector<Triplet<Scalar> > IJV;
  44. IJV.reserve(Qr);
  45. #pragma omp parallel for if (Qr>10000)
  46. for(int e = 0;e<Qr;e++)
  47. {
  48. // find all
  49. const auto R = aabb.find(V,Ele,Q.row(e).eval(),false);
  50. for(const auto r : R)
  51. {
  52. #pragma omp critical
  53. IJV.push_back(Triplet<Scalar>(e,r,1));
  54. }
  55. }
  56. I.resize(Qr,Ele.rows());
  57. I.setFromTriplets(IJV.begin(),IJV.end());
  58. }