on_boundary.cpp 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. #include "on_boundary.h"
  2. // IGL includes
  3. #include "sort.h"
  4. #include "face_occurences.h"
  5. // STL includes
  6. #include <map>
  7. template <typename IntegerT>
  8. IGL_INLINE void igl::on_boundary(
  9. const std::vector<std::vector<IntegerT> > & T,
  10. std::vector<bool> & I,
  11. std::vector<std::vector<bool> > & C)
  12. {
  13. using namespace std;
  14. using namespace igl;
  15. // Get a list of all faces
  16. vector<vector<IntegerT> > F(T.size()*4,vector<IntegerT>(3));
  17. // Gather faces, loop over tets
  18. for(int i = 0; i< (int)T.size();i++)
  19. {
  20. assert(T[i].size() == 4);
  21. // get face in correct order
  22. F[i*4+0][0] = T[i][1];
  23. F[i*4+0][1] = T[i][3];
  24. F[i*4+0][2] = T[i][2];
  25. // get face in correct order
  26. F[i*4+1][0] = T[i][0];
  27. F[i*4+1][1] = T[i][2];
  28. F[i*4+1][2] = T[i][3];
  29. // get face in correct order
  30. F[i*4+2][0] = T[i][0];
  31. F[i*4+2][1] = T[i][3];
  32. F[i*4+2][2] = T[i][1];
  33. // get face in correct order
  34. F[i*4+3][0] = T[i][0];
  35. F[i*4+3][1] = T[i][1];
  36. F[i*4+3][2] = T[i][2];
  37. }
  38. // Counts
  39. vector<int> FC;
  40. face_occurences(F,FC);
  41. C.resize(T.size(),vector<bool>(4));
  42. I.resize(T.size(),false);
  43. for(int i = 0; i< (int)T.size();i++)
  44. {
  45. for(int j = 0;j<4;j++)
  46. {
  47. C[i][j] = FC[i*4+j]==1;
  48. assert(C[i][j] == 2 || C[i][j] == 1);
  49. // if any are on boundary set to true
  50. I[i] = I[i] || C[i][j];
  51. }
  52. }
  53. }
  54. #ifndef IGL_NO_EIGEN
  55. #include "list_to_matrix.h"
  56. #include "matrix_to_list.h"
  57. template <typename DerivedT, typename DerivedI, typename DerivedC>
  58. IGL_INLINE void igl::on_boundary(
  59. const Eigen::PlainObjectBase<DerivedT>& T,
  60. Eigen::PlainObjectBase<DerivedI>& I,
  61. Eigen::PlainObjectBase<DerivedC>& C)
  62. {
  63. assert(T.cols() == 0 || T.cols() == 4);
  64. using namespace std;
  65. using namespace Eigen;
  66. using namespace igl;
  67. // Cop out: use vector of vectors version
  68. vector<vector<typename Eigen::PlainObjectBase<DerivedT>::Scalar> > vT;
  69. matrix_to_list(T,vT);
  70. vector<bool> vI;
  71. vector<vector<bool> > vC;
  72. on_boundary(vT,vI,vC);
  73. list_to_matrix(vI,I);
  74. list_to_matrix(vC,C);
  75. }
  76. #endif
  77. #ifndef IGL_HEADER_ONLY
  78. // Explicit template specialization
  79. template void igl::on_boundary<Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1>, Eigen::Matrix<int, -1, -1, 0, -1, -1> >(Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> > const&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&, Eigen::PlainObjectBase<Eigen::Matrix<int, -1, -1, 0, -1, -1> >&);
  80. #endif