ray_box_intersect.h 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_BOX_INTERSECT_H
  9. #define IGL_RAY_BOX_INTERSECT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Geometry>
  13. namespace igl
  14. {
  15. /// Determine whether a ray origin+t*dir and box intersect within the ray's parameterized
  16. /// range (t0,t1)
  17. ///
  18. /// @param[in] source 3-vector origin of ray
  19. /// @param[in] dir 3-vector direction of ray
  20. /// @param[in] box axis aligned box
  21. /// @param[in] t0 hit only if hit.t less than t0
  22. /// @param[in] t1 hit only if hit.t greater than t1
  23. /// @param[out] tmin minimum of interval of overlap within [t0,t1]
  24. /// @param[out] tmax maximum of interval of overlap within [t0,t1]
  25. /// @return true if hit
  26. template <
  27. typename Derivedsource,
  28. typename Deriveddir,
  29. typename Scalar>
  30. IGL_INLINE bool ray_box_intersect(
  31. const Eigen::MatrixBase<Derivedsource> & source,
  32. const Eigen::MatrixBase<Deriveddir> & dir,
  33. const Eigen::AlignedBox<Scalar,3> & box,
  34. const Scalar & t0,
  35. const Scalar & t1,
  36. Scalar & tmin,
  37. Scalar & tmax);
  38. /// \overload
  39. /// \brief same with direction inverse precomputed
  40. template <
  41. typename Derivedsource,
  42. typename Deriveddir,
  43. typename Scalar>
  44. IGL_INLINE bool ray_box_intersect(
  45. const Eigen::MatrixBase<Derivedsource> & source,
  46. const Eigen::MatrixBase<Deriveddir> & inv_dir,
  47. const Eigen::MatrixBase<Deriveddir> & inv_dir_pad,
  48. const Eigen::AlignedBox<Scalar,3> & box,
  49. const Scalar & t0,
  50. const Scalar & t1,
  51. Scalar & tmin,
  52. Scalar & tmax);
  53. }
  54. #ifndef IGL_STATIC_LIBRARY
  55. # include "ray_box_intersect.cpp"
  56. #endif
  57. #endif