euler_characteristic.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2016 Michael Rabinovich <michaelrabinovich27@gmail.com@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. #include "euler_characteristic.h"
  9. #include "edge_topology.h"
  10. #include "edges.h"
  11. template <typename Scalar, typename Index>
  12. IGL_INLINE int igl::euler_characteristic(
  13. const Eigen::PlainObjectBase<Scalar> & V,
  14. const Eigen::PlainObjectBase<Index> & F)
  15. {
  16. int euler_v = V.rows();
  17. Eigen::MatrixXi EV, FE, EF;
  18. igl::edge_topology(V, F, EV, FE, EF);
  19. int euler_e = EV.rows();
  20. int euler_f = F.rows();
  21. int euler_char = euler_v - euler_e + euler_f;
  22. return euler_char;
  23. }
  24. template <typename DerivedF>
  25. IGL_INLINE int igl::euler_characteristic(
  26. const Eigen::MatrixBase<DerivedF> & F)
  27. {
  28. const int nf = F.rows();
  29. const int nv = F.maxCoeff()+1;
  30. Eigen::Matrix<typename DerivedF::Scalar,Eigen::Dynamic,2> E;
  31. edges(F,E);
  32. const int ne = E.rows();
  33. return nv - ne + nf;
  34. }
  35. #ifdef IGL_STATIC_LIBRARY
  36. // Explicit template instantiation
  37. template int igl::euler_characteristic<Eigen::Matrix<double, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<double, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  38. template int igl::euler_characteristic<Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::MatrixBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&);
  39. #endif