quad_planarity.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031
  1. #include "quad_planarity.h"
  2. #include <Eigen/Geometry>
  3. template <typename DerivedV, typename DerivedF, typename DerivedP>
  4. IGL_INLINE void igl::quad_planarity(
  5. const Eigen::PlainObjectBase<DerivedV>& V,
  6. const Eigen::PlainObjectBase<DerivedF>& F,
  7. Eigen::PlainObjectBase<DerivedP> & P)
  8. {
  9. int nf = F.rows();
  10. P.setZero(nf,1);
  11. for (int i =0; i<nf; ++i)
  12. {
  13. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v1 = V.row(F(i,0));
  14. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v2 = V.row(F(i,1));
  15. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v3 = V.row(F(i,2));
  16. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v4 = V.row(F(i,3));
  17. Eigen::Matrix<typename DerivedV::Scalar,1,3> diagCross=(v3-v1).cross(v4-v2);
  18. typename Eigen::PlainObjectBase<DerivedV>::Scalar denom = diagCross.norm()*(((v3-v1).norm()+(v4-v2).norm())/2);
  19. if (fabs(denom)<1e-8)
  20. //degenerate quad is still planar
  21. P[i] = 0;
  22. else
  23. P[i] = (diagCross.dot(v2-v1)/denom);
  24. }
  25. }
  26. #ifdef IGL_STATIC_LIBRARY
  27. // Explicit template specialization
  28. template void igl::quad_planarity<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<double, -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, 1, 0, -1, 1> >&);
  29. #endif