limit_faces.cpp 1.3 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. // This file is part of libigl, a simple c++ geometry processing library.
  2. //
  3. // Copyright (C) 2013 Alec Jacobson <[email protected]>
  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 "limit_faces.h"
  9. #include <vector>
  10. #include <Eigen/Dense>
  11. template <typename MatF, typename VecL>
  12. IGL_INLINE void igl::limit_faces(
  13. const MatF & F,
  14. const VecL & L,
  15. const bool exclusive,
  16. MatF & LF)
  17. {
  18. std::vector<bool> in(F.rows(),false);
  19. int num_in = 0;
  20. // loop over faces
  21. for(int i = 0;i<F.rows();i++)
  22. {
  23. bool all = true;
  24. bool any = false;
  25. for(int j = 0;j<F.cols();j++)
  26. {
  27. bool found = false;
  28. // loop over L
  29. for(int l = 0;l<L.size();l++)
  30. {
  31. if(F(i,j) == L(l))
  32. {
  33. found = true;
  34. break;
  35. }
  36. }
  37. any |= found;
  38. all &= found;
  39. }
  40. in[i] = (exclusive?all:any);
  41. num_in += (in[i]?1:0);
  42. }
  43. LF.resize(num_in,F.cols());
  44. // loop over faces
  45. int lfi = 0;
  46. for(int i = 0;i<F.rows();i++)
  47. {
  48. if(in[i])
  49. {
  50. LF.row(lfi) = F.row(i);
  51. lfi++;
  52. }
  53. }
  54. }
  55. #ifdef IGL_STATIC_LIBRARY
  56. // Explicit template instantiation
  57. #endif