is_manifold.cpp 2.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 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. #include "is_manifold.h"
  9. #include <algorithm>
  10. template <typename DerivedV, typename DerivedF>
  11. IGL_INLINE bool igl::is_manifold(const Eigen::PlainObjectBase<DerivedV>& /*V*/,
  12. const Eigen::PlainObjectBase<DerivedF>& F)
  13. {
  14. std::vector<std::vector<int> > TTT;
  15. for(int f=0;f<F.rows();++f)
  16. for (int i=0;i<3;++i)
  17. {
  18. // v1 v2 f ei
  19. int v1 = F(f,i);
  20. int v2 = F(f,(i+1)%3);
  21. if (v1 > v2) std::swap(v1,v2);
  22. std::vector<int> r(4);
  23. r[0] = v1; r[1] = v2;
  24. r[2] = f; r[3] = i;
  25. TTT.push_back(r);
  26. }
  27. std::sort(TTT.begin(),TTT.end());
  28. for(int i=2;i<(int)TTT.size();++i)
  29. {
  30. std::vector<int>& r1 = TTT[i-2];
  31. std::vector<int>& r2 = TTT[i-1];
  32. std::vector<int>& r3 = TTT[i];
  33. if ( (r1[0] == r2[0] && r2[0] == r3[0])
  34. &&
  35. (r1[1] == r2[1] && r2[1] == r3[1]) )
  36. {
  37. return false;
  38. }
  39. }
  40. return true;
  41. }
  42. #ifndef IGL_HEADER_ONLY
  43. // Explicit template specialization
  44. // generated by autoexplicit.sh
  45. template bool igl::is_manifold<Eigen::Matrix<float, -1, 3, 1, -1, 3>, Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<float, -1, 3, 1, -1, 3> > const&, Eigen::PlainObjectBase<Eigen::Matrix<unsigned int, -1, -1, 1, -1, -1> > const&);
  46. // generated by autoexplicit.sh
  47. //template bool igl::is_manifold<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&);
  48. template bool igl::is_manifold<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&);
  49. #endif