unproject_onto_mesh.h 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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. #ifndef IGL_EMBREE_UNPROJECT_ONTO_MESH_H
  9. #define IGL_EMBREE_UNPROJECT_ONTO_MESH_H
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include "Hit.h"
  14. namespace igl
  15. {
  16. namespace embree
  17. {
  18. // Forward define
  19. class EmbreeIntersector;
  20. // Unproject a screen location (using the given model, proj and viewport) to find
  21. // the first hit on a mesh.
  22. //
  23. // Inputs:
  24. // pos screen space coordinates
  25. // F #F by 3 face matrix
  26. // model model matrix
  27. // proj projection matrix
  28. // viewport vieweport vector
  29. // ei EmbreeIntersector containing (V,F)
  30. // Outputs:
  31. // fid id of the first face hit
  32. // bc barycentric coordinates of hit
  33. // Returns true if there is a hit
  34. IGL_INLINE bool unproject_onto_mesh(
  35. const Eigen::Vector2f& pos,
  36. const Eigen::MatrixXi& F,
  37. const Eigen::Matrix4f& model,
  38. const Eigen::Matrix4f& proj,
  39. const Eigen::Vector4f& viewport,
  40. const EmbreeIntersector & ei,
  41. int& fid,
  42. Eigen::Vector3f& bc);
  43. // Unproject a screen location (using the given model, proj and viewport) to find
  44. // the first face on the mesh and the closest vertex
  45. //
  46. // Inputs:
  47. // pos screen space coordinates
  48. // F #F by 3 face matrix
  49. // model model matrix
  50. // proj projection matrix
  51. // viewport vieweport vector
  52. // ei EmbreeIntersector containing (V,F)
  53. // Outputs:
  54. // fid id of the first face hit
  55. // vid vertex id of the closest vertex hit
  56. // Returns true if there is a hit
  57. IGL_INLINE bool unproject_onto_mesh(
  58. const Eigen::Vector2f& pos,
  59. const Eigen::MatrixXi& F,
  60. const Eigen::Matrix4f& model,
  61. const Eigen::Matrix4f& proj,
  62. const Eigen::Vector4f& viewport,
  63. const EmbreeIntersector & ei,
  64. int& fid,
  65. int& vid);
  66. }
  67. }
  68. #ifndef IGL_STATIC_LIBRARY
  69. # include "unproject_onto_mesh.cpp"
  70. #endif
  71. #endif