in_element.cpp 1.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  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. const int Qr = Q.rows();
  12. I.setConstant(Qr,1,-1);
  13. #pragma omp parallel for
  14. for(int e = 0;e<Qr;e++)
  15. {
  16. // find all
  17. const auto R = aabb.find(V,Ele,Q.row(e),true);
  18. if(!R.empty())
  19. {
  20. I(e) = R[0];
  21. }
  22. }
  23. }
  24. IGL_INLINE void igl::in_element(
  25. const Eigen::MatrixXd & V,
  26. const Eigen::MatrixXi & Ele,
  27. const Eigen::MatrixXd & Q,
  28. const InElementAABB & aabb,
  29. Eigen::SparseMatrix<double> & I)
  30. {
  31. using namespace std;
  32. using namespace Eigen;
  33. using namespace igl;
  34. const int Qr = Q.rows();
  35. std::vector<Triplet<double> > IJV;
  36. IJV.reserve(Qr);
  37. #pragma omp parallel for
  38. for(int e = 0;e<Qr;e++)
  39. {
  40. // find all
  41. const auto R = aabb.find(V,Ele,Q.row(e),false);
  42. for(const auto r : R)
  43. {
  44. #pragma omp critical
  45. IJV.push_back(Triplet<double>(e,r,1));
  46. }
  47. }
  48. I.resize(Qr,Ele.rows());
  49. I.setFromTriplets(IJV.begin(),IJV.end());
  50. }