ambient_occlusion.cpp 4.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #include "ambient_occlusion.h"
  9. #include "../ambient_occlusion.h"
  10. #include "EmbreeIntersector.h"
  11. #include "../Hit.h"
  12. template <
  13. typename DerivedP,
  14. typename DerivedN,
  15. typename DerivedS >
  16. IGL_INLINE void igl::embree::ambient_occlusion(
  17. const igl::embree::EmbreeIntersector & ei,
  18. const Eigen::MatrixBase<DerivedP> & P,
  19. const Eigen::MatrixBase<DerivedN> & N,
  20. const int num_samples,
  21. Eigen::PlainObjectBase<DerivedS> & S)
  22. {
  23. const auto & shoot_ray = [&ei](
  24. const Eigen::Vector3f& s,
  25. const Eigen::Vector3f& dir)->bool
  26. {
  27. igl::Hit<float> hit;
  28. const float tnear = 1e-4f;
  29. return ei.intersectRay(s,dir,hit,tnear);
  30. };
  31. const auto Pf = P.template cast<float>().eval();
  32. const auto Nf = N.template cast<float>().eval();
  33. Eigen::Matrix<float,Eigen::Dynamic,1> Sf;
  34. igl::ambient_occlusion(shoot_ray,Pf,Nf,num_samples,Sf);
  35. S = Sf.template cast<typename DerivedS::Scalar>();
  36. }
  37. template <
  38. typename DerivedV,
  39. typename DerivedF,
  40. typename DerivedP,
  41. typename DerivedN,
  42. typename DerivedS >
  43. IGL_INLINE void igl::embree::ambient_occlusion(
  44. const Eigen::MatrixBase<DerivedV> & V,
  45. const Eigen::MatrixBase<DerivedF> & F,
  46. const Eigen::MatrixBase<DerivedP> & P,
  47. const Eigen::MatrixBase<DerivedN> & N,
  48. const int num_samples,
  49. Eigen::PlainObjectBase<DerivedS> & S)
  50. {
  51. EmbreeIntersector ei;
  52. ei.init(V.template cast<float>(),F.template cast<int>());
  53. ambient_occlusion(ei,P,N,num_samples,S);
  54. }
  55. #ifdef IGL_STATIC_LIBRARY
  56. // Explicit template instantiation
  57. template void igl::embree::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(igl::embree::EmbreeIntersector const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  58. template void igl::embree::ambient_occlusion<Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(igl::embree::EmbreeIntersector const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  59. template void igl::embree::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  60. template void igl::embree::ambient_occlusion<Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 3, 0, -1, 3>, Eigen::Matrix<double, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  61. template void igl::embree::ambient_occlusion<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  62. #endif