propagate_winding_numbers.h 8.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Qingnan Zhou <qnzhou@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. //
  9. #ifndef IGL_CGAL_PROPAGATE_WINDING_NUMBERS_H
  10. #define IGL_CGAL_PROPAGATE_WINDING_NUMBERS_H
  11. #include "../igl_inline.h"
  12. #include <Eigen/Core>
  13. #include <vector>
  14. // The following methods compute the winding number on each side of each facet
  15. // or patch of a 3D mesh. The input mesh is valid if it splits the ambient
  16. // space, R^3, into subspaces with constant integer winding numbers. That is
  17. // the input mesh should be closed and for each directed edge the number of
  18. // clockwise facing facets should equal the number of counterclockwise facing
  19. // facets.
  20. namespace igl {
  21. namespace cgal {
  22. // Compute winding number on each side of each patch. All patches must
  23. // be connected. The per-patch label partitions the patches into
  24. // different components, and winding number is computed for each
  25. // component. For example, ``patch_W(i, j*2)`` for ``i`` in [0, #P)
  26. // and ``j`` in [0, k) is the winding number on the positive side of
  27. // patch ``i`` with respect to component ``j``. Similarly,
  28. // ``patch_W(i, j*2+1)`` is the winding number on the negative side of
  29. // patch ``i`` with respect to component ``j``.
  30. //
  31. // Patch and intersection curve can be generated using:
  32. // ``igl::extract_manifold_patches(...)`` and
  33. // ``igl::extract_non_manifold_edge_curves(...)``
  34. //
  35. //
  36. // Inputs:
  37. // V #V by 3 list of vertices.
  38. // F #F by 3 list of trianlges.
  39. // uE #uE by 2 list of undirected edges.
  40. // uE2E #uE list of lists mapping each undirected edge to directed
  41. // edges.
  42. // labels #P list of labels, ranging from 0 to k-1.
  43. // These labels partition patches into k components, and
  44. // winding number is computed for each component.
  45. // P #F list of patch indices.
  46. // intersection_curves A list of non-manifold curves that separates
  47. // the mesh into patches.
  48. //
  49. // Outputs:
  50. // patch_W #P by k*2 list of winding numbers on each side of a
  51. // patch for each component.
  52. //
  53. // Returns:
  54. // True iff integer winding numbers can be consistently assigned.
  55. template<
  56. typename DerivedV,
  57. typename DerivedF,
  58. typename DeriveduE,
  59. typename uE2EType,
  60. typename DerivedC,
  61. typename DerivedP,
  62. typename DerivedW >
  63. IGL_INLINE bool propagate_winding_numbers_single_component_patch_wise(
  64. const Eigen::PlainObjectBase<DerivedV>& V,
  65. const Eigen::PlainObjectBase<DerivedF>& F,
  66. const Eigen::PlainObjectBase<DeriveduE>& uE,
  67. const std::vector<std::vector<uE2EType> >& uE2E,
  68. const Eigen::PlainObjectBase<DerivedC>& labels,
  69. const Eigen::PlainObjectBase<DerivedP>& P,
  70. const std::vector<std::vector<size_t> >& intersection_curves,
  71. Eigen::PlainObjectBase<DerivedW>& patch_W);
  72. #if 0
  73. template<
  74. typename DerivedV,
  75. typename DerivedF,
  76. typename DeriveduE,
  77. typename uE2EType,
  78. typename DerivedEMAP,
  79. typename DerivedC,
  80. typename DerivedP,
  81. typename DerivedW >
  82. IGL_INLINE bool propagate_winding_numbers_single_component_patch_wise(
  83. const Eigen::PlainObjectBase<DerivedV>& V,
  84. const Eigen::PlainObjectBase<DerivedF>& F,
  85. const Eigen::PlainObjectBase<DeriveduE>& uE,
  86. const std::vector<std::vector<uE2EType> >& uE2E,
  87. const Eigen::PlainObjectBase<DerivedEMAP>& EMAP,
  88. const Eigen::PlainObjectBase<DerivedC>& labels,
  89. const Eigen::PlainObjectBase<DerivedP>& P,
  90. Eigen::PlainObjectBase<DerivedW>& patch_W);
  91. #endif
  92. // Compute winding number on each side of the face. The input mesh must
  93. // be a single edge-connected component.
  94. //
  95. // Inputs:
  96. // V #V by 3 list of vertex positions.
  97. // F #F by 3 list of triangle indices into V.
  98. // labels #F list of facet labels ranging from 0 to k-1.
  99. //
  100. // Output:
  101. // W #F by 2*k list of winding numbers.
  102. // ``W(i, 2*j)`` is the winding number on the positive side of
  103. // facet ``i`` with respect to facets labelled ``j``.
  104. // ``W(i, 2*j+1)`` is the winding number on the negative side of
  105. // facet ``i`` with respect to facets labelled ``j``.
  106. //
  107. // Returns:
  108. // True iff integer winding number can be consistently assigned.
  109. template<
  110. typename DerivedV,
  111. typename DerivedF,
  112. typename DerivedC,
  113. typename DerivedW>
  114. IGL_INLINE bool propagate_winding_numbers_single_component(
  115. const Eigen::PlainObjectBase<DerivedV>& V,
  116. const Eigen::PlainObjectBase<DerivedF>& F,
  117. const Eigen::PlainObjectBase<DerivedC>& labels,
  118. Eigen::PlainObjectBase<DerivedW>& W);
  119. // Compute the winding number on each side of the face.
  120. // This method assumes the input mesh (V, F) forms a single connected
  121. // component.
  122. //
  123. // Inputs:
  124. // V #V by 3 list of vertex positions.
  125. // F #F by 3 list of triangle indices into V.
  126. //
  127. // Output:
  128. // W #F by 2 list of winding numbers. W(i,0) is the winding number
  129. // on the positive side of facet i, and W(i, 1) is the winding
  130. // number on the negative side of facet I[i].
  131. //
  132. // Returns:
  133. // True iff integer winding number can be consistently assigned.
  134. template<
  135. typename DerivedV,
  136. typename DerivedF,
  137. typename DerivedW>
  138. IGL_INLINE bool propagate_winding_numbers_single_component(
  139. const Eigen::PlainObjectBase<DerivedV>& V,
  140. const Eigen::PlainObjectBase<DerivedF>& F,
  141. Eigen::PlainObjectBase<DerivedW>& W);
  142. // Compute winding number on each side of the face. The input mesh
  143. // could contain multiple connected components. The input mesh must
  144. // represent the boundary of a valid 3D volume, which means it is
  145. // closed, consistently oriented and induces integer winding numbers.
  146. //
  147. // Inputs:
  148. // V #V by 3 list of vertex positions.
  149. // F #F by 3 list of triangle indices into V.
  150. // labels #F list of facet labels ranging from 0 to k-1.
  151. //
  152. // Output:
  153. // W #F by k*2 list of winding numbers. ``W(i,j*2)`` is the winding
  154. // number on the positive side of facet ``i`` with respect to the
  155. // facets labeled ``j``. Similarly, ``W(i,j*2+1)`` is the winding
  156. // number on the negative side of facet ``i`` with respect to the
  157. // facets labeled ``j``.
  158. template<
  159. typename DerivedV,
  160. typename DerivedF,
  161. typename DerivedL,
  162. typename DerivedW>
  163. IGL_INLINE void propagate_winding_numbers(
  164. const Eigen::PlainObjectBase<DerivedV>& V,
  165. const Eigen::PlainObjectBase<DerivedF>& F,
  166. const Eigen::PlainObjectBase<DerivedL>& labels,
  167. Eigen::PlainObjectBase<DerivedW>& W);
  168. template<
  169. typename DerivedV,
  170. typename DerivedF,
  171. typename DerivedL,
  172. typename DerivedW>
  173. IGL_INLINE void propagate_winding_numbers_beta(
  174. const Eigen::PlainObjectBase<DerivedV>& V,
  175. const Eigen::PlainObjectBase<DerivedF>& F,
  176. const Eigen::PlainObjectBase<DerivedL>& labels,
  177. Eigen::PlainObjectBase<DerivedW>& W);
  178. }
  179. }
  180. #ifndef IGL_STATIC_LIBRARY
  181. # include "propagate_winding_numbers.cpp"
  182. #endif
  183. #endif