remesh_self_intersections.h 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879
  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 as
  29. // (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" only
  33. // 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. template <
  53. typename DerivedV,
  54. typename DerivedF,
  55. typename DerivedVV,
  56. typename DerivedFF,
  57. typename DerivedIF,
  58. typename DerivedJ,
  59. typename DerivedIM>
  60. IGL_INLINE void remesh_self_intersections(
  61. const Eigen::PlainObjectBase<DerivedV> & V,
  62. const Eigen::PlainObjectBase<DerivedF> & F,
  63. const RemeshSelfIntersectionsParam & params,
  64. Eigen::PlainObjectBase<DerivedVV> & VV,
  65. Eigen::PlainObjectBase<DerivedFF> & FF,
  66. Eigen::PlainObjectBase<DerivedIF> & IF,
  67. Eigen::PlainObjectBase<DerivedJ> & J,
  68. Eigen::PlainObjectBase<DerivedIM> & IM);
  69. }
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "remesh_self_intersections.cpp"
  72. #endif
  73. #endif