cross_field_missmatch.cpp 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151
  1. #include "cross_field_missmatch.h"
  2. #include "comb_cross_field.h"
  3. #include <vector>
  4. #include <deque>
  5. #include "per_face_normals.h"
  6. #include "is_border_vertex.h"
  7. #include "vf.h"
  8. #include "tt.h"
  9. //namespace igl {
  10. // template <typename DerivedV, typename DerivedF, typename DerivedO>
  11. // class MissMatchCalculator
  12. // {
  13. // public:
  14. //
  15. // const Eigen::PlainObjectBase<DerivedV> &V;
  16. // const Eigen::PlainObjectBase<DerivedF> &F;
  17. // const Eigen::PlainObjectBase<DerivedV> &PD1;
  18. // const Eigen::PlainObjectBase<DerivedV> &PD2;
  19. // Eigen::PlainObjectBase<DerivedV> N;
  20. //
  21. // private:
  22. // // internal
  23. // std::vector<bool> V_border; // bool
  24. // std::vector<std::vector<int> > VF;
  25. // std::vector<std::vector<int> > VFi;
  26. // Eigen::PlainObjectBase<DerivedF> TT;
  27. // Eigen::PlainObjectBase<DerivedF> TTi;
  28. //
  29. //
  30. // private:
  31. //
  32. // ///return true if a vertex is singluar by looking at initialized missmatches
  33. // // possible bugs, verify deleted flag vs IsD()
  34. // // not sorted vf, but should not make a difference
  35. // // olga: TODO: this returns the index modulo 4.
  36. // int oneRingMissMatch(const int vid)
  37. // {
  38. // ///check that is on border..
  39. // if (V_border[vid])
  40. // return 0;
  41. //
  42. // int missmatch=0;
  43. // for (unsigned int i=0;i<VF[vid].size();i++)
  44. // {
  45. // // look for the vertex
  46. // int j=-1;
  47. // for (unsigned z=0; z<3; ++z)
  48. // if (F(VF[vid][i],z) == vid)
  49. // j=z;
  50. // assert(j!=-1);
  51. //
  52. // missmatch+=Handle_MMatch(VF[vid][i],j);
  53. // }
  54. //
  55. // missmatch=missmatch%4;
  56. // return missmatch;
  57. // }
  58. //
  59. //
  60. // ///compute the mismatch between 2 faces
  61. // int MissMatchByCross(const int f0,
  62. // const int f1)
  63. // {
  64. // Eigen::Matrix<typename DerivedV::Scalar, 3, 1> dir0 = PD1.row(f0);
  65. // Eigen::Matrix<typename DerivedV::Scalar, 3, 1> dir1 = PD1.row(f1);
  66. // Eigen::Matrix<typename DerivedV::Scalar, 3, 1> n0 = N.row(f0);
  67. // Eigen::Matrix<typename DerivedV::Scalar, 3, 1> n1 = N.row(f1);
  68. //
  69. // Eigen::Matrix<typename DerivedV::Scalar, 3, 1> dir1Rot = Comb<DerivedV, DerivedF>::Rotate(n1,n0,dir1);
  70. // dir1Rot.normalize();
  71. //
  72. // // TODO: this should be equivalent to the other code below, to check!
  73. // // Compute the angle between the two vectors
  74. // // double a0 = atan2(dir0.dot(B2.row(f0)),dir0.dot(B1.row(f0)));
  75. // // double a1 = atan2(dir1Rot.dot(B2.row(f0)),dir1Rot.dot(B1.row(f0)));
  76. // //
  77. // // double angle_diff = a1-a0; //VectToAngle(f0,dir1Rot);
  78. //
  79. // double angle_diff = atan2(dir1Rot.dot(PD2.row(f0)),dir1Rot.dot(PD1.row(f0)));
  80. //
  81. // // std::cerr << "Dani: " << dir0(0) << " " << dir0(1) << " " << dir0(2) << " " << dir1Rot(0) << " " << dir1Rot(1) << " " << dir1Rot(2) << " " << angle_diff << std::endl;
  82. //
  83. // double step=M_PI/2.0;
  84. // int i=(int)floor((angle_diff/step)+0.5);
  85. // int k=0;
  86. // if (i>=0)
  87. // k=i%4;
  88. // else
  89. // k=(-(3*i))%4;
  90. // return k;
  91. // }
  92. //
  93. //
  94. //public:
  95. // MissMatchCalculator(const Eigen::PlainObjectBase<DerivedV> &_V,
  96. // const Eigen::PlainObjectBase<DerivedF> &_F,
  97. // const Eigen::PlainObjectBase<DerivedV> &_PD1,
  98. // const Eigen::PlainObjectBase<DerivedV> &_PD2
  99. // ):
  100. // V(_V),
  101. // F(_F),
  102. // PD1(_PD1),
  103. // PD2(_PD2)
  104. // {
  105. // igl::per_face_normals(V,F,N);
  106. // V_border = igl::is_border_vertex(V,F);
  107. // igl::vf(V,F,VF,VFi);
  108. // igl::tt(V,F,TT,TTi);
  109. // }
  110. //
  111. // void calculateMissmatch(Eigen::PlainObjectBase<DerivedO> &Handle_MMatch)
  112. // {
  113. // Handle_MMatch.setConstant(F.rows(),3,-1);
  114. // for (unsigned int i=0;i<F.rows();i++)
  115. // {
  116. // for (int j=0;j<3;j++)
  117. // {
  118. // if (i==TT(i,j) || TT(i,j) == -1)
  119. // Handle_MMatch(i,j)=0;
  120. // else
  121. // Handle_MMatch(i,j) = MissMatchByCross(i,TT(i,j));
  122. // }
  123. // }
  124. // }
  125. //
  126. //};
  127. //}
  128. //template <typename DerivedV, typename DerivedF, typename DerivedO>
  129. //IGL_INLINE void igl::cross_field_missmatch(const Eigen::PlainObjectBase<DerivedV> &V,
  130. // const Eigen::PlainObjectBase<DerivedF> &F,
  131. // const Eigen::PlainObjectBase<DerivedV> &PD1,
  132. // const Eigen::PlainObjectBase<DerivedV> &PD2,
  133. // const bool isCombed,
  134. // Eigen::PlainObjectBase<DerivedO> &missmatch)
  135. //{
  136. // Eigen::PlainObjectBase<DerivedV> PD1_combed;
  137. // Eigen::PlainObjectBase<DerivedV> PD2_combed;
  138. //
  139. // if (!isCombed)
  140. // igl::comb_cross_field(V,F,PD1,PD2,PD1_combed,PD2_combed);
  141. // else
  142. // {
  143. // PD1_combed = PD1;
  144. // PD2_combed = PD2;
  145. // }
  146. // igl::MissMatchCalculator<DerivedV, DerivedF, DerivedO> sf(V, F, PD1_combed, PD2_combed);
  147. // sf.calculateMissmatch(missmatch);
  148. //}