remesh_self_intersections.h 3.3 KB

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