grad.h 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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. /// Gradient operator on a triangle mesh.
  15. /// Gradient of a scalar function defined on piecewise linear elements (mesh)
  16. /// is constant on each triangle [tetrahedron] i,j,k:
  17. /// grad(Xijk) = (Xj-Xi) * (Vi - Vk)^R90 / 2A + (Xk-Xi) * (Vj - Vi)^R90 / 2A
  18. /// where Xi is the scalar value at vertex i, Vi is the 3D position of vertex
  19. /// i, and A is the area of triangle (i,j,k). ^R90 represent a rotation of
  20. /// 90 degrees
  21. ///
  22. /// @param[in] V #vertices by 3 list of mesh vertex positions
  23. /// @param[in] F #faces by 3 list of mesh face indices [or a #faces by 4 list of tetrahedral indices]
  24. /// @param[out] G #faces*dim by #V Gradient operator
  25. /// @param[in] uniform boolean (default false) - Use a uniform mesh instead of the vertices V
  26. ///
  27. template <typename DerivedV, typename DerivedF>
  28. IGL_INLINE void grad(
  29. const Eigen::MatrixBase<DerivedV>&V,
  30. const Eigen::MatrixBase<DerivedF>&F,
  31. Eigen::SparseMatrix<typename DerivedV::Scalar> &G,
  32. bool uniform = false);
  33. }
  34. #ifndef IGL_STATIC_LIBRARY
  35. # include "grad.cpp"
  36. #endif
  37. #endif