in_element.cpp 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. #include "in_element.h"
  2. IGL_INLINE void igl::in_element(
  3. const Eigen::MatrixXd & V,
  4. const Eigen::MatrixXi & Ele,
  5. const Eigen::MatrixXd & Q,
  6. const InElementAABB & aabb,
  7. Eigen::VectorXi & I)
  8. {
  9. using namespace std;
  10. using namespace Eigen;
  11. using namespace igl;
  12. const int Qr = Q.rows();
  13. I.setConstant(Qr,1,-1);
  14. #pragma omp parallel for
  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. IGL_INLINE void igl::in_element(
  26. const Eigen::MatrixXd & V,
  27. const Eigen::MatrixXi & Ele,
  28. const Eigen::MatrixXd & Q,
  29. const InElementAABB & aabb,
  30. Eigen::SparseMatrix<double> & I)
  31. {
  32. using namespace std;
  33. using namespace Eigen;
  34. using namespace igl;
  35. const int Qr = Q.rows();
  36. std::vector<Triplet<double> > IJV;
  37. IJV.reserve(Qr);
  38. #pragma omp parallel for
  39. for(int e = 0;e<Qr;e++)
  40. {
  41. // find all
  42. const auto R = aabb.find(V,Ele,Q.row(e),false);
  43. for(const auto r : R)
  44. {
  45. #pragma omp critical
  46. IJV.push_back(Triplet<double>(e,r,1));
  47. }
  48. }
  49. I.resize(Qr,Ele.rows());
  50. I.setFromTriplets(IJV.begin(),IJV.end());
  51. }