shape_diameter_function.cpp 4.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  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 "shape_diameter_function.h"
  9. #include "../shape_diameter_function.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::shape_diameter_function(
  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)->float
  26. {
  27. igl::Hit<float> hit;
  28. const float tnear = 1e-4f;
  29. if(ei.intersectRay(s,dir,hit,tnear))
  30. {
  31. return hit.t;
  32. }else
  33. {
  34. return std::numeric_limits<double>::infinity();
  35. }
  36. };
  37. const auto Pf = P.template cast<float>().eval();
  38. const auto Nf = N.template cast<float>().eval();
  39. Eigen::Matrix<float,Eigen::Dynamic,1> Sf;
  40. igl::shape_diameter_function(shoot_ray,Pf,Nf,num_samples,Sf);
  41. S = Sf.template cast<typename DerivedS::Scalar>();
  42. }
  43. template <
  44. typename DerivedV,
  45. typename DerivedF,
  46. typename DerivedP,
  47. typename DerivedN,
  48. typename DerivedS >
  49. IGL_INLINE void igl::embree::shape_diameter_function(
  50. const Eigen::MatrixBase<DerivedV> & V,
  51. const Eigen::MatrixBase<DerivedF> & F,
  52. const Eigen::MatrixBase<DerivedP> & P,
  53. const Eigen::MatrixBase<DerivedN> & N,
  54. const int num_samples,
  55. Eigen::PlainObjectBase<DerivedS> & S)
  56. {
  57. EmbreeIntersector ei;
  58. ei.init(V.template cast<float>(),F.template cast<int>());
  59. shape_diameter_function(ei,P,N,num_samples,S);
  60. }
  61. #ifdef IGL_STATIC_LIBRARY
  62. // Explicit template instantiation
  63. template void igl::embree::shape_diameter_function<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> >&);
  64. template void igl::embree::shape_diameter_function<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> >&);
  65. template void igl::embree::shape_diameter_function<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> >&);
  66. template void igl::embree::shape_diameter_function<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> >&);
  67. template void igl::embree::shape_diameter_function<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> >&);
  68. #endif