tt.cpp 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "tt.h"
  2. #include "is_manifold.h"
  3. #include <algorithm>
  4. template <typename Scalar, typename Index>
  5. IGL_INLINE void igl::tt_preprocess(const Eigen::PlainObjectBase<Scalar>& /*V*/,
  6. const Eigen::PlainObjectBase<Index>& F,
  7. std::vector<std::vector<int> >& TTT)
  8. {
  9. for(int f=0;f<F.rows();++f)
  10. for (int i=0;i<F.cols();++i)
  11. {
  12. // v1 v2 f ei
  13. int v1 = F(f,i);
  14. int v2 = F(f,(i+1)%F.cols());
  15. if (v1 > v2) std::swap(v1,v2);
  16. std::vector<int> r(4);
  17. r[0] = v1; r[1] = v2;
  18. r[2] = f; r[3] = i;
  19. TTT.push_back(r);
  20. }
  21. std::sort(TTT.begin(),TTT.end());
  22. }
  23. // Extract the face adjacencies
  24. template <typename Index>
  25. IGL_INLINE void igl::tt_extractTT(const Eigen::PlainObjectBase<Index>& F,
  26. std::vector<std::vector<int> >& TTT,
  27. Eigen::PlainObjectBase<Index>& TT)
  28. {
  29. TT = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
  30. for(int i=1;i<(int)TTT.size();++i)
  31. {
  32. std::vector<int>& r1 = TTT[i-1];
  33. std::vector<int>& r2 = TTT[i];
  34. if ((r1[0] == r2[0]) && (r1[1] == r2[1]))
  35. {
  36. TT(r1[2],r1[3]) = r2[2];
  37. TT(r2[2],r2[3]) = r1[2];
  38. }
  39. }
  40. }
  41. // Extract the face adjacencies indices (needed for fast traversal)
  42. template <typename Index>
  43. IGL_INLINE void igl::tt_extractTTi(const Eigen::PlainObjectBase<Index>& F,
  44. std::vector<std::vector<int> >& TTT,
  45. Eigen::PlainObjectBase<Index>& TTi)
  46. {
  47. TTi = Eigen::PlainObjectBase<Index>::Constant((int)(F.rows()),F.cols(),-1);
  48. for(int i=1;i<(int)TTT.size();++i)
  49. {
  50. std::vector<int>& r1 = TTT[i-1];
  51. std::vector<int>& r2 = TTT[i];
  52. if ((r1[0] == r2[0]) && (r1[1] == r2[1]))
  53. {
  54. TTi(r1[2],r1[3]) = r2[3];
  55. TTi(r2[2],r2[3]) = r1[3];
  56. }
  57. }
  58. }
  59. // Compute triangle-triangle adjacency
  60. template <typename Scalar, typename Index>
  61. IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<Scalar>& V,
  62. const Eigen::PlainObjectBase<Index>& F,
  63. Eigen::PlainObjectBase<Index>& TT)
  64. {
  65. assert(igl::is_manifold(V,F));
  66. std::vector<std::vector<int> > TTT;
  67. tt_preprocess(V,F,TTT);
  68. tt_extractTT(F,TTT,TT);
  69. }
  70. // Compute triangle-triangle adjacency with indices
  71. template <typename Scalar, typename Index>
  72. IGL_INLINE void igl::tt(const Eigen::PlainObjectBase<Scalar>& V,
  73. const Eigen::PlainObjectBase<Index>& F,
  74. Eigen::PlainObjectBase<Index>& TT,
  75. Eigen::PlainObjectBase<Index>& TTi)
  76. {
  77. assert(igl::is_manifold(V,F));
  78. std::vector<std::vector<int> > TTT;
  79. tt_preprocess(V,F,TTT);
  80. tt_extractTT(F,TTT,TT);
  81. tt_extractTTi(F,TTT,TTi);
  82. }
  83. #ifndef IGL_HEADER_ONLY
  84. // Explicit template specialization
  85. // generated by autoexplicit.sh
  86. #endif