ray_mesh_intersect.h 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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. #ifndef IGL_RAY_MESH_INTERSECT_H
  9. #define IGL_RAY_MESH_INTERSECT_H
  10. #include "igl_inline.h"
  11. #include "Hit.h"
  12. #include <Eigen/Core>
  13. #include <vector>
  14. namespace igl
  15. {
  16. /// Shoot a ray against a mesh (V,F) and collect all hits. If you have many
  17. /// rays, consider using AABB.h
  18. ///
  19. /// @param[in] source 3-vector origin of ray
  20. /// @param[in] dir 3-vector direction of ray
  21. /// @param[in] V #V by 3 list of mesh vertex positions
  22. /// @param[in] F #F by 3 list of mesh face indices into V
  23. /// @param[out] hits **sorted** list of hits
  24. /// @return true if there were any hits (hits.size() > 0)
  25. ///
  26. /// \see AABB
  27. template <
  28. typename Derivedsource,
  29. typename Deriveddir,
  30. typename DerivedV,
  31. typename DerivedF>
  32. IGL_INLINE bool ray_mesh_intersect(
  33. const Eigen::MatrixBase<Derivedsource> & source,
  34. const Eigen::MatrixBase<Deriveddir> & dir,
  35. const Eigen::MatrixBase<DerivedV> & V,
  36. const Eigen::MatrixBase<DerivedF> & F,
  37. std::vector<igl::Hit> & hits);
  38. /// \overload
  39. /// @param[in] hit first hit, set only if it exists
  40. template <
  41. typename Derivedsource,
  42. typename Deriveddir,
  43. typename DerivedV,
  44. typename DerivedF>
  45. IGL_INLINE bool ray_mesh_intersect(
  46. const Eigen::MatrixBase<Derivedsource> & source,
  47. const Eigen::MatrixBase<Deriveddir> & dir,
  48. const Eigen::MatrixBase<DerivedV> & V,
  49. const Eigen::MatrixBase<DerivedF> & F,
  50. igl::Hit & hit);
  51. // Explicit function to check one triangle (given by index f) of the mesh.
  52. // This function is used by ray_mesh_intersect to check each triangle.
  53. // Outputs:
  54. // hit hit with the given triangle, set only if it exists
  55. // Returns true if there was a hit
  56. template <
  57. typename Derivedsource,
  58. typename Deriveddir,
  59. typename DerivedV,
  60. typename DerivedF>
  61. IGL_INLINE bool ray_triangle_intersect(
  62. const Eigen::MatrixBase<Derivedsource> & source,
  63. const Eigen::MatrixBase<Deriveddir> & dir,
  64. const Eigen::MatrixBase<DerivedV> & V,
  65. const Eigen::MatrixBase<DerivedF> & F,
  66. const int f,
  67. igl::Hit& hit);
  68. }
  69. #ifndef IGL_STATIC_LIBRARY
  70. # include "ray_mesh_intersect.cpp"
  71. #endif
  72. #endif