propagate_winding_numbers.h 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899
  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_COPYLEFT_CGAL_PROPAGATE_WINDING_NUMBERS_H
  10. #define IGL_COPYLEFT_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. {
  22. namespace copyleft
  23. {
  24. namespace cgal
  25. {
  26. // TODO: This shouldn't need to be in igl::copyleft::cgal, it should
  27. // instead take as input an index of the ambient cell and the winding
  28. // number vector there.
  29. //
  30. // Compute winding number on each side of the face. The input mesh
  31. // could contain multiple connected components. The input mesh must
  32. // represent the boundary of a valid 3D volume, which means it is
  33. // closed, consistently oriented and induces integer winding numbers.
  34. //
  35. // Inputs:
  36. // V #V by 3 list of vertex positions.
  37. // F #F by 3 list of triangle indices into V.
  38. // labels #F list of facet labels ranging from 0 to k-1.
  39. // Output:
  40. // W #F by k*2 list of winding numbers. ``W(i,j*2)`` is the winding
  41. // number on the positive side of facet ``i`` with respect to the
  42. // facets labeled ``j``. Similarly, ``W(i,j*2+1)`` is the winding
  43. // number on the negative side of facet ``i`` with respect to the
  44. // facets labeled ``j``.
  45. // Returns true iff the input induces a piecewise-constant winding number
  46. // field.
  47. template<
  48. typename DerivedV,
  49. typename DerivedF,
  50. typename DerivedL,
  51. typename DerivedW>
  52. IGL_INLINE bool propagate_winding_numbers(
  53. const Eigen::PlainObjectBase<DerivedV>& V,
  54. const Eigen::PlainObjectBase<DerivedF>& F,
  55. const Eigen::PlainObjectBase<DerivedL>& labels,
  56. Eigen::PlainObjectBase<DerivedW>& W);
  57. // Inputs:
  58. // V #V by 3 list of vertex positions.
  59. // F #F by 3 list of triangle indices into V.
  60. // P #F list of patch ids.
  61. // C #P by 2 list of cell ids on each side of each patch.
  62. // labels #F list of facet labels ranging from 0 to k-1.
  63. // Output:
  64. // W #F by k*2 list of winding numbers. ``W(i,j*2)`` is the winding
  65. // number on the positive side of facet ``i`` with respect to the
  66. // facets labeled ``j``. Similarly, ``W(i,j*2+1)`` is the winding
  67. // number on the negative side of facet ``i`` with respect to the
  68. // facets labeled ``j``.
  69. template<
  70. typename DerivedV,
  71. typename DerivedF,
  72. typename DeriveduE,
  73. typename uE2EType,
  74. typename DerivedP,
  75. typename DerivedC,
  76. typename DerivedL,
  77. typename DerivedW>
  78. IGL_INLINE bool propagate_winding_numbers(
  79. const Eigen::PlainObjectBase<DerivedV>& V,
  80. const Eigen::PlainObjectBase<DerivedF>& F,
  81. const Eigen::PlainObjectBase<DeriveduE>& uE,
  82. const std::vector<std::vector<uE2EType> >& uE2E,
  83. const size_t num_patches,
  84. const Eigen::PlainObjectBase<DerivedP>& P,
  85. const size_t num_cells,
  86. const Eigen::PlainObjectBase<DerivedC>& C,
  87. const Eigen::PlainObjectBase<DerivedL>& labels,
  88. Eigen::PlainObjectBase<DerivedW>& W);
  89. }
  90. }
  91. }
  92. #ifndef IGL_STATIC_LIBRARY
  93. # include "propagate_winding_numbers.cpp"
  94. #endif
  95. #endif