is_edge_manifold.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  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_edge_manifold.h"
  9. #include <algorithm>
  10. template <typename DerivedV, typename DerivedF>
  11. IGL_INLINE bool igl::is_edge_manifold(const Eigen::PlainObjectBase<DerivedV>& /*V*/,
  12. const Eigen::PlainObjectBase<DerivedF>& F)
  13. {
  14. // List of edges (i,j,f,c) where edge i<j is associated with corner i of face
  15. // f
  16. std::vector<std::vector<int> > TTT;
  17. for(int f=0;f<F.rows();++f)
  18. for (int i=0;i<3;++i)
  19. {
  20. // v1 v2 f ei
  21. int v1 = F(f,i);
  22. int v2 = F(f,(i+1)%3);
  23. if (v1 > v2) std::swap(v1,v2);
  24. std::vector<int> r(4);
  25. r[0] = v1; r[1] = v2;
  26. r[2] = f; r[3] = i;
  27. TTT.push_back(r);
  28. }
  29. // Sort lexicographically
  30. std::sort(TTT.begin(),TTT.end());
  31. for(int i=2;i<(int)TTT.size();++i)
  32. {
  33. // Check any edges occur 3 times
  34. std::vector<int>& r1 = TTT[i-2];
  35. std::vector<int>& r2 = TTT[i-1];
  36. std::vector<int>& r3 = TTT[i];
  37. if ( (r1[0] == r2[0] && r2[0] == r3[0])
  38. &&
  39. (r1[1] == r2[1] && r2[1] == r3[1]) )
  40. {
  41. return false;
  42. }
  43. }
  44. return true;
  45. }
  46. #ifdef IGL_STATIC_LIBRARY
  47. // Explicit template specialization
  48. // generated by autoexplicit.sh
  49. template bool igl::is_edge_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&);
  50. // generated by autoexplicit.sh
  51. //template bool igl::is_edge_manifold<double>(Eigen::Matrix<double, -1, -1, 0, -1, -1> const&, Eigen::Matrix<int, -1, -1, 0, -1, -1> const&);
  52. template bool igl::is_edge_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&);
  53. #endif