grad.h 1.2 KB

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