remesh_self_intersections.h 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  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_REMESH_SELF_INTERSECTIONS_H
  9. #define IGL_REMESH_SELF_INTERSECTIONS_H
  10. #include <igl/igl_inline.h>
  11. #include <Eigen/Dense>
  12. #ifdef MEX
  13. # include <mex.h>
  14. # include <cassert>
  15. # undef assert
  16. # define assert( isOK ) ( (isOK) ? (void)0 : (void) mexErrMsgTxt(C_STR(__FILE__<<":"<<__LINE__<<": failed assertion `"<<#isOK<<"'"<<std::endl) ) )
  17. #endif
  18. namespace igl
  19. {
  20. // Optional Parameters
  21. // DetectOnly Only compute IF, leave VV and FF alone
  22. struct RemeshSelfIntersectionsParam
  23. {
  24. bool detect_only;
  25. bool first_only;
  26. RemeshSelfIntersectionsParam():detect_only(false),first_only(false){};
  27. };
  28. // Given a triangle mesh (V,F) compute a new mesh (VV,FF) which is the same
  29. // as (V,F) except that any self-intersecting triangles in (V,F) have been
  30. // subdivided (new vertices and face created) so that the self-intersection
  31. // contour lies exactly on edges in (VV,FF). New vertices will appear in
  32. // original faces or on original edges. New vertices on edges are "merged"
  33. // only across original faces sharing that edge. This means that if the input
  34. // triangle mesh is a closed manifold the output will be too.
  35. //
  36. // Inputs:
  37. // V #V by 3 list of vertex positions
  38. // F #F by 3 list of triangle indices into V
  39. // params struct of optional parameters
  40. // Outputs:
  41. // VV #VV by 3 list of vertex positions
  42. // FF #FF by 3 list of triangle indices into V
  43. // IF #intersecting face pairs by 2 list of intersecting face pairs,
  44. // indexing F
  45. // J #FF list of indices into F denoting birth triangle
  46. // IM #VV list of indices into VV of unique vertices.
  47. //
  48. // Known bugs: If an existing edge in (V,F) lies exactly on another face then
  49. // any resulting additional vertices along that edge may not get properly
  50. // connected so that the output mesh has the same global topology. This is
  51. // because
  52. //
  53. // Example:
  54. // // resolve intersections
  55. // igl::remesh_self_intersections(V,F,params,VV,FF,IF,J,IM);
  56. // // _apply_ duplicate vertex mapping IM to FF
  57. // for_each(FF.data(),FF.data()+FF.size(),[&IM](int & a){a=IM(a);});
  58. // // remove any vertices now unreferenced after duplicate mapping.
  59. // igl::remove_unreferenced(VV,FF,SV,SF,UIM);
  60. // // Now (SV,SF) is ready to extract outer hull
  61. // igl::outer_hull(SV,SF,G,J,flip);
  62. //
  63. template <
  64. typename DerivedV,
  65. typename DerivedF,
  66. typename DerivedVV,
  67. typename DerivedFF,
  68. typename DerivedIF,
  69. typename DerivedJ,
  70. typename DerivedIM>
  71. IGL_INLINE void remesh_self_intersections(
  72. const Eigen::PlainObjectBase<DerivedV> & V,
  73. const Eigen::PlainObjectBase<DerivedF> & F,
  74. const RemeshSelfIntersectionsParam & params,
  75. Eigen::PlainObjectBase<DerivedVV> & VV,
  76. Eigen::PlainObjectBase<DerivedFF> & FF,
  77. Eigen::PlainObjectBase<DerivedIF> & IF,
  78. Eigen::PlainObjectBase<DerivedJ> & J,
  79. Eigen::PlainObjectBase<DerivedIM> & IM);
  80. }
  81. #ifndef IGL_STATIC_LIBRARY
  82. # include "remesh_self_intersections.cpp"
  83. #endif
  84. #endif