quad_planarity.cpp 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Alec Jacobson <alecjacobson@gmail.com>
  4. //
  5. // This Source Code Form is subject to the terms of the Mozilla Public License
  6. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  7. // obtain one at http://mozilla.org/MPL/2.0/.
  8. #include "quad_planarity.h"
  9. #include <Eigen/Geometry>
  10. template <typename DerivedV, typename DerivedF, typename DerivedP>
  11. IGL_INLINE void igl::quad_planarity(
  12. const Eigen::PlainObjectBase<DerivedV>& V,
  13. const Eigen::PlainObjectBase<DerivedF>& F,
  14. Eigen::PlainObjectBase<DerivedP> & P)
  15. {
  16. int nf = F.rows();
  17. P.setZero(nf,1);
  18. for (int i =0; i<nf; ++i)
  19. {
  20. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v1 = V.row(F(i,0));
  21. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v2 = V.row(F(i,1));
  22. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v3 = V.row(F(i,2));
  23. const Eigen::Matrix<typename DerivedV::Scalar,1,3> &v4 = V.row(F(i,3));
  24. Eigen::Matrix<typename DerivedV::Scalar,1,3> diagCross=(v3-v1).cross(v4-v2);
  25. typename Eigen::PlainObjectBase<DerivedV>::Scalar denom = diagCross.norm()*(((v3-v1).norm()+(v4-v2).norm())/2);
  26. if (fabs(denom)<1e-8)
  27. //degenerate quad is still planar
  28. P[i] = 0;
  29. else
  30. P[i] = (diagCross.dot(v2-v1)/denom);
  31. }
  32. }
  33. #ifdef IGL_STATIC_LIBRARY
  34. // Explicit template specialization
  35. 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> >&);
  36. #endif