unproject_in_mesh.cpp 2.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <alecjacobson@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_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 > & hits)
  22. {
  23. using namespace std;
  24. using namespace Eigen;
  25. const auto & shoot_ray = [&ei](
  26. const Eigen::Vector3f& s,
  27. const Eigen::Vector3f& dir,
  28. std::vector<igl::Hit> & hits)
  29. {
  30. int num_rays_shot;
  31. ei.intersectRay(s,dir,hits,num_rays_shot);
  32. };
  33. return igl::unproject_in_mesh(pos,model,proj,viewport,shoot_ray,obj,hits);
  34. }
  35. template <typename Derivedobj>
  36. IGL_INLINE int igl::embree::unproject_in_mesh(
  37. const Eigen::Vector2f& pos,
  38. const Eigen::Matrix4f& model,
  39. const Eigen::Matrix4f& proj,
  40. const Eigen::Vector4f& viewport,
  41. const EmbreeIntersector & ei,
  42. Eigen::PlainObjectBase<Derivedobj> & obj)
  43. {
  44. std::vector<igl::Hit> hits;
  45. return unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
  46. }
  47. #ifdef IGL_STATIC_LIBRARY
  48. 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, std::allocator<igl::Hit> >&);
  49. 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, std::allocator<igl::Hit> >&);
  50. 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> >&);
  51. #endif