unproject_in_mesh.cpp 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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 igl;
  24. using namespace std;
  25. using namespace Eigen;
  26. const auto & shoot_ray = [&ei](
  27. const Eigen::Vector3f& s,
  28. const Eigen::Vector3f& dir,
  29. std::vector<igl::Hit> & hits)
  30. {
  31. int num_rays_shot;
  32. ei.intersectRay(s,dir,hits,num_rays_shot);
  33. };
  34. return igl::unproject_in_mesh(pos,model,proj,viewport,shoot_ray,obj,hits);
  35. }
  36. template <typename Derivedobj>
  37. IGL_INLINE int igl::embree::unproject_in_mesh(
  38. const Eigen::Vector2f& pos,
  39. const Eigen::Matrix4f& model,
  40. const Eigen::Matrix4f& proj,
  41. const Eigen::Vector4f& viewport,
  42. const EmbreeIntersector & ei,
  43. Eigen::PlainObjectBase<Derivedobj> & obj)
  44. {
  45. std::vector<igl::Hit> hits;
  46. return unproject_in_mesh(pos,model,proj,viewport,ei,obj,hits);
  47. }
  48. #ifdef IGL_STATIC_LIBRARY
  49. 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> >&);
  50. 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> >&);
  51. 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> >&);
  52. #endif