on_boundary.cpp 2.4 KB

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