#include "half_space_box.h" #include "assign_scalar.h" #include #include template IGL_INLINE void igl::copyleft::cgal::half_space_box( const CGAL::Plane_3 & P, const Eigen::PlainObjectBase & V, Eigen::Matrix & BV, Eigen::Matrix & BF) { typedef CGAL::Plane_3 Plane; typedef CGAL::Point_3 Point; typedef CGAL::Vector_3 Vector; typedef CGAL::Epeck::FT EScalar; Eigen::RowVector3d avg = V.colwise().mean(); Point o3(avg(0),avg(1),avg(2)); Point o2 = P.projection(o3); Vector u; EScalar max_sqrd = -1; for(int v = 0;v vBV;vBV.reserve(8); Vector v = CGAL::cross_product(u,n); // Scale u,v,n to be longer than bbd const auto & longer_than = [](const EScalar min_sqr, Vector & x) { assert(x.squared_length() > 0); while(x.squared_length() < min_sqr) { x = 2.*x; } }; longer_than(bbd*bbd,u); longer_than(bbd*bbd,v); longer_than(bbd*bbd,n); vBV.emplace_back( o2 + u + v); vBV.emplace_back( o2 - u + v); vBV.emplace_back( o2 - u - v); vBV.emplace_back( o2 + u - v); vBV.emplace_back( o2 + u + v - n); vBV.emplace_back( o2 - u + v - n); vBV.emplace_back( o2 - u - v - n); vBV.emplace_back( o2 + u - v - n); BV.resize(8,3); for(int b = 0;b<8;b++) { igl::copyleft::cgal::assign_scalar(vBV[b].x(),BV(b,0)); igl::copyleft::cgal::assign_scalar(vBV[b].y(),BV(b,1)); igl::copyleft::cgal::assign_scalar(vBV[b].z(),BV(b,2)); } BF.resize(12,3); BF<< 1,0,2, 2,0,3, 4,5,6, 4,6,7, 0,1,4, 4,1,5, 1,2,5, 5,2,6, 2,3,6, 6,3,7, 3,0,7, 7,0,4; } template IGL_INLINE void igl::copyleft::cgal::half_space_box( const Eigen::PlainObjectBase & p, const Eigen::PlainObjectBase & n, const Eigen::PlainObjectBase & V, Eigen::Matrix & BV, Eigen::Matrix & BF) { typedef CGAL::Plane_3 Plane; typedef CGAL::Point_3 Point; typedef CGAL::Vector_3 Vector; Plane P(Point(p(0),p(1),p(2)),Vector(n(0),n(1),n(2))); return half_space_box(P,V,BV,BF); } template IGL_INLINE void igl::copyleft::cgal::half_space_box( const Eigen::PlainObjectBase & equ, const Eigen::PlainObjectBase & V, Eigen::Matrix & BV, Eigen::Matrix & BF) { typedef CGAL::Plane_3 Plane; Plane P(equ(0),equ(1),equ(2),equ(3)); return half_space_box(P,V,BV,BF); } #ifdef IGL_STATIC_LIBRARY // Explicit template specialization template void igl::copyleft::cgal::half_space_box, Eigen::Matrix, Eigen::Matrix >(Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::PlainObjectBase > const&, Eigen::Matrix, 8, 3, 0, 8, 3>&, Eigen::Matrix&); #endif