intersect_with_half_space.cpp 6.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  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::MatrixBase<DerivedV > & V,
  14. const Eigen::MatrixBase<DerivedF > & F,
  15. const Eigen::MatrixBase<Derivedp > & p,
  16. const Eigen::MatrixBase<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::MatrixBase<DerivedV > & V,
  36. const Eigen::MatrixBase<DerivedF > & F,
  37. const Eigen::MatrixBase<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::MatrixBase<DerivedV > & V,
  54. const Eigen::MatrixBase<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 instantiation
  76. // generated by autoexplicit.sh
  77. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, 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<double, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<double, 1, 3, 1, 1, 3>, Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<double>, Eigen::Matrix<double, 1, 3, 1, 1, 3> const>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<double, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<double>, Eigen::Matrix<double, 1, 3, 1, 1, 3> const> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, 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<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  82. // generated by autoexplicit.sh
  83. template bool igl::copyleft::cgal::intersect_with_half_space<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<int, -1, 3, 1, -1, 3>, Eigen::Matrix<float, 1, 3, 1, 1, 3>, Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<float>, Eigen::Matrix<float, 1, 3, 1, 1, 3> const>, Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, 1, 0, -1, 1> >(Eigen::MatrixBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, 3, 1, -1, 3> > const&, Eigen::MatrixBase<Eigen::Matrix<float, 1, 3, 1, 1, 3> > const&, Eigen::MatrixBase<Eigen::CwiseUnaryOp<Eigen::internal::scalar_opposite_op<float>, Eigen::Matrix<float, 1, 3, 1, 1, 3> const> > const&, Eigen::PlainObjectBase<Eigen::Matrix<CGAL::Lazy_exact_nt<CGAL::Gmpq>, -1, -1, 1, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, 1, 0, -1, 1> >&);
  84. #endif