2
0

connected_components.h 1.3 KB

12345678910111213141516171819202122232425262728293031323334
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2020 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_CONNECTED_COMPONENTS_H
  9. #define IGL_CONNECTED_COMPONENTS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. /// Determine the connected components of a graph described by the input
  16. /// adjacency matrix (similar to MATLAB's graphconncomp or gptoolbox's
  17. /// conncomp, but A is transposed for unsymmetric graphs).
  18. ///
  19. /// @param[in] A #A by #A adjacency matrix (treated as describing an directed graph)
  20. /// @param[out] C #A list of component indices into [0,#K-1]
  21. /// @param[out] K #K list of sizes of each component
  22. /// @return number of connected components
  23. template < typename Atype, typename DerivedC, typename DerivedK>
  24. IGL_INLINE int connected_components(
  25. const Eigen::SparseMatrix<Atype> & A,
  26. Eigen::PlainObjectBase<DerivedC> & C,
  27. Eigen::PlainObjectBase<DerivedK> & K);
  28. }
  29. #ifndef IGL_STATIC_LIBRARY
  30. # include "connected_components.cpp"
  31. #endif
  32. #endif