angles.cpp 1.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 Daniele Panozzo <daniele.panozzo@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 "angles.h"
  9. #include <cassert>
  10. template <
  11. typename DerivedV,
  12. typename DerivedF,
  13. typename Derivedtheta>
  14. void igl::angles(
  15. Eigen::PlainObjectBase<DerivedV>& V,
  16. Eigen::PlainObjectBase<DerivedF>& F,
  17. Eigen::PlainObjectBase<Derivedtheta>& theta)
  18. {
  19. theta.resize(F.rows(),F.cols());
  20. auto corner = [](const Eigen::PlainObjectBase<DerivedV>& x, const Eigen::PlainObjectBase<DerivedV>& y, const Eigen::PlainObjectBase<DerivedV>& z)
  21. {
  22. Eigen::RowVector3d v1 = (x-y).normalized();
  23. Eigen::RowVector3d v2 = (z-y).normalized();
  24. return acos(v1 * v2.transpose());
  25. };
  26. for(unsigned i=0; i<F.rows(); ++i)
  27. {
  28. for(unsigned j=0; j<F.cols(); ++j)
  29. {
  30. theta(i,j) = corner(
  31. V.row(F(i,int(j-1+F.cols())%F.cols())),
  32. V.row(F(i,j)),
  33. V.row(F(i,(j+1+F.cols())%F.cols()))
  34. );
  35. }
  36. }
  37. }
  38. }
  39. #ifdef IGL_STATIC_LIBRARY
  40. // Explicit template specialization
  41. #endif