unproject_in_mesh.h 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103
  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. #ifndef IGL_UNPROJECT_IN_MESH
  9. #define IGL_UNPROJECT_IN_MESH
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Core>
  12. #include <vector>
  13. #include "Hit.h"
  14. namespace igl
  15. {
  16. // Forward define
  17. class EmbreeIntersector;
  18. #ifndef IGL_OPENGL_4
  19. // Unproject a screen location (using current opengl viewport, projection, and
  20. // model view) to a 3D position
  21. //
  22. // Inputs:
  23. // x x-coordinate of mouse location
  24. // y y-coordinate of mouse location
  25. // ei EmbreeIntersector containing (V,F)
  26. // Outputs:
  27. // obj 3d unprojected mouse point in mesh
  28. // Returns number of hits
  29. //
  30. template <
  31. typename Derivedobj>
  32. IGL_INLINE int unproject_in_mesh(
  33. const int x,
  34. const int y,
  35. const igl::EmbreeIntersector & ei,
  36. Eigen::PlainObjectBase<Derivedobj> & obj);
  37. template <
  38. typename Derivedobj>
  39. IGL_INLINE int unproject_in_mesh(
  40. const int x,
  41. const int y,
  42. const igl::EmbreeIntersector & ei,
  43. Eigen::PlainObjectBase<Derivedobj> & obj,
  44. std::vector<igl::Hit > & hits);
  45. #endif
  46. // Unproject a screen location (using the given model, proj and viewewport) to a 3D position
  47. // and a set of hits
  48. //
  49. // Inputs:
  50. // pos screen space coordinates
  51. // model model matrix
  52. // proj projection matrix
  53. // viewport vieweport vector
  54. // ei EmbreeIntersector containing (V,F)
  55. // Outputs:
  56. // obj 3d unprojected mouse point in mesh
  57. // hits vector of embree hits
  58. // Returns number of hits
  59. template <
  60. typename Derivedobj>
  61. IGL_INLINE int unproject_in_mesh(
  62. const Eigen::Vector2f& pos,
  63. const Eigen::Matrix4f& model,
  64. const Eigen::Matrix4f& proj,
  65. const Eigen::Vector4f& viewport,
  66. const igl::EmbreeIntersector & ei,
  67. Eigen::PlainObjectBase<Derivedobj> & obj,
  68. std::vector<igl::Hit > & hits);
  69. // Unproject a screen location (using the given model, proj and viewewport) to a 3D position
  70. // and a set of hits
  71. //
  72. // Inputs:
  73. // pos screen space coordinates
  74. // F #F by 3 face matrix
  75. // model model matrix
  76. // proj projection matrix
  77. // viewport vieweport vector
  78. // ei EmbreeIntersector containing (V,F)
  79. // Outputs:
  80. // fid id of the first face hit
  81. // vid vertex id of the closest vertex hit
  82. // Returns true if there is a hit
  83. IGL_INLINE bool unproject_in_mesh(
  84. const Eigen::Vector2f& pos,
  85. const Eigen::MatrixXi& F,
  86. const Eigen::Matrix4f& model,
  87. const Eigen::Matrix4f& proj,
  88. const Eigen::Vector4f& viewport,
  89. const igl::EmbreeIntersector & ei,
  90. int& fid,
  91. int& vid);
  92. }
  93. #ifndef IGL_STATIC_LIBRARY
  94. # include "unproject_in_mesh.cpp"
  95. #endif
  96. #endif