pos.h 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126
  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. #ifndef IGL_POS_H
  9. #define IGL_POS_H
  10. #include <Eigen/Core>
  11. #include <vector>
  12. namespace igl
  13. {
  14. // Pos - Fake halfedge for fast and easy navigation on triangle meshes with VT and TT adj
  15. template <typename S>
  16. class Pos
  17. {
  18. public:
  19. // Init the pos by specifying Face,Edge Index and Orientation
  20. Pos(const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* F,
  21. Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FF,
  22. Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FFi,
  23. int fi,
  24. int ei,
  25. bool reverse = false
  26. )
  27. : F(F), FF(FF), FFi(FFi), fi(fi), ei(ei), reverse(reverse)
  28. {}
  29. // // Init the pos by specifying Face,Vertex Index and Orientation
  30. // Pos(Eigen::MatrixXi& F,
  31. // Eigen::MatrixXi& FF,
  32. // Eigen::MatrixXi& FFi,
  33. // int fi,
  34. // int vi,
  35. // bool reverse = false
  36. // )
  37. // : F(F), FF(FF), FFi(FFi), fi(fi), reverse(reverse)
  38. // {
  39. // ei = -1;
  40. // for (int i=0;i<3;++i)
  41. // if (F(fi,i) == vi)
  42. // ei = i;
  43. // assert(ei != -1);
  44. //
  45. // if (reverse)
  46. // ei = (ei-1)%3;
  47. // }
  48. // Change Face
  49. void flipF()
  50. {
  51. int fin = (*FF)(fi,ei);
  52. int ein = (*FFi)(fi,ei);
  53. int reversen = !reverse;
  54. fi = fin;
  55. ei = ein;
  56. reverse = reversen;
  57. }
  58. // Change Edge
  59. void flipE()
  60. {
  61. if (!reverse)
  62. ei = (ei+2)%3; // ei-1
  63. else
  64. ei = (ei+1)%3;
  65. reverse = !reverse;
  66. }
  67. // Change Vertex
  68. void flipV()
  69. {
  70. reverse = !reverse;
  71. }
  72. // Get vertex index
  73. int Vi()
  74. {
  75. assert(fi >= 0);
  76. assert(fi < F->rows());
  77. assert(ei >= 0);
  78. assert(ei <= 2);
  79. if (!reverse)
  80. return (*F)(fi,ei);
  81. else
  82. return (*F)(fi,(ei+1)%3);
  83. }
  84. // Get face index
  85. int Fi()
  86. {
  87. return fi;
  88. }
  89. bool operator==(Pos& p2)
  90. {
  91. return
  92. (
  93. (fi == p2.fi) &&
  94. (ei == p2.ei) &&
  95. (reverse == p2.reverse) &&
  96. (F == p2.F) &&
  97. (FF == p2.FF) &&
  98. (FFi == p2.FFi)
  99. );
  100. }
  101. int fi;
  102. int ei;
  103. bool reverse;
  104. const Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* F;
  105. Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FF;
  106. Eigen::Matrix<S, Eigen::Dynamic, Eigen::Dynamic>* FFi;
  107. };
  108. }
  109. #endif