remesh_self_intersections.h 3.9 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <[email protected]>
  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_COPYLEFT_CGAL_REMESH_SELF_INTERSECTIONS_H
  9. #define IGL_COPYLEFT_CGAL_REMESH_SELF_INTERSECTIONS_H
  10. #include "../../igl_inline.h"
  11. #include "RemeshSelfIntersectionsParam.h"
  12. #include <Eigen/Dense>
  13. namespace igl
  14. {
  15. namespace copyleft
  16. {
  17. namespace cgal
  18. {
  19. /// Given a triangle mesh (V,F) compute a new mesh (VV,FF) which is the same
  20. /// as (V,F) except that any self-intersecting triangles in (V,F) have been
  21. /// subdivided (new vertices and face created) so that the self-intersection
  22. /// contour lies exactly on edges in (VV,FF). New vertices will appear in
  23. /// original faces or on original edges. New vertices on edges are "merged"
  24. /// only across original faces sharing that edge. This means that if the input
  25. /// triangle mesh is a closed manifold the output will be too.
  26. ///
  27. /// @param[in] V #V by 3 list of vertex positions
  28. /// @param[in] F #F by 3 list of triangle indices into V
  29. /// @param[in] params struct of optional parameters
  30. /// @param[out] VV #VV by 3 list of vertex positions
  31. /// @param[out] FF #FF by 3 list of triangle indices into VV
  32. /// @param[out] IF #intersecting face pairs by 2 list of intersecting
  33. /// face pairs, indexing F
  34. /// @param[out] J #FF list of indices into F denoting birth triangle
  35. /// @param[out] IM #VV list of indices into VV of unique vertices.
  36. ///
  37. /// \bug If an existing edge in (V,F) lies exactly on another face then
  38. /// any resulting additional vertices along that edge may not get properly
  39. /// connected so that the output mesh has the same global topology. This
  40. /// is because …
  41. ///
  42. /// #### Example.
  43. /// // resolve intersections
  44. /// igl::copyleft::cgal::remesh_self_intersections(V,F,params,VV,FF,IF,J,IM);
  45. /// // _apply_ duplicate vertex mapping IM to FF
  46. /// for_each(FF.data(),FF.data()+FF.size(),[&IM](int & a){a=IM(a);});
  47. /// // remove any vertices now unreferenced after duplicate mapping.
  48. /// igl::remove_unreferenced(VV,FF,SV,SF,UIM);
  49. /// // Now (SV,SF) is ready to extract outer hull
  50. /// igl::copyleft::cgal::outer_hull(SV,SF,G,J,flip);
  51. ///
  52. template <
  53. typename DerivedV,
  54. typename DerivedF,
  55. typename DerivedVV,
  56. typename DerivedFF,
  57. typename DerivedIF,
  58. typename DerivedJ,
  59. typename DerivedIM>
  60. IGL_INLINE void remesh_self_intersections(
  61. const Eigen::MatrixBase<DerivedV> & V,
  62. const Eigen::MatrixBase<DerivedF> & F,
  63. const RemeshSelfIntersectionsParam & params,
  64. Eigen::PlainObjectBase<DerivedVV> & VV,
  65. Eigen::PlainObjectBase<DerivedFF> & FF,
  66. Eigen::PlainObjectBase<DerivedIF> & IF,
  67. Eigen::PlainObjectBase<DerivedJ> & J,
  68. Eigen::PlainObjectBase<DerivedIM> & IM);
  69. /// \overload
  70. ///
  71. /// IM above is _applied_ to merge duplicated vertices in VV.
  72. template <
  73. typename DerivedV,
  74. typename DerivedF,
  75. typename DerivedVV,
  76. typename DerivedFF,
  77. typename DerivedIF,
  78. typename DerivedJ>
  79. IGL_INLINE void remesh_self_intersections(
  80. const Eigen::MatrixBase<DerivedV> & V,
  81. const Eigen::MatrixBase<DerivedF> & F,
  82. const RemeshSelfIntersectionsParam & params,
  83. Eigen::PlainObjectBase<DerivedVV> & VV,
  84. Eigen::PlainObjectBase<DerivedFF> & FF,
  85. Eigen::PlainObjectBase<DerivedIF> & IF,
  86. Eigen::PlainObjectBase<DerivedJ> & J);
  87. }
  88. }
  89. }
  90. #ifndef IGL_STATIC_LIBRARY
  91. # include "remesh_self_intersections.cpp"
  92. #endif
  93. #endif