cotmatrix.h 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2014 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_COTMATRIX_H
  9. #define IGL_COTMATRIX_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Dense>
  12. #include <Eigen/Sparse>
  13. // History:
  14. // Used const references rather than copying the entire mesh
  15. // Alec 9 October 2011
  16. // removed cotan (uniform weights) optional parameter it was building a buggy
  17. // half of the uniform laplacian, please see adjacency_matrix instead
  18. // Alec 9 October 2011
  19. namespace igl
  20. {
  21. /// Constructs the cotangent stiffness matrix (discrete laplacian) for a given
  22. /// mesh (V,F).
  23. ///
  24. /// @tparam DerivedV derived type of eigen matrix for V (e.g. derived from
  25. /// Eigen::MatrixXd)
  26. /// @tparam DerivedF derived type of eigen matrix for F (e.g. derived from
  27. /// Eigen::MatrixXi)
  28. /// @tparam Scalar scalar type for eigen sparse matrix (e.g. double)
  29. /// @param[in] V #V by dim list of mesh vertex positions
  30. /// @param[in] F #F by simplex_size list of mesh elements (triangles or tetrahedra)
  31. /// @param[out] L #V by #V cotangent matrix, each row i corresponding to V(i,:)
  32. ///
  33. /// \see
  34. /// adjacency_matrix
  35. ///
  36. /// \note This Laplacian uses the convention that diagonal entries are
  37. /// **minus** the sum of off-diagonal entries. The diagonal entries are
  38. /// therefore in general negative and the matrix is **negative** semi-definite
  39. /// (immediately, -L is **positive** semi-definite)
  40. ///
  41. template <typename DerivedV, typename DerivedF, typename Scalar>
  42. IGL_INLINE void cotmatrix(
  43. const Eigen::MatrixBase<DerivedV> & V,
  44. const Eigen::MatrixBase<DerivedF> & F,
  45. Eigen::SparseMatrix<Scalar>& L);
  46. /// Cotangent Laplacian (and mass matrix) for polygon meshes according to
  47. /// "Polygon Laplacian Made Simple" [Bunge et al.\ 2020]
  48. ///
  49. /// @param[in] V #V by 3 list of mesh vertex positions
  50. /// @param[in] I #I vectorized list of polygon corner indices into rows of some matrix V
  51. /// @param[in] C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) = size of
  52. /// the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the indices of
  53. /// the ith polygon
  54. /// @param[out] L #V by #V polygon Laplacian made simple matrix
  55. /// @param[out] M #V by #V mass matrix
  56. /// @param[out] P #V+#polygons by #V prolongation operator
  57. template <
  58. typename DerivedV,
  59. typename DerivedI,
  60. typename DerivedC,
  61. typename Scalar>
  62. IGL_INLINE void cotmatrix(
  63. const Eigen::MatrixBase<DerivedV> & V,
  64. const Eigen::MatrixBase<DerivedI> & I,
  65. const Eigen::MatrixBase<DerivedC> & C,
  66. Eigen::SparseMatrix<Scalar>& L,
  67. Eigen::SparseMatrix<Scalar>& M,
  68. Eigen::SparseMatrix<Scalar>& P);
  69. }
  70. #ifndef IGL_STATIC_LIBRARY
  71. # include "cotmatrix.cpp"
  72. #endif
  73. #endif