in_element.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354
  1. #include "in_element.h"
  2. template <typename DerivedV, typename DerivedQ, int DIM>
  3. IGL_INLINE void igl::in_element(
  4. const Eigen::PlainObjectBase<DerivedV> & V,
  5. const Eigen::MatrixXi & Ele,
  6. const Eigen::PlainObjectBase<DerivedQ> & Q,
  7. const AABB<DerivedV,DIM> & aabb,
  8. Eigen::VectorXi & I)
  9. {
  10. using namespace std;
  11. using namespace Eigen;
  12. const int Qr = Q.rows();
  13. I.setConstant(Qr,1,-1);
  14. #pragma omp parallel for if (Qr>10000)
  15. for(int e = 0;e<Qr;e++)
  16. {
  17. // find all
  18. const auto R = aabb.find(V,Ele,Q.row(e),true);
  19. if(!R.empty())
  20. {
  21. I(e) = R[0];
  22. }
  23. }
  24. }
  25. template <typename DerivedV, typename DerivedQ, int DIM, typename Scalar>
  26. IGL_INLINE void igl::in_element(
  27. const Eigen::PlainObjectBase<DerivedV> & V,
  28. const Eigen::MatrixXi & Ele,
  29. const Eigen::PlainObjectBase<DerivedQ> & Q,
  30. const AABB<DerivedV,DIM> & aabb,
  31. Eigen::SparseMatrix<Scalar> & I)
  32. {
  33. using namespace std;
  34. using namespace Eigen;
  35. using namespace igl;
  36. const int Qr = Q.rows();
  37. std::vector<Triplet<Scalar> > IJV;
  38. IJV.reserve(Qr);
  39. #pragma omp parallel for if (Qr>10000)
  40. for(int e = 0;e<Qr;e++)
  41. {
  42. // find all
  43. const auto R = aabb.find(V,Ele,Q.row(e),false);
  44. for(const auto r : R)
  45. {
  46. #pragma omp critical
  47. IJV.push_back(Triplet<Scalar>(e,r,1));
  48. }
  49. }
  50. I.resize(Qr,Ele.rows());
  51. I.setFromTriplets(IJV.begin(),IJV.end());
  52. }