shape_diameter_function.h 3.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2017 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. #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. // Inputs:
  22. // shoot_ray function handle that outputs hits of a given ray against a
  23. // mesh (embedded in function handles as captured variable/data)
  24. // P #P by 3 list of origin points
  25. // N #P by 3 list of origin normals
  26. // Outputs:
  27. // S #P list of shape diamater function values between bounding box
  28. // diagonal (perfect sphere) and 0 (perfect needle hook)
  29. //
  30. template <
  31. typename DerivedP,
  32. typename DerivedN,
  33. typename DerivedS >
  34. IGL_INLINE void shape_diameter_function(
  35. const std::function<
  36. double(
  37. const Eigen::Vector3f&,
  38. const Eigen::Vector3f&)
  39. > & shoot_ray,
  40. const Eigen::PlainObjectBase<DerivedP> & P,
  41. const Eigen::PlainObjectBase<DerivedN> & N,
  42. const int num_samples,
  43. Eigen::PlainObjectBase<DerivedS> & S);
  44. // Inputs:
  45. // AABB axis-aligned bounding box hierarchy around (V,F)
  46. template <
  47. typename DerivedV,
  48. int DIM,
  49. typename DerivedF,
  50. typename DerivedP,
  51. typename DerivedN,
  52. typename DerivedS >
  53. IGL_INLINE void shape_diameter_function(
  54. const igl::AABB<DerivedV,DIM> & aabb,
  55. const Eigen::PlainObjectBase<DerivedV> & V,
  56. const Eigen::PlainObjectBase<DerivedF> & F,
  57. const Eigen::PlainObjectBase<DerivedP> & P,
  58. const Eigen::PlainObjectBase<DerivedN> & N,
  59. const int num_samples,
  60. Eigen::PlainObjectBase<DerivedS> & S);
  61. // Inputs:
  62. // V #V by 3 list of mesh vertex positions
  63. // F #F by 3 list of mesh face indices into V
  64. template <
  65. typename DerivedV,
  66. typename DerivedF,
  67. typename DerivedP,
  68. typename DerivedN,
  69. typename DerivedS >
  70. IGL_INLINE void shape_diameter_function(
  71. const Eigen::PlainObjectBase<DerivedV> & V,
  72. const Eigen::PlainObjectBase<DerivedF> & F,
  73. const Eigen::PlainObjectBase<DerivedP> & P,
  74. const Eigen::PlainObjectBase<DerivedN> & N,
  75. const int num_samples,
  76. Eigen::PlainObjectBase<DerivedS> & S);
  77. // per_face whether to compute per face (S is #F by 1) or per vertex (S is
  78. // #V by 1)
  79. template <
  80. typename DerivedV,
  81. typename DerivedF,
  82. typename DerivedS>
  83. IGL_INLINE void shape_diameter_function(
  84. const Eigen::PlainObjectBase<DerivedV> & V,
  85. const Eigen::PlainObjectBase<DerivedF> & F,
  86. const bool per_face,
  87. const int num_samples,
  88. Eigen::PlainObjectBase<DerivedS> & S);
  89. };
  90. #ifndef IGL_STATIC_LIBRARY
  91. # include "shape_diameter_function.cpp"
  92. #endif
  93. #endif