grad.h 1.4 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_MAT_H
  9. #define IGL_GRAD_MAT_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl {
  14. // GRAD
  15. // G = grad(V,F)
  16. //
  17. // Compute the numerical gradient operator
  18. //
  19. // Inputs:
  20. // V #vertices by 3 list of mesh vertex positions
  21. // F #faces by 3 list of mesh face indices
  22. // Outputs:
  23. // G #faces*dim by #V Gradient operator
  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 DerivedV, typename DerivedF>
  33. IGL_INLINE void grad(const Eigen::PlainObjectBase<DerivedV>&V,
  34. const Eigen::PlainObjectBase<DerivedF>&F,
  35. Eigen::SparseMatrix<typename DerivedV::Scalar> &G);
  36. }
  37. #ifndef IGL_STATIC_LIBRARY
  38. # include "grad.cpp"
  39. #endif
  40. #endif