euler_characteristic.h 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Michael Rabinovich <[email protected]>
  4. // Copyright (C) 2017 Alec Jacobson <[email protected]>
  5. //
  6. // This Source Code Form is subject to the terms of the Mozilla Public License
  7. // v. 2.0. If a copy of the MPL was not distributed with this file, You can
  8. // obtain one at http://mozilla.org/MPL/2.0/.
  9. #ifndef IGL_EULER_CHARACTERISTIC_H
  10. #define IGL_EULER_CHARACTERISTIC_H
  11. #include "igl_inline.h"
  12. #include <Eigen/Dense>
  13. #include <Eigen/Sparse>
  14. #include <vector>
  15. namespace igl
  16. {
  17. /// Computes the Euler characteristic of a given mesh (V,F)
  18. ///
  19. /// χ = |V| - |E| + |F|
  20. ///
  21. /// For example,
  22. /// - a single triangle has 3 - 3 + 1 = 1
  23. /// - a tetrahedron has 4 - 6 + 4 = 2
  24. ///
  25. /// @param[in] F #F by dim list of mesh faces (must be triangles)
  26. /// @return An int containing the Euler characteristic
  27. ///
  28. /// \note There is [some confusion](https://github.com/libigl/libigl/issues/2249#issue-1863608449) over the standard definition of Euler
  29. /// characteristic. libigl's definition agrees with
  30. /// [wikipedia](https://en.wikipedia.org/wiki/Euler_characteristic) and [David
  31. /// Eppstein's
  32. /// proofs](https://www.ics.uci.edu/~eppstein/junkyard/euler/all.html).
  33. template <typename DerivedF>
  34. IGL_INLINE int euler_characteristic(
  35. const Eigen::MatrixBase<DerivedF> & F);
  36. }
  37. #ifndef IGL_STATIC_LIBRARY
  38. # include "euler_characteristic.cpp"
  39. #endif
  40. #endif