selfintersect.h 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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_SELFINTERSECT_H
  9. #define IGL_SELFINTERSECT_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 SelfintersectParam
  23. {
  24. bool detect_only;
  25. bool first_only;
  26. SelfintersectParam():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. IGL_INLINE void selfintersect(
  53. const Eigen::MatrixXd & V,
  54. const Eigen::MatrixXi & F,
  55. const SelfintersectParam & params,
  56. Eigen::MatrixXd & VV,
  57. Eigen::MatrixXi & FF,
  58. Eigen::MatrixXi & IF,
  59. Eigen::VectorXi & J,
  60. Eigen::VectorXi & IM);
  61. }
  62. #ifndef IGL_STATIC_LIBRARY
  63. # include "selfintersect.cpp"
  64. #endif
  65. #endif