ambient_occlusion.cpp 3.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #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::PlainObjectBase<DerivedP> & P,
  19. const Eigen::PlainObjectBase<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 hit;
  28. const float tnear = 1e-4f;
  29. return ei.intersectRay(s,dir,hit,tnear);
  30. };
  31. return igl::ambient_occlusion(shoot_ray,P,N,num_samples,S);
  32. }
  33. template <
  34. typename DerivedV,
  35. typename DerivedF,
  36. typename DerivedP,
  37. typename DerivedN,
  38. typename DerivedS >
  39. IGL_INLINE void igl::embree::ambient_occlusion(
  40. const Eigen::PlainObjectBase<DerivedV> & V,
  41. const Eigen::PlainObjectBase<DerivedF> & F,
  42. const Eigen::PlainObjectBase<DerivedP> & P,
  43. const Eigen::PlainObjectBase<DerivedN> & N,
  44. const int num_samples,
  45. Eigen::PlainObjectBase<DerivedS> & S)
  46. {
  47. using namespace igl;
  48. using namespace Eigen;
  49. EmbreeIntersector ei;
  50. ei.init(V.template cast<float>(),F.template cast<int>());
  51. ambient_occlusion(ei,P,N,num_samples,S);
  52. }
  53. #ifdef IGL_STATIC_LIBRARY
  54. // Explicit template specialization
  55. 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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  56. 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::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  57. 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::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<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, 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::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&, int, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  59. #endif