on_boundary.cpp 2.7 KB

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