grad.h 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. #ifndef IGL_GRAD_H
  2. #define IGL_GRAD_H
  3. #include "igl_inline.h"
  4. #include <Eigen/Core>
  5. namespace igl {
  6. // GRAD
  7. // G = grad(V,F,X)
  8. //
  9. // Compute the numerical gradient at every face of a triangle mesh.
  10. //
  11. // Inputs:
  12. // V #vertices by 3 list of mesh vertex positions
  13. // F #faces by 3 list of mesh face indices
  14. // X # vertices list of scalar function values
  15. // Outputs:
  16. // G #faces by 3 list of gradient values
  17. //
  18. // Gradient of a scalar function defined on piecewise linear elements (mesh)
  19. // is constant on each triangle i,j,k: grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 /
  20. // 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A where Xi is the scalar value at vertex
  21. // i, Vi is the 3D position of vertex i, and A is the area of triangle
  22. // (i,j,k). ^R90 represent a rotation of 90 degrees
  23. //
  24. template <typename T, typename S>
  25. IGL_INLINE void grad(
  26. const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
  27. const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic> &F,
  28. const Eigen::Matrix<T, Eigen::Dynamic, 1>&X,
  29. Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &G );
  30. }
  31. #ifdef IGL_HEADER_ONLY
  32. # include "grad.cpp"
  33. #endif
  34. #endif