gradMat.h 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445
  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 T, typename S>
  33. IGL_INLINE void gradMat(const Eigen::Matrix<T, Eigen::Dynamic, Eigen::Dynamic> &V,
  34. const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic> &F,
  35. Eigen::SparseMatrix<T> &G);
  36. }
  37. #ifdef IGL_HEADER_ONLY
  38. # include "gradMat.cpp"
  39. #endif
  40. #endif