shape_diameter_function.cpp 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869
  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 "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::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)->double
  26. {
  27. igl::Hit 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. return igl::shape_diameter_function(shoot_ray,P,N,num_samples,S);
  38. }
  39. template <
  40. typename DerivedV,
  41. typename DerivedF,
  42. typename DerivedP,
  43. typename DerivedN,
  44. typename DerivedS >
  45. IGL_INLINE void igl::embree::shape_diameter_function(
  46. const Eigen::PlainObjectBase<DerivedV> & V,
  47. const Eigen::PlainObjectBase<DerivedF> & F,
  48. const Eigen::PlainObjectBase<DerivedP> & P,
  49. const Eigen::PlainObjectBase<DerivedN> & N,
  50. const int num_samples,
  51. Eigen::PlainObjectBase<DerivedS> & S)
  52. {
  53. using namespace Eigen;
  54. EmbreeIntersector ei;
  55. ei.init(V.template cast<float>(),F.template cast<int>());
  56. shape_diameter_function(ei,P,N,num_samples,S);
  57. }
  58. #ifdef IGL_STATIC_LIBRARY
  59. // Explicit template instantiation
  60. 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::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> >&);
  61. 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::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> >&);
  62. 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::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> >&);
  63. 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::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> >&);
  64. 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::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> >&);
  65. #endif