quad_planarity.cpp 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839
  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 DerivedV::Scalar denom =
  26. diagCross.norm()*(((v3-v1).norm()+(v4-v2).norm())/2);
  27. if (fabs(denom)<1e-8)
  28. //degenerate quad is still planar
  29. P[i] = 0;
  30. else
  31. P[i] = (diagCross.dot(v2-v1)/denom);
  32. }
  33. }
  34. #ifdef IGL_STATIC_LIBRARY
  35. // Explicit template instantiation
  36. 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> >&);
  37. #endif