fast_winding_number.h 10 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. #ifndef IGL_FAST_WINDING_NUMBER
  2. #define IGL_FAST_WINDING_NUMBER
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. namespace igl
  6. {
  7. // Generate the precomputation for the fast winding number for point data
  8. // [Barill et. al 2018].
  9. //
  10. // Given a set of 3D points P, with normals N, areas A, along with octree
  11. // data, and an expansion order, we define a taylor series expansion at each
  12. // octree cell.
  13. //
  14. // The octree data is designed to come from igl::build_octree, and the areas
  15. // (if not obtained at scan time), may be calculated using
  16. // igl::point_areas_and_normals.
  17. //
  18. // Inputs:
  19. // P #P by 3 list of point locations
  20. // N #P by 3 list of point normals
  21. // A #P by 1 list of point areas
  22. // point_indices a vector of vectors, where the ith entry is a vector of
  23. // the indices into P that are the ith octree cell's points
  24. // children a vector of vectors, where the ith entry is a vector of
  25. // the ith octree cell's of octree children
  26. // expansion_order the order of the taylor expansion. We support 0,1,2.
  27. // Outputs:
  28. // CM #OctreeCells by 3 list of each cell's center of mass
  29. // R #OctreeCells by 1 list of each cell's maximum distance of any point
  30. // to the center of mass
  31. // EC #OctreeCells by #TaylorCoefficients list of expansion coefficients.
  32. // (Note that #TaylorCoefficients = ∑_{i=1}^{expansion_order} 3^i)
  33. //
  34. template <typename DerivedP, typename DerivedA, typename DerivedN,
  35. typename Index, typename DerivedCM, typename DerivedR, typename DerivedEC>
  36. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  37. const Eigen::MatrixBase<DerivedN>& N,
  38. const Eigen::MatrixBase<DerivedA>& A,
  39. const std::vector<std::vector<Index> > & point_indices,
  40. const std::vector<Eigen::Matrix<Index,8,1>, Eigen::aligned_allocator<Eigen::Matrix<Index,8,1> > > & children,
  41. const int exansion_order,
  42. Eigen::PlainObjectBase<DerivedCM>& CM,
  43. Eigen::PlainObjectBase<DerivedR>& R,
  44. Eigen::PlainObjectBase<DerivedEC>& EC);
  45. // Evaluate the fast winding number for point data, having already done the
  46. // the precomputation
  47. //
  48. // Inputs:
  49. // P #P by 3 list of point locations
  50. // N #P by 3 list of point normals
  51. // A #P by 1 list of point areas
  52. // point_indices a vector of vectors, where the ith entry is a vector of
  53. // the indices into P that are the ith octree cell's points
  54. // children a vector of vectors, where the ith entry is a vector of
  55. // the ith octree cell's of octree children
  56. // CM #OctreeCells by 3 list of each cell's center of mass
  57. // R #OctreeCells by 1 list of each cell's maximum distance of any point
  58. // to the center of mass
  59. // EC #OctreeCells by #TaylorCoefficients list of expansion coefficients.
  60. // (Note that #TaylorCoefficients = ∑_{i=1}^{expansion_order} 3^i)
  61. // Q #Q by 3 list of query points for the winding number
  62. // beta This is a Barnes-Hut style accuracy term that separates near feild
  63. // from far field. The higher the beta, the more accurate and slower
  64. // the evaluation. We reccommend using a beta value of 2. Note that
  65. // for a beta value ≤ 0, we use the direct evaluation, rather than
  66. // the fast approximation
  67. // Outputs:
  68. // WN #Q by 1 list of windinng number values at each query point
  69. //
  70. template <typename DerivedP, typename DerivedA, typename DerivedN,
  71. typename Index, typename DerivedCM, typename DerivedR, typename DerivedEC,
  72. typename DerivedQ, typename BetaType, typename DerivedWN>
  73. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  74. const Eigen::MatrixBase<DerivedN>& N,
  75. const Eigen::MatrixBase<DerivedA>& A,
  76. const std::vector<std::vector<Index> > & point_indices,
  77. const std::vector<Eigen::Matrix<Index,8,1>, Eigen::aligned_allocator<Eigen::Matrix<Index,8,1> > > & children,
  78. const Eigen::MatrixBase<DerivedCM>& CM,
  79. const Eigen::MatrixBase<DerivedR>& R,
  80. const Eigen::MatrixBase<DerivedEC>& EC,
  81. const Eigen::MatrixBase<DerivedQ>& Q,
  82. const BetaType beta,
  83. Eigen::PlainObjectBase<DerivedWN>& WN);
  84. // Evaluate the fast winding number for point data.
  85. //
  86. // This function performes the precomputation and evaluation all in one.
  87. // If you need to acess the precomuptation for repeated evaluations, use the
  88. // two functions designed for exposed precomputation (described above).
  89. // Inputs:
  90. // P #P by 3 list of point locations
  91. // N #P by 3 list of point normals
  92. // A #P by 1 list of point areas
  93. // Q #Q by 3 list of query points for the winding number
  94. // beta This is a Barnes-Hut style accuracy term that separates near feild
  95. // from far field. The higher the beta, the more accurate and slower
  96. // the evaluation. We reccommend using a beta value of 2.
  97. // expansion_order the order of the taylor expansion. We support 0,1,2.
  98. // Outputs:
  99. // WN #Q by 1 list of windinng number values at each query point
  100. //
  101. template <typename DerivedP, typename DerivedA, typename DerivedN,
  102. typename DerivedQ, typename BetaType, typename DerivedWN>
  103. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  104. const Eigen::MatrixBase<DerivedN>& N,
  105. const Eigen::MatrixBase<DerivedA>& A,
  106. const Eigen::MatrixBase<DerivedQ>& Q,
  107. const int expansion_order,
  108. const BetaType beta,
  109. Eigen::PlainObjectBase<DerivedWN>& WN
  110. );
  111. // Evaluate the fast winding number for point data, with default expansion
  112. // order and beta (both are set to 2).
  113. //
  114. // This function performes the precomputation and evaluation all in one.
  115. // If you need to acess the precomuptation for repeated evaluations, use the
  116. // two functions designed for exposed precomputation (described above).
  117. //
  118. // Inputs:
  119. // P #P by 3 list of point locations
  120. // N #P by 3 list of point normals
  121. // A #P by 1 list of point areas
  122. // Q #Q by 3 list of query points for the winding number
  123. // beta This is a Barnes-Hut style accuracy term that separates near feild
  124. // from far field. The higher the beta, the more accurate and slower
  125. // the evaluation. We reccommend using a beta value of 2.
  126. // expansion_order the order of the taylor expansion. We support 0,1,2.
  127. // Outputs:
  128. // WN #Q by 1 list of windinng number values at each query point
  129. //
  130. template <typename DerivedP, typename DerivedA, typename DerivedN,
  131. typename DerivedQ, typename DerivedWN>
  132. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  133. const Eigen::MatrixBase<DerivedN>& N,
  134. const Eigen::MatrixBase<DerivedA>& A,
  135. const Eigen::MatrixBase<DerivedQ>& Q,
  136. Eigen::PlainObjectBase<DerivedWN>& WN
  137. );
  138. // Evaluate the fast winding number for point data, without known areas. The
  139. // areas are calculated using igl::knn_search and
  140. // igl::point_areas_and_normals.
  141. //
  142. // This function performes the precomputation and evaluation all in one.
  143. // If you need to acess the precomuptation for repeated evaluations, use the
  144. // two functions designed for exposed precomputation (described above).
  145. // Inputs:
  146. // P #P by 3 list of point locations
  147. // N #P by 3 list of point normals
  148. // Q #Q by 3 list of query points for the winding number
  149. // beta This is a Barnes-Hut style accuracy term that separates near feild
  150. // from far field. The higher the beta, the more accurate and slower
  151. // the evaluation. We reccommend using a beta value of 2.
  152. // expansion_order the order of the taylor expansion. We support 0,1,2.
  153. // Outputs:
  154. // WN #Q by 1 list of windinng number values at each query point
  155. //
  156. template <typename DerivedP, typename DerivedN, typename DerivedQ,
  157. typename BetaType, typename DerivedWN>
  158. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  159. const Eigen::MatrixBase<DerivedN>& N,
  160. const Eigen::MatrixBase<DerivedQ>& Q,
  161. const int expansion_order,
  162. const BetaType beta,
  163. Eigen::PlainObjectBase<DerivedWN>& WN
  164. );
  165. // Evaluate the fast winding number for point data, without known areas. The
  166. // areas are calculated using igl::knn_search and
  167. // igl::point_areas_and_normals. This function uses the default expansion
  168. // order and beta (both are set to 2).
  169. //
  170. // This function performes the precomputation and evaluation all in one.
  171. // If you need to acess the precomuptation for repeated evaluations, use the
  172. // two functions designed for exposed precomputation (described above).
  173. // Inputs:
  174. // P #P by 3 list of point locations
  175. // N #P by 3 list of point normals
  176. // Q #Q by 3 list of query points for the winding number
  177. // Outputs:
  178. // WN #Q by 1 list of windinng number values at each query point
  179. //
  180. template <typename DerivedP, typename DerivedN, typename DerivedQ,
  181. typename DerivedWN>
  182. IGL_INLINE void fast_winding_number(const Eigen::MatrixBase<DerivedP>& P,
  183. const Eigen::MatrixBase<DerivedN>& N,
  184. const Eigen::MatrixBase<DerivedQ>& Q,
  185. Eigen::PlainObjectBase<DerivedWN>& WN
  186. );
  187. }
  188. #ifndef IGL_STATIC_LIBRARY
  189. # include "fast_winding_number.cpp"
  190. #endif
  191. #endif