remesh_self_intersections.h 3.4 KB

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