remesh_self_intersections.h 3.1 KB

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