gaussian_curvature.cpp 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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 "gaussian_curvature.h"
  9. #include "internal_angles.h"
  10. #include "PI.h"
  11. #include <iostream>
  12. template <typename DerivedV, typename DerivedF, typename DerivedK>
  13. IGL_INLINE void igl::gaussian_curvature(
  14. const Eigen::MatrixBase<DerivedV>& V,
  15. const Eigen::MatrixBase<DerivedF>& F,
  16. Eigen::PlainObjectBase<DerivedK> & K)
  17. {
  18. // internal corner angles
  19. Eigen::Matrix<
  20. typename DerivedV::Scalar,
  21. DerivedF::RowsAtCompileTime,
  22. DerivedF::ColsAtCompileTime> A;
  23. internal_angles(V,F,A);
  24. K.resize(V.rows(),1);
  25. K.setConstant(V.rows(),1,2.*PI);
  26. assert(A.rows() == F.rows());
  27. assert(A.cols() == F.cols());
  28. assert(K.rows() == V.rows());
  29. assert(F.maxCoeff() < V.rows());
  30. assert(K.cols() == 1);
  31. const int Frows = F.rows();
  32. //K_G(x_i) = (2π - ∑θj)
  33. for(int f = 0;f<Frows;f++)
  34. {
  35. // throw normal at each corner
  36. for(int j = 0; j < 3;j++)
  37. {
  38. K(F(f,j),0) -= A(f,j);
  39. }
  40. }
  41. }
  42. #ifdef IGL_STATIC_LIBRARY
  43. // Explicit template instantiation
  44. template void igl::gaussian_curvature<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::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> >&);
  45. template void igl::gaussian_curvature<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::MatrixBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<double, -1, 1, 0, -1, 1> >&);
  46. #endif