facet_components.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  1. #include "facet_components.h"
  2. #include <igl/triangle_triangle_adjacency.h>
  3. #include <vector>
  4. #include <queue>
  5. template <typename DerivedF, typename DerivedC>
  6. IGL_INLINE void igl::facet_components(
  7. const Eigen::PlainObjectBase<DerivedF> & F,
  8. Eigen::PlainObjectBase<DerivedC> & C)
  9. {
  10. using namespace std;
  11. using namespace igl;
  12. typedef typename DerivedF::Index Index;
  13. vector<vector<vector<Index > > > TT;
  14. vector<vector<vector<Index > > > TTi;
  15. triangle_triangle_adjacency(F,TT,TTi);
  16. return facet_components(TT,C);
  17. }
  18. template <
  19. typename TTIndex,
  20. typename DerivedC>
  21. IGL_INLINE void igl::facet_components(
  22. const std::vector<std::vector<std::vector<TTIndex > > > & TT,
  23. Eigen::PlainObjectBase<DerivedC> & C)
  24. {
  25. using namespace std;
  26. using namespace igl;
  27. typedef TTIndex Index;
  28. const Index m = TT.size();
  29. C.resize(m,1);
  30. vector<bool> seen(m,false);
  31. Index id = 0;
  32. for(Index g = 0;g<m;g++)
  33. {
  34. if(seen[g])
  35. {
  36. continue;
  37. }
  38. queue<Index> Q;
  39. Q.push(g);
  40. while(!Q.empty())
  41. {
  42. const Index f = Q.front();
  43. Q.pop();
  44. if(seen[f])
  45. {
  46. continue;
  47. }
  48. seen[f] = true;
  49. C(f,0) = id;
  50. // Face f's neighbor lists opposite opposite each corner
  51. for(const auto & c : TT[f])
  52. {
  53. // Each neighbor
  54. for(const auto & n : c)
  55. {
  56. if(!seen[n])
  57. {
  58. Q.push(n);
  59. }
  60. }
  61. }
  62. }
  63. id++;
  64. }
  65. }
  66. #ifdef IGL_STATIC_LIBRARY
  67. // Explicit template specialization
  68. template void igl::facet_components<long, Eigen::Matrix<long, -1, 1, 0, -1, 1> >(std::vector<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > >, std::allocator<std::vector<std::vector<long, std::allocator<long> >, std::allocator<std::vector<long, std::allocator<long> > > > > > const&, Eigen::PlainObjectBase<Eigen::Matrix<long, -1, 1, 0, -1, 1> >&);
  69. #endif