shape_diameter_function.h 3.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 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_SHAPE_DIAMETER_FUNCTION_H
  9. #define IGL_SHAPE_DIAMETER_FUNCTION_H
  10. #include "igl_inline.h"
  11. #include "AABB.h"
  12. #include <Eigen/Core>
  13. #include <functional>
  14. namespace igl
  15. {
  16. /// Compute shape diamater function per given point. In the parlence of the
  17. /// paper "Consistent Mesh Partitioning and Skeletonisation using the Shape
  18. /// Diameter Function" [Shapiro et al. 2008], this implementation uses a 180°
  19. /// cone and a _uniform_ average (_not_ a average weighted by inverse angles).
  20. ///
  21. /// @param[in] shoot_ray function handle that outputs hits of a given ray against a
  22. /// mesh (embedded in function handles as captured variable/data)
  23. /// @param[in] P #P by 3 list of origin points
  24. /// @param[in] N #P by 3 list of origin normals
  25. /// @param[out] S #P list of shape diamater function values between bounding box
  26. /// @param[out] diagonal (perfect sphere) and 0 (perfect needle hook)
  27. ///
  28. template <
  29. typename DerivedP,
  30. typename DerivedN,
  31. typename DerivedS >
  32. IGL_INLINE void shape_diameter_function(
  33. const std::function<
  34. typename DerivedP::Scalar(
  35. const Eigen::Matrix<typename DerivedP::Scalar,3,1> &,
  36. const Eigen::Matrix<typename DerivedP::Scalar,3,1> &)
  37. > & shoot_ray,
  38. const Eigen::MatrixBase<DerivedP> & P,
  39. const Eigen::MatrixBase<DerivedN> & N,
  40. const int num_samples,
  41. Eigen::PlainObjectBase<DerivedS> & S);
  42. /// \overload
  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. template <
  48. typename DerivedV,
  49. int DIM,
  50. typename DerivedF,
  51. typename DerivedP,
  52. typename DerivedN,
  53. typename DerivedS >
  54. IGL_INLINE void shape_diameter_function(
  55. const igl::AABB<DerivedV,DIM> & aabb,
  56. const Eigen::MatrixBase<DerivedV> & V,
  57. const Eigen::MatrixBase<DerivedF> & F,
  58. const Eigen::MatrixBase<DerivedP> & P,
  59. const Eigen::MatrixBase<DerivedN> & N,
  60. const int num_samples,
  61. Eigen::PlainObjectBase<DerivedS> & S);
  62. /// \overload
  63. template <
  64. typename DerivedV,
  65. typename DerivedF,
  66. typename DerivedP,
  67. typename DerivedN,
  68. typename DerivedS >
  69. IGL_INLINE void shape_diameter_function(
  70. const Eigen::MatrixBase<DerivedV> & V,
  71. const Eigen::MatrixBase<DerivedF> & F,
  72. const Eigen::MatrixBase<DerivedP> & P,
  73. const Eigen::MatrixBase<DerivedN> & N,
  74. const int num_samples,
  75. Eigen::PlainObjectBase<DerivedS> & S);
  76. /// @param[in] per_face whether to compute per face (S is #F by 1) or per vertex (S is
  77. /// #V by 1)
  78. template <
  79. typename DerivedV,
  80. typename DerivedF,
  81. typename DerivedS>
  82. IGL_INLINE void shape_diameter_function(
  83. const Eigen::MatrixBase<DerivedV> & V,
  84. const Eigen::MatrixBase<DerivedF> & F,
  85. const bool per_face,
  86. const int num_samples,
  87. Eigen::PlainObjectBase<DerivedS> & S);
  88. };
  89. #ifndef IGL_STATIC_LIBRARY
  90. # include "shape_diameter_function.cpp"
  91. #endif
  92. #endif