gaussian_curvature.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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 "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::PlainObjectBase<DerivedV>& V,
  15. const Eigen::PlainObjectBase<DerivedF>& F,
  16. Eigen::PlainObjectBase<DerivedK> & K)
  17. {
  18. using namespace Eigen;
  19. using namespace std;
  20. // internal corner angles
  21. Matrix<
  22. typename DerivedV::Scalar,
  23. DerivedF::RowsAtCompileTime,
  24. DerivedF::ColsAtCompileTime> A;
  25. internal_angles(V,F,A);
  26. K.resize(V.rows(),1);
  27. K.setConstant(V.rows(),1,2.*PI);
  28. assert(A.rows() == F.rows());
  29. assert(A.cols() == F.cols());
  30. assert(K.rows() == V.rows());
  31. assert(F.maxCoeff() < V.rows());
  32. assert(K.cols() == 1);
  33. const int Frows = F.rows();
  34. //K_G(x_i) = (2π - ∑θj)
  35. //#ifndef IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE
  36. //# define IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE 1000
  37. //#endif
  38. //#pragma omp parallel for if (Frows>IGL_GAUSSIAN_CURVATURE_OMP_MIN_VALUE)
  39. for(int f = 0;f<Frows;f++)
  40. {
  41. // throw normal at each corner
  42. for(int j = 0; j < 3;j++)
  43. {
  44. // Q: Does this need to be critical?
  45. // H: I think so, sadly. Maybe there's a way to use reduction
  46. //#pragma omp critical
  47. K(F(f,j),0) -= A(f,j);
  48. }
  49. }
  50. }
  51. #ifdef IGL_STATIC_LIBRARY
  52. // Explicit template specialization
  53. 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::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> >&);
  54. 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::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> >&);
  55. #endif