components.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2015 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_COMPONENTS_H
  9. #define IGL_COMPONENTS_H
  10. #include "igl_inline.h"
  11. #include <Eigen/Core>
  12. #include <Eigen/Sparse>
  13. namespace igl
  14. {
  15. // Compute connected components of a graph represented by an adjacency
  16. // matrix. This version is faster than the previous version using boost.
  17. //
  18. // Inputs:
  19. // A n by n adjacency matrix
  20. // Outputs:
  21. // C n list of component ids (starting with 0)
  22. // counts #components list of counts for each component
  23. //
  24. template <typename AScalar, typename DerivedC, typename Derivedcounts>
  25. IGL_INLINE void components(
  26. const Eigen::SparseMatrix<AScalar> & A,
  27. Eigen::PlainObjectBase<DerivedC> & C,
  28. Eigen::PlainObjectBase<Derivedcounts> & counts);
  29. template <typename AScalar, typename DerivedC>
  30. IGL_INLINE void components(
  31. const Eigen::SparseMatrix<AScalar> & A,
  32. Eigen::PlainObjectBase<DerivedC> & C);
  33. // Ditto but for mesh faces as input. This computes connected components of
  34. // **vertices** where **edges** establish connectivity.
  35. //
  36. // Inputs:
  37. // F n by 3 list of triangle indices
  38. // Outputs:
  39. // C max(F) list of component ids
  40. template <typename DerivedF, typename DerivedC>
  41. IGL_INLINE void components(
  42. const Eigen::PlainObjectBase<DerivedF> & F,
  43. Eigen::PlainObjectBase<DerivedC> & C);
  44. }
  45. #ifndef IGL_STATIC_LIBRARY
  46. # include "components.cpp"
  47. #endif
  48. #endif