ambient_occlusion.h 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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_AMBIENT_OCCLUSION_H
  9. #define IGL_AMBIENT_OCCLUSION_H
  10. #include "igl_inline.h"
  11. #include "AABB.h"
  12. #include <Eigen/Core>
  13. #include <functional>
  14. namespace igl
  15. {
  16. /// Compute ambient occlusion per given point using ray-mesh intersection
  17. /// function handle.
  18. ///
  19. /// @param[in] shoot_ray function handle that outputs hits of a given ray against a
  20. /// mesh (embedded in function handles as captured variable/data)
  21. /// @param[in] P #P by 3 list of origin points
  22. /// @param[in] N #P by 3 list of origin normals
  23. /// @param[in] num_samples number of samples to use (e.g., 1000)
  24. /// @param[out] S #P list of ambient occlusion values between 1 (fully occluded) and
  25. /// 0 (not occluded)
  26. ///
  27. template <
  28. typename DerivedP,
  29. typename DerivedN,
  30. typename DerivedS >
  31. IGL_INLINE void ambient_occlusion(
  32. const std::function<
  33. bool(
  34. const Eigen::Matrix<typename DerivedP::Scalar,3,1>&,
  35. const Eigen::Matrix<typename DerivedP::Scalar,3,1>&)
  36. > & shoot_ray,
  37. const Eigen::MatrixBase<DerivedP> & P,
  38. const Eigen::MatrixBase<DerivedN> & N,
  39. const int num_samples,
  40. Eigen::PlainObjectBase<DerivedS> & S);
  41. /// Compute ambient occlusion per given point for mesh (V,F) with precomputed
  42. /// AABB tree.
  43. ///
  44. // @param[in] AABB axis-aligned bounding box hierarchy around (V,F)
  45. /// @param[in] V #V by 3 list of mesh vertex positions
  46. /// @param[in] F #F by 3 list of mesh face indices into V
  47. /// @param[in] P #P by 3 list of origin points
  48. /// @param[in] N #P by 3 list of origin normals
  49. /// @param[in] num_samples number of samples to use (e.g., 1000)
  50. /// @param[out] S #P list of ambient occlusion values between 1 (fully occluded) and
  51. /// 0 (not occluded)
  52. ///
  53. template <
  54. typename DerivedV,
  55. int DIM,
  56. typename DerivedF,
  57. typename DerivedP,
  58. typename DerivedN,
  59. typename DerivedS >
  60. IGL_INLINE void ambient_occlusion(
  61. const igl::AABB<DerivedV,DIM> & aabb,
  62. const Eigen::MatrixBase<DerivedV> & V,
  63. const Eigen::MatrixBase<DerivedF> & F,
  64. const Eigen::MatrixBase<DerivedP> & P,
  65. const Eigen::MatrixBase<DerivedN> & N,
  66. const int num_samples,
  67. Eigen::PlainObjectBase<DerivedS> & S);
  68. /// Compute ambient occlusion per given point for mesh (V,F)
  69. ///
  70. /// @param[in] V #V by 3 list of mesh vertex positions
  71. /// @param[in] F #F by 3 list of mesh face indices into V
  72. /// @param[in] P #P by 3 list of origin points
  73. /// @param[in] N #P by 3 list of origin normals
  74. /// @param[in] num_samples number of samples to use (e.g., 1000)
  75. /// @param[out] S #P list of ambient occlusion values between 1 (fully occluded) and
  76. /// 0 (not occluded)
  77. template <
  78. typename DerivedV,
  79. typename DerivedF,
  80. typename DerivedP,
  81. typename DerivedN,
  82. typename DerivedS >
  83. IGL_INLINE void ambient_occlusion(
  84. const Eigen::MatrixBase<DerivedV> & V,
  85. const Eigen::MatrixBase<DerivedF> & F,
  86. const Eigen::MatrixBase<DerivedP> & P,
  87. const Eigen::MatrixBase<DerivedN> & N,
  88. const int num_samples,
  89. Eigen::PlainObjectBase<DerivedS> & S);
  90. };
  91. #ifndef IGL_STATIC_LIBRARY
  92. # include "ambient_occlusion.cpp"
  93. #endif
  94. #endif