limit_faces.h 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. #ifndef IGL_LIMIT_FACES
  2. #define IGL_LIMIT_FACES
  3. namespace igl
  4. {
  5. // LIMIT_FACES limit given faces F to those which contain (only) indices found
  6. // in L.
  7. //
  8. // [LF] = limit_faces(F,L,exclusive);
  9. // [LF,in] = limit_faces(F,L,exclusive);
  10. //
  11. // Templates:
  12. // MatF matrix type of faces, matrixXi
  13. // VecL matrix type of vertex indices, VectorXi
  14. // Inputs:
  15. // F #F by 3 list of face indices
  16. // L #L by 1 list of allowed indices
  17. // exclusive flag specifying whether a face is included only if all its
  18. // indices are in L, default is false
  19. // Outputs:
  20. // LF #LF by 3 list of remaining faces after limiting
  21. // in #F list of whether given face was included
  22. //
  23. template <typename MatF, typename VecL>
  24. void limit_faces(
  25. const MatF & F,
  26. const VecL & L,
  27. const bool exclusive,
  28. MatF & LF);
  29. }
  30. // Implementation
  31. #include <vector>
  32. template <typename MatF, typename VecL>
  33. void igl::limit_faces(
  34. const MatF & F,
  35. const VecL & L,
  36. const bool exclusive,
  37. MatF & LF)
  38. {
  39. using namespace std;
  40. using namespace Eigen;
  41. vector<bool> in(F.rows(),false);
  42. int num_in = 0;
  43. // loop over faces
  44. for(int i = 0;i<F.rows();i++)
  45. {
  46. bool all = true;
  47. bool any = false;
  48. for(int j = 0;j<F.cols();j++)
  49. {
  50. bool found = false;
  51. // loop over L
  52. for(int l = 0;l<L.size();l++)
  53. {
  54. if(F(i,j) == L(l))
  55. {
  56. found = true;
  57. break;
  58. }
  59. }
  60. any |= found;
  61. all &= found;
  62. }
  63. in[i] = (exclusive?all:any);
  64. num_in += (in[i]?1:0);
  65. }
  66. LF.resize(num_in,F.cols());
  67. // loop over faces
  68. int lfi = 0;
  69. for(int i = 0;i<F.rows();i++)
  70. {
  71. if(in[i])
  72. {
  73. LF.row(lfi) = F.row(i);
  74. lfi++;
  75. }
  76. }
  77. }
  78. #endif