intersect_with_half_space.cpp 5.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. #include "intersect_with_half_space.h"
  2. #include "mesh_boolean.h"
  3. #include "half_space_box.h"
  4. template <
  5. typename DerivedV,
  6. typename DerivedF,
  7. typename Derivedp,
  8. typename Derivedn,
  9. typename DerivedVC,
  10. typename DerivedFC,
  11. typename DerivedJ>
  12. IGL_INLINE bool igl::copyleft::cgal::intersect_with_half_space(
  13. const Eigen::PlainObjectBase<DerivedV > & V,
  14. const Eigen::PlainObjectBase<DerivedF > & F,
  15. const Eigen::PlainObjectBase<Derivedp > & p,
  16. const Eigen::PlainObjectBase<Derivedn > & n,
  17. Eigen::PlainObjectBase<DerivedVC > & VC,
  18. Eigen::PlainObjectBase<DerivedFC > & FC,
  19. Eigen::PlainObjectBase<DerivedJ > & J)
  20. {
  21. typedef CGAL::Plane_3<CGAL::Epeck> Plane;
  22. typedef CGAL::Point_3<CGAL::Epeck> Point;
  23. typedef CGAL::Vector_3<CGAL::Epeck> Vector;
  24. Plane P(Point(p(0),p(1),p(2)),Vector(n(0),n(1),n(2)));
  25. return intersect_with_half_space(V,F,P,VC,FC,J);
  26. }
  27. template <
  28. typename DerivedV,
  29. typename DerivedF,
  30. typename Derivedequ,
  31. typename DerivedVC,
  32. typename DerivedFC,
  33. typename DerivedJ>
  34. IGL_INLINE bool igl::copyleft::cgal::intersect_with_half_space(
  35. const Eigen::PlainObjectBase<DerivedV > & V,
  36. const Eigen::PlainObjectBase<DerivedF > & F,
  37. const Eigen::PlainObjectBase<Derivedequ > & equ,
  38. Eigen::PlainObjectBase<DerivedVC > & VC,
  39. Eigen::PlainObjectBase<DerivedFC > & FC,
  40. Eigen::PlainObjectBase<DerivedJ > & J)
  41. {
  42. typedef CGAL::Plane_3<CGAL::Epeck> Plane;
  43. Plane P(equ(0),equ(1),equ(2),equ(3));
  44. return intersect_with_half_space(V,F,P,VC,FC,J);
  45. }
  46. template <
  47. typename DerivedV,
  48. typename DerivedF,
  49. typename DerivedVC,
  50. typename DerivedFC,
  51. typename DerivedJ>
  52. IGL_INLINE bool igl::copyleft::cgal::intersect_with_half_space(
  53. const Eigen::PlainObjectBase<DerivedV > & V,
  54. const Eigen::PlainObjectBase<DerivedF > & F,
  55. const CGAL::Plane_3<CGAL::Epeck> & P,
  56. Eigen::PlainObjectBase<DerivedVC > & VC,
  57. Eigen::PlainObjectBase<DerivedFC > & FC,
  58. Eigen::PlainObjectBase<DerivedJ > & J)
  59. {
  60. Eigen::Matrix<CGAL::Epeck::FT,8,3> BV;
  61. Eigen::Matrix<int,12,3> BF;
  62. half_space_box(P,V,BV,BF);
  63. // Disturbingly, (BV,BF) must be first argument
  64. const bool ret = mesh_boolean(BV,BF,V,F,MESH_BOOLEAN_TYPE_INTERSECT,VC,FC,J);
  65. // But now J is wrong...
  66. std::for_each(
  67. J.data(),
  68. J.data()+J.size(),
  69. [&BF,&F](typename DerivedJ::Scalar & j)
  70. {j = (j<BF.rows()?F.rows()+j:j-BF.rows());}
  71. );
  72. return ret;
  73. }
  74. #ifdef IGL_STATIC_LIBRARY
  75. // Explicit template specialization
  76. // generated by autoexplicit.sh
  77. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 3, 0, -1, 3>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 3, 0, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 3, 0, -1, 3> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  78. // generated by autoexplicit.sh
  79. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 4, 0, -1, 4>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 4, 0, -1, 4>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 4, 0, -1, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, 4, 0, -1, 4> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  80. // generated by autoexplicit.sh
  81. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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<CGAL::Lazy_exact_nt<CGAL::Gmpq>, 1, 4, 1, 1, 4> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  82. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -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, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  83. #endif