grad.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  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. #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: grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 /
  27. // 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A where Xi is the scalar value at vertex
  28. // i, Vi is the 3D position of vertex i, and A is the area of triangle
  29. // (i,j,k). ^R90 represent a rotation of 90 degrees
  30. //
  31. template <typename T, typename S>
  32. IGL_INLINE void grad(
  33. const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
  34. const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic> &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