remesh_self_intersections.h 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 Alec Jacobson <alecjacobson@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. #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. // Inputs:
  28. // V #V by 3 list of vertex positions
  29. // F #F by 3 list of triangle indices into V
  30. // params struct of optional parameters
  31. // Outputs:
  32. // VV #VV by 3 list of vertex positions
  33. // FF #FF by 3 list of triangle indices into VV
  34. // IF #intersecting face pairs by 2 list of intersecting face pairs,
  35. // indexing F
  36. // J #FF list of indices into F denoting birth triangle
  37. // IM #VV list of indices into VV of unique vertices.
  38. //
  39. // Known bugs: If an existing edge in (V,F) lies exactly on another face then
  40. // any resulting additional vertices along that edge may not get properly
  41. // connected so that the output mesh has the same global topology. This is
  42. // because
  43. //
  44. // Example:
  45. // // resolve intersections
  46. // igl::copyleft::cgal::remesh_self_intersections(V,F,params,VV,FF,IF,J,IM);
  47. // // _apply_ duplicate vertex mapping IM to FF
  48. // for_each(FF.data(),FF.data()+FF.size(),[&IM](int & a){a=IM(a);});
  49. // // remove any vertices now unreferenced after duplicate mapping.
  50. // igl::remove_unreferenced(VV,FF,SV,SF,UIM);
  51. // // Now (SV,SF) is ready to extract outer hull
  52. // igl::copyleft::cgal::outer_hull(SV,SF,G,J,flip);
  53. //
  54. template <
  55. typename DerivedV,
  56. typename DerivedF,
  57. typename DerivedVV,
  58. typename DerivedFF,
  59. typename DerivedIF,
  60. typename DerivedJ,
  61. typename DerivedIM>
  62. IGL_INLINE void remesh_self_intersections(
  63. const Eigen::PlainObjectBase<DerivedV> & V,
  64. const Eigen::PlainObjectBase<DerivedF> & F,
  65. const RemeshSelfIntersectionsParam & params,
  66. Eigen::PlainObjectBase<DerivedVV> & VV,
  67. Eigen::PlainObjectBase<DerivedFF> & FF,
  68. Eigen::PlainObjectBase<DerivedIF> & IF,
  69. Eigen::PlainObjectBase<DerivedJ> & J,
  70. Eigen::PlainObjectBase<DerivedIM> & IM);
  71. }
  72. }
  73. }
  74. #ifndef IGL_STATIC_LIBRARY
  75. # include "remesh_self_intersections.cpp"
  76. #endif
  77. #endif