mesh_boolean_cork.cpp 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  1. #ifndef IGL_NO_CORK
  2. #include "mesh_boolean_cork.h"
  3. #include "to_cork_mesh.h"
  4. #include "from_cork_mesh.h"
  5. template <
  6. typename DerivedVA,
  7. typename DerivedFA,
  8. typename DerivedVB,
  9. typename DerivedFB,
  10. typename DerivedVC,
  11. typename DerivedFC>
  12. IGL_INLINE void igl::mesh_boolean_cork(
  13. const Eigen::PlainObjectBase<DerivedVA > & VA,
  14. const Eigen::PlainObjectBase<DerivedFA > & FA,
  15. const Eigen::PlainObjectBase<DerivedVB > & VB,
  16. const Eigen::PlainObjectBase<DerivedFB > & FB,
  17. const MeshBooleanType & type,
  18. Eigen::PlainObjectBase<DerivedVC > & VC,
  19. Eigen::PlainObjectBase<DerivedFC > & FC)
  20. {
  21. CorkTriMesh A,B,C;
  22. // pointer to output so it's easy to redirect on degenerate cases
  23. CorkTriMesh *ret = &C;
  24. to_cork_mesh(VA,FA,A);
  25. to_cork_mesh(VB,FB,B);
  26. switch(type)
  27. {
  28. case MESH_BOOLEAN_TYPE_UNION:
  29. if(A.n_triangles == 0)
  30. {
  31. ret = &B;
  32. }else if(B.n_triangles == 0)
  33. {
  34. ret = &A;
  35. }else
  36. {
  37. computeUnion(A,B,ret);
  38. }
  39. break;
  40. case MESH_BOOLEAN_TYPE_INTERSECT:
  41. if(A.n_triangles == 0 || B.n_triangles == 0)
  42. {
  43. ret->n_triangles = 0;
  44. ret->n_vertices = 0;
  45. }else
  46. {
  47. computeIntersection(A,B,ret);
  48. }
  49. break;
  50. case MESH_BOOLEAN_TYPE_MINUS:
  51. if(A.n_triangles == 0)
  52. {
  53. ret->n_triangles = 0;
  54. ret->n_vertices = 0;
  55. }else if(B.n_triangles == 0)
  56. {
  57. ret = &A;
  58. }else
  59. {
  60. computeDifference(A,B,ret);
  61. }
  62. break;
  63. case MESH_BOOLEAN_TYPE_XOR:
  64. if(A.n_triangles == 0)
  65. {
  66. ret = &B;
  67. }else if(B.n_triangles == 0)
  68. {
  69. ret = &A;
  70. }else
  71. {
  72. computeSymmetricDifference(A,B,&C);
  73. }
  74. break;
  75. case MESH_BOOLEAN_TYPE_RESOLVE:
  76. resolveIntersections(A,B,&C);
  77. break;
  78. default:
  79. assert(false && "Unknown type");
  80. return;
  81. }
  82. from_cork_mesh(*ret,VC,FC);
  83. freeCorkTriMesh(&A);
  84. freeCorkTriMesh(&B);
  85. freeCorkTriMesh(&C);
  86. }
  87. #ifdef IGL_STATIC_LIBRARY
  88. // Explicit template specialization
  89. template void igl::mesh_boolean_cork<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, MeshBooleanType const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  90. #endif
  91. #endif