fast_winding_number.h 10 KB

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