grad.h 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647
  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. #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 [or a #faces by 4 list of tetrahedral indices]
  22. // uniform boolean (default false) - Use a uniform mesh instead of the vertices V
  23. // Outputs:
  24. // G #faces*dim by #V Gradient operator
  25. //
  26. // Gradient of a scalar function defined on piecewise linear elements (mesh)
  27. // is constant on each triangle [tetrahedron] i,j,k:
  28. // grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
  29. // where Xi is the scalar value at vertex i, Vi is the 3D position of vertex
  30. // i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of
  31. // 90 degrees
  32. //
  33. template <typename DerivedV, typename DerivedF>
  34. IGL_INLINE void grad(
  35. const Eigen::MatrixBase<DerivedV>&V,
  36. const Eigen::MatrixBase<DerivedF>&F,
  37. Eigen::SparseMatrix<typename DerivedV::Scalar> &G,
  38. bool uniform = false);
  39. }
  40. #ifndef IGL_STATIC_LIBRARY
  41. # include "grad.cpp"
  42. #endif
  43. #endif