unproject_onto_mesh.cpp 1.5 KB

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