unproject_in_mesh.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[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_in_mesh.h"
  9. #include "EmbreeIntersector.h"
  10. #include "../unproject_ray.h"
  11. #include "../unproject_in_mesh.h"
  12. #include <vector>
  13. template <typename Derivedobj>
  14. IGL_INLINE int igl::embree::unproject_in_mesh(
  15. const Eigen::Vector2f& pos,
  16. const Eigen::Matrix4f& model,
  17. const Eigen::Matrix4f& proj,
  18. const Eigen::Vector4f& viewport,
  19. const EmbreeIntersector & ei,
  20. Eigen::PlainObjectBase<Derivedobj> & obj,
  21. std::vector<igl::Hit<float> > & hits)
  22. {
  23. const auto & shoot_ray = [&ei](
  24. const Eigen::Vector3f& s,
  25. const Eigen::Vector3f& dir,
  26. std::vector<igl::Hit<float> > & hits)
  27. {
  28. int num_rays_shot;
  29. ei.intersectRay(s,dir,hits,num_rays_shot);
  30. };
  31. return igl::unproject_in_mesh(pos,model,proj,viewport,shoot_ray,obj,hits);
  32. }
  33. template <typename Derivedobj>
  34. IGL_INLINE int igl::embree::unproject_in_mesh(
  35. const Eigen::Vector2f& pos,
  36. const Eigen::Matrix4f& model,
  37. const Eigen::Matrix4f& proj,
  38. const Eigen::Vector4f& viewport,
  39. const EmbreeIntersector & ei,
  40. Eigen::PlainObjectBase<Derivedobj> & obj)
  41. {
  42. std::vector<igl::Hit<float> > hits;
  43. return unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
  44. }
  45. #ifdef IGL_STATIC_LIBRARY
  46. template int igl::embree::unproject_in_mesh<Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::Matrix<float, 2, 1, 0, 2, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, igl::embree::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, std::vector<igl::Hit<float>, std::allocator<igl::Hit<float>> >&);
  47. template int igl::embree::unproject_in_mesh<Eigen::Matrix<double, 1, 3, 1, 1, 3> >(Eigen::Matrix<float, 2, 1, 0, 2, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, igl::embree::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> >&, std::vector<igl::Hit<float>, std::allocator<igl::Hit<float>> >&);
  48. template int igl::embree::unproject_in_mesh<Eigen::Matrix<double, 3, 1, 0, 3, 1> >(Eigen::Matrix<float, 2, 1, 0, 2, 1> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 4, 0, 4, 4> const&, Eigen::Matrix<float, 4, 1, 0, 4, 1> const&, igl::embree::EmbreeIntersector const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 3, 1, 0, 3, 1> >&);
  49. #endif