adjacency_matrix.h 2.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  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_ADJACENCY_MATRIX_H
  9. #define IGL_ADJACENCY_MATRIX_H
  10. #include "igl_inline.h"
  11. #define EIGEN_YES_I_KNOW_SPARSE_MODULE_IS_NOT_STABLE_YET
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. namespace igl
  15. {
  16. /// Constructs the graph adjacency matrix of a given mesh (V,F)
  17. ///
  18. /// @tparam T should be a eigen sparse matrix primitive type like `int` or `double`
  19. /// @param[in] F #F by dim list of mesh simplices
  20. /// @param[out] A max(F)+1 by max(F)+1 adjacency matrix, each row i corresponding to V(i,:)
  21. ///
  22. /// #### Example
  23. /// \code{.cpp}
  24. /// // Mesh in (V,F)
  25. /// Eigen::SparseMatrix<double> A;
  26. /// adjacency_matrix(F,A);
  27. /// // sum each row
  28. /// SparseVector<double> Asum;
  29. /// sum(A,1,Asum);
  30. /// // Convert row sums into diagonal of sparse matrix
  31. /// Eigen::SparseMatrix<double> Adiag;
  32. /// diag(Asum,Adiag);
  33. /// // Build uniform laplacian
  34. /// Eigen::SparseMatrix<double> U;
  35. /// U = A-Adiag;
  36. /// \endcode
  37. ///
  38. /// \see
  39. /// edges,
  40. /// cotmatrix,
  41. /// diag
  42. template <typename DerivedF, typename T>
  43. IGL_INLINE void adjacency_matrix(
  44. const Eigen::MatrixBase<DerivedF> & F,
  45. Eigen::SparseMatrix<T>& A);
  46. /// Constructs an vertex adjacency for a polygon mesh.
  47. ///
  48. /// @param[in] I #I vectorized list of polygon corner indices into rows of some matrix V
  49. /// @param[in] C #polygons+1 list of cumulative polygon sizes so that C(i+1)-C(i) =
  50. /// size of the ith polygon, and so I(C(i)) through I(C(i+1)-1) are the
  51. /// indices of the ith polygon
  52. /// @param[out] A max(I)+1 by max(I)+1 adjacency matrix, each row i corresponding to V(i,:)
  53. ///
  54. template <typename DerivedI, typename DerivedC, typename T>
  55. IGL_INLINE void adjacency_matrix(
  56. const Eigen::MatrixBase<DerivedI> & I,
  57. const Eigen::MatrixBase<DerivedC> & C,
  58. Eigen::SparseMatrix<T>& A);
  59. }
  60. #ifndef IGL_STATIC_LIBRARY
  61. # include "adjacency_matrix.cpp"
  62. #endif
  63. #endif