unproject_onto_mesh.cpp 1.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Daniele Panozzo <daniele.panozzo@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 "unproject_onto_mesh.h"
  9. #include "EmbreeIntersector.h"
  10. #include "../unproject_onto_mesh.h"
  11. #include <vector>
  12. IGL_INLINE bool igl::embree::unproject_onto_mesh(
  13. const Eigen::Vector2f& pos,
  14. const Eigen::MatrixXi& F,
  15. const Eigen::Matrix4f& model,
  16. const Eigen::Matrix4f& proj,
  17. const Eigen::Vector4f& viewport,
  18. const EmbreeIntersector & ei,
  19. int& fid,
  20. Eigen::Vector3f& bc)
  21. {
  22. using namespace std;
  23. using namespace Eigen;
  24. const auto & shoot_ray = [&ei](
  25. const Eigen::Vector3f& s,
  26. const Eigen::Vector3f& dir,
  27. igl::Hit & hit)->bool
  28. {
  29. return ei.intersectRay(s,dir,hit);
  30. };
  31. return igl::unproject_onto_mesh(pos,model,proj,viewport,shoot_ray,fid,bc);
  32. }
  33. IGL_INLINE bool igl::embree::unproject_onto_mesh(
  34. const Eigen::Vector2f& pos,
  35. const Eigen::MatrixXi& F,
  36. const Eigen::Matrix4f& model,
  37. const Eigen::Matrix4f& proj,
  38. const Eigen::Vector4f& viewport,
  39. const EmbreeIntersector & ei,
  40. int& fid,
  41. int& vid)
  42. {
  43. Eigen::Vector3f bc;
  44. if(!igl::embree::unproject_onto_mesh(pos,F,model,proj,viewport,ei,fid,bc))
  45. {
  46. return false;
  47. }
  48. int i;
  49. bc.maxCoeff(&i);
  50. vid = F(fid,i);
  51. return true;
  52. }
  53. #ifdef IGL_STATIC_LIBRARY
  54. // Explicit template specialization
  55. #endif