on_boundary.cpp 2.7 KB

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