coplanar.cpp 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  1. #include "coplanar.h"
  2. #include "row_to_point.h"
  3. #include <CGAL/Exact_predicates_inexact_constructions_kernel.h>
  4. #include <CGAL/Point_3.h>
  5. template <typename DerivedV>
  6. IGL_INLINE bool igl::copyleft::cgal::coplanar(
  7. const Eigen::MatrixBase<DerivedV> & V)
  8. {
  9. // 3 points in 3D are always coplanar
  10. if(V.rows() < 4){ return true; }
  11. // spanning points found so far
  12. std::vector<CGAL::Point_3<CGAL::Epick> > p;
  13. for(int i = 0;i<V.rows();i++)
  14. {
  15. const CGAL::Point_3<CGAL::Epick> pi(V(i,0), V(i,1), V(i,2));
  16. switch(p.size())
  17. {
  18. case 0:
  19. p.push_back(pi);
  20. break;
  21. case 1:
  22. if(p[0] != pi)
  23. {
  24. p.push_back(pi);
  25. }
  26. break;
  27. case 2:
  28. if(!CGAL::collinear(p[0],p[1],pi))
  29. {
  30. p.push_back(pi);
  31. }
  32. break;
  33. case 3:
  34. if(!CGAL::coplanar(p[0],p[1],p[2],pi))
  35. {
  36. return false;
  37. }
  38. break;
  39. }
  40. }
  41. return true;
  42. }
  43. #ifdef IGL_STATIC_LIBRARY
  44. // Explicit template instantiation
  45. template bool igl::copyleft::cgal::coplanar<Eigen::Matrix<double, -1, 3, 0, -1, 3> >(Eigen::MatrixBase<Eigen::Matrix<double, -1, 3, 0, -1, 3> > const&);
  46. #endif