ray_mesh_intersect.h 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 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_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.
  17. //
  18. // Inputs:
  19. // source 3-vector origin of ray
  20. // dir 3-vector direction of ray
  21. // V #V by 3 list of mesh vertex positions
  22. // F #F by 3 list of mesh face indices into V
  23. // Outputs:
  24. // hits **sorted** list of hits
  25. // Returns true if there were any hits (hits.size() > 0)
  26. //
  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. // Outputs:
  39. // hit first hit, set only if it exists
  40. // Returns true if there was a hit
  41. template <
  42. typename Derivedsource,
  43. typename Deriveddir,
  44. typename DerivedV,
  45. typename DerivedF>
  46. IGL_INLINE bool ray_mesh_intersect(
  47. const Eigen::MatrixBase<Derivedsource> & source,
  48. const Eigen::MatrixBase<Deriveddir> & dir,
  49. const Eigen::MatrixBase<DerivedV> & V,
  50. const Eigen::MatrixBase<DerivedF> & F,
  51. igl::Hit & hit);
  52. }
  53. #ifndef IGL_STATIC_LIBRARY
  54. # include "ray_mesh_intersect.cpp"
  55. #endif
  56. #endif