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