limit_faces.cpp 1.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263
  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 "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. using namespace std;
  19. using namespace Eigen;
  20. vector<bool> in(F.rows(),false);
  21. int num_in = 0;
  22. // loop over faces
  23. for(int i = 0;i<F.rows();i++)
  24. {
  25. bool all = true;
  26. bool any = false;
  27. for(int j = 0;j<F.cols();j++)
  28. {
  29. bool found = false;
  30. // loop over L
  31. for(int l = 0;l<L.size();l++)
  32. {
  33. if(F(i,j) == L(l))
  34. {
  35. found = true;
  36. break;
  37. }
  38. }
  39. any |= found;
  40. all &= found;
  41. }
  42. in[i] = (exclusive?all:any);
  43. num_in += (in[i]?1:0);
  44. }
  45. LF.resize(num_in,F.cols());
  46. // loop over faces
  47. int lfi = 0;
  48. for(int i = 0;i<F.rows();i++)
  49. {
  50. if(in[i])
  51. {
  52. LF.row(lfi) = F.row(i);
  53. lfi++;
  54. }
  55. }
  56. }
  57. #ifdef IGL_STATIC_LIBRARY
  58. // Explicit template specialization
  59. #endif